File: alphabet.rst

package info (click to toggle)
python-cogent 2023.2.12a1%2Bdfsg-2%2Bdeb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 12,416 kB
  • sloc: python: 89,165; makefile: 117; sh: 16
file content (58 lines) | stat: -rw-r--r-- 1,090 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
Alphabets
---------

.. authors Gavin Huttley

``Alphabet`` and ``MolType``
^^^^^^^^^^^^^^^^^^^^^^^^^^^^

``MolType`` instances have an ``Alphabet``.

.. jupyter-execute::

    from cogent3 import DNA, PROTEIN

    print(DNA.alphabet)
    print(PROTEIN.alphabet)

``Alphabet`` instances have a ``MolType``.

.. jupyter-execute::

    PROTEIN.alphabet.moltype == PROTEIN

Creating tuple alphabets
^^^^^^^^^^^^^^^^^^^^^^^^

You can create a tuple alphabet of, for example, dinucleotides or trinucleotides.

.. jupyter-execute::

    dinuc_alphabet = DNA.alphabet.get_word_alphabet(2)
    print(dinuc_alphabet)
    trinuc_alphabet = DNA.alphabet.get_word_alphabet(3)
    print(trinuc_alphabet)

Convert a sequence into integers
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. jupyter-execute::

    seq = "TAGT"
    indices = DNA.alphabet.to_indices(seq)
    indices

Convert integers to a sequence
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. jupyter-execute::

    seq = DNA.alphabet.from_indices([0, 2, 3, 0])
    seq

or

.. jupyter-execute::

    seq = DNA.alphabet.from_ordinals_to_seq([0, 2, 3, 0])
    seq