我有一个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"):
但是我不太确定下一行或下一行2应该按位置解析吗?有任何想法吗?
您也可以使用一个轨迹标记列表,而不只是一个轨迹标记。
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`.
您可以在extract
中找到有关Biopython Cookbook方法和功能限定符的更多信息。