def tree_from_order(order): nodes = script_tree.getNodes(tree) for n in nodes: if not script_tree.isRoot(tree, n): if script_tree.isLeaf(tree, n): index = len(order) else: index = order.index(script_tree.getBootstrap(tree, n)) index_parent = order.index(script_tree.getBootstrap(tree, script_tree.getParent(tree, n))) script_tree.setLength(tree, n, index - index_parent) return script_tree.writeTree(tree, root, False)
def order_from_tree(tree): order = [] nodes = script_tree.getNodes(tree) root = script_tree.getRoot(tree) for n in nodes: if not script_tree.isLeaf(tree, n): order.append(n) # print order order.sort(lambda x, y: cmp(script_tree.distanceFrom(tree, x, root), script_tree.distanceFrom(tree, y, root))) for i in range(len(order)): order[i] = script_tree.getBootstrap(tree, order[i]) return order
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 order_from_tree(tree): order = [] nodes = script_tree.getNodes(tree) root = script_tree.getRoot(tree) for n in nodes: if not script_tree.isLeaf(tree,n): order.append(n) #print order order.sort(lambda x,y: cmp(script_tree.distanceFrom(tree,x,root),script_tree.distanceFrom(tree,y,root))) for i in range(len(order)): order[i] = script_tree.getBootstrap(tree,order[i]) return order
def tree_from_order(order): nodes = script_tree.getNodes(tree) for n in nodes: if not script_tree.isRoot(tree,n): if script_tree.isLeaf(tree,n): index = len(order) else: index = order.index(script_tree.getBootstrap(tree,n)) index_parent = order.index(script_tree.getBootstrap(tree,script_tree.getParent(tree,n))) script_tree.setLength(tree,n,index-index_parent) return script_tree.writeTree(tree,root,False)
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
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
root = script_tree.getRoot(tree) for n in nodes: if not script_tree.isLeaf(tree, n): order.append(n) # print order order.sort(lambda x, y: cmp(script_tree.distanceFrom(tree, x, root), script_tree.distanceFrom(tree, y, root))) for i in range(len(order)): order[i] = script_tree.getBootstrap(tree, order[i]) return order # useful variables degre_entrant = {} edge = {} 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] = []
def order_from_tree(tree): order = [] nodes = script_tree.getNodes(tree) root = script_tree.getRoot(tree) for n in nodes: if not script_tree.isLeaf(tree,n): order.append(n) #print order order.sort(lambda x,y: cmp(script_tree.distanceFrom(tree,x,root),script_tree.distanceFrom(tree,y,root))) for i in range(len(order)): order[i] = script_tree.getBootstrap(tree,order[i]) return order # useful variables nodes1 = script_tree.getNodes(tree1) leaves1 = script_tree.getLeavesNames(tree1) root1 = script_tree.getRoot(tree1) internal_nodes1 = [] nodes2 = script_tree.getNodes(tree2) leaves2 = script_tree.getLeavesNames(tree2) root2 = script_tree.getRoot(tree2) internal_nodes2 = [] order_input1 = order_from_tree(tree1) order_input2 = order_from_tree(tree2) #value_input = value(order_input)
MINIMUM_SUPPORT_WITHIN_A_FAMILY = 0.05 MINIMUM_FAMILY_SIZE = 5 #MAXIMUM_DIFFERENCE_WITH_PROFILE = 6000 OUTPUT_FILE_REC = "constraints_from_recs" OUTPUT_FILE_TRF = "constraints_from_transfers" parameters = sys.argv[1:] species_tree = script_tree.readTree(open(parameters[0], "r").readline()) extant_species = script_tree.getLeavesNames(species_tree) gene_tree_file = parameters[1] gene_trees = [] for gt in open(gene_tree_file, "r").readlines(): gene_trees.append(gt.strip()) nodes = script_tree.getNodes(species_tree) for n in nodes: script_tree.setLength(species_tree, 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
MINIMUM_SUPPORT_WITHIN_A_FAMILY = 0.05 MINIMUM_FAMILY_SIZE = 5 #MAXIMUM_DIFFERENCE_WITH_PROFILE = 6000 OUTPUT_FILE_REC = "constraints_from_recs" OUTPUT_FILE_TRF = "constraints_from_transfers" parameters = sys.argv[1:] species_tree = script_tree.readTree(open(parameters[0],"r").readline()) extant_species = script_tree.getLeavesNames(species_tree) gene_tree_file = parameters[1] gene_trees = [] for gt in open(gene_tree_file,"r").readlines(): gene_trees.append(gt.strip()) nodes = script_tree.getNodes(species_tree) for n in nodes: script_tree.setLength(species_tree,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:
nodes = script_tree.getNodes(tree) root = script_tree.getRoot(tree) for n in nodes: if not script_tree.isLeaf(tree,n): order.append(n) #print order order.sort(lambda x,y: cmp(script_tree.distanceFrom(tree,x,root),script_tree.distanceFrom(tree,y,root))) for i in range(len(order)): order[i] = script_tree.getBootstrap(tree,order[i]) return order # useful variables degre_entrant = {} 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] = []