def load_tree_sequences(nwk_file, fasta_file): ''' Load a tree with associated sequences on leaves. ''' tree = PhyloTree(newick=nwk_file, format=1) tree.link_to_alignment(alignment=fasta_file, alg_format='fasta') return tree
def load_tree(f_tree, f_align): # Tree style ts = TreeStyle() ts.show_leaf_name = True ts.show_branch_length = True ts.show_branch_support = True ts.branch_vertical_margin = 10 # Load phylogenetic tree tree = PhyloTree(f_tree.read()) if f_align is not None: tree.link_to_alignment(f_align.read()) return tree, ts
from Bio import SeqIO from Bio import motifs from Bio.Cluster import distancematrix from Bio.Cluster import clustercentroids records = list(SeqIO.parse("./txt/cm_perm_sequence_27_social.fasta", "fasta")) for seq_record in SeqIO.parse("./txt/cm_perm_sequence_27_social.fasta", "fasta"): print seq_record.id print repr(seq_record.seq) print len(seq_record) from Bio.Align.Applications import ClustalwCommandline clustalx = '/Applications/PhylogeneticAnalysis/clustalw2' cline = ClustalwCommandline(clustalx, infile="./txt/cm_perm_sequence_27_social.fasta") print cline stdout, stderr = cline() from Bio import Phylo tree = Phylo.read("./txt/cm_perm_sequence_27_social.dnd", "newick") tree.rooted = True #Phylo.draw(tree) from ete2 import Tree from ete2 import PhyloTree t = PhyloTree('./txt/cm_perm_sequence_27_social.dnd') t.link_to_alignment(alignment="./txt/cm_perm_sequence_27_social.fasta", alg_format="fasta") #from ete2 import ClusterTree #t = ClusterTree('./txt/cm_perm_sequence_27_social.dnd') t.show() #t.show("heatmap") #t.show("cluster_cbars") #t.show("cluster_bars") #t.show("cluster_lines")
if node.collapsed == 1: node.img_style["draw_descendants"]= False if node.is_leaf(): if hasattr (node, "sequence"): seqface = MySequenceFace(node.sequence, "nt", fsize=10, col_w=11, interactive=True) faces.add_face_to_node(seqface, node, 1, aligned=True) if __name__ == "__main__": tree = PhyloTree('(Orangutan,Human,Chimp);') tree.link_to_alignment(""" >Chimp HARWLNEKLRCELRTLKKLGLDGYKAVSQYVKGRA >Orangutan DARWINEKLRCVSRTLKKLGLDGYKGVSQYVKGRP >Human DARWHNVKLRCELRTLKKLGLVGFKAVSQFVIRRA """) nt_sequences = {"Human" : "GACGCACGGTGGCACAACGTAAAATTAAGATGTGAATTGAGAACTCTGAAAAAATTGGGACTGGTCGGCTTCAAGGCAGTAAGTCAATTCGTAATACGTCGTGCG", "Chimp" : "CACGCCCGATGGCTCAACGAAAAGTTAAGATGCGAATTGAGAACTCTGAAAAAATTGGGACTGGACGGCTACAAGGCAGTAAGTCAGTACGTTAAAGGTCGTGCG", "Orangutan": "GATGCACGCTGGATCAACGAAAAGTTAAGATGCGTATCGAGAACTCTGAAAAAATTGGGACTGGACGGCTACAAGGGAGTAAGTCAATACGTTAAAGGTCGTCCG" } for l in nt_sequences: (tree & l).nt_sequence = nt_sequences[l] tree.dist = 0 ts = TreeStyle() ts.title.add_face(TextFace("Example for nucleotides...", fsize=15), column=0) ts.layout_fn = test_layout_evol tree.show(tree_style=ts)
""" # Load a tree and link it to an alignment. As usual, 'alignment' can # be the path to a file or data in text format. t = PhyloTree("(((seqA,seqB),seqC),seqD);", alignment=fasta_txt, alg_format="fasta") #We can now access the sequence of every leaf node print "These are the nodes and its sequences:" for leaf in t.iter_leaves(): print leaf.name, leaf.sequence #seqD MAEAPDETIQQFMALTNVSHNIAVQYLSEFGDLNEAL--------------REEAH #seqC MAEIPDATIQ---ALTNVSHNIAVQYLSEFGDLNEALNSYYASQTDDQPDRREEAH #seqA MAEIPDETIQQFMALT---HNIAVQYLSEFGDLNEALNSYYASQTDDIKDRREEAH #seqB MAEIPDATIQQFMALTNVSHNIAVQY--EFGDLNEALNSYYAYQTDDQKDRREEAH # # The associated alignment can be changed at any time t.link_to_alignment(alignment=iphylip_txt, alg_format="iphylip") # Let's check that sequences have changed print "These are the nodes and its re-linked sequences:" for leaf in t.iter_leaves(): print leaf.name, leaf.sequence #seqD MAEAPDETIQQFMALTNVSHNIAVQYLSEFGDLNEAL--------------REEAHQ----------FMALTNVSH #seqC MAEIPDATIQ---ALTNVSHNIAVQYLSEFGDLNEALNSYYASQTDDQPDRREEAHQFMALTNVSH---------- #seqA MAEIPDETIQQFMALT---HNIAVQYLSEFGDLNEALNSYYASQTDDIKDRREEAHQFMALTNVSHQFMALTNVSH #seqB MAEIPDATIQQFMALTNVSHNIAVQY--EFGDLNEALNSYYAYQTDDQKDRREEAHQFMALTNVSH---------- # # The sequence attribute is considered as node feature, so you can # even include sequences in your extended newick format! print t.write(features=["sequence"], format=9) # # # (((seqA[&&NHX:sequence=MAEIPDETIQQFMALT---HNIAVQYLSEFGDLNEALNSYYASQTDDIKDRREEAHQF