本文整理汇总了Python中tree.Node.otu方法的典型用法代码示例。如果您正苦于以下问题:Python Node.otu方法的具体用法?Python Node.otu怎么用?Python Node.otu使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tree.Node
的用法示例。
在下文中一共展示了Node.otu方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: parse_trees
# 需要导入模块: from tree import Node [as 别名]
# 或者: from tree.Node import otu [as 别名]
def parse_trees(e, otus):
"""
Get trees from an etree object
Args:
e: A nexml document parsed by etree
otus: OTUs returned by parse_otus
Returns:
list: A list of ivy Storage objects each
containing every node of a tree.
"""
from tree import Node
v = []
for tb in e.findall(NEXML+"trees"):
for te in tb.findall(NEXML+"tree"):
t = storage.Storage()
t.attrib = storage.Storage(te.attrib)
t.nodes = {}
for n in te.findall(NEXML+"node"):
node = Node()
if n.attrib.get("otu"):
node.isleaf = True
node.otu = otus[n.attrib["otu"]]
node.label = node.otu.label
t.nodes[n.attrib["id"]] = node
for edge in te.findall(NEXML+"edge"):
d = edge.attrib
n = t.nodes[d["target"]]
p = t.nodes[d["source"]]
length = d.get("length")
if length:
n.length = float(length)
p.add_child(n)
r = [ n for n in t.nodes.values() if not n.parent ]
assert len(r)==1
r = r[0]
r.isroot = True
for i, n in enumerate(r): n.id = i+1
t.root = r
v.append(t)
return v