-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathminced.java
304 lines (280 loc) · 11 KB
/
minced.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
import java.io.*;
public class minced
{
public static final String VERSION = "0.4.2";
public static void main(String[] args)
{
//default values
int screenDisplay = 1;
int minNumRepeats = 3;
int minRepeatLength = 23;
int maxRepeatLength = 47;
int minSpacerLength = 26;
int maxSpacerLength = 50;
int searchWindowLength = 8;
boolean spacers = false;
// set the output format
// 0 = original report
// 1 = summary gff
// 2 = full gff
int outformat = 0;
int numOptions = 0;
if (args.length == 0)
{
printUsage();
//System.out.println("No arguments specified.");
//System.out.println("Try 'minced --help' for more information.");
System.exit(1);
}
if (args[0].equals("--help") || args[0].equals("-h"))
{
printUsage();
System.exit(1);
}
if (args[0].equals("--version"))
{
printVersion();
System.exit(0);
}
int i = 0;
while (args[i].charAt(0) == '-')
{
try
{
if (args[i].endsWith("minNR"))
{
i++;
if (i >= args.length)
{
System.out.println("Missing option value for " + args[i - 1] + ".");
System.out.println("Try 'minced --help' for more information.");
System.exit(1);
}
minNumRepeats = Integer.parseInt(args[i]);
numOptions += 2;
}
else if (args[i].endsWith("gff")) {
outformat = 1;
numOptions++;
}
else if (args[i].endsWith("gffFull")) {
outformat = 2;
numOptions++;
}
else if (args[i].endsWith("spacers")) {
spacers = true;
numOptions++;
}
else if (args[i].endsWith("minRL"))
{
i++;
if (i >= args.length)
{
System.out.println("Missing option value for " + args[i - 1] + ".");
System.out.println("Try 'minced --help' for more information.");
System.exit(1);
}
minRepeatLength = Integer.parseInt(args[i]);
numOptions +=2;
}
else if (args[i].endsWith("maxRL"))
{
i++;
if (i >= args.length)
{
System.out.println("Missing option value for " + args[i - 1] + ".");
System.out.println("Try 'minced --help' for more information.");
System.exit(1);
}
maxRepeatLength = Integer.parseInt(args[i]);
numOptions += 2;
}
else if (args[i].endsWith("minSL"))
{
i++;
if (i >= args.length)
{
System.out.println("Missing option value for " + args[i - 1] + ".");
System.out.println("Try 'minced --help' for more information.");
System.exit(1);
}
minSpacerLength = Integer.parseInt(args[i]);
numOptions += 2;
}
else if (args[i].endsWith("maxSL"))
{
i++;
if (i >= args.length)
{
System.out.println("Missing option value for " + args[i - 1] + ".");
System.out.println("Try 'minced --help' for more information.");
System.exit(1);
}
maxSpacerLength = Integer.parseInt(args[i]);
numOptions += 2;
}
else if (args[i].endsWith("searchWL"))
{
i++;
if (i >= args.length)
{
System.out.println("Missing option value for " + args[i - 1] + ".");
System.out.println("Try 'minced --help' for more information.");
System.exit(1);
}
searchWindowLength = Integer.parseInt(args[i]);
numOptions += 2;
if ( (searchWindowLength < 6) || (searchWindowLength > 9) )
{
searchWindowLength = 8;
System.out.println("--Reseting search window length to " + searchWindowLength + "--");
}
}
/*
else if (args[i].endsWith("screen"))
{
i++;
if (i >= args.length)
{
System.out.println("Missing option value for " + args[i - 1] + ".");
System.out.println("Try 'minced --help' for more information.");
System.exit(1);
}
screenDisplay = Integer.parseInt(args[i]);
numOptions++;
if ( screenDisplay != 1 )
screenDisplay = 0;
}
*/
else
{
System.out.println("Invalid option: " + args[i]);
System.out.println("Try 'minced --help' for more information.");
System.exit(1);
}
i++; //--------//
if (i >= args.length)
{
System.out.println("No input file specified.");
System.out.println("Try 'minced --help' for more information.");
System.exit(1);
}
} //end try
catch (NumberFormatException e) // exception will be caught if user does not specify an integer after each option
{
System.out.println("Invalid argument type. Please, specify an option followed by an integer. For example: -minNR 3");
System.out.println("Try 'minced --help' for more information.");
System.exit(1);
}
} // end while
// Last options should be an input file and optional output file
String inputFileName = "";
String outputFileName = "";
String outputGffFileName = "";
boolean outputFileSpecified = false;
boolean outputGffFileSpecified = false;
int numArgsRemaining = args.length - numOptions;
if (numArgsRemaining == 1)
inputFileName = args[i];
else if (numArgsRemaining == 2)
{
inputFileName = args[i];
outputFileSpecified = true;
outputFileName = args[i + 1];
screenDisplay = 0;
}
else if (numArgsRemaining == 3)
{
inputFileName = args[i];
outputFileSpecified = true;
outputGffFileSpecified = true;
outputFileName = args[i + 1];
outputGffFileName = args[i + 2];
screenDisplay = 0;
}
else
{
System.out.println("Improper usage.");
System.out.println("Try 'minced --help' for more information.");
System.exit(1);
}
File inputFile = new File(inputFileName);
if (!inputFile.exists())
{
System.out.println("Input file " + inputFile.getPath() + " does not exist.");
System.exit(1);
}
if (inputFile.isDirectory())
{
System.out.println("You have entered a directory name. An input file name is required: " + inputFile.getPath());
System.exit(1);
}
File outputFile;
if (outputFileSpecified)
{
outputFile = new File(outputFileName);
if (outputFile.isDirectory())
{
System.out.println("You have entered an existing directory name. An output file name is required: " + outputFile.getAbsolutePath());
System.exit(1);
}
if (!outputFile.getAbsoluteFile().getParentFile().isDirectory())
{
System.out.println("You did not enter a valid file output path: " + outputFile.getAbsolutePath());
System.exit(1);
}
}
CRISPRFinder client = new CRISPRFinder(inputFileName,
outputFileName,
outputGffFileName,
screenDisplay,
minNumRepeats,
minRepeatLength,
maxRepeatLength,
minSpacerLength,
maxSpacerLength,
searchWindowLength,
outformat,
spacers);
client.goCRISPRFinder();
}
public static void printUsage()
{
System.out.println("MinCED, a program to find CRISPRs in shotgun DNA sequences or full genomes");
System.out.println();
System.out.println("Usage: minced [options] file.fa [outputFile.txt] [outputFile.gff]");
System.out.println();
System.out.println("Options: -searchWL Length of search window used to discover CRISPRs (range: 6-9). Default: 8");
System.out.println(" -minNR Minimum number of repeats a CRISPR must contain. Default: 3");
System.out.println(" -minRL Minimum length of the CRISPR repeats. Default: 23");
System.out.println(" -maxRL Maximum length of the CRISPR repeats. Default: 47");
System.out.println(" -minSL Minimum length of the CRISPR spacers. Default: 26");
System.out.println(" -maxSL Maximum length of the CRISPR spacers. Default: 50");
System.out.println(" -gff Output summary results in gff format containing");
System.out.println(" only the positions of the CRISPR arrays. Default: false");
System.out.println(" -gffFull Output detailed results in gff format containing");
System.out.println(" positions of CRISPR arrays and all repeat units. Default: false");
System.out.println(" -spacers Output a fasta formatted file containing the spacers. Default: false");
System.out.println(" -h --help Output this handy help message");
System.out.println(" --version Output version information");
System.out.println();
System.out.println("Examples: minced ecoli.fna");
System.out.println(" minced metagenome.fna");
System.out.println(" minced metagenome.fna metagenome.crisprs");
System.out.println(" minced metagenome.fna metagenome.crisprs metagenome.gff");
System.out.println();
}
public static void printVersion()
{
System.out.println("minced " + VERSION);
System.out.println("MinCED - Mining CRISPRs in Environmental Datasets (version " + VERSION + ")");
System.out.println("Copyright 2011 Florent Angly <[email protected]>");
System.out.println(" 2013-2019 Connor Skennerton <[email protected]>");
System.out.println();
System.out.println("Minced is a modified version of CRT (www.room220.com/crt)");
System.out.println("Charles Bland et al., CRISPR Recognition Tool (CRT): a tool for automatic");
System.out.println("detection of clustered regularly interspaced palindromic repeats");
System.out.println("BMC Bioinformatics 8, no. 1 (2007): 209.");
System.out.println("Distributed under the GNU General Public License version 3");
}
}