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 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 main(): """ main function """ tree = EvolTree (WRKDIR + 'tree.nw') tree.workdir = 'data/protamine/PRM1/paml/' random_swap(tree) tree.link_to_evol_model (WRKDIR + 'paml/fb/fb.out', 'fb') check_annotation (tree) tree.link_to_evol_model (WRKDIR + 'paml/M1/M1.out', 'M1') tree.link_to_evol_model (WRKDIR + 'paml/M2/M2.out', 'M2') tree.link_to_evol_model (WRKDIR + 'paml/M7/M7.out', 'M7') tree.link_to_evol_model (WRKDIR + 'paml/M8/M8.out', 'M8') tree.link_to_alignment (WRKDIR + 'alignments.fasta_ali') print 'pv of LRT M2 vs M1: ', print tree.get_most_likely ('M2','M1') print 'pv of LRT M8 vs M7: ', print tree.get_most_likely ('M8','M7') tree.show (histfaces=['M2']) print 'The End.'
from ete2 import EvolTree from ete2 import faces tree = EvolTree("data/S_example/measuring_S_tree.nw") tree.link_to_alignment("data/S_example/alignment_S_measuring_evol.fasta") print tree print "\n Running free-ratio model with calculation of ancestral sequences..." tree.run_model("fb_anc") # tree.link_to_evol_model('/tmp/ete2-codeml/fb_anc/out', 'fb_anc') I = TreeStyle() I.force_topology = False I.draw_aligned_faces_as_table = True I.draw_guiding_lines = True I.guiding_lines_type = 2 I.guiding_lines_color = "#CCCCCC" for n in sorted(tree.get_descendants() + [tree], key=lambda x: x.node_id): if n.is_leaf(): continue anc_face = faces.SequenceFace(n.sequence, "aa", fsize=10, bg_colors={}) I.aligned_foot.add_face(anc_face, 1) I.aligned_foot.add_face(faces.TextFace("node_id: #%d " % (n.node_id), fsize=8), 0) print "display result of bs_anc model, with ancestral amino acid sequences." tree.show(tree_style=I) print "\nThe End."
print tree raw_input ('\n tree and alignment loaded\n Hit some key, to start computation of site models M1 and M2.\n') print 'running model M1' tree.run_model ('M1') print 'running model M2' tree.run_model ('M2') print '\n\n comparison of models M1 and M2, p-value: ' + str(tree.get_most_likely ('M2','M1')) #tree.show() print 'by default the hist represented is this one:' tree.show (histfaces=['M2']) print 'but we can choose between many others...' model2 = tree.get_evol_model ('M2') col2 = {'NS' : 'black', 'RX' : 'black', 'RX+': 'black', 'CN' : 'black', 'CN+': 'black', 'PS' : 'black', 'PS+': 'black'} model2.set_histface (up=False, kind='curve', colors=col2, ylim=[0,4], hlines = [2.5, 1.0, 4.0, 0.5], header = 'Many lines, error boxes, background black', hlines_col=['orange', 'yellow', 'red', 'cyan'], errors=True) tree.show(histfaces=['M2'])
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. ''' # TODO: re-enable model M3 print 'running branch-site C...' tree.run_model ('bsC.137') #print 'running branch-site D...'
from ete2 import EvolTree tree = EvolTree ("data/S_example/measuring_S_tree.nw") print tree raw_input ('\n tree loaded, hit some key.\n') print 'Now, it is necessary to link this tree to an alignment:' tree.link_to_alignment ('data/S_example/alignment_S_measuring_evol.fasta') raw_input ('\n alignment loaded, hit some key to see.\n') tree.show() print ''' we will run free-ratio model that is one of models available through function run_model: +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ''' print tree.run_model.__doc__ +'\n+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++' tree.run_model ('fb.example') raw_input ('free-ratio model runned, all results are store in a Model object.') fb = tree.get_evol_model('fb.example') print 'Have a look to the parameters used to run this model on codeml: '