如何评估blast_record中的特定序列

时间:2019-06-15 17:33:41

标签: python python-3.x biopython

以下代码将打印出记录中的所有序列。 我如何评估具体的一个?

from Bio.Blast import NCBIWWW
from Bio.Blast import NCBIXML

fly=0
grape=0
with open('input.txt', 'r') as file:

    count = 1

    for i in file:
        print("Sequence {} :{}  Length: {}".format(count, i[:20], len(i))) 
        count += 1

    count -= 1
    print("There are %d sequences." % count)  # count = 10

    file.seek(0) # move position indicator to the start.

    for i in range(1,2):
        seq = file.readline()

        try:
            with open('dna_lab5_%d.xml' % i, 'r') as f:
                print("Using saved file")
        except FileNotFoundError:
            print("Performing online BLAST search")
            with open('dna_lab5_%d.xml' % i, 'w') as f:

                 handle = NCBIWWW.qblast("blastn", "nt", seq)
                 result = handle.read()
                 f.write(result)

        finally:
            with open('dna_lab5_%d.xml' % i,'r+') as f:

                records=NCBIXML.parse(f)

                for record in records:


                    for alignment in record.alignments:
                         for hsp in alignment.hsps:
                            print(alignment.title)
#                             if "melanogaster" in alignment[0].title:
#                                 fly+=1
#                             else:
#                                 grape+=1
#
# print (fly)

我想要序列的第一行,所以我尝试了 records[0].alignments[0].hsps[0].title 我也尝试过 records.alignments[0].title 他们都没有工作。 我可以知道从他们那里读书的正确方法吗?

谢谢

0 个答案:

没有答案