Skip to content

Commit

Permalink
Merge pull request #87 from paulsengroup/feature/improve-error-msg
Browse files Browse the repository at this point in the history
Refuse to add pixels to files that have already been finalized
  • Loading branch information
robomics authored Oct 18, 2024
2 parents 127d7b1 + d4e9947 commit 41bd79f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/hic_file_writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ const std::vector<std::uint32_t> &HiCFileWriter::resolutions() const noexcept {
const hictk::Reference &HiCFileWriter::chromosomes() const { return _w.chromosomes(); }

void HiCFileWriter::add_pixels(const nb::object &df) {
if (_finalized) {
throw std::runtime_error(
"caught attempt to add_pixels to a .hic file that has already been finalized!");
}

const auto coo_format = nb::cast<bool>(df.attr("columns").attr("__contains__")("bin1_id"));
const auto pixels =
coo_format ? coo_df_to_thin_pixels<float>(df, false)
Expand Down
9 changes: 9 additions & 0 deletions test/test_file_creation_cool.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ def test_file_creation_thin_pixel(self, file, resolution, tmpdir):
w.add_pixels(df[start:end])

w.finalize()
with pytest.raises(Exception):
w.add_pixels(df)

del w
gc.collect()

Expand All @@ -58,6 +61,9 @@ def test_file_creation(self, file, resolution, tmpdir):
w.add_pixels(df[start:end])

w.finalize()
with pytest.raises(Exception):
w.add_pixels(df)

del w
gc.collect()

Expand All @@ -80,6 +86,9 @@ def test_file_creation_float_counts(self, file, resolution, tmpdir):
w.add_pixels(df[start:end])

w.finalize()
with pytest.raises(Exception):
w.add_pixels(df)

del w
gc.collect()

Expand Down
6 changes: 6 additions & 0 deletions test/test_file_creation_hic.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ def test_file_creation_thin_pixel(self, file, resolution, tmpdir):
w.add_pixels(df[start:end])

w.finalize()
with pytest.raises(Exception):
w.add_pixels(df)

del w
gc.collect()

Expand All @@ -58,6 +61,9 @@ def test_file_creation(self, file, resolution, tmpdir):
w.add_pixels(df[start:end])

w.finalize()
with pytest.raises(Exception):
w.add_pixels(df)

del w
gc.collect()

Expand Down

0 comments on commit 41bd79f

Please sign in to comment.