Skip to content

Commit

Permalink
Restructure project
Browse files Browse the repository at this point in the history
  • Loading branch information
robomics committed Aug 1, 2023
1 parent 8fd741d commit 8a7cf81
Show file tree
Hide file tree
Showing 10 changed files with 235 additions and 106 deletions.
21 changes: 14 additions & 7 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,23 @@ find_package(
COMPONENTS Interpreter Development.Module
REQUIRED)

# For some reason linking to std::filesystem breaks cibw builds for Apple Silicon
# find_package(Filesystem REQUIRED)
# For some reason linking to std::filesystem breaks cibw builds for Apple Silicon find_package(Filesystem REQUIRED)

find_package(pybind11 CONFIG REQUIRED)

pybind11_add_module(hictkpy MODULE hictkpy.cpp)
pybind11_add_module(
hictkpy
MODULE
hictkpy.cpp
hictkpy_cooler.cpp
hictkpy_file.cpp
hictkpy_hic.cpp)

target_include_directories(hictkpy PRIVATE include)
target_link_libraries(
hictkpy
PRIVATE hictkpy_project_options hictkpy_project_warnings
PUBLIC hictk::cooler
hictk::file
hictk::hic)
PRIVATE hictkpy_project_options
hictkpy_project_warnings
hictk::cooler
hictk::file
hictk::hic)
8 changes: 4 additions & 4 deletions src/hictkpy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@

#include <pybind11/pybind11.h>

#include "./common.hpp"
#include "./hictkpy_cooler.hpp"
#include "./hictkpy_file.hpp"
#include "./hictkpy_hic.hpp"
#include "hictk/cooler/cooler.hpp"
#include "hictk/file.hpp"
#include "hictk/hic.hpp"
#include "hictk/hic/utils.hpp"
#include "hictkpy/common.hpp"
#include "hictkpy/cooler.hpp"
#include "hictkpy/file.hpp"
#include "hictkpy/hic.hpp"

