本文介绍了如何从滑行中获取王国,门,阶级,秩序,家庭,属和物种的分类学特定ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个滑行清单,看起来像这样:
I have a list of taxids that looks like this:
1204725
2162
1300163
420247
我希望从上面的标本中按顺序获取具有分类ID的文件:
I am looking to get a file with taxonomic ids in order from the taxids above:
kingdom_id phylum_id class_id order_id family_id genus_id species_id
我正在使用软件包" ete3 ".我使用的工具 ete-ncbiquery 可以告诉您上述ID的沿袭. (我使用下面的命令从linux笔记本电脑运行它)
I am using the package "ete3". I use the tool ete-ncbiquery that tells you the lineage from the ids above. (I run it from my linux laptop with the command below)
ete3 ncbiquery --search 1204725 2162 13000163 420247 --info
结果如下:
# Taxid Sci.Name Rank Named Lineage Taxid Lineage
2162 Methanobacterium formicicum species root,cellular organisms,Archaea,Euryarchaeota,Methanobacteria,Methanobacteriales,Methanobacteriaceae,Methanobacterium,Methanobacterium formicicum 1,131567,2157,28890,183925,2158,2159,2160,2162
1204725 Methanobacterium formicicum DSM 3637 no rank root,cellular organisms,Archaea,Euryarchaeota,Methanobacteria,Methanobacteriales,Methanobacteriaceae,Methanobacterium,Methanobacterium formicicum,Methanobacterium formicicum DSM 3637 1,131567,2157,28890,183925,2158,2159,2160,2162,1204725
420247 Methanobrevibacter smithii ATCC 35061 no rank root,cellular organisms,Archaea,Euryarchaeota,Methanobacteria,Methanobacteriales,Methanobacteriaceae,Methanobrevibacter,Methanobrevibacter smithii,Methanobrevibacter smithii ATCC 350611,131567,2157,28890,183925,2158,2159,2172,2173,420247
我不知道哪些物品(IDS)与我要寻找的物品相对应(如果有的话)
I have no idea which items (IDS) correspond to what I am looking for (if any)
推荐答案
以下代码:
import csv
from ete3 import NCBITaxa
ncbi = NCBITaxa()
def get_desired_ranks(taxid, desired_ranks):
lineage = ncbi.get_lineage(taxid)
lineage2ranks = ncbi.get_rank(lineage)
ranks2lineage = dict((rank, taxid) for (taxid, rank) in lineage2ranks.items())
return {'{}_id'.format(rank): ranks2lineage.get(rank, '<not present>') for rank in desired_ranks}
def main(taxids, desired_ranks, path):
with open(path, 'w') as csvfile:
fieldnames = ['{}_id'.format(rank) for rank in desired_ranks]
writer = csv.DictWriter(csvfile, delimiter='\t', fieldnames=fieldnames)
writer.writeheader()
for taxid in taxids:
writer.writerow(get_desired_ranks(taxid, desired_ranks))
if __name__ == '__main__':
taxids = [1204725, 2162, 1300163, 420247]
desired_ranks = ['kingdom', 'phylum', 'class', 'order', 'family', 'genus', 'species']
path = 'taxids.csv'
main(taxids, desired_ranks, path)
产生一个看起来像这样的文件:
Produces a file that looks like this:
kingdom_id phylum_id class_id order_id family_id genus_id species_id
<not present> 28890 183925 2158 2159 2160 2162
<not present> 28890 183925 2158 2159 2160 2162
<not present> 28890 183925 2158 2159 2160 2162
<not present> 28890 183925 2158 2159 2172 2173
这篇关于如何从滑行中获取王国,门,阶级,秩序,家庭,属和物种的分类学特定ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!