Example #1
0
def maximum_distance(tree, root):
    c1 = script_tree.getChildren(tree, root)[0]
    c2 = script_tree.getChildren(tree, root)[1]
    name = script_tree.getBootstrap(tree, root)
    if script_tree.isLeaf(tree, c1) and script_tree.isLeaf(tree, c2):
        return [[name], [name]]
    elif script_tree.isLeaf(tree, c1):
        oo = maximum_distance(tree, c2)
        return [[name] + oo[0], [name] + oo[1]]
    elif script_tree.isLeaf(tree, c2):
        oo = maximum_distance(tree, c1)
        return [[name] + oo[0], [name] + oo[1]]
    else:
        orders1 = maximum_distance(tree, c1)
        orders2 = maximum_distance(tree, c2)
        return [[name] + orders1[0] + orders2[0], [name] + orders2[1] + orders1[1]]
Example #2
0
File: MaxTiC.py Project: ssolo/ALE
def maximum_distance(tree,root):
  c1 = script_tree.getChildren(tree,root)[0]
  c2 = script_tree.getChildren(tree,root)[1]
  name = script_tree.getBootstrap(tree,root)
  if script_tree.isLeaf(tree,c1) and script_tree.isLeaf(tree,c2):
    return [[name],[name]]
  elif script_tree.isLeaf(tree,c1):
    oo = maximum_distance(tree,c2)
    return [[name] + oo[0],[name] + oo[1]]
  elif script_tree.isLeaf(tree,c2):
    oo = maximum_distance(tree,c1)
    return [[name] + oo[0],[name] + oo[1]]
  else:
    orders1 = maximum_distance(tree,c1)
    orders2 = maximum_distance(tree,c2)
    return [[name] + orders1[0] + orders2[0],[name] + orders2[1] + orders1[1]]
Example #3
0
def opt(tree, root):
    if (script_tree.isLeaf(tree, script_tree.getChildren(tree, root)[0]) and
            script_tree.isLeaf(tree, script_tree.getChildren(tree, root)[1])):
        return [script_tree.getBootstrap(tree, root)]
    elif script_tree.isLeaf(tree, script_tree.getChildren(tree, root)[0]):
        return opt(tree, script_tree.getChildren(tree, root)[1]) + [script_tree.getBootstrap(tree, root)]
    elif script_tree.isLeaf(tree, script_tree.getChildren(tree, root)[1]):
        return opt(tree, script_tree.getChildren(tree, root)[0]) + [script_tree.getBootstrap(tree, root)]
    else:
        order1 = opt(tree, script_tree.getChildren(tree, root)[0])
        order2 = opt(tree, script_tree.getChildren(tree, root)[1])
        # print "level",len(order1)+len(order2),order1,order2
        return mix(order1, order2) + [script_tree.getBootstrap(tree, root)]
Example #4
0
def opt(tree,root):
  if (script_tree.isLeaf(tree,script_tree.getChildren(tree,root)[0]) and
      script_tree.isLeaf(tree,script_tree.getChildren(tree,root)[1])):
    return [script_tree.getBootstrap(tree,root)]
  elif script_tree.isLeaf(tree,script_tree.getChildren(tree,root)[0]):
    return opt(tree,script_tree.getChildren(tree,root)[1])+[script_tree.getBootstrap(tree,root)]
  elif script_tree.isLeaf(tree,script_tree.getChildren(tree,root)[1]):
    return opt(tree,script_tree.getChildren(tree,root)[0])+[script_tree.getBootstrap(tree,root)]
  else:
    order1 = opt(tree,script_tree.getChildren(tree,root)[0])
    order2 = opt(tree,script_tree.getChildren(tree,root)[1])
    #print "level",len(order1)+len(order2),order1,order2
    return mix(order1,order2) + [script_tree.getBootstrap(tree,root)]
def receptor_search(t,n):
  if script_tree.isLeaf(t,n):
    result = []
  else:
    annot = script_tree.getBootstrap(t,n)
    if annot.find("T@") >= 0:
      result = []
    elif annot.split(".")[1][:2] == "D@":
      children = script_tree.getChildren(t,n)
      result = receptor_search(t,children[0]) + receptor_search(t,children[1])
    else:
      result = [annot.split(".")[1]]
  #print result
  return result
