Skip to content

Commit

Permalink
Pick one paired-end alignment randomly if there are multiple
Browse files Browse the repository at this point in the history
equally good ones

Closes #359
  • Loading branch information
marcelm committed Nov 20, 2023
1 parent 451aed3 commit bdd4a5b
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/aln.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,8 @@ inline void align_PE(
float dropoff,
InsertSizeDistribution &isize_est,
unsigned max_tries,
size_t max_secondary
size_t max_secondary,
std::minstd_rand& random_engine
) {
const auto mu = isize_est.mu;
const auto sigma = isize_est.sigma;
Expand Down Expand Up @@ -912,6 +913,23 @@ inline void align_PE(
high_scores.resize(j);
}

// If there are multiple top-scoring alignments with the same score,
// pick one randomly
{
size_t i = 1;
for ( ; i < high_scores.size(); ++i) {
if (high_scores[i].score != high_scores[0].score) {
break;
}
}
if (i > 1) {
size_t random_index = std::uniform_int_distribution<>(0, i - 1)(random_engine);
if (random_index != 0) {
std::swap(high_scores[0], high_scores[random_index]);
}
}
}

auto [mapq1, mapq2] = joint_mapq_from_high_scores(high_scores);
auto best_aln_pair = high_scores[0];
auto alignment1 = best_aln_pair.alignment1;
Expand Down Expand Up @@ -1093,7 +1111,7 @@ void align_PE_read(
record2,
index_parameters.syncmer.k,
references, details,
map_param.dropoff_threshold, isize_est, map_param.max_tries, map_param.max_secondary);
map_param.dropoff_threshold, isize_est, map_param.max_tries, map_param.max_secondary, random_engine);
}
statistics.tot_extend += extend_timer.duration();
statistics += details[0];
Expand Down

0 comments on commit bdd4a5b

Please sign in to comment.