aditya shukla wrote:
I am puzzled why this class is inside the function and why -1 instead of
+1, but...
I presume each node gets an attribute 'distance_from_ root', so read that
attribute of whatever node.
Hello folks , i am using the newick module
http://www.daimi.au.dk/~mailund/newick.html.I am just learning to use it
and i have a question about it.
>
from newick.tree import parse_tree
from newick.tree import add_parent_link s
from newick.tree import add_distance_fr om_root
>
import sys
>
t = parse_tree('((A :2,B:3):1,C:6); ')
>
print t
>
deltas = add_distance_fr om_root(t)
>
now when i do this i can get the output like this
>
>
(('A' : 2.0, 'B' : 3.0) : 1.0, 'C' : 6.0)
None
>
This is the code of the add_distance_fr om_root(0
>
def add_distance_fr om_root(tree):
'''Extend all nodes with the distance (branch length) from the root'''
tree.distance_f rom_root = 0.0 # 'tree' is the root...
>
class V(TreeVisitor):
def pre_visit_edge( self,src,b,l,ds t):
if l is None: l = 0
dst.distance_fr om_root = src.distance_fr om_root - l
http://www.daimi.au.dk/~mailund/newick.html.I am just learning to use it
and i have a question about it.
>
from newick.tree import parse_tree
from newick.tree import add_parent_link s
from newick.tree import add_distance_fr om_root
>
import sys
>
t = parse_tree('((A :2,B:3):1,C:6); ')
>
print t
>
deltas = add_distance_fr om_root(t)
>
now when i do this i can get the output like this
>
>
(('A' : 2.0, 'B' : 3.0) : 1.0, 'C' : 6.0)
None
>
This is the code of the add_distance_fr om_root(0
>
def add_distance_fr om_root(tree):
'''Extend all nodes with the distance (branch length) from the root'''
tree.distance_f rom_root = 0.0 # 'tree' is the root...
>
class V(TreeVisitor):
def pre_visit_edge( self,src,b,l,ds t):
if l is None: l = 0
dst.distance_fr om_root = src.distance_fr om_root - l
+1, but...
tree.dfs_traver se(V())
>
From here it is clear that the function does not return anything but i
wanna get the value of the distance from root.How can i get this?
>
From here it is clear that the function does not return anything but i
wanna get the value of the distance from root.How can i get this?
attribute of whatever node.