Skip to content
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
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,26 @@ Once installed, you can import and use the Digest library in Python:
['ACGTA', 'CGTAG', 'AGCTA', 'TAGCT', 'GCTGA', 'TTACA', 'TACAT', 'GTATG', 'GCAAG', 'TGATC', 'CGTAG', 'TAGTG', 'ATGCT']
```

We have also implemented parallel execution in the python library:
```
>>> import timeit
>>> timeit.timeit('window_minimizer(seq, k=5, w=11)',
... setup='from digest import window_minimizer; seq = open("tests/bench/chrY.fa", "rb").read()',
... number=10)
19.85955114942044
>>> timeit.timeit('window_minimizer(seq, k=5, w=11, num_threads=4)',
... setup='from digest import window_minimizer; seq = open("tests/bench/chrY.fa", "rb").read()',
... number=10)
10.327348310500383
```

Functions can also return numpy arrays with the `*_np` function variant:
```
>>> from digest import window_minimizer_np
>>> window_minimizer_np(b'ACGTACGTAGCTAGCTAGCTAGCTGATTACATACTGTATGCAAGCTAGCTGATCGATCGTAGCTAGTGATGCTAGCTAC', k=5, w=11)
array([ 4, 5, 16, 19, 21, 26, 27, 35, 39, 49, 57, 63, 68], dtype=uint32)
```

<!---
# Implementation
Supports Mod Minimizers, Window Minimizers, and Syncmers
Expand Down
18 changes: 9 additions & 9 deletions include/digest/thread_out.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ void thread_mod(
ind += assigned_kmer_am;
}
for (auto &t : thread_vector) {
vec.emplace_back(t.get());
vec.emplace_back(std::move(t.get()));
}
}

Expand Down Expand Up @@ -235,7 +235,7 @@ void thread_mod(
ind += assigned_kmer_am;
}
for (auto &t : thread_vector) {
vec.emplace_back(t.get());
vec.emplace_back(std::move(t.get()));
}
}

Expand Down Expand Up @@ -305,14 +305,14 @@ void thread_wind(
extras--;
}

thread_vector.emplace_back(std::async(thread_wind_roll1<P, T>, seq, ind,
thread_vector.push_back(std::async(thread_wind_roll1<P, T>, seq, ind,
k, large_wind_kmer_am,
minimized_h, assigned_lwind_am));

ind += assigned_lwind_am;
}
for (auto &t : thread_vector) {
vec.emplace_back(t.get());
vec.emplace_back(std::move(t.get()));
}

// handle duplicates
Expand Down Expand Up @@ -365,7 +365,7 @@ void thread_wind(
unsigned lwinds_per_thread = num_lwinds / thread_count;
unsigned extras = num_lwinds % thread_count;
vec.reserve(thread_count);
std::vector<std::future<std::pair<uint32_t, uint32_t>>> thread_vector;
std::vector<std::future<std::vector<std::pair<uint32_t, uint32_t>>>> thread_vector;

size_t ind = start;
for (unsigned i = 0; i < thread_count; i++) {
Expand All @@ -377,14 +377,14 @@ void thread_wind(
extras--;
}

thread_vector.emplace_back(std::async(thread_wind_roll2<P, T>, seq, ind,
thread_vector.push_back(std::async(thread_wind_roll2<P, T>, seq, ind,
k, large_wind_kmer_am,
minimized_h, assigned_lwind_am));

ind += assigned_lwind_am;
}
for (auto &t : thread_vector) {
vec.emplace_back(t.get());
vec.emplace_back(std::move(t.get()));
}

// handle duplicates
Expand Down Expand Up @@ -473,7 +473,7 @@ void thread_sync(
}
for (auto &t : thread_vector) {

vec.emplace_back(t.get());
vec.emplace_back(std::move(t.get()));
}
}

Expand Down Expand Up @@ -535,7 +535,7 @@ void thread_sync(
ind += assigned_lwind_am;
}
for (auto &t : thread_vector) {
vec.emplace_back(t.get());
vec.emplace_back(std::move(t.get()));
}
}

Expand Down
54 changes: 46 additions & 8 deletions pybind/bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,53 @@ 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,

m.def("window_minimizer",
[](std::string_view seq, unsigned k, unsigned w, unsigned num_threads, bool include_hash) {
return window_minimizer_wrapper(seq.data(), seq.size(), k, w, num_threads, include_hash);
},
"A function that runs window minimizer digestion",
py::call_guard<py::gil_scoped_release>(),
py::arg("seq"), py::arg("k") = 31, py::arg("w") = 11, py::arg("num_threads") = 1,
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,

m.def("modimizer",
[](std::string_view seq, unsigned k, uint32_t mod, unsigned num_threads, bool include_hash) {
return modimizer_wrapper(seq.data(), seq.size(), k, mod, num_threads, include_hash);
},
"A function that runs mod-minimizer digestion",
py::call_guard<py::gil_scoped_release>(),
py::arg("seq"), py::arg("k") = 31, py::arg("mod") = 100, py::arg("num_threads") = 1,
py::arg("include_hash") = false);

m.def("syncmer",
[](std::string_view seq, unsigned k, unsigned w, unsigned num_threads, bool include_hash) {
return syncmer_wrapper(seq.data(), seq.size(), k, w, num_threads, include_hash);
},
"A function that runs syncmer digestion",
py::call_guard<py::gil_scoped_release>(),
py::arg("seq"), py::arg("k") = 31, py::arg("w") = 11, py::arg("num_threads") = 1,
py::arg("include_hash") = false);

m.def("window_minimizer_np",
[](std::string_view seq, unsigned k, unsigned w, unsigned num_threads, bool include_hash) {
return window_minimizer_numpy(seq.data(), seq.size(), k, w, num_threads, include_hash);
},
"A function that runs window minimizer digestion and returns a numpy array",
py::arg("seq"), py::arg("k") = 31, py::arg("w") = 11, py::arg("num_threads") = 1,
py::arg("include_hash") = false);
m.def("modimizer_np",
[](std::string_view seq, unsigned k, uint32_t mod, unsigned num_threads, bool include_hash) {
return modimizer_numpy(seq.data(), seq.size(), k, mod, num_threads, include_hash);
},
"A function that runs mod-minimizer digestion and returns a numpy array",
py::arg("seq"), py::arg("k") = 31, py::arg("mod") = 100, py::arg("num_threads") = 1,
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,
m.def("syncmer_np",
[](std::string_view seq, unsigned k, unsigned w, unsigned num_threads, bool include_hash) {
return syncmer_numpy(seq.data(), seq.size(), k, w, num_threads, include_hash);
},
"A function that runs syncmer digestion and returns a numpy array",
py::arg("seq"), py::arg("k") = 31, py::arg("w") = 11, py::arg("num_threads") = 1,
py::arg("include_hash") = false);
}
Loading
Loading