1 // ***************************************************************************
2 // bamtools.cpp (c) 2010 Derek Barnett, Erik Garrison
3 // Marth Lab, Department of Biology, Boston College
4 // All rights reserved.
5 // ---------------------------------------------------------------------------
6 // Last modified: 2 June 2010
7 // ---------------------------------------------------------------------------
8 // Integrates a number of BamTools functionalities into a single executable.
9 // ***************************************************************************
15 #include "bamtools_count.h"
16 #include "bamtools_coverage.h"
17 #include "bamtools_filter.h"
18 #include "bamtools_header.h"
19 #include "bamtools_index.h"
20 #include "bamtools_merge.h"
21 #include "bamtools_sam.h"
22 #include "bamtools_sort.h"
23 #include "bamtools_stats.h"
26 using namespace BamTools;
28 // ------------------------------------------
29 // bamtools subtool names
30 static const string COUNT = "count";
31 static const string COVERAGE = "coverage";
32 static const string FILTER = "filter";
33 static const string HEADER = "header";
34 static const string INDEX = "index";
35 static const string MERGE = "merge";
36 static const string SAM = "sam";
37 static const string SORT = "sort";
38 static const string STATS = "stats";
40 // ------------------------------------------
41 // bamtools help/version names
42 static const string HELP = "help";
43 static const string LONG_HELP = "--help";
44 static const string SHORT_HELP = "-h";
46 static const string VERSION = "version";
47 static const string LONG_VERSION = "--version";
48 static const string SHORT_VERSION = "-v";
50 // ------------------------------------------
52 int Help(int argc, char* argv[]) {
54 // 'bamtools help COMMAND'
57 AbstractTool* tool(0);
58 if ( argv[2] == COUNT ) tool = new CountTool;
59 if ( argv[2] == COVERAGE ) tool = new CoverageTool;
60 if ( argv[2] == FILTER ) tool = new FilterTool;
61 if ( argv[2] == HEADER ) tool = new HeaderTool;
62 if ( argv[2] == INDEX ) tool = new IndexTool;
63 if ( argv[2] == MERGE ) tool = new MergeTool;
64 if ( argv[2] == SAM ) tool = new SamTool;
65 if ( argv[2] == SORT ) tool = new SortTool;
66 if ( argv[2] == STATS ) tool = new StatsTool;
68 // if tool known, print its help screen
69 if ( tool ) return tool->Help();
72 // either 'bamtools help' or unrecognized argument after 'help'
74 cerr << "usage: bamtools [--help] COMMAND [ARGS]" << endl;
76 cerr << "Available bamtools commands:" << endl;
77 cerr << "\tcount Prints number of alignments in BAM file" << endl;
78 cerr << "\tcoverage Prints coverage statistics from the input BAM file" << endl;
79 cerr << "\tfilter Filters BAM file(s) by user-specified criteria" << endl;
80 cerr << "\theader Prints BAM header information" << endl;
81 cerr << "\tindex Generates index for BAM file" << endl;
82 cerr << "\tmerge Merge multiple BAM files into single file" << endl;
83 cerr << "\tsam Prints the BAM file in SAM (text) format" << endl;
84 cerr << "\tsort Sorts the BAM file according to some criteria" << endl;
85 cerr << "\tstats Prints some basic statistics from the input BAM file" << endl;
87 cerr << "See 'bamtools help COMMAND' for more information on a specific command." << endl;
92 // ------------------------------------------
96 cout << "bamtools v0.8.xx" << endl;
97 cout << "Part of BamTools API and toolkit" << endl;
98 cout << "Primary authors: Derek Barnett, Erik Garrison, Michael Stromberg" << endl;
99 cout << "(c) 2009-2010 Marth Lab, Biology Dept., Boston College" << endl;
104 // ------------------------------------------
105 // toolkit entry point
106 int main(int argc, char* argv[]) {
109 if ( (argc == 1) ) return Help(argc, argv);
111 // 'bamtools help', 'bamtools --help', or 'bamtools -h'
112 if ( (argv[1] == HELP) || (argv[1] == LONG_HELP) || (argv[1] == SHORT_HELP) ) return Help(argc, argv);
114 // 'bamtools version', 'bamtools --version', or 'bamtools -v'
115 if ( (argv[1] == VERSION) || (argv[1] == LONG_VERSION) || (argv[1] == SHORT_VERSION) ) return Version();
117 // determine desired sub-tool
118 AbstractTool* tool(0);
119 if ( argv[1] == COUNT ) tool = new CountTool;
120 if ( argv[1] == COVERAGE ) tool = new CoverageTool;
121 if ( argv[1] == FILTER ) tool = new FilterTool;
122 if ( argv[1] == HEADER ) tool = new HeaderTool;
123 if ( argv[1] == INDEX ) tool = new IndexTool;
124 if ( argv[1] == MERGE ) tool = new MergeTool;
125 if ( argv[1] == SAM ) tool = new SamTool;
126 if ( argv[1] == SORT ) tool = new SortTool;
127 if ( argv[1] == STATS ) tool = new StatsTool;
129 // if found, run tool
130 if ( tool ) return tool->Run(argc, argv);
131 // no match found, show help
132 else return Help(argc, argv);