X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=src%2Ftoolkit%2Fbamtools_count.cpp;h=40e7c5d6d3373afb65591ba6cec751a9f2762619;hb=8c80d760637f8df39262683cd2570f0589423d36;hp=0a0620a563ea4466458e0719d2510b415b8b5c58;hpb=577b6032aa3d85616047c8aba6061dd8dad20cfc;p=bamtools.git diff --git a/src/toolkit/bamtools_count.cpp b/src/toolkit/bamtools_count.cpp index 0a0620a..40e7c5d 100644 --- a/src/toolkit/bamtools_count.cpp +++ b/src/toolkit/bamtools_count.cpp @@ -3,24 +3,23 @@ // Marth Lab, Department of Biology, Boston College // All rights reserved. // --------------------------------------------------------------------------- -// Last modified: 3 September 2010 +// Last modified: 23 March 2011 // --------------------------------------------------------------------------- // Prints alignment count for BAM file(s) // *************************************************************************** +#include "bamtools_count.h" + +#include +#include +#include +using namespace BamTools; + #include #include #include - -#include "bamtools_count.h" -#include "bamtools_options.h" -#include "bamtools_utilities.h" -#include "BamReader.h" -#include "BamMultiReader.h" - using namespace std; -using namespace BamTools; - + // --------------------------------------------- // CountSettings implementation @@ -78,8 +77,8 @@ int CountTool::Run(int argc, char* argv[]) { // open reader without index BamMultiReader reader; - if (!reader.Open(m_settings->InputFiles, false, true)) { - cerr << "ERROR: Could not open input BAM file(s)... Aborting." << endl; + if ( !reader.Open(m_settings->InputFiles) ) { + cerr << "bamtools count ERROR: could not open input BAM file(s)... Aborting." << endl; return 1; } @@ -100,22 +99,15 @@ int CountTool::Run(int argc, char* argv[]) { BamRegion region; if ( Utilities::ParseRegionString(m_settings->Region, reader, region) ) { - // attempt to re-open reader with index files - reader.Close(); - bool openedOK = reader.Open(m_settings->InputFiles, true, true ); - - // if error - if ( !openedOK ) { - cerr << "ERROR: Could not open input BAM file(s)... Aborting." << endl; - return 1; - } - - // if index data available, we can use SetRegion + // attempt to find index files + reader.LocateIndexes(); + + // if index data available for all BAM files, we can use SetRegion if ( reader.IsIndexLoaded() ) { - // attempt to use SetRegion(), if failed report error + // attempt to set region on reader if ( !reader.SetRegion(region.LeftRefID, region.LeftPosition, region.RightRefID, region.RightPosition) ) { - cerr << "ERROR: Region requested, but could not set BamReader region to REGION: " << m_settings->Region << " Aborting." << endl; + cerr << "bamtools count ERROR: set region failed. Check that REGION describes a valid range" << endl; reader.Close(); return 1; } @@ -128,7 +120,7 @@ int CountTool::Run(int argc, char* argv[]) { // no index data available, we have to iterate through until we // find overlapping alignments else { - while( reader.GetNextAlignmentCore(al) ) { + while ( reader.GetNextAlignmentCore(al) ) { if ( (al.RefID >= region.LeftRefID) && ( (al.Position + al.Length) >= region.LeftPosition ) && (al.RefID <= region.RightRefID) && ( al.Position <= region.RightPosition) ) { @@ -140,8 +132,9 @@ int CountTool::Run(int argc, char* argv[]) { // error parsing REGION string else { - cerr << "ERROR: Could not parse REGION - " << m_settings->Region << endl; - cerr << "Be sure REGION is in valid format (see README) and that coordinates are valid for selected references" << endl; + cerr << "bamtools count ERROR: could not parse REGION - " << m_settings->Region << endl; + cerr << "Check that REGION is in valid format (see documentation) and that the coordinates are valid" + << endl; reader.Close(); return 1; } @@ -150,7 +143,7 @@ int CountTool::Run(int argc, char* argv[]) { // print results cout << alignmentCount << endl; - // clean & exit + // clean up & exit reader.Close(); return 0; }