complementMain.cpp 3.48 KB
Newer Older
Aaron's avatar
Aaron committed
1
2
3
4
5
6
7
8
9
/*****************************************************************************
  complementBedMain.cpp

  (c) 2009 - Aaron Quinlan
  Hall Laboratory
  Department of Biochemistry and Molecular Genetics
  University of Virginia
  aaronquinlan@gmail.com

Aaron's avatar
Aaron committed
10
  Licenced under the GNU General Public License 2.0 license.
Aaron's avatar
Aaron committed
11
******************************************************************************/
Aaron Quinlan's avatar
Aaron Quinlan committed
12
#include "complementBed.h"
Aaron's avatar
Aaron committed
13
#include "version.h"
Aaron Quinlan's avatar
Aaron Quinlan committed
14
15
16
17

using namespace std;

// define our program name
Aaron's avatar
Aaron committed
18
#define PROGRAM_NAME "bedtools complement"
Aaron Quinlan's avatar
Aaron Quinlan committed
19
20
21
22
23
24


// define our parameter checking macro
#define PARAMETER_CHECK(param, paramLen, actualLen) (strncmp(argv[i], param, min(actualLen, paramLen))== 0) && (actualLen == paramLen)

// function declarations
Aaron's avatar
Aaron committed
25
void complement_help(void);
Aaron Quinlan's avatar
Aaron Quinlan committed
26

Aaron's avatar
Aaron committed
27
int complement_main(int argc, char* argv[]) {
Aaron Quinlan's avatar
Aaron Quinlan committed
28

29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
    // our configuration variables
    bool showHelp = false;

    // input files
    string bedFile = "stdin";
    string genomeFile;

    bool haveBed = true;
    bool haveGenome = false;

    for(int i = 1; i < argc; i++) {
        int parameterLength = (int)strlen(argv[i]);

        if((PARAMETER_CHECK("-h", 2, parameterLength)) ||
        (PARAMETER_CHECK("--help", 5, parameterLength))) {
            showHelp = true;
        }
    }

Aaron's avatar
Aaron committed
48
    if(showHelp) complement_help();
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75

    // do some parsing (all of these parameters require 2 strings)
    for(int i = 1; i < argc; i++) {

        int parameterLength = (int)strlen(argv[i]);

        if(PARAMETER_CHECK("-i", 2, parameterLength)) {
            if ((i+1) < argc) {
                bedFile = argv[i + 1];
                i++;
            }
        }
        else if(PARAMETER_CHECK("-g", 2, parameterLength)) {
            if ((i+1) < argc) {
                haveGenome = true;
                genomeFile = argv[i + 1];
                i++;
            }
        }
        else {
          cerr << endl << "*****ERROR: Unrecognized parameter: " << argv[i] << " *****" << endl << endl;
            showHelp = true;
        }
    }

    // make sure we have both input files
    if (!haveBed || !haveGenome) {
Aaron's avatar
Aaron committed
76
      cerr << endl << "*****" << endl << "*****ERROR: Need -i BED file and -g genome file. " << endl << "*****" << endl;
77
78
79
80
81
82
83
      showHelp = true;
    }
    if (!showHelp) {
        BedComplement *bc = new BedComplement(bedFile, genomeFile);
        bc->ComplementBed();
    }
    else {
Aaron's avatar
Aaron committed
84
        complement_help();
85
    }
Aaron's avatar
Aaron committed
86
    return 0;
Aaron Quinlan's avatar
Aaron Quinlan committed
87
88
}

Aaron's avatar
Aaron committed
89
void complement_help(void) {
90

Aaron's avatar
Aaron committed
91
    cerr << "\nTool:    bedtools complement (aka complementBed)" << endl;
Aaron's avatar
Aaron committed
92
    cerr << "Version: " << VERSION << "\n";    
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
    cerr << "Summary: Returns the base pair complement of a feature file." << endl << endl;

    cerr << "Usage:   " << PROGRAM_NAME << " [OPTIONS] -i <bed/gff/vcf> -g <genome>" << endl << endl;

    cerr << "Notes: " << endl;
    cerr << "\t(1)  The genome file should tab delimited and structured as follows:" << endl;
    cerr << "\t     <chromName><TAB><chromSize>" << endl << endl;
    cerr << "\tFor example, Human (hg19):" << endl;
    cerr << "\tchr1\t249250621" << endl;
    cerr << "\tchr2\t243199373" << endl;
    cerr << "\t..." << endl;
    cerr << "\tchr18_gl000207_random\t4262" << endl << endl;

    cerr << "Tips: " << endl;
    cerr << "\tOne can use the UCSC Genome Browser's MySQL database to extract" << endl;
    cerr << "\tchromosome sizes. For example, H. sapiens:" << endl << endl;
Aaron's avatar
Aaron committed
109
    cerr << "\tmysql --user=genome --host=genome-mysql.cse.ucsc.edu -A -e \\" << endl;
110
111
112
113
    cerr << "\t\"select chrom, size from hg19.chromInfo\"  > hg19.genome" << endl << endl;

    exit(1);

Aaron Quinlan's avatar
Aaron Quinlan committed
114
}