Skip to content
Alex Safatli edited this page Jan 19, 2016 · 3 revisions

Scoring in Pylogeny currently supports two types of objective functions:

  • Log-likelihood (Maximum Likelihood), and
  • Parsimony (Parsimonious Criterion).

To acquire the values to these objective functions for any tree, we can leverage the scoring module found in the framework and its comprising functions. To perform scoring, a tree also needs to be paired with a sequence alignment.

This example showcases finding the log-likelihood for a tree involving taxa found for 16S rRNA sequences in the bacterial family Lachnospiraceae.

from pylogeny.tree import tree
from pylogeny.alignment import phylipFriendlyAlignment as alignment
from pylogeny.scoring import getLogLikelihood

# to find the score, we need an alignment that is "Phylip friendly" (see import)
a = alignment("al.fasta") # this file can be found in the /tests/ directory

# let us acquire a tree object by using FastTree
t = a.getApproxMLTree()

# get the score
ll = getLogLikelihood(t,a) # will score and also optimize branch lengths
print ll # print the score
print t # print the Newick string (with optimized branch lengths)

The above example generates a tree. If we already have a tree and we want to score it, this requires conversion of the Newick string because the Phylip-friendly alignment class has renamed all taxa names to different and shortened names.

newick = "(((Brachyspira_hyodysenteriae_WA1_16S,Brachyspira_murdochii_DSM_12563_16S),((((Anaerofustis_stercorihominis_DSM_17244_16S,Eubacterium_yurii_subsp._margaretiae_ATCC_43715_16S),Syntrophothermus_lipocalidus_DSM_12680_16S),Pelobacter_carbinolicus_DSM_2380_16S),Treponema_vincentii_ATCC_35580_16S)),Brachyspira_pilosicoli_95_1000_16S);"
converted = a.convertOriginalNewick(newick)
print getLogLikelihood(tree(converted),a)

Furthermore, to see the Newick string for the tree that was generated, but with the original taxa names:

print a.reinterpretTree(t) # print the Newick string with original taxa names

Clone this wiki locally