hello, I am beginner of python I have two dna sequences in fasta format. I want to blast these two sequences.can anyone suggest me some solution in python. I have used NcbiblastnCommandline. but it is not worked.
from Bio.Blast.Applications import NcbiblastpCommandline
from StringIO import StringIO
from Bio.Blast import NCBIXML
from Bio.Seq import Seq
from Bio.SeqRecord import SeqRecord
from Bio import SeqIO
# Create two sequence files
seq1 = SeqRecord(Seq("FQTWEEFSRAAEKLYLADPMKVRVVLKYRHVDGNLCIKVTDDLVCLVYRTDQAQDVKKIEKF"),
id="seq1")
seq2 = SeqRecord(Seq("FQTWEEFSRAEKLYLADPMKVRVVLRYRHVDGNLCIKVTDDLICLVYRTDQAQDVKKIEKF"),
id="seq2")
SeqIO.write(seq1, "seq1.fasta", "fasta")
SeqIO.write(seq2, "seq2.fasta", "fasta")
# Run BLAST and parse the output as XML
output = NcbiblastpCommandline(query="seq1.fasta", subject="seq2.fasta", outfmt=5)()[0]
blast_result_record = NCBIXML.read(StringIO(output))
# Print some information on the result
for alignment in blast_result_record.alignments:
for hsp in alignment.hsps:
print '****Alignment****'
print 'sequence:', alignment.title
print 'length:', alignment.length
print 'e value:', hsp.expect
print hsp.query
print hsp.match
print hsp.sbjct
I found that error file not specified.
If there is no particular reason to run BLAST through Biopython with XML output, I typically will run the blast command if I have downstream python code, using
suprocess()
, with tab-delimited output which is easier to parse IMO after with python.Have you installed local blastp? Looking at your code, I assume you are using Windows.
Biopython tries to run just "blastp" not "blastp.exe" thus we must specify exact path to the blastp.exe (I think).
This is the line I ran blastp with your code.
C:\apps\ncbi-blast-2.6.0+\bin\blastp.exe is the executable of blastp I downloaded from NCBI FTP server.
thank you very much.I will try this
It is not working. I am getting same error.
Could you give me complete error message and your path of blastp.exe?
yes, the code above works for me, so without the error message difficult to solve