Skip to content

Commit

Permalink
Run astyle on all cc/hh files in lib
Browse files Browse the repository at this point in the history
Moved suppressions to inline comments, update Makefile accordingly and remove unused suppressions.txt

Fix assign_partition_id to use .empty() instead of .size()

Move cppcheck suppressions to same line as variables

Fix suppressions comment format, properly wrap nbfilled in ifdef
  • Loading branch information
Benjamin Taylor committed Sep 19, 2014
1 parent 8890e22 commit 5dcc6a7
Show file tree
Hide file tree
Showing 18 changed files with 194 additions and 112 deletions.
11 changes: 11 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
2014-09-19 Ben Taylor <taylo886@msu.edu>

* Makefile: add --inline-suppr to cppcheck, cppcheck-result.xml targets
* khmer/_khmermodule.cc: Add comments to address cppcheck false positives
* lib/hashtable.cc, lib/hashtable.hh: take args to filter_if_present by
reference, address scope in destructor
* lib/read_parsers.cc: Add comments to address cppcheck false positives
* lib/subset.cc, lib/subset.hh: Adjust output_partitioned_file,
find_unpart to take args by reference, fix assign_partition_id to use
.empty() instead of .size()

2014-09-10 Titus Brown <titus@idyll.org>

* sandbox/calc-median-distribution.py: catch exceptions generated by reads
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@ cppcheck-result.xml: $(CPPSOURCES)
ls lib/*.cc khmer/_khmermodule.cc | grep -v test | cppcheck -DNDEBUG \
-DVERSION=0.0.cppcheck -UNO_UNIQUE_RC --enable=all \
--file-list=- -j8 --platform=unix64 --std=posix --xml \
--xml-version=2 2> cppcheck-result.xml
--inline-suppr --xml-version=2 2> cppcheck-result.xml

cppcheck: $(CPPSOURCES)
ls lib/*.cc khmer/_khmermodule.cc | grep -v test | cppcheck -DNDEBUG \
-DVERSION=0.0.cppcheck -UNO_UNIQUE_RC --enable=all \
--file-list=- -j8 --platform=unix64 --std=posix --quiet
--file-list=- -j8 --platform=unix64 --std=posix --inline-suppr --quiet

pep8: $(PYSOURCES) $(wildcard tests/*.py)
pep8 --exclude=_version.py setup.py khmer/ scripts/ tests/ || true
Expand Down
11 changes: 6 additions & 5 deletions khmer/_khmermodule.cc
Original file line number Diff line number Diff line change
Expand Up @@ -745,9 +745,9 @@ _ReadPairIterator_iternext( PyObject * self )
uint8_t pair_mode = myself->pair_mode;

ReadPair the_read_pair;

bool stop_iteration = false;
bool invalid_file_format = false;
// cppcheck-suppress unreadVariable
bool stop_iteration = false;
bool invalid_file_format = false;
char exc_message[ CHAR_MAX ];
bool unknown_pair_reading_mode = false;
bool invalid_read_pair = false;
Expand Down Expand Up @@ -1991,8 +1991,9 @@ static PyObject * hash_abundance_distribution_with_reads_parser(

read_parsers:: IParser * rparser = rparser_obj->parser;
Hashbits * hashbits = tracking_obj->hashbits;

HashIntoType * dist = NULL;

// cppcheck-suppress unreadVariable
HashIntoType * dist = NULL;

Py_BEGIN_ALLOW_THREADS
dist = counting->abundance_distribution(rparser, hashbits);
Expand Down
48 changes: 32 additions & 16 deletions lib/counting.hh
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ protected:

Byte ** _counts;

virtual void _allocate_counters() {
virtual void _allocate_counters()
{
_n_tables = _tablesizes.size();

_counts = new Byte*[_n_tables];
Expand All @@ -58,7 +59,8 @@ public:
get_active_config( ).get_number_of_threads( )
) :
khmer::Hashtable(ksize, number_of_threads),
_use_bigcount(false), _bigcount_spin_lock(false) {
_use_bigcount(false), _bigcount_spin_lock(false)
{
_tablesizes.push_back(single_tablesize);

_allocate_counters();
Expand All @@ -71,12 +73,14 @@ public:
) :
khmer::Hashtable(ksize, number_of_threads),
_use_bigcount(false), _bigcount_spin_lock(false),
_tablesizes(tablesizes) {
_tablesizes(tablesizes)
{

_allocate_counters();
}

virtual ~CountingHash() {
virtual ~CountingHash()
{
if (_counts) {
for (size_t i = 0; i < _n_tables; i++) {
if (_counts[i]) {
Expand All @@ -92,40 +96,47 @@ public:
}
}

virtual BoundedCounterType test_and_set_bits(const char * kmer) {
virtual BoundedCounterType test_and_set_bits(const char * kmer)
{
BoundedCounterType x = get_count(kmer); // @CTB just hash it, yo.
count(kmer);
return !x;
}

virtual BoundedCounterType test_and_set_bits(HashIntoType khash) {
virtual BoundedCounterType test_and_set_bits(HashIntoType khash)
{
BoundedCounterType x = get_count(khash);
count(khash);
return !x;
}

std::vector<HashIntoType> get_tablesizes() const {
std::vector<HashIntoType> get_tablesizes() const
{
return _tablesizes;
}

void set_use_bigcount(bool b) {
void set_use_bigcount(bool b)
{
_use_bigcount = b;
}
bool get_use_bigcount() {
bool get_use_bigcount()
{
return _use_bigcount;
}

virtual void save(std::string);
virtual void load(std::string);

// accessors to get table info
const HashIntoType n_entries() const {
const HashIntoType n_entries() const
{
return _tablesizes[0];
}

// count number of occupied bins
virtual const HashIntoType n_occupied(HashIntoType start=0,
HashIntoType stop=0) const {
HashIntoType stop=0) const
{
HashIntoType n = 0;
if (stop == 0) {
stop = _tablesizes[0];
Expand All @@ -138,12 +149,14 @@ public:
return n;
}

virtual void count(const char * kmer) {
virtual void count(const char * kmer)
{
HashIntoType hash = _hash(kmer, _ksize);
count(hash);
}

virtual void count(HashIntoType khash) {
virtual void count(HashIntoType khash)
{

unsigned int n_full = 0;

Expand Down Expand Up @@ -177,13 +190,15 @@ public:
} // count

// get the count for the given k-mer.
virtual const BoundedCounterType get_count(const char * kmer) const {
virtual const BoundedCounterType get_count(const char * kmer) const
{
HashIntoType hash = _hash(kmer, _ksize);
return get_count(hash);
}

// get the count for the given k-mer hash.
virtual const BoundedCounterType get_count(HashIntoType khash) const {
virtual const BoundedCounterType get_count(HashIntoType khash) const
{
unsigned int max_count = _max_count;
BoundedCounterType min_count = max_count;
for (unsigned int i = 0; i < _n_tables; i++) {
Expand Down Expand Up @@ -269,7 +284,8 @@ public:
class CountingHashGzFileWriter : public CountingHashFile
{
public:
CountingHashGzFileWriter(const std::string &outfilename, const CountingHash &ht);
CountingHashGzFileWriter(const std::string &outfilename,
const CountingHash &ht);
};
};

Expand Down
51 changes: 34 additions & 17 deletions lib/hashbits.hh
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ protected:
HashIntoType _n_overlap_kmers;
Byte ** _counts;

virtual void _allocate_counters() {
virtual void _allocate_counters()
{
_n_tables = _tablesizes.size();

_counts = new Byte*[_n_tables];
Expand All @@ -43,15 +44,17 @@ protected:
public:
Hashbits(WordLength ksize, std::vector<HashIntoType>& tablesizes)
: khmer::Hashtable(ksize),
_tablesizes(tablesizes) {
_tablesizes(tablesizes)
{
_occupied_bins = 0;
_n_unique_kmers = 0;
_n_overlap_kmers = 0;

_allocate_counters();
}

~Hashbits() {
~Hashbits()
{
if (_counts) {
for (size_t i = 0; i < _n_tables; i++) {
delete[] _counts[i];
Expand All @@ -65,15 +68,17 @@ public:

}

std::vector<HashIntoType> get_tablesizes() const {
std::vector<HashIntoType> get_tablesizes() const
{
return _tablesizes;
}

virtual void save(std::string);
virtual void load(std::string);

// for overlap k-mer counting
void consume_fasta_overlap(const std::string &filename,HashIntoType curve[2][100],
void consume_fasta_overlap(const std::string &filename,
HashIntoType curve[2][100],
khmer::Hashbits &ht2,
unsigned int &total_reads,
unsigned long long &n_consumed,
Expand All @@ -92,21 +97,24 @@ public:

// count number of occupied bins
virtual const HashIntoType n_occupied(HashIntoType start=0,
HashIntoType stop=0) const {
HashIntoType stop=0) const
{
// @@ CTB need to be able to *save* this...
return _occupied_bins/_n_tables;
}

virtual const HashIntoType n_kmers(HashIntoType start=0,
HashIntoType stop=0) const {
HashIntoType stop=0) const
{
return _n_unique_kmers; // @@ CTB need to be able to *save* this...
}

// Get and set the hashbits for the given kmer.
inline
virtual
BoundedCounterType
test_and_set_bits(const char * kmer) {
test_and_set_bits(const char * kmer)
{
HashIntoType hash = _hash(kmer, _ksize);
return test_and_set_bits(hash);
}
Expand All @@ -119,7 +127,8 @@ public:
inline
virtual
BoundedCounterType
test_and_set_bits( HashIntoType khash ) {
test_and_set_bits( HashIntoType khash )
{
bool is_new_kmer = false;

for (size_t i = 0; i < _n_tables; i++) {
Expand All @@ -143,16 +152,19 @@ public:
} // test_and_set_bits

virtual const HashIntoType n_overlap_kmers(HashIntoType start=0,
HashIntoType stop=0) const {
HashIntoType stop=0) const
{
return _n_overlap_kmers; // @@ CTB need to be able to *save* this...
}

virtual void count(const char * kmer) {
virtual void count(const char * kmer)
{
HashIntoType hash = _hash(kmer, _ksize);
count(hash);
}

virtual void count(HashIntoType khash) {
virtual void count(HashIntoType khash)
{
bool is_new_kmer = false;

for (size_t i = 0; i < _n_tables; i++) {
Expand All @@ -170,7 +182,8 @@ public:
}
}

virtual bool check_overlap(HashIntoType khash, Hashbits &ht2) {
virtual bool check_overlap(HashIntoType khash, Hashbits &ht2)
{

for (size_t i = 0; i < ht2._n_tables; i++) {
HashIntoType bin = khash % ht2._tablesizes[i];
Expand All @@ -183,12 +196,14 @@ public:
return true;
}

virtual void count_overlap(const char * kmer, Hashbits &ht2) {
virtual void count_overlap(const char * kmer, Hashbits &ht2)
{
HashIntoType hash = _hash(kmer, _ksize);
count_overlap(hash,ht2);
}

virtual void count_overlap(HashIntoType khash, Hashbits &ht2) {
virtual void count_overlap(HashIntoType khash, Hashbits &ht2)
{
bool is_new_kmer = false;

for (size_t i = 0; i < _n_tables; i++) {
Expand All @@ -210,13 +225,15 @@ public:
}

// get the count for the given k-mer.
virtual const BoundedCounterType get_count(const char * kmer) const {
virtual const BoundedCounterType get_count(const char * kmer) const
{
HashIntoType hash = _hash(kmer, _ksize);
return get_count(hash);
}

// get the count for the given k-mer hash.
virtual const BoundedCounterType get_count(HashIntoType khash) const {
virtual const BoundedCounterType get_count(HashIntoType khash) const
{
for (size_t i = 0; i < _n_tables; i++) {
HashIntoType bin = khash % _tablesizes[i];
HashIntoType byte = bin / 8;
Expand Down
3 changes: 2 additions & 1 deletion lib/khmer.hh
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ typedef std::queue<HashIntoType> NodeQueue;
typedef std::map<PartitionID, PartitionID*> PartitionToPartitionPMap;
typedef std::map<HashIntoType, unsigned int> TagCountMap;
typedef std::map<PartitionID, unsigned int> PartitionCountMap;
typedef std::map<unsigned long long, unsigned long long> PartitionCountDistribution;
typedef std::map<unsigned long long, unsigned long long>
PartitionCountDistribution;

// types used in @camillescott's sparse labeling extension
typedef unsigned long long int Label;
Expand Down
7 changes: 5 additions & 2 deletions lib/khmer_exception.hh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
namespace khmer
{

///
///
// A base class for all exceptions.
//
// All exceptions should be derived from this base class.
Expand All @@ -27,7 +27,10 @@ public:
: _msg(msg.c_str()) { }

virtual ~khmer_exception() throw() { }
virtual const char* what() const throw () { return _msg; }
virtual const char* what() const throw ()
{
return _msg;
}

protected:
const char * _msg;
Expand Down
11 changes: 6 additions & 5 deletions lib/labelhash.cc
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,12 @@ LabelHash::consume_fasta_and_tag_with_labels(

}

void LabelHash::consume_partitioned_fasta_and_tag_with_labels(const std::string &filename,
unsigned int &total_reads,
unsigned long long &n_consumed,
CallbackFn callback,
void * callback_data)
void LabelHash::consume_partitioned_fasta_and_tag_with_labels(
const std::string &filename,
unsigned int &total_reads,
unsigned long long &n_consumed,
CallbackFn callback,
void * callback_data)
{
total_reads = 0;
n_consumed = 0;
Expand Down
Loading

0 comments on commit 5dcc6a7

Please sign in to comment.