1
/*****************************************************************************
4
(c) 2009 - Aaron Quinlan
6
Department of Biochemistry and Molecular Genetics
10
Licenced under the GNU General Public License 2.0 license.
11
******************************************************************************/
17
// define our program name
18
#define PROGRAM_NAME "bedtools jaccard"
21
// define our parameter checking macro
22
#define PARAMETER_CHECK(param, paramLen, actualLen) (strncmp(argv[i], param, min(actualLen, paramLen))== 0) && (actualLen == paramLen)
24
// function declarations
25
void jaccard_help(void);
27
int jaccard_main(int argc, char* argv[]) {
29
// our configuration variables
30
bool showHelp = false;
37
float overlapFraction = 1E-9;
39
bool haveBedA = false;
40
bool haveBedB = false;
41
bool haveFraction = false;
42
bool reciprocalFraction = false;
44
// check to see if we should print out some help
45
if(argc <= 1) showHelp = true;
47
for(int i = 1; i < argc; i++) {
48
int parameterLength = (int)strlen(argv[i]);
50
if((PARAMETER_CHECK("-h", 2, parameterLength)) ||
51
(PARAMETER_CHECK("--help", 5, parameterLength))) {
56
if(showHelp) jaccard_help();
58
// do some parsing (all of these parameters require 2 strings)
59
for(int i = 1; i < argc; i++) {
61
int parameterLength = (int)strlen(argv[i]);
63
if(PARAMETER_CHECK("-a", 2, parameterLength)) {
66
bedAFile = argv[i + 1];
70
else if(PARAMETER_CHECK("-b", 2, parameterLength)) {
73
bedBFile = argv[i + 1];
77
else if(PARAMETER_CHECK("-f", 2, parameterLength)) {
80
overlapFraction = atof(argv[i + 1]);
84
else if(PARAMETER_CHECK("-r", 2, parameterLength)) {
85
reciprocalFraction = true;
89
<< "*****ERROR: Unrecognized parameter: "
97
// make sure we have both input files
98
if (!haveBedA || !haveBedB) {
99
cerr << endl << "*****" << endl << "*****ERROR: Need -a and -b files. " << endl << "*****" << endl;
103
if (reciprocalFraction && !haveFraction) {
104
cerr << endl << "*****" << endl << "*****ERROR: If using -r, you need to define -f." << endl << "*****" << endl;
110
Jaccard *j = new Jaccard(bedAFile, bedBFile,
111
overlapFraction, reciprocalFraction);
121
void jaccard_help(void) {
123
cerr << "\nTool: bedtools jaccard (aka jaccard)" << endl;
124
cerr << "Version: " << VERSION << "\n";
125
cerr << "Summary: Calculate Jaccard statistic b/w two feature files."
127
<< "\t Jaccard is the length of the intersection over the union."
129
<< "\t Values range from 0 (no intersection) to 1 (self intersection)."
132
cerr << "Usage: " << PROGRAM_NAME << " [OPTIONS] -a <bed/gff/vcf> -b <bed/gff/vcf>" << endl << endl;
134
cerr << "Options: " << endl;
137
cerr << "\t-f\t" << "Minimum overlap required as a fraction of A." << endl;
138
cerr << "\t\t- Default is 1E-9 (i.e., 1bp)." << endl;
139
cerr << "\t\t- FLOAT (e.g. 0.50)" << endl << endl;
141
cerr << "\t-r\t" << "Require that the fraction overlap be reciprocal for A and B." << endl;
142
cerr << "\t\t- In other words, if -f is 0.90 and -r is used, this requires" << endl;
143
cerr << "\t\t that B overlap 90% of A and A _also_ overlaps 90% of B." << endl << endl;
145
cerr << "Notes: " << endl;
146
cerr << "\t(1) Input files must be sorted by chrom, then start position."
149
// end the program here