Esempio n. 1
0
def distance_from(x, y):
    nodes = script_tree.getNodes(species_tree)
    for n in nodes:
        if script_tree.isLeaf(species_tree, n):
            name = script_tree.getName(species_tree, n)
        else:
            name = script_tree.getBootstrap(species_tree, n)
        if name == x:
            A = n
        if name == y:
            B = n
    return script_tree.distanceFrom(species_tree, A, B)
def distance_from(x,y):
  nodes = script_tree.getNodes(species_tree)
  for n in nodes:
    if script_tree.isLeaf(species_tree,n):
      name = script_tree.getName(species_tree,n)
    else:
      name = script_tree.getBootstrap(species_tree,n)
    if name == x:
      A = n
    if name == y:
      B = n
  return script_tree.distanceFrom(species_tree,A,B)
def parent(x):
  #print x
  nodes = script_tree.getNodes(species_tree)
  for n in nodes:
    if script_tree.isLeaf(species_tree,n):
      name = script_tree.getName(species_tree,n)
    else:
      name = script_tree.getBootstrap(species_tree,n)
    if name == x:
      if script_tree.isRoot(species_tree,n):
	result = -1
      else:
	result = script_tree.getBootstrap(species_tree,script_tree.getParent(species_tree,n))
  return result
Esempio n. 4
0
def parent(x):
    #print x
    nodes = script_tree.getNodes(species_tree)
    for n in nodes:
        if script_tree.isLeaf(species_tree, n):
            name = script_tree.getName(species_tree, n)
        else:
            name = script_tree.getBootstrap(species_tree, n)
        if name == x:
            if script_tree.isRoot(species_tree, n):
                result = -1
            else:
                result = script_tree.getBootstrap(
                    species_tree, script_tree.getParent(species_tree, n))
    return result
Esempio n. 5
0
graph = {}
nodes = script_tree.getNodes(tree)
leaves = script_tree.getLeavesNames(tree)
root = script_tree.getRoot(tree)
# rootname = script_tree.getBootstrap(tree,root)
internal_nodes = []

# initialise from nodes
for n in nodes:
    if (not script_tree.isLeaf(tree, n)):
        node = script_tree.getBootstrap(tree, n)
        graph[node] = []
        degre_entrant[node] = []
        internal_nodes.append(node)
    else:
        node = script_tree.getName(tree, n)
        graph[node] = []

print
"tree with ", len(internal_nodes), "internal nodes"

# parse transfers
# by_family = {}
for line in constraints:
    # print line
    if (len(line.split()) >= 2 or len(line.split(",")) >= 2) and line.find("FRQ") < 0 and line[0] != "#":
        # print line
        # compute first and second, the donnor and receptor
        if line.find(",") >= 0:
            words = line.strip().split(",")
            words = words[1:]
Esempio n. 6
0
 #species_under_origin.append(script_tree.getName(species_tree,l))
 leaves = script_tree.getLeaves(tree, root)
 #species_present = []
 #for l in leaves:
 #if script_tree.getName(tree,l).split("_")[0] not in species_present:
 #species_present.append(script_tree.getName(tree,l).split("_")[0])
 if len(
         leaves
 ) > MINIMUM_FAMILY_SIZE:  # and difference_symetrique(species_present,species_under_origin) < MAXIMUM_DIFFERENCE_WITH_PROFILE:
     #print script_tree.writeTree(tree,root,False)
     #print origination,len(leaves),len(species_present),len(species_under_origin),
     #output_distr.write(str(difference_symetrique(species_present,species_under_origin))+"\n")
     nodes = script_tree.getNodes(tree)
     for n in nodes:
         if script_tree.isLeaf(tree, n):
             annot = script_tree.getName(tree, n)
         else:
             annot = script_tree.getBootstrap(tree, n)
         #if script_tree.isLeaf(tree,n) and annot.find("T")>=0:
         #print annot
         # annot: evenement
         events = annot.split(".")
         if events[0] == "":
             del events[0]
         for e in events:
             if e[:2] == "T@":
                 # on a touve un transfert
                 #print e
                 donnor = e[2:].split("->")[0]
                 receptor = e[2:].split("->")[1]
                 #print annot,donnor,receptor
	      #species_under_origin = []
	      #for l in leaves:
		#species_under_origin.append(script_tree.getName(species_tree,l))
	leaves = script_tree.getLeaves(tree,root)
	#species_present = []
	#for l in leaves:
	  #if script_tree.getName(tree,l).split("_")[0] not in species_present:
	    #species_present.append(script_tree.getName(tree,l).split("_")[0])
	if len(leaves) > MINIMUM_FAMILY_SIZE:# and difference_symetrique(species_present,species_under_origin) < MAXIMUM_DIFFERENCE_WITH_PROFILE:
	  #print script_tree.writeTree(tree,root,False)
	  #print origination,len(leaves),len(species_present),len(species_under_origin),
	  #output_distr.write(str(difference_symetrique(species_present,species_under_origin))+"\n")
	  nodes = script_tree.getNodes(tree)
	  for n in nodes:
	    if script_tree.isLeaf(tree,n):
	      annot = script_tree.getName(tree,n)
	    else:
	      annot = script_tree.getBootstrap(tree,n)
	    #if script_tree.isLeaf(tree,n) and annot.find("T")>=0:
	      #print annot
	    # annot: evenement
	    events = annot.split(".")
	    if events[0] == "":
	      del events[0]
	    for e in events:
	      if e[:2] == "T@":
		# on a touve un transfert
		#print e
		donnor = e[2:].split("->")[0]
		receptor = e[2:].split("->")[1]
		#print annot,donnor,receptor
Esempio n. 8
0
edge = {}
graph = {}
nodes = script_tree.getNodes(tree)
leaves = script_tree.getLeavesNames(tree)
root = script_tree.getRoot(tree)
internal_nodes = []

# initialise from nodes
for n in nodes:
  if (not script_tree.isLeaf(tree,n)):
    node = script_tree.getBootstrap(tree,n)
    graph[node] = []
    degre_entrant[node] = []
    internal_nodes.append(node)
  else:
    node = script_tree.getName(tree,n)
    graph[node] = []

# initialise from branches
for n in nodes:
  if (not script_tree.isLeaf(tree,n)):
    if (not script_tree.isRoot(tree,n)):
      parent = script_tree.getBootstrap(tree,script_tree.getParent(tree,n))
      child = script_tree.getBootstrap(tree,n)
      graph[parent].append(child)
      edge[parent+","+child] = MAX_NUMBER
  else:
    parent = script_tree.getBootstrap(tree,script_tree.getParent(tree,n))
    child = script_tree.getName(tree,n)
    graph[parent].append(child)