comparison BEDTools-Version-2.14.3/src/multiBamCov/multiBamCovMain.cpp @ 0:dfcd8b6c1bda

Uploaded
author aaronquinlan
date Thu, 03 Nov 2011 10:25:04 -0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:dfcd8b6c1bda
1 /*****************************************************************************
2 multiBamCovMain.cpp
3
4 (c) 2009 - Aaron Quinlan
5 Hall Laboratory
6 Department of Biochemistry and Molecular Genetics
7 University of Virginia
8 aaronquinlan@gmail.com
9
10 Licenced under the GNU General Public License 2.0 license.
11 ******************************************************************************/
12 #include "multiBamCov.h"
13 #include "version.h"
14
15 using namespace std;
16
17 // define our program name
18 #define PROGRAM_NAME "multiBamCov"
19
20
21 // define our parameter checking macro
22 #define PARAMETER_CHECK(param, paramLen, actualLen) (strncmp(argv[i], param, min(actualLen, paramLen))== 0) && (actualLen == paramLen)
23
24 // function declarations
25 void ShowHelp(void);
26
27 int main(int argc, char* argv[]) {
28
29 // our configuration variables
30 bool showHelp = false;
31
32 // input files
33 string bedFile;
34 vector<string> bamFiles;
35 int minQual = 0;
36
37 // input arguments
38 bool haveBed = false;
39 bool haveBams = false;
40 bool properOnly = false;
41 bool keepDuplicates = false;
42 bool keepFailedQC = false;
43
44 // check to see if we should print out some help
45 if(argc <= 1) showHelp = true;
46
47 for(int i = 1; i < argc; i++) {
48 int parameterLength = (int)strlen(argv[i]);
49
50 if((PARAMETER_CHECK("-h", 2, parameterLength)) ||
51 (PARAMETER_CHECK("--help", 5, parameterLength))) {
52 showHelp = true;
53 }
54 }
55
56 if(showHelp) ShowHelp();
57
58 // do some parsing (all of these parameters require 2 strings)
59 for(int i = 1; i < argc; i++) {
60
61 int parameterLength = (int)strlen(argv[i]);
62
63 if(PARAMETER_CHECK("-bed", 4, parameterLength)) {
64 if ((i+1) < argc) {
65 haveBed = true;
66 bedFile = argv[i + 1];
67 i++;
68 }
69 }
70 else if(PARAMETER_CHECK("-bams", 5, parameterLength)) {
71 if ((i+1) < argc) {
72 haveBams = true;
73 i = i+1;
74 string file = argv[i];
75 while (file[0] != '-' && i < argc) {
76 bamFiles.push_back(file);
77 i++;
78 if (i < argc)
79 file = argv[i];
80 }
81 i--;
82 }
83 }
84 else if(PARAMETER_CHECK("-q", 2, parameterLength)) {
85 if ((i+1) < argc) {
86 minQual = atoi(argv[i + 1]);
87 i++;
88 }
89 }
90 else if(PARAMETER_CHECK("-p", 2, parameterLength)) {
91 properOnly = true;
92 }
93 else if(PARAMETER_CHECK("-D", 2, parameterLength)) {
94 keepDuplicates = true;
95 }
96
97 else if(PARAMETER_CHECK("-F", 2, parameterLength)) {
98 keepFailedQC = true;
99 }
100 else {
101 cerr << endl << "*****ERROR: Unrecognized parameter: " << argv[i] << " *****" << endl << endl;
102 showHelp = true;
103 }
104 }
105
106 if (!showHelp) {
107 MultiCovBam *mc = new MultiCovBam(bamFiles, bedFile, minQual, properOnly, keepDuplicates, keepFailedQC);
108 mc->CollectCoverage();
109 delete mc;
110 return 0;
111 }
112 else {
113 ShowHelp();
114 }
115 }
116
117 void ShowHelp(void) {
118
119 cerr << endl << "Program: " << PROGRAM_NAME << " (v" << VERSION << ")" << endl;
120
121 cerr << "Author: Aaron Quinlan (aaronquinlan@gmail.com)" << endl;
122
123 cerr << "Summary: Counts sequence coverage for multiple bams at specific loci." << endl << endl;
124
125 cerr << "Usage: " << PROGRAM_NAME << " [OPTIONS] -bams aln.1.bam aln.2.bam ... aln.n.bam -bed <bed/gff/vcf>" << endl << endl;
126
127 cerr << "Options: " << endl;
128
129 cerr << "\t-bams\t" << "The bam files." << endl << endl;
130
131 cerr << "\t-bed\t" << "The bed file." << endl << endl;
132
133 cerr << "\t-q\t" << "Minimum mapping quality allowed. Default is 0." << endl << endl;
134
135 cerr << "\t-D\t" << "Include duplicate-marked reads. Default is to count non-duplicates only" << endl << endl;
136
137 cerr << "\t-F\t" << "Include failed-QC reads. Default is to count pass-QC reads only" << endl << endl;
138
139 cerr << "\t-p\t" << "Only count proper pairs. Default is to count all alignments with MAPQ" << endl;
140 cerr << "\t\t" << "greater than the -q argument, regardless of the BAM FLAG field." << endl << endl;
141
142 // end the program here
143 exit(1);
144
145 }