diff --git a/ChangeLog b/ChangeLog index 7cc955c17b..13669a1953 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2015-02-23 Michael R. Crusoe + + * khmer/{__init__.py,_khmermodule.cc},lib/{hashbits.cc,hashbits.hh, + hashtable,tests/test_{c_wrapper,read_parsers}.py: remove unused callback + functionality + 2015-02-23 Michael R. Crusoe * setup.py: point to the latest screed release candidate to work around diff --git a/khmer/__init__.py b/khmer/__init__.py index f8b1b1c566..c66140fa40 100644 --- a/khmer/__init__.py +++ b/khmer/__init__.py @@ -10,7 +10,6 @@ from khmer._khmer import _new_counting_hash from khmer._khmer import _new_hashbits -from khmer._khmer import set_reporting_callback from khmer._khmer import _LabelHash from khmer._khmer import _Hashbits from khmer._khmer import _HLLCounter @@ -100,16 +99,6 @@ def load_counting_hash(filename): return hashtable -def _default_reporting_callback(info, n_reads, other): - print '...', info, n_reads, other - - -def reset_reporting_callback(): - set_reporting_callback(_default_reporting_callback) - -reset_reporting_callback() - - def extract_hashbits_info(filename): """Open the given hashbits file and return a tuple of information. diff --git a/khmer/_khmermodule.cc b/khmer/_khmermodule.cc index caefbde074..7ca5c504e7 100644 --- a/khmer/_khmermodule.cc +++ b/khmer/_khmermodule.cc @@ -137,46 +137,6 @@ class _khmer_signal : public _khmer_exception typedef pre_partition_info _pre_partition_info; -// default callback obj; -static PyObject *_callback_obj = NULL; - -// callback function to pass into C++ functions - -void _report_fn(const char * info, void * data, unsigned long long n_reads, - unsigned long long other) -{ - // handle signals etc. (like CTRL-C) - if (PyErr_CheckSignals() != 0) { - throw _khmer_signal("PyErr_CheckSignals received a signal"); - } - - // set data to default? - if (!data && _callback_obj) { - data = _callback_obj; - } - - // if 'data' is set, it is None, or a Python callable - if (data) { - PyObject * obj = (PyObject *) data; - if (obj != Py_None) { - PyObject * args = Py_BuildValue("sKK", info, n_reads, other); - if (args != NULL) { - PyObject * r = PyObject_Call(obj, args, NULL); - Py_XDECREF(r); - } - Py_XDECREF(args); - } - } - - if (PyErr_Occurred()) { - throw _khmer_signal("PyErr_Occurred is set"); - } - - // ...allow other Python threads to do stuff... - Py_BEGIN_ALLOW_THREADS; - Py_END_ALLOW_THREADS; -} - /***********************************************************************/ // @@ -853,11 +813,8 @@ static PyObject * hash_consume_fasta(PyObject * self, PyObject * args) CountingHash * counting = me->counting; const char * filename; - PyObject * callback_obj = NULL; - if (!PyArg_ParseTuple( - args, "s|O", &filename, &callback_obj - )) { + if (!PyArg_ParseTuple(args, "s", &filename)) { return NULL; } @@ -865,8 +822,7 @@ static PyObject * hash_consume_fasta(PyObject * self, PyObject * args) unsigned long long n_consumed = 0; unsigned int total_reads = 0; try { - counting->consume_fasta(filename, total_reads, n_consumed, - _report_fn, callback_obj); + counting->consume_fasta(filename, total_reads, n_consumed); } catch (_khmer_signal &e) { PyErr_SetString(PyExc_IOError, e.get_message().c_str()); return NULL; @@ -886,11 +842,8 @@ static PyObject * hash_consume_fasta_with_reads_parser( CountingHash * counting = me->counting; PyObject * rparser_obj = NULL; - PyObject * callback_obj = NULL; - if (!PyArg_ParseTuple( - args, "O|O", &rparser_obj, &callback_obj - )) { + if (!PyArg_ParseTuple(args, "O", &rparser_obj)) { return NULL; } @@ -904,8 +857,7 @@ static PyObject * hash_consume_fasta_with_reads_parser( bool exc_raised = false; Py_BEGIN_ALLOW_THREADS try { - counting->consume_fasta(rparser, total_reads, n_consumed, - _report_fn, callback_obj); + counting->consume_fasta(rparser, total_reads, n_consumed); } catch (_khmer_signal &e) { exc = e.get_message().c_str(); exc_raised = true; @@ -1175,10 +1127,9 @@ static PyObject * hash_fasta_count_kmers_by_position(PyObject * self, unsigned int max_read_len = 0; long max_read_len_long; int limit_by_count_int; - PyObject * callback_obj = NULL; - if (!PyArg_ParseTuple(args, "sli|O", &inputfile, &max_read_len_long, - &limit_by_count_int, &callback_obj)) { + if (!PyArg_ParseTuple(args, "sli", &inputfile, &max_read_len_long, + &limit_by_count_int)) { return NULL; } if (max_read_len_long < 0 || max_read_len_long >= pow(2, 32)) { @@ -1197,7 +1148,7 @@ static PyObject * hash_fasta_count_kmers_by_position(PyObject * self, unsigned long long * counts; counts = counting->fasta_count_kmers_by_position(inputfile, max_read_len, - (unsigned short) limit_by_count_int, _report_fn, callback_obj); + (unsigned short) limit_by_count_int); PyObject * x = PyList_New(max_read_len); if (x == NULL) { @@ -1226,17 +1177,13 @@ static PyObject * hash_fasta_dump_kmers_by_abundance(PyObject * self, const char * inputfile; int limit_by = 0; - PyObject * callback_obj = NULL; - if (!PyArg_ParseTuple(args, "si|O", &inputfile, &limit_by, - &callback_obj)) { + if (!PyArg_ParseTuple(args, "si", &inputfile, &limit_by)) { return NULL; } counting->fasta_dump_kmers_by_abundance(inputfile, - limit_by, - _report_fn, callback_obj); - + limit_by); Py_RETURN_NONE; } @@ -1427,9 +1374,8 @@ static PyObject * hash_consume_fasta_and_tag(PyObject * self, PyObject * args) CountingHash * counting = me->counting; const char * filename; - PyObject * callback_obj = NULL; - if (!PyArg_ParseTuple(args, "s|O", &filename, &callback_obj)) { + if (!PyArg_ParseTuple(args, "s", &filename)) { return NULL; } @@ -1439,8 +1385,7 @@ static PyObject * hash_consume_fasta_and_tag(PyObject * self, PyObject * args) unsigned int total_reads; try { - counting->consume_fasta_and_tag(filename, total_reads, n_consumed, - _report_fn, callback_obj); + counting->consume_fasta_and_tag(filename, total_reads, n_consumed); } catch (_khmer_signal &e) { PyErr_SetString(PyExc_IOError, e.get_message().c_str()); return NULL; @@ -1498,18 +1443,16 @@ static PyObject * hash_do_subset_partition_with_abundance(PyObject * self, khmer_KCountingHashObject * me = (khmer_KCountingHashObject *) self; CountingHash * counting = me->counting; - PyObject * callback_obj = NULL; HashIntoType start_kmer = 0, end_kmer = 0; PyObject * break_on_stop_tags_o = NULL; PyObject * stop_big_traversals_o = NULL; BoundedCounterType min_count, max_count; - if (!PyArg_ParseTuple(args, "HH|KKOOO", + if (!PyArg_ParseTuple(args, "HH|KKOO", &min_count, &max_count, &start_kmer, &end_kmer, &break_on_stop_tags_o, - &stop_big_traversals_o, - &callback_obj)) { + &stop_big_traversals_o)) { return NULL; } @@ -1529,8 +1472,7 @@ static PyObject * hash_do_subset_partition_with_abundance(PyObject * self, subset_p->do_partition_with_abundance(start_kmer, end_kmer, min_count, max_count, break_on_stop_tags, - stop_big_traversals, - _report_fn, callback_obj); + stop_big_traversals); Py_END_ALLOW_THREADS } catch (_khmer_signal &e) { return NULL; @@ -1870,12 +1812,10 @@ static PyObject * hashbits_count_overlap(PyObject * self, PyObject * args) Hashbits * hashbits = me->hashbits; khmer_KHashbitsObject * ht2_argu; const char * filename; - PyObject * callback_obj = NULL; Hashbits * ht2; - if (!PyArg_ParseTuple(args, "sO!|O", &filename, &khmer_KHashbitsType, - &ht2_argu, - &callback_obj)) { + if (!PyArg_ParseTuple(args, "sO!", &filename, &khmer_KHashbitsType, + &ht2_argu)) { return NULL; } @@ -1888,8 +1828,7 @@ static PyObject * hashbits_count_overlap(PyObject * self, PyObject * args) HashIntoType curve[2][100]; try { - hashbits->consume_fasta_overlap(filename, curve, *ht2, total_reads, n_consumed, - _report_fn, callback_obj); + hashbits->consume_fasta_overlap(filename, curve, *ht2, total_reads, n_consumed); } catch (_khmer_signal &e) { PyErr_SetString(PyExc_IOError, e.get_message().c_str()); return NULL; @@ -2247,15 +2186,13 @@ static PyObject * hashbits_do_subset_partition(PyObject * self, khmer_KHashbitsObject * me = (khmer_KHashbitsObject *) self; Hashbits * hashbits = me->hashbits; - PyObject * callback_obj = NULL; HashIntoType start_kmer = 0, end_kmer = 0; PyObject * break_on_stop_tags_o = NULL; PyObject * stop_big_traversals_o = NULL; - if (!PyArg_ParseTuple(args, "|KKOOO", &start_kmer, &end_kmer, + if (!PyArg_ParseTuple(args, "|KKOO", &start_kmer, &end_kmer, &break_on_stop_tags_o, - &stop_big_traversals_o, - &callback_obj)) { + &stop_big_traversals_o)) { return NULL; } @@ -2273,8 +2210,7 @@ static PyObject * hashbits_do_subset_partition(PyObject * self, Py_BEGIN_ALLOW_THREADS subset_p = new SubsetPartition(hashbits); subset_p->do_partition(start_kmer, end_kmer, break_on_stop_tags, - stop_big_traversals, - _report_fn, callback_obj); + stop_big_traversals); Py_END_ALLOW_THREADS } catch (_khmer_signal &e) { return NULL; @@ -2350,9 +2286,8 @@ static PyObject * hashbits_consume_fasta(PyObject * self, PyObject * args) Hashbits * hashbits = me->hashbits; const char * filename; - PyObject * callback_obj = NULL; - if (!PyArg_ParseTuple(args, "s|O", &filename, &callback_obj)) { + if (!PyArg_ParseTuple(args, "s", &filename)) { return NULL; } @@ -2362,8 +2297,7 @@ static PyObject * hashbits_consume_fasta(PyObject * self, PyObject * args) unsigned int total_reads = 0; try { - hashbits->consume_fasta(filename, total_reads, n_consumed, - _report_fn, callback_obj); + hashbits->consume_fasta(filename, total_reads, n_consumed); } catch (_khmer_signal &e) { PyErr_SetString(PyExc_IOError, e.get_message().c_str()); return NULL; @@ -2383,10 +2317,9 @@ static PyObject * hashbits_consume_fasta_with_reads_parser( Hashbits * hashbits = me->hashbits; PyObject * rparser_obj = NULL; - PyObject * callback_obj = NULL; if (!PyArg_ParseTuple( - args, "O|O", &rparser_obj, &callback_obj)) { + args, "O", &rparser_obj)) { return NULL; } @@ -2399,8 +2332,7 @@ static PyObject * hashbits_consume_fasta_with_reads_parser( char const * exc = NULL; Py_BEGIN_ALLOW_THREADS try { - hashbits->consume_fasta(rparser, total_reads, n_consumed, - _report_fn, callback_obj); + hashbits->consume_fasta(rparser, total_reads, n_consumed); } catch (_khmer_signal &e) { exc = e.get_message().c_str(); } @@ -2451,9 +2383,8 @@ static PyObject * hashbits_consume_fasta_and_tag(PyObject * self, Hashbits * hashbits = me->hashbits; const char * filename; - PyObject * callback_obj = NULL; - if (!PyArg_ParseTuple(args, "s|O", &filename, &callback_obj)) { + if (!PyArg_ParseTuple(args, "s", &filename)) { return NULL; } @@ -2463,8 +2394,7 @@ static PyObject * hashbits_consume_fasta_and_tag(PyObject * self, unsigned int total_reads; try { - hashbits->consume_fasta_and_tag(filename, total_reads, n_consumed, - _report_fn, callback_obj); + hashbits->consume_fasta_and_tag(filename, total_reads, n_consumed); } catch (_khmer_signal &e) { PyErr_SetString(PyExc_IOError, e.get_message().c_str()); return NULL; @@ -2484,10 +2414,9 @@ static PyObject * hashbits_consume_fasta_and_tag_with_reads_parser( Hashbits * hashbits = me->hashbits; python::ReadParser_Object * rparser_obj = NULL; - PyObject * callback_obj = NULL; - if (!PyArg_ParseTuple( args, "O!|O", &python::ReadParser_Type, - &rparser_obj, &callback_obj )) { + if (!PyArg_ParseTuple( args, "O!", &python::ReadParser_Type, + &rparser_obj)) { return NULL; } @@ -2500,7 +2429,7 @@ static PyObject * hashbits_consume_fasta_and_tag_with_reads_parser( Py_BEGIN_ALLOW_THREADS try { hashbits->consume_fasta_and_tag( - rparser, total_reads, n_consumed, _report_fn, callback_obj + rparser, total_reads, n_consumed ); } catch (_khmer_signal &e) { exc = e.get_message().c_str(); @@ -2523,9 +2452,8 @@ static PyObject * hashbits_consume_fasta_and_tag_with_stoptags(PyObject * self, Hashbits * hashbits = me->hashbits; const char * filename; - PyObject * callback_obj = NULL; - if (!PyArg_ParseTuple(args, "s|O", &filename, &callback_obj)) { + if (!PyArg_ParseTuple(args, "s", &filename)) { return NULL; } @@ -2536,8 +2464,7 @@ static PyObject * hashbits_consume_fasta_and_tag_with_stoptags(PyObject * self, try { hashbits->consume_fasta_and_tag_with_stoptags(filename, - total_reads, n_consumed, - _report_fn, callback_obj); + total_reads, n_consumed); } catch (_khmer_signal &e) { PyErr_SetString(PyExc_IOError, e.get_message().c_str()); return NULL; @@ -2556,9 +2483,8 @@ static PyObject * hashbits_consume_partitioned_fasta(PyObject * self, Hashbits * hashbits = me->hashbits; const char * filename; - PyObject * callback_obj = NULL; - if (!PyArg_ParseTuple(args, "s|O", &filename, &callback_obj)) { + if (!PyArg_ParseTuple(args, "s", &filename)) { return NULL; } @@ -2568,8 +2494,7 @@ static PyObject * hashbits_consume_partitioned_fasta(PyObject * self, unsigned int total_reads; try { - hashbits->consume_partitioned_fasta(filename, total_reads, n_consumed, - _report_fn, callback_obj); + hashbits->consume_partitioned_fasta(filename, total_reads, n_consumed); } catch (_khmer_signal &e) { PyErr_SetString(PyExc_IOError, e.get_message().c_str()); return NULL; @@ -2729,12 +2654,10 @@ static PyObject * hashbits_output_partitions(PyObject * self, PyObject * args) const char * filename = NULL; const char * output = NULL; - PyObject * callback_obj = NULL; PyObject * output_unassigned_o = NULL; - if (!PyArg_ParseTuple(args, "ss|OO", &filename, &output, - &output_unassigned_o, - &callback_obj)) { + if (!PyArg_ParseTuple(args, "ss|O", &filename, &output, + &output_unassigned_o)) { return NULL; } @@ -2749,9 +2672,7 @@ static PyObject * hashbits_output_partitions(PyObject * self, PyObject * args) SubsetPartition * subset_p = hashbits->partition; n_partitions = subset_p->output_partitioned_file(filename, output, - output_unassigned, - _report_fn, - callback_obj); + output_unassigned); } catch (_khmer_signal &e) { PyErr_SetString(PyExc_IOError, e.get_message().c_str()); return NULL; @@ -2771,10 +2692,9 @@ static PyObject * hashbits_find_unpart(PyObject * self, PyObject * args) const char * filename = NULL; PyObject * traverse_o = NULL; PyObject * stop_big_traversals_o = NULL; - PyObject * callback_obj = NULL; - if (!PyArg_ParseTuple(args, "sOO|O", &filename, &traverse_o, - &stop_big_traversals_o, &callback_obj)) { + if (!PyArg_ParseTuple(args, "sOO", &filename, &traverse_o, + &stop_big_traversals_o)) { return NULL; } @@ -2785,8 +2705,7 @@ static PyObject * hashbits_find_unpart(PyObject * self, PyObject * args) try { SubsetPartition * subset_p = hashbits->partition; n_singletons = subset_p->find_unpart(filename, traverse, - stop_big_traversals, - _report_fn, callback_obj); + stop_big_traversals); } catch (_khmer_signal &e) { return NULL; } @@ -2804,14 +2723,13 @@ static PyObject * hashbits_filter_if_present(PyObject * self, PyObject * args) const char * filename = NULL; const char * output = NULL; - PyObject * callback_obj = NULL; - if (!PyArg_ParseTuple(args, "ss|O", &filename, &output, &callback_obj)) { + if (!PyArg_ParseTuple(args, "ss", &filename, &output)) { return NULL; } try { - hashbits->filter_if_present(filename, output, _report_fn, callback_obj); + hashbits->filter_if_present(filename, output); } catch (_khmer_signal &e) { return NULL; } @@ -3801,9 +3719,8 @@ static PyObject * labelhash_consume_fasta_and_tag_with_labels( std::ofstream outfile; const char * filename; - PyObject * callback_obj = NULL; - if (!PyArg_ParseTuple(args, "s|O", &filename, &callback_obj)) { + if (!PyArg_ParseTuple(args, "s", &filename)) { return NULL; } @@ -3813,7 +3730,7 @@ static PyObject * labelhash_consume_fasta_and_tag_with_labels( //Py_BEGIN_ALLOW_THREADS try { hb->consume_fasta_and_tag_with_labels(filename, total_reads, - n_consumed, _report_fn, callback_obj); + n_consumed); } catch (_khmer_signal &e) { exc = e.get_message().c_str(); } catch (khmer_file_exception &e) { @@ -3836,9 +3753,8 @@ static PyObject * labelhash_consume_partitioned_fasta_and_tag_with_labels( LabelHash * labelhash = me->labelhash; const char * filename; - PyObject * callback_obj = NULL; - if (!PyArg_ParseTuple(args, "s|O", &filename, &callback_obj)) { + if (!PyArg_ParseTuple(args, "s", &filename)) { return NULL; } @@ -3849,7 +3765,7 @@ static PyObject * labelhash_consume_partitioned_fasta_and_tag_with_labels( try { labelhash->consume_partitioned_fasta_and_tag_with_labels(filename, - total_reads, n_consumed, _report_fn, callback_obj); + total_reads, n_consumed); } catch (_khmer_signal &e) { PyErr_SetString(PyExc_IOError, "error parsing in consume_partitioned_fasta_and_tag_with_labels"); @@ -4635,21 +4551,6 @@ static PyObject * murmur3_forward_hash_no_rc(PyObject * self, PyObject * args) return PyLong_FromUnsignedLongLong(_hash_murmur_forward(kmer)); } -static PyObject * set_reporting_callback(PyObject * self, PyObject * args) -{ - PyObject * o; - - if (!PyArg_ParseTuple(args, "O", &o)) { - return NULL; - } - - Py_XDECREF(_callback_obj); - Py_INCREF(o); - _callback_obj = o; - - Py_RETURN_NONE; -} - // // technique for resolving literal below found here: // https://gcc.gnu.org/onlinedocs/gcc-4.9.1/cpp/Stringification.html @@ -4721,10 +4622,6 @@ static PyMethodDef KhmerMethods[] = { "Calculate the hash value of a k-mer using MurmurHash3 " "(no reverse complement)", }, - { - "set_reporting_callback", set_reporting_callback, - METH_VARARGS, "", - }, { "get_version_cpp", get_version_cpp, METH_VARARGS, "return the VERSION c++ compiler option" diff --git a/lib/hashbits.cc b/lib/hashbits.cc index ab4694247f..045de3b8e8 100644 --- a/lib/hashbits.cc +++ b/lib/hashbits.cc @@ -163,9 +163,7 @@ unsigned int Hashbits::check_and_process_read_overlap(std::string &read, void Hashbits::consume_fasta_overlap(const std::string &filename, HashIntoType curve[2][100],Hashbits &ht2, unsigned int &total_reads, - unsigned long long &n_consumed, - CallbackFn callback, - void * callback_data) + unsigned long long &n_consumed) { total_reads = 0; n_consumed = 0; @@ -224,15 +222,6 @@ void Hashbits::consume_fasta_overlap(const std::string &filename, curve[0][total_reads/block_size-1] = n_overlap_kmers(); curve[1][total_reads/block_size-1] = n_unique_kmers(); } - // run callback, if specified - if (total_reads % CALLBACK_PERIOD == 0 && callback) { - try { - callback("consume_fasta", callback_data, total_reads, n_consumed); - } catch (...) { - throw; - } - } - } // while delete parser; diff --git a/lib/hashbits.hh b/lib/hashbits.hh index 74a7d14ccb..cd9f42b914 100644 --- a/lib/hashbits.hh +++ b/lib/hashbits.hh @@ -81,11 +81,7 @@ public: HashIntoType curve[2][100], khmer::Hashbits &ht2, unsigned int &total_reads, - unsigned long long &n_consumed, - CallbackFn callback, - void * callback_data); - - + unsigned long long &n_consumed); // just for overlap k-mer counting! unsigned int check_and_process_read_overlap(std::string &read, diff --git a/lib/hashtable.cc b/lib/hashtable.cc index 1a7bc99a6e..5bfa5c51b6 100644 --- a/lib/hashtable.cc +++ b/lib/hashtable.cc @@ -120,8 +120,7 @@ void Hashtable:: consume_fasta( std:: string const &filename, - unsigned int &total_reads, unsigned long long &n_consumed, - CallbackFn callback, void * callback_data + unsigned int &total_reads, unsigned long long &n_consumed ) { IParser * parser = @@ -129,8 +128,7 @@ consume_fasta( consume_fasta( parser, - total_reads, n_consumed, - callback, callback_data + total_reads, n_consumed ); delete parser; @@ -140,13 +138,9 @@ void Hashtable:: consume_fasta( read_parsers:: IParser * parser, - unsigned int &total_reads, unsigned long long &n_consumed, - CallbackFn callback, void * callback_data + unsigned int &total_reads, unsigned long long &n_consumed ) { -#if (0) // Note: Used with callback - currently disabled. - unsigned long long int n_consumed_LOCAL = 0; -#endif Read read; // Iterate through the reads and consume their k-mers. @@ -159,28 +153,8 @@ consume_fasta( unsigned int this_n_consumed = check_and_process_read(read.sequence, is_valid); -#if (0) // Note: Used with callback - currently disabled. - n_consumed_LOCAL = __sync_add_and_fetch( &n_consumed, this_n_consumed ); -#else __sync_add_and_fetch( &n_consumed, this_n_consumed ); -#endif __sync_add_and_fetch( &total_reads, 1 ); - - // TODO: Figure out alternative to callback into Python VM - // Cannot use in multi-threaded operation. -#if (0) - // run callback, if specified - if (callback && (0 == (total_reads_LOCAL % CALLBACK_PERIOD))) { - try { - callback( - "consume_fasta", callback_data, - total_reads_LOCAL, n_consumed_LOCAL - ); - } catch (...) { - throw; - } - } -#endif // 0 } catch (read_parsers::NoMoreReadsAvailable) { } @@ -445,8 +419,7 @@ void Hashtable:: consume_fasta_and_tag( std:: string const &filename, - unsigned int &total_reads, unsigned long long &n_consumed, - CallbackFn callback, void * callback_data + unsigned int &total_reads, unsigned long long &n_consumed ) { IParser * parser = @@ -454,8 +427,7 @@ consume_fasta_and_tag( consume_fasta_and_tag( parser, - total_reads, n_consumed, - callback, callback_data + total_reads, n_consumed ); delete parser; @@ -465,13 +437,9 @@ void Hashtable:: consume_fasta_and_tag( read_parsers:: IParser * parser, - unsigned int &total_reads, unsigned long long &n_consumed, - CallbackFn callback, void * callback_data + unsigned int &total_reads, unsigned long long &n_consumed ) { -#if (0) // Note: Used with callback - currently disabled. - unsigned long long int n_consumed_LOCAL = 0; -#endif Read read; // TODO? Delete the following assignments. @@ -487,30 +455,9 @@ consume_fasta_and_tag( unsigned long long this_n_consumed = 0; consume_sequence_and_tag( read.sequence, this_n_consumed ); -#if (0) // Note: Used with callback - currently disabled. - n_consumed_LOCAL = __sync_add_and_fetch( &n_consumed, this_n_consumed ); -#else __sync_add_and_fetch( &n_consumed, this_n_consumed ); -#endif __sync_add_and_fetch( &total_reads, 1 ); } - - // TODO: Figure out alternative to callback into Python VM - // Cannot use in multi-threaded operation. -#if (0) - // run callback, if specified - if (total_reads_TL % CALLBACK_PERIOD == 0 && callback) { - std::cout << "n tags: " << all_tags.size() << "\n"; - try { - callback("consume_fasta_and_tag", callback_data, total_reads_TL, - n_consumed); - } catch (...) { - delete parser; - throw; - } - } -#endif // 0 - } // while reads left for parser } @@ -523,9 +470,7 @@ consume_fasta_and_tag( void Hashtable::consume_fasta_and_tag_with_stoptags(const std::string &filename, unsigned int &total_reads, - unsigned long long &n_consumed, - CallbackFn callback, - void * callback_data) + unsigned long long &n_consumed) { total_reads = 0; n_consumed = 0; @@ -614,17 +559,6 @@ void Hashtable::consume_fasta_and_tag_with_stoptags(const std::string &filename, // reset the sequence info, increment read number total_reads++; - // run callback, if specified - if (total_reads % CALLBACK_PERIOD == 0 && callback) { - std::cout << "n tags: " << all_tags.size() << "\n"; - try { - callback("consume_fasta_and_tag", callback_data, total_reads, - n_consumed); - } catch (...) { - delete parser; - throw; - } - } } delete parser; } @@ -655,9 +589,7 @@ void Hashtable::divide_tags_into_subsets(unsigned int subset_size, void Hashtable::consume_partitioned_fasta(const std::string &filename, unsigned int &total_reads, - unsigned long long &n_consumed, - CallbackFn callback, - void * callback_data) + unsigned long long &n_consumed) { total_reads = 0; n_consumed = 0; @@ -696,17 +628,6 @@ void Hashtable::consume_partitioned_fasta(const std::string &filename, // reset the sequence info, increment read number total_reads++; - - // run callback, if specified - if (total_reads % CALLBACK_PERIOD == 0 && callback) { - try { - callback("consume_partitioned_fasta", callback_data, total_reads, - n_consumed); - } catch (...) { - delete parser; - throw; - } - } } delete parser; @@ -926,9 +847,7 @@ const } void Hashtable::filter_if_present(const std::string &infilename, - const std::string &outputfile, - CallbackFn callback, - void * callback_data) + const std::string &outputfile) { IParser* parser = IParser::get_parser(infilename); ofstream outfile(outputfile.c_str()); @@ -964,18 +883,6 @@ void Hashtable::filter_if_present(const std::string &infilename, } total_reads++; - - // run callback, if specified - if (total_reads % CALLBACK_PERIOD == 0 && callback) { - try { - callback("filter_if_present", callback_data,total_reads, reads_kept); - } catch (...) { - delete parser; - parser = NULL; - outfile.close(); - throw; - } - } } } diff --git a/lib/hashtable.hh b/lib/hashtable.hh index b6fa88632b..fc08c57732 100644 --- a/lib/hashtable.hh +++ b/lib/hashtable.hh @@ -281,18 +281,14 @@ public: void consume_fasta( std::string const &filename, unsigned int &total_reads, - unsigned long long &n_consumed, - CallbackFn callback = NULL, - void * callback_data = NULL + unsigned long long &n_consumed ); // Count every k-mer from a stream of FASTA or FASTQ reads, // using the supplied parser. void consume_fasta( read_parsers:: IParser * parser, unsigned int &total_reads, - unsigned long long &n_consumed, - CallbackFn callback = NULL, - void * callback_data = NULL + unsigned long long &n_consumed ); void get_median_count(const std::string &s, @@ -359,9 +355,7 @@ public: void consume_fasta_and_tag( std::string const &filename, unsigned int &total_reads, - unsigned long long &n_consumed, - CallbackFn callback = NULL, - void * callback_data = NULL + unsigned long long &n_consumed ); // Count every k-mer from a stream of FASTA or FASTQ reads, @@ -370,9 +364,7 @@ public: void consume_fasta_and_tag( read_parsers:: IParser * parser, unsigned int &total_reads, - unsigned long long &n_consumed, - CallbackFn callback = NULL, - void * callback_data = NULL + unsigned long long &n_consumed ); void consume_sequence_and_tag(const std::string& seq, @@ -382,9 +374,7 @@ public: void consume_fasta_and_tag_with_stoptags(const std::string &filename, unsigned int &total_reads, - unsigned long long &n_consumed, - CallbackFn callback = 0, - void * callback_data = 0); + unsigned long long &n_consumed); void consume_fasta_and_traverse(const std::string &filename, unsigned int distance, unsigned int big_threshold, @@ -393,17 +383,13 @@ public: void consume_partitioned_fasta(const std::string &filename, unsigned int &total_reads, - unsigned long long &n_consumed, - CallbackFn callback = 0, - void * callback_data = 0); + unsigned long long &n_consumed); virtual BoundedCounterType test_and_set_bits(const char * kmer) = 0; virtual BoundedCounterType test_and_set_bits(HashIntoType khash) = 0; void filter_if_present(const std::string &infilename, - const std::string &outputfilename, - CallbackFn callback=0, - void * callback_data=0); + const std::string &outputfilename); unsigned int count_kmers_within_radius(HashIntoType kmer_f, HashIntoType kmer_r, diff --git a/tests/test_c_wrapper.py b/tests/test_c_wrapper.py deleted file mode 100644 index 58c1f96d46..0000000000 --- a/tests/test_c_wrapper.py +++ /dev/null @@ -1,48 +0,0 @@ -# -# This file is part of khmer, http://github.com/ged-lab/khmer/, and is -# Copyright (C) Michigan State University, 2009-2013. It is licensed under -# the three-clause BSD license; see doc/LICENSE.txt. -# Contact: khmer-project@idyll.org -# -import os -import khmer - -import khmer_tst_utils as utils - -reads_filename = utils.get_test_data('test-reads.fa') - -N_READS = 25000 - - -def teardown(): - utils.cleanup() - - -class GoodException(Exception): - pass - - -def callback_raise(info, n_reads, other): - raise GoodException - - -def setup(): - khmer.set_reporting_callback(None) - - -def teardown(): - khmer.reset_reporting_callback() - - -def test_raise_in_consume_fasta(): - return # @CTB - kh = khmer.new_hashtable(4, 4 ** 4) - - try: - n, _ = kh.consume_fasta(reads_filename, 0, 0, callback_raise) - print n - assert 0 - except GoodException: - pass - except: - raise diff --git a/tests/test_read_parsers.py b/tests/test_read_parsers.py index 42c8e72ae9..4e38730dda 100644 --- a/tests/test_read_parsers.py +++ b/tests/test_read_parsers.py @@ -164,9 +164,6 @@ def test_old_illumina_pair_mating(): import threading - # Note: This file, when used in conjunction with a 65600 byte per-thread - # prefetch buffer, tests the paired read mating logic with the - # old Illumina read name format. rparser = ReadParser(utils.get_test_data("test-reads.fa")) def thread_1_runtime(rparser): @@ -177,7 +174,6 @@ def thread_2_runtime(rparser): for readnum, read in enumerate(rparser): if 0 == readnum: pass - # assert "850:2:1:1198:16820/1" == read.name, read.name t1 = threading.Thread(target=thread_1_runtime, args=[rparser]) t2 = threading.Thread(target=thread_2_runtime, args=[rparser])