-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #42 from vshiv18/main
Python bindings
- Loading branch information
Showing
8 changed files
with
190 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[submodule "extern/pybind11"] | ||
path = extern/pybind11 | ||
url = ../../pybind/pybind11 | ||
branch = stable |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#include <pybind11/pybind11.h> | ||
#include <pybind11/stl.h> | ||
#include <digest_utils.hpp> | ||
|
||
namespace py = pybind11; | ||
|
||
PYBIND11_MODULE(Digest, m) { | ||
m.doc() = "bindings for Digest"; | ||
m.def("window_minimizer", &window_minimizer, "A function that runs window minimizer digestion", | ||
py::arg("seq"), py::arg("k") = 31, py::arg("w") = 11, py::arg("include_hash") = false); | ||
m.def("modimizer", &modimizer, "A function that runs mod-minimizer digestion", | ||
py::arg("seq"), py::arg("k") = 31, py::arg("mod") = 100, py::arg("include_hash") = false); | ||
m.def("syncmer", &syncmer, "A function that runs syncmer digestion", | ||
py::arg("seq"), py::arg("k") = 31, py::arg("w") = 11, py::arg("include_hash") = false); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#include <digest/window_minimizer.hpp> | ||
#include <digest/syncmer.hpp> | ||
#include <digest/mod_minimizer.hpp> | ||
#include <variant> | ||
|
||
std::variant<std::vector<uint32_t>, std::vector<std::pair<uint32_t, uint32_t>>> window_minimizer ( | ||
const std::string &seq, unsigned k, unsigned large_window, bool include_hash=false) { | ||
digest::WindowMin<digest::BadCharPolicy::SKIPOVER, digest::ds::Adaptive> digester (seq, k, large_window); | ||
if (include_hash) { | ||
std::vector<std::pair<uint32_t, uint32_t>> output; | ||
digester.roll_minimizer(seq.length(), output); | ||
return output; | ||
} | ||
else { | ||
std::vector<uint32_t> output; | ||
digester.roll_minimizer(seq.length(), output); | ||
return output; | ||
} | ||
} | ||
//std::vector<std::pair<size_t, size_t>> output; | ||
|
||
std::variant<std::vector<uint32_t>, std::vector<std::pair<uint32_t, uint32_t>>> modimizer ( | ||
const std::string &seq, unsigned k, uint32_t mod, bool include_hash=false) { | ||
digest::ModMin<digest::BadCharPolicy::SKIPOVER> digester (seq, k, mod); | ||
if (include_hash) { | ||
std::vector<std::pair<uint32_t, uint32_t>> output; | ||
digester.roll_minimizer(seq.length(), output); | ||
return output; | ||
} | ||
else { | ||
std::vector<uint32_t> output; | ||
digester.roll_minimizer(seq.length(), output); | ||
return output; | ||
} | ||
} | ||
|
||
std::variant<std::vector<uint32_t>, std::vector<std::pair<uint32_t, uint32_t>>> syncmer ( | ||
const std::string &seq, unsigned k, unsigned large_window, bool include_hash=false) { | ||
digest::Syncmer<digest::BadCharPolicy::WRITEOVER, digest::ds::Adaptive> digester (seq, k, large_window); | ||
if (include_hash) { | ||
std::vector<std::pair<uint32_t, uint32_t>> output; | ||
digester.roll_minimizer(seq.length(), output); | ||
return output; | ||
} | ||
else { | ||
std::vector<uint32_t> output; | ||
digester.roll_minimizer(seq.length(), output); | ||
return output; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[build-system] | ||
requires = ["setuptools", "pybind11", "ninja", "meson"] | ||
build-backend = "setuptools.build_meta" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
### Adapted from Uncalled setup.py by Sam Kovaka | ||
|
||
from setuptools import setup, find_packages, Extension | ||
from setuptools.command.build_ext import build_ext | ||
import os | ||
import subprocess | ||
import sys | ||
|
||
try: | ||
from pybind11.setup_helpers import Pybind11Extension, ParallelCompile, naive_recompile | ||
ParallelCompile("NPY_NUM_BUILD_JOBS", default=4, needs_recompile=naive_recompile).install() | ||
except: | ||
from setuptools import Extension as Pybind11Extension | ||
|
||
ROOT_DIR = os.getcwd() | ||
|
||
class get_pybind_include(object): | ||
"""Helper class to determine the pybind11 include path | ||
The purpose of this class is to postpone importing pybind11 | ||
until it is actually installed, so that the ``get_include()`` | ||
method can be invoked. """ | ||
|
||
def __str__(self): | ||
import pybind11 | ||
from pybind11.setup_helpers import Pybind11Extension | ||
return pybind11.get_include() | ||
|
||
digest = Pybind11Extension( | ||
"Digest", | ||
sources = ['pybind/bindings.cpp'], | ||
include_dirs = [ | ||
'build/include', | ||
'pybind', | ||
get_pybind_include() | ||
], | ||
library_dirs=['build/lib'], | ||
define_macros = [("PYBIND", None)], | ||
extra_compile_args=['-std=c++17', '-fPIC'] | ||
) | ||
|
||
# class MesonBuildExt(build_ext): | ||
# def run(self): | ||
# # Check for Meson and Ninja installation | ||
# try: | ||
# subprocess.check_output(['meson', '--version']) | ||
# except FileNotFoundError: | ||
# raise RuntimeError("Meson must be installed to build the extensions") | ||
|
||
# try: | ||
# subprocess.check_output(['ninja', '--version']) | ||
# except FileNotFoundError: | ||
# raise RuntimeError("Ninja must be installed to build the extensions") | ||
|
||
# def build_extension(self): | ||
# build_temp = os.path.abspath(self.build_temp) | ||
# # ext_fullpath = self.get_ext_fullpath(ext.name) | ||
# # ext_dir = os.path.abspath(os.path.dirname(ext_fullpath)) | ||
# ext_dir = os.path.abspath(os.path.join(ROOT_DIR, 'build')) | ||
# meson_build_dir = os.path.join(build_temp, 'meson_build') | ||
|
||
# # Create build directory if it doesn't exist | ||
# if not os.path.exists(meson_build_dir): | ||
# os.makedirs(meson_build_dir) | ||
|
||
# meson_args = [ | ||
# 'meson', 'setup', '--prefix', ext_dir, | ||
# '--buildtype=release', meson_build_dir | ||
# ] | ||
|
||
# subprocess.check_call(meson_args) | ||
# subprocess.check_call(['meson', 'install', '-C', meson_build_dir]) | ||
|
||
setup( | ||
name = 'Digest', | ||
version = '0.2', | ||
python_requires=">=3.8", | ||
setup_requires=['setuptools', 'pybind11>=2.6.0', 'meson','ninja'], | ||
install_requires=['pybind11>=2.6.0'], | ||
packages=find_packages(), | ||
ext_modules = [digest], | ||
include_package_data=True, | ||
# cmdclass={'build_ext': MesonBuildExt}, | ||
) |