Mercurial > repos > aaronquinlan > multi_intersect
comparison BEDTools-Version-2.14.3/src/windowBed/windowMain.cpp @ 1:bec36315bd12 default tip
Deleted selected files
| author | aaronquinlan |
|---|---|
| date | Sat, 19 Nov 2011 14:17:03 -0500 |
| parents | dfcd8b6c1bda |
| children |
comparison
equal
deleted
inserted
replaced
| 0:dfcd8b6c1bda | 1:bec36315bd12 |
|---|---|
| 1 /***************************************************************************** | |
| 2 windowMain.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 "windowBed.h" | |
| 13 #include "version.h" | |
| 14 | |
| 15 using namespace std; | |
| 16 | |
| 17 // define the version | |
| 18 #define PROGRAM_NAME "windowBed" | |
| 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 | |
| 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 int leftSlop = 1000; | |
| 38 int rightSlop = 1000; | |
| 39 | |
| 40 bool haveBedA = false; | |
| 41 bool haveBedB = false; | |
| 42 bool noHit = false; | |
| 43 bool anyHit = false; | |
| 44 bool writeCount = false; | |
| 45 bool haveSlop = false; | |
| 46 bool haveLeft = false; | |
| 47 bool haveRight = false; | |
| 48 bool strandWindows = false; | |
| 49 bool matchOnSameStrand = false; | |
| 50 bool matchOnDiffStrand = false; | |
| 51 bool inputIsBam = false; | |
| 52 bool outputIsBam = true; | |
| 53 bool uncompressedBam = false; | |
| 54 | |
| 55 // check to see if we should print out some help | |
| 56 if(argc <= 1) showHelp = true; | |
| 57 | |
| 58 for(int i = 1; i < argc; i++) { | |
| 59 int parameterLength = (int)strlen(argv[i]); | |
| 60 | |
| 61 if((PARAMETER_CHECK("-h", 2, parameterLength)) || | |
| 62 (PARAMETER_CHECK("--help", 5, parameterLength))) { | |
| 63 showHelp = true; | |
| 64 } | |
| 65 } | |
| 66 | |
| 67 if(showHelp) ShowHelp(); | |
| 68 | |
| 69 // do some parsing (all of these parameters require 2 strings) | |
| 70 for(int i = 1; i < argc; i++) { | |
| 71 | |
| 72 int parameterLength = (int)strlen(argv[i]); | |
| 73 | |
| 74 if(PARAMETER_CHECK("-a", 2, parameterLength)) { | |
| 75 if ((i+1) < argc) { | |
| 76 haveBedA = true; | |
| 77 bedAFile = argv[i + 1]; | |
| 78 i++; | |
| 79 } | |
| 80 } | |
| 81 else if(PARAMETER_CHECK("-abam", 5, parameterLength)) { | |
| 82 if ((i+1) < argc) { | |
| 83 haveBedA = true; | |
| 84 inputIsBam = true; | |
| 85 bedAFile = argv[i + 1]; | |
| 86 i++; | |
| 87 } | |
| 88 } | |
| 89 else if(PARAMETER_CHECK("-b", 2, parameterLength)) { | |
| 90 if ((i+1) < argc) { | |
| 91 haveBedB = true; | |
| 92 bedBFile = argv[i + 1]; | |
| 93 i++; | |
| 94 } | |
| 95 } | |
| 96 else if(PARAMETER_CHECK("-bed", 4, parameterLength)) { | |
| 97 outputIsBam = false; | |
| 98 } | |
| 99 else if(PARAMETER_CHECK("-u", 2, parameterLength)) { | |
| 100 anyHit = true; | |
| 101 } | |
| 102 else if(PARAMETER_CHECK("-c", 2, parameterLength)) { | |
| 103 writeCount = true; | |
| 104 } | |
| 105 else if (PARAMETER_CHECK("-v", 2, parameterLength)) { | |
| 106 noHit = true; | |
| 107 } | |
| 108 else if (PARAMETER_CHECK("-sw", 3, parameterLength)) { | |
| 109 strandWindows = true; | |
| 110 } | |
| 111 else if (PARAMETER_CHECK("-sm", 3, parameterLength)) { | |
| 112 matchOnSameStrand = true; | |
| 113 } | |
| 114 else if (PARAMETER_CHECK("-Sm", 3, parameterLength)) { | |
| 115 matchOnDiffStrand = true; | |
| 116 } | |
| 117 else if (PARAMETER_CHECK("-w", 2, parameterLength)) { | |
| 118 if ((i+1) < argc) { | |
| 119 haveSlop = true; | |
| 120 leftSlop = atoi(argv[i + 1]); | |
| 121 rightSlop = leftSlop; | |
| 122 i++; | |
| 123 } | |
| 124 } | |
| 125 else if (PARAMETER_CHECK("-l", 2, parameterLength)) { | |
| 126 if ((i+1) < argc) { | |
| 127 haveLeft = true; | |
| 128 leftSlop = atoi(argv[i + 1]); | |
| 129 i++; | |
| 130 } | |
| 131 } | |
| 132 else if (PARAMETER_CHECK("-r", 2, parameterLength)) { | |
| 133 if ((i+1) < argc) { | |
| 134 haveRight = true; | |
| 135 rightSlop = atoi(argv[i + 1]); | |
| 136 i++; | |
| 137 } | |
| 138 } | |
| 139 else if(PARAMETER_CHECK("-ubam", 5, parameterLength)) { | |
| 140 uncompressedBam = true; | |
| 141 } | |
| 142 else { | |
| 143 cerr << endl << "*****ERROR: Unrecognized parameter: " << argv[i] << " *****" << endl << endl; | |
| 144 showHelp = true; | |
| 145 } | |
| 146 } | |
| 147 | |
| 148 // make sure we have both input files | |
| 149 if (!haveBedA || !haveBedB) { | |
| 150 cerr << endl << "*****" << endl << "*****ERROR: Need -a and -b files. " << endl << "*****" << endl; | |
| 151 showHelp = true; | |
| 152 } | |
| 153 | |
| 154 if (anyHit && noHit) { | |
| 155 cerr << endl << "*****" << endl << "*****ERROR: Request either -u OR -v, not both." << endl << "*****" << endl; | |
| 156 showHelp = true; | |
| 157 } | |
| 158 | |
| 159 if (anyHit && writeCount) { | |
| 160 cerr << endl << "*****" << endl << "*****ERROR: Request either -u OR -c, not both." << endl << "*****" << endl; | |
| 161 showHelp = true; | |
| 162 } | |
| 163 | |
| 164 if (haveLeft && (leftSlop < 0)) { | |
| 165 cerr << endl << "*****" << endl << "*****ERROR: Upstream window (-l) must be positive." << endl << "*****" << endl; | |
| 166 showHelp = true; | |
| 167 } | |
| 168 | |
| 169 if (haveRight && (rightSlop < 0)) { | |
| 170 cerr << endl << "*****" << endl << "*****ERROR: Downstream window (-r) must be positive." << endl << "*****" << endl; | |
| 171 showHelp = true; | |
| 172 } | |
| 173 | |
| 174 if (haveSlop && (haveLeft || haveRight)) { | |
| 175 cerr << endl << "*****" << endl << "*****ERROR: Cannot choose -w with -l or -r. Either specify -l and -r or specify solely -w" << endl << "*****" << endl; | |
| 176 showHelp = true; | |
| 177 } | |
| 178 | |
| 179 if ((haveLeft && !haveRight) || (haveRight && !haveLeft)) { | |
| 180 cerr << endl << "*****" << endl << "*****ERROR: Please specify both -l and -r." << endl << "*****" << endl; | |
| 181 showHelp = true; | |
| 182 } | |
| 183 | |
| 184 if (matchOnSameStrand && matchOnDiffStrand) { | |
| 185 cerr << endl << "*****" << endl << "*****ERROR: Use either -sm or -Sm, not both." << endl << "*****" << endl; | |
| 186 showHelp = true; | |
| 187 } | |
| 188 | |
| 189 if (!showHelp) { | |
| 190 BedWindow *bi = new BedWindow(bedAFile, bedBFile, leftSlop, rightSlop, anyHit, | |
| 191 noHit, writeCount, strandWindows, matchOnSameStrand, matchOnDiffStrand, | |
| 192 inputIsBam, outputIsBam, uncompressedBam); | |
| 193 delete bi; | |
| 194 return 0; | |
| 195 } | |
| 196 else { | |
| 197 ShowHelp(); | |
| 198 } | |
| 199 } | |
| 200 | |
| 201 | |
| 202 void ShowHelp(void) { | |
| 203 | |
| 204 cerr << endl << "Program: " << PROGRAM_NAME << " (v" << VERSION << ")" << endl; | |
| 205 | |
| 206 cerr << "Author: Aaron Quinlan (aaronquinlan@gmail.com)" << endl; | |
| 207 | |
| 208 cerr << "Summary: Examines a \"window\" around each feature in A and" << endl; | |
| 209 cerr << "\t reports all features in B that overlap the window. For each" << endl; | |
| 210 cerr << "\t overlap the entire entry in A and B are reported." << endl << endl; | |
| 211 | |
| 212 cerr << "Usage: " << PROGRAM_NAME << " [OPTIONS] -a <bed/gff/vcf> -b <bed/gff/vcf>" << endl << endl; | |
| 213 | |
| 214 cerr << "Options: " << endl; | |
| 215 | |
| 216 cerr << "\t-abam\t" << "The A input file is in BAM format. Output will be BAM as well." << endl << endl; | |
| 217 | |
| 218 cerr << "\t-ubam\t" << "Write uncompressed BAM output. Default is to write compressed BAM." << endl << endl; | |
| 219 | |
| 220 cerr << "\t-bed\t" << "When using BAM input (-abam), write output as BED. The default" << endl; | |
| 221 cerr << "\t\tis to write output in BAM when using -abam." << endl << endl; | |
| 222 | |
| 223 cerr << "\t-w\t" << "Base pairs added upstream and downstream of each entry" << endl; | |
| 224 cerr << "\t\tin A when searching for overlaps in B." << endl; | |
| 225 cerr << "\t\t- Creates symterical \"windows\" around A." << endl; | |
| 226 cerr << "\t\t- Default is 1000 bp." << endl; | |
| 227 cerr << "\t\t- (INTEGER)" << endl << endl; | |
| 228 | |
| 229 cerr << "\t-l\t" << "Base pairs added upstream (left of) of each entry" << endl; | |
| 230 cerr << "\t\tin A when searching for overlaps in B." << endl; | |
| 231 cerr << "\t\t- Allows one to define assymterical \"windows\"." << endl; | |
| 232 cerr << "\t\t- Default is 1000 bp." << endl; | |
| 233 cerr << "\t\t- (INTEGER)" << endl << endl; | |
| 234 | |
| 235 cerr << "\t-r\t" << "Base pairs added downstream (right of) of each entry" << endl; | |
| 236 cerr << "\t\tin A when searching for overlaps in B." << endl; | |
| 237 cerr << "\t\t- Allows one to define assymterical \"windows\"." << endl; | |
| 238 cerr << "\t\t- Default is 1000 bp." << endl; | |
| 239 cerr << "\t\t- (INTEGER)" << endl << endl; | |
| 240 | |
| 241 cerr << "\t-sw\t" << "Define -l and -r based on strand. For example if used, -l 500" << endl; | |
| 242 cerr << "\t\tfor a negative-stranded feature will add 500 bp downstream." << endl; | |
| 243 cerr << "\t\t- Default = disabled." << endl << endl; | |
| 244 | |
| 245 cerr << "\t-sm\t" << "Only report hits in B that overlap A on the _same_ strand." << endl; | |
| 246 cerr << "\t\t- By default, overlaps are reported without respect to strand." << endl << endl; | |
| 247 | |
| 248 cerr << "\t-Sm\t" << "Only report hits in B that overlap A on the _opposite_ strand." << endl; | |
| 249 cerr << "\t\t- By default, overlaps are reported without respect to strand." << endl << endl; | |
| 250 | |
| 251 cerr << "\t-u\t" << "Write the original A entry _once_ if _any_ overlaps found in B." << endl; | |
| 252 cerr << "\t\t- In other words, just report the fact >=1 hit was found." << endl << endl; | |
| 253 | |
| 254 cerr << "\t-c\t" << "For each entry in A, report the number of overlaps with B." << endl; | |
| 255 cerr << "\t\t- Reports 0 for A entries that have no overlap with B." << endl; | |
| 256 cerr << "\t\t- Overlaps restricted by -f." << endl << endl; | |
| 257 | |
| 258 cerr << "\t-v\t" << "Only report those entries in A that have _no overlaps_ with B." << endl; | |
| 259 cerr << "\t\t- Similar to \"grep -v.\"" << endl << endl; | |
| 260 | |
| 261 // end the program here | |
| 262 exit(1); | |
| 263 } |
