[Biopython] Blast Two Sequences

Islam Amin eng.islamamin at gmail.com
Thu Mar 9 07:42:43 UTC 2017


Dear All,
I got a script from the following link : https://www.biostars.org/p/42687/
<https://www.biostars.org/p/42687/> about how to blast two sequences in
biopython, I wonder if is it possible to pass the sequences direct to as
following:
*NcbiblastpCommandline(query*="FQTWEEFSRAAEKLYLADPMKVRV"*,subject*="FQTWEEFSRAEKLYLADPMK",
outfmt=5)()[0]
unfortunately, I got the error when I'm trying to pass the sequence direct
instead of read fasta file, is there any way to pass sequences direct.

* the script is:*

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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.open-bio.org/pipermail/biopython/attachments/20170309/01531cd0/attachment.html>


More information about the Biopython mailing list