]> git.donarmstrong.com Git - bamtools.git/blob - bamtools_dump.h
Reorganization of toolkit. Split subtools out to own headers. Added custom getopt...
[bamtools.git] / bamtools_dump.h
1 // ***************************************************************************
2 // bamtools_dump.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 // Dumps alignment summaries out to stdout.
9 //
10 // ** This should probably go the way of the dodo soon? bamtools sam makes this
11 //   obsolete and probably worthless.
12 // 
13 // ***************************************************************************
14
15 #ifndef BAMTOOLS_DUMP_H
16 #define BAMTOOLS_DUMP_H
17
18 #include <iostream>
19 #include <string>
20 #include <vector>
21
22 #include "BamMultiReader.h"
23 // #include "GetOpt.h"
24 #include "bamtools_getopt.h"
25
26 namespace BamTools { 
27
28 int BamDumpHelp(void) { 
29     std::cerr << std::endl;
30     std::cerr << "usage:\tbamtools dump [BAM file1] [BAM file2] [BAM file3]..." << std::endl;
31     std::cerr << "\t[BAM file]\tInput file(s) to dump alignment summaries from [default=stdin]" << std::endl;
32     std::cerr << std::endl;
33     return 0;
34 }
35
36 // Spit out basic BamAlignment data 
37 void PrintAlignment(const BamTools::BamAlignment& alignment) {
38     std::cout << "---------------------------------" << std::endl;
39     std::cout << "Name: "       << alignment.Name << std::endl;
40     std::cout << "Aligned to: " << alignment.RefID;
41     std::cout << ":"            << alignment.Position << std::endl;
42     std::cout << std::endl;
43 }
44
45 int RunBamDump(int argc, char* argv[]) {
46   
47     // else parse command line for args
48     GetOpt options(argc, argv, 1);
49     
50     std::vector<std::string> inputFilenames;
51     options.addVariableLengthOption("in", &inputFilenames);
52
53     if ( !options.parse() ) return BamDumpHelp();
54     if ( inputFilenames.empty() ) { inputFilenames.push_back("stdin"); }
55     
56     // open files
57     BamMultiReader reader;
58     reader.Open(inputFilenames, false);
59
60     // dump alignment summaries to stdout
61     BamAlignment bAlignment;
62     while (reader.GetNextAlignment(bAlignment)) {
63         PrintAlignment(bAlignment);
64     }
65
66     // clean up & exit
67     reader.Close(); 
68     return 0;
69 }
70
71 } // namespace BamTools
72
73 #endif // BAMTOOLS_DUMP_H