生物密码子:如何用GenBan中的“Locus”键进行解析

2024-04-25 18:59:35 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个Genbank文件,其中包含许多序列。我有第二个文本文件,其中包含这些序列的名称,以及一些其他有关它们的信息,在一个TSV中,我把它作为一个数据帧读入。我使用.sample函数从这个数据中随机选择一个名称,并将其赋给变量n_name,如下面的代码块所示。你知道吗

n = df_bp_pos_2.sample(n = 1)
n_value = n.iloc[:2]
n_name = n.iloc[:1]

n_name等于genbank文件中的基因座名称,大小写精确。我试图通过genbank文件进行解析,并提取具有locus = n_name的序列。genbank文件名为all.gb。我有:

from Bio import SeqIO
for seq_record in SeqIO.parse("all.gb", "genbank"):

但是我不太确定下一行或者下一行应该是什么,用轨迹来解析?有什么想法吗?你知道吗


Tags: 文件数据samplename名称信息tsv序列
1条回答
网友
1楼 · 发布于 2024-04-25 18:59:35

您也可以使用轨迹标记列表,而不是仅使用一个轨迹标记。你知道吗

from Bio import SeqIO

locus_tags = ["b0001", "b0002"] # Example list of locus tags
records = []

for record in SeqIO.parse('all.gb', 'genbank'):
    for feature in record.features:
        tag = feature.qualifiers.get('locus_tag')
        if tag:
            if tag[0] in locus_tags:
                # Here you need to either extract the feature sequence from the record (using the extract method) if you only want the feature dna sequence, or alternatively get the translation for the protein by accession the 'translation' field in qualifiers, or make a translation of the feature on the fly. Afterwards you canappend the resulting record to `records`.

您可以在Biopython Cookbook中找到更多关于extract方法和特性限定符的信息。你知道吗

相关问题 更多 >