gpt4 book ai didi

python - 如何识别基因组中特定位置的特征

转载 作者:行者123 更新时间:2023-11-28 17:46:05 24 4
gpt4 key购买 nike

我有兴趣确定基因组特定位置的特征(即基因/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']

最佳答案

我从未使用过 BioPython,但我在其文档中找到了它:http://biopython.org/wiki/SeqIO

from Bio import SeqIO
handle = open("example.fasta", "rU")
records = list(SeqIO.parse(handle, "fasta"))
handle.close()
print records[0].id #first record
print records[-1].id #last record

这就是你要找的吗?

关于python - 如何识别基因组中特定位置的特征,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17868682/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com