Skip to content

Commit

Permalink
Add accessors for BinTable objects to FileWriter classes
Browse files Browse the repository at this point in the history
  • Loading branch information
robomics committed Nov 11, 2024
1 parent 6b2f865 commit eb802e7
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/cooler_file_writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,14 @@ const hictk::Reference &CoolerFileWriter::chromosomes() const {
return ref;
}

std::shared_ptr<const hictk::BinTable> CoolerFileWriter::bins_ptr() const noexcept {
if (!_w) {
return {};
}

return _w->bins_ptr();
}

void CoolerFileWriter::add_pixels(const nb::object &df) {
if (!_w.has_value()) {
throw std::runtime_error(
Expand Down Expand Up @@ -193,6 +201,8 @@ void CoolerFileWriter::bind(nb::module_ &m) {
nb::arg("include_ALL") = false,
"Get chromosomes sizes as a dictionary mapping names to sizes.",
nb::rv_policy::take_ownership);
writer.def("bins", &get_bins_from_object<hictkpy::CoolerFileWriter>, "Get table of bins.",
nb::sig("def bins(self) -> hictkpy.BinTable"), nb::rv_policy::move);

writer.def("add_pixels", &hictkpy::CoolerFileWriter::add_pixels,
nb::sig("def add_pixels(self, pixels: pandas.DataFrame)"), nb::arg("pixels"),
Expand Down
6 changes: 6 additions & 0 deletions src/hic_file_writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ const std::vector<std::uint32_t> &HiCFileWriter::resolutions() const noexcept {

const hictk::Reference &HiCFileWriter::chromosomes() const { return _w.chromosomes(); }

hictkpy::BinTable HiCFileWriter::bins(std::uint32_t resolution) const {
return hictkpy::BinTable{_w.bins(resolution)};
}

void HiCFileWriter::add_pixels(const nb::object &df) {
if (_finalized) {
throw std::runtime_error(
Expand Down Expand Up @@ -172,6 +176,8 @@ void HiCFileWriter::bind(nb::module_ &m) {
nb::arg("include_ALL") = false,
"Get chromosomes sizes as a dictionary mapping names to sizes.",
nb::rv_policy::take_ownership);
writer.def("bins", &hictkpy::HiCFileWriter::bins, "Get table of bins for the given resolution.",
nb::sig("def bins(self, resolution: int) -> hictkpy.BinTable"), nb::rv_policy::move);

writer.def("add_pixels", &hictkpy::HiCFileWriter::add_pixels,
nb::sig("def add_pixels(self, pixels: pd.DataFrame) -> None"), nb::arg("pixels"),
Expand Down
1 change: 1 addition & 0 deletions src/include/hictkpy/cooler_file_writer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class CoolerFileWriter {
[[nodiscard]] std::uint32_t resolution() const noexcept;

[[nodiscard]] const hictk::Reference& chromosomes() const;
[[nodiscard]] std::shared_ptr<const hictk::BinTable> bins_ptr() const noexcept;

void add_pixels(const nanobind::object& df);

Expand Down
1 change: 1 addition & 0 deletions src/include/hictkpy/hic_file_writer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class HiCFileWriter {
[[nodiscard]] const std::vector<std::uint32_t>& resolutions() const noexcept;

[[nodiscard]] const hictk::Reference& chromosomes() const;
[[nodiscard]] hictkpy::BinTable bins(std::uint32_t resolution) const;

void add_pixels(const nanobind::object& df);

Expand Down

0 comments on commit eb802e7

Please sign in to comment.