def showTreeWithPictures(tree = None, alignment=None, branchLengths=True, bootstrapSupport=True, tolabel=None): print("ShowTreeWithPictures",tree, alignment, branchLengths,bootstrapSupport, tolabel) if alignment: t = EvolTree(tree, alignment,alg_format="paml") t.link_to_alignment(alignment,alg_format="paml") else: t = EvolTree(tree) nsFG = NodeStyle() nsFG["fgcolor"] = "darkgreen" nsFG["size"] = 8 for node in t.traverse(): print(node.node_id) if tolabel: if str(node.node_id) in tolabel: node.set_style(nsFG) ts = TreeStyle() ts.show_leaf_name = True ts.show_branch_length = branchLengths ts.show_branch_support = bootstrapSupport out = FILE if branchLengths: out+="_Len" if bootstrapSupport: out+="_Boot" t.render(out+"_tree.pdf",tree_style=ts) t.render(out+"_tree.png",tree_style=ts) if INTERACTIVE: t.show(tree_style=ts)
def showAlignmentWithTree(unlabelledTreeAsString,alignment): t = EvolTree(unlabelledTreeAsString, alignment,alg_format="paml") t.link_to_alignment(alignment, alg_format="paml") for node in t.traverse(): print(node) print(node.node_id, node.name) print(t.write()) #print(t) t.show() #layout=evol_clean_layout)
def showTreeWithPictures(tree = None, alignment=None, branchLengths=True, bootstrapSupport=True, tolabel=None,showZScores=False,showLogs=False ): print(PICS) print("ShowTreeWithPictures",tree, alignment, branchLengths,bootstrapSupport, tolabel,showZScores,showLogs ) if not alignment: nsFG = NodeStyle() nsFG["fgcolor"] = "darkgreen" nsFG["size"] = 8 t = EvolTree(tree) #todo:label # for node in t.traverse(): print(node.node_id) if tolabel: if str(node.node_id) in tolabel: node.set_style(nsFG) #q'n'd if (node.name.split("_")[0]+".png" in PICS): print(node.name.split("_")[0]+".png") node.add_face(ImgFace(PICDIR+os.sep+node.name.split("_")[0]+".png", height=50), column=1, position="aligned") #non GRZM identifier elif (node.name+".png" in PICS): print(node.name+".png") node.add_face(ImgFace(PICDIR+os.sep+node.name+".png", height=50), column=1, position="aligned") ts = TreeStyle() ts.show_leaf_name = True ts.show_branch_length = branchLengths ts.show_branch_support = bootstrapSupport out = FILE if branchLengths: out+="_Len" if bootstrapSupport: out+="_Boot" if Z: out+="_Z" if L: out+="_L" t.render(out+"_tree.pdf",tree_style=ts) t.render(out+"_tree.png",tree_style=ts) if INTERACTIVE: t.show(tree_style=ts) else: t = EvolTree(tree, alignment,alg_format="paml") t.link_to_alignment(alignment,alg_format="paml") #todo label #todo check treestyle #ts = TreeStyle() #ts.show_leaf_name = True #ts.show_branch_length = branchLength #ts.show_branch_support = bootstrapSupport t.show()
def showTreeNodes(unlabelledTreeAsString): t = EvolTree(unlabelledTreeAsString) for node in t.traverse(): #print(node) #print(node.node_id, node.name) #if (node.name.split("_")[0] in GENES): # print(node.name, node.node_id) leaves = node.get_leaf_names() #leaves = [l for l in leaves if l.split("_")[0] in GENES ] if leaves !=[]: print(node) print(leaves, node.name, node.node_id) print("\n")
def showAlignmentWithTree(unlabelledTreeAsString,alignment): t = EvolTree(unlabelledTreeAsString, alignment,alg_format="paml") #print(t) #t.run_model ('fb.example') # t.show() t.link_to_alignment(alignment, alg_format="paml") for node in t.traverse(): print(node) print(node.node_id, node.name) #t.mark_tree([8], marks=["#1"]) #print(t.write()) print(alignment) #print(t) t.show() #layout=evol_clean_layout)
def showAlignmentWithTree(tree,alignment): print(tree) t = EvolTree(tree, alignment,alg_format="paml") nsFG = NodeStyle() nsFG["fgcolor"] = "darkgreen" nsFG["size"] = 15 #print(t) #t.run_model ('fb.example') # t.show() t.link_to_alignment(alignment, alg_format="paml") for node in t.traverse(): print(node) #if (node.name.split("_")[0] in GENES): # print(node.name, node.node_id) # if (node.name.split("_")[0] == "GRMZM2G083841"): # node.add_face(ImgFace("83841.1.png", height=50, width=50), column=1, position="aligned") # if (node.name.split("_")[0] == "GRMZM2G473001"): # node.add_face(ImgFace("473001.png", height=50, width=50), column=1, position="aligned") node.add_face(TextFace(str(node.node_id)),column=0) #node.add_face(ImgFace("tux.png", height=50), column=1) # node.set_style(nsFG) leaves = node.get_leaf_names() #leaves = [l for l in leaves if l.split("_")[0] in GENES ] if leaves !=[]: print(node.name, node.node_id) #print(node.node_id) #t.mark_tree([8], marks=["#1"]) #print(t.write()) #print(alignment) #print(t) #t.show() #layout=evol_clean_layout) ts = TreeStyle() ts.show_leaf_name = True ts.show_branch_length = True ts.show_branch_support = True t = fakeUnroot(t) t.show(tree_style=ts) t.render("tree.pdf", tree_style=ts)
def showTreeNodes(unlabelledTreeAsString): t = EvolTree(unlabelledTreeAsString) for node in t.traverse(): print(node) print(node.node_id, node.name)
tree = EvolTree ("data/S_example/measuring_S_tree.nw") tree.link_to_alignment ('data/S_example/alignment_S_measuring_evol.fasta') print tree print 'Tree and alignment loaded.' raw_input ('Tree will be mark in order to contrast Gorilla and Chimpanzee as foreground \nspecies.') marks = ['1', 3, '7'] tree.mark_tree (marks, ['#1'] * 3) print tree.write () # display marked branches in orange for node in tree.traverse (): if not hasattr (node, 'mark'): continue if node.mark == '': continue node.img_style = NodeStyle() node.img_style ['bgcolor'] = '#ffaa00' tree.show() print '''now running branch-site models C and D that represents the addition of one class of sites in on specific branch. These models must be compared to null models M1 and M3. if branch-site models are detected to be significantly better, than, one class of site is evolving at different rate in the marked clade.
def labelForPamlRegex(unlabelledTreeAsString, regex, tree): pattern = re.compile(regex) t = EvolTree(unlabelledTreeAsString) marks = [] count = 1 outfiles = [] #nsFG=TreeStyle() nsMatch = NodeStyle() #match nsMatch["fgcolor"] = "blue" nsMatch["size"] = 10 nsBG = NodeStyle() nsBG["fgcolor"] = "black" nsBG["size"] = 0 nsFG = [] tolabelreg = [] for i in range(0,MAX_PARENT): nsFG.append( NodeStyle()) nsFG[i]["size"] = 10 nsFG[i]["fgcolor"] = NODE_COLORS[i] isroot=True for node in t.traverse(): node.set_style(nsBG) if node.is_root(): print("root") node.unroot() node._support = None for node in t.get_descendants(): node.add_face(TextFace(node.node_id), column=0) #traverse and match for node in t.traverse(): if re.match(pattern, node.name): print("MATCH", node.name, node.node_id) node.set_style(nsMatch) n = node try: for i in range(0,MAX_PARENT): n = n.up n.set_style(nsFG[i]) marks.append("#"+str(count)) print(count) t.mark_tree([str(count)], marks=marks) #just label everything with #1 print(t.write()) tolabelreg.append(str(n.node_id)) outfile = tree+"."+"_".join([str(n.node_id)]) with open(outfile, 'w') as out: out.write(t.write()) outfiles.append(outfile) except AttributeError: pass marks.append("#"+str(count)) print(count) t.mark_tree([str(count)], marks=marks) #just label everything with #1 print(t.write()) outfile = tree+"."+"_".join([str(node.node_id)]) with open(outfile, 'w') as out: out.write(t.write()) outfiles.append(outfile) #t.show() t.render(tree+".png") return(outfiles, tolabelreg)
def label_regex(unlabeled_tree, regex, treefile, depth=4, model_list=None, paml_msa=None, outfile=None): pattern = re.compile(regex) t = EvolTree(unlabeled_tree) marks = [] count = 1 outfiles = [] ts = TreeStyle() ts.mode = "c" nsMatch = NodeStyle() # match nsMatch["fgcolor"] = "blue" nsMatch["size"] = 10 nsBG = NodeStyle() nsBG["fgcolor"] = "black" nsBG["size"] = 0 nsFG = [] tolabelreg = [] for i in range(0, depth): nsFG.append(NodeStyle()) nsFG[i]["size"] = 10 nsFG[i]["fgcolor"] = "blue" #isroot = True #for node in t.traverse(): # node.set_style(nsBG) # if node.is_root(): # print("root") # node.unroot() # node._support = None for node in t.get_descendants(): node.add_face(TextFace(node.node_id), column=0) # traverse and match for node in t.traverse(): if re.match(pattern, node.name): node.set_style(nsMatch) n = node try: for i in range(0, depth): n = n.up n.set_style(nsFG[i]) marks.append("#" + str(count)) #print(count) t.mark_tree([str(count)], marks=marks) #just label everything with #1 tolabelreg.append(str(n.node_id)) outfile = treefile + "." + "_".join([str(n.node_id)]) with open(outfile, 'w') as out: out.write(t.write()) outfiles.append(outfile) except AttributeError: pass else: node.set_style(nsBG) for f in tolabelreg: print(f,"FFF") for m in model_list: generateCtl(model=m, treefile=treefile+"."+f, seqfile=paml_msa, outfile=treefile+"."+f, generateOther=False) t = fakeUnroot(t) t.render(treefile+".png", tree_style=ts) return outfiles, tolabelreg