Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/randstrobes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,14 @@ std::ostream& operator<<(std::ostream& os, const QueryRandstrobe& randstrobe) {
return os;
}

Randstrobe make_randstrobe(Syncmer strobe1, Syncmer strobe2) {
return Randstrobe{
randstrobe_hash(strobe1.hash, strobe2.hash),
static_cast<uint32_t>(strobe1.position),
static_cast<uint32_t>(strobe2.position)
};
}

Randstrobe RandstrobeIterator::get(unsigned int strobe1_index) const {
unsigned int w_end = std::min(static_cast<size_t>(strobe1_index + w_max), syncmers.size() - 1);

Expand All @@ -167,7 +175,7 @@ Randstrobe RandstrobeIterator::get(unsigned int strobe1_index) const {
}
}

return Randstrobe{randstrobe_hash(strobe1.hash, strobe2.hash), static_cast<uint32_t>(strobe1.position), static_cast<uint32_t>(strobe2.position)};
return make_randstrobe(strobe1, strobe2);
}

Randstrobe RandstrobeGenerator::next() {
Expand Down Expand Up @@ -198,7 +206,8 @@ Randstrobe RandstrobeGenerator::next() {
}
}
syncmers.pop_front();
return Randstrobe{randstrobe_hash(strobe1.hash, strobe2.hash), static_cast<uint32_t>(strobe1.position), static_cast<uint32_t>(strobe2.position)};

return make_randstrobe(strobe1, strobe2);
}

/*
Expand Down
35 changes: 35 additions & 0 deletions tests/tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,41 @@ TEST_CASE("read_/write_vector") {
CHECK(y == expected);
}

TEST_CASE("RandstrobeGenerator is sane") {
auto references = References::from_fasta("tests/phix.fasta");
auto& seq = references.sequences[0];
auto parameters = IndexParameters::from_read_length(300);

RandstrobeGenerator iter{seq, parameters.syncmer, parameters.randstrobe};

Randstrobe randstrobe;
while ((randstrobe = iter.next()) != iter.end()) {
CHECK(randstrobe.hash > 0);
CHECK(randstrobe.strobe1_pos >= 0);
CHECK(randstrobe.strobe2_pos >= randstrobe.strobe2_pos);
CHECK(randstrobe.strobe1_pos < seq.length());
CHECK(randstrobe.strobe2_pos < seq.length());
}
}

TEST_CASE("RandstrobeIterator is sane") {
auto references = References::from_fasta("tests/phix.fasta");
auto& seq = references.sequences[0];
auto parameters = IndexParameters::from_read_length(300);

auto syncmers = canonical_syncmers(seq, parameters.syncmer);
RandstrobeIterator iter{syncmers, parameters.randstrobe};

while (iter.has_next()) {
auto randstrobe = iter.next();
CHECK(randstrobe.hash > 0);
CHECK(randstrobe.strobe1_pos >= 0);
CHECK(randstrobe.strobe2_pos >= randstrobe.strobe2_pos);
CHECK(randstrobe.strobe1_pos < seq.length());
CHECK(randstrobe.strobe2_pos < seq.length());
}
}

TEST_CASE("both randstrobes iterator implementations give same results") {
auto references = References::from_fasta("tests/phix.fasta");
auto& seq = references.sequences[0];
Expand Down