Skip to content

Commit

Permalink
Improved code style in runs bugfix.
Browse files Browse the repository at this point in the history
  • Loading branch information
OndrejSladky committed Feb 12, 2024
1 parent 9e8919a commit 5f4647c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 33 deletions.
6 changes: 1 addition & 5 deletions src/parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,7 @@ std::pair<size_t, size_t> ReadIntervals(kh_O64_t *intervals, kh_S64_t *kMers, st
currentKMer |= data;
--beforeKMerEnd;
if (beforeKMerEnd == 0) {
bool represented = kh_get_S64(kMers, currentKMer) != kh_end(kMers);
if (!represented && complements) {
auto rc = ReverseComplement(currentKMer, k);
represented = kh_get_S64(kMers, rc) != kh_end(kMers);
}
bool represented = containsKMer(kMers, currentKMer, k, complements);
bool set = false;
if (represented) {
interval_used = true;
Expand Down
34 changes: 6 additions & 28 deletions tests/masks_unittest.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@ namespace {

TEST(Mask, OptimizeRuns) {
std::string path = std::filesystem::current_path();
path += "/tests/testdata/runstest.fa";

struct TestCase {
std::vector<kmer_t> kMers;
int k;
bool complements;
bool approximate;
std::string relativePath;
std::string wantResult;
};
std::vector<TestCase> tests = {
Expand All @@ -86,6 +86,7 @@ namespace {
KMerToNumber({"AT"})
},
2, false, false,
"/tests/testdata/runstest.fa",
"> superstring\nacgcgttACGtATt\n"
},
{
Expand All @@ -97,52 +98,29 @@ namespace {
KMerToNumber({"AT"})
},
2, false, true,
"/tests/testdata/runstest.fa",
"> superstring\nACgCGTtACGtATt\n"
},
};

for (auto &t : tests) {
std::stringstream of;
auto kMersDict = kh_init_S64();
int ret;
for (auto &kMer : t.kMers) kh_put_S64(kMersDict, kMer, &ret);

OptimizeRuns(path, kMersDict, of, t.k, t.complements, t.approximate);

EXPECT_EQ(t.wantResult, of.str());
}
}

TEST(Mask, OptimizeRuns2) {
std::string path = std::filesystem::current_path();
path += "/tests/testdata/runstest2.fa"; // ACtaGta

struct TestCase {
std::vector<kmer_t> kMers;
int k;
bool complements;
bool approximate;
std::string wantResult;
};
std::vector<TestCase> tests = {
{
{
KMerToNumber({"ACT"}),
KMerToNumber({"CTA"}),
KMerToNumber({"GTA"})
},
3, true, false,
"/tests/testdata/runstest2.fa",
"> superstring\nACTAGta\n"
},
};

for (auto &t : tests) {
std::stringstream of;
auto totalPath = path + t.relativePath;
auto kMersDict = kh_init_S64();
int ret;
for (auto &kMer : t.kMers) kh_put_S64(kMersDict, kMer, &ret);

OptimizeRuns(path, kMersDict, of, t.k, t.complements, t.approximate);
OptimizeRuns(totalPath, kMersDict, of, t.k, t.complements, t.approximate);

EXPECT_EQ(t.wantResult, of.str());
}
Expand Down

0 comments on commit 5f4647c

Please sign in to comment.