Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add implementations for the new sequence changing method in libhandlegraph. #208

Merged
merged 13 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,13 @@ target_include_directories(sparsepp INTERFACE "${bdsg_DIR}/deps/sparsepp/")
add_subdirectory("${bdsg_DIR}/deps/mio")

if (BUILD_PYTHON_BINDINGS)

# Binder (because some generated bindings depend on headers packaged with Binder)
# See also: Binder commit defined in make_and_run_binder.py which actually generates bindings.
set(BINDER_COMMIT b6cac94c78ade6c6ffcbda629ffa520561a31788)
ExternalProject_Add(binder
GIT_REPOSITORY "https://github.com/RosettaCommons/binder.git"
GIT_TAG "ee2ecff151d125c3add072a7765aebad6f42a70d"
GIT_REPOSITORY "https://github.com/adamnovak/binder.git"
GIT_TAG "${BINDER_COMMIT}"
# we don't actually build or install Binder via its CMake because we just need its headers
#CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=${INSTALL_DIR}
CONFIGURE_COMMAND ""
Expand All @@ -202,14 +205,16 @@ if (BUILD_PYTHON_BINDINGS)
set(binder_INCLUDE "${INSTALL_DIR}/${CMAKE_INSTALL_INCLUDEDIR}")

# pybind11
# See also: pybind11 commit defined in make_and_run_binder.py.
set(PYBIND11_COMMIT 5b0a6fc2017fcc176545afe3e09c9f9885283242)
if (CMAKE_MAJOR_VERSION EQUAL "3" AND CMAKE_MINOR_VERSION EQUAL "10")
# We need pybind11 installed in ./pybind11 *before* CMake can finish processing this file.
# On CMake 3.11+ we can do that with FetchContent
# But on CMake 3.10, available on Ubuntu 18.04, we have to just call git ourselves.
if (NOT EXISTS "${PROJECT_SOURCE_DIR}/pybind11")
message(WARNING "Running on CMake without FetchContent_Declare; attempting to download pybind11 manually")
execute_process(COMMAND git clone https://github.com/RosettaCommons/pybind11.git "${PROJECT_SOURCE_DIR}/pybind11")
execute_process(COMMAND git checkout 5b0a6fc2017fcc176545afe3e09c9f9885283242
execute_process(COMMAND git checkout "${PYBIND11_COMMIT}"
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}/pybind11")
endif()

Expand All @@ -225,7 +230,7 @@ if (BUILD_PYTHON_BINDINGS)
FetchContent_Declare(
pybind11
GIT_REPOSITORY https://github.com/RosettaCommons/pybind11.git
GIT_TAG 5b0a6fc2017fcc176545afe3e09c9f9885283242
GIT_TAG "${PYBIND11_COMMIT}"
)
FetchContent_GetProperties(pybind11)
if (NOT pybind11_POPULATED)
Expand Down
4 changes: 2 additions & 2 deletions bdsg/cmake_bindings/bdsg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ void bind_bdsg_overlays_packed_path_position_overlay(std::function< pybind11::mo
void bind_bdsg_overlays_packed_path_position_overlay_1(std::function< pybind11::module &(std::string const &namespace_) > &M);
void bind_bdsg_overlays_path_position_overlays(std::function< pybind11::module &(std::string const &namespace_) > &M);
void bind_bdsg_overlays_path_subgraph_overlay(std::function< pybind11::module &(std::string const &namespace_) > &M);
void bind_bdsg_overlays_reference_path_overlay(std::function< pybind11::module &(std::string const &namespace_) > &M);
void bind_bdsg_overlays_vectorizable_overlays(std::function< pybind11::module &(std::string const &namespace_) > &M);
void bind_bdsg_overlays_vectorizable_overlays_1(std::function< pybind11::module &(std::string const &namespace_) > &M);
void bind_handlegraph_trivially_serializable(std::function< pybind11::module &(std::string const &namespace_) > &M);
void bind_bdsg_packed_graph(std::function< pybind11::module &(std::string const &namespace_) > &M);
void bind_bdsg_snarl_distance_index(std::function< pybind11::module &(std::string const &namespace_) > &M);
Expand Down Expand Up @@ -93,8 +93,8 @@ PYBIND11_MODULE(bdsg, root_module) {
bind_bdsg_overlays_packed_path_position_overlay_1(M);
bind_bdsg_overlays_path_position_overlays(M);
bind_bdsg_overlays_path_subgraph_overlay(M);
bind_bdsg_overlays_reference_path_overlay(M);
bind_bdsg_overlays_vectorizable_overlays(M);
bind_bdsg_overlays_vectorizable_overlays_1(M);
bind_handlegraph_trivially_serializable(M);
bind_bdsg_packed_graph(M);
bind_bdsg_snarl_distance_index(M);
Expand Down
2 changes: 1 addition & 1 deletion bdsg/cmake_bindings/bdsg.sources
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ bdsg/overlays/packed_path_position_overlay.cpp
bdsg/overlays/packed_path_position_overlay_1.cpp
bdsg/overlays/path_position_overlays.cpp
bdsg/overlays/path_subgraph_overlay.cpp
bdsg/overlays/reference_path_overlay.cpp
bdsg/overlays/vectorizable_overlays.cpp
bdsg/overlays/vectorizable_overlays_1.cpp
handlegraph/trivially_serializable.cpp
bdsg/packed_graph.cpp
bdsg/snarl_distance_index.cpp
152 changes: 77 additions & 75 deletions bdsg/cmake_bindings/bdsg/graph_proxy.cpp

Large diffs are not rendered by default.

138 changes: 70 additions & 68 deletions bdsg/cmake_bindings/bdsg/graph_proxy_1.cpp

Large diffs are not rendered by default.

150 changes: 76 additions & 74 deletions bdsg/cmake_bindings/bdsg/internal/base_packed_graph.cpp

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion bdsg/cmake_bindings/bdsg/internal/eades_algorithm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
#include <functional>
#include <handlegraph/handle_graph.hpp>
#include <handlegraph/types.hpp>
#include <iterator>
#include <memory>
#include <string>
#include <string_view>
#include <utility>
#include <vector>

Expand Down
31 changes: 26 additions & 5 deletions bdsg/cmake_bindings/bdsg/internal/hash_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
#include <handlegraph/types.hpp>
#include <ios>
#include <istream>
#include <iterator>
#include <memory>
#include <sstream> // __str__
#include <streambuf>
#include <string>
#include <string_view>
#include <utility>
#include <vector>

Expand Down Expand Up @@ -627,6 +627,19 @@ struct PyCallBack_bdsg_HashGraph : public bdsg::HashGraph {
}
return HashGraph::destroy_path(a0);
}
void destroy_paths(const class std::vector<handlegraph::path_handle_t> & a0) override {
pybind11::gil_scoped_acquire gil;
pybind11::function overload = pybind11::get_overload(static_cast<const bdsg::HashGraph *>(this), "destroy_paths");
if (overload) {
auto o = overload.operator()<pybind11::return_value_policy::reference>(a0);
if (pybind11::detail::cast_is_temporary_value_reference<void>::value) {
static pybind11::detail::override_caster_t<void> caster;
return pybind11::detail::cast_ref<void>(std::move(o), caster);
}
else return pybind11::detail::cast_safe<void>(std::move(o));
}
return HashGraph::destroy_paths(a0);
}
struct handlegraph::path_handle_t create_path_handle(const std::string & a0, bool a1) override {
pybind11::gil_scoped_acquire gil;
pybind11::function overload = pybind11::get_overload(static_cast<const bdsg::HashGraph *>(this), "create_path_handle");
Expand Down Expand Up @@ -1013,14 +1026,20 @@ void bind_bdsg_internal_hash_map(std::function< pybind11::module &(std::string c
{ // bdsg::wang_hash file:bdsg/internal/hash_map.hpp line:120
pybind11::class_<bdsg::wang_hash<long long,void>, std::shared_ptr<bdsg::wang_hash<long long,void>>> cl(M("bdsg"), "wang_hash_long_long_void_t", "");
cl.def( pybind11::init( [](){ return new bdsg::wang_hash<long long,void>(); } ) );
cl.def("__call__", (unsigned long (bdsg::wang_hash<long long,void>::*)(const long long &) const) &bdsg::wang_hash<long long>::operator(), "C++: bdsg::wang_hash<long long>::operator()(const long long &) const --> unsigned long", pybind11::arg("x"));
cl.def("assign", (struct bdsg::wang_hash<long long> & (bdsg::wang_hash<long long,void>::*)(const struct bdsg::wang_hash<long long> &)) &bdsg::wang_hash<long long>::operator=, "C++: bdsg::wang_hash<long long>::operator=(const struct bdsg::wang_hash<long long> &) --> struct bdsg::wang_hash<long long> &", pybind11::return_value_policy::automatic, pybind11::arg(""));
cl.def("__call__", (unsigned long (bdsg::wang_hash<long long,void>::*)(const long long &) const) &bdsg::wang_hash<long long, void>::operator(), "C++: bdsg::wang_hash<long long, void>::operator()(const long long &) const --> unsigned long", pybind11::arg("x"));
cl.def("assign", (struct bdsg::wang_hash<long long, void> & (bdsg::wang_hash<long long,void>::*)(const struct bdsg::wang_hash<long long, void> &)) &bdsg::wang_hash<long long, void>::operator=, "C++: bdsg::wang_hash<long long, void>::operator=(const struct bdsg::wang_hash<long long, void> &) --> struct bdsg::wang_hash<long long, void> &", pybind11::return_value_policy::automatic, pybind11::arg(""));
}
{ // bdsg::wang_hash file:bdsg/internal/hash_map.hpp line:120
pybind11::class_<bdsg::wang_hash<long,void>, std::shared_ptr<bdsg::wang_hash<long,void>>> cl(M("bdsg"), "wang_hash_long_void_t", "");
cl.def( pybind11::init( [](){ return new bdsg::wang_hash<long,void>(); } ) );
cl.def("__call__", (unsigned long (bdsg::wang_hash<long,void>::*)(const long &) const) &bdsg::wang_hash<long, void>::operator(), "C++: bdsg::wang_hash<long, void>::operator()(const long &) const --> unsigned long", pybind11::arg("x"));
cl.def("assign", (struct bdsg::wang_hash<long, void> & (bdsg::wang_hash<long,void>::*)(const struct bdsg::wang_hash<long, void> &)) &bdsg::wang_hash<long, void>::operator=, "C++: bdsg::wang_hash<long, void>::operator=(const struct bdsg::wang_hash<long, void> &) --> struct bdsg::wang_hash<long, void> &", pybind11::return_value_policy::automatic, pybind11::arg(""));
}
{ // bdsg::wang_hash file:bdsg/internal/hash_map.hpp line:120
pybind11::class_<bdsg::wang_hash<char,void>, std::shared_ptr<bdsg::wang_hash<char,void>>> cl(M("bdsg"), "wang_hash_char_void_t", "");
cl.def( pybind11::init( [](){ return new bdsg::wang_hash<char,void>(); } ) );
cl.def("__call__", (unsigned long (bdsg::wang_hash<char,void>::*)(const char &) const) &bdsg::wang_hash<char>::operator(), "C++: bdsg::wang_hash<char>::operator()(const char &) const --> unsigned long", pybind11::arg("x"));
cl.def("assign", (struct bdsg::wang_hash<char> & (bdsg::wang_hash<char,void>::*)(const struct bdsg::wang_hash<char> &)) &bdsg::wang_hash<char>::operator=, "C++: bdsg::wang_hash<char>::operator=(const struct bdsg::wang_hash<char> &) --> struct bdsg::wang_hash<char> &", pybind11::return_value_policy::automatic, pybind11::arg(""));
cl.def("__call__", (unsigned long (bdsg::wang_hash<char,void>::*)(const char &) const) &bdsg::wang_hash<char, void>::operator(), "C++: bdsg::wang_hash<char, void>::operator()(const char &) const --> unsigned long", pybind11::arg("x"));
cl.def("assign", (struct bdsg::wang_hash<char, void> & (bdsg::wang_hash<char,void>::*)(const struct bdsg::wang_hash<char, void> &)) &bdsg::wang_hash<char, void>::operator=, "C++: bdsg::wang_hash<char, void>::operator=(const struct bdsg::wang_hash<char, void> &) --> struct bdsg::wang_hash<char, void> &", pybind11::return_value_policy::automatic, pybind11::arg(""));
}
{ // bdsg::StringHashMapFor file:bdsg/internal/hash_map.hpp line:212
pybind11::class_<bdsg::StringHashMapFor<bdsg::STLBackend>, std::shared_ptr<bdsg::StringHashMapFor<bdsg::STLBackend>>> cl(M("bdsg"), "StringHashMapFor_bdsg_STLBackend_t", "");
Expand Down Expand Up @@ -1111,6 +1130,7 @@ void bind_bdsg_internal_hash_map(std::function< pybind11::module &(std::string c
cl.def("create_handle", (struct handlegraph::handle_t (bdsg::HashGraph::*)(const std::string &)) &bdsg::HashGraph::create_handle, "Create a new node with the given sequence and return the handle.\n The sequence may not be empty.\n\nC++: bdsg::HashGraph::create_handle(const std::string &) --> struct handlegraph::handle_t", pybind11::arg("sequence"));
cl.def("create_handle", (struct handlegraph::handle_t (bdsg::HashGraph::*)(const std::string &, const long long &)) &bdsg::HashGraph::create_handle, "Create a new node with the given id and sequence, then return the handle.\n The sequence may not be empty.\n The ID must be strictly greater than 0.\n\nC++: bdsg::HashGraph::create_handle(const std::string &, const long long &) --> struct handlegraph::handle_t", pybind11::arg("sequence"), pybind11::arg("id"));
cl.def("destroy_handle", (void (bdsg::HashGraph::*)(const struct handlegraph::handle_t &)) &bdsg::HashGraph::destroy_handle, "Remove the node belonging to the given handle and all of its edges.\n Destroys any paths in which the node participates.\n Invalidates the destroyed handle.\n May be called during serial for_each_handle iteration **ONLY** on the node being iterated.\n May **NOT** be called during parallel for_each_handle iteration.\n May **NOT** be called on the node from which edges are being followed during follow_edges.\n May **NOT** be called during iteration over paths, if it would destroy a path.\n May **NOT** be called during iteration along a path, if it would destroy that path.\n\nC++: bdsg::HashGraph::destroy_handle(const struct handlegraph::handle_t &) --> void", pybind11::arg("handle"));
cl.def("change_sequence", (struct handlegraph::handle_t (bdsg::HashGraph::*)(const struct handlegraph::handle_t &, const std::string &)) &bdsg::HashGraph::change_sequence, "Change the sequence of handle to a new sequence. Returns a (possibly alterered)\n handle to the node with the new sequence. May invalidate the existing handle. Updates\n paths if called through an inheriting MutablePath interface.\n\nC++: bdsg::HashGraph::change_sequence(const struct handlegraph::handle_t &, const std::string &) --> struct handlegraph::handle_t", pybind11::arg("handle"), pybind11::arg("sequence"));
cl.def("create_edge", (void (bdsg::HashGraph::*)(const struct handlegraph::handle_t &, const struct handlegraph::handle_t &)) &bdsg::HashGraph::create_edge, "Create an edge connecting the given handles in the given order and orientations.\n Ignores existing edges.\n\nC++: bdsg::HashGraph::create_edge(const struct handlegraph::handle_t &, const struct handlegraph::handle_t &) --> void", pybind11::arg("left"), pybind11::arg("right"));
cl.def("destroy_edge", (void (bdsg::HashGraph::*)(const struct handlegraph::handle_t &, const struct handlegraph::handle_t &)) &bdsg::HashGraph::destroy_edge, "Remove the edge connecting the given handles in the given order and orientations.\n Ignores nonexistent edges.\n Does not update any stored paths.\n\nC++: bdsg::HashGraph::destroy_edge(const struct handlegraph::handle_t &, const struct handlegraph::handle_t &) --> void", pybind11::arg("left"), pybind11::arg("right"));
cl.def("truncate_handle", (struct handlegraph::handle_t (bdsg::HashGraph::*)(const struct handlegraph::handle_t &, bool, unsigned long)) &bdsg::HashGraph::truncate_handle, "Shorten a node by truncating either the left or right side of the node, relative to the orientation\n of the handle, starting from a given offset along the nodes sequence. Any edges on the truncated\n end of the node are deleted. Returns a (possibly altered) handle to the truncated node.\n May invalid stored paths.\n\nC++: bdsg::HashGraph::truncate_handle(const struct handlegraph::handle_t &, bool, unsigned long) --> struct handlegraph::handle_t", pybind11::arg("handle"), pybind11::arg("trunc_left"), pybind11::arg("offset"));
Expand Down Expand Up @@ -1140,6 +1160,7 @@ void bind_bdsg_internal_hash_map(std::function< pybind11::module &(std::string c
cl.def("for_each_path_handle_impl", (bool (bdsg::HashGraph::*)(const class std::function<bool (const struct handlegraph::path_handle_t &)> &) const) &bdsg::HashGraph::for_each_path_handle_impl, "Execute a function on each path in the graph\n\nC++: bdsg::HashGraph::for_each_path_handle_impl(const class std::function<bool (const struct handlegraph::path_handle_t &)> &) const --> bool", pybind11::arg("iteratee"));
cl.def("for_each_step_on_handle_impl", (bool (bdsg::HashGraph::*)(const struct handlegraph::handle_t &, const class std::function<bool (const struct handlegraph::step_handle_t &)> &) const) &bdsg::HashGraph::for_each_step_on_handle_impl, "Calls a function with all steps of a node on paths.\n\nC++: bdsg::HashGraph::for_each_step_on_handle_impl(const struct handlegraph::handle_t &, const class std::function<bool (const struct handlegraph::step_handle_t &)> &) const --> bool", pybind11::arg("handle"), pybind11::arg("iteratee"));
cl.def("destroy_path", (void (bdsg::HashGraph::*)(const struct handlegraph::path_handle_t &)) &bdsg::HashGraph::destroy_path, "Destroy the given path. Invalidates handles to the path and its node steps.\n\nC++: bdsg::HashGraph::destroy_path(const struct handlegraph::path_handle_t &) --> void", pybind11::arg("path"));
cl.def("destroy_paths", (void (bdsg::HashGraph::*)(const class std::vector<handlegraph::path_handle_t> &)) &bdsg::HashGraph::destroy_paths, "Destroy the given set of paths. Invalidates handles to all the paths and their steps.\n\nC++: bdsg::HashGraph::destroy_paths(const class std::vector<handlegraph::path_handle_t> &) --> void", pybind11::arg("paths"));
cl.def("create_path_handle", [](bdsg::HashGraph &o, const std::string & a0) -> handlegraph::path_handle_t { return o.create_path_handle(a0); }, "", pybind11::arg("name"));
cl.def("create_path_handle", (struct handlegraph::path_handle_t (bdsg::HashGraph::*)(const std::string &, bool)) &bdsg::HashGraph::create_path_handle, "Create a path with the given name. The caller must ensure that no path\n with the given name exists already, or the behavior is undefined.\n Returns a handle to the created empty path. Handles to other paths must\n remain valid.\n\nC++: bdsg::HashGraph::create_path_handle(const std::string &, bool) --> struct handlegraph::path_handle_t", pybind11::arg("name"), pybind11::arg("is_circular"));
cl.def("append_step", (struct handlegraph::step_handle_t (bdsg::HashGraph::*)(const struct handlegraph::path_handle_t &, const struct handlegraph::handle_t &)) &bdsg::HashGraph::append_step, "Append a visit to a node to the given path. Returns a handle to the new\n final step on the path which is appended. If the path is cirular, the new\n step is placed between the steps considered \"last\" and \"first\" by the\n method path_begin. Handles to prior steps on the path, and to other paths,\n must remain valid.\n\nC++: bdsg::HashGraph::append_step(const struct handlegraph::path_handle_t &, const struct handlegraph::handle_t &) --> struct handlegraph::step_handle_t", pybind11::arg("path"), pybind11::arg("to_append"));
Expand Down
2 changes: 1 addition & 1 deletion bdsg/cmake_bindings/bdsg/internal/is_single_stranded.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
#include <functional>
#include <handlegraph/handle_graph.hpp>
#include <handlegraph/types.hpp>
#include <iterator>
#include <memory>
#include <string>
#include <string_view>
#include <utility>
#include <vector>

Expand Down
Loading
Loading