本文整理汇总了Python中ete3.Tree.taxname方法的典型用法代码示例。如果您正苦于以下问题:Python Tree.taxname方法的具体用法?Python Tree.taxname怎么用?Python Tree.taxname使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ete3.Tree
的用法示例。
在下文中一共展示了Tree.taxname方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: load_ncbi_tree_from_dump
# 需要导入模块: from ete3 import Tree [as 别名]
# 或者: from ete3.Tree import taxname [as 别名]
def load_ncbi_tree_from_dump(tar):
from ete3 import Tree
# Download: ftp://ftp.ncbi.nih.gov/pub/taxonomy/taxdump.tar.gz
parent2child = {}
name2node = {}
node2taxname = {}
synonyms = set()
name2rank = {}
node2common = {}
print("Loading node names...")
for line in tar.extractfile("names.dmp"):
line = str(line.decode())
fields = list(map(str.strip, line.split("|")))
nodename = fields[0]
name_type = fields[3].lower()
taxname = fields[1]
if name_type == "scientific name":
node2taxname[nodename] = taxname
if name_type == "genbank common name":
node2common[nodename] = taxname
elif name_type in set(["synonym", "equivalent name", "genbank equivalent name",
"anamorph", "genbank synonym", "genbank anamorph", "teleomorph"]):
synonyms.add( (nodename, taxname) )
print(len(node2taxname), "names loaded.")
print(len(synonyms), "synonyms loaded.")
print("Loading nodes...")
for line in tar.extractfile("nodes.dmp"):
line = str(line.decode())
fields = line.split("|")
nodename = fields[0].strip()
parentname = fields[1].strip()
n = Tree()
n.name = nodename
n.taxname = node2taxname[nodename]
if nodename in node2common:
n.common_name = node2common[nodename]
n.rank = fields[2].strip()
parent2child[nodename] = parentname
name2node[nodename] = n
print(len(name2node), "nodes loaded.")
print("Linking nodes...")
for node in name2node:
if node == "1":
t = name2node[node]
else:
parent = parent2child[node]
parent_node = name2node[parent]
parent_node.add_child(name2node[node])
print("Tree is loaded.")
return t, synonyms