• 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

95.0
/dnachisel/builtin_specifications/codon_optimization/BaseCodonOptimizationClass.py
1
from ..CodonSpecification import CodonSpecification
1✔
2
from python_codon_tables import get_codons_table
1✔
3
import numpy as np
1✔
4
from ...Location import Location
1✔
5
from ...biotools import group_nearby_indices
1✔
6

7

8
class BaseCodonOptimizationClass(CodonSpecification):
1✔
9

10
    best_possible_score = 0  # Don't forget to change in subclasses if needed
1✔
11
    localization_group_spread = 3
1✔
12

13
    def __init__(self, species=None, location=None, codon_usage_table=None, boost=1.0):
1✔
14
        self.boost = boost
1✔
15
        self.location = Location.from_data(location)
1✔
16
        self.species = species
1✔
17
        self.codon_usage_table = self.get_codons_table(species, codon_usage_table)
1✔
18

19
    def get_codons(self, problem):
1✔
20
        subsequence = self.location.extract_sequence(problem.sequence)
1✔
21
        if len(subsequence) % 3:
1✔
UNCOV
22
            raise ValueError(
×
23
                "Spec. %s is on a window/sequence with size not multiple of 3)"
24
                % (self.label())
25
            )
26
        return [
1✔
27
            subsequence[3 * i : 3 * (i + 1)] for i in range(int(len(subsequence) / 3))
28
        ]
29

30
    @staticmethod
1✔
31
    def get_codons_table(species, codon_usage_table):
1✔
32
        if codon_usage_table is None:
1✔
33
            if species is None:
1✔
UNCOV
34
                raise ValueError(
×
35
                    "Provide either an species name or a codon usage table"
36
                )
37
            else:
38
                codon_usage_table = get_codons_table(species)
1✔
39
        return codon_usage_table
1✔
40

41
    def initialized_on_problem(self, problem, role):
1✔
42
        """Get location from sequence if no location provided."""
43
        return self._copy_with_full_span_if_no_location(problem)
1✔
44

45
    def codons_indices_to_locations(self, indices):
1✔
46
        """Convert a list of codon positions to a list of Locations"""
47
        indices = np.array(indices)
1✔
48
        if self.location.strand == -1:
1✔
49
            indices = sorted(self.location.end - 3 * indices)
1✔
50
            return [
1✔
51
                Location(group[0] - 3, group[-1], strand=-1)
52
                for group in group_nearby_indices(
53
                    indices, max_group_spread=self.localization_group_spread
54
                )
55
            ]
56
        else:
57
            indices = self.location.start + 3 * indices
1✔
58
            return [
1✔
59
                Location(group[0], group[-1] + 3)
60
                for group in group_nearby_indices(
61
                    indices, max_group_spread=self.localization_group_spread
62
                )
63
            ]
64

65
    def get_codons_synonyms(self):
1✔
66
        """Return a dict {"GTG": [GTG, GTC, ...]} of synonymous codons."""
67
        return {
1✔
68
            codon: [c for c in aa_codons]
69
            for aa, aa_codons in self.codon_usage_table.items()
70
            if len(aa) == 1
71
            for codon in aa_codons
72
        }
73

74
    def get_codons_translations(self):
1✔
75
        """Return a dict {"ATG": "M", "TAG": "*", ...}."""
76
        return {
1✔
77
            codon: aa
78
            for aa, aa_codons in self.codon_usage_table.items()
79
            if len(aa) == 1
80
            for codon in aa_codons.keys()
81
        }
82

83
    def localized_on_window(self, new_location, start_codon, end_codon):
1✔
84
        """Relocate without changing much."""
85
        # The "new_location" already has exactly the right span and strand
86
        # thanks to superclass CodonSpecification
87
        return self.copy_with_changes(location=new_location)
1✔
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