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

Edinburgh-Genome-Foundry / DnaChisel / 5190565251

pending completion
5190565251

push

github

veghp
Bump to v3.2.11

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

2966 of 3299 relevant lines covered (89.91%)

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

43
    method
44
      Either 'use_best_codon', 'match_codon_usage', or 'harmonize_rca'
45
      (see above for details)
46

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

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

62
    original_species
63
      When the method is 'harmonize_rca', this is the native species of the
64
      original coding sequence. Same characteristics as parameter ``species``
65
      above.
66
  
67
    original_codon_usage_table
68
      Optional codon usage table of the original sequence's native species.
69
      A dict of the form ``{'*': {"TGA": 0.112, "TAA": 0.68}, 'K': ...}``
70
      giving the codon usage table.
71
  
72
    References
73
    ==========
74
  
75
    Claassens et. al., Improving heterologous membrane protein
76
    production in Escherichia coli by combining transcriptional tuning and
77
    codon usage algorithms. PLOS One, 2017
78

79
    Hale and Thompson, Codon Optimization of the Gene Encoding a
80
    Domain from Human Type 1 Neurofibromin Protein... Protein Expression and
81
    Purification 1998.
82

83
    """
84
    if method == "use_best_codon":
1✔
85
        return MaximizeCAI(
1✔
86
            species=species,
87
            location=location,
88
            codon_usage_table=codon_usage_table,
89
            boost=boost,
90
        )
91

92
    elif method == "match_codon_usage":
1✔
93
        return MatchTargetCodonUsage(
1✔
94
            species=species,
95
            location=location,
96
            codon_usage_table=codon_usage_table,
97
            boost=boost,
98
        )
99
    elif method == "harmonize_rca":
1✔
100
        return HarmonizeRCA(
1✔
101
            species=species,
102
            location=location,
103
            codon_usage_table=codon_usage_table,
104
            original_species=original_species,
105
            original_codon_usage_table=original_codon_usage_table,
106
            boost=boost,
107
        )
108
    raise ValueError("Parameter 'mode' should be one of best_codon, "
×
109
                     "match_usage, ")
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

© 2025 Coveralls, Inc