]> git.donarmstrong.com Git - bamtools.git/blob - bamtools.cpp
d80d96047e94917970cd586952bbfb780ed203b4
[bamtools.git] / bamtools.cpp
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 // ***************************************************************************
10
11 // Std C/C++ includes
12 #include <iostream>
13
14 // BamTools includes
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"
23
24 using namespace std;
25 using namespace BamTools;
26
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";
38
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";
44
45 static const string VERSION       = "version";
46 static const string LONG_VERSION  = "--version";
47 static const string SHORT_VERSION = "-v";
48
49 int Help(int argc, char* argv[]) {
50   
51     // 'bamtools help COMMAND'
52     if (argc > 2) {
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();
61     }
62      
63     // either 'bamtools help' or unrecognized argument after 'help'
64     cerr << endl;
65     cerr << "usage: bamtools [--help] COMMAND [ARGS]" << endl;
66     cerr << 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;
76     cerr << endl;
77     cerr << "See 'bamtools help COMMAND' for more information on a specific command." << endl;
78     cerr << endl;
79     
80     return 0;
81 }
82
83 int Version(void) {
84     cout << 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;
89     cout << endl;
90     return 0;
91 }
92
93 int main(int argc, char* argv[]) {
94
95     // just 'bamtools'
96     if ( (argc == 1) ) return Help(argc, argv);
97     
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); 
100     
101     // 'bamtools version', 'bamtools --version', or 'bamtools -v'
102     if ( (argv[1] == VERSION) || (argv[1] == LONG_VERSION) || (argv[1] == SHORT_VERSION) ) return Version(); 
103         
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);
113     
114     // unrecognized 2nd argument, print help
115     return Help(argc, argv);    
116 }