Skip to content

Commit

Permalink
Merge branch 'min-coverage-default-None' into 'dev'
Browse files Browse the repository at this point in the history
None default argument for min_coverage

See merge request epi2melabs/pyspoa!5
  • Loading branch information
julibeg committed Oct 4, 2023
2 parents ec00b28 + 2ee44ba commit ffc856a
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [v0.2.1]
### Changed
- Default argument for `min_coverage` to `None`

## [v0.2.0]
### Changed
- Updated SPOA to v4.1.2
Expand Down
13 changes: 10 additions & 3 deletions pyspoa.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
#include "spoa.hpp"

#define PYBIND11_DETAILED_ERROR_MESSAGES // for type information in casting errors
#include <pybind11/stl.h>
#include <pybind11/pybind11.h>

using namespace pybind11::literals; // for _a in pybind def

auto poa(std::vector<std::string> sequences, int algorithm, bool genmsa,
int m, int n, int g, int e, int q, int c, int min_coverage) -> pybind11::tuple
int m, int n, int g, int e, int q, int c, pybind11::object min_coverage) -> pybind11::tuple
{
// set min_coverage to the default of the SPOA CLI (-1) if None
int min_cov = -1;
if (min_coverage != pybind11::none()) {
min_cov = min_coverage.cast<int>();
}
auto alignment_engine = spoa::AlignmentEngine::Create(
static_cast<spoa::AlignmentType>(algorithm), m, n, g, e, q, c
);
Expand All @@ -18,7 +25,7 @@ auto poa(std::vector<std::string> sequences, int algorithm, bool genmsa,
graph.AddAlignment(alignment, it);
}

auto consensus = graph.GenerateConsensus(min_coverage);
auto consensus = graph.GenerateConsensus(min_cov);
std::vector<std::string> msa;
if (genmsa)
msa = graph.GenerateMultipleSequenceAlignment();
Expand All @@ -31,7 +38,7 @@ PYBIND11_MODULE(spoa, m) {
"poa", &poa, "",
"sequences"_a, "algorithm"_a=0, "genmsa"_a=true,
"m"_a=5, "n"_a=-4, "g"_a=-8, "e"_a=-6, "q"_a=-10, "c"_a=-4,
"min_coverage"_a=-1
"min_coverage"_a=pybind11::none()
);

m.attr("__version__") = VERSION_INFO;
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def build_extensions(self):

setup(
name='pyspoa',
version='0.2.0',
version='0.2.1',
author='Oxford Nanoporetech Technologies, Ltd.',
author_email='support@nanoporetech.com',
url='https://github.com/nanoporetech/pyspoa',
Expand Down
24 changes: 24 additions & 0 deletions tests/test_pyspoa.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,30 @@ def test_bindings_no_msa(self):
self.assertEqual(consensus, 'AACTTATA')
self.assertEqual(len(msa), 0)

def test_bindings_min_coverage(self):
""" simple poa to check bindings with `min_coverage` param"""
consensus, msa = poa(['AACTTATA', 'AACTTATG', 'AACTATA'], min_coverage=3)
self.assertEqual(consensus, 'AACTAT')
self.assertEqual(len(msa), 3)

def test_bindings_min_coverage_None(self):
""" simple poa to check bindings with `min_coverage=None`"""
consensus, msa = poa(['AACTTATA', 'AACTTATG', 'AACTATA'], min_coverage=None)
self.assertEqual(consensus, 'AACTTATA')
self.assertEqual(len(msa), 3)

def test_bindings_min_coverage_wrong_type_string(self):
""" check that bindings with `min_coverage=str` throw error"""
self.assertRaises(
RuntimeError, poa, ["AACTTATA", "AACTTATG", "AACTATA"], min_coverage="x"
)

def test_bindings_min_coverage_wrong_type_float(self):
""" check that bindings with `min_coverage=float` throw error"""
self.assertRaises(
RuntimeError, poa, ["AACTTATA", "AACTTATG", "AACTATA"], min_coverage=1.5
)


if __name__ == '__main__':
main()

0 comments on commit ffc856a

Please sign in to comment.