]> git.donarmstrong.com Git - bamtools.git/blob - bamtools_header.h
Reorganization of toolkit. Split subtools out to own headers. Added custom getopt...
[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 [BAM file1] [BAM file2] [BAM file3]..." << std::endl;
29     std::cerr << "\t[BAM file]\tInput file(s) to dump header contents from [default=stdin]" << std::endl;
30     std::cerr << std::endl;
31     return 0;
32 }
33
34 int RunBamHeader(int argc, char* argv[]) {
35
36     // else parse command line for args
37     GetOpt options(argc, argv, 1);
38     
39     std::vector<std::string> inputFilenames;
40     options.addVariableLengthOption("in", &inputFilenames);
41
42     if ( !options.parse() ) return BamHeaderHelp();
43     if ( inputFilenames.empty() ) { inputFilenames.push_back("stdin"); }
44   
45     // open files
46     BamMultiReader reader;
47     reader.Open(inputFilenames, false);
48         
49     // dump header contents to stdout
50     std::cout << reader.GetHeaderText() << std::endl;
51     
52     // clean up & exit
53     reader.Close();
54     return 0;
55 }
56
57 } // namespace BamTools
58
59 #endif // BAMTOOLS_HEADER_H