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
Added mechanisms for retrieving tags by position within a sequence #749
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
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 |
---|---|---|
|
@@ -1326,6 +1326,91 @@ static PyObject * hash_consume_and_tag(PyObject * self, PyObject * args) | |
return Py_BuildValue("K", n_consumed); | ||
} | ||
|
||
static PyObject * hash_get_tags_and_positions(PyObject * self, PyObject * args) | ||
{ | ||
khmer_KCountingHashObject * me = (khmer_KCountingHashObject *) self; | ||
CountingHash * counting = me->counting; | ||
|
||
const char * seq; | ||
|
||
if (!PyArg_ParseTuple(args, "s", &seq)) { | ||
return NULL; | ||
} | ||
|
||
// call the C++ function, and trap signals => Python | ||
|
||
std::vector<unsigned int> posns; | ||
std::vector<HashIntoType> tags; | ||
try { | ||
unsigned int pos = 1; | ||
KMerIterator kmers(seq, counting->ksize()); | ||
|
||
while (!kmers.done()) { | ||
HashIntoType kmer = kmers.next(); | ||
if (set_contains(counting->all_tags, kmer)) { | ||
posns.push_back(pos); | ||
tags.push_back(kmer); | ||
} | ||
pos++; | ||
} | ||
} catch (_khmer_signal &e) { | ||
PyErr_SetString(PyExc_ValueError, e.get_message().c_str()); | ||
return NULL; | ||
} | ||
|
||
PyObject * posns_list = PyList_New(posns.size()); | ||
for (size_t i = 0; i < posns.size(); i++) { | ||
PyObject * tup = Py_BuildValue("IK", posns[i], tags[i]); | ||
PyList_SET_ITEM(posns_list, i, tup); | ||
} | ||
|
||
return posns_list; | ||
} | ||
|
||
static PyObject * hash_find_all_tags_list(PyObject * self, PyObject *args) | ||
{ | ||
khmer_KCountingHashObject * me = (khmer_KCountingHashObject *) self; | ||
CountingHash * counting = me->counting; | ||
|
||
const char * kmer_s = NULL; | ||
|
||
if (!PyArg_ParseTuple(args, "s", &kmer_s)) { | ||
return NULL; | ||
} | ||
|
||
if (strlen(kmer_s) < counting->ksize()) { | ||
PyErr_SetString( PyExc_ValueError, | ||
"starting kmer is smaller than the K size of the counting table"); | ||
return NULL; | ||
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. This code branch is untested |
||
} | ||
|
||
SeenSet tags; | ||
|
||
Py_BEGIN_ALLOW_THREADS | ||
|
||
HashIntoType kmer_f, kmer_r; | ||
_hash(kmer_s, counting->ksize(), kmer_f, kmer_r); | ||
|
||
counting->partition->find_all_tags(kmer_f, kmer_r, tags, | ||
counting->all_tags); | ||
|
||
Py_END_ALLOW_THREADS | ||
|
||
PyObject * x = PyList_New(tags.size()); | ||
if (x == NULL) { | ||
return NULL; | ||
} | ||
SeenSet::iterator si; | ||
unsigned long long i = 0; | ||
for (si = tags.begin(); si != tags.end(); ++si) { | ||
// type K for python unsigned long long | ||
PyList_SET_ITEM(x, i, Py_BuildValue("K", *si)); | ||
i++; | ||
} | ||
|
||
return x; | ||
} | ||
|
||
static PyObject * hash_consume_fasta_and_tag(PyObject * self, PyObject * args) | ||
{ | ||
khmer_KCountingHashObject * me = (khmer_KCountingHashObject *) self; | ||
|
@@ -1485,6 +1570,8 @@ static PyMethodDef khmer_counting_methods[] = { | |
METH_VARARGS, "" | ||
}, | ||
{ "consume_and_tag", hash_consume_and_tag, METH_VARARGS, "Consume a sequence and tag it" }, | ||
{ "get_tags_and_positions", hash_get_tags_and_positions, METH_VARARGS, "Retrieve tags and their positions in a sequence." }, | ||
{ "find_all_tags_list", hash_find_all_tags_list, METH_VARARGS, "Find all tags within range of the given k-mer, return as list" }, | ||
{ "consume_fasta_and_tag", hash_consume_fasta_and_tag, METH_VARARGS, "Count all k-mers in a given file" }, | ||
{ "do_subset_partition_with_abundance", hash_do_subset_partition_with_abundance, METH_VARARGS, "" }, | ||
{ "find_all_tags_truncate_on_abundance", hash_find_all_tags_truncate_on_abundance, METH_VARARGS, "" }, | ||
|
@@ -2479,7 +2566,7 @@ static PyObject * hashbits_find_all_tags(PyObject * self, PyObject *args) | |
return NULL; | ||
} | ||
|
||
if (strlen(kmer_s) < hashbits->ksize()) { // @@ | ||
if (strlen(kmer_s) < hashbits->ksize()) { | ||
PyErr_SetString( PyExc_ValueError, | ||
"starting kmer is smaller than the K size of the hashbits"); | ||
return NULL; | ||
|
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
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.
1356-1357 lack testing coverage and won't be called ever anyhow
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.
fixed!
On Tue, Feb 10, 2015 at 11:16:55AM -0800, Michael R. Crusoe wrote:
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.
Thanks; making new pull request