Example #6
0
def random_order(tree, root):
    c1 = script_tree.getChildren(tree, root)[0]
    c2 = script_tree.getChildren(tree, root)[1]
    name = script_tree.getBootstrap(tree, root)
    if script_tree.isLeaf(tree, c1) and script_tree.isLeaf(tree, c2):
        return [name]
    elif script_tree.isLeaf(tree, c1):
        return [name] + random_order(tree, c2)
    elif script_tree.isLeaf(tree, c2):
        return [name] + random_order(tree, c1)
    else:
        order1 = random_order(tree, c1)
        order2 = random_order(tree, c2)
        # if script_tree.isRoot(tree,root):
        # print order1,order2
        pos = range(len(order1) + len(order2))
        for i in range(len(order2)):
            index = int(random.random() * (len(pos)))
            del pos[index]
        # if script_tree.isRoot(tree,root):
        # print pos
        order = [name]
        previous = 0
        for i in pos:
            for j in range(i - previous):
                # if script_tree.isRoot(tree,root):
                # print order2,i,previous
                order.append(order2[0])
                del order2[0]
            order.append(order1[0])
            del order1[0]
            previous = i + 1

        # if script_tree.isRoot(tree,root):
        # print order1,order2,order
        return order + order2
Example #7
0
def receptor_search(t, n):
    if script_tree.isLeaf(t, n):
        result = []
    else:
        annot = script_tree.getBootstrap(t, n)
        if annot.find("T@") >= 0:
            result = []
        elif annot.split(".")[1][:2] == "D@":
            children = script_tree.getChildren(t, n)
            result = receptor_search(t, children[0]) + receptor_search(
                t, children[1])
        else:
            result = [annot.split(".")[1]]
    #print result
    return result
Example #8
0
def random_order(tree,root):
  c1 = script_tree.getChildren(tree,root)[0]
  c2 = script_tree.getChildren(tree,root)[1]
  name = script_tree.getBootstrap(tree,root)
  if script_tree.isLeaf(tree,c1) and script_tree.isLeaf(tree,c2):
    return [name]
  elif script_tree.isLeaf(tree,c1):
    return [name] + random_order(tree,c2)
  elif script_tree.isLeaf(tree,c2):
    return [name] + random_order(tree,c1)
  else:
    order1 = random_order(tree,c1)
    order2 = random_order(tree,c2)
    #if script_tree.isRoot(tree,root):
      #print order1,order2
    pos = range(len(order1)+len(order2))
    for i in range(len(order2)):
      index = int(random.random()*(len(pos)))
      del pos[index]
    #if script_tree.isRoot(tree,root):
      #print pos
    order = [name]
    previous = 0
    for i in pos:
      for j in range(i - previous):
	#if script_tree.isRoot(tree,root):
	  #print order2,i,previous
	order.append(order2[0])
	del order2[0]
      order.append(order1[0])
      del order1[0]
      previous = i+1
	
    #if script_tree.isRoot(tree,root):
      #print order1,order2,order
    return order + order2
Example #9
0
         parent(donnor)) + "," + str(receptor)
     if not constraints_trf.has_key(c):
         constraints_trf[c] = 0
     constraints_trf[c] = constraints_trf[c] + 1
 # 2/ calculer la contrainte selon les reconciliations
 if script_tree.isLeaf(tree, n):
     receptor = []
 else:
     if events[0][:2] != "T@":
         if events[0][:2] == "D@":
             species = events[0][2:]
         else:
             species = events[0]
         receptor = [species]
     else:
         children = script_tree.getChildren(
             tree, n)
         child1 = children[0]
         if script_tree.isLeaf(tree, child1):
             annot_child1 = script_tree.getName(
                 tree, child1).split(
                     ".")[-1].split("_")[0]
         else:
             annot_child1 = script_tree.getBootstrap(
                 tree, child1).split(".")[-1]
         if annot_child1[:2] == "T@":
             annot_child1 = annot_child1[
                 2:].split("->")[0]
         if annot_child1[:2] == "D@":
             annot_child1 = annot_child1[2:]
         child2 = children[1]
         if script_tree.isLeaf(tree, child2):
		  c = str(parent(donnor))+","+str(receptor)
		  if not constraints_trf.has_key(c):
		    constraints_trf[c] = 0
		  constraints_trf[c] = constraints_trf[c] + 1
		# 2/ calculer la contrainte selon les reconciliations  
		if script_tree.isLeaf(tree,n):
		  receptor = []
		else:
		  if events[0][:2] != "T@":
		    if events[0][:2] == "D@":
		      species = events[0][2:]
		    else:
		      species = events[0]
		    receptor = [species]
		  else:
		    children = script_tree.getChildren(tree,n)
		    child1 = children[0]
		    if script_tree.isLeaf(tree,child1):
		      annot_child1 = script_tree.getName(tree,child1).split(".")[-1].split("_")[0]
		    else:
		      annot_child1 = script_tree.getBootstrap(tree,child1).split(".")[-1]
		    if annot_child1[:2] == "T@":
		      annot_child1 = annot_child1[2:].split("->")[0]
		    if annot_child1[:2] == "D@":
		      annot_child1 = annot_child1[2:]
		    child2 = children[1]
		    if script_tree.isLeaf(tree,child2):
		      annot_child2 = script_tree.getName(tree,child2).split(".")[-1].split("_")[0]
		    else:
		      annot_child2 = script_tree.getBootstrap(tree,child2).split(".")[-1]
		    if annot_child2[:2] == "T@":