File: phylogeny_app_controllers.rst

package info (click to toggle)
python-cogent 1.4.1-1.2
  • links: PTS, VCS
  • area: non-free
  • in suites: squeeze
  • size: 13,260 kB
  • ctags: 20,087
  • sloc: python: 116,163; ansic: 732; makefile: 74; sh: 9
file content (61 lines) | stat: -rw-r--r-- 3,162 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
Using phylogeny application controllers to construct phylogenetic trees from alignments
=======================================================================================

.. sectionauthor:: Daniel McDonald

This document provides a few use case examples of how to use the phylogeny application controllers available in PyCogent. Each phylogeny application controller provides the support method ``build_tree_from_alignment``. This method takes as input an ``Alignment`` object, a ``SequenceColleciton`` object or a dict mapping sequence IDs to sequences. The ``MolType`` must also be specified. Optionally, you can indicate if you would like the "best_tree$", as well as any additional application parameters. These methods return a ``PhyloNode`` object.

To start, lets import all of our ``build_tree_from_alignment`` methods and our ``MolType``:

.. doctest::

    >>> from cogent.core.moltype import DNA
    >>> from cogent.app.clearcut import build_tree_from_alignment as clearcut_build_tree
    >>> from cogent.app.clustalw import build_tree_from_alignment as clustalw_build_tree
    >>> from cogent.app.fasttree import build_tree_from_alignment as fasttree_build_tree
    >>> from cogent.app.muscle import build_tree_from_alignment as muscle_build_tree
    >>> from cogent.app.raxml import build_tree_from_alignment as raxml_build_tree

Next, we'll load up a test set of sequences and construct an ``Alignment``:

.. doctest::

    >>> from cogent import LoadSeqs
    >>> from cogent.app.muscle import align_unaligned_seqs
    >>> unaligned = LoadSeqs(filename='data/test2.fasta', aligned=False)
    >>> aln = align_unaligned_seqs(unaligned, DNA)

Now, let's construct some trees with default parameters!

.. note:: We are explicitly seeding Clearcut and RAxML to ensure reproducible results, and FastTree's output depends slightly on which version of FastTree is installed

.. doctest::

    >>> clearcut_tree = clearcut_build_tree(aln, DNA, params={'-s':42})
    >>> clustalw_tree = clustalw_build_tree(aln, DNA)
    >>> fasttree_tree = fasttree_build_tree(aln, DNA)
    >>> muscle_tree = muscle_build_tree(aln, DNA)
    >>> raxml_tree = raxml_build_tree(aln, DNA, params={'-p':42})
    >>> clearcut_tree
    Tree("(Mouse,(((HowlerMon,Human),DogFaced),NineBande));")
    >>> clustalw_tree
    Tree("((DogFaced,(HowlerMon,Human)),Mouse,NineBande);")
    >>> muscle_tree
    Tree("(Mouse,(DogFaced,(Human,(HowlerMon,NineBande))));")
    >>> raxml_tree
    Tree("((HowlerMon,Human),(DogFaced,Mouse),NineBande);")

.. code-block:: python

    >>> fasttree_tree
    Tree("(Mouse,NineBande,(DogFaced,(HowlerMon,Human)0.752)0.508);")

These methods allow the programmer to specify any of the applications parameters. Let's look at an example where we tell Clearcut to use traditional neighbor-joining, shuffle the distance matrix, use Kimura distance correction and explicitly seed the random number generator:

.. doctest::

    >>> clearcut_params = {'-N':True,'-k':True,'-S':True,'-s':42}
    >>> clearcut_tree = clearcut_build_tree(aln, DNA, params=clearcut_params)
    >>> clearcut_tree
    Tree("(((HowlerMon,Human),(NineBande,Mouse)),DogFaced);")