Ejemplo n.º 1
0
def plot_phylo_tree_pars(align: MultipleSeqAlignment, accession_numbers: dict):
    """
    Plots a phylogenetic tree
    :param align: MultipleSeqAlignment with the alignment result to be plotted
    :param accession_numbers: dict of accession numbers and their translation to human-understandable names
    :return: figure-handle of the plotted phylogenetic tree
    """
    scorer = ParsimonyScorer()
    searcher = NNITreeSearcher(scorer)
    constructor = ParsimonyTreeConstructor(searcher)
    tree = constructor.build_tree(align)
    print(Phylo.draw_ascii(tree))

    # plot the tree
    fig, ax = plt.subplots(1, 1)
    # remove the names for the non-terminals for better visual appeal
    for non_terminal in tree.get_nonterminals():
        non_terminal.name = ''
    # draw the resulting tree
    Phylo.draw(tree, show_confidence=False, axes=ax, do_show=False)
    ax.set_xlim(right=0.8)
    return fig
Ejemplo n.º 2
0
def create_tree_parsimony_impl(msa):
    calculator = DistanceCalculator('identity')
    constructor = DistanceTreeConstructor(distance_calculator=calculator, method='nj')
    starting_tree = constructor.build_tree(msa)

    scorer = ParsimonyScorer()
    searcher = NNITreeSearcher(scorer)
    constructor = ParsimonyTreeConstructor(searcher=searcher,starting_tree=starting_tree)
    tree = constructor.build_tree(msa)
    Phylo.write(tree, "../../data/created/tree" + str(random.randint(0,10000000)) + ".nex", "nexus")
    Phylo.draw(tree,do_show=False)
    plt.savefig("../../data/created/createdTree_parsimony.png")
    return "../../data/created/createdTree_parsimony.png"
 def test_build_tree(self):
     aln = AlignIO.read('TreeConstruction/msa.phy', 'phylip')
     tree1 = Phylo.read('./TreeConstruction/upgma.tre', 'newick')
     tree2 = Phylo.read('./TreeConstruction/nj.tre', 'newick')
     alphabet = ['A', 'T', 'C', 'G']
     step_matrix = [[0], [2.5, 0], [2.5, 1, 0], [1, 2.5, 2.5, 0]]
     matrix = _Matrix(alphabet, step_matrix)
     scorer = ParsimonyScorer(matrix)
     searcher = NNITreeSearcher(scorer)
     constructor = ParsimonyTreeConstructor(searcher, tree1)
     best_tree = constructor.build_tree(aln)
     Phylo.write(best_tree, './TreeConstruction/pars1.tre', 'newick')
     constructor.starting_tree = tree2
     best_tree = constructor.build_tree(aln)
     Phylo.write(best_tree, './TreeConstruction/pars2.tre', 'newick')
     constructor.starting_tree = None
     best_tree = constructor.build_tree(aln)
     Phylo.write(best_tree, './TreeConstruction/pars3.tre', 'newick')
Ejemplo n.º 4
0
 def test_build_tree(self):
     aln = AlignIO.read("TreeConstruction/msa.phy", "phylip")
     tree1 = Phylo.read("./TreeConstruction/upgma.tre", "newick")
     tree2 = Phylo.read("./TreeConstruction/nj.tre", "newick")
     alphabet = ["A", "T", "C", "G"]
     step_matrix = [[0], [2.5, 0], [2.5, 1, 0], [1, 2.5, 2.5, 0]]
     matrix = _Matrix(alphabet, step_matrix)
     scorer = ParsimonyScorer(matrix)
     searcher = NNITreeSearcher(scorer)
     constructor = ParsimonyTreeConstructor(searcher, tree1)
     best_tree = constructor.build_tree(aln)
     Phylo.write(best_tree, os.path.join(temp_dir, "pars1.tre"), "newick")
     constructor.starting_tree = tree2
     best_tree = constructor.build_tree(aln)
     Phylo.write(best_tree, os.path.join(temp_dir, "pars2.tre"), "newick")
     constructor.starting_tree = None
     best_tree = constructor.build_tree(aln)
     Phylo.write(best_tree, os.path.join(temp_dir, "pars3.tre"), "newick")
