Skip to content

Commit

Permalink
[Update] Also test situation with duplicated in full run
Browse files Browse the repository at this point in the history
  • Loading branch information
choishingwan committed Apr 17, 2020
1 parent 7d32886 commit 38def8a
Showing 1 changed file with 40 additions and 12 deletions.
52 changes: 40 additions & 12 deletions test/csrc/binaryplink_snp_load.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,20 +166,48 @@ TEST_CASE("generate snp vector")
bim << "1 SNP_2 0 933331 C T" << std::endl;
bim << "1 SNP_4 0 1008567 G A" << std::endl;
bim.close();
bim.open("load_snp2.bim");
bim << "chr1 SNP_5 0 742429 A C" << std::endl;
bim.close();
bplink.gen_bed_head("load_snp2.bed", num_sample, 1, true, false);
bplink.load_snps("load_snp", std::vector<IITree<size_t, size_t>> {},
false);
auto res = bplink.existed_snps();
REQUIRE(res.size() == 4);
REQUIRE(res[0].rs() == "SNP_1");
REQUIRE(res[1].rs() == "SNP_2");
REQUIRE(res[2].rs() == "SNP_4");
REQUIRE(res[3].rs() == "SNP_5");
SECTION("without duplicates")
{
bim.open("load_snp2.bim");
bim << "chr1 SNP_5 0 742429 A C" << std::endl;
bim.close();
bplink.gen_bed_head("load_snp2.bed", num_sample, 1, true, false);
bplink.load_snps("load_snp", std::vector<IITree<size_t, size_t>> {},
false);
auto res = bplink.existed_snps();
REQUIRE(res.size() == 4);
REQUIRE(res[0].rs() == "SNP_1");
REQUIRE(res[1].rs() == "SNP_2");
REQUIRE(res[2].rs() == "SNP_4");
REQUIRE(res[3].rs() == "SNP_5");
}
SECTION("with duplicates")
{
bim.open("load_snp2.bim");
bim << "chr1 SNP_5 0 742429 A C" << std::endl;
bim << "chr1 SNP_5 0 742429 A C" << std::endl;
bim.close();
bplink.gen_bed_head("load_snp2.bed", num_sample, 1, true, false);
REQUIRE_THROWS(bplink.load_snps(
"load_snp", std::vector<IITree<size_t, size_t>> {}, false));
std::ifstream dup("load_snp.valid");
REQUIRE(dup.is_open());
std::string line;
size_t num_dup = 0;
std::vector<std::string> token;
while (std::getline(dup, line))
{
token = misc::split(line, "\t");
++num_dup;
}
REQUIRE(num_dup == 3);
REQUIRE(token.size() == 5);
// we are checking the last line only
REQUIRE(token[0] == "SNP_4");
}
}


// one invalid loc
// one invalid chr
// one invalid anything
Expand Down

0 comments on commit 38def8a

Please sign in to comment.