File: simulate_alignment.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 (57 lines) | stat: -rw-r--r-- 1,640 bytes parent folder | download | duplicates (5)
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
Simulate an alignment
=====================

.. sectionauthor:: Gavin Huttley

How to  simulate an alignment. For this example we just create a simple model using a four taxon tree with very different branch lengths, a Felsenstein model with very different nucleotide frequencies and a long alignment.

See the other examples for how to define other substitution models.

.. doctest::

    >>> import sys
    >>> from cogent import LoadTree
    >>> from cogent.evolve import substitution_model

Specify the 4 taxon tree,

.. doctest::

    >>> t = LoadTree(treestring='(a:0.4,b:0.3,(c:0.15,d:0.2)edge.0:0.1);')

Define our Felsenstein 1981 substitution model.

.. doctest::

    >>> sm = substitution_model.Nucleotide(motif_probs = {'A': 0.5, 'C': 0.2,
    ... 'G': 0.2, 'T': 0.1}, model_gaps=False)
    >>> lf = sm.makeLikelihoodFunction(t)
    >>> lf.setConstantLengths()
    >>> lf.setName('F81 model')
    >>> print lf
    F81 model
    ==========================
      edge    parent    length
    --------------------------
         a      root    0.4000
         b      root    0.3000
         c    edge.0    0.1500
         d    edge.0    0.2000
    edge.0      root    0.1000
    --------------------------
    ===============
    motif    mprobs
    ---------------
        T    0.1000
        C    0.2000
        A    0.5000
        G    0.2000
    ---------------

We'll now create a simulated alignment of length 1000 nucleotides.

.. doctest::

    >>> simulated = lf.simulateAlignment(sequence_length=1000)

The result is a normal ``Cogent`` alignment object, which can be used in the same way as any other alignment object.