biotite 0.41.2__cp311-cp311-macosx_11_0_arm64.whl → 1.0.1__cp311-cp311-macosx_11_0_arm64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of biotite might be problematic. Click here for more details.
- biotite/__init__.py +2 -3
- biotite/application/__init__.py +1 -1
- biotite/application/application.py +20 -10
- biotite/application/autodock/__init__.py +1 -1
- biotite/application/autodock/app.py +74 -79
- biotite/application/blast/__init__.py +1 -1
- biotite/application/blast/alignment.py +19 -10
- biotite/application/blast/webapp.py +92 -85
- biotite/application/clustalo/__init__.py +1 -1
- biotite/application/clustalo/app.py +46 -61
- biotite/application/dssp/__init__.py +1 -1
- biotite/application/dssp/app.py +8 -11
- biotite/application/localapp.py +62 -60
- biotite/application/mafft/__init__.py +1 -1
- biotite/application/mafft/app.py +16 -22
- biotite/application/msaapp.py +78 -89
- biotite/application/muscle/__init__.py +1 -1
- biotite/application/muscle/app3.py +50 -64
- biotite/application/muscle/app5.py +23 -31
- biotite/application/sra/__init__.py +1 -1
- biotite/application/sra/app.py +64 -68
- biotite/application/tantan/__init__.py +1 -1
- biotite/application/tantan/app.py +22 -45
- biotite/application/util.py +7 -9
- biotite/application/viennarna/rnaalifold.py +34 -28
- biotite/application/viennarna/rnafold.py +24 -39
- biotite/application/viennarna/rnaplot.py +36 -21
- biotite/application/viennarna/util.py +17 -12
- biotite/application/webapp.py +13 -14
- biotite/copyable.py +13 -13
- biotite/database/__init__.py +1 -1
- biotite/database/entrez/__init__.py +1 -1
- biotite/database/entrez/check.py +2 -3
- biotite/database/entrez/dbnames.py +7 -5
- biotite/database/entrez/download.py +55 -49
- biotite/database/entrez/key.py +1 -1
- biotite/database/entrez/query.py +62 -23
- biotite/database/error.py +2 -1
- biotite/database/pubchem/__init__.py +1 -1
- biotite/database/pubchem/download.py +43 -45
- biotite/database/pubchem/error.py +2 -2
- biotite/database/pubchem/query.py +34 -31
- biotite/database/pubchem/throttle.py +3 -4
- biotite/database/rcsb/__init__.py +1 -1
- biotite/database/rcsb/download.py +44 -52
- biotite/database/rcsb/query.py +85 -80
- biotite/database/uniprot/check.py +6 -3
- biotite/database/uniprot/download.py +6 -11
- biotite/database/uniprot/query.py +115 -31
- biotite/file.py +12 -31
- biotite/sequence/__init__.py +3 -3
- biotite/sequence/align/__init__.py +2 -2
- biotite/sequence/align/alignment.py +99 -90
- biotite/sequence/align/banded.cpython-311-darwin.so +0 -0
- biotite/sequence/align/buckets.py +12 -10
- biotite/sequence/align/cigar.py +43 -52
- biotite/sequence/align/kmeralphabet.cpython-311-darwin.so +0 -0
- biotite/sequence/align/kmeralphabet.pyx +55 -51
- biotite/sequence/align/kmersimilarity.cpython-311-darwin.so +0 -0
- biotite/sequence/align/kmertable.cpython-311-darwin.so +0 -0
- biotite/sequence/align/kmertable.pyx +3 -2
- biotite/sequence/align/localgapped.cpython-311-darwin.so +0 -0
- biotite/sequence/align/localungapped.cpython-311-darwin.so +0 -0
- biotite/sequence/align/matrix.py +81 -82
- biotite/sequence/align/multiple.cpython-311-darwin.so +0 -0
- biotite/sequence/align/multiple.pyx +1 -1
- biotite/sequence/align/pairwise.cpython-311-darwin.so +0 -0
- biotite/sequence/align/permutation.cpython-311-darwin.so +0 -0
- biotite/sequence/align/permutation.pyx +12 -4
- biotite/sequence/align/selector.cpython-311-darwin.so +0 -0
- biotite/sequence/align/selector.pyx +52 -54
- biotite/sequence/align/statistics.py +32 -33
- biotite/sequence/align/tracetable.cpython-311-darwin.so +0 -0
- biotite/sequence/alphabet.py +51 -65
- biotite/sequence/annotation.py +78 -77
- biotite/sequence/codec.cpython-311-darwin.so +0 -0
- biotite/sequence/codon.py +90 -79
- biotite/sequence/graphics/__init__.py +1 -1
- biotite/sequence/graphics/alignment.py +184 -103
- biotite/sequence/graphics/colorschemes.py +10 -12
- biotite/sequence/graphics/dendrogram.py +79 -34
- biotite/sequence/graphics/features.py +133 -99
- biotite/sequence/graphics/logo.py +22 -28
- biotite/sequence/graphics/plasmid.py +229 -178
- biotite/sequence/io/fasta/__init__.py +1 -1
- biotite/sequence/io/fasta/convert.py +44 -33
- biotite/sequence/io/fasta/file.py +42 -55
- biotite/sequence/io/fastq/__init__.py +1 -1
- biotite/sequence/io/fastq/convert.py +11 -14
- biotite/sequence/io/fastq/file.py +68 -112
- biotite/sequence/io/genbank/__init__.py +2 -2
- biotite/sequence/io/genbank/annotation.py +12 -20
- biotite/sequence/io/genbank/file.py +74 -76
- biotite/sequence/io/genbank/metadata.py +74 -62
- biotite/sequence/io/genbank/sequence.py +13 -14
- biotite/sequence/io/general.py +39 -30
- biotite/sequence/io/gff/__init__.py +2 -2
- biotite/sequence/io/gff/convert.py +10 -15
- biotite/sequence/io/gff/file.py +81 -65
- biotite/sequence/phylo/__init__.py +1 -1
- biotite/sequence/phylo/nj.cpython-311-darwin.so +0 -0
- biotite/sequence/phylo/tree.cpython-311-darwin.so +0 -0
- biotite/sequence/phylo/upgma.cpython-311-darwin.so +0 -0
- biotite/sequence/profile.py +57 -28
- biotite/sequence/search.py +17 -15
- biotite/sequence/seqtypes.py +200 -164
- biotite/sequence/sequence.py +15 -17
- biotite/structure/__init__.py +3 -3
- biotite/structure/atoms.py +246 -236
- biotite/structure/basepairs.py +260 -271
- biotite/structure/bonds.cpython-311-darwin.so +0 -0
- biotite/structure/bonds.pyx +29 -32
- biotite/structure/box.py +67 -71
- biotite/structure/celllist.cpython-311-darwin.so +0 -0
- biotite/structure/chains.py +55 -39
- biotite/structure/charges.cpython-311-darwin.so +0 -0
- biotite/structure/compare.py +32 -32
- biotite/structure/density.py +13 -18
- biotite/structure/dotbracket.py +20 -22
- biotite/structure/error.py +10 -2
- biotite/structure/filter.py +83 -78
- biotite/structure/geometry.py +130 -119
- biotite/structure/graphics/atoms.py +60 -43
- biotite/structure/graphics/rna.py +81 -68
- biotite/structure/hbond.py +112 -93
- biotite/structure/info/__init__.py +0 -2
- biotite/structure/info/atoms.py +10 -11
- biotite/structure/info/bonds.py +41 -43
- biotite/structure/info/ccd.py +4 -5
- biotite/structure/info/groups.py +1 -3
- biotite/structure/info/masses.py +5 -10
- biotite/structure/info/misc.py +1 -1
- biotite/structure/info/radii.py +20 -20
- biotite/structure/info/standardize.py +15 -26
- biotite/structure/integrity.py +18 -71
- biotite/structure/io/__init__.py +3 -4
- biotite/structure/io/dcd/__init__.py +1 -1
- biotite/structure/io/dcd/file.py +22 -20
- biotite/structure/io/general.py +47 -61
- biotite/structure/io/gro/__init__.py +1 -1
- biotite/structure/io/gro/file.py +73 -72
- biotite/structure/io/mol/__init__.py +1 -1
- biotite/structure/io/mol/convert.py +8 -11
- biotite/structure/io/mol/ctab.py +37 -36
- biotite/structure/io/mol/header.py +14 -10
- biotite/structure/io/mol/mol.py +9 -53
- biotite/structure/io/mol/sdf.py +47 -50
- biotite/structure/io/netcdf/__init__.py +1 -1
- biotite/structure/io/netcdf/file.py +24 -23
- biotite/structure/io/pdb/__init__.py +1 -1
- biotite/structure/io/pdb/convert.py +32 -20
- biotite/structure/io/pdb/file.py +151 -172
- biotite/structure/io/pdb/hybrid36.cpython-311-darwin.so +0 -0
- biotite/structure/io/pdbqt/__init__.py +1 -1
- biotite/structure/io/pdbqt/convert.py +17 -11
- biotite/structure/io/pdbqt/file.py +128 -80
- biotite/structure/io/pdbx/__init__.py +1 -2
- biotite/structure/io/pdbx/bcif.py +36 -44
- biotite/structure/io/pdbx/cif.py +140 -110
- biotite/structure/io/pdbx/component.py +10 -16
- biotite/structure/io/pdbx/convert.py +260 -258
- biotite/structure/io/pdbx/encoding.cpython-311-darwin.so +0 -0
- biotite/structure/io/trajfile.py +90 -107
- biotite/structure/io/trr/__init__.py +1 -1
- biotite/structure/io/trr/file.py +12 -15
- biotite/structure/io/xtc/__init__.py +1 -1
- biotite/structure/io/xtc/file.py +11 -14
- biotite/structure/mechanics.py +9 -11
- biotite/structure/molecules.py +3 -4
- biotite/structure/pseudoknots.py +53 -67
- biotite/structure/rdf.py +23 -21
- biotite/structure/repair.py +137 -86
- biotite/structure/residues.py +26 -16
- biotite/structure/sasa.cpython-311-darwin.so +0 -0
- biotite/structure/{resutil.py → segments.py} +24 -23
- biotite/structure/sequence.py +10 -11
- biotite/structure/sse.py +100 -119
- biotite/structure/superimpose.py +39 -77
- biotite/structure/transform.py +97 -71
- biotite/structure/util.py +11 -13
- biotite/version.py +2 -2
- biotite/visualize.py +69 -55
- {biotite-0.41.2.dist-info → biotite-1.0.1.dist-info}/METADATA +6 -5
- biotite-1.0.1.dist-info/RECORD +322 -0
- biotite/structure/io/ctab.py +0 -72
- biotite/structure/io/mmtf/__init__.py +0 -21
- biotite/structure/io/mmtf/assembly.py +0 -214
- biotite/structure/io/mmtf/convertarray.cpython-311-darwin.so +0 -0
- biotite/structure/io/mmtf/convertarray.pyx +0 -341
- biotite/structure/io/mmtf/convertfile.cpython-311-darwin.so +0 -0
- biotite/structure/io/mmtf/convertfile.pyx +0 -501
- biotite/structure/io/mmtf/decode.cpython-311-darwin.so +0 -0
- biotite/structure/io/mmtf/decode.pyx +0 -152
- biotite/structure/io/mmtf/encode.cpython-311-darwin.so +0 -0
- biotite/structure/io/mmtf/encode.pyx +0 -183
- biotite/structure/io/mmtf/file.py +0 -233
- biotite/structure/io/npz/__init__.py +0 -20
- biotite/structure/io/npz/file.py +0 -152
- biotite/structure/io/pdbx/legacy.py +0 -267
- biotite/structure/io/tng/__init__.py +0 -13
- biotite/structure/io/tng/file.py +0 -46
- biotite/temp.py +0 -86
- biotite-0.41.2.dist-info/RECORD +0 -340
- {biotite-0.41.2.dist-info → biotite-1.0.1.dist-info}/WHEEL +0 -0
- {biotite-0.41.2.dist-info → biotite-1.0.1.dist-info}/licenses/LICENSE.rst +0 -0
biotite/sequence/codon.py
CHANGED
|
@@ -7,11 +7,10 @@ __author__ = "Patrick Kunzmann"
|
|
|
7
7
|
__all__ = ["CodonTable"]
|
|
8
8
|
|
|
9
9
|
import copy
|
|
10
|
-
from os.path import join, dirname, realpath
|
|
11
|
-
import numpy as np
|
|
12
10
|
from numbers import Integral
|
|
13
|
-
from .
|
|
14
|
-
|
|
11
|
+
from os.path import dirname, join, realpath
|
|
12
|
+
import numpy as np
|
|
13
|
+
from biotite.sequence.seqtypes import NucleotideSequence, ProteinSequence
|
|
15
14
|
|
|
16
15
|
# Abbreviations
|
|
17
16
|
_NUC_ALPH = NucleotideSequence.alphabet_unamb
|
|
@@ -20,7 +19,7 @@ _PROT_ALPH = ProteinSequence.alphabet
|
|
|
20
19
|
# Multiplier array that converts a codon in code representation
|
|
21
20
|
# into a unique integer
|
|
22
21
|
_radix = len(_NUC_ALPH)
|
|
23
|
-
_radix_multiplier = np.array([_radix**n for n in (2,1,0)], dtype=int)
|
|
22
|
+
_radix_multiplier = np.array([_radix**n for n in (2, 1, 0)], dtype=int)
|
|
24
23
|
|
|
25
24
|
|
|
26
25
|
class CodonTable(object):
|
|
@@ -29,14 +28,14 @@ class CodonTable(object):
|
|
|
29
28
|
amino acid.
|
|
30
29
|
It also defines start codons. A :class:`CodonTable`
|
|
31
30
|
takes/outputs either the symbols or code of the codon/amino acid.
|
|
32
|
-
|
|
31
|
+
|
|
33
32
|
Furthermore, this class is able to give a list of codons that
|
|
34
33
|
corresponds to a given amino acid.
|
|
35
|
-
|
|
34
|
+
|
|
36
35
|
The :func:`load()` method allows loading of NCBI codon tables.
|
|
37
|
-
|
|
36
|
+
|
|
38
37
|
Objects of this class are immutable.
|
|
39
|
-
|
|
38
|
+
|
|
40
39
|
Parameters
|
|
41
40
|
----------
|
|
42
41
|
codon_dict : dict of (str -> str)
|
|
@@ -47,27 +46,27 @@ class CodonTable(object):
|
|
|
47
46
|
starts : iterable object of str
|
|
48
47
|
The start codons. Each entry must be a string of length 3
|
|
49
48
|
(all upper case).
|
|
50
|
-
|
|
49
|
+
|
|
51
50
|
Examples
|
|
52
51
|
--------
|
|
53
|
-
|
|
52
|
+
|
|
54
53
|
Get the amino acid coded by a given codon (symbol and code):
|
|
55
|
-
|
|
54
|
+
|
|
56
55
|
>>> table = CodonTable.default_table()
|
|
57
56
|
>>> print(table["ATG"])
|
|
58
57
|
M
|
|
59
58
|
>>> print(table[(1,2,3)])
|
|
60
59
|
14
|
|
61
|
-
|
|
60
|
+
|
|
62
61
|
Get the codons coding for a given amino acid (symbol and code):
|
|
63
|
-
|
|
62
|
+
|
|
64
63
|
>>> table = CodonTable.default_table()
|
|
65
64
|
>>> print(table["M"])
|
|
66
65
|
('ATG',)
|
|
67
66
|
>>> print(table[14])
|
|
68
67
|
((0, 2, 0), (0, 2, 2), (1, 2, 0), (1, 2, 1), (1, 2, 2), (1, 2, 3))
|
|
69
68
|
"""
|
|
70
|
-
|
|
69
|
+
|
|
71
70
|
# For efficient mapping of codon codes to amino acid codes,
|
|
72
71
|
# especially in in the 'map_codon_codes()' function, the class
|
|
73
72
|
# maps each possible codon into a unique number using a radix based
|
|
@@ -77,7 +76,7 @@ class CodonTable(object):
|
|
|
77
76
|
|
|
78
77
|
# file for builtin codon tables from NCBI
|
|
79
78
|
_table_file = join(dirname(realpath(__file__)), "codon_tables.txt")
|
|
80
|
-
|
|
79
|
+
|
|
81
80
|
def __init__(self, codon_dict, starts):
|
|
82
81
|
# Check if 'starts' is iterable object of length 3 string
|
|
83
82
|
for start in starts:
|
|
@@ -100,12 +99,10 @@ class CodonTable(object):
|
|
|
100
99
|
if (self._codons == -1).any():
|
|
101
100
|
# Find the missing codon
|
|
102
101
|
missing_index = np.where(self._codons == -1)[0][0]
|
|
103
|
-
codon_code = CodonTable._to_codon(missing_index)
|
|
102
|
+
codon_code = CodonTable._to_codon(missing_index)
|
|
104
103
|
codon = _NUC_ALPH.decode_multiple(codon_code)
|
|
105
104
|
codon_str = "".join(codon)
|
|
106
|
-
raise ValueError(
|
|
107
|
-
f"Codon dictionary does not contain codon '{codon_str}'"
|
|
108
|
-
)
|
|
105
|
+
raise ValueError(f"Codon dictionary does not contain codon '{codon_str}'")
|
|
109
106
|
|
|
110
107
|
def __repr__(self):
|
|
111
108
|
"""Represent CodonTable as a string for debugging."""
|
|
@@ -131,8 +128,10 @@ class CodonTable(object):
|
|
|
131
128
|
codon_numbers = np.where(self._codons == aa_code)[0]
|
|
132
129
|
codon_codes = CodonTable._to_codon(codon_numbers)
|
|
133
130
|
codons = tuple(
|
|
134
|
-
[
|
|
135
|
-
|
|
131
|
+
[
|
|
132
|
+
"".join(_NUC_ALPH.decode_multiple(codon_code))
|
|
133
|
+
for codon_code in codon_codes
|
|
134
|
+
]
|
|
136
135
|
)
|
|
137
136
|
return codons
|
|
138
137
|
elif len(item) == 3:
|
|
@@ -147,37 +146,36 @@ class CodonTable(object):
|
|
|
147
146
|
elif isinstance(item, int):
|
|
148
147
|
# Code for amino acid -> return possible codon codes
|
|
149
148
|
codon_numbers = np.where(self._codons == item)[0]
|
|
150
|
-
codon_codes = tuple(
|
|
151
|
-
|
|
149
|
+
codon_codes = tuple(
|
|
150
|
+
[tuple(code.tolist()) for code in CodonTable._to_codon(codon_numbers)]
|
|
151
|
+
)
|
|
152
152
|
return codon_codes
|
|
153
153
|
else:
|
|
154
154
|
# Code for codon as any iterable object
|
|
155
155
|
# Code for codon -> return corresponding amino acid codes
|
|
156
156
|
if len(item) != 3:
|
|
157
|
-
raise ValueError(
|
|
158
|
-
f"{item} is an invalid sequence code for a codon"
|
|
159
|
-
)
|
|
157
|
+
raise ValueError(f"{item} is an invalid sequence code for a codon")
|
|
160
158
|
codon_number = CodonTable._to_number(item)
|
|
161
159
|
aa_code = self._codons[codon_number]
|
|
162
160
|
return aa_code
|
|
163
|
-
|
|
161
|
+
|
|
164
162
|
def map_codon_codes(self, codon_codes):
|
|
165
163
|
"""
|
|
166
164
|
Efficiently map multiple codons to the corresponding amino
|
|
167
165
|
acids.
|
|
168
|
-
|
|
166
|
+
|
|
169
167
|
Parameters
|
|
170
168
|
----------
|
|
171
169
|
codon_codes : ndarray, dtype=int, shape=(n,3)
|
|
172
170
|
The codons to be translated into amino acids.
|
|
173
171
|
The codons are given as symbol codes.
|
|
174
172
|
*n* is the amount of codons.
|
|
175
|
-
|
|
173
|
+
|
|
176
174
|
Returns
|
|
177
175
|
-------
|
|
178
176
|
aa_codes : ndarray, dtype=int, shape=(n,)
|
|
179
177
|
The amino acids as symbol codes.
|
|
180
|
-
|
|
178
|
+
|
|
181
179
|
Examples
|
|
182
180
|
--------
|
|
183
181
|
>>> dna = NucleotideSequence("ATGGTTTAA")
|
|
@@ -208,46 +206,50 @@ class CodonTable(object):
|
|
|
208
206
|
codon_numbers = CodonTable._to_number(codon_codes)
|
|
209
207
|
aa_codes = self._codons[codon_numbers]
|
|
210
208
|
return aa_codes
|
|
211
|
-
|
|
209
|
+
|
|
212
210
|
def codon_dict(self, code=False):
|
|
213
211
|
"""
|
|
214
212
|
Get the codon to amino acid mappings dictionary.
|
|
215
|
-
|
|
213
|
+
|
|
216
214
|
Parameters
|
|
217
215
|
----------
|
|
218
216
|
code : bool
|
|
219
217
|
If true, the dictionary contains keys and values as code.
|
|
220
218
|
Otherwise, the dictionary contains strings for codons and
|
|
221
219
|
amino acid. (Default: False)
|
|
222
|
-
|
|
220
|
+
|
|
223
221
|
Returns
|
|
224
222
|
-------
|
|
225
223
|
codon_dict : dict
|
|
226
224
|
The dictionary mapping codons to amino acids.
|
|
227
225
|
"""
|
|
228
226
|
if code:
|
|
229
|
-
return {
|
|
230
|
-
|
|
227
|
+
return {
|
|
228
|
+
tuple(CodonTable._to_codon(codon_number)): aa_code
|
|
229
|
+
for codon_number, aa_code in enumerate(self._codons)
|
|
230
|
+
}
|
|
231
231
|
else:
|
|
232
|
-
return {
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
232
|
+
return {
|
|
233
|
+
"".join(_NUC_ALPH.decode_multiple(codon_code)): _PROT_ALPH.decode(
|
|
234
|
+
aa_code
|
|
235
|
+
)
|
|
236
|
+
for codon_code, aa_code in self.codon_dict(code=True).items()
|
|
237
|
+
}
|
|
238
|
+
|
|
237
239
|
def is_start_codon(self, codon_codes):
|
|
238
240
|
codon_numbers = CodonTable._to_number(codon_codes)
|
|
239
241
|
return np.isin(codon_numbers, self._starts)
|
|
240
|
-
|
|
242
|
+
|
|
241
243
|
def start_codons(self, code=False):
|
|
242
244
|
"""
|
|
243
245
|
Get the start codons of the codon table.
|
|
244
|
-
|
|
246
|
+
|
|
245
247
|
Parameters
|
|
246
248
|
----------
|
|
247
249
|
code : bool
|
|
248
250
|
If true, the code will be returned instead of strings.
|
|
249
251
|
(Default: False)
|
|
250
|
-
|
|
252
|
+
|
|
251
253
|
Returns
|
|
252
254
|
-------
|
|
253
255
|
start_codons : tuple
|
|
@@ -256,25 +258,29 @@ class CodonTable(object):
|
|
|
256
258
|
"""
|
|
257
259
|
if code:
|
|
258
260
|
return tuple(
|
|
259
|
-
[
|
|
260
|
-
|
|
261
|
+
[
|
|
262
|
+
tuple(CodonTable._to_codon(codon_number))
|
|
263
|
+
for codon_number in self._starts
|
|
264
|
+
]
|
|
261
265
|
)
|
|
262
266
|
else:
|
|
263
267
|
return tuple(
|
|
264
|
-
[
|
|
265
|
-
|
|
268
|
+
[
|
|
269
|
+
"".join(_NUC_ALPH.decode_multiple(codon_code))
|
|
270
|
+
for codon_code in self.start_codons(code=True)
|
|
271
|
+
]
|
|
266
272
|
)
|
|
267
|
-
|
|
273
|
+
|
|
268
274
|
def with_start_codons(self, starts):
|
|
269
275
|
"""
|
|
270
276
|
Create an new :class:`CodonTable` with the same codon mappings,
|
|
271
277
|
but changed start codons.
|
|
272
|
-
|
|
278
|
+
|
|
273
279
|
Parameters
|
|
274
280
|
----------
|
|
275
281
|
starts : iterable object of str
|
|
276
282
|
The new start codons.
|
|
277
|
-
|
|
283
|
+
|
|
278
284
|
Returns
|
|
279
285
|
-------
|
|
280
286
|
new_table : CodonTable
|
|
@@ -287,17 +293,17 @@ class CodonTable(object):
|
|
|
287
293
|
)
|
|
288
294
|
new_table._starts = CodonTable._to_number(start_codon_codes)
|
|
289
295
|
return new_table
|
|
290
|
-
|
|
296
|
+
|
|
291
297
|
def with_codon_mappings(self, codon_dict):
|
|
292
298
|
"""
|
|
293
299
|
Create an new :class:`CodonTable` with partially changed codon
|
|
294
300
|
mappings.
|
|
295
|
-
|
|
301
|
+
|
|
296
302
|
Parameters
|
|
297
303
|
----------
|
|
298
304
|
codon_dict : dict of (str -> str)
|
|
299
305
|
The changed codon mappings.
|
|
300
|
-
|
|
306
|
+
|
|
301
307
|
Returns
|
|
302
308
|
-------
|
|
303
309
|
new_table : CodonTable
|
|
@@ -328,9 +334,9 @@ class CodonTable(object):
|
|
|
328
334
|
else:
|
|
329
335
|
string += " "
|
|
330
336
|
# Add space for next codon
|
|
331
|
-
string += " "*3
|
|
337
|
+
string += " " * 3
|
|
332
338
|
# Remove terminal space
|
|
333
|
-
string = string
|
|
339
|
+
string = string[:-6]
|
|
334
340
|
# Jump to next line
|
|
335
341
|
string += "\n"
|
|
336
342
|
# Add empty line
|
|
@@ -353,10 +359,10 @@ class CodonTable(object):
|
|
|
353
359
|
if not isinstance(numbers, np.ndarray):
|
|
354
360
|
numbers = np.array(list(numbers), dtype=int)
|
|
355
361
|
codons = np.zeros(numbers.shape + (3,), dtype=int)
|
|
356
|
-
for n in (2,1,0):
|
|
362
|
+
for n in (2, 1, 0):
|
|
357
363
|
val = _radix**n
|
|
358
364
|
digit = numbers // val
|
|
359
|
-
codons[..., -(n+1)] = digit
|
|
365
|
+
codons[..., -(n + 1)] = digit
|
|
360
366
|
numbers = numbers - digit * val
|
|
361
367
|
return codons
|
|
362
368
|
|
|
@@ -364,14 +370,14 @@ class CodonTable(object):
|
|
|
364
370
|
def load(table_name):
|
|
365
371
|
"""
|
|
366
372
|
Load a NCBI codon table.
|
|
367
|
-
|
|
373
|
+
|
|
368
374
|
Parameters
|
|
369
375
|
----------
|
|
370
376
|
table_name : str or int
|
|
371
377
|
If a string is given, it is interpreted as official NCBI
|
|
372
378
|
codon table name (e.g. "Vertebrate Mitochondrial").
|
|
373
379
|
An integer is interpreted as NCBI codon table ID.
|
|
374
|
-
|
|
380
|
+
|
|
375
381
|
Returns
|
|
376
382
|
-------
|
|
377
383
|
table : CodonTable
|
|
@@ -380,7 +386,7 @@ class CodonTable(object):
|
|
|
380
386
|
# Loads codon tables from codon_tables.txt
|
|
381
387
|
with open(CodonTable._table_file, "r") as f:
|
|
382
388
|
lines = f.read().split("\n")
|
|
383
|
-
|
|
389
|
+
|
|
384
390
|
# Extract data for codon table from file
|
|
385
391
|
table_found = False
|
|
386
392
|
aa = None
|
|
@@ -391,11 +397,11 @@ class CodonTable(object):
|
|
|
391
397
|
for line in lines:
|
|
392
398
|
if not line:
|
|
393
399
|
table_found = False
|
|
394
|
-
if
|
|
400
|
+
if isinstance(table_name, Integral) and line.startswith("id"):
|
|
395
401
|
# remove identifier 'id'
|
|
396
402
|
if table_name == int(line[2:]):
|
|
397
403
|
table_found = True
|
|
398
|
-
elif
|
|
404
|
+
elif isinstance(table_name, str) and line.startswith("name"):
|
|
399
405
|
# Get list of table names from lines
|
|
400
406
|
# (separated with ';')
|
|
401
407
|
# remove identifier 'name'
|
|
@@ -404,7 +410,7 @@ class CodonTable(object):
|
|
|
404
410
|
table_found = True
|
|
405
411
|
if table_found:
|
|
406
412
|
if line.startswith("AA"):
|
|
407
|
-
#Remove identifier
|
|
413
|
+
# Remove identifier
|
|
408
414
|
aa = line[5:].strip()
|
|
409
415
|
elif line.startswith("Init"):
|
|
410
416
|
init = line[5:].strip()
|
|
@@ -414,19 +420,24 @@ class CodonTable(object):
|
|
|
414
420
|
base2 = line[5:].strip()
|
|
415
421
|
elif line.startswith("Base3"):
|
|
416
422
|
base3 = line[5:].strip()
|
|
417
|
-
|
|
423
|
+
|
|
418
424
|
# Create codon table from data
|
|
419
|
-
if
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
425
|
+
if (
|
|
426
|
+
aa is not None
|
|
427
|
+
and init is not None
|
|
428
|
+
and base1 is not None
|
|
429
|
+
and base2 is not None
|
|
430
|
+
and base3 is not None
|
|
431
|
+
):
|
|
432
|
+
symbol_dict = {}
|
|
433
|
+
starts = []
|
|
434
|
+
# aa, init and baseX all have the same length
|
|
435
|
+
for i in range(len(aa)):
|
|
436
|
+
codon = base1[i] + base2[i] + base3[i]
|
|
437
|
+
if init[i] == "i":
|
|
438
|
+
starts.append(codon)
|
|
439
|
+
symbol_dict[codon] = aa[i]
|
|
440
|
+
return CodonTable(symbol_dict, starts)
|
|
430
441
|
else:
|
|
431
442
|
raise ValueError(f"Codon table '{table_name}' was not found")
|
|
432
443
|
|
|
@@ -434,7 +445,7 @@ class CodonTable(object):
|
|
|
434
445
|
def table_names():
|
|
435
446
|
"""
|
|
436
447
|
The possible codon table names for :func:`load()`.
|
|
437
|
-
|
|
448
|
+
|
|
438
449
|
Returns
|
|
439
450
|
-------
|
|
440
451
|
names : list of str
|
|
@@ -447,14 +458,14 @@ class CodonTable(object):
|
|
|
447
458
|
if line.startswith("name"):
|
|
448
459
|
names.extend([name.strip() for name in line[4:].split(";")])
|
|
449
460
|
return names
|
|
450
|
-
|
|
461
|
+
|
|
451
462
|
@staticmethod
|
|
452
463
|
def default_table():
|
|
453
464
|
"""
|
|
454
465
|
The default codon table.
|
|
455
466
|
The table is equal to the NCBI "Standard" codon table,
|
|
456
467
|
with the difference that only "ATG" is a start codon.
|
|
457
|
-
|
|
468
|
+
|
|
458
469
|
Returns
|
|
459
470
|
-------
|
|
460
471
|
table : CodonTable
|