File: plot_aln-gaps-per-seq.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 (54 lines) | stat: -rw-r--r-- 1,974 bytes parent folder | download | duplicates (2)
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
.. jupyter-execute::
    :hide-code:

    import set_working_directory

Counting gaps per sequence
==========================

We have several different ways of counting sequence gaps, and of visualising the results. By default, the ``count_gaps_per_seq()`` method returns a matrix of counts without the ability to visualise the results. When setting the argument ``unique=True``, the counts are for gaps uniquely induced by each sequence. This can be a useful indicator of highly divergent sequences.

.. jupyter-execute::

    from cogent3 import load_aligned_seqs

    aln = load_aligned_seqs("data/brca1.fasta", moltype="dna")

    counts = aln.count_gaps_per_seq(unique=True)
    counts[10: 20] # limiting the width of the displayed output

Plotting counts of unique gaps
------------------------------

Using the ``drawable`` argument causes the returned object to have a ``drawable`` attribute (type ``Drawable`` which has ``show()`` and ``write()`` methods), for the corresponding plot type. The three plot types supported are shown below. In all cases, placing the mouse pointer over a data point will show hover text with the number of unique gaps and the sequence name.

Displaying unique gaps as a bar chart
-------------------------------------

.. jupyter-execute::

    counts = aln.count_gaps_per_seq(unique=True, drawable="bar")
    counts.drawable.show(width=500)

.. jupyter-execute::
    :hide-code:

    outpath = set_working_directory.get_thumbnail_dir() / "plot_aln-gaps-per-seq.png"

    counts.drawable.write(outpath)

Displaying unique gaps as a violin plot
---------------------------------------

.. jupyter-execute::

    counts = aln.count_gaps_per_seq(unique=True, drawable="violin")
    counts.drawable.show(width=300, height=500)

Displaying unique gaps as a box plot
------------------------------------

.. jupyter-execute::

    counts = aln.count_gaps_per_seq(unique=True, drawable="box")
    counts.drawable.show(width=300, height=500)