Ejemplo n.º 5
0
 def test_build_tree(self):
     aln = AlignIO.read(open('TreeConstruction/msa.phy'), 'phylip')
     tree1 = Phylo.read('./TreeConstruction/upgma.tre', 'newick')
     tree2 = Phylo.read('./TreeConstruction/nj.tre', 'newick')
     alphabet = ['A', 'T', 'C', 'G']
     step_matrix = [[0],
                    [2.5,   0],
                    [2.5,   1,    0],
                    [  1, 2.5,  2.5, 0]]
     matrix = _Matrix(alphabet, step_matrix)
     scorer = ParsimonyScorer(matrix)
     searcher = NNITreeSearcher(scorer)
     constructor = ParsimonyTreeConstructor(searcher, tree1)
     best_tree = constructor.build_tree(aln)
     Phylo.write(best_tree, './TreeConstruction/pars1.tre', 'newick')
     constructor.starting_tree = tree2
     best_tree = constructor.build_tree(aln)
     Phylo.write(best_tree, './TreeConstruction/pars2.tre', 'newick')
     constructor.starting_tree = None
     best_tree = constructor.build_tree(aln)
     Phylo.write(best_tree, './TreeConstruction/pars3.tre', 'newick')
Ejemplo n.º 6
0
filePath = input("Enter the text file path:")
alignment = fastaToPhy(textToFasta(filePath))
distanceCalculator = DistanceCalculator('identity')
distanceMatrix = distanceCalculator.get_distance(alignment)

print('Distance Matrix:')
print(distanceMatrix)
print()

distanceConstructor = DistanceTreeConstructor()
##############################UPGMA##############################
UPGMATree = distanceConstructor.upgma(distanceMatrix)
Phylo.draw(UPGMATree)
print('UPGMA Phylogenetic Tree:')
Phylo.draw_ascii(UPGMATree)

##############################NJ##############################
NJTree = distanceConstructor.nj(distanceMatrix)
Phylo.draw(NJTree)
print('Neighbor joining Phylogenetic Tree:')
Phylo.draw_ascii(NJTree)

##############################PARSIMONY##############################
parsimonyScorer = Phylo.TreeConstruction.ParsimonyScorer()
searcher = Phylo.TreeConstruction.NNITreeSearcher(parsimonyScorer)
parsimonyConstructor = ParsimonyTreeConstructor(searcher, NJTree)
parsimonyTree = parsimonyConstructor.build_tree(alignment)
print('Parsimony Phylogenetic Tree:')
Phylo.draw_ascii(parsimonyTree)
Phylo.draw(parsimonyTree)
Ejemplo n.º 7
0
def build_parsimony_tree(alignment):
    scorer = ParsimonyScorer()
    searcher = NNITreeSearcher(scorer)
    constructor = ParsimonyTreeConstructor(searcher)
    return constructor.build_tree(alignment)
Ejemplo n.º 8
0
# print(stdout, stderr)
# print(cline)
aln = AlignIO.read('outAlign.aln', 'clustal')
# print(aln)

calculator = DistanceCalculator('identity')
dm = calculator.get_distance(aln)
print(dm)

constructor = DistanceTreeConstructor(calculator, 'nj')
tree = constructor.build_tree(aln)
print(tree)

scorer = ParsimonyScorer()
searcher = NNITreeSearcher(scorer)
constructor = ParsimonyTreeConstructor(searcher, tree)
pars_tree = constructor.build_tree(aln)

egfr_phy = pars_tree.as_phyloxml()

print(pars_tree)
print(egfr_phy)
print(list(pars_tree.find_elements('Inner3')))

for clade in egfr_phy.get_terminals():
    key = clade.name
    accession = PhyloXML.Accession(key, 'NCBI')
    mol_seq = PhyloXML.MolSeq(lookup[key], is_aligned=True)
    sequence = PhyloXML.Sequence(type='aa',
                                 accession=accession,
                                 mol_seq=mol_seq)