]> git.donarmstrong.com Git - bamtools.git/blob - bamtools_count.cpp
Put utilities into own class with static methods
[bamtools.git] / bamtools_count.cpp
1 // ***************************************************************************
2 // bamtools_count.cpp (c) 2010 Derek Barnett, Erik Garrison
3 // Marth Lab, Department of Biology, Boston College
4 // All rights reserved.
5 // ---------------------------------------------------------------------------
6 // Last modified: 2 June 2010
7 // ---------------------------------------------------------------------------
8 // Prints alignment count for BAM file
9 //
10 // ** Expand to multiple?? 
11 //
12 // ***************************************************************************
13
14 #include <iostream>
15 #include <string>
16 #include <vector>
17
18 #include "bamtools_count.h"
19 #include "bamtools_options.h"
20 #include "bamtools_utilities.h"
21 #include "BamReader.h"
22
23 using namespace std;
24 using namespace BamTools;
25   
26 // ---------------------------------------------  
27 // CountSettings implementation
28
29 struct CountTool::CountSettings {
30
31     // flags
32     bool HasInputBamFilename;
33     bool HasRegion;
34
35     // filenames
36     std::string InputBamFilename;
37     std::string Region;
38     
39     // constructor
40     CountSettings(void)
41         : HasInputBamFilename(false)
42         , HasRegion(false)
43         , InputBamFilename(Options::StandardIn())
44     { }  
45 }; 
46   
47 // ---------------------------------------------
48 // CountTool implementation
49
50 CountTool::CountTool(void) 
51     : AbstractTool()
52     , m_settings(new CountSettings)
53
54     // set program details
55     Options::SetProgramInfo("bamtools count", "prints alignment counts for a BAM file", "-in <filename> ");
56     
57     // set up options 
58     OptionGroup* IO_Opts = Options::CreateOptionGroup("Input & Output");
59     Options::AddValueOption("-in", "BAM filename", "the input BAM file", "", m_settings->HasInputBamFilename, m_settings->InputBamFilename, IO_Opts, Options::StandardIn());
60     
61     OptionGroup* FilterOpts = Options::CreateOptionGroup("Filters");
62     Options::AddValueOption("-region", "REGION", "genomic region. See README for more details", "", m_settings->HasRegion, m_settings->Region, FilterOpts);
63 }
64
65 CountTool::~CountTool(void) { 
66     delete m_settings;
67     m_settings = 0;
68 }
69
70 int CountTool::Help(void) { 
71     Options::DisplayHelp();
72     return 0;
73
74
75 int CountTool::Run(int argc, char* argv[]) { 
76
77     // parse command line arguments
78     Options::Parse(argc, argv, 1);
79
80     //open our BAM reader
81 //     BamReader reader;
82 //     reader.Open(m_settings.InputBamFilename);
83
84     // count alignments
85     string startChrom;
86     string stopChrom;
87     int startPos;
88     int stopPos;
89     
90     if ( !m_settings->HasRegion ) {
91         cerr << "Counting all alignments " << endl;
92     } else {
93         if ( Utilities::ParseRegionString(m_settings->Region, startChrom, startPos, stopChrom, stopPos) ) {
94             cerr << "Counting only alignments in region " << m_settings->Region << endl;
95             cerr << "StartChrom: " << startChrom << endl;
96             cerr << "StartPos:   " << startPos << endl;
97             cerr << "StopChrom:  " << stopChrom << endl;
98             cerr << "StopPos:    " << stopPos << endl;
99         }
100     }
101      
102     cerr << " from " << m_settings->InputBamFilename << endl;
103     cerr << "FEATURE NOT YET IMPLEMENTED!" << endl;
104
105     // clean & exit
106 //     reader.Close();
107     return 0;
108 }