]> git.donarmstrong.com Git - bamtools.git/blob - bamtools_header.h
Mostly cleaned up help & usage messages. Added MIT license.
[bamtools.git] / bamtools_header.h
1 // ***************************************************************************
2 // bamtools_header.h (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 // Prints the SAM-style header from a single BAM file (or merged header from
9 // multiple BAM files) to stdout.
10 // ***************************************************************************
11
12 #ifndef BAMTOOLS_HEADER_H
13 #define BAMTOOLS_HEADER_H
14
15 #include <iostream>
16 #include <string>
17 #include <vector>
18
19 #include "BamReader.h"
20 #include "BamMultiReader.h"
21 // #include "GetOpt.h"
22 #include "bamtools_getopt.h"
23
24 namespace BamTools {
25
26 int BamHeaderHelp(void) { 
27     std::cerr << std::endl;
28     std::cerr << "usage:\tbamtools header [--in FILE [FILE] [FILE] ...]" << std::endl;
29     std::cerr << std::endl;
30     std::cerr << "\t--in FILE  Input file(s) to dump header contents from  [stdin]" << std::endl;
31     std::cerr << std::endl;
32     return 0;
33 }
34
35 int RunBamHeader(int argc, char* argv[]) {
36
37     // else parse command line for args
38     GetOpt options(argc, argv, 1);
39     
40     std::vector<std::string> inputFilenames;
41     options.addVariableLengthOption("in", &inputFilenames);
42
43     if ( !options.parse() ) return BamHeaderHelp();
44     if ( inputFilenames.empty() ) { inputFilenames.push_back("stdin"); }
45   
46     // open files
47     BamMultiReader reader;
48     reader.Open(inputFilenames, false);
49         
50     // dump header contents to stdout
51     std::cout << reader.GetHeaderText() << std::endl;
52     
53     // clean up & exit
54     reader.Close();
55     return 0;
56 }
57
58 } // namespace BamTools
59
60 #endif // BAMTOOLS_HEADER_H