comparison BEDTools-Version-2.14.3/src/subtractBed/subtractMain.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 subtractMain.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 "subtractBed.h"
13 #include "version.h"
14
15 using namespace std;
16
17 // define our program name
18 #define PROGRAM_NAME "subtractBed"
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 bedAFile;
34 string bedBFile;
35
36 // input arguments
37 float overlapFraction = 1E-9;
38
39 bool haveBedA = false;
40 bool haveBedB = false;
41 bool haveFraction = false;
42 bool sameStrand = false;
43 bool diffStrand = false;
44
45 // check to see if we should print out some help
46 if(argc <= 1) showHelp = true;
47
48 for(int i = 1; i < argc; i++) {
49 int parameterLength = (int)strlen(argv[i]);
50
51 if((PARAMETER_CHECK("-h", 2, parameterLength)) ||
52 (PARAMETER_CHECK("--help", 5, parameterLength))) {
53 showHelp = true;
54 }
55 }
56
57 if(showHelp) ShowHelp();
58
59 // do some parsing (all of these parameters require 2 strings)
60 for(int i = 1; i < argc; i++) {
61
62 int parameterLength = (int)strlen(argv[i]);
63
64 if(PARAMETER_CHECK("-a", 2, parameterLength)) {
65 if ((i+1) < argc) {
66 haveBedA = true;
67 bedAFile = argv[i + 1];
68 i++;
69 }
70 }
71 else if(PARAMETER_CHECK("-b", 2, parameterLength)) {
72 if ((i+1) < argc) {
73 haveBedB = true;
74 bedBFile = argv[i + 1];
75 i++;
76 }
77 }
78 else if(PARAMETER_CHECK("-f", 2, parameterLength)) {
79 if ((i+1) < argc) {
80 haveFraction = true;
81 overlapFraction = atof(argv[i + 1]);
82 i++;
83 }
84 }
85 else if (PARAMETER_CHECK("-s", 2, parameterLength)) {
86 sameStrand = true;
87 }
88 else if (PARAMETER_CHECK("-S", 2, parameterLength)) {
89 diffStrand = true;
90 }
91 else {
92 cerr << endl << "*****ERROR: Unrecognized parameter: " << argv[i] << " *****" << endl << endl;
93 showHelp = true;
94 }
95 }
96
97 // make sure we have both input files
98 if (!haveBedA || !haveBedB) {
99 cerr << endl << "*****" << endl << "*****ERROR: Need -a and -b files. " << endl << "*****" << endl;
100 showHelp = true;
101 }
102
103 if (sameStrand && diffStrand) {
104 cerr << endl << "*****" << endl << "*****ERROR: Request either -s OR -S, not both." << endl << "*****" << endl;
105 showHelp = true;
106 }
107
108 if (!showHelp) {
109
110 BedSubtract *bs = new BedSubtract(bedAFile, bedBFile, overlapFraction, sameStrand, diffStrand);
111 delete bs;
112 return 0;
113 }
114 else {
115 ShowHelp();
116 }
117 }
118
119 void ShowHelp(void) {
120
121 cerr << endl << "Program: " << PROGRAM_NAME << " (v" << VERSION << ")" << endl;
122
123 cerr << "Author: Aaron Quinlan (aaronquinlan@gmail.com)" << endl;
124
125 cerr << "Summary: Removes the portion(s) of an interval that is overlapped" << endl;
126 cerr << "\t by another feature(s)." << endl << endl;
127
128 cerr << "Usage: " << PROGRAM_NAME << " [OPTIONS] -a <bed/gff/vcf> -b <bed/gff/vcf>" << endl << endl;
129
130 cerr << "Options: " << endl;
131 cerr << "\t-f\t" << "Minimum overlap required as a fraction of A." << endl;
132 cerr << "\t\t- Default is 1E-9 (i.e., 1bp)." << endl;
133 cerr << "\t\t- (FLOAT) (e.g. 0.50)" << endl << endl;
134
135 cerr << "\t-s\t" << "Require same strandedness. That is, only subtract hits in B that" << endl;
136 cerr << "\t\toverlap A on the _same_ strand." << endl;
137 cerr << "\t\t- By default, overlaps are subtracted without respect to strand." << endl << endl;
138
139 cerr << "\t-S\t" << "Force strandedness. That is, only subtract hits in B that" << endl;
140 cerr << "\t\toverlap A on the _opposite_ strand." << endl;
141 cerr << "\t\t- By default, overlaps are subtracted without respect to strand." << endl << endl;
142
143 // end the program here
144 exit(1);
145 }