BLAST Alignment in Java

Articles —> BLAST Alignment in Java

The JeUtils library is capable of performing a BLAST sequence alignment by communicating with the NCBI BLAST sequence alignment servers*.

To run a BLAST analysis, first create an instance of the PutCommand class, configuring with the appropriate parameters (query, database, etc...). This places the query into the BLAST queue at NCBI. Once complete, create an instance of GetCommand, which is used to retrieve the results once complete. Lastly, construct a Blast object which wraps both the GetCommand and PutCommand object to fully automate the BLAST alignment.


//First construct a PutCommand

//with the necessary parameters

PutCommand put = new PutCommand();

put.setQuery("agaaattaaagctacttacaacaacggtctactacaaattaaggtgcctaaaattgtcaatgacactgaaaagccgaagccaaaaaagaggatcgccattgaggaaatacccgacgaagaattg");

put.setProgram("blastn");

put.setDatabase("nr");

//Construct a GetCommand to get the results

GetCommand get = new GetCommand(new BlastParser(){



	@Override

        /**

        * Simply prints results to the command line

        * @param output The output from the blast results.

        */

 	public void parseBlastOutput(String output) {

		System.out.println(output);

	}

	

});

get.setFormatType("Text");

//Create the Blast object to run the get and put processes

Blast blast = new Blast(put, get);

//Run the alignment. Blast implements Runnable, and can therefore be run in a separate thread.

blast.run();

The above code does a blastn search against the Non-redundant GenBank CDS translations (nr). The results are printed out to the command line, however the BlastParser could be implemented to do a variety of other things (save to file or database, parse data to retrieve particular features (such as homology, closest relatives, homologs from a particular organism etc...).

*NCBI is a public utility used by a great many people - please avoid large volumes of requests at a single time.




Comments

  • K K   -   November, 3, 2013

    Can i store the blast output as a String?

  • Greg Cope   -   November, 3, 2013

    The BlastParser object passed to GetCommand above is passed the BLAST results as a String object when the results are complete, thus providing a custom implementation of the BlastParser interface lets you further parse or deal with the BLAST results (in the above example, the results are just printed to the command line using System.out.println).

  • Akash kumar   -   February, 19, 2016

    This code print nothing blast output it only print

    BLASTN 2.3.1+

    Reference: Stephen F. Altschul, Thomas L. Madden, Alejandro

    A. Schaffer, Jinghui Zhang, Zheng Zhang, Webb Miller, and

    David J. Lipman (1997), "Gapped BLAST and PSI-BLAST: a new

    generation of protein database search programs", Nucleic

    Acids Res. 25:3389-3402.

    Please suggest me how to get the similarity index

Back to Articles


© 2008-2017 Greg Cope