Skip to content

Commit

Permalink
Merge pull request #3 from paulsengroup/fix/query-mirroring
Browse files Browse the repository at this point in the history
Bugfix: query mirroring
  • Loading branch information
robomics committed Apr 16, 2024
2 parents 462d1df + f9e13cf commit 4a1e69e
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 5 deletions.
1 change: 1 addition & 0 deletions conanfile.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ hdf5*:enable_cxx=False
hdf5*:hl=False
hdf5*:threadsafe=False
hdf5*:parallel=False
hictk*:with_eigen=False
highfive*:with_boost=False
highfive*:with_eigen=False
highfive*:with_opencv=False
Expand Down
11 changes: 7 additions & 4 deletions src/hictkr_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,13 +255,16 @@ static Rcpp::NumericMatrix fetch_as_matrix(const Selector &sel) {
matrix.at(i1, i2) = tp.count;

if (mirror_matrix) {
// Mirror matrix below diagonal
if (i2 - i1 < num_rows && i1 < num_cols && i2 < num_rows) {
const auto delta = i2 - i1;
if (delta >= 0 && delta < num_rows && i1 < num_cols && i2 < num_rows) {
matrix.at(i2, i1) = tp.count;
} else if (i2 - i1 > num_cols && i1 < num_cols && i2 < num_rows) {
} else if ((delta < 0 || delta > num_cols) && i1 < num_cols && i2 < num_rows) {
const auto i3 = static_cast<std::int64_t>(tp.bin2_id - row_offset);
const auto i4 = static_cast<std::int64_t>(tp.bin1_id - col_offset);
matrix.at(i3, i4) = tp.count;

if (i3 >= 0 && i3 < num_rows && i4 >= 0 && i4 < num_cols) {
matrix.at(i3, i4) = tp.count;
}
}
}
});
Expand Down
31 changes: 30 additions & 1 deletion tests/testthat/test-fetch-dense.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ for (path in test_files) {
expect_equal(sum_, 178263235)
})

test_that("HiCFile: fetch (dense) cis", {
test_that("HiCFile: fetch (dense) symmetric cis", {
f <- File(path, 100000)

m <- fetch(f, "chr2R:10,000,000-15,000,000", type="dense")
Expand All @@ -31,6 +31,35 @@ for (path in test_files) {
expect_equal(sum_, 6029333)
})

test_that("HiCFile: fetch (dense) asymmetric cis", {
f <- File(path, 100000)

m <- fetch(f, "chr2L:0-10,000,000", "chr2L:5,000,000-20,000,000", type="dense")

shape <- dim(m)
sum_ <- sum(m)

expect_equal(shape, c(100, 150))
expect_equal(sum_, 6287451)


m <- fetch(f, "chr2L:0-10,000,000", "chr2L:10,000,000-20,000,000", type="dense")

shape <- dim(m)
sum_ <- sum(m)

expect_equal(shape, c(100, 100))
expect_equal(sum_, 761223)

m <- fetch(f, "chr2L:0-10,000,000", "chr2L:0-15,000,000", type="dense")

shape <- dim(m)
sum_ <- sum(m)

expect_equal(shape, c(100, 150))
expect_equal(sum_, 12607205)
})

test_that("HiCFile: fetch (dense) cis BED queries", {
f <- File(path, 100000)

Expand Down

0 comments on commit 4a1e69e

Please sign in to comment.