binary tree compare nodes' feature from leaves to root python ete2 tools
I have a binary tree:
root
/ \
g h
/ \ / \
d a e f
/ \
b c
each node has 'seq' feature which stores the dna sequence of each node
('AACCGGT')
the sisters who are both leaves (b,c and e,f) have each one a score (float
) what I want is to :
compare score of leaf which has score with it's sister b.score with c.score
d.score = max (b.score,c.score)
same for e, f and h
compare a.seq with d.seq ==> d and e will have a score
g.score max (e.score, a.score) ... till arrive to the root NOte: every
leaf node has 'model feature' I compare b.seq with c.seq based on b.model
==>I got b.score then based on c.model ==> I got c.score I did some tries
:
def affect_score(n): if (n.score)==0:
n.score=affect_score(n.get_children()[0]) result=n.score if not
n.is_root(): sis=n.get_sisters()[0] else: sis=n if sis.score==0:
sis.score=affect_score(sis.get_children()[0]) if result
Can anyone helps me by telling what shall I do ? Note that It's my first
time working with tree data sturcture and recursion thanks in advance for
any suggestion
No comments:
Post a Comment