Skip to content

Commit

Permalink
make format the get_raw_tables changes from dib-lab#671
Browse files Browse the repository at this point in the history
  • Loading branch information
kdm9 committed Mar 9, 2015
1 parent b3a9cae commit 635aa28
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
8 changes: 5 additions & 3 deletions khmer/_khmermodule.cc
Original file line number Diff line number Diff line change
Expand Up @@ -694,8 +694,9 @@ hash_get_raw_tables(khmer_KCountingHash_Object * self, PyObject * args)
PyObject * raw_tables = PyList_New(sizes.size());
for (unsigned int i=0; i<sizes.size(); ++i) {
PyObject * buf = PyBuffer_FromMemory(table_ptrs[i], sizes[i]);
if(!PyBuffer_Check(buf))
if(!PyBuffer_Check(buf)) {
return NULL;
}
PyList_SET_ITEM(raw_tables, i, buf);
}

Expand Down Expand Up @@ -1552,8 +1553,9 @@ static PyMethodDef khmer_counting_methods[] = {
},
{ "output_fasta_kmer_pos_freq", (PyCFunction)hash_output_fasta_kmer_pos_freq, METH_VARARGS, "" },
{ "get", (PyCFunction)hash_get, METH_VARARGS, "Get the count for the given k-mer" },
{ "get_raw_tables", (PyCFunction)hash_get_raw_tables,
METH_VARARGS, "Get a list of the raw tables as memoryview objects"
{
"get_raw_tables", (PyCFunction)hash_get_raw_tables,
METH_VARARGS, "Get a list of the raw tables as memoryview objects"
},
{ "get_min_count", (PyCFunction)hash_get_min_count, METH_VARARGS, "Get the smallest count of all the k-mers in the string" },
{ "get_max_count", (PyCFunction)hash_get_max_count, METH_VARARGS, "Get the largest count of all the k-mers in the string" },
Expand Down
3 changes: 2 additions & 1 deletion lib/counting.hh
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ public:

// Writing to the tables outside of defined methods has undefined behavior!
// As such, this should only be used to return read-only interfaces
Byte ** get_raw_tables() {
Byte ** get_raw_tables()
{
return _counts;
}

Expand Down
4 changes: 3 additions & 1 deletion tests/test_counting_hash.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,16 @@ def test_collision_3(self):

assert hi.get(GG) == 2


def test_get_raw_tables():
ht = khmer.new_counting_hash(20, 1e5, 4)
tables = ht.get_raw_tables()

for size, table in zip(ht.hashsizes(), tables):
assert type(table) is buffer
assert isinstance(table, buffer)
assert size == len(table)


def test_get_raw_tables_view():
ht = khmer.new_counting_hash(20, 1e5, 4)
tables = ht.get_raw_tables()
Expand Down

0 comments on commit 635aa28

Please sign in to comment.