Mercurial > repos > aaronquinlan > multi_intersect
comparison BEDTools-Version-2.14.3/src/nucBed/nucBedMain.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 nucBedMain.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 "nucBed.h" | |
| 13 #include "version.h" | |
| 14 | |
| 15 using namespace std; | |
| 16 | |
| 17 // define our program name | |
| 18 #define PROGRAM_NAME "nucBed" | |
| 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 fastaDbFile; | |
| 34 string bedFile; | |
| 35 string pattern; | |
| 36 | |
| 37 // checks for existence of parameters | |
| 38 bool haveFastaDb = false; | |
| 39 bool haveBed = false; | |
| 40 bool printSeq = false; | |
| 41 bool hasPattern = false; | |
| 42 bool forceStrand = false; | |
| 43 | |
| 44 // check to see if we should print out some help | |
| 45 if(argc <= 1) showHelp = true; | |
| 46 | |
| 47 for(int i = 1; i < argc; i++) { | |
| 48 int parameterLength = (int)strlen(argv[i]); | |
| 49 | |
| 50 if((PARAMETER_CHECK("-h", 2, parameterLength)) || | |
| 51 (PARAMETER_CHECK("--help", 5, parameterLength))) { | |
| 52 showHelp = true; | |
| 53 } | |
| 54 } | |
| 55 | |
| 56 if(showHelp) ShowHelp(); | |
| 57 | |
| 58 // do some parsing (all of these parameters require 2 strings) | |
| 59 for(int i = 1; i < argc; i++) { | |
| 60 | |
| 61 int parameterLength = (int)strlen(argv[i]); | |
| 62 | |
| 63 if(PARAMETER_CHECK("-fi", 3, parameterLength)) { | |
| 64 if ((i+1) < argc) { | |
| 65 haveFastaDb = true; | |
| 66 fastaDbFile = argv[i + 1]; | |
| 67 i++; | |
| 68 } | |
| 69 } | |
| 70 else if(PARAMETER_CHECK("-bed", 4, parameterLength)) { | |
| 71 if ((i+1) < argc) { | |
| 72 haveBed = true; | |
| 73 bedFile = argv[i + 1]; | |
| 74 i++; | |
| 75 } | |
| 76 } | |
| 77 else if(PARAMETER_CHECK("-seq", 4, parameterLength)) { | |
| 78 printSeq = true; | |
| 79 } | |
| 80 else if(PARAMETER_CHECK("-s", 2, parameterLength)) { | |
| 81 forceStrand = true; | |
| 82 } | |
| 83 else if(PARAMETER_CHECK("-pattern", 8, parameterLength)) { | |
| 84 if ((i+1) < argc) { | |
| 85 hasPattern = true; | |
| 86 pattern = argv[i + 1]; | |
| 87 i++; | |
| 88 } | |
| 89 } | |
| 90 else { | |
| 91 cerr << "*****ERROR: Unrecognized parameter: " << argv[i] << " *****" << endl << endl; | |
| 92 showHelp = true; | |
| 93 } | |
| 94 } | |
| 95 | |
| 96 if (!haveFastaDb || !haveBed) { | |
| 97 showHelp = true; | |
| 98 } | |
| 99 | |
| 100 if (!showHelp) { | |
| 101 | |
| 102 NucBed *nuc = new NucBed(fastaDbFile, bedFile, printSeq, hasPattern, pattern, forceStrand); | |
| 103 delete nuc; | |
| 104 | |
| 105 return 0; | |
| 106 } | |
| 107 else { | |
| 108 ShowHelp(); | |
| 109 } | |
| 110 } | |
| 111 | |
| 112 void ShowHelp(void) { | |
| 113 | |
| 114 cerr << endl << "Program: " << PROGRAM_NAME << " (v" << VERSION << ")" << endl; | |
| 115 | |
| 116 cerr << "Author: Aaron Quinlan (aaronquinlan@gmail.com)" << endl; | |
| 117 | |
| 118 cerr << "Summary: Profiles the nucleotide content of intervals in a fasta file." << endl << endl; | |
| 119 | |
| 120 cerr << "Usage: " << PROGRAM_NAME << " [OPTIONS] -fi <fasta> -bed <bed/gff/vcf>" << endl << endl; | |
| 121 | |
| 122 cerr << "Options: " << endl; | |
| 123 cerr << "\t-fi\tInput FASTA file" << endl << endl; | |
| 124 cerr << "\t-bed\tBED/GFF/VCF file of ranges to extract from -fi" << endl << endl; | |
| 125 cerr << "\t-s\tProfile the sequence according to strand." << endl << endl; | |
| 126 cerr << "\t-seq\tPrint the extracted sequence" << endl << endl; | |
| 127 cerr << "\t-pattern\tReport the number of times a user-defined sequence is observed (case-insensitive)." << endl << endl; | |
| 128 | |
| 129 | |
| 130 cerr << "Output format: " << endl; | |
| 131 cerr << "\tThe following information will be reported after each original BED entry:" << endl; | |
| 132 cerr << "\t 1) %AT content" << endl; | |
| 133 cerr << "\t 2) %GC content" << endl; | |
| 134 cerr << "\t 3) Number of As observed" << endl; | |
| 135 cerr << "\t 4) Number of Cs observed" << endl; | |
| 136 cerr << "\t 5) Number of Gs observed" << endl; | |
| 137 cerr << "\t 6) Number of Ts observed" << endl; | |
| 138 cerr << "\t 7) Number of Ns observed" << endl; | |
| 139 cerr << "\t 8) Number of other bases observed" << endl; | |
| 140 cerr << "\t 9) The length of the explored sequence/interval." << endl; | |
| 141 cerr << "\t 10) The sequence extracted from the FASTA file. (optional, if -seq is used)" << endl; | |
| 142 cerr << "\t 11) The number of times a user defined pattern was observed. (optional, if -pattern is used.)" << endl; | |
| 143 | |
| 144 // end the program here | |
| 145 exit(1); | |
| 146 | |
| 147 } |
