[BioPython] Running Blast locally

Peter biopython at maubp.freeserve.co.uk
Fri Jun 16 15:53:31 UTC 2006


Muthuraman, Manickam wrote:
> Dear Christof
> 
> Your command also works  separately but my question was how to intergrate blast in biopython script.
> 
> in biopython tutorial and cookbook they have the follwoing code where i need to provide the path to database ,file to blast and blast_exe.
> 
> I am not clear how to set the path for seq_file,db and exe.
> 
> import os
> my_blast_db=os.path.join(os.getcwd(),'at-est','a-cds-10-7.fasta')
> my_blast_file=os.path.join(os.getcwd(),'at-est','test_blast','sorghum_est-test.fasta')
> my_blast_exe=os.path.join(os.getcwd(),'blast','/home/manickam/blast/blastall')

Try typing this at the python prompt:

import os
help(os.path.join)

Are you familiar with relative paths etc?  You might find something like 
this easier to understand:

my_blast_db   = '/home/manickam/db/at-est/a-cds-10-7.fasta')
my_blast_file = '/home/manickam/sorghum_est-test.fasta')
my_blast_exe  = '/home/manickam/blast/blastall'

Or, based on you previous email you were using:

 > here is the command :
 > ./blastall -d db/swissprot -i /home/manickam/Documents/m_cold.fasta
 > -p blastp

Maybe something like this:

my_blast_db   = '/home/manickam/blast/db/swissprot')
my_blast_file = '/home/manickam/Documents/m_cold.fasta')
my_blast_exe  = '/home/manickam/blast/blastall'

It all depends on where you installed the blast program, where you put 
the blast databases, and where you are going to have your inputfile.

> here is the whole script
01> import os
02> my_blast_db=os.path.join(os.getcwd(),'at-est','a-cds-10-7.fasta')
03> 
my_blast_file=os.path.join(os.getcwd(),'at-est','test_blast','sorghum_est-test.fasta')
04> 
my_blast_exe=os.path.join(os.getcwd(),'blast','/home/manickam/blast/blastall')
05> from Bio.Blast import NCBIStandalone
06> 
blast_out,error_info=NCBIStandalone.blastall(my_blast_exe,'blastp',my_blast_db,my_blast_file)

At this point, some example scripts will save the output to a file, and 
then reload it and carry on.  This is very helpful if you have problems 
because you can open the file by hand and look at it.

07> b_parser=NCBIStandalone.BlastParser()
08> b_iterator=NCBIStandalone.Iterator(blast_out,b_parser)
09> b_record=b_iterator.next()
10> while 1:
11>     b_record=b_iterator.next()
12>     if b_record is None:
13>         break
14>     for alignment in b_record.alignments:
15>         print "inside 2 loop"
16>         for hsp in alignment.hsps:
17>             print "inside 1 loop"
18>             print 'seq:',alignment.title
> 
> it runs but b_record is None so it comes out of the while loop at first time itself. so it mean i am not getting out put of the blast.

Notice that at line 9, you set b_record to the first set of results 
(i.e. from the first sequence in your FASTA file).

Then, inside the look, at line 11 set b_record to the SECOND set of 
results and try and look at it.

I suggest you comment out line 9, and it should work better.

Finally, this code is using the "plain text" blast output, which can 
sometimes cause BioPython trouble.  I would recommend the XML parser but 
as you might know from the mailing list, it looks like they have changed 
the file format for multiple results in XML output...

Peter




More information about the Biopython mailing list