namespace hictkpy {

Expand Down
50 changes: 25 additions & 25 deletions src/hictkpy_cooler.hpp → src/hictkpy_cooler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,25 @@
//
// SPDX-License-Identifier: MIT

#pragma once

#include <pybind11/pybind11.h>

#include <cstdint>
#include <string>
#include <vector>

#include "hictk/cooler/cooler.hpp"
#include "hictk/reference.hpp"
#include "hictkpy/common.hpp"
#include "hictkpy/cooler.hpp"

// This is fine, this header is only supposed to be included in hictkpy.cpp
namespace py = pybind11;

namespace hictkpy::cooler {

inline hictk::cooler::File file_ctor(std::string_view uri) { return hictk::cooler::File(uri); }
hictk::cooler::File file_ctor(std::string_view uri) { return hictk::cooler::File(uri); }

inline hictk::cooler::File file_ctor(std::string_view uri, const py::dict &py_chroms,
std::uint32_t bin_size, bool overwrite_if_exists = false) {
hictk::cooler::File file_ctor(std::string_view uri, const py::dict &py_chroms,
std::uint32_t bin_size, bool overwrite_if_exists) {
std::vector<std::string> chrom_names{};
std::vector<std::uint32_t> chrom_sizes{};

Expand All @@ -32,11 +32,11 @@ inline hictk::cooler::File file_ctor(std::string_view uri, const py::dict &py_ch
return hictk::cooler::File::create(uri, chroms, bin_size, overwrite_if_exists);
}

inline bool is_cooler(std::string_view uri) { return bool(hictk::cooler::utils::is_cooler(uri)); }
bool is_cooler(std::string_view uri) { return bool(hictk::cooler::utils::is_cooler(uri)); }

inline hictk::cooler::File cooler_ctor(std::string_view uri, const py::dict &py_chroms,
std::uint32_t bin_size, bool overwrite_if_exists = false,
bool float_pixels = false) {
hictk::cooler::File cooler_ctor(std::string_view uri, const py::dict &py_chroms,
std::uint32_t bin_size, bool overwrite_if_exists,
bool float_pixels) {
std::vector<std::string> chrom_names{};
std::vector<std::uint32_t> chrom_sizes{};

Expand All @@ -51,7 +51,7 @@ inline hictk::cooler::File cooler_ctor(std::string_view uri, const py::dict &py_
return hictk::cooler::File::create(uri, chroms, bin_size, overwrite_if_exists);
}

[[nodiscard]] inline py::dict get_cooler_attrs(const hictk::cooler::File &clr) {
[[nodiscard]] py::dict get_cooler_attrs(const hictk::cooler::File &clr) {
py::dict py_attrs;
const auto &attrs = clr.attributes();

Expand Down Expand Up @@ -103,32 +103,32 @@ inline hictk::cooler::File cooler_ctor(std::string_view uri, const py::dict &py_
return py_attrs;
}

inline py::object fetch(const hictk::cooler::File &f, std::string_view range1,
std::string_view range2, std::string_view normalization,
std::string_view count_type, bool join, std::string_view query_type) {
py::object fetch(const hictk::cooler::File &f, std::string_view range1, std::string_view range2,
std::string_view normalization, std::string_view count_type, bool join,
std::string_view query_type) {
return file_fetch(f, range1, range2, normalization, count_type, join, query_type);
}

inline py::object fetch_sparse(const hictk::cooler::File &f, std::string_view range1,
std::string_view range2, std::string_view normalization,
std::string_view count_type, std::string_view query_type) {
py::object fetch_sparse(const hictk::cooler::File &f, std::string_view range1,
std::string_view range2, std::string_view normalization,
std::string_view count_type, std::string_view query_type) {
return file_fetch_sparse(f, range1, range2, normalization, count_type, query_type);
}

inline py::object fetch_dense(const hictk::cooler::File &f, std::string_view range1,
std::string_view range2, std::string_view normalization,
std::string_view count_type, std::string_view query_type) {
py::object fetch_dense(const hictk::cooler::File &f, std::string_view range1,
std::string_view range2, std::string_view normalization,
std::string_view count_type, std::string_view query_type) {
return file_fetch_dense(f, range1, range2, normalization, count_type, query_type);
}

inline py::object fetch_sum(const hictk::cooler::File &f, std::string_view range1,
std::string_view range2, std::string_view normalization,
std::string_view count_type, std::string_view query_type) {
py::object fetch_sum(const hictk::cooler::File &f, std::string_view range1, std::string_view range2,
std::string_view normalization, std::string_view count_type,
std::string_view query_type) {
return file_fetch_sum(f, range1, range2, normalization, count_type, query_type);
}

inline std::int64_t fetch_nnz(const hictk::cooler::File &f, std::string_view range1,
std::string_view range2, std::string_view query_type) {
std::int64_t fetch_nnz(const hictk::cooler::File &f, std::string_view range1,
std::string_view range2, std::string_view query_type) {
return file_fetch_nnz(f, range1, range2, query_type);
}
} // namespace hictkpy::cooler
39 changes: 20 additions & 19 deletions src/hictkpy_file.hpp → src/hictkpy_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,65 +2,66 @@
//
// SPDX-License-Identifier: MIT

#pragma once

#include <cstdint>
#include <string>
#include <string_view>
#include <variant>

#include "./common.hpp"
#include "hictk/file.hpp"
#include "hictkpy/file.hpp"

namespace py = pybind11;

namespace hictkpy::file {
[[nodiscard]] hictk::File ctor(std::string_view path, std::int32_t resolution,
std::string_view matrix_type, std::string_view matrix_unit) {
hictk::File ctor(std::string_view path, std::int32_t resolution, std::string_view matrix_type,
std::string_view matrix_unit) {
return hictk::File{std::string{path}, static_cast<std::uint32_t>(resolution),
hictk::hic::ParseMatrixTypeStr(std::string{matrix_type}),
hictk::hic::ParseUnitStr(std::string{matrix_unit})};
}

inline py::object fetch(const hictk::File &f, std::string_view range1, std::string_view range2,
std::string_view normalization, std::string_view count_type, bool join,
std::string_view query_type) {
py::object fetch(const hictk::File &f, std::string_view range1, std::string_view range2,
std::string_view normalization, std::string_view count_type, bool join,
std::string_view query_type) {
return std::visit(
[&](const auto &ff) -> py::object {
return file_fetch(ff, range1, range2, normalization, count_type, join, query_type);
},
f.get());
}

inline py::object fetch_sparse(const hictk::File &f, std::string_view range1,
std::string_view range2, std::string_view normalization,
std::string_view count_type, std::string_view query_type) {
py::object fetch_sparse(const hictk::File &f, std::string_view range1, std::string_view range2,
std::string_view normalization, std::string_view count_type,
std::string_view query_type) {
return std::visit(
[&](const auto &ff) -> py::object {
return file_fetch_sparse(ff, range1, range2, normalization, count_type, query_type);
},
f.get());
}

inline py::object fetch_dense(const hictk::File &f, std::string_view range1,
std::string_view range2, std::string_view normalization,
std::string_view count_type, std::string_view query_type) {
py::object fetch_dense(const hictk::File &f, std::string_view range1, std::string_view range2,
std::string_view normalization, std::string_view count_type,
std::string_view query_type) {
return std::visit(
[&](const auto &ff) -> py::object {
return file_fetch_dense(ff, range1, range2, normalization, count_type, query_type);
},
f.get());
}

inline py::object fetch_sum(const hictk::File &f, std::string_view range1, std::string_view range2,
std::string_view normalization, std::string_view count_type,
std::string_view query_type) {
py::object fetch_sum(const hictk::File &f, std::string_view range1, std::string_view range2,
std::string_view normalization, std::string_view count_type,
std::string_view query_type) {
return std::visit(
[&](const auto &ff) -> py::object {
return file_fetch_sum(ff, range1, range2, normalization, count_type, query_type);
},
f.get());
}

inline std::int64_t fetch_nnz(const hictk::File &f, std::string_view range1,
std::string_view range2, std::string_view query_type) {
std::int64_t fetch_nnz(const hictk::File &f, std::string_view range1, std::string_view range2,
std::string_view query_type) {
return std::visit([&](const auto &ff) { return file_fetch_nnz(ff, range1, range2, query_type); },
f.get());
}
Expand Down
52 changes: 52 additions & 0 deletions src/hictkpy_hic.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Copyright (C) 2023 Roberto Rossini <[email protected]>
//
// SPDX-License-Identifier: MIT

#include "hictkpy/hic.hpp"

#include <cstdint>
#include <string>
#include <string_view>

#include "hictk/hic.hpp"
#include "hictkpy/common.hpp"

namespace py = pybind11;

namespace hictkpy::hic {
hictk::hic::File file_ctor(std::string_view path, std::int32_t resolution,
std::string_view matrix_type, std::string_view matrix_unit) {
return hictk::hic::File{std::string{path}, static_cast<std::uint32_t>(resolution),
hictk::hic::ParseMatrixTypeStr(std::string{matrix_type}),
hictk::hic::ParseUnitStr(std::string{matrix_unit})};
}

py::object fetch(const hictk::hic::File &f, std::string_view range1, std::string_view range2,
std::string_view normalization, std::string_view count_type, bool join,
std::string_view query_type) {
return file_fetch(f, range1, range2, normalization, count_type, join, query_type);
}

py::object fetch_sparse(const hictk::hic::File &f, std::string_view range1, std::string_view range2,
std::string_view normalization, std::string_view count_type,
std::string_view query_type) {
return file_fetch_sparse(f, range1, range2, normalization, count_type, query_type);
}

py::object fetch_dense(const hictk::hic::File &f, std::string_view range1, std::string_view range2,
std::string_view normalization, std::string_view count_type,
std::string_view query_type) {
return file_fetch_dense(f, range1, range2, normalization, count_type, query_type);
}

py::object fetch_sum(const hictk::hic::File &f, std::string_view range1, std::string_view range2,
std::string_view normalization, std::string_view count_type,
std::string_view query_type) {
return file_fetch_sum(f, range1, range2, normalization, count_type, query_type);
}

std::int64_t fetch_nnz(const hictk::hic::File &f, std::string_view range1, std::string_view range2,
std::string_view query_type) {
return file_fetch_nnz(f, range1, range2, query_type);
}
} // namespace hictkpy::hic
51 changes: 0 additions & 51 deletions src/hictkpy_hic.hpp

This file was deleted.

File renamed without changes.
46 changes: 46 additions & 0 deletions src/include/hictkpy/cooler.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright (C) 2023 Roberto Rossini <[email protected]>
//
// SPDX-License-Identifier: MIT

#pragma once

#include <pybind11/pybind11.h>

#include <cstdint>
#include <string>
#include <string_view>
#include <vector>

#include "hictk/cooler/cooler.hpp"

namespace hictkpy::cooler {

hictk::cooler::File file_ctor(std::string_view uri);

hictk::cooler::File file_ctor(std::string_view uri, const pybind11::dict &py_chroms,
std::uint32_t bin_size, bool overwrite_if_exists = false);
bool is_cooler(std::string_view uri);

hictk::cooler::File cooler_ctor(std::string_view uri, const pybind11::dict &py_chroms,
std::uint32_t bin_size, bool overwrite_if_exists = false,
bool float_pixels = false);
[[nodiscard]] pybind11::dict get_cooler_attrs(const hictk::cooler::File &clr);

pybind11::object fetch(const hictk::cooler::File &f, std::string_view range1,
std::string_view range2, std::string_view normalization,
std::string_view count_type, bool join, std::string_view query_type);
pybind11::object fetch_sparse(const hictk::cooler::File &f, std::string_view range1,
std::string_view range2, std::string_view normalization,
std::string_view count_type, std::string_view query_type);

pybind11::object fetch_dense(const hictk::cooler::File &f, std::string_view range1,
std::string_view range2, std::string_view normalization,
std::string_view count_type, std::string_view query_type);

pybind11::object fetch_sum(const hictk::cooler::File &f, std::string_view range1,
std::string_view range2, std::string_view normalization,
std::string_view count_type, std::string_view query_type);
std::int64_t fetch_nnz(const hictk::cooler::File &f, std::string_view range1,
std::string_view range2, std::string_view query_type);

} // namespace hictkpy::cooler
Loading

0 comments on commit 8a7cf81

Please sign in to comment.