diff --git a/src/alignment.cpp b/src/alignment.cpp index b9dce5a260..e8a1496793 100644 --- a/src/alignment.cpp +++ b/src/alignment.cpp @@ -1321,8 +1321,10 @@ pair compute_template_lengths(const int64_t& pos1, const vecto // And find the distance int32_t dist = max_end - min_start; - if (pos1 < pos2) { - // Count read 1 as the overall "leftmost", so its value will be positive + if (bounds1.first < bounds2.first || (bounds1.first == bounds2.first && bounds1.second < bounds2.second)) { + // Count read 1 as the overall "leftmost" if it starts earlier or + // starts at the same point and ends earlier, so its value will be + // positive return make_pair(dist, -dist); } else { // Count read 2 as the overall leftmost diff --git a/src/unittest/alignment.cpp b/src/unittest/alignment.cpp index a4b19df860..a29441977c 100644 --- a/src/unittest/alignment.cpp +++ b/src/unittest/alignment.cpp @@ -335,8 +335,8 @@ TEST_CASE("Template length for HTS output formats is outermost to outermost when TEST_CASE("Template length for HTS output formats is outermost to outermost when read 2 is a suffix of read 1", "[alignment][tlen]") { auto lengths = compute_template_lengths(1000, {{151, 'M'}}, 1141, {{10, 'M'}}); - REQUIRE(lengths.first == -151); // Read 1 is the leftmost since it starts earliest - REQUIRE(lengths.second == 151); + REQUIRE(lengths.first == 151); // Read 1 is the leftmost since it starts earliest + REQUIRE(lengths.second == -151); } TEST_CASE("Template length for HTS output formats is outermost to outermost when read 1 and read 2 have identical coordinates", "[alignment][tlen]") {