def main(arg1, arg2): with open(arg1) as f: content = f.readlines() # you may also want to remove whitespace characters like `\n` at the end of each line content = [x.strip() for x in content] t2 = Tree(content[0]) ###print(t2) triplets = [] taxa = [] for i in range(0, len(content)): t1 = Tree(content[i]) leaves, triplets = tp.triplet_decompose(t1, triplets) t2 = Tree(content[i]) ###print(t2) taxa += leaves ###print(triplets) triplets_dict = defaultdict(list) for t in triplets: trip_key = [t[1][0], t[1][1], t[0]] trip_key.sort() trip_key = str(trip_key).strip('[]') trip_key = trip_key.replace("'", '') trip_key = trip_key.replace(" ", "") if (t in triplets_dict[trip_key]) is False: triplets_dict[trip_key].append(t) ###print(triplets_dict) Cpc = physic_pc(list(set(taxa)), triplets, triplets_dict)
def main(arg1, arg2): with open(arg1) as f: content = f.readlines() # you may also want to remove whitespace characters like `\n` at the end of each line content = [x.strip() for x in content] t2=Tree(content[0]) ####print(t2) triplets=[] taxa=[] good=[] bad=[] for i in range(1,len(content)): t1=Tree(content[i]) ####print(t1) leaves,triplets=tp.triplet_decompose(t1,triplets) #t2=Tree(content[i]) ####print(t2) taxa+=leaves Super_triplet=[] t2=content[0] Super_leaves,Supers_triplets=tp.main(t2,Super_triplet) R_pi=intersection(triplets,Super_triplet) final_tree=check_pi(R_pi,Tree(t2)) ###print("final ishhhhhh: --",final_tree) #main("test1.txt",2)
def main(arg1, arg2): with open(arg1) as f: content = f.readlines() # you may also want to remove whitespace characters like `\n` at the end of each line content = [x.strip() for x in content] t2=Tree(content[0]) ###print(t2) triplets=[] taxa=[] for i in range(0,len(content)): t1=Tree(content[i]) leaves,triplets=tp.triplet_decompose(t1,triplets) t2=Tree(content[i]) ###print(t2) taxa+=leaves ###print(triplets) triplets_dict=defaultdict(list) for t in triplets: trip_key=[t[1][0],t[1][1],t[0]] trip_key.sort() trip_key=str(trip_key).strip('[]') trip_key=trip_key.replace("'", '') trip_key=trip_key.replace(" ", "") if (t in triplets_dict[trip_key]) is False : triplets_dict[trip_key].append(t) ###print(triplets_dict) Cpc=pc.physic_pc(list(set(taxa)),triplets,triplets_dict) #print(Cpc) '''Super_triplet=[] #t2=content[0] Super_leaves,Supers_triplets=tp.triplet_decompose(Cpc,Super_triplet) R_pi=intersection(triplets,Super_triplet) print(R_pi) final_tree=pi.check_pi(Cpc,R_pi) #print("final is: --",final_tree)''' return Cpc
def main(arg1, arg2): with open(arg1) as f: content = f.readlines() content = [x.strip() for x in content] t2 = Tree(content[0]) #print(t2) triplets = [] taxa = [] for i in range(0, len(content)): t1 = Tree(content[i]) t1.resolve_polytomy() leaves, triplets = tp.triplet_decompose(t1, triplets) #t2=Tree(content[i]) #print(t2) taxa += leaves #print(set(taxa)) Cpc = build(list(set(taxa)), triplets) #print(Cpc) Cpc.show() return Cpc
def main(arg1, arg2): with open(arg1) as f: content = f.readlines() triplets = [] taxa = [] good = [] bad = [] for i in range(0, len(content)): #####print(i) t1 = Tree(content[i]) t1.resolve_polytomy() #####print(t1.write(format=9)) leaves, triplets = tp.triplet_decompose(t1, triplets) #t2=Tree(content[i]) #####print(t2) #####print(triplets) taxa += leaves taxa_com = set(taxa) #####print(triplets) d = {ni: indi for indi, ni in enumerate(taxa)} rows, cols = (len(taxa), len(taxa)) triplets_dict = defaultdict(list) for t in triplets: trip_key = [t[1][0], t[1][1], t[0]] trip_key.sort() trip_key = str(trip_key).strip('[]') trip_key = trip_key.replace("'", '') trip_key = trip_key.replace(" ", "") if (t in triplets_dict[trip_key]) is False: triplets_dict[trip_key].append(t) #t2=MaxCut.main(arg1, arg2) t2, overlap_per1, inconsist_per1, triplets_dict1 = MaxCut.main(arg1, 2) print( "-------------------------------------bulid-------------------------------------------------" ) trees = [] t2.show() for node in t2.traverse("postorder"): children_node = node.get_children() if len(children_node) > 2: trees += children_node trees.append(t2) #print(trees) taxa = [] dict_leaves = {} for i in range(len(trees)): c = trees[i] c.detach() for leaves in c: if leaves.name != '': dict_leaves[leaves.name] = i taxa.append(leaves.name) newick_supertrees = [] ###print("last tree",trees[len(trees)-1]) with open(arg1) as f: content = f.readlines() # you may also want to remove whitespace characters like `\n` at the end of each line content = [x.strip() for x in content] t2 = Tree(content[0]) for i in range(0, len(content) - 2): t1 = Tree(content[i + 1]) t1.resolve_polytomy() for leaves in t1: leaves.name = "leaf" + str(dict_leaves[leaves.name]) for i in range(len(trees)): current_leaf_set = t1.search_nodes(name="leaf" + str(i)) #####print(current_leaf_set) if len(current_leaf_set) > 1: for j in range(1, len(current_leaf_set)): current_leaf_set[j].delete() newick_supertrees.append(t1.write(format=9)) #####print(newick_supertrees) trees_structure, overlap_per1, inconsist_per1, triplets_dict1 = MaxCut.main( newick_supertrees, 1) #####print("------------structure-------------") #####print(overlap_per,inconsist_per) #####print(trees_structure) for i in range(len(trees)): node_add = trees_structure.search_nodes(name="leaf" + str(i)) if len(node_add) > 0: node_add = node_add[0] node_add_parent = node_add.up ###print(trees[i]) node_add_parent.add_child(trees[i]) node_add.detach() taxa = set(taxa) final_taxa = [] for nodes in trees_structure: if nodes.is_leaf(): if nodes.name != '': final_taxa.append(nodes.name) trees_structure.prune(final_taxa) trees_structure.show() supertree_triplets = [] ST_triplets_dict = defaultdict(list) st_leaves, supertree_triplets, ST_triplets_dict = tp_d.triplet_decompose( trees_structure, supertree_triplets, ST_triplets_dict) total = 1 #triplets_dict=defaultdict(list) overlap = 0 inconsist = 0 for keys in triplets_dict: overlap += len( intersection(triplets_dict[keys], ST_triplets_dict[keys])) total += len(triplets_dict[keys]) if len(triplets_dict[keys]) > 1: inconsist += len(triplets_dict[keys]) overlap_per = overlap / total inconsist_per = inconsist / total #####print(taxa_com) ##print(trees_structure) return trees_structure, overlap_per, inconsist_per
def main(arg1, arg2): if arg2 == 2: with open(arg1) as f: content = f.readlines() else: content = arg1 ####print(content) # you may also want to remove whitespace characters like `\n` at the end of each line #content = [x.strip() for x in content] t2 = Tree(content[0]) #print(t2) triplets = [] taxa = [] good = [] bad = [] for i in range(0, len(content)): ####print(i) t1 = Tree(content[i]) #t1.show() ###print(t1.write(format=9)) t1.resolve_polytomy() for leaf in t1: if leaf.is_leaf() is True: taxa.append(leaf.name) leaves, triplets = tp.triplet_decompose(t1, triplets) #print("leaves",leaves) #t2=Tree(content[i]) ####print(triplets) #taxa+=leaves taxa = set(taxa) #print(triplets) #print("taxa",taxa) d = {ni: indi for indi, ni in enumerate(taxa)} rows, cols = (len(taxa), len(taxa)) triplets_dict = defaultdict(list) for t in triplets: trip_key = [t[1][0], t[1][1], t[0]] trip_key.sort() trip_key = str(trip_key).strip('[]') trip_key = trip_key.replace("'", '') trip_key = trip_key.replace(" ", "") if (t in triplets_dict[trip_key]) is False: triplets_dict[trip_key].append(t) #print(triplets_dict) ####print(good) ####print(bad) ####print(clades) ####print("__________________________________________________________") ####print(outgroup) #g = Graph(connections, outgroup, good, bad, directed=True) ####print(g._graph_good) ####print(g._weights) #triplets_dict=defaultdict(list) supertree = Max_cut(taxa, triplets_dict) #print("supertree",supertree) #supertree.show() '''supertree_triplets=[] ST_triplets_dict=defaultdict(list) st_leaves,supertree_triplets,ST_triplets_dict=tp_d.triplet_decompose(supertree,supertree_triplets,ST_triplets_dict) total=1 overlap=0 inconsist=0 for keys in triplets_dict: overlap += len(intersection(triplets_dict[keys],ST_triplets_dict[keys])) total+=len(triplets_dict[keys]) if len(triplets_dict[keys])>1: inconsist+=len(triplets_dict[keys]) overlap_per=overlap/total inconsist_per=inconsist/total #t2=Tree("((ah, ((ae, ab), ai)), ((ag, aa), (ac, (ad, (aj, af)))));") ####print(t2) #triplet_test.main(arg1,supertree,True,25) ##print(supertree)''' return supertree, 0, 0, triplets_dict