X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=src%2Ftoolkit%2Fbamtools_index.cpp;h=6e5a86df6b65329e47283a754835d4de55544a30;hb=8c80d760637f8df39262683cd2570f0589423d36;hp=b1e4bc3e00eaf6fd359b35fc081d6147b4ecb0ae;hpb=90bb3691f9aa2a2e8a4dd906c2439c7bc434eb78;p=bamtools.git diff --git a/src/toolkit/bamtools_index.cpp b/src/toolkit/bamtools_index.cpp index b1e4bc3..6e5a86d 100644 --- a/src/toolkit/bamtools_index.cpp +++ b/src/toolkit/bamtools_index.cpp @@ -3,21 +3,21 @@ // Marth Lab, Department of Biology, Boston College // All rights reserved. // --------------------------------------------------------------------------- -// Last modified: 2 September 2010 +// Last modified: 21 March 2011 // --------------------------------------------------------------------------- -// Creates a BAM index (".bai") file for the provided BAM file. +// Creates a BAM index file. // *************************************************************************** -#include -#include - #include "bamtools_index.h" -#include "bamtools_options.h" -#include "BamReader.h" -using namespace std; +#include +#include using namespace BamTools; +#include +#include +using namespace std; + // --------------------------------------------- // IndexSettings implementation @@ -51,7 +51,7 @@ IndexTool::IndexTool(void) // set up options OptionGroup* IO_Opts = Options::CreateOptionGroup("Input & Output"); Options::AddValueOption("-in", "BAM filename", "the input BAM file", "", m_settings->HasInputBamFilename, m_settings->InputBamFilename, IO_Opts, Options::StandardIn()); - Options::AddOption("-bti", "create (non-standard) BamTools index file", m_settings->IsUsingBamtoolsIndex, IO_Opts); + Options::AddOption("-bti", "create (non-standard) BamTools index file (*.bti). Default behavior is to create standard BAM index (*.bai)", m_settings->IsUsingBamtoolsIndex, IO_Opts); } IndexTool::~IndexTool(void) { @@ -71,11 +71,15 @@ int IndexTool::Run(int argc, char* argv[]) { // open our BAM reader BamReader reader; - reader.Open(m_settings->InputBamFilename); + if ( !reader.Open(m_settings->InputBamFilename) ) { + cerr << "bamtools index ERROR: could not open BAM file: " << m_settings->InputBamFilename << endl; + return 1; + } // create index for BAM file - bool useDefaultIndex = !m_settings->IsUsingBamtoolsIndex; - reader.CreateIndex(useDefaultIndex); + const BamIndex::IndexType type = ( m_settings->IsUsingBamtoolsIndex ? BamIndex::BAMTOOLS + : BamIndex::STANDARD ); + reader.CreateIndex(type); // clean & exit reader.Close();