diff --git a/test/units/hic/file_writer_test.cpp b/test/units/hic/file_writer_test.cpp index 4cba153cc..166bbcb4d 100644 --- a/test/units/hic/file_writer_test.cpp +++ b/test/units/hic/file_writer_test.cpp @@ -88,40 +88,57 @@ TEST_CASE("HiC: HiCInteractionToBlockMapper", "[hic][v9][short]") { CHECK(num_interactions == pixels1.size() + pixels2.size()); } -TEST_CASE("HiC: HiCFileWriter", "[hic][v9][short]") { - const auto path1 = (datadir / "4DNFIZ1ZVXC8.hic9").string(); - const auto path2 = (testdir() / "hic_writer_001.hic").string(); - const auto path3 = (testdir() / "hic_writer_002.hic").string(); - const std::vector resolutions{500'000, 1'000'000, 2'500'000}; - - SECTION("create file") { - { - const auto chromosomes = hic::File(path1, resolutions.front()).chromosomes(); - HiCFileWriter w(path2, chromosomes, resolutions, "dm6", 3); - for (std::size_t i = 0; i < resolutions.size(); ++i) { - if (i % 2 == 0) { - const auto resolution = resolutions[i]; - const hic::File f((datadir / "4DNFIZ1ZVXC8.hic9").string(), resolution); - const auto sel = f.fetch(); - w.add_pixels(resolution, sel.begin(), sel.end()); - } +// NOLINTNEXTLINE(readability-function-cognitive-complexity) +static void hic_file_writer_create_file_test(const std::string& path1, const std::string& path2, + const std::vector& resolutions, + std::size_t num_threads) { + { + const auto chromosomes = hic::File(path1, resolutions.front()).chromosomes(); + std::filesystem::remove(path2); + HiCFileWriter w(path2, chromosomes, resolutions, "dm6", num_threads); + for (std::size_t i = 0; i < resolutions.size(); ++i) { + if (i % 2 == 0) { + const auto resolution = resolutions[i]; + const hic::File f((datadir / "4DNFIZ1ZVXC8.hic9").string(), resolution); + const auto sel1 = f.fetch("chr3R"); + const auto sel2 = f.fetch("chr3R", "chr4"); + w.add_pixels(resolution, sel1.begin(), sel1.end()); + w.add_pixels(resolution, sel2.begin(), sel2.end()); } - w.serialize(); } + w.serialize(); + } - for (const auto& resolution : resolutions) { - fmt::print(FMT_STRING("Comparing {}...\n"), resolution); - const hic::File f1(path1, resolution); - const hic::File f2(path2, resolution); - const auto expected_pixels = f1.fetch().read_all(); - const auto pixels = f2.fetch().read_all(); + for (const auto& resolution : resolutions) { + fmt::print(FMT_STRING("Comparing {}...\n"), resolution); + const hic::File f1(path1, resolution); + const hic::File f2(path2, resolution); - REQUIRE(expected_pixels.size() == pixels.size()); - for (std::size_t i = 0; i < pixels.size(); ++i) { - CHECK(expected_pixels[i] == pixels[i]); - } + const auto expected_pixels1 = f1.fetch("chr3R").read_all(); + const auto expected_pixels2 = f1.fetch("chr3R", "chr4").read_all(); + const auto pixels1 = f2.fetch("chr3R").read_all(); + const auto pixels2 = f2.fetch("chr3R", "chr4").read_all(); + + REQUIRE(expected_pixels1.size() == pixels1.size()); + for (std::size_t i = 0; i < pixels1.size(); ++i) { + CHECK(expected_pixels1[i] == pixels1[i]); + } + REQUIRE(expected_pixels2.size() == pixels2.size()); + for (std::size_t i = 0; i < pixels2.size(); ++i) { + CHECK(expected_pixels2[i] == pixels2[i]); } } +} + +// NOLINTNEXTLINE(readability-function-cognitive-complexity) +TEST_CASE("HiC: HiCFileWriter", "[hic][v9][short]") { + const auto path1 = (datadir / "4DNFIZ1ZVXC8.hic9").string(); + const auto path2 = (testdir() / "hic_writer_001.hic").string(); + const auto path3 = (testdir() / "hic_writer_002.hic").string(); + const std::vector resolutions{25'000, 250'000, 500'000}; + + SECTION("create file (st)") { hic_file_writer_create_file_test(path1, path2, resolutions, 1); } + SECTION("create file (mt)") { hic_file_writer_create_file_test(path1, path2, resolutions, 3); } SECTION("add weights") { const std::uint32_t resolution = 500'000;