• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Edinburgh-Genome-Foundry / DnaChisel / 14225235949

02 Apr 2025 04:56PM UTC coverage: 90.508% (+0.5%) from 90.054%
14225235949

push

github

veghp
Bump to v3.2.14

1 of 1 new or added line in 1 file covered. (100.0%)

101 existing lines in 35 files now uncovered.

2994 of 3308 relevant lines covered (90.51%)

0.91 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

90.91
/dnachisel/builtin_specifications/codon_optimization/CodonOptimize.py
1
from .HarmonizeRCA import HarmonizeRCA
1✔
2
from .MatchTargetCodonUsage import MatchTargetCodonUsage
1✔
3
from .MaximizeCAI import MaximizeCAI
1✔
4

5

6
def CodonOptimize(
1✔
7
    species=None,
8
    method="use_best_codon",
9
    location=None,
10
    codon_usage_table=None,
11
    original_species=None,
12
    original_codon_usage_table=None,
13
    boost=1.0,
14
):
15
    """Codon-optimize a coding sequence using a user-selected method.
16

17
    This pseudo-specification is actually a function which returns an instance
18
    of another specification class depending on the selected "method":
19

20
    - For method="use_best_codon", every codon will be replaced by the "best"
21
      (i.e. most frequent) synonymous codon in the target organism. This is
22
      equivalent to Codon Adaptation Index (CAI) optimization.
23
    - For method="match_codon_usage", the final sequence's codon usage will
24
      match as much as possible the codon usage profile of the target species
25
      (this method is used throughout the literature, see for instance Hale
26
      and Thomson 1998).
27
    - For method="harmonize_rca", Each codon will be replaced by a synonymous
28
      codon whose usage in the target organism matches the usage of the
29
      original codon in its host organism (as per Claassens 2017).
30

31
    Warning: always use this specification with an EnforceTranslation constraint
32
    defined over the same location, to preserve the amino acid sequence.
33

34

35
    Parameters
36
    ==========
37
    species
38
      Species for which the sequence will be codon-optimized.
39
      Either a TaxID (this requires a web connection as the corresponding table
40
      will be downloaded from the internet) or the name of the species to
41
      codon-optimize for (the name must be supported by ``python_codon_tables``
42
      e.g. ``e_coli``, ``s_cerevisiae``, ``h_sapiens``, ``c_elegans``,
43
      ``b_subtilis``, ``d_melanogaster``).
44
      Note that a ``codon_usage_table`` can be provided instead, or even in
45
      addition, for species whose codon usage table cannot be auto-imported.
46

47
    method
48
      Either 'use_best_codon', 'match_codon_usage', or 'harmonize_rca'
49
      (see above for details)
50

51
    location
52
      Either a DnaChisel Location or a tuple of the form (start, end, strand)
53
      or just (start, end), with strand defaulting to +1, indicating the
54
      position of the gene to codon-optimize. If not provided, the whole
55
      sequence is considered as the gene. The location should have a length
56
      that is a multiple of 3. The location strand is either 1 if the gene is
57
      encoded on the (+) strand, or -1 for antisense.
58

59
    codon_usage_table
60
      Optional codon usage table of the species for which the sequence will be
61
      codon-optimized, which can be provided instead of ``species``. A dict of
62
      the form ``{'*': {"TGA": 0.112, "TAA": 0.68}, 'K': ...}`` giving the codon
63
      frequency table (relative usage of each codon; frequencies add up to 1,
64
      separately for each amino acid). See parameter ``species`` above.
65

66
    original_species
67
      When the method is 'harmonize_rca', this is the native species of the
68
      original coding sequence. Same characteristics as parameter ``species``
69
      above.
70

71
    original_codon_usage_table
72
      Optional codon usage table of the original sequence's native species.
73
      A dict of the form ``{'*': {"TGA": 0.112, "TAA": 0.68}, 'K': ...}``
74
      giving the codon usage table.
75

76
    References
77
    ==========
78

79
    Claassens et. al., Improving heterologous membrane protein
80
    production in Escherichia coli by combining transcriptional tuning and
81
    codon usage algorithms. PLOS One, 2017
82

83
    Hale and Thompson, Codon Optimization of the Gene Encoding a
84
    Domain from Human Type 1 Neurofibromin Protein... Protein Expression and
85
    Purification 1998.
86

87
    """
88
    if method == "use_best_codon":
1✔
89
        return MaximizeCAI(
1✔
90
            species=species,
91
            location=location,
92
            codon_usage_table=codon_usage_table,
93
            boost=boost,
94
        )
95

96
    elif method == "match_codon_usage":
1✔
97
        return MatchTargetCodonUsage(
1✔
98
            species=species,
99
            location=location,
100
            codon_usage_table=codon_usage_table,
101
            boost=boost,
102
        )
103
    elif method == "harmonize_rca":
1✔
104
        return HarmonizeRCA(
1✔
105
            species=species,
106
            location=location,
107
            codon_usage_table=codon_usage_table,
108
            original_species=original_species,
109
            original_codon_usage_table=original_codon_usage_table,
110
            boost=boost,
111
        )
UNCOV
112
    raise ValueError(
×
113
        "`method` must be 'use_best_codon', 'match_codon_usage' "
114
        f"or 'harmonize_rca', not {method!r}"
115
    )
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc