Skip to content

Commit

Permalink
Improved error checking
Browse files Browse the repository at this point in the history
  • Loading branch information
vellamike committed Jan 11, 2024
1 parent e143c83 commit 95075ea
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
9 changes: 7 additions & 2 deletions dorado/utils/sequence_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,11 @@ std::tuple<int, int, std::vector<uint8_t>> realign_moves(const std::string& quer
query_sequence,
target_sequence); // We are going to compute the overlap between the two reads

auto failed_realignment = std::make_tuple(-1, -1, std::vector<uint8_t>());
// No overlap was computed, so return the tuple (-1, -1) and an empty vector to indicate that no move table realignment was computed
if (!is_overlap) {
return failed_realignment;
}
// Advance the query and target position.
++query_start;
++target_start;
Expand All @@ -264,8 +269,8 @@ std::tuple<int, int, std::vector<uint8_t>> realign_moves(const std::string& quer
// Free the memory allocated by edlibAlign
edlibFreeAlignResult(edlib_result);

// Return the tuple (-1, -1) and an empty vector
return std::make_tuple(-1, -1, std::vector<uint8_t>());
// Return the tuple (-1, -1) and an empty vector to indicate that no move table realignment was computed
return failed_realignment;
}

// Let's keep two cursor positions - one for the new move table and one for the old:
Expand Down
15 changes: 9 additions & 6 deletions tests/RealignMovesTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ TEST_CASE("Realign Moves No Error", TEST_GROUP) {
std::vector<uint8_t> moves = {1, 0, 1, 0, 1, 0, 0, 1}; // Example moves vector

// Test that calling realign_moves does not throw any exceptions
REQUIRE_NOTHROW(utils::realign_moves(query_sequence, target_sequence, moves));
CHECK_NOTHROW(utils::realign_moves(query_sequence, target_sequence, moves));
}

TEST_CASE("No alignment doesn't produce an error", TEST_GROUP) {
Expand All @@ -26,10 +26,13 @@ TEST_CASE("No alignment doesn't produce an error", TEST_GROUP) {
REQUIRE_NOTHROW(utils::realign_moves(query_sequence, target_sequence, moves));

// Call the function and store the result
auto result = utils::realign_moves(query_sequence, target_sequence, moves);
int move_offset, target_start;
std::vector<uint8_t> new_moves;

CHECK_NOTHROW(std::tie(move_offset, target_start, new_moves) =
utils::realign_moves(query_sequence, target_sequence, moves));

// Check that the returned tuple has the expected values
REQUIRE(std::get<0>(result) == -1); // Check the first value of the tuple
REQUIRE(std::get<1>(result) == -1); // Check the second value of the tuple
REQUIRE(std::get<2>(result).empty()); // Check that the vector in the tuple is empty
CHECK(move_offset == -1);
CHECK(target_start == -1);
CHECK(new_moves.empty());
}

0 comments on commit 95075ea

Please sign in to comment.