Skip to content

Commit

Permalink
Fix hictk dump -t bins for files in .scool format
Browse files Browse the repository at this point in the history
  • Loading branch information
robomics committed Feb 11, 2024
1 parent 082348e commit c76cbf9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
6 changes: 6 additions & 0 deletions src/hictk/cli/cli_dump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,12 @@ void Cli::transform_args_dump_subcommand() {
c.resolution = hic::utils::list_resolutions(c.uri).back();
} else if (c.format == "mcool" && c.resolution == 0 && c.table == "chroms") {
c.resolution = cooler::utils::list_resolutions(c.uri).back();
} else if (c.format == "scool" && (c.table == "chroms" || c.table == "bins")) {
const cooler::SingleCellFile sclr{c.uri};
if (sclr.cells().empty()) {
throw std::runtime_error("file does not contain any cell");
}
c.uri = fmt::format(FMT_STRING("{}::/cells/{}"), c.uri, *sclr.cells().begin());
}

if (_cli.get_subcommand("dump")->get_option("--range2")->empty()) {
Expand Down
18 changes: 14 additions & 4 deletions test/scripts/hictk_dump_bins.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ script_dir="$(readlink_py "$(dirname "$0")")"
ref_cooler="$data_dir/integration_tests/4DNFIZ1ZVXC8.mcool"
ref_hic="$data_dir/hic/4DNFIZ1ZVXC8.hic8"

ref_scooler="$data_dir/cooler/single_cell_cooler_test_file.scool"
cell_id='GSM2687248_41669_ACAGTG-R1-DpnII.100000.cool'

export PATH="$PATH:$script_dir"

if ! command -v cooler &> /dev/null; then
Expand All @@ -49,22 +52,29 @@ if [ $status -ne 0 ]; then
exit $status
fi

if ! check_test_files_exist.sh "$ref_cooler"; then
if ! check_test_files_exist.sh "$ref_cooler" "$ref_scooler" "$ref_hic"; then
exit 1
fi

outdir="$(mktemp -d -t hictk-tmp-XXXXXXXXXX)"
trap 'rm -rf -- "$outdir"' EXIT

cooler dump -t bins "$ref_cooler::/resolutions/100000" | cut -f 1-3 > "$outdir/expected.chrom.sizes"
cooler dump -t bins "$ref_cooler::/resolutions/100000" | cut -f 1-3 > "$outdir/expected1.chrom.sizes"
cooler dump -t bins "$ref_scooler::/cells/$cell_id" | cut -f 1-3 > "$outdir/expected2.chrom.sizes"

"$hictk_bin" dump -t bins "$ref_cooler::/resolutions/100000" > "$outdir/out.cooler.chrom.sizes"
"$hictk_bin" dump -t bins --resolution 100000 "$ref_hic" > "$outdir/out.hic.chrom.sizes"
"$hictk_bin" dump -t bins "$ref_scooler" > "$outdir/out.scooler.chrom.sizes"

if ! compare_plain_files.sh "$outdir/expected1.chrom.sizes" "$outdir/out.cooler.chrom.sizes"; then
status=1
fi

if ! compare_plain_files.sh "$outdir/expected.chrom.sizes" "$outdir/out.cooler.chrom.sizes"; then
if ! compare_plain_files.sh "$outdir/expected1.chrom.sizes" "$outdir/out.hic.chrom.sizes"; then
status=1
fi

if ! compare_plain_files.sh "$outdir/expected.chrom.sizes" "$outdir/out.hic.chrom.sizes"; then
if ! compare_plain_files.sh "$outdir/expected2.chrom.sizes" "$outdir/out.scooler.chrom.sizes"; then
status=1
fi

Expand Down

0 comments on commit c76cbf9

Please sign in to comment.