From 20e692c4a06c181ff7216c00d5808966210e47c9 Mon Sep 17 00:00:00 2001 From: Derek Date: Thu, 3 Jun 2010 12:30:15 -0400 Subject: [PATCH] Minor formatting/commenting fixes. No major changes to actual code paths --- bamtools.cpp | 50 ++++++++++++++++++++++---------------------- bamtools_count.cpp | 8 +++---- bamtools_header.cpp | 3 ++- bamtools_merge.cpp | 4 ++-- bamtools_options.cpp | 35 ++++++++++++++++++++++++------- bamtools_stats.cpp | 2 +- bamtools_tool.h | 12 +++-------- bamtools_variant.h | 4 ++-- 8 files changed, 66 insertions(+), 52 deletions(-) diff --git a/bamtools.cpp b/bamtools.cpp index 12731f2..b5ba6e0 100644 --- a/bamtools.cpp +++ b/bamtools.cpp @@ -3,7 +3,7 @@ // Marth Lab, Department of Biology, Boston College // All rights reserved. // --------------------------------------------------------------------------- -// Last modified: 1 June 2010 +// Last modified: 2 June 2010 // --------------------------------------------------------------------------- // Integrates a number of BamTools functionalities into a single executable. // *************************************************************************** @@ -50,8 +50,9 @@ static const string SHORT_VERSION = "-v"; int Help(int argc, char* argv[]) { // 'bamtools help COMMAND' - AbstractTool* tool(0); if (argc > 2) { + + AbstractTool* tool(0); if ( argv[2] == COUNT ) tool = new CountTool; if ( argv[2] == COVERAGE ) tool = new CoverageTool; if ( argv[2] == HEADER ) tool = new HeaderTool; @@ -60,36 +61,35 @@ int Help(int argc, char* argv[]) { if ( argv[2] == SAM ) tool = new SamTool; if ( argv[2] == SORT ) tool = new SortTool; if ( argv[2] == STATS ) tool = new StatsTool; + + // if tool known, print its help screen + if ( tool ) return tool->Help(); } - - if ( tool ) return tool->Help(); - else { - - // either 'bamtools help' or unrecognized argument after 'help' - cerr << endl; - cerr << "usage: bamtools [--help] COMMAND [ARGS]" << endl; - cerr << endl; - cerr << "Available bamtools commands:" << endl; - cerr << "\tcount Prints number of alignments in BAM file" << endl; - cerr << "\tcoverage Prints coverage statistics from the input BAM file" << endl; - cerr << "\theader Prints BAM header information" << endl; - cerr << "\tindex Generates index for BAM file" << endl; - cerr << "\tmerge Merge multiple BAM files into single file" << endl; - cerr << "\tsam Prints the BAM file in SAM (text) format" << endl; - cerr << "\tsort Sorts the BAM file according to some criteria" << endl; - cerr << "\tstats Prints some basic statistics from the input BAM file" << endl; - cerr << endl; - cerr << "See 'bamtools help COMMAND' for more information on a specific command." << endl; - cerr << endl; - return 0; - } + + // either 'bamtools help' or unrecognized argument after 'help' + cerr << endl; + cerr << "usage: bamtools [--help] COMMAND [ARGS]" << endl; + cerr << endl; + cerr << "Available bamtools commands:" << endl; + cerr << "\tcount Prints number of alignments in BAM file" << endl; + cerr << "\tcoverage Prints coverage statistics from the input BAM file" << endl; + cerr << "\theader Prints BAM header information" << endl; + cerr << "\tindex Generates index for BAM file" << endl; + cerr << "\tmerge Merge multiple BAM files into single file" << endl; + cerr << "\tsam Prints the BAM file in SAM (text) format" << endl; + cerr << "\tsort Sorts the BAM file according to some criteria" << endl; + cerr << "\tstats Prints some basic statistics from the input BAM file" << endl; + cerr << endl; + cerr << "See 'bamtools help COMMAND' for more information on a specific command." << endl; + cerr << endl; + return 0; } // ------------------------------------------ // Print version info int Version(void) { cout << endl; - cout << "bamtools v0.x.xx" << endl; + cout << "bamtools v0.8.xx" << endl; cout << "Part of BamTools API and toolkit" << endl; cout << "Primary authors: Derek Barnett, Erik Garrison, Michael Stromberg" << endl; cout << "(c) 2009-2010 Marth Lab, Biology Dept., Boston College" << endl; diff --git a/bamtools_count.cpp b/bamtools_count.cpp index dad30e6..c84c6ab 100644 --- a/bamtools_count.cpp +++ b/bamtools_count.cpp @@ -56,15 +56,15 @@ CountTool::CountTool(void) , m_settings(new CountSettings) { // set program details - Options::SetProgramInfo("bamtools count", "prints alignment counts for a BAM file", "-in [-region REGION -index ]"); + Options::SetProgramInfo("bamtools count", "prints alignment counts for a BAM file", "-in [-region [-index ]]"); // 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::AddValueOption("-index", "BAM index filename", "the BAM index file", "", m_settings->HasBamIndexFilename, m_settings->BamIndexFilename, IO_Opts); + Options::AddValueOption("-in", "BAM filename", "the input BAM file", "", m_settings->HasInputBamFilename, m_settings->InputBamFilename, IO_Opts, Options::StandardIn()); + Options::AddValueOption("-index", "BAM index filename", "the BAM index file", "", m_settings->HasBamIndexFilename, m_settings->BamIndexFilename, IO_Opts); OptionGroup* FilterOpts = Options::CreateOptionGroup("Filters"); - Options::AddValueOption("-region", "REGION", "genomic region. Index file is recommended for optimal performance.", "", m_settings->HasRegion, m_settings->Region, FilterOpts); + Options::AddValueOption("-region", "REGION", "genomic region. Index file is recommended for better performance. See \'bamtools help index\' for more details on creating one", "", m_settings->HasRegion, m_settings->Region, FilterOpts); } CountTool::~CountTool(void) { diff --git a/bamtools_header.cpp b/bamtools_header.cpp index 2e8c31e..8fbb70e 100644 --- a/bamtools_header.cpp +++ b/bamtools_header.cpp @@ -69,7 +69,8 @@ int HeaderTool::Run(int argc, char* argv[]) { Options::Parse(argc, argv, 1); // set to default input if none provided - if ( !m_settings->HasInputBamFilename ) m_settings->InputFiles.push_back(Options::StandardIn()); + if ( !m_settings->HasInputBamFilename ) + m_settings->InputFiles.push_back(Options::StandardIn()); // open files BamMultiReader reader; diff --git a/bamtools_merge.cpp b/bamtools_merge.cpp index 402d377..cae6134 100644 --- a/bamtools_merge.cpp +++ b/bamtools_merge.cpp @@ -62,8 +62,8 @@ MergeTool::MergeTool(void) // set up options OptionGroup* IO_Opts = Options::CreateOptionGroup("Input & Output"); - Options::AddValueOption("-in", "BAM filename", "the input BAM file(s)", "", m_settings->HasInputBamFilename, m_settings->InputFiles, IO_Opts); - Options::AddValueOption("-out", "BAM filename", "the output BAM file", "", m_settings->HasOutputBamFilename, m_settings->OutputFilename, IO_Opts); + Options::AddValueOption("-in", "BAM filename", "the input BAM file(s)", "", m_settings->HasInputBamFilename, m_settings->InputFiles, IO_Opts); + Options::AddValueOption("-out", "BAM filename", "the output BAM file", "", m_settings->HasOutputBamFilename, m_settings->OutputFilename, IO_Opts); // OptionGroup* FilterOpts = Options::CreateOptionGroup("Filters"); // Options::AddValueOption("-region", "REGION", "genomic region. See README for more details", "", m_settings->HasRegion, m_settings->Region, FilterOpts); diff --git a/bamtools_options.cpp b/bamtools_options.cpp index 89f545a..931fbd8 100644 --- a/bamtools_options.cpp +++ b/bamtools_options.cpp @@ -1,3 +1,23 @@ +// *************************************************************************** +// bamtools_options.cpp (c) 2010 Derek Barnett, Erik Garrison +// Marth Lab, Department of Biology, Boston College +// All rights reserved. +// --------------------------------------------------------------------------- +// Last modified: 2 June 2010 +// --------------------------------------------------------------------------- +// Parses command line arguments and creates a help menu +// --------------------------------------------------------------------------- +// Modified from: +// The Mosaik suite's command line parser class: COptions +// (c) 2006 - 2009 Michael Str�mberg +// Marth Lab, Department of Biology, Boston College +// Dual licenced under the GNU General Public License 2.0+ license or as +// a commercial license with the Marth Lab. +// +// * Modified slightly to fit BamTools, otherwise code is same. +// * (BamTools namespace, added stdin/stdout) (DB) +// *************************************************************************** + #include "bamtools_options.h" #include #include @@ -52,14 +72,12 @@ void Options::DisplayHelp(void) { // display the menu printf("Description: %s.\n\n", m_description.c_str()); - printf("Usage: "); printf("%s", m_programName.c_str()); printf(" %s\n\n", m_exampleArguments.c_str()); - vector