前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >如何根据物种拉丁名找到其在NCBI Taxonomy所处的位置

如何根据物种拉丁名找到其在NCBI Taxonomy所处的位置

作者头像
用户7010445
发布2020-03-03 14:27:40
1.8K0
发布2020-03-03 14:27:40
举报
问题描述:

我想知道某个物种在NCBI的分类系统里被归为哪个目、哪个科、哪个属? 单个物种可以手动NCBI网站检索,如果物种数非常多如何实现?

之前读 ete3 的帮助文档的时候看到过类似的功能http://etetoolkit.org/docs/latest/tutorial/tutorial_ncbitaxonomy.html。最近可能会用到这个功能,记录自己使用的代码 (首先是安装ete3:自己windows10电脑安装了Anaconda3,直接在DOS窗口下使用命令pip install ete3即可安装)

  • 单个物种 以石榴Punica granatum为例
代码语言:javascript
复制
from ete3 import NCBITaxa
ncbi = NCBITaxa
name2taxid = ncbi.get_name_translator(["Punica granatum"])
for a,b in name2taxid.items():
    lineage = ncbi.get_lineage(b[0])
    names = ncbi.get_taxid_translator(lineage)
    for taxid in lineage:
        print(names[taxid])

输出结果

代码语言:javascript
复制
root
cellular organisms
Eukaryota
Viridiplantae
Streptophyta
Streptophytina
Embryophyta
Tracheophyta
Euphyllophyta
Spermatophyta
Magnoliophyta
Mesangiospermae
eudicotyledons
Gunneridae
Pentapetalae
rosids
malvids
Myrtales
Lythraceae
Punica
Punica granatum
  • 多个物种 将物种拉丁名放到文本文件里,每行一个
代码语言:javascript
复制
Lumnitzera littorea
Punica granatum
Heimia myrtifolia
Sonneratia alba
Epilobium ulleungensis

代码

代码语言:javascript
复制
import sys
from ete3 import NCBITaxa
input_file = sys.argv[1]
output_file = sys.argv[2]
ncbi = NCBITaxa()
fw = open(output_file,"w")
with open(input_file,"r") as fr:
    for line in fr:
        species_name = line.strip()
        name2taxid = ncbi.get_name_translator([species_name])
        for a,b in name2taxid.items():
            lineage = ncbi.get_lineage(b[0])
            names = ncbi.get_taxid_translator(lineage)
            i = 1
            for taxid in lineage:   
                if i < len(lineage):
                    fw.write(names[taxid]+",")
                    i = i + 1
                else:
                    fw.write(names[taxid]+"\n")
        print(species_name + ":","OK")


fw.close()
#使用方法
python .\get_species_placement_in_NCBI.py .\Organism_name.txt placement.txt
#输出结果
root,cellular organisms,Eukaryota,Viridiplantae,Streptophyta,Streptophytina,Embryophyta,Tracheophyta,Euphyllophyta,Spermatophyta,Magnoliophyta,Mesangiospermae,eudicotyledons,Gunneridae,Pentapetalae,rosids,malvids,Myrtales,Combretaceae,Lumnitzera,Lumnitzera littorea
root,cellular organisms,Eukaryota,Viridiplantae,Streptophyta,Streptophytina,Embryophyta,Tracheophyta,Euphyllophyta,Spermatophyta,Magnoliophyta,Mesangiospermae,eudicotyledons,Gunneridae,Pentapetalae,rosids,malvids,Myrtales,Lythraceae,Punica,Punica granatum
root,cellular organisms,Eukaryota,Viridiplantae,Streptophyta,Streptophytina,Embryophyta,Tracheophyta,Euphyllophyta,Spermatophyta,Magnoliophyta,Mesangiospermae,eudicotyledons,Gunneridae,Pentapetalae,rosids,malvids,Myrtales,Lythraceae,Heimia,Heimia myrtifolia
root,cellular organisms,Eukaryota,Viridiplantae,Streptophyta,Streptophytina,Embryophyta,Tracheophyta,Euphyllophyta,Spermatophyta,Magnoliophyta,Mesangiospermae,eudicotyledons,Gunneridae,Pentapetalae,rosids,malvids,Myrtales,Lythraceae,Sonneratia,Sonneratia alba
root,cellular organisms,Eukaryota,Viridiplantae,Streptophyta,Streptophytina,Embryophyta,Tracheophyta,Euphyllophyta,Spermatophyta,Magnoliophyta,Mesangiospermae,eudicotyledons,Gunneridae,Pentapetalae,rosids,malvids,Myrtales,Onagraceae,Onagroideae,Epilobieae,Epilobium,Epilobium ulleungensis
本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2019-03-19,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 小明的数据分析笔记本 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 问题描述:
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档