X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=src%2Ftoolkit%2Fbamtools_stats.cpp;h=42e7cbceb4d3a14a4bdefebd9a0f3fe617e1edda;hb=8c80d760637f8df39262683cd2570f0589423d36;hp=2764499df82b59b3332f0dcd49df6472125be726;hpb=577b6032aa3d85616047c8aba6061dd8dad20cfc;p=bamtools.git diff --git a/src/toolkit/bamtools_stats.cpp b/src/toolkit/bamtools_stats.cpp index 2764499..42e7cbc 100644 --- a/src/toolkit/bamtools_stats.cpp +++ b/src/toolkit/bamtools_stats.cpp @@ -3,11 +3,17 @@ // Marth Lab, Department of Biology, Boston College // All rights reserved. // --------------------------------------------------------------------------- -// Last modified: 12 October 2010 +// Last modified: 21 March 2011 // --------------------------------------------------------------------------- // Prints general alignment statistics for BAM file(s). // *************************************************************************** +#include "bamtools_stats.h" + +#include +#include +using namespace BamTools; + #include #include #include @@ -15,11 +21,7 @@ #include #include #include -#include "bamtools_stats.h" -#include "bamtools_options.h" -#include "BamMultiReader.h" using namespace std; -using namespace BamTools; // --------------------------------------------- // StatsSettings implementation @@ -98,10 +100,11 @@ StatsTool::StatsToolPrivate::StatsToolPrivate(StatsTool::StatsSettings* _setting StatsTool::StatsToolPrivate::~StatsToolPrivate(void) { } -// median is of type double because in the case of even number of data elements, we need to return the average of middle 2 elements +// median is of type double because in the case of even number of data elements, +// we need to return the average of middle 2 elements bool StatsTool::StatsToolPrivate::CalculateMedian(vector& data, double& median) { - // check that data exists + // skip if data empty if ( data.empty() ) return false; // find middle element @@ -214,24 +217,22 @@ void StatsTool::StatsToolPrivate::ProcessAlignment(const BamAlignment& al) { bool StatsTool::StatsToolPrivate::Run() { - // opens the BAM files without checking for indexes + // open the BAM files BamMultiReader reader; - if ( !reader.Open(settings->InputFiles, false, true) ) { - cerr << "Could not open input BAM file(s)... quitting." << endl; + if ( !reader.Open(settings->InputFiles) ) { + cerr << "bamtools stats ERROR: could not open input BAM file(s)... Aborting." << endl; reader.Close(); return false; } - // plow through file, keeping track of stats + // plow through alignments, keeping track of stats BamAlignment al; while ( reader.GetNextAlignmentCore(al) ) ProcessAlignment(al); + reader.Close(); - // print stats + // print stats & exit PrintStats(); - - // clean and exit - reader.Close(); return true; } @@ -271,7 +272,7 @@ int StatsTool::Run(int argc, char* argv[]) { // parse command line arguments Options::Parse(argc, argv, 1); - + // set to default input if none provided if ( !m_settings->HasInput ) m_settings->InputFiles.push_back(Options::StandardIn());