Skip to content

Commit

Permalink
refactor: make amplicon a cached property
Browse files Browse the repository at this point in the history
  • Loading branch information
msto committed Nov 18, 2024
1 parent 534d516 commit 8318695
Showing 1 changed file with 4 additions and 15 deletions.
19 changes: 4 additions & 15 deletions prymer/api/primer_pair.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ class methods to represent a primer pair. The primer pair is comprised of a lef
""" # noqa: E501

from dataclasses import dataclass
from dataclasses import field
from dataclasses import replace
from functools import cached_property
from typing import Iterator
from typing import Optional

Expand All @@ -55,7 +55,7 @@ class methods to represent a primer pair. The primer pair is comprised of a lef
from prymer.api.span import Span


@dataclass(frozen=True, init=True, kw_only=True, slots=True)
@dataclass(frozen=True, init=True, kw_only=True)
class PrimerPair(OligoLike):
"""
Represents a pair of primers that work together to amplify an amplicon. The
Expand All @@ -79,22 +79,11 @@ class PrimerPair(OligoLike):
amplicon_tm: float
penalty: float
amplicon_sequence: Optional[str] = None
_amplicon: Span = field(init=False)

def __post_init__(self) -> None:
# Derive the amplicon from the left and right primers. This must be done before
# calling super() as `PrimerLike.id` depends on the amplicon being set
object.__setattr__(
self,
"_amplicon",
PrimerPair.calculate_amplicon_span(self.left_primer, self.right_primer),
)
super(PrimerPair, self).__post_init__()

@property
@cached_property
def amplicon(self) -> Span:
"""Returns the mapping for the amplicon"""
return self._amplicon
return self.calculate_amplicon_span(self.left_primer, self.right_primer)

@property
def span(self) -> Span:
Expand Down

0 comments on commit 8318695

Please sign in to comment.