本文整理汇总了Python中dendropy.Tree.as_string方法的典型用法代码示例。如果您正苦于以下问题:Python Tree.as_string方法的具体用法?Python Tree.as_string怎么用?Python Tree.as_string使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dendropy.Tree
的用法示例。
在下文中一共展示了Tree.as_string方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: reroot_tree
# 需要导入模块: from dendropy import Tree [as 别名]
# 或者: from dendropy.Tree import as_string [as 别名]
def reroot_tree(tstr):
"""Input: a tree path to a Newick tree. Output: a re-rooted version of the tree, based on the outgroup defined in configuration.py"""
t = Tree()
t.read_from_string(tstr.__str__(), "newick")
og = ap.params["outgroup"]
og = re.sub("\[", "", og)
og = re.sub("\]", "", og)
og = re.sub("\"", "", og)
ogs = og.split(",")
mrca = t.mrca(taxon_labels=ogs)
t.reroot_at_edge(mrca.edge, update_splits=False)
ret = t.as_string("newick")
ret = re.sub("\[\&\R\] ", "", ret)
ret = ret.strip()
return ret
示例2: reroot_newick
# 需要导入模块: from dendropy import Tree [as 别名]
# 或者: from dendropy.Tree import as_string [as 别名]
def reroot_newick(con, newick):
"""Provide a newick string, this method will re-root the tree
based on the 'outgroup' setting."""
cur = con.cursor()
dendrotree = Tree()
dendrotree.read_from_string(newick, "newick")
sql = "select shortname from Taxa where id in (select taxonid from GroupsTaxa where groupid in (select id from TaxaGroups where name='outgroup'))"
cur.execute(sql)
rrr = cur.fetchall()
outgroup_labels = []
for iii in rrr:
label = re.sub("_", " ", iii[0])
outgroup_labels.append( label.__str__() )
mrca = dendrotree.mrca(taxon_labels=outgroup_labels)
if mrca.edge.tail_node != None and mrca.edge.head_node != None:
dendrotree.reroot_at_edge(mrca.edge, update_splits=True)
newick = dendrotree.as_string("newick")
return newick