Mercurial > repos > aaronquinlan > multi_intersect
comparison BEDTools-Version-2.14.3/src/annotateBed/annotateMain.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 annotateMain.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 "annotateBed.h" | |
| 13 #include "version.h" | |
| 14 | |
| 15 using namespace std; | |
| 16 | |
| 17 // define the version | |
| 18 #define PROGRAM_NAME "annotateBed" | |
| 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 int main(int argc, char* argv[]) { | |
| 27 | |
| 28 // our configuration variables | |
| 29 bool showHelp = false; | |
| 30 | |
| 31 // input file | |
| 32 string mainFile; | |
| 33 | |
| 34 // parm flags | |
| 35 bool sameStrand = false; | |
| 36 bool diffStrand = false; | |
| 37 bool haveBed = false; | |
| 38 bool haveFiles = false; | |
| 39 bool haveTitles = false; | |
| 40 bool reportCounts = false; | |
| 41 bool reportBoth = false; | |
| 42 | |
| 43 // list of annotation files / names | |
| 44 vector<string> inputFiles; | |
| 45 vector<string> inputTitles; | |
| 46 | |
| 47 // check to see if we should print out some help | |
| 48 if(argc <= 1) showHelp = true; | |
| 49 | |
| 50 for(int i = 1; i < argc; i++) { | |
| 51 int parameterLength = (int)strlen(argv[i]); | |
| 52 | |
| 53 if((PARAMETER_CHECK("-h", 2, parameterLength)) || | |
| 54 (PARAMETER_CHECK("--help", 5, parameterLength))) { | |
| 55 showHelp = true; | |
| 56 } | |
| 57 } | |
| 58 | |
| 59 if(showHelp) ShowHelp(); | |
| 60 | |
| 61 // do some parsing (all of these parameters require 2 strings) | |
| 62 for(int i = 1; i < argc; i++) { | |
| 63 | |
| 64 int parameterLength = (int)strlen(argv[i]); | |
| 65 | |
| 66 if(PARAMETER_CHECK("-i", 2, parameterLength)) { | |
| 67 if ((i+1) < argc) { | |
| 68 haveBed = true; | |
| 69 mainFile = argv[i + 1]; | |
| 70 i++; | |
| 71 } | |
| 72 } | |
| 73 else if(PARAMETER_CHECK("-files", 6, parameterLength)) { | |
| 74 if ((i+1) < argc) { | |
| 75 haveFiles = true; | |
| 76 i = i+1; | |
| 77 string file = argv[i]; | |
| 78 while (file[0] != '-' && i < argc) { | |
| 79 inputFiles.push_back(file); | |
| 80 i++; | |
| 81 if (i < argc) | |
| 82 file = argv[i]; | |
| 83 } | |
| 84 i--; | |
| 85 } | |
| 86 } | |
| 87 else if(PARAMETER_CHECK("-names", 6, parameterLength)) { | |
| 88 if ((i+1) < argc) { | |
| 89 haveTitles = true; | |
| 90 i = i+1; | |
| 91 string title = argv[i]; | |
| 92 while (title[0] != '-' && i < argc) { | |
| 93 inputTitles.push_back(title); | |
| 94 i++; | |
| 95 if (i < argc) | |
| 96 title = argv[i]; | |
| 97 } | |
| 98 i--; | |
| 99 } | |
| 100 } | |
| 101 else if(PARAMETER_CHECK("-counts", 7, parameterLength)) { | |
| 102 reportCounts = true; | |
| 103 } | |
| 104 else if(PARAMETER_CHECK("-both", 5, parameterLength)) { | |
| 105 reportBoth = true; | |
| 106 } | |
| 107 else if (PARAMETER_CHECK("-s", 2, parameterLength)) { | |
| 108 sameStrand = true; | |
| 109 } | |
| 110 else if (PARAMETER_CHECK("-S", 2, parameterLength)) { | |
| 111 diffStrand = true; | |
| 112 } | |
| 113 else { | |
| 114 cerr << endl << "*****ERROR: Unrecognized parameter: " << argv[i] << " *****" << endl << endl; | |
| 115 showHelp = true; | |
| 116 } | |
| 117 } | |
| 118 | |
| 119 // make sure we have both input files | |
| 120 if (!haveBed || !haveFiles) { | |
| 121 cerr << endl << "*****" << endl << "*****ERROR: Need -i and -files files. " << endl << "*****" << endl; | |
| 122 showHelp = true; | |
| 123 } | |
| 124 if (sameStrand && diffStrand) { | |
| 125 cerr << endl << "*****" << endl << "*****ERROR: Request either -s OR -S, not both." << endl << "*****" << endl; | |
| 126 showHelp = true; | |
| 127 } | |
| 128 | |
| 129 if (!showHelp) { | |
| 130 BedAnnotate *ba = new BedAnnotate(mainFile, inputFiles, inputTitles, sameStrand, diffStrand, reportCounts, reportBoth); | |
| 131 ba->AnnotateBed(); | |
| 132 delete ba; | |
| 133 return 0; | |
| 134 } | |
| 135 else { | |
| 136 ShowHelp(); | |
| 137 } | |
| 138 } | |
| 139 | |
| 140 void ShowHelp(void) { | |
| 141 | |
| 142 cerr << endl << "Program: " << PROGRAM_NAME << " (v" << VERSION << ")" << endl; | |
| 143 | |
| 144 cerr << "Author: Aaron Quinlan (aaronquinlan@gmail.com)" << endl; | |
| 145 | |
| 146 cerr << "Summary: Annotates the depth & breadth of coverage of features from multiple files" << endl; | |
| 147 cerr << "\t on the intervals in -i." << endl << endl; | |
| 148 | |
| 149 cerr << "Usage: " << PROGRAM_NAME << " [OPTIONS] -i <bed/gff/vcf> -files FILE1 FILE2 .. FILEn" << endl << endl; | |
| 150 | |
| 151 cerr << "Options: " << endl; | |
| 152 | |
| 153 cerr << "\t-names\t" << "A list of names (one / file) to describe each file in -i." << endl; | |
| 154 cerr << "\t\tThese names will be printed as a header line." << endl << endl; | |
| 155 | |
| 156 cerr << "\t-counts\t" << "Report the count of features in each file that overlap -i." << endl; | |
| 157 cerr << "\t\t- Default is to report the fraction of -i covered by each file." << endl << endl; | |
| 158 | |
| 159 cerr << "\t-both\t" << "Report the counts followed by the % coverage." << endl; | |
| 160 cerr << "\t\t- Default is to report the fraction of -i covered by each file." << endl << endl; | |
| 161 | |
| 162 cerr << "\t-s\t" << "Require same strandedness. That is, only counts overlaps" << endl; | |
| 163 cerr << "\t\ton the _same_ strand." << endl; | |
| 164 cerr << "\t\t- By default, overlaps are counted without respect to strand." << endl << endl; | |
| 165 | |
| 166 cerr << "\t-S\t" << "Require different strandedness. That is, only count overlaps" << endl; | |
| 167 cerr << "\t\ton the _opposite_ strand." << endl; | |
| 168 cerr << "\t\t- By default, overlaps are counted without respect to strand." << endl << endl; | |
| 169 exit(1); | |
| 170 } |
