我刚接触Biopython,在解析genbank文件时遇到了性能问题。
我必须解析很多gb文件,从中我有登录号。在解析之后,我只想检查文件的分类法和器官。现在,我有这样的代码:
from Bio import SeqIO
from Bio import Entrez
gb_acc1 = Entrez.efetch(db='nucleotide', id=access1, rettype='gb', retmode='text') #Where access1 contents the accession number
rec = SeqIO.read(gb_acc1, 'genbank')
cache[access1] = rec #where cache is just a dictionary where saving the gb files already downloaded
feat = cache[access1].features[0]
if 'organelle' in feat.qualifiers.keys(): #And the code goes on为了查找我拥有的分类法:
gi_h = Entrez.efetch(db='nucleotide', id=access, rettype='gb', retmode='text')
gi_rec = SeqIO.read(gi_h, 'genbank')
cache[access]=gi_rec
if cache[access].annotations['taxonomy'][1] == 'Fungi':
fungi += 1 #And the code goes on这(整个脚本)运行得很好。我的问题是,我下载了整个gb文件(有时很大),只是为了查看这两个特性:细胞器和分类法。如果我只能下载gb文件的这一部分,我的脚本会快得多,但我还没有弄清楚这是否可能。
有没有人知道这是否可以做到,如果可以,如何做到?提前谢谢你
发布于 2016-07-28 07:14:10
你可以使用seq_start and seq_stop截断你的序列,然后像以前一样解析它,例如
gb_acc1 = Entrez.efetch(db='nuccore', id=access1, rettype='gb', retmode='xml', seq_start=1, seq_stop=1)也许您甚至不需要存储整个GenBank文件,只需要存储一个字典,其中ID作为键,分类法和器官作为值?
https://stackoverflow.com/questions/38614031
复制相似问题