Skip to content

Instantly share code, notes, and snippets.

@klmr
Last active February 15, 2018 08:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save klmr/8f4c5c641790619c3baaad05614ca715 to your computer and use it in GitHub Desktop.
Save klmr/8f4c5c641790619c3baaad05614ca715 to your computer and use it in GitHub Desktop.
  • Invalid signature void main() (… I mean, seriously?!)
  • Missing namespace qualifiers throughout
  • Missing include for accumulate
  • Missing ) in accumulate call
  • Invalid arguments to accumulate call:
    • init missing
    • op has wrong function type (expected (T, T) -> T; got (T) -> void)
    • — in fact, it seems they actually meant std::for_each.
  • … but using std::accumulate correctly would have been way easier, without a gratuitous lambda.
  • Expensive copy of base_quals() (this should absolutely be captured by const-ref)
  • Inconsistent indentation
  • Misleading variable naming: abq is a sum, not an average, of base qualities.
  • Unused, gratuitous constant declaration
  • Expensive endl instead of '\n'

Here’s a cleaned up version:

#include "gamgee/gamgee.h"
#include <iostream>
#include <numeric>

int main() {
    for (auto const& record : gamgee::SingleSamReader("input.bam")) {
        auto const& bqs = record.base_quals();
        auto const sum_qual = std::accumulate(bqs.begin(), bqs.end(), 0.0);
        std::cout << sum_qual / bqs.size() << "\n";
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment