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

Edinburgh-Genome-Foundry / DnaChisel / 14225166311

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

push

github

veghp
Switch to Sphinx

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

77.42
/dnachisel/builtin_specifications/AvoidHeterodimerization.py
1
try:
1✔
2
    import primer3
1✔
3

4
    PRIMER3_AVAILABLE = True
1✔
5
except (ImportError, OSError):
×
6
    primer3 = None
×
7

8
from ..Specification import Specification, SpecEvaluation
1✔
9

10

11
class AvoidHeterodimerization(Specification):
1✔
12
    """Avoid that the (sub)sequence anneals with other primers.
13

14
    Parameters
15
    ----------
16

17
    other_primers_sequences
18
      List of ATGC strings representing the sequences of the other primers
19
      with which annealing will be avoided.
20

21
    tmax
22
      Maximal melting temperature of the interaction between the (sub)sequence
23
      and the other_primers_sequences.
24

25
    location
26
      Location of the subsequence to be optimized.
27

28
    boost
29
      Multiplicator for this specification's score when used in a
30
      multi-objective optimization.
31
    """
32

33
    def __init__(self, other_primers_sequences, tmax=5, location=None, boost=1.0):
1✔
34
        self.other_primers_sequences = other_primers_sequences
1✔
35
        self.tmax = tmax
1✔
36
        self.location = location
1✔
37
        self.boost = boost
1✔
38

39
    def initialized_on_problem(self, problem, role=None):
1✔
40
        return self._copy_with_full_span_if_no_location(problem)
1✔
41

42
    def localize(self, location, problem=None):
1✔
43
        if self.location.overlap_region(location) is None:
×
44
            return None
×
45
        else:
46
            return self
×
47

48
    def evaluate(self, problem):
1✔
49
        if not PRIMER3_AVAILABLE:
1✔
50
            raise ImportError(
×
51
                "Using avoid_heterodimerization requires primer3"
52
                " installed (pip install primer3-py)"
53
            )
54
        if len(self.other_primers_sequences) == 0:
1✔
55
            return SpecEvaluation(
1✔
56
                specification=self,
57
                problem=problem,
58
                score=0,
59
                locations=[self.location],
60
                message="No existing primer",
61
            )
62
        sequence = self.location.extract_sequence(problem.sequence)
1✔
63
        melting_temps = [
1✔
64
            primer3.calcHeterodimer(sequence, other_seq).tm
65
            for other_seq in self.other_primers_sequences
66
        ]
67
        largest_tm = max(melting_temps)
1✔
68
        # hackish penalty to guide optimization:
69
        penalty = 0.001 * sum(melting_temps) / len(melting_temps)
1✔
70
        score = self.tmax - largest_tm - penalty
1✔
71
        return SpecEvaluation(
1✔
72
            specification=self,
73
            problem=problem,
74
            score=score,
75
            locations=[self.location],
76
            message="Largest Tm = %.1f " % largest_tm,
77
        )
78

79
    def label_parameters(self):
1✔
80
        return [
×
81
            ("primers", len(self.other_primers_sequences)),
82
            ("tmax", self.tmax),
83
        ]
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