当前位置: 首页>>代码示例>>Python>>正文


Python Tree.common_name方法代码示例

本文整理汇总了Python中ete3.Tree.common_name方法的典型用法代码示例。如果您正苦于以下问题:Python Tree.common_name方法的具体用法?Python Tree.common_name怎么用?Python Tree.common_name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ete3.Tree的用法示例。


在下文中一共展示了Tree.common_name方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: load_ncbi_tree_from_dump

# 需要导入模块: from ete3 import Tree [as 别名]
# 或者: from ete3.Tree import common_name [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
开发者ID:Ward9250,项目名称:ete,代码行数:54,代码来源:ncbiquery.py

示例2: getTheTrees

# 需要导入模块: from ete3 import Tree [as 别名]
# 或者: from ete3.Tree import common_name [as 别名]
def getTheTrees(): 
	##DOWNLOAD taxdump and store in taxo folder
	##DOWNLOAD TAXREF BY HAND! and put it in taxo/

	class Trans:
		def __init__(self):
			self.common_name_FR = []


	print "Getting french translations..."
	TRANS = {} ##translations in french
	with open("taxo/TAXREFv11.txt") as f:  
		for line in f:
			sciname = line.split("\t")[14]
			comnameFR = line.split("\t")[19]
			if (TRANS.has_key(sciname)==False and line.split("\t")[19]!=''):
				TRANS[sciname] = Trans()
			if (line.split("\t")[19]!=''):
				TRANS[sciname].common_name_FR.append(comnameFR)

	#get translation of ranks
	print "\nGetting rank names in french..."
	RANKS = {}
	with open("ranks.txt") as f:  
		for line in f:
			rank_en = line.split("\t")[0]
			rank_fr = line.split("\t")[1].rstrip() ##to remove \n
			RANKS[rank_en] = rank_fr


	class Taxid:
		def __init__(self):
			self.sci_name = ""
			self.authority = ""
			self.synonym = ""
#			self.common_name = ""
			self.common_name = []
#			self.common_name_FR = ""
			self.common_name_FR = []

	cpt = 0
	cptfr = 0
	ATTR = {} ##here we will list attribute of each species per taxid
	print "Reading NCBI taxonomy..."
	with open("taxo/names.dmp") as f:  
		for line in f:		
			taxid = line.split("|")[0].replace("\t","")
			tid_val = line.split("|")[1].replace("\t","")
			tid_type = line.split("|")[3].replace("\t","")
			if (ATTR.has_key(taxid)==False):
				ATTR[taxid] = Taxid()
			if (tid_type=="scientific name"):
				ATTR[taxid].sci_name = tid_val
				#and get translation in french (if any)
				if TRANS.has_key(tid_val):
					ATTR[taxid].common_name_FR = TRANS[tid_val].common_name_FR
					cptfr += 1
			if (tid_type=="authority"):
				if (ATTR[taxid].authority!=""):
					ATTR[taxid].authority = ATTR[taxid].authority + ", " + tid_val
				else:
					ATTR[taxid].authority = tid_val
			if (tid_type=="synonym"):
				if (ATTR[taxid].synonym!=""):
					ATTR[taxid].synonym = ATTR[taxid].synonym + ", " + tid_val
				else:
					ATTR[taxid].synonym = tid_val
			if (tid_type=="common name"):
				cpt +=1
				ATTR[taxid].common_name.append(tid_val)
				# if (ATTR[taxid].common_name!=""):
				# 	ATTR[taxid].common_name = ATTR[taxid].common_name + ", " + tid_val
				# else: 
				# 	ATTR[taxid].common_name = tid_val


	T = {}

	###New gettrees
	from ete3 import Tree
	filepath = 'taxo/nodes.dmp'  
	print "Building the NCBI taxonomy tree..."
	with open(filepath) as fp:  
		first_line = fp.readline() ## remove the 1 | 1 edge
		for line in fp:
			dad = line.split("|")[1].replace("\t","")
			son = line.split("|")[0].replace("\t","")
			rank = line.split("|")[2].replace("\t","")
			if (T.has_key(dad)==False):
				T[dad] = Tree()
				T[dad].name = dad
#				T[dad].rank = rank
#				T[dad].rank_FR = RANKS[rank]
				T[dad].taxid = dad
				T[dad].sci_name = ATTR[dad].sci_name
				T[dad].common_name = ATTR[dad].common_name
				T[dad].synonym = ATTR[dad].synonym
				T[dad].authority = ATTR[dad].authority
				T[dad].common_name_FR = ATTR[dad].common_name_FR
			if (T.has_key(son)==False):
#.........这里部分代码省略.........
开发者ID:damiendevienne,项目名称:Lifemap,代码行数:103,代码来源:getTrees_fun.py

示例3: open

# 需要导入模块: from ete3 import Tree [as 别名]
# 或者: from ete3.Tree import common_name [as 别名]
filepath = 'taxo/nodes.dmp'  
print "Building the NCBI taxonomy tree..."
with open(filepath) as fp:  
	first_line = fp.readline() ## remove the 1 | 1 edge
	for line in fp:
		dad = line.split("|")[1].replace("\t","")
		son = line.split("|")[0].replace("\t","")
		rank = line.split("|")[2].replace("\t","")
		if (T.has_key(dad)==False):
			T[dad] = Tree()
			T[dad].name = dad
			T[dad].rank = rank
			T[dad].rank_FR = RANKS[rank]
			T[dad].taxid = dad
			T[dad].sci_name = ATTR[dad].sci_name
			T[dad].common_name = ATTR[dad].common_name
			T[dad].synonym = ATTR[dad].synonym
			T[dad].authority = ATTR[dad].authority
			T[dad].common_name_FR = ATTR[dad].common_name_FR
		if (T.has_key(son)==False):
			T[son] = Tree()
			T[son].name = son
			T[son].rank = rank
			T[son].rank_FR = RANKS[rank]
			T[son].taxid = son
			T[son].sci_name = ATTR[son].sci_name
			T[son].common_name = ATTR[son].common_name
			T[son].synonym = ATTR[son].synonym
			T[son].authority = ATTR[son].authority
			T[son].common_name_FR = ATTR[son].common_name_FR
		T[dad].add_child(T[son])
开发者ID:damiendevienne,项目名称:Lifemap,代码行数:33,代码来源:getTrees.py


注:本文中的ete3.Tree.common_name方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。