-
Notifications
You must be signed in to change notification settings - Fork 298
[MRG] Expose *_with_reads_parser method overloads to Python API #1753
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
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -109,25 +109,43 @@ PyMethodDef khmer_hashtable_methods[] = { | |
| "Increment the counts of all the k-mers in the sequences in the " | ||
| "given file" | ||
| }, | ||
| { | ||
| "consume_seqfile_with_reads_parser", | ||
| (PyCFunction)hashtable_consume_seqfile_with_reads_parser, METH_VARARGS, | ||
| "Count all k-mers retrieved with this reads parser object." | ||
| }, | ||
| { | ||
| "consume_seqfile_banding", | ||
| (PyCFunction)hashtable_consume_seqfile_banding, METH_VARARGS, | ||
| "Consume sequences in k-mer banding mode" | ||
| }, | ||
| { | ||
| "consume_seqfile_banding_with_reads_parser", | ||
| (PyCFunction)hashtable_consume_seqfile_banding_with_reads_parser, | ||
| METH_VARARGS, | ||
| "Consume sequences in k-mer banding mode" | ||
| }, | ||
| { | ||
| "consume_seqfile_with_mask", | ||
| (PyCFunction)hashtable_consume_seqfile_with_mask, METH_VARARGS, | ||
| "Consume any k-mers not present in the provided mask" | ||
| }, | ||
| { | ||
| "consume_seqfile_with_mask_with_reads_parser", | ||
| (PyCFunction)hashtable_consume_seqfile_with_mask_with_reads_parser, | ||
| METH_VARARGS, | ||
| "Consume any k-mers not present in the provided mask" | ||
| }, | ||
| { | ||
| "consume_seqfile_banding_with_mask", | ||
| (PyCFunction)hashtable_consume_seqfile_banding_with_mask, METH_VARARGS, | ||
| "Consume sequences in k-mer banding mode, with a mask" | ||
| }, | ||
| { | ||
| "consume_seqfile_with_reads_parser", | ||
| (PyCFunction)hashtable_consume_seqfile_with_reads_parser, METH_VARARGS, | ||
| "Count all k-mers retrieved with this reads parser object." | ||
| "consume_seqfile_banding_with_mask_with_reads_parser", | ||
| (PyCFunction)hashtable_consume_seqfile_banding_with_mask_with_reads_parser, | ||
| METH_VARARGS, | ||
| "Consume sequences in k-mer banding mode, with a mask" | ||
| }, | ||
| { | ||
| "get", | ||
|
|
@@ -369,6 +387,52 @@ hashtable_consume_seqfile(khmer_KHashtable_Object * me, PyObject * args) | |
| return Py_BuildValue("IK", total_reads, n_consumed); | ||
| } | ||
|
|
||
| PyObject * | ||
| hashtable_consume_seqfile_with_reads_parser(khmer_KHashtable_Object * me, | ||
| PyObject * args) | ||
| { | ||
| Hashtable * hashtable = me->hashtable; | ||
|
|
||
| PyObject * rparser_obj = NULL; | ||
|
|
||
| if (!PyArg_ParseTuple(args, "O", &rparser_obj)) { | ||
| return NULL; | ||
| } | ||
|
|
||
| FastxParserPtr& rparser = _PyObject_to_khmer_ReadParser( rparser_obj ); | ||
|
|
||
| // call the C++ function, and trap signals => Python | ||
| unsigned long long n_consumed = 0; | ||
| unsigned int total_reads = 0; | ||
| const char *value_exception = NULL; | ||
| const char *file_exception = NULL; | ||
| std::string exc_string; | ||
|
|
||
| Py_BEGIN_ALLOW_THREADS | ||
| try { | ||
| hashtable->consume_seqfile<FastxReader>(rparser, total_reads, n_consumed); | ||
| } catch (oxli_file_exception &exc) { | ||
| exc_string = exc.what(); | ||
| file_exception = exc_string.c_str(); | ||
| } catch (oxli_value_exception &exc) { | ||
| exc_string = exc.what(); | ||
| value_exception = exc_string.c_str(); | ||
| } | ||
| Py_END_ALLOW_THREADS | ||
|
|
||
| if (file_exception != NULL) { | ||
| PyErr_SetString(PyExc_OSError, file_exception); | ||
| return NULL; | ||
| } | ||
| if (value_exception != NULL) { | ||
| PyErr_SetString(PyExc_ValueError, value_exception); | ||
| return NULL; | ||
| } | ||
|
|
||
| rparser->close(); | ||
| return Py_BuildValue("IK", total_reads, n_consumed); | ||
| } | ||
|
|
||
| PyObject * | ||
| hashtable_consume_seqfile_banding(khmer_KHashtable_Object * me, PyObject * args) | ||
| { | ||
|
|
@@ -398,6 +462,38 @@ hashtable_consume_seqfile_banding(khmer_KHashtable_Object * me, PyObject * args) | |
| return Py_BuildValue("IK", total_reads, n_consumed); | ||
| } | ||
|
|
||
| PyObject * | ||
| hashtable_consume_seqfile_banding_with_reads_parser(khmer_KHashtable_Object * me, PyObject * args) | ||
| { | ||
| Hashtable * hashtable = me->hashtable; | ||
|
|
||
| PyObject * rparser_obj = NULL; | ||
| unsigned int num_bands; | ||
| unsigned int band; | ||
|
|
||
| if (!PyArg_ParseTuple(args, "OII", &rparser_obj, &num_bands, &band)) { | ||
| return NULL; | ||
| } | ||
|
|
||
| FastxParserPtr& rparser = _PyObject_to_khmer_ReadParser( rparser_obj ); | ||
|
|
||
| // call the C++ function, and trap signals => Python | ||
| unsigned long long n_consumed = 0; | ||
| unsigned int total_reads = 0; | ||
| try { | ||
| hashtable->consume_seqfile_banding<FastxReader>(rparser, num_bands, band, total_reads, n_consumed); | ||
| } catch (oxli_file_exception &exc) { | ||
| PyErr_SetString(PyExc_OSError, exc.what()); | ||
| return NULL; | ||
| } catch (oxli_value_exception &exc) { | ||
| PyErr_SetString(PyExc_ValueError, exc.what()); | ||
| return NULL; | ||
| } | ||
|
|
||
| rparser->close(); | ||
| return Py_BuildValue("IK", total_reads, n_consumed); | ||
| } | ||
|
|
||
| PyObject * | ||
| hashtable_consume_seqfile_with_mask(khmer_KHashtable_Object * me, PyObject * args) | ||
| { | ||
|
|
@@ -429,6 +525,40 @@ hashtable_consume_seqfile_with_mask(khmer_KHashtable_Object * me, PyObject * arg | |
| return Py_BuildValue("IK", total_reads, n_consumed); | ||
| } | ||
|
|
||
| PyObject * | ||
| hashtable_consume_seqfile_with_mask_with_reads_parser(khmer_KHashtable_Object * me, PyObject * args) | ||
| { | ||
| Hashtable * hashtable = me->hashtable; | ||
|
|
||
| PyObject * rparser_obj = NULL; | ||
| khmer_KHashtable_Object *mask = NULL; | ||
| unsigned int threshold = 0; | ||
|
|
||
| if (!PyArg_ParseTuple(args, "OO|I", &rparser_obj, &mask, &threshold)) { | ||
| return NULL; | ||
| } | ||
|
|
||
| FastxParserPtr& rparser = _PyObject_to_khmer_ReadParser( rparser_obj ); | ||
|
|
||
| // call the C++ function, and trap signals => Python | ||
| unsigned long long n_consumed = 0; | ||
| unsigned int total_reads = 0; | ||
| try { | ||
| hashtable->consume_seqfile_with_mask<FastxReader>( | ||
| rparser, mask->hashtable, threshold, total_reads, n_consumed | ||
| ); | ||
| } catch (oxli_file_exception &exc) { | ||
| PyErr_SetString(PyExc_OSError, exc.what()); | ||
| return NULL; | ||
| } catch (oxli_value_exception &exc) { | ||
| PyErr_SetString(PyExc_ValueError, exc.what()); | ||
| return NULL; | ||
| } | ||
|
|
||
| rparser->close(); | ||
| return Py_BuildValue("IK", total_reads, n_consumed); | ||
| } | ||
|
|
||
| PyObject * | ||
| hashtable_consume_seqfile_banding_with_mask(khmer_KHashtable_Object * me, PyObject * args) | ||
| { | ||
|
|
@@ -464,52 +594,42 @@ hashtable_consume_seqfile_banding_with_mask(khmer_KHashtable_Object * me, PyObje | |
| } | ||
|
|
||
| PyObject * | ||
| hashtable_consume_seqfile_with_reads_parser(khmer_KHashtable_Object * me, | ||
| PyObject * args) | ||
| hashtable_consume_seqfile_banding_with_mask_with_reads_parser(khmer_KHashtable_Object * me, PyObject * args) | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like git is struggling with the similarity between all of the variants of this function and the fact that I cut n pasted this function further up, again for consistency. I promise the CPython code changes are a lot more boring than this diff would suggest. :-) |
||
| { | ||
| Hashtable * hashtable = me->hashtable; | ||
| Hashtable * hashtable = me->hashtable; | ||
|
|
||
| PyObject * rparser_obj = NULL; | ||
| unsigned int num_bands; | ||
| unsigned int band; | ||
| khmer_KHashtable_Object *mask = NULL; | ||
| unsigned int threshold = 0; | ||
|
|
||
| if (!PyArg_ParseTuple(args, "O", &rparser_obj)) { | ||
| if (!PyArg_ParseTuple(args, "OIIO|I", &rparser_obj, &num_bands, &band, &mask, &threshold)) { | ||
| return NULL; | ||
| } | ||
|
|
||
| FastxParserPtr& rparser = _PyObject_to_khmer_ReadParser( rparser_obj ); | ||
|
|
||
| // call the C++ function, and trap signals => Python | ||
| unsigned long long n_consumed = 0; | ||
| unsigned int total_reads = 0; | ||
| const char *value_exception = NULL; | ||
| const char *file_exception = NULL; | ||
| std::string exc_string; | ||
|
|
||
| Py_BEGIN_ALLOW_THREADS | ||
| unsigned long long n_consumed = 0; | ||
| unsigned int total_reads = 0; | ||
| try { | ||
| hashtable->consume_seqfile<FastxReader>(rparser, total_reads, n_consumed); | ||
| hashtable->consume_seqfile_banding_with_mask<FastxReader>( | ||
| rparser, num_bands, band, mask->hashtable, threshold, total_reads, | ||
| n_consumed | ||
| ); | ||
| } catch (oxli_file_exception &exc) { | ||
| exc_string = exc.what(); | ||
| file_exception = exc_string.c_str(); | ||
| } catch (oxli_value_exception &exc) { | ||
| exc_string = exc.what(); | ||
| value_exception = exc_string.c_str(); | ||
| } | ||
| Py_END_ALLOW_THREADS | ||
|
|
||
| if (file_exception != NULL) { | ||
| PyErr_SetString(PyExc_OSError, file_exception); | ||
| PyErr_SetString(PyExc_OSError, exc.what()); | ||
| return NULL; | ||
| } | ||
| if (value_exception != NULL) { | ||
| PyErr_SetString(PyExc_ValueError, value_exception); | ||
| } catch (oxli_value_exception &exc) { | ||
| PyErr_SetString(PyExc_ValueError, exc.what()); | ||
| return NULL; | ||
| } | ||
|
|
||
| rparser->close(); | ||
| return Py_BuildValue("IK", total_reads, n_consumed); | ||
| } | ||
|
|
||
|
|
||
|
|
||
| PyObject * | ||
| hashtable_consume(khmer_KHashtable_Object * me, PyObject * args) | ||
| { | ||
|
|
||
This file contains hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved this function up for consistency's sake: for each overloaded method, the version that accepts a string is first, and the version that accepts a parser is second.