def spearman_similarity(A, B): m = maximum_distance(tree, script_tree.getRoot(tree)) #print m,A,B #print spearman_distance(m[0],m[1]),spearman_distance(A,B) #print (spearman_distance(m[0],m[1]) - spearman_distance(A,B))/(spearman_distance(m[0],m[1])) return (spearman_distance(m[0], m[1]) - spearman_distance(A, B)) / (spearman_distance(m[0], m[1]))
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 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 donnor_search(t, n): current_node = n result = -1 while result == -1 and not script_tree.isRoot(t, current_node): current_node = script_tree.getParent(t, current_node) annot = script_tree.getBootstrap(t, current_node) event = annot[1:].split(".")[0] if event[:2] != "T@" and event[:2] != "D@": result = event if annot.find("@T") >= 0: current_node = script_tree.getRoot(t) result = -1 return result
def donnor_search(t,n): current_node = n result = -1 while result == -1 and not script_tree.isRoot(t,current_node): current_node = script_tree.getParent(t,current_node) annot = script_tree.getBootstrap(t,current_node) event = annot[1:].split(".")[0] if event[:2] != "T@" and event[:2] != "D@": result = event if annot.find("@T") >= 0: current_node = script_tree.getRoot(t) result = -1 return result
def kendall_similarity(A, B): m = maximum_distance(tree, script_tree.getRoot(tree)) # print m # print kendall_distance(m[0],m[1]) , kendall_distance(A,B) return (kendall_distance(m[0], m[1]) - kendall_distance(A, B)) / (kendall_distance(m[0], m[1]))
elif words[0] == "ls": TIME_FOR_SEARCH = float(words[1]) elif words[0] == "d": MIN_TRANSFER_DIST = int(words[1]) elif words[0] == "rd": RANDOM = int(words[1]) elif words[0] == "ts": THRESHOLD_CONSTRAINTS = float(words[1]) else: print "unused parameter (bad format):", p name_constraint_file = parameters[1] tree = script_tree.readTree(open(parameters[0], "r").readline()) constraints = open(name_constraint_file, "r").readlines() root = script_tree.getRoot(tree) print name_constraint_file def maximum_spearman(n): if n % 2 == 0: m = n / 2 return 2 * m * m else: m = (n - 1) / 2 return 2 * m * m + 2 * m # def maximum_distance(tree,root):
elif words[0] == "r": RANDOM_TYPE = int(words[1]) elif words[0] == "ls": TIME_FOR_SEARCH = float(words[1]) elif words[0] == "d": MIN_TRANSFER_DIST = int(words[1]) elif words[0] == "rd": RANDOM = int(words[1]) elif words[0] == "ts": THRESHOLD_CONSTRAINTS = float(words[1]) else: print "unused parameter (bad format):",p tree = script_tree.readTree(open(parameters[0],"r").readline()) root = script_tree.getRoot(tree) tree1 = script_tree.readTree(open(parameters[0],"r").readline()) tree2 = script_tree.readTree(open(parameters[1],"r").readline()) root1 = script_tree.getRoot(tree1) root2 = script_tree.getRoot(tree2) def maximum_spearman(n): if n % 2 == 0: m = n /2 return 2 * m * m else: m = (n-1)/2
output_trf.write("#family,older,younger,support\n") for gt in gene_trees: file_rec = open(gt,"r").readlines() print gt, constraints_rec = {} constraints_trf = {} i = 0 while i < len(file_rec): words = file_rec[i].split() #print words,len(words) if len(words) > 1 and words[1] == "reconciled": number = int(words[0]) for j in range(i+2,i+2+number): #print file_rec[j] tree = script_tree.readTree(file_rec[j]) # one reconciliation root = script_tree.getRoot(tree) #annot = script_tree.getBootstrap(tree,root) #event = annot.split(".")[-1] #if event[:2] == "T@" or event[:2] == "D@": #origination = event[2:].split("->")[0] #else: #origination = event # detect origination species #nodes = script_tree.getNodes(species_tree) ##for n in nodes: #if script_tree.isLeaf(species_tree,n): #name = script_tree.getName(species_tree,n) #if name == origination: #species_under_origin = [name] #else: #name = script_tree.getBootstrap(species_tree,n) #if name == origination:
def kendall_similarity(A,B): m = maximum_distance(tree,script_tree.getRoot(tree)) #print m #print kendall_distance(m[0],m[1]) , kendall_distance(A,B) return (kendall_distance(m[0],m[1]) - kendall_distance(A,B))/(kendall_distance(m[0],m[1]))
def spearman_similarity(A,B): m = maximum_distance(tree,script_tree.getRoot(tree)) #print m,A,B #print spearman_distance(m[0],m[1]),spearman_distance(A,B) #print (spearman_distance(m[0],m[1]) - spearman_distance(A,B))/(spearman_distance(m[0],m[1])) return (spearman_distance(m[0],m[1]) - spearman_distance(A,B))/(spearman_distance(m[0],m[1]))