[BioPython] Node problem

Ernesto e.picardi at unical.it
Fri Nov 5 07:24:12 EST 2004


Hi all,
I have a list of nodes such as:

Nodo1=Nodo("A",0.1,None,None,1)
Nodo2=Nodo("B",0.2,None,None,1)
Nodo3=Nodo("C",0.3,None,None,1)
Nodo4=Nodo("D",0.4,None,None,1)
Nodo6=Nodo("nodo6",0.2,Nodo1,Nodo2,0)
Nodo7=Nodo("nodo7",0.3,Nodo3,Nodo4,0)
Nodo8=Nodo("nodo8",0.1,Nodo6,Nodo7,0)
Nodo5=Nodo("E",0.5,None,None,1)
Nodo9=Nodo("Root",None,Nodo8,Nodo5,None).

where Nodo9 is the root. I would to substitute each node with its specific value starting from the root, in order to obtain a tree like the following:

Tree=Nodo(9,None,Nodo(8,0.01,Nodo(6,0.01,Nodo(1,0.01,None,None,1),Nodo(2,0.01,None,None,1),0),Nodo(7,0.01,Nodo(3,0.01,None,None,1),Nodo(4,0.01,None,None,1),0),0),Nodo(5,0.01,None,None,1),None)

Main difficulty is that the value of each node is an istance according to the following class:

class Nodo:
    '''definisci la struttura del nodo'''
    def __init__(self, contenuto, br=None, sinistra=None, destra=None, tip=None,seq=None):
        self.c = contenuto       #  node name
 self.b = br              # branch length
        self.s = sinistra         # left
        self.d = destra      # rigth
 self.t = tip         # is 1 for a tip or 0 for other nodes
 self.seq = seq



Could you suggest me how I could obtain Tree? I could use the recursion but I don't know.

Thank in advance for your help

Ernesto 


More information about the BioPython mailing list