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 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190
|
.. _genetic-codes:
Using genetic codes
^^^^^^^^^^^^^^^^^^^
Selecting codes in methods that support them
""""""""""""""""""""""""""""""""""""""""""""
In cases where a ``cogent3`` object method has a ``gc`` argument, you can just use the number under "Code ID" column.
For example, I've created a partial codon in ``"s1"``
.. jupyter-execute::
from cogent3 import make_aligned_seqs
data = {
"s1": "GCTCATGCCAGCTCTTTACAGCATGAGAACA--AGT",
"s2": "ACTCATGCCAACTCATTACAGCATGAGAACAGCAGT",
"s3": "ACTCATGCCAGCTCATTACAGCATGAGAACAGCAGT",
"s4": "ACTCATGCCAGCTCATTACAGCATGAGAACAGCAGT",
"s5": "ACTCATGCCAGCTCAGTACAGCATGAGAACAGCAGT",
}
nt_seqs = make_aligned_seqs(data=data, moltype="dna")
nt_seqs
We specify the genetic code, and we allow incomplete codons. In this case, if a codon contains a gap, they are converted to ``?`` in the translation.
.. jupyter-execute::
nt_seqs.get_translation(gc=1, incomplete_ok=True)
Translate DNA sequences
"""""""""""""""""""""""
.. jupyter-execute::
from cogent3 import get_code
standard_code = get_code(1)
standard_code.translate("TTTGCAAAC")
Conversion to a ``ProteinSequence`` from a ``DnaSequence`` is shown in :ref:`translation`.
Translate all six frames
""""""""""""""""""""""""
.. jupyter-execute::
from cogent3 import get_code, make_seq
standard_code = get_code(1)
seq = make_seq("ATGCTAACATAAA", moltype="dna")
translations = standard_code.sixframes(seq)
print(translations)
Find out how many stops in a frame
""""""""""""""""""""""""""""""""""
.. jupyter-execute::
from cogent3 import get_code, make_seq
standard_code = get_code(1)
seq = make_seq("ATGCTAACATAAA", moltype="dna")
stops_frame1 = standard_code.get_stop_indices(seq, start=0)
stops_frame1
.. jupyter-execute::
stop_index = stops_frame1[0]
seq[stop_index : stop_index + 3]
Translate a codon
"""""""""""""""""
.. jupyter-execute::
from cogent3 import get_code, make_seq
standard_code = get_code(1)
standard_code["TTT"]
or get the codons for a single amino acid
.. jupyter-execute::
standard_code["A"]
Look up the amino acid corresponding to a single codon
""""""""""""""""""""""""""""""""""""""""""""""""""""""
.. jupyter-execute::
from cogent3 import get_code
standard_code = get_code(1)
standard_code["TTT"]
Get all the codons for one amino acid
"""""""""""""""""""""""""""""""""""""
.. jupyter-execute::
from cogent3 import get_code
standard_code = get_code(1)
standard_code["A"]
Get all the codons for a group of amino acids
"""""""""""""""""""""""""""""""""""""""""""""
.. jupyter-execute::
targets = ["A", "C"]
codons = [standard_code[aa] for aa in targets]
codons
.. jupyter-execute::
flat_list = sum(codons, [])
flat_list
Converting the ``CodonAlphabet`` to codon series
""""""""""""""""""""""""""""""""""""""""""""""""
.. jupyter-execute::
from cogent3 import get_code
gc = get_code(1)
alphabet = gc.get_alphabet()
print(alphabet)
Obtaining the codons from a ``DnaSequence`` object
""""""""""""""""""""""""""""""""""""""""""""""""""
Use the method ``get_in_motif_size``
.. jupyter-execute::
from cogent3 import make_seq
my_seq = make_seq("ATGCACTGGTAA", name="my_gene", moltype="dna")
codons = my_seq.get_in_motif_size(3)
codons
Translating a DNA sequence
""""""""""""""""""""""""""
The defaults for ``get_translation()`` include using the standard genetic code and trimming a terminating stop if it exists.
.. jupyter-execute::
pep = my_seq.get_translation()
pep
Translating a DNA sequence containing stop codons
"""""""""""""""""""""""""""""""""""""""""""""""""
.. jupyter-execute::
:hide-code:
from cogent3.core.alphabet import AlphabetError
Making a sequence that contains both internal and terminating stop codons.
.. jupyter-execute::
:raises:
from cogent3 import make_seq
seq = make_seq("ATGTGATGGTAA", name="s1", moltype="dna")
Translating this will fail with default settings.
.. jupyter-execute::
:raises: AlphabetError
pep = seq.get_translation()
Unless you explicitly allow stop codons
.. jupyter-execute::
pep = seq.get_translation(include_stop=True)
pep
|