Skip to content

Commit

Permalink
Merge pull request #79 from paulsengroup/improve-hictk-dump
Browse files Browse the repository at this point in the history
Add --cis-only and --trans-only CLI options to hictk dump.
[ci full]
  • Loading branch information
robomics authored Dec 11, 2023
2 parents da1fd7d + 1c67c55 commit b0bad0b
Show file tree
Hide file tree
Showing 18 changed files with 617 additions and 258 deletions.
10 changes: 7 additions & 3 deletions docs/cli_reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,16 @@ hictk dump
Matrix unit (ignored when file is not in .hic format).
-t,--table TEXT:{chroms,bins,pixels,normalizations,resolutions,cells} [pixels]
Name of the table to dump.
-r,--range TEXT [all] Excludes: --query-file
-r,--range TEXT [all] Excludes: --query-file --cis-only --trans-only
Coordinates of the genomic regions to be dumped following UCSC-style notation (chr1:0-1000).
--range2 TEXT [all] Needs: --range Excludes: --query-file
--range2 TEXT [all] Needs: --range Excludes: --query-file --cis-only --trans-only
Coordinates of the genomic regions to be dumped following UCSC-style notation (chr1:0-1000).
--query-file TEXT:(FILE) OR ({-}) Excludes: --range --range2
--query-file TEXT:(FILE) OR ({-}) Excludes: --range --range2 --cis-only --trans-only
Path to a BEDPE file with the list of coordinates to be fetched (pass - to read queries from stdin).
--cis-only Excludes: --range --range2 --query-file --trans-only
Dump intra-chromosomal interactions only.
--trans-only Excludes: --range --range2 --query-file --cis-only
Dump inter-chromosomal interactions only.
-b,--balance TEXT [NONE] Balance interactions using the given method.
--sorted,--unsorted{false} Return interactions in ascending order.
--join,--no-join{false} Output pixels in BG2 format.
Expand Down
19 changes: 19 additions & 0 deletions docs/reading_interactions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,22 @@ Dump tables other than pixels:
5000
10000
...
Dump cis or trans interactions only:

.. code-block:: console
user@dev:/tmp$ hictk dump data/4DNFIZ1ZVXC8.hic9 --resolution 1000 --cis-only --join
chr2L 7000 8000 chr2L 7000 8000 1745
chr2L 7000 8000 chr2L 12000 13000 1766
chr2L 7000 8000 chr2L 17000 18000 1078
...
user@dev:/tmp$ hictk dump data/4DNFIZ1ZVXC8.hic9 --resolution 1000 --trans-only --join
chr2L 7000 8000 chr2R 27000 28000 1
chr2L 7000 8000 chr2R 322000 323000 1
chr2L 7000 8000 chr2R 397000 398000 1
...
3 changes: 3 additions & 0 deletions src/hictk/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ target_sources(
${CMAKE_CURRENT_SOURCE_DIR}/convert/cool_to_hic.cpp
${CMAKE_CURRENT_SOURCE_DIR}/convert/hic_to_cool.cpp
${CMAKE_CURRENT_SOURCE_DIR}/dump/dump.cpp
${CMAKE_CURRENT_SOURCE_DIR}/dump/dump_common.cpp
${CMAKE_CURRENT_SOURCE_DIR}/dump/dump_multiple.cpp
${CMAKE_CURRENT_SOURCE_DIR}/dump/dump_single.cpp
${CMAKE_CURRENT_SOURCE_DIR}/fix_mcool/fix_mcool.cpp
${CMAKE_CURRENT_SOURCE_DIR}/load/load.cpp
${CMAKE_CURRENT_SOURCE_DIR}/merge/merge.cpp
Expand Down
24 changes: 24 additions & 0 deletions src/hictk/cli/cli_dump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,16 @@ void Cli::make_dump_subcommand() {
->check(CLI::ExistingFile | CLI::IsMember({"-"}))
->capture_default_str();

sc.add_flag(
"--cis-only",
c.cis_only,
"Dump intra-chromosomal interactions only.");

sc.add_flag(
"--trans-only",
c.trans_only,
"Dump inter-chromosomal interactions only.");

sc.add_option(
"-b,--balance",
c.normalization,
Expand Down Expand Up @@ -111,8 +121,18 @@ void Cli::make_dump_subcommand() {
// clang-format on

sc.get_option("--range2")->needs(sc.get_option("--range"));

sc.get_option("--query-file")->excludes(sc.get_option("--range"));
sc.get_option("--query-file")->excludes(sc.get_option("--range2"));
sc.get_option("--query-file")->excludes(sc.get_option("--cis-only"));
sc.get_option("--query-file")->excludes(sc.get_option("--trans-only"));

sc.get_option("--cis-only")->excludes(sc.get_option("--trans-only"));
sc.get_option("--cis-only")->excludes(sc.get_option("--range"));
sc.get_option("--cis-only")->excludes(sc.get_option("--range2"));

sc.get_option("--trans-only")->excludes(sc.get_option("--range"));
sc.get_option("--trans-only")->excludes(sc.get_option("--range2"));

_config = std::monostate{};
}
Expand Down Expand Up @@ -168,6 +188,10 @@ void Cli::validate_dump_subcommand() const {
errors.emplace_back("--matrix-type=FRAG is not yet supported.");
}

if ((c.cis_only || c.trans_only) && c.table != "pixels") {
errors.emplace_back("--cis-only and --trans-only require --table=pixels.");
}

for (const auto& w : warnings) {
SPDLOG_WARN(FMT_STRING("{}"), w);
}
Expand Down
Loading

0 comments on commit b0bad0b

Please sign in to comment.