0
|
1 /*****************************************************************************
|
|
2 maskFastaFromBedMain.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 "maskFastaFromBed.h"
|
|
13 #include "version.h"
|
|
14
|
|
15 using namespace std;
|
|
16
|
|
17 // define our program name
|
|
18 #define PROGRAM_NAME "maskFastaFromBed"
|
|
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 fastaInFile;
|
|
34 string bedFile;
|
|
35
|
|
36 // output files
|
|
37 string fastaOutFile;
|
|
38
|
|
39 // defaults for parameters
|
|
40 bool haveFastaIn = false;
|
|
41 bool haveBed = false;
|
|
42 bool haveFastaOut = false;
|
|
43 bool softMask = false;
|
|
44 char maskChar = 'N';
|
|
45
|
|
46 // check to see if we should print out some help
|
|
47 if(argc <= 1) showHelp = true;
|
|
48
|
|
49 for(int i = 1; i < argc; i++) {
|
|
50 int parameterLength = (int)strlen(argv[i]);
|
|
51
|
|
52 if((PARAMETER_CHECK("-h", 2, parameterLength)) ||
|
|
53 (PARAMETER_CHECK("--help", 5, parameterLength))) {
|
|
54 showHelp = true;
|
|
55 }
|
|
56 }
|
|
57
|
|
58 if(showHelp) ShowHelp();
|
|
59
|
|
60 // do some parsing (all of these parameters require 2 strings)
|
|
61 for(int i = 1; i < argc; i++) {
|
|
62
|
|
63 int parameterLength = (int)strlen(argv[i]);
|
|
64
|
|
65 if(PARAMETER_CHECK("-fi", 3, parameterLength)) {
|
|
66 if ((i+1) < argc) {
|
|
67 haveFastaIn = true;
|
|
68 fastaInFile = argv[i + 1];
|
|
69 i++;
|
|
70 }
|
|
71 }
|
|
72 else if(PARAMETER_CHECK("-fo", 3, parameterLength)) {
|
|
73 if ((i+1) < argc) {
|
|
74 haveFastaOut = true;
|
|
75 fastaOutFile = argv[i + 1];
|
|
76 i++;
|
|
77 }
|
|
78 }
|
|
79 else if(PARAMETER_CHECK("-bed", 4, parameterLength)) {
|
|
80 if ((i+1) < argc) {
|
|
81 haveBed = true;
|
|
82 bedFile = argv[i + 1];
|
|
83 i++;
|
|
84 }
|
|
85 }
|
|
86 else if(PARAMETER_CHECK("-soft", 5, parameterLength)) {
|
|
87 softMask = true;
|
|
88 }
|
|
89 else if(PARAMETER_CHECK("-mc", 3, parameterLength)) {
|
|
90 if ((i+1) < argc) {
|
|
91 string mask = argv[i + 1];
|
|
92 if (mask.size() > 1) {
|
|
93 cerr << "*****ERROR: The mask character (-mc) should be a single character.*****" << endl << endl;
|
|
94 showHelp = true;
|
|
95 }
|
|
96 else {
|
|
97 maskChar = mask[0];
|
|
98 }
|
|
99 i++;
|
|
100 }
|
|
101 }
|
|
102 else {
|
|
103 cerr << "*****ERROR: Unrecognized parameter: " << argv[i] << " *****" << endl << endl;
|
|
104 showHelp = true;
|
|
105 }
|
|
106 }
|
|
107
|
|
108 if (!haveFastaIn || !haveFastaOut || !haveBed) {
|
|
109 showHelp = true;
|
|
110 }
|
|
111
|
|
112 if (!showHelp) {
|
|
113
|
|
114 MaskFastaFromBed *maskFasta = new MaskFastaFromBed(fastaInFile, bedFile, fastaOutFile, softMask, maskChar);
|
|
115 delete maskFasta;
|
|
116 return 0;
|
|
117 }
|
|
118 else {
|
|
119 ShowHelp();
|
|
120 }
|
|
121 }
|
|
122
|
|
123 void ShowHelp(void) {
|
|
124
|
|
125
|
|
126
|
|
127 cerr << endl << "Program: " << PROGRAM_NAME << " (v" << VERSION << ")" << endl;
|
|
128
|
|
129 cerr << "Author: Aaron Quinlan (aaronquinlan@gmail.com)" << endl;
|
|
130
|
|
131 cerr << "Summary: Mask a fasta file based on feature coordinates." << endl << endl;
|
|
132
|
|
133 cerr << "Usage: " << PROGRAM_NAME << " [OPTIONS] -fi <fasta> -out <fasta> -bed <bed/gff/vcf>" << endl << endl;
|
|
134
|
|
135 cerr << "Options:" << endl;
|
|
136 cerr << "\t-fi\tInput FASTA file" << endl;
|
|
137 cerr << "\t-bed\tBED/GFF/VCF file of ranges to mask in -fi" << endl;
|
|
138 cerr << "\t-fo\tOutput FASTA file" << endl;
|
|
139 cerr << "\t-soft\tEnforce \"soft\" masking. That is, instead of masking with Ns," << endl;
|
|
140 cerr << "\t\tmask with lower-case bases." << endl;
|
|
141 cerr << "\t-mc\tReplace masking character. That is, instead of masking with Ns, use another character." << endl;
|
|
142
|
|
143 // end the program here
|
|
144 exit(1);
|
|
145
|
|
146 }
|