]> git.donarmstrong.com Git - bamtools.git/commitdiff
Minor formatting/commenting fixes. No major changes to actual code paths
authorDerek <derekwbarnett@gmail.com>
Thu, 3 Jun 2010 16:30:15 +0000 (12:30 -0400)
committerDerek <derekwbarnett@gmail.com>
Thu, 3 Jun 2010 16:30:15 +0000 (12:30 -0400)
bamtools.cpp
bamtools_count.cpp
bamtools_header.cpp
bamtools_merge.cpp
bamtools_options.cpp
bamtools_stats.cpp
bamtools_tool.h
bamtools_variant.h

index 12731f21cbabeaf41107ae955a55e7921ed5ce2a..b5ba6e0a7b00f083ddd3d3866bdb242e70fd6aa4 100644 (file)
@@ -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;
index dad30e63993b87a8408672d7ab39ad9df8234bb8..c84c6ab68d54ef4ecb67c48cc58ab24f28508e77 100644 (file)
@@ -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 <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) { 
index 2e8c31e60c4f9f7a7dcc903af91cec5c79d4d29c..8fbb70e9b6c08835960a841026103ea11b9e8501 100644 (file)
@@ -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;
index 402d3773d85696a376d449612dc948cb31663911..cae61344eb9c8d30b2aa72c620788bf1a06f9270 100644 (file)
@@ -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);
index 89f545a443fc962963c48b5b5f663b0fb54ade82..931fbd8be4740892fe7fbe60db79726d7325bfac 100644 (file)
@@ -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 <cstdio>
 #include <cstdlib>
@@ -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<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());
@@ -100,14 +118,15 @@ void Options::DisplayHelp(void) {
                 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);
 
@@ -115,7 +134,8 @@ void Options::DisplayHelp(void) {
                 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);
                 }
@@ -167,7 +187,6 @@ void Options::Parse(int argc, char* argv[], int offset) {
         if (ovMapIter == m_optionsMap.end()) {
             errorBuilder << ERROR_SPACER << "An unrecognized argument was found: " << argument << std::endl;
             foundError = true;
-
         } else {
 
             *ovMapIter->second.pFoundArgument = true;
@@ -252,7 +271,7 @@ void Options::SetProgramInfo(const string& programName, const string& descriptio
 }
 
 // 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; }
index 7a6fa452bc801fd86488a93d075f5f43ef6c5949..5014f3ea8a6ba20a4820d25682e3e4162ddc2142 100644 (file)
@@ -51,7 +51,7 @@ StatsTool::StatsTool(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::AddValueOption("-in", "BAM filename", "the input BAM file", "", m_settings->HasInputBamFilename,  m_settings->InputBamFilename,  IO_Opts, Options::StandardIn());
 }
 
 StatsTool::~StatsTool(void) {
index 7d2fb6bb3d17c0f162320c3ab9a181031a8fcfee..bcd5cfed040e72b2be997fee7bc04c94af64da38 100644 (file)
@@ -3,12 +3,10 @@
 // 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
@@ -21,16 +19,12 @@ namespace BamTools {
 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
index 708ffd4fc87ce57dc43c57d1f9ef65c8e6cf553a..4927de984d38bbc641b846046db995a3d5a38025 100644 (file)
@@ -3,7 +3,7 @@
 // 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
 // ---------------------------------------------------------------------------
@@ -12,7 +12,7 @@
 // (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