Skip to content

Commit

Permalink
Fix for ok_regions with not matching product size
Browse files Browse the repository at this point in the history
  • Loading branch information
untergasser committed Sep 25, 2024
1 parent 2534eaa commit e1232c2
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 19 deletions.
55 changes: 36 additions & 19 deletions src/libprimer3.cc
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ static void _adjust_seq_args(const p3_global_settings *pa,
pr_append_str *warning);

static void _optimize_ok_regions_list(const p3_global_settings *pa,
seq_args *sa);
seq_args *sa,
pr_append_str *warning);

static int any_5_prime_ol_extension_has_problem(const primer_rec *);

Expand Down Expand Up @@ -6640,7 +6641,7 @@ _adjust_seq_args(const p3_global_settings *pa,

/* Update ok regions, if non empty */
if (sa->ok_regions.count > 0) {
_optimize_ok_regions_list(pa, sa);
_optimize_ok_regions_list(pa, sa, warning);
}

}
Expand All @@ -6652,8 +6653,10 @@ _adjust_seq_args(const p3_global_settings *pa,
*/
static void
_optimize_ok_regions_list(const p3_global_settings *pa,
seq_args *sa)
seq_args *sa,
pr_append_str *warning)
{
char buffer[255];
/* We do this only if we enabled the optimization and
* the primers were NOT specified. */
if (!OPTIMIZE_OK_REGIONS || (sa->left_input) || (sa->right_input)) {
Expand Down Expand Up @@ -6696,8 +6699,8 @@ _optimize_ok_regions_list(const p3_global_settings *pa,
new_rs = ls + pmin - omax - 1; /* -1 just to be safe */
new_re = le - omin + pmax + 1; /* +1 just to be safe */
/* Adjust the ranges */
if ((rs == -1) || (new_rs > rs)) { rs = new_rs; }
if ((re == -1) || (new_re < re)) { re = new_re; }
if (((rs == -1) || (new_rs > rs)) && ((new_rs < re - omin) || (re < omin))) { rs = new_rs; }
if (((re == -1) || (new_re < re)) && (rs < new_re)) { re = new_re; }
if (rs < 0) { rs = 0; }
if (re > (signed) strlen(sa->sequence)) { re = strlen(sa->sequence); }
}
Expand All @@ -6707,26 +6710,40 @@ _optimize_ok_regions_list(const p3_global_settings *pa,
new_ls = rs + omin - pmax - 1; /* -1 just to be safe */
new_le = re - pmin + omax + 1; /* +1 just to be safe */
/* Adjust the ranges */
if ((ls == -1) || (new_ls > ls)) { ls = new_ls; }
if ((le == -1) || (new_le < le)) { le = new_le; }
if (((ls == -1) || (new_ls > ls)) && ((new_ls < le - omin) || (le < omin))) { ls = new_ls; }
if (((le == -1) || (new_le < le)) && (ls < new_le)) { le = new_le; }
if (ls < 0) { ls = 0; }
if (le > (signed) strlen(sa->sequence)) { le = strlen(sa->sequence); }
}
/* Temporary testing fprintf: */
/* fprintf(stderr, "Adjusted range [%d,%d,%d,%d] to [%d,%d,%d,%d],
pmin is %d, pmax is %d, omin is %d, omax is %d\n",
sa->ok_regions.left_pairs[i][0],
sa->ok_regions.left_pairs[i][0] +
sa->ok_regions.left_pairs[i][1] - 1,
sa->ok_regions.right_pairs[i][0],
sa->ok_regions.right_pairs[i][0] +
sa->ok_regions.right_pairs[i][1] - 1, ls, le, rs, re,
/* fprintf(stderr, "Adjusted range [%d,%d,%d,%d] to [%d,%d,%d,%d], \
pmin is %d, pmax is %d, omin is %d, omax is %d\n", \
sa->ok_regions.left_pairs[i][0], \
sa->ok_regions.left_pairs[i][0] + \
sa->ok_regions.left_pairs[i][1] - 1, \
sa->ok_regions.right_pairs[i][0], \
sa->ok_regions.right_pairs[i][0] + \
sa->ok_regions.right_pairs[i][1] - 1, ls, le, rs, re, \
pmin, pmax, omin, omax);
*/
sa->ok_regions.left_pairs[i][0] = ls;
sa->ok_regions.left_pairs[i][1] = le - ls + 1;
sa->ok_regions.right_pairs[i][0] = rs;
sa->ok_regions.right_pairs[i][1] = re - rs + 1;

if ((pmax > rs - le) && (pmin < re - ls + 1)) {
sa->ok_regions.left_pairs[i][0] = ls;
sa->ok_regions.left_pairs[i][1] = le - ls + 1;
sa->ok_regions.right_pairs[i][0] = rs;
sa->ok_regions.right_pairs[i][1] = re - rs + 1;
} else {
snprintf(buffer, 255, "PAIR_OK_REGIONS[%d,%d,%d,%d] does not allow products of %d-%dbp", \
sa->ok_regions.left_pairs[i][0], \
sa->ok_regions.left_pairs[i][1], \
sa->ok_regions.right_pairs[i][0], \
sa->ok_regions.right_pairs[i][1], \
pmin, \
pmax);
sa->ok_regions.left_pairs[i][1] = 1;
sa->ok_regions.right_pairs[i][1] = 1;
pr_append_new_chunk(warning, buffer);
}
}
/* any_left and any_right not true anymore */
sa->ok_regions.any_left = 0;
Expand Down
2 changes: 2 additions & 0 deletions test/primer_ok_regions2_output
Original file line number Diff line number Diff line change
Expand Up @@ -23242,6 +23242,7 @@ PRIMER_MAX_SELF_END=100
PRIMER_PAIR_MAX_COMPL_END=100
SEQUENCE_PRIMER_PAIR_OK_REGION_LIST=238,20,400,20
PRIMER_EXPLAIN_FLAG=1
PRIMER_WARNING=PAIR_OK_REGIONS[238,20,400,20] does not allow products of 200-200bp
PRIMER_LEFT_EXPLAIN=considered 2261, not in any ok left region 2261, ok 0
PRIMER_RIGHT_EXPLAIN=considered 2261, not in any ok right region 2261, ok 0
PRIMER_PAIR_EXPLAIN=considered 0, ok 0
Expand Down Expand Up @@ -23305,6 +23306,7 @@ PRIMER_MAX_SELF_END=100
PRIMER_PAIR_MAX_COMPL_END=100
SEQUENCE_PRIMER_PAIR_OK_REGION_LIST=238,20,400,20;238,20,,
PRIMER_EXPLAIN_FLAG=1
PRIMER_WARNING=PAIR_OK_REGIONS[238,20,400,20] does not allow products of 200-200bp
PRIMER_LEFT_EXPLAIN=considered 2261, not in any ok left region 2260, ok 1
PRIMER_RIGHT_EXPLAIN=considered 2261, not in any ok right region 2258, ok 3
PRIMER_PAIR_EXPLAIN=considered 3, unacceptable product size 2, ok 1
Expand Down

0 comments on commit e1232c2

Please sign in to comment.