【发布时间】:2013-07-25 21:02:38
【问题描述】:
我有兴趣确定基因组特定位置的特征(即基因/cds)。例如,什么基因(如果有)包含位置 2,000,000。我知道如何使用for 循环并遍历基因组中的每个特征(代码包含在下面)来做到这一点,但这是我想做数亿次随机化研究的一部分,而这个将花费比我想要的更长的时间。
下面包含的代码是我正在尝试做的更具体的示例:
from Bio import SeqIO
import random
GenomeSeq = SeqIO.read(open("reference_sequence.gbk", "r"), "genbank")
interesting_position = random.randint(0, len(GenomeSeq))
for feature in GenomeSeq.features: # loop each position through whole genome
# In this particular case I'm interested in focusing on cds, but
# in others, I may be interested in other feature types?
if feature.type == "CDS":
if (feature.location._start.position <= interesting_position and
feature.location._end.position >= interesting_position):
try:
print feature.qualifiers['gene']
except KeyError:
print feature
我考虑过制作一个字典,其中基因中的每个位置对应一个键,特征 ID 作为值,因为查找比循环更快,但似乎应该有一种方法做GenomeSeq[interestion_position].qualifiers['gene']
【问题讨论】:
-
可能是
GenomeSeq[interesting_position].features()之类的? -
@verbsintransit 是的,这很好,但它似乎不起作用,我得到一个属性错误('str' 对象没有属性'features')。这是行之有效的事情,还是您希望看到的事情?