-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from paulsengroup/impl-hic-lazy-fetch [ci full]
Implement iterators over .hic files
- Loading branch information
Showing
88 changed files
with
3,222 additions
and
2,297 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Copyright (C) 2023 Roberto Rossini <roberros@uio.no> | ||
# | ||
# SPDX-License-Identifier: MIT | ||
|
||
add_subdirectory(hic) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Copyright (C) 2022 Roberto Rossini <roberros@uio.no> | ||
# | ||
# SPDX-License-Identifier: MIT | ||
|
||
find_package(CLI11 REQUIRED QUIET) | ||
find_package(Filesystem REQUIRED) | ||
|
||
add_executable(hictk_hic_dump_bench dump.cpp) | ||
|
||
target_link_libraries( | ||
hictk_hic_dump_bench | ||
PRIVATE hictk_project_warnings hictk_project_options | ||
PUBLIC hictk::hic) | ||
|
||
target_link_system_libraries( | ||
hictk_hic_dump_bench | ||
PUBLIC | ||
CLI11::CLI11 | ||
std::filesystem) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
// Copyright (C) 2023 Roberto Rossini <roberros@uio.no> | ||
// | ||
// SPDX-License-Identifier: MIT | ||
|
||
#include <fmt/format.h> | ||
|
||
#include <CLI/CLI.hpp> | ||
#include <chrono> | ||
#include <cstdint> | ||
|
||
#include "hictk/hic.hpp" | ||
|
||
using namespace hictk; | ||
|
||
struct Config { | ||
std::string path_to_hic{}; | ||
std::vector<std::uint32_t> resolutions{}; | ||
|
||
std::size_t target_num_records{1'000'000}; | ||
bool genome_wide{}; | ||
std::vector<std::size_t> block_cache_sizes{25'000'000}; | ||
}; | ||
|
||
static void dump_genome_wide(const std::string& path_to_hic, std::uint32_t resolution, | ||
std::size_t target_num_records, std::size_t block_cache_size) { | ||
hic::HiCFile hf(path_to_hic, resolution, hic::MatrixType::observed, hic::MatrixUnit::BP, | ||
block_cache_size); | ||
auto sel = hf.fetch(); | ||
|
||
const auto t0 = std::chrono::steady_clock::now(); | ||
auto first = sel.begin<float>(); | ||
auto last = sel.end<float>(); | ||
|
||
std::size_t i = 0; | ||
for (; i < target_num_records && first != last; ++i) { | ||
std::ignore = ++first; | ||
} | ||
|
||
const auto t1 = std::chrono::steady_clock::now(); | ||
|
||
const auto delta = | ||
static_cast<double>(std::chrono::duration_cast<std::chrono::microseconds>(t1 - t0).count()) / | ||
1.0e6; | ||
fmt::print(FMT_STRING("{}\t{}\t{}\t{}\t{}\n"), path_to_hic, resolution, i, block_cache_size, | ||
delta); | ||
} | ||
|
||
static void dump(const std::string& path_to_hic, std::uint32_t resolution, | ||
std::size_t target_num_records, std::size_t block_cache_size) { | ||
hic::HiCFile const hf(path_to_hic, resolution, hic::MatrixType::observed, hic::MatrixUnit::BP, | ||
block_cache_size); | ||
auto sel = hf.fetch("chr1"); | ||
|
||
const auto t0 = std::chrono::steady_clock::now(); | ||
auto first = sel.begin<float>(); | ||
auto last = sel.end<float>(); | ||
|
||
std::size_t i = 0; | ||
for (; i < target_num_records && first != last; ++i) { | ||
std::ignore = ++first; | ||
} | ||
|
||
const auto t1 = std::chrono::steady_clock::now(); | ||
|
||
const auto delta = | ||
static_cast<double>(std::chrono::duration_cast<std::chrono::microseconds>(t1 - t0).count()) / | ||
1.0e6; | ||
fmt::print(FMT_STRING("{}\t{}\t{}\t{}\t{}\n"), path_to_hic, resolution, i, block_cache_size, | ||
delta); | ||
} | ||
|
||
int main(int argc, char** argv) { | ||
CLI::App cli{}; | ||
|
||
Config c{}; | ||
|
||
cli.add_option("hic", c.path_to_hic, "Path to a .hic file."); | ||
cli.add_option("resolution", c.resolutions, "Resolution in bp."); | ||
cli.add_option("--target-num-records", c.target_num_records, "")->capture_default_str(); | ||
cli.add_option("--block-cache-size", c.block_cache_sizes, "")->capture_default_str(); | ||
cli.add_flag("--genome-wide", c.genome_wide, "")->capture_default_str(); | ||
|
||
try { | ||
cli.parse(argc, argv); | ||
|
||
fmt::print(FMT_STRING("file\tresolution\tnum_records\tblock_cache_size\ttime\n")); | ||
for (const auto& resolution : c.resolutions) { | ||
for (const auto& block_size : c.block_cache_sizes) { | ||
c.genome_wide | ||
? dump_genome_wide(c.path_to_hic, resolution, c.target_num_records, block_size) | ||
: dump(c.path_to_hic, resolution, c.target_num_records, block_size); | ||
} | ||
} | ||
} catch (const CLI::ParseError& e) { | ||
return cli.exit(e); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.