Mercurial > repos > aaronquinlan > multi_intersect
comparison BEDTools-Version-2.14.3/src/shuffleBed/shuffleBedMain.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 shuffleBedMain.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 "shuffleBed.h" | |
13 #include "version.h" | |
14 | |
15 using namespace std; | |
16 | |
17 // define our program name | |
18 #define PROGRAM_NAME "shuffleBed" | |
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 = "stdin"; | |
34 string excludeFile; | |
35 string includeFile; | |
36 string genomeFile; | |
37 | |
38 bool haveBed = true; | |
39 bool haveGenome = false; | |
40 bool haveExclude = false; | |
41 bool haveInclude = false; | |
42 bool haveSeed = false; | |
43 float overlapFraction = 0.0; | |
44 int seed = -1; | |
45 bool sameChrom = false; | |
46 | |
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("-i", 2, parameterLength)) { | |
65 if ((i+1) < argc) { | |
66 bedFile = argv[i + 1]; | |
67 i++; | |
68 } | |
69 } | |
70 else if(PARAMETER_CHECK("-g", 2, parameterLength)) { | |
71 if ((i+1) < argc) { | |
72 haveGenome = true; | |
73 genomeFile = argv[i + 1]; | |
74 i++; | |
75 } | |
76 } | |
77 else if(PARAMETER_CHECK("-excl", 5, parameterLength)) { | |
78 if ((i+1) < argc) { | |
79 haveExclude = true; | |
80 excludeFile = argv[i + 1]; | |
81 i++; | |
82 } | |
83 } | |
84 else if(PARAMETER_CHECK("-incl", 5, parameterLength)) { | |
85 if ((i+1) < argc) { | |
86 haveInclude = true; | |
87 includeFile = argv[i + 1]; | |
88 i++; | |
89 } | |
90 } | |
91 else if(PARAMETER_CHECK("-seed", 5, parameterLength)) { | |
92 if ((i+1) < argc) { | |
93 haveSeed = true; | |
94 seed = atoi(argv[i + 1]); | |
95 i++; | |
96 } | |
97 } | |
98 else if(PARAMETER_CHECK("-chrom", 6, parameterLength)) { | |
99 sameChrom = true; | |
100 } | |
101 else if(PARAMETER_CHECK("-f", 2, parameterLength)) { | |
102 if ((i+1) < argc) { | |
103 overlapFraction = atof(argv[i + 1]); | |
104 i++; | |
105 } | |
106 } | |
107 else { | |
108 cerr << endl << "*****ERROR: Unrecognized parameter: " << argv[i] << " *****" << endl << endl; | |
109 showHelp = true; | |
110 } | |
111 } | |
112 | |
113 // make sure we have both input files | |
114 if (!haveBed || !haveGenome) { | |
115 cerr << endl << "*****" << endl << "*****ERROR: Need both a BED (-i) and a genome (-g) file. " << endl << "*****" << endl; | |
116 showHelp = true; | |
117 } | |
118 | |
119 if (haveInclude && haveExclude) { | |
120 cerr << endl << "*****" << endl << "*****ERROR: Cannot use -incl and -excl together." << endl << "*****" << endl; | |
121 showHelp = true; | |
122 } | |
123 | |
124 if (!showHelp) { | |
125 BedShuffle *bc = new BedShuffle(bedFile, genomeFile, excludeFile, includeFile, | |
126 haveSeed, haveExclude, haveInclude, sameChrom, | |
127 overlapFraction, seed); | |
128 delete bc; | |
129 return 0; | |
130 } | |
131 else { | |
132 ShowHelp(); | |
133 } | |
134 } | |
135 | |
136 void ShowHelp(void) { | |
137 | |
138 cerr << endl << "Program: " << PROGRAM_NAME << " (v" << VERSION << ")" << endl; | |
139 | |
140 cerr << "Author: Aaron Quinlan (aaronquinlan@gmail.com)" << endl; | |
141 | |
142 cerr << "Summary: Randomly permute the locations of a feature file among a genome." << endl << endl; | |
143 | |
144 cerr << "Usage: " << PROGRAM_NAME << " [OPTIONS] -i <bed/gff/vcf> -g <genome>" << endl << endl; | |
145 | |
146 cerr << "Options: " << endl; | |
147 cerr << "\t-excl\t" << "A BED/GFF/VCF file of coordinates in which features in -i" << endl; | |
148 cerr << "\t\tshould not be placed (e.g. gaps.bed)." << endl << endl; | |
149 | |
150 cerr << "\t-incl\t" << "Instead of randomly placing features in a genome, the -incl" << endl; | |
151 cerr << "\t\toptions defines a BED/GFF/VCF file of coordinates in which " << endl; | |
152 cerr << "\t\tfeatures in -i should be randomly placed (e.g. genes.bed). " << endl << endl; | |
153 | |
154 cerr << "\t-chrom\t" << "Keep features in -i on the same chromosome."<< endl; | |
155 cerr << "\t\t- By default, the chrom and position are randomly chosen." << endl << endl; | |
156 | |
157 cerr << "\t-seed\t" << "Supply an integer seed for the shuffling." << endl; | |
158 cerr << "\t\t- By default, the seed is chosen automatically." << endl; | |
159 cerr << "\t\t- (INTEGER)" << endl << endl; | |
160 | |
161 cerr << "\t-f\t" << "Maximum overlap (as a fraction of the -i feature) with an -excl" << endl; | |
162 cerr << "\t\tfeature that is tolerated before searching for a new, " << endl; | |
163 cerr << "\t\trandomized locus. For example, -f 0.10 allows up to 10%" << endl; | |
164 cerr << "\t\tof a randomized feature to overlap with a given feature" << endl; | |
165 cerr << "\t\tin the -excl file. **Cannot be used with -incl file.**" << endl; | |
166 cerr << "\t\t- Default is 1E-9 (i.e., 1bp)." << endl; | |
167 cerr << "\t\t- FLOAT (e.g. 0.50)" << endl << endl; | |
168 | |
169 cerr << "Notes: " << endl; | |
170 cerr << "\t(1) The genome file should tab delimited and structured as follows:" << endl; | |
171 cerr << "\t <chromName><TAB><chromSize>" << endl << endl; | |
172 cerr << "\tFor example, Human (hg19):" << endl; | |
173 cerr << "\tchr1\t249250621" << endl; | |
174 cerr << "\tchr2\t243199373" << endl; | |
175 cerr << "\t..." << endl; | |
176 cerr << "\tchr18_gl000207_random\t4262" << endl << endl; | |
177 | |
178 | |
179 cerr << "Tips: " << endl; | |
180 cerr << "\tOne can use the UCSC Genome Browser's MySQL database to extract" << endl; | |
181 cerr << "\tchromosome sizes. For example, H. sapiens:" << endl << endl; | |
182 cerr << "\tmysql --user=genome --host=genome-mysql.cse.ucsc.edu -A -e \\" << endl; | |
183 cerr << "\t\"select chrom, size from hg19.chromInfo\" > hg19.genome" << endl << endl; | |
184 | |
185 | |
186 // end the program here | |
187 exit(1); | |
188 } |