[Biojava-l] BLAST from Java

Russell Smithies russell.smithies@xtra.co.nz
Wed, 20 Feb 2002 22:40:41 +1300


Thanx for your help, I've got it working OK now.
I downloaded Blast from NCBI and now it works.

Test code I'm using now is:
******************************
import java.io.*;
public class blasttest{
public static void main(String [] args)throws Exception{

//command strings for BLAST
  String [] cmds = {"c:/bio/blast/blastall.exe",
                    "-p",
                    "blastn",
                    "-d",
                    "c:/bio/blast/ecoli",
                    "-e",
                    "1e-30",
                    "-m8",
                    "-i",
                    "c:/bio/blast/test.txt"};
  Process pro = Runtime.getRuntime().exec(cmds);
  InputStream out = pro.getInputStream();
  int i;
	while((i = out.read())!= -1){
	//do stuff with results
	 System.out.print((char)i);
	}

  }
 }
************************************************
I might ty using different Process for input/output and Threading it to see
if it makes a difference.

Is it worth writing some of this Blast stuff "properly' and adding it to
Biojava?
There's nothing too tricky about running it but being able to use some of
Biojavas other methods on the results might be handy.

Russell


> -----Original Message-----
> From: Thomas Down [mailto:td2@sanger.ac.uk]
> Sent: Wednesday, 20 February 2002 9:16 p.m.
> To: Russell Smithies
> Cc: biojava-l@biojava.org
> Subject: Re: [Biojava-l] BLAST from Java
>
>
> Hmmm, are you saying that the command works okay via
> a batch file, but not if you exec it directly?  Very strange...
>
> I'm not a Windows user.  But one thing which occurs to
> me: you're handling the output of the process on the same
> thread as the Process itself.  I always use separate threads
> (I don't know if this is the `official' way of doing things,
> but it's a pragmatic approach which always seems to be reliable):
>
>    Process pro = // create process.
>    final InputStream out = pro.getInputStream();
>    Thread outputPump = new Thread() {
>      public void run() {
>        try {
>          int i;
>          while ((i = out.read()) != -1) {
>            System.out.print((char) i);
>          }
>        } (catch IOException ex) {}
>      }
>    } ;
>    outputPump.start();
>    pro.waitFor();
>
>
> Having said that, I still don't really understand why running
> blast via a batch file helps.  But you might like to try the
> recipe above and see if it makes a difference.
>
>       Thomas
>
>