// 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.
// ***************************************************************************
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;
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;
, m_settings(new CountSettings)
{
// set program details
- Options::SetProgramInfo("bamtools count", "prints alignment counts for a BAM file", "-in <filename> [-region REGION -index <filename>]");
+ Options::SetProgramInfo("bamtools count", "prints alignment counts for a BAM file", "-in <filename> [-region <REGION> [-index <filename>]]");
// 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) {
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;
// 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);
+// ***************************************************************************
+// 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 <cstdio>
#include <cstdlib>
// 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<Option>::const_iterator optionIter;
+ vector<Option>::const_iterator optionIter;
vector<OptionGroup>::const_iterator groupIter;
-
for (groupIter = m_optionGroups.begin(); groupIter != m_optionGroups.end(); ++groupIter) {
printf("%s:\n", groupIter->Name.c_str());
description = sb.str();
}
- if (description.size() <= DESC_LENGTH_FIRST_ROW) {
+ if ( description.size() <= DESC_LENGTH_FIRST_ROW ) {
printf("%s\n", description.c_str());
} else {
// handle the first row
const char* pDescription = description.data();
unsigned int cutIndex = DESC_LENGTH_FIRST_ROW;
- while(pDescription[cutIndex] != ' ') cutIndex--;
+ while(pDescription[cutIndex] != ' ')
+ cutIndex--;
printf("%s\n", description.substr(0, cutIndex).c_str());
description = description.substr(cutIndex + 1);
while(description.size() > DESC_LENGTH) {
pDescription = description.data();
cutIndex = DESC_LENGTH;
- while(pDescription[cutIndex] != ' ') cutIndex--;
+ while(pDescription[cutIndex] != ' ')
+ cutIndex--;
printf("%s%s\n", indentBuffer, description.substr(0, cutIndex).c_str());
description = description.substr(cutIndex + 1);
}
if (ovMapIter == m_optionsMap.end()) {
errorBuilder << ERROR_SPACER << "An unrecognized argument was found: " << argument << std::endl;
foundError = true;
-
} else {
*ovMapIter->second.pFoundArgument = true;
}
// return string representations of stdin
-const string& Options::StandardIn(void) { return m_stdin; }
+const string& Options::StandardIn(void) { return m_stdin; }
// return string representations of stdout
const string& Options::StandardOut(void) { return m_stdout; }
// 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("-in", "BAM filename", "the input BAM file", "", m_settings->HasInputBamFilename, m_settings->InputBamFilename, IO_Opts, Options::StandardIn());
}
StatsTool::~StatsTool(void) {
// Marth Lab, Department of Biology, Boston College
// All rights reserved.
// ---------------------------------------------------------------------------
-// Last modified: 1 June 2010
+// Last modified: 2 June 2010
// ---------------------------------------------------------------------------
// Base class for all other BamTools sub-tools
-//
-// ** Expand to multiple??
-//
+// All derived classes must provide Help() and Run() methods
// ***************************************************************************
#ifndef BAMTOOLS_ABSTRACTTOOL_H
class AbstractTool {
public:
- AbstractTool(void) : STDIN("stdin"), STDOUT("stdout") { }
+ AbstractTool(void) { }
virtual ~AbstractTool(void) { }
public:
virtual int Help(void) =0;
virtual int Run(int argc, char* argv[]) =0;
-
- public:
- const std::string STDIN;
- const std::string STDOUT;
};
} // namespace BamTools
// Marth Lab, Department of Biology, Boston College
// All rights reserved.
// ---------------------------------------------------------------------------
-// Last modified: 1 June 2010
+// Last modified: 2 June 2010
// ---------------------------------------------------------------------------
// Provides a template-based variant type
// ---------------------------------------------------------------------------
// (c) 2000 Fernando Cacciola
// Dr. Dobb's (http://www.ddj.com/cpp/184401293)
//
-// * Modified to fit BamTools code-style, otherwise code is same. (DB)
+// * Modified to be in BamTools namespace, otherwise code is same. (DB)
// ***************************************************************************
#ifndef BAMTOOLS_VARIANT_H