File: alphabet.rst

package info (click to toggle)
python-cogent 1.5.3-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 16,424 kB
  • ctags: 24,343
  • sloc: python: 134,200; makefile: 100; ansic: 17; sh: 10
file content (65 lines) | stat: -rw-r--r-- 1,300 bytes parent folder | download | duplicates (4)
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
Alphabets
---------

.. authors Gavin Huttley

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

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

.. doctest::
    
    >>> from cogent import DNA, PROTEIN
    >>> print DNA.Alphabet
    ('T', 'C', 'A', 'G')
    >>> print PROTEIN.Alphabet
    ('A', 'C', 'D', 'E', ...

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

.. doctest::
    
    >>> PROTEIN.Alphabet.MolType == PROTEIN
    True

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

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

.. doctest::
    
    >>> dinuc_alphabet = DNA.Alphabet.getWordAlphabet(2)
    >>> print dinuc_alphabet
    ('TT', 'CT', 'AT', 'GT', ...
    >>> trinuc_alphabet = DNA.Alphabet.getWordAlphabet(3)
    >>> print trinuc_alphabet
    ('TTT', 'CTT', 'ATT', ...

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

.. doctest::
    
    >>> seq = 'TAGT'
    >>> indices = DNA.Alphabet.toIndices(seq)
    >>> indices
    [0, 2, 3, 0]

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

.. doctest::
    
    >>> seq = DNA.Alphabet.fromIndices([0,2,3,0])
    >>> seq
    ['T', 'A', 'G', 'T']

or

.. doctest::
    
    >>> seq = DNA.Alphabet.fromOrdinalsToSequence([0,2,3,0])
    >>> seq
    DnaSequence(TAGT)