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
|
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
|