TabularMSA替换Alignment(scikit-bio 0.4.1.dev0)

时间:2016-01-12 22:16:11

标签: skbio

我想读取PHYLIP对齐(FASTA格式),更新序列标签并将结果写回文件。如何编辑以下行以在scikit-bio 0.4.1.dev0中使用TabularMSA(而不是之前支持的Alignment):

from skbio import Alignment ... msa_fa = Alignment.read(gene_msa_fa_fp, format='fasta') msa_fa_update_ids, new_to_old_ids = msa_fa.update_ids(func=id_mapper) msa_fa_update_ids.write(output_msa_phy_fp, format='phylip') ...

谢谢!

1 个答案:

答案 0 :(得分:1)

将FASTA文件读入TabularMSA对象时,序列标识符存储在键metadata下的每个序列的"id"字典中。以PHYLIP格式编写TabularMSA对象时,MSA的index属性用于标记序列。使用reassign_index将FASTA序列标识符用作MSA索引,然后将其映射到您想要编写的序列标签,最后以PHYLIP格式写出:

from skbio import TabularMSA, DNA
msa = TabularMSA.read("aln.fasta", constructor=DNA)
msa.reassign_index(minter='id')
msa.reassign_index(mapping=id_mapper)
msa.write('aln.phy', format='phylip')

设置索引的方法有多种,包括直接设置属性或使用reassign_index mappingminter参数设置属性。