Skip to content

Commit

Permalink
feat: set minimum 3 prime region length to 8, added context to docstring
Browse files Browse the repository at this point in the history
  • Loading branch information
ameynert committed Jan 11, 2025
1 parent c9075ac commit ac16e3c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
17 changes: 11 additions & 6 deletions prymer/offtarget/offtarget_detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@
ReferenceName: TypeAlias = str
"""Alias for a reference sequence name."""

MINIMUM_THREE_PRIME_REGION_LENGTH: int = 8
"""Minimum allowable seed length for the 3' region."""


@dataclass(init=True, frozen=True)
class OffTargetResult:
Expand Down Expand Up @@ -189,6 +192,8 @@ def __init__( # noqa: C901
3. Checking of primer pairs: `max_primer_hits`, `min_primer_pair_hits`,
`max_primer_pair_hits`, and `max_amplicon_size`.
The `three_prime_region_length` parameter is used as the seed length for `bwa aln`.
Args:
ref: the reference genome fasta file (must be indexed with BWA)
max_primer_hits: the maximum number of hits an individual primer can have in the genome
Expand All @@ -204,8 +209,8 @@ def __init__( # noqa: C901
reference sequence, it may be appropriate to set this value to 0. Must be greater
than or equal to 0.
three_prime_region_length: the number of bases at the 3' end of the primer in which the
parameter `max_mismatches_in_three_prime_region` is evaluated. Must be greater than
0.
parameter `max_mismatches_in_three_prime_region` is evaluated. This value is used as
the seed length (`bwa aln -l`). Must be a minimum of 8.
max_mismatches_in_three_prime_region: the maximum number of mismatches that are
tolerated in the three prime region of each primer defined by
`three_prime_region_length`. Must be between 0 and `three_prime_region_length`,
Expand All @@ -232,7 +237,7 @@ def __init__( # noqa: C901
ValueError: If `max_amplicon_size` is not greater than 0.
ValueError: If any of `max_primer_hits`, `max_primer_pair_hits`, or
`min_primer_pair_hits` are not greater than or equal to 0.
ValueError: If `three_prime_region_length` is not greater than 0.
ValueError: If `three_prime_region_length` is not greater than or equal to 8.
ValueError: If `max_mismatches_in_three_prime_region` is outside the range 0 to
`three_prime_region_length`, inclusive.
ValueError: If `max_mismatches` is not greater than or equal to 0.
Expand All @@ -256,10 +261,10 @@ def __init__( # noqa: C901
"'min_primer_pair_hits' must be greater than or equal to 0. "
f"Saw {min_primer_pair_hits}"
)
if three_prime_region_length < 1:
if three_prime_region_length < MINIMUM_THREE_PRIME_REGION_LENGTH:
errors.append(
"'three_prime_region_length' must be greater than 0. "
f"Saw {three_prime_region_length}"
"'three_prime_region_length' must be greater than or equal to "
f"{MINIMUM_THREE_PRIME_REGION_LENGTH}. Saw {three_prime_region_length}"
)
if (
max_mismatches_in_three_prime_region < 0
Expand Down
2 changes: 1 addition & 1 deletion tests/offtarget/test_offtarget.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ class CustomPrimer(Oligo):
(-1, 1, 1, 20, 0, 0, 1, 0, 0, "'max_primer_hits' must be greater than or equal to 0. Saw -1"), # noqa: E501
(1, -1, 1, 20, 0, 0, 1, 0, 0, "'max_primer_pair_hits' must be greater than or equal to 0. Saw -1"), # noqa: E501
(1, 1, -1, 20, 0, 0, 1, 0, 0, "'min_primer_pair_hits' must be greater than or equal to 0. Saw -1"), # noqa: E501
(1, 1, 1, 0, 0, 0, 1, 0, 0, "'three_prime_region_length' must be greater than 0. Saw 0"),
(1, 1, 1, 5, 0, 0, 1, 0, 0, "'three_prime_region_length' must be greater than or equal to 8. Saw 5"), # noqa: E501
(1, 1, 1, 20, -1, 0, 1, 0, 0, "'max_mismatches_in_three_prime_region' must be between 0 and 'three_prime_region_length'=20 inclusive. Saw -1"), # noqa: E501
(1, 1, 1, 20, 21, 0, 1, 0, 0, "'max_mismatches_in_three_prime_region' must be between 0 and 'three_prime_region_length'=20 inclusive. Saw 21"), # noqa: E501
(1, 1, 1, 20, 0, -1, 1, 0, 0, "'max_mismatches' must be greater than or equal to 0. Saw -1"), # noqa: E501
Expand Down

0 comments on commit ac16e3c

Please sign in to comment.