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: 20 July 2010
7 // ---------------------------------------------------------------------------
8 // Integrates a number of BamTools functionalities into a single executable.
9 // ***************************************************************************
15 #include "bamtools_convert.h"
16 #include "bamtools_count.h"
17 #include "bamtools_coverage.h"
18 #include "bamtools_filter.h"
19 #include "bamtools_header.h"
20 #include "bamtools_index.h"
21 #include "bamtools_merge.h"
22 #include "bamtools_random.h"
23 // #include "bamtools_sam.h"
24 #include "bamtools_sort.h"
25 #include "bamtools_stats.h"
28 using namespace BamTools;
30 // ------------------------------------------
31 // bamtools subtool names
32 static const string CONVERT = "convert";
33 static const string COUNT = "count";
34 static const string COVERAGE = "coverage";
35 static const string FILTER = "filter";
36 static const string HEADER = "header";
37 static const string INDEX = "index";
38 static const string MERGE = "merge";
39 static const string RANDOM = "random";
40 // static const string SAM = "sam";
41 static const string SORT = "sort";
42 static const string STATS = "stats";
44 // ------------------------------------------
45 // bamtools help/version names
46 static const string HELP = "help";
47 static const string LONG_HELP = "--help";
48 static const string SHORT_HELP = "-h";
50 static const string VERSION = "version";
51 static const string LONG_VERSION = "--version";
52 static const string SHORT_VERSION = "-v";
54 // ------------------------------------------
56 int Help(int argc, char* argv[]) {
58 // 'bamtools help COMMAND'
61 AbstractTool* tool(0);
62 if ( argv[2] == CONVERT ) tool = new ConvertTool;
63 if ( argv[2] == COUNT ) tool = new CountTool;
64 if ( argv[2] == COVERAGE ) tool = new CoverageTool;
65 if ( argv[2] == FILTER ) tool = new FilterTool;
66 if ( argv[2] == HEADER ) tool = new HeaderTool;
67 if ( argv[2] == INDEX ) tool = new IndexTool;
68 if ( argv[2] == MERGE ) tool = new MergeTool;
69 if ( argv[2] == RANDOM ) tool = new RandomTool;
70 // if ( argv[2] == SAM ) tool = new SamTool;
71 if ( argv[2] == SORT ) tool = new SortTool;
72 if ( argv[2] == STATS ) tool = new StatsTool;
74 // if tool known, print its help screen
75 if ( tool ) return tool->Help();
78 // either 'bamtools help' or unrecognized argument after 'help'
80 cerr << "usage: bamtools [--help] COMMAND [ARGS]" << endl;
82 cerr << "Available bamtools commands:" << endl;
83 cerr << "\tconvert Converts between BAM and a number of other formats" << endl;
84 cerr << "\tcount Prints number of alignments in BAM file" << endl;
85 cerr << "\tcoverage Prints coverage statistics from the input BAM file" << endl;
86 cerr << "\tfilter Filters BAM file(s) by user-specified criteria" << endl;
87 cerr << "\theader Prints BAM header information" << endl;
88 cerr << "\tindex Generates index for BAM file" << endl;
89 cerr << "\tmerge Merge multiple BAM files into single file" << endl;
90 cerr << "\trandom Grab a random subset of alignments" << endl;
91 // cerr << "\tsam Prints the BAM file in SAM (text) format" << endl;
92 cerr << "\tsort Sorts the BAM file according to some criteria" << endl;
93 cerr << "\tstats Prints some basic statistics from the input BAM file" << endl;
95 cerr << "See 'bamtools help COMMAND' for more information on a specific command." << endl;
100 // ------------------------------------------
101 // Print version info
104 cout << "bamtools v0.8.xx" << endl;
105 cout << "Part of BamTools API and toolkit" << endl;
106 cout << "Primary authors: Derek Barnett, Erik Garrison, Michael Stromberg" << endl;
107 cout << "(c) 2009-2010 Marth Lab, Biology Dept., Boston College" << endl;
112 // ------------------------------------------
113 // toolkit entry point
114 int main(int argc, char* argv[]) {
117 if ( (argc == 1) ) return Help(argc, argv);
119 // 'bamtools help', 'bamtools --help', or 'bamtools -h'
120 if ( (argv[1] == HELP) || (argv[1] == LONG_HELP) || (argv[1] == SHORT_HELP) ) return Help(argc, argv);
122 // 'bamtools version', 'bamtools --version', or 'bamtools -v'
123 if ( (argv[1] == VERSION) || (argv[1] == LONG_VERSION) || (argv[1] == SHORT_VERSION) ) return Version();
125 // determine desired sub-tool
126 AbstractTool* tool(0);
127 if ( argv[1] == CONVERT ) tool = new ConvertTool;
128 if ( argv[1] == COUNT ) tool = new CountTool;
129 if ( argv[1] == COVERAGE ) tool = new CoverageTool;
130 if ( argv[1] == FILTER ) tool = new FilterTool;
131 if ( argv[1] == HEADER ) tool = new HeaderTool;
132 if ( argv[1] == INDEX ) tool = new IndexTool;
133 if ( argv[1] == MERGE ) tool = new MergeTool;
134 if ( argv[1] == RANDOM ) tool = new RandomTool;
135 // if ( argv[1] == SAM ) tool = new SamTool;
136 if ( argv[1] == SORT ) tool = new SortTool;
137 if ( argv[1] == STATS ) tool = new StatsTool;
139 // if found, run tool
140 if ( tool ) return tool->Run(argc, argv);
141 // no match found, show help
142 else return Help(argc, argv);