4
.. authors Gavin Huttley
6
``Alphabet`` and ``MolType``
7
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9
``MolType`` instances have an ``Alphabet``.
13
>>> from cogent import DNA, PROTEIN
14
>>> print DNA.Alphabet
16
>>> print PROTEIN.Alphabet
17
('A', 'C', 'D', 'E', ...
19
``Alphabet`` instances have a ``MolType``.
23
>>> PROTEIN.Alphabet.MolType == PROTEIN
26
Creating tuple alphabets
27
^^^^^^^^^^^^^^^^^^^^^^^^
29
You can create a tuple alphabet of, for example, dinucleotides or trinucleotides.
33
>>> dinuc_alphabet = DNA.Alphabet.getWordAlphabet(2)
34
>>> print dinuc_alphabet
35
('TT', 'CT', 'AT', 'GT', ...
36
>>> trinuc_alphabet = DNA.Alphabet.getWordAlphabet(3)
37
>>> print trinuc_alphabet
38
('TTT', 'CTT', 'ATT', ...
40
Convert a sequence into integers
41
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
46
>>> indices = DNA.Alphabet.toIndices(seq)
50
Convert integers to a sequence
51
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
55
>>> seq = DNA.Alphabet.fromIndices([0,2,3,0])
63
>>> seq = DNA.Alphabet.fromOrdinalsToSequence([0,2,3,0])