8

我有一个出租车清单,如下所示:

1204725
2162
1300163
420247

我希望从上面的taxids中按顺序获取带有分类ID的文件:

kingdom_id      phylum_id       class_id        order_id        family_id       genus_id        species_id   

我正在使用包“ ete3 ”。我使用工具ete-ncbiquery告诉您来自上述 id 的血统。(我使用下面的命令从我的 linux 笔记本电脑上运行它)

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)对应于我正在寻找的(如果有的话)

4

3 回答 3

9

以下代码:

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)

生成如下所示的文件:

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
于 2016-04-09T13:53:54.917 回答
1

使用结果中的 Taxid Lineage 编号,尝试在 ete3 的get_rank方法中使用它们。例如:_

from ete3 import NCBITaxa
ncbi = NCBITaxa()

print ncbi.get_rank([9606, 9443])
# {9443: u'order', 9606: u'species'}

推测结果字典应该包含所有 ID 的排名信息,包括您可能想要消除的任何中间“无排名”ID。

于 2016-04-08T19:19:02.890 回答
0

您也可以使用 R 包taxonomizr。该软件包需要一些时间来下载必要的文件,但之后它非常快速和容易。

library("taxonomizr)
getNamesAndNodes()
taxaNodes <- read.nodes('nodes.dmp')
taxaNames <- read.names('names.dmp')
taxaID <- c("1204725", "2162", "1300163", "420247")

getNamesAndNodes从 ncbi下载names.dmp和文件。nodes.dmp

于 2018-05-08T14:23:46.197 回答