File: evo-hypothesis.rst

package info (click to toggle)
python-cogent 2024.5.7a1%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 74,600 kB
  • sloc: python: 92,479; makefile: 117; sh: 16
file content (77 lines) | stat: -rw-r--r-- 2,017 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
.. jupyter-execute::
    :hide-code:

    import set_working_directory

Testing a hypothesis – non-stationary or time-reversible
--------------------------------------------------------

We test the hypothesis that the GTR model is sufficient for a data set, compared with the GN (non-stationary general nucleotide model).

.. jupyter-execute::

    from cogent3 import get_app

    loader = get_app("load_aligned", format="fasta", moltype="dna")
    aln = loader("data/primate_brca1.fasta")

    tree = "data/primate_brca1.tree"

    null = get_app("model", "GTR", tree=tree, optimise_motif_probs=True)
    alt = get_app("model", "GN", tree=tree, optimise_motif_probs=True)
    hyp = get_app("hypothesis", null, alt)
    result = hyp(aln)
    type(result)

``result`` is a ``hypothesis_result`` object. The ``repr()`` displays the likelihood ratio test statistic, degrees of freedom and associated p-value>

.. jupyter-execute::

    result

In this case, we accept the null given the p-value is > 0.05. We use this object to demonstrate the properties of a ``hypothesis_result``.

``hypothesis_result`` has attributes and keys
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Accessing the test statistics
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. jupyter-execute::

    result.LR, result.df, result.pvalue

The null hypothesis
~~~~~~~~~~~~~~~~~~~

This model is accessed via the ``null`` attribute.

.. jupyter-execute::

    result.null

.. jupyter-execute::

    result.null.lf

The alternate hypothesis
~~~~~~~~~~~~~~~~~~~~~~~~

.. jupyter-execute::

    result.alt.lf

Saving hypothesis results
^^^^^^^^^^^^^^^^^^^^^^^^^

You are advised to save these results as serialised data since this provides maximum flexibility for downstream analyses.

The following would write the result into a ``sqlitedb``.

.. code-block:: python

    from cogent3 import get_app, open_data_store

    output = open_data_store("path/to/myresults.sqlitedb", mode="w")
    writer = get_app("write_db", data_store=output)
    writer(result)