0
|
1 /*****************************************************************************
|
|
2 pairToPairMain.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 "pairToPair.h"
|
|
13 #include "version.h"
|
|
14
|
|
15 using namespace std;
|
|
16
|
|
17 // define our program name
|
|
18 #define PROGRAM_NAME "pairToPair"
|
|
19
|
|
20 // define our parameter checking macro
|
|
21 #define PARAMETER_CHECK(param, paramLen, actualLen) (strncmp(argv[i], param, min(actualLen, paramLen))== 0) && (actualLen == paramLen)
|
|
22
|
|
23 // function declarations
|
|
24 void ShowHelp(void);
|
|
25
|
|
26 int main(int argc, char* argv[]) {
|
|
27
|
|
28 // our configuration variables
|
|
29 bool showHelp = false;
|
|
30
|
|
31 // input files
|
|
32 string bedAFile;
|
|
33 string bedBFile;
|
|
34
|
|
35 // input arguments
|
|
36 float overlapFraction = 1E-9;
|
|
37 int slop = 0;
|
|
38 string searchType = "both";
|
|
39
|
|
40 // flags to track parameters
|
|
41 bool haveBedA = false;
|
|
42 bool haveBedB = false;
|
|
43 bool haveSearchType = false;
|
|
44 bool haveFraction = false;
|
|
45 bool ignoreStrand = false;
|
|
46 bool requireDifferentNames = false;
|
|
47 bool haveSlop = false;
|
|
48 bool strandedSlop = false;
|
|
49 // check to see if we should print out some help
|
|
50 if(argc <= 1) showHelp = true;
|
|
51
|
|
52 for(int i = 1; i < argc; i++) {
|
|
53 int parameterLength = (int)strlen(argv[i]);
|
|
54
|
|
55 if((PARAMETER_CHECK("-h", 2, parameterLength)) ||
|
|
56 (PARAMETER_CHECK("--help", 5, parameterLength))) {
|
|
57 showHelp = true;
|
|
58 }
|
|
59 }
|
|
60
|
|
61 if(showHelp) ShowHelp();
|
|
62
|
|
63 // do some parsing (all of these parameters require 2 strings)
|
|
64 for(int i = 1; i < argc; i++) {
|
|
65
|
|
66 int parameterLength = (int)strlen(argv[i]);
|
|
67
|
|
68 if(PARAMETER_CHECK("-a", 2, parameterLength)) {
|
|
69 if ((i+1) < argc) {
|
|
70 haveBedA = true;
|
|
71 bedAFile = argv[i + 1];
|
|
72 i++;
|
|
73 }
|
|
74 }
|
|
75 else if(PARAMETER_CHECK("-b", 2, parameterLength)) {
|
|
76 if ((i+1) < argc) {
|
|
77 haveBedB = true;
|
|
78 bedBFile = argv[i + 1];
|
|
79 i++;
|
|
80 }
|
|
81 }
|
|
82 else if(PARAMETER_CHECK("-type", 5, parameterLength)) {
|
|
83 if ((i+1) < argc) {
|
|
84 haveSearchType = true;
|
|
85 searchType = argv[i + 1];
|
|
86 i++;
|
|
87 }
|
|
88 }
|
|
89 else if(PARAMETER_CHECK("-f", 2, parameterLength)) {
|
|
90 if ((i+1) < argc) {
|
|
91 haveFraction = true;
|
|
92 overlapFraction = atof(argv[i + 1]);
|
|
93 i++;
|
|
94 }
|
|
95 }
|
|
96 else if(PARAMETER_CHECK("-slop", 5, parameterLength)) {
|
|
97 if ((i+1) < argc) {
|
|
98 haveSlop = true;
|
|
99 slop = atoi(argv[i + 1]);
|
|
100 i++;
|
|
101 }
|
|
102 }
|
|
103 else if(PARAMETER_CHECK("-ss", 3, parameterLength)) {
|
|
104 strandedSlop = true;
|
|
105 }
|
|
106 else if(PARAMETER_CHECK("-rdn", 4, parameterLength)) {
|
|
107 requireDifferentNames = true;
|
|
108 }
|
|
109 else if(PARAMETER_CHECK("-is", 3, parameterLength)) {
|
|
110 ignoreStrand = true;
|
|
111 }
|
|
112 else {
|
|
113 cerr << endl << "*****ERROR: Unrecognized parameter: " << argv[i] << " *****" << endl << endl;
|
|
114 showHelp = true;
|
|
115 }
|
|
116 }
|
|
117
|
|
118
|
|
119 // make sure we have both input files
|
|
120 if (!haveBedA || !haveBedB) {
|
|
121 cerr << endl << "*****" << endl << "*****ERROR: Need -a and -b files. " << endl << "*****" << endl;
|
|
122 showHelp = true;
|
|
123 }
|
|
124
|
|
125 if (haveSearchType && (searchType != "neither") && (searchType != "both") && (searchType != "either") && (searchType != "notboth")) {
|
|
126 cerr << endl << "*****" << endl << "*****ERROR: Request \"both\",\"neither\",\"either\",or \"notboth\"" << endl << "*****" << endl;
|
|
127 showHelp = true;
|
|
128 }
|
|
129
|
|
130 if (strandedSlop == true && haveSlop == false) {
|
|
131 cerr << endl << "*****" << endl << "*****ERROR: Need a -slop value if requesting -ss." << endl << "*****" << endl;
|
|
132 showHelp = true;
|
|
133 }
|
|
134
|
|
135 if (!showHelp) {
|
|
136
|
|
137 PairToPair *bi = new PairToPair(bedAFile, bedBFile, overlapFraction, searchType,
|
|
138 ignoreStrand, requireDifferentNames, slop, strandedSlop);
|
|
139 delete bi;
|
|
140 return 0;
|
|
141 }
|
|
142 else {
|
|
143 ShowHelp();
|
|
144 }
|
|
145 }
|
|
146
|
|
147
|
|
148 void ShowHelp(void) {
|
|
149 cerr << endl << "Program: " << PROGRAM_NAME << " (v" << VERSION << ")" << endl;
|
|
150
|
|
151 cerr << "Author: Aaron Quinlan (aaronquinlan@gmail.com)" << endl;
|
|
152
|
|
153 cerr << "Summary: Report overlaps between two paired-end BED files (BEDPE)." << endl << endl;
|
|
154
|
|
155 cerr << "Usage: " << PROGRAM_NAME << " [OPTIONS] -a <BEDPE> -b <BEDPE>" << endl << endl;
|
|
156
|
|
157 cerr << "Options: " << endl;
|
|
158 cerr << "\t-f\t" << "Minimum overlap required as fraction of A (e.g. 0.05)." << endl;
|
|
159 cerr << "\t\tDefault is 1E-9 (effectively 1bp)." << endl << endl;
|
|
160
|
|
161 cerr << "\t-type \t" << "Approach to reporting overlaps between A and B." << endl << endl;
|
|
162 cerr << "\t\tneither\tReport overlaps if neither end of A overlaps B." << endl;
|
|
163 cerr << "\t\teither\tReport overlaps if either ends of A overlap B." << endl;
|
|
164 cerr << "\t\tboth\tReport overlaps if both ends of A overlap B." << endl;
|
|
165 cerr << "\t\tnotboth\tReport overlaps if one or neither of ends of A overlap B." << endl;
|
|
166
|
|
167 cerr << "\t\t- Default = both." << endl << endl;
|
|
168
|
|
169 cerr << "\t-slop \t" << "The amount of slop (in b.p.). to be added to each footprint." << endl;
|
|
170 cerr << "\t\t*Note*: Slop is subtracted from start1 and start2 and added to end1 and end2." << endl << endl;
|
|
171
|
|
172 cerr << "\t-ss\t" << "Add slop based to each BEDPE footprint based on strand." << endl;
|
|
173 cerr << "\t\t- If strand is \"+\", slop is only added to the end coordinates." << endl;
|
|
174 cerr << "\t\t- If strand is \"-\", slop is only added to the start coordinates." << endl;
|
|
175 cerr << "\t\t- By default, slop is added in both directions." << endl << endl;
|
|
176
|
|
177 cerr << "\t-is\t" << "Ignore strands when searching for overlaps." << endl;
|
|
178 cerr << "\t\t- By default, strands are enforced." << endl << endl;
|
|
179
|
|
180 cerr << "\t-rdn\t" << "Require the hits to have different names (i.e. avoid self-hits)." << endl;
|
|
181 cerr << "\t\t- By default, same names are allowed." << endl << endl;
|
|
182
|
|
183
|
|
184 cerr << "Refer to the BEDTools manual for BEDPE format." << endl << endl;
|
|
185
|
|
186 // end the program here
|
|
187 exit(1);
|
|
188 }
|