Mercurial > repos > aaronquinlan > multi_intersect
comparison BEDTools-Version-2.14.3/src/fastaFromBed/fastaFromBedMain.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 fastaFromBedMain.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 "fastaFromBed.h" | |
13 #include "version.h" | |
14 | |
15 using namespace std; | |
16 | |
17 // define our program name | |
18 #define PROGRAM_NAME "fastaFromBed" | |
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 | |
36 // output files | |
37 string fastaOutFile; | |
38 | |
39 // checks for existence of parameters | |
40 bool haveFastaDb = false; | |
41 bool haveBed = false; | |
42 bool haveFastaOut = false; | |
43 bool useNameOnly = false; | |
44 bool useFasta = true; | |
45 bool useStrand = false; | |
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("-fi", 3, parameterLength)) { | |
67 if ((i+1) < argc) { | |
68 haveFastaDb = true; | |
69 fastaDbFile = argv[i + 1]; | |
70 i++; | |
71 } | |
72 } | |
73 else if(PARAMETER_CHECK("-fo", 3, parameterLength)) { | |
74 if ((i+1) < argc) { | |
75 haveFastaOut = true; | |
76 fastaOutFile = argv[i + 1]; | |
77 i++; | |
78 } | |
79 } | |
80 else if(PARAMETER_CHECK("-bed", 4, parameterLength)) { | |
81 if ((i+1) < argc) { | |
82 haveBed = true; | |
83 bedFile = argv[i + 1]; | |
84 i++; | |
85 } | |
86 } | |
87 else if(PARAMETER_CHECK("-name", 5, parameterLength)) { | |
88 useNameOnly = true; | |
89 } | |
90 else if(PARAMETER_CHECK("-tab", 4, parameterLength)) { | |
91 useFasta = false; | |
92 } | |
93 else if(PARAMETER_CHECK("-s", 2, parameterLength)) { | |
94 useStrand = true; | |
95 } | |
96 else { | |
97 cerr << "*****ERROR: Unrecognized parameter: " << argv[i] << " *****" << endl << endl; | |
98 showHelp = true; | |
99 } | |
100 } | |
101 | |
102 if (!haveFastaDb || !haveFastaOut || !haveBed) { | |
103 showHelp = true; | |
104 } | |
105 | |
106 if (!showHelp) { | |
107 | |
108 Bed2Fa *b2f = new Bed2Fa(useNameOnly, fastaDbFile, bedFile, fastaOutFile, useFasta, useStrand); | |
109 delete b2f; | |
110 | |
111 return 0; | |
112 } | |
113 else { | |
114 ShowHelp(); | |
115 } | |
116 } | |
117 | |
118 void ShowHelp(void) { | |
119 | |
120 cerr << endl << "Program: " << PROGRAM_NAME << " (v" << VERSION << ")" << endl; | |
121 | |
122 cerr << "Author: Aaron Quinlan (aaronquinlan@gmail.com)" << endl; | |
123 | |
124 cerr << "Summary: Extract DNA sequences into a fasta file based on feature coordinates." << endl << endl; | |
125 | |
126 cerr << "Usage: " << PROGRAM_NAME << " [OPTIONS] -fi <fasta> -bed <bed/gff/vcf> -fo <fasta> " << endl << endl; | |
127 | |
128 cerr << "Options: " << endl; | |
129 cerr << "\t-fi\tInput FASTA file" << endl; | |
130 cerr << "\t-bed\tBED/GFF/VCF file of ranges to extract from -fi" << endl; | |
131 cerr << "\t-fo\tOutput file (can be FASTA or TAB-delimited)" << endl; | |
132 cerr << "\t-name\tUse the name field for the FASTA header" << endl; | |
133 | |
134 cerr << "\t-tab\tWrite output in TAB delimited format." << endl; | |
135 cerr << "\t\t- Default is FASTA format." << endl << endl; | |
136 | |
137 cerr << "\t-s\tForce strandedness. If the feature occupies the antisense strand," << endl; | |
138 cerr << "\t\tthe sequence will be reverse complemented." << endl; | |
139 cerr << "\t\t- By default, strand information is ignored." << endl << endl; | |
140 | |
141 | |
142 | |
143 // end the program here | |
144 exit(1); | |
145 | |
146 } |