Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Runs bug #70

Merged
merged 4 commits into from
Feb 16, 2024
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
1 change: 0 additions & 1 deletion src/masks.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ void OptimizeRuns(std::string path, kh_S64_t *kMers, std::ostream &of, int k, bo
else intervalsSet[i] = mappedSize == 0 ? false : (glp_get_col_prim(lp, intervalMapping[i] + 1) > 0.5);
}

of << "> superstring" << std::endl;
ReadIntervals(nullptr, kMers, intervalsForKMer, path, k, complements, of, intervalsSet);
of << std::endl;
}
Expand Down
6 changes: 4 additions & 2 deletions src/parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,9 @@ std::pair<size_t, size_t> ReadIntervals(kh_O64_t *intervals, kh_S64_t *kMers, st
currentInterval += interval_used;
interval_used = false;
}
else if (c == '\n') readingHeader = false;
// Reprint the header.
if (readingHeader && !reading) of << c;
if (c == '\n') readingHeader = false;
if (readingHeader) continue;
auto data = NucleotideToInt(c);
// Disregard white space.
Expand All @@ -186,7 +188,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);
bool represented = containsKMer(kMers, currentKMer, k, complements);
bool set = false;
if (represented) {
interval_used = true;
Expand Down
17 changes: 15 additions & 2 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,17 +98,29 @@ namespace {
KMerToNumber({"AT"})
},
2, false, true,
"/tests/testdata/runstest.fa",
"> superstring\nACgCGTtACGtATt\n"
},
{
{
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
2 changes: 2 additions & 0 deletions tests/testdata/runstest2.fa
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
> superstring
ACtaGta
Loading