0
|
1 /*****************************************************************************
|
|
2 linksBedMain.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 "linksBed.h"
|
|
13 #include "version.h"
|
|
14
|
|
15 using namespace std;
|
|
16
|
|
17 // define our program name
|
|
18 #define PROGRAM_NAME "linksBed"
|
|
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 bool haveBed = true;
|
|
35
|
|
36 /* Defaults for everyone else */
|
|
37 string org = "human";
|
|
38 string db = "hg18";
|
|
39 string base = "http://genome.ucsc.edu";
|
|
40
|
|
41 for(int i = 1; i < argc; i++) {
|
|
42 int parameterLength = (int)strlen(argv[i]);
|
|
43
|
|
44 if((PARAMETER_CHECK("-h", 2, parameterLength)) ||
|
|
45 (PARAMETER_CHECK("--help", 5, parameterLength))) {
|
|
46 showHelp = true;
|
|
47 }
|
|
48 }
|
|
49
|
|
50 if(showHelp) ShowHelp();
|
|
51
|
|
52 // do some parsing (all of these parameters require 2 strings)
|
|
53 for(int i = 1; i < argc; i++) {
|
|
54
|
|
55 int parameterLength = (int)strlen(argv[i]);
|
|
56
|
|
57 if(PARAMETER_CHECK("-i", 2, parameterLength)) {
|
|
58 if ((i+1) < argc) {
|
|
59 bedFile = argv[i + 1];
|
|
60 i++;
|
|
61 }
|
|
62 }
|
|
63 else if(PARAMETER_CHECK("-base", 5, parameterLength)) {
|
|
64 if ((i+1) < argc) {
|
|
65 base = argv[i + 1];
|
|
66 i++;
|
|
67 }
|
|
68 }
|
|
69 else if(PARAMETER_CHECK("-org", 4, parameterLength)) {
|
|
70 if ((i+1) < argc) {
|
|
71 org = argv[i + 1];
|
|
72 i++;
|
|
73 }
|
|
74 }
|
|
75 else if(PARAMETER_CHECK("-db", 3, parameterLength)) {
|
|
76 if ((i+1) < argc) {
|
|
77 db = argv[i + 1];
|
|
78 i++;
|
|
79 }
|
|
80 }
|
|
81 else {
|
|
82 cerr << endl << "*****ERROR: Unrecognized parameter: " << argv[i] << " *****" << endl << endl;
|
|
83 showHelp = true;
|
|
84 }
|
|
85 }
|
|
86
|
|
87 // make sure we have both input files
|
|
88 if (!haveBed) {
|
|
89 cerr << endl << "*****" << endl << "*****ERROR: Need -i BED file. " << endl << "*****" << endl;
|
|
90 showHelp = true;
|
|
91 }
|
|
92
|
|
93 if (!showHelp) {
|
|
94 BedLinks *bl = new BedLinks(bedFile, base, org, db);
|
|
95 delete bl;
|
|
96 return 0;
|
|
97 }
|
|
98 else {
|
|
99 ShowHelp();
|
|
100 }
|
|
101 }
|
|
102
|
|
103 void ShowHelp(void) {
|
|
104
|
|
105 cerr << endl << "Program: " << PROGRAM_NAME << " (v" << VERSION << ")" << endl;
|
|
106
|
|
107 cerr << "Author: Aaron Quinlan (aaronquinlan@gmail.com)" << endl;
|
|
108
|
|
109 cerr << "Summary: Creates HTML links to an UCSC Genome Browser from a feature file." << endl << endl;
|
|
110 cerr << "Usage: " << PROGRAM_NAME << " [OPTIONS] -i <bed/gff/vcf> > out.html" << endl << endl;
|
|
111
|
|
112 cerr << "Options: " << endl;
|
|
113 cerr << "\t-base\t" << "The browser basename. Default: http://genome.ucsc.edu " << endl;
|
|
114 cerr << "\t-org\t" << "The organism. Default: human" << endl;
|
|
115 cerr << "\t-db\t" << "The build. Default: hg18" << endl << endl;
|
|
116
|
|
117 cerr << "Example: " << endl;
|
|
118 cerr << "\t" << "By default, the links created will point to human (hg18) UCSC browser." << endl;
|
|
119 cerr << "\tIf you have a local mirror, you can override this behavior by supplying" << endl;
|
|
120 cerr << "\tthe -base, -org, and -db options." << endl << endl;
|
|
121 cerr << "\t" << "For example, if the URL of your local mirror for mouse MM9 is called: " << endl;
|
|
122 cerr << "\thttp://mymirror.myuniversity.edu, then you would use the following:" << endl;
|
|
123 cerr << "\t" << "-base http://mymirror.myuniversity.edu" << endl;
|
|
124 cerr << "\t" << "-org mouse" << endl;
|
|
125 cerr << "\t" << "-db mm9" << endl;
|
|
126
|
|
127
|
|
128 exit(1);
|
|
129 }
|