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: 26 May 2010
7 // ---------------------------------------------------------------------------
8 // Integrates a number of BamTools functionalities into a single executable.
9 // ***************************************************************************
15 #include "bamtools_coverage.h"
16 #include "bamtools_dump.h"
17 #include "bamtools_header.h"
18 #include "bamtools_index.h"
19 #include "bamtools_merge.h"
20 #include "bamtools_sam.h"
21 #include "bamtools_sort.h"
22 #include "bamtools_stats.h"
25 using namespace BamTools;
27 // ------------------------------------------
28 // bamtools subtool names
29 static const string COVERAGE = "coverage";
30 static const string DUMP = "dump"; // <-- do we even want to keep this? I think 'bamtools sam' will be more useful anyway
31 // nobody's going to want what was essentially an early, bloated, debugging output
32 static const string HEADER = "header";
33 static const string INDEX = "index";
34 static const string MERGE = "merge";
35 static const string SAM = "sam";
36 static const string SORT = "sort";
37 static const string STATS = "stats";
39 // ------------------------------------------
40 // bamtools help/version names
41 static const string HELP = "help";
42 static const string LONG_HELP = "--help";
43 static const string SHORT_HELP = "-h";
45 static const string VERSION = "version";
46 static const string LONG_VERSION = "--version";
47 static const string SHORT_VERSION = "-v";
49 int Help(int argc, char* argv[]) {
51 // 'bamtools help COMMAND'
53 if ( argv[2] == COVERAGE) return BamCoverageHelp();
54 if ( argv[2] == DUMP ) return BamDumpHelp(); // keep?
55 if ( argv[2] == HEADER ) return BamHeaderHelp();
56 if ( argv[2] == INDEX ) return BamIndexHelp();
57 if ( argv[2] == MERGE ) return BamMergeHelp();
58 if ( argv[2] == SAM ) return BamSamHelp();
59 if ( argv[2] == SORT ) return BamSortHelp();
60 if ( argv[2] == STATS ) return BamStatsHelp();
63 // either 'bamtools help' or unrecognized argument after 'help'
65 cerr << "usage: bamtools [--help] COMMAND [ARGS]" << endl;
67 cerr << "Available bamtools commands:" << endl;
68 cerr << "\tcoverage\tPrints coverage statistics from the input BAM file" << endl;
69 cerr << "\tdump\t\tDump BAM file contents to text output" << endl; // keep?
70 cerr << "\theader\t\tPrints BAM header information" << endl;
71 cerr << "\tindex\t\tGenerates index for BAM file" << endl;
72 cerr << "\tmerge\t\tMerge multiple BAM files into single file" << endl;
73 cerr << "\tsam\t\tPrints the BAM file in SAM (text) format" << endl;
74 cerr << "\tsort\t\tSorts the BAM file according to some criteria" << endl;
75 cerr << "\tstats\t\tPrints some basic statistics from the input BAM file" << endl;
77 cerr << "See 'bamtools help COMMAND' for more information on a specific command." << endl;
85 cout << "bamtools v0.x.xx" << endl;
86 cout << "Part of BamTools API and toolkit" << endl;
87 cout << "Primary authors: Derek Barnett, Erik Garrison, Michael Stromberg" << endl;
88 cout << "(c) 2009-2010 Marth Lab, Biology Dept., Boston College" << endl;
93 int main(int argc, char* argv[]) {
96 if ( (argc == 1) ) return Help(argc, argv);
98 // 'bamtools help', 'bamtools --help', or 'bamtools -h'
99 if ( (argv[1] == HELP) || (argv[1] == LONG_HELP) || (argv[1] == SHORT_HELP) ) return Help(argc, argv);
101 // 'bamtools version', 'bamtools --version', or 'bamtools -v'
102 if ( (argv[1] == VERSION) || (argv[1] == LONG_VERSION) || (argv[1] == SHORT_VERSION) ) return Version();
104 // run desired sub-tool
105 if ( argv[1] == COVERAGE ) return RunBamCoverage(argc, argv);
106 if ( argv[1] == DUMP ) return RunBamDump(argc, argv); // keep?
107 if ( argv[1] == HEADER ) return RunBamHeader(argc, argv);
108 if ( argv[1] == INDEX ) return RunBamIndex(argc, argv);
109 if ( argv[1] == MERGE ) return RunBamMerge(argc, argv);
110 if ( argv[1] == SAM ) return RunBamSam(argc, argv);
111 if ( argv[1] == SORT ) return RunBamSort(argc, argv);
112 if ( argv[1] == STATS ) return RunBamStats(argc, argv);
114 // unrecognized 2nd argument, print help
115 return Help(argc, argv);