Skip to content

Commit

Permalink
Fix asserts when aligning an empty sequence (#383)
Browse files Browse the repository at this point in the history
  • Loading branch information
hmusta authored Feb 5, 2022
1 parent cbca6d6 commit d4ffe55
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
5 changes: 3 additions & 2 deletions metagraph/src/graph/alignment/aligner_extender_methods.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ DefaultColumnExtender::DefaultColumnExtender(const DeBruijnGraph &graph,
[&](char c) { return config_.get_row(c)[c]; });

std::partial_sum(partial_sums_.rbegin(), partial_sums_.rend(), partial_sums_.rbegin());
assert(config_.match_score(query_) == partial_sums_.front());
assert(config_.get_row(query_.back())[query_.back()] == partial_sums_.back());
assert(query_.empty() || config_.match_score(query_) == partial_sums_.front());
assert(query_.empty() || config_.get_row(query_.back())[query_.back()] == partial_sums_.back());

partial_sums_.push_back(0);

// precompute profiles to store match/mismatch scores and Cigar::Operators
Expand Down
2 changes: 1 addition & 1 deletion metagraph/src/graph/alignment/aligner_seeder_methods.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ ExactSeeder::ExactSeeder(const DeBruijnGraph &graph,

std::partial_sum(partial_sum_.begin(), partial_sum_.end(), partial_sum_.begin());
assert(config_.match_score(query_) == partial_sum_.back());
assert(config_.get_row(query_.front())[query_.front()] == partial_sum_[1]);
assert(query_.empty() || config_.get_row(query_.front())[query_.front()] == partial_sum_[1]);
assert(!partial_sum_.front());
}

Expand Down
13 changes: 13 additions & 0 deletions metagraph/tests/graph/test_aligner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,19 @@ TYPED_TEST(DBGAlignerTest, bad_min_cell_score) {
ASSERT_THROW(DBGAligner<>(*graph, config), std::runtime_error);
}

TYPED_TEST(DBGAlignerTest, align_empty) {
size_t k = 4;
std::string reference = "CATTT";
std::string query;

auto graph = build_graph_batch<TypeParam>(k, { reference });
DBGAlignerConfig config(DBGAlignerConfig::dna_scoring_matrix(2, -1, -2));
DBGAligner<> aligner(*graph, config);
auto paths = aligner.align(query);

EXPECT_EQ(0ull, paths.size());
}

TYPED_TEST(DBGAlignerTest, align_sequence_much_too_short) {
size_t k = 4;
std::string reference = "CATTT";
Expand Down

0 comments on commit d4ffe55

Please sign in to comment.