-
Notifications
You must be signed in to change notification settings - Fork 223
/
UserException.java
executable file
·427 lines (353 loc) · 19.7 KB
/
UserException.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
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
/*
* Copyright (c) 2010, The Broad Institute
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
package org.broadinstitute.sting.utils.exceptions;
import net.sf.samtools.SAMFileHeader;
import net.sf.samtools.SAMRecord;
import net.sf.samtools.SAMSequenceDictionary;
import org.broadinstitute.sting.gatk.phonehome.GATKRunReport;
import org.broadinstitute.sting.utils.GenomeLoc;
import org.broadinstitute.sting.utils.help.DocumentedGATKFeature;
import org.broadinstitute.sting.utils.help.HelpUtils;
import org.broadinstitute.sting.utils.sam.ReadUtils;
import org.broadinstitute.sting.utils.variantcontext.VariantContext;
import java.io.File;
/**
* Represents the common user errors detected by Sting / GATK
*
* Root class for all GATK user errors, as well as the container for errors themselves
*
* User: depristo
* Date: Sep 3, 2010
* Time: 2:24:09 PM
*/
@DocumentedGATKFeature(
groupName = "User exceptions",
summary = "Exceptions caused by incorrect user behavior, such as bad files, bad arguments, etc." )
public class UserException extends ReviewedStingException {
public UserException(String msg) { super(msg); }
public UserException(String msg, Throwable e) { super(msg, e); }
private UserException(Throwable e) { super("", e); } // cannot be called, private access
protected static String getMessage(Throwable t) {
String message = t.getMessage();
return message != null ? message : t.getClass().getName();
}
public static class CommandLineException extends UserException {
public CommandLineException(String message) {
super(String.format("Invalid command line: %s", message));
}
}
public static class MalformedReadFilterException extends CommandLineException {
public MalformedReadFilterException(String message) {
super(String.format("Malformed read filter: %s",message));
}
}
public static class MalformedWalkerArgumentsException extends CommandLineException {
public MalformedWalkerArgumentsException(String message) {
super(String.format("Malformed walker argument: %s",message));
}
}
public static class MalformedGenomeLoc extends UserException {
public MalformedGenomeLoc(String message, GenomeLoc loc) {
super(String.format("Badly formed genome loc: %s: %s", message, loc));
}
public MalformedGenomeLoc(String message) {
super(String.format("Badly formed genome loc: %s", message));
}
}
public static class BadInput extends UserException {
public BadInput(String message) {
super(String.format("Bad input: %s", message));
}
}
public static class NotSupportedInGATKLite extends UserException {
public NotSupportedInGATKLite(String message) {
super(String.format("GATK Lite does not support all of the features of the full version: %s", message));
}
}
// todo -- fix up exception cause passing
public static class MissingArgument extends CommandLineException {
public MissingArgument(String arg, String message) {
super(String.format("Argument %s was missing: %s", arg, message));
}
}
public static class BadArgumentValue extends CommandLineException {
public BadArgumentValue(String arg, String message) {
super(String.format("Argument %s has a bad value: %s", arg, message));
}
}
public static class UnknownTribbleType extends CommandLineException {
public UnknownTribbleType(String type, String message) {
super(String.format("Unknown tribble type %s: %s", type, message));
}
}
public static class BadTmpDir extends UserException {
public BadTmpDir(String message) {
super(String.format("Failure working with the tmp directory %s. Override with -Djava.io.tmpdir=X on the command line to a bigger/better file system. Exact error was %s", System.getProperties().get("java.io.tmpdir"), message));
}
}
public static class TooManyOpenFiles extends UserException {
public TooManyOpenFiles() {
super(String.format("There was a failure because there are too many files open concurrently; your system's open file handle limit is too small. See the unix ulimit command to adjust this limit"));
}
}
public static class LocalParallelizationProblem extends UserException {
public LocalParallelizationProblem(final File file) {
super(String.format("There was a failure because temporary file %s could not be found while running the GATK with more than one thread. Possible causes for this problem include: your system's open file handle limit is too small, your output or temp directories do not have sufficient space, or just an isolated file system blip", file.getAbsolutePath()));
}
}
public static class NotEnoughMemory extends UserException {
public NotEnoughMemory() {
super(String.format("There was a failure because you did not provide enough memory to run this program. See the -Xmx JVM argument to adjust the maximum heap size provided to Java"));
}
}
public static class ErrorWritingBamFile extends UserException {
public ErrorWritingBamFile(String message) {
super(String.format("An error occurred when trying to write the BAM file. Usually this happens when there is not enough space in the directory to which the data is being written (generally the temp directory) or when your system's open file handle limit is too small. To tell Java to use a bigger/better file system use -Djava.io.tmpdir=X on the command line. The exact error was %s", message));
}
}
public static class NoSpaceOnDevice extends UserException {
public NoSpaceOnDevice() {
super("There is no space left on the device, so writing failed");
}
}
public static class CouldNotReadInputFile extends UserException {
public CouldNotReadInputFile(String message, Exception e) {
super(String.format("Couldn't read file because %s caused by %s", message, getMessage(e)));
}
public CouldNotReadInputFile(File file) {
super(String.format("Couldn't read file %s", file.getAbsolutePath()));
}
public CouldNotReadInputFile(File file, String message) {
super(String.format("Couldn't read file %s because %s", file.getAbsolutePath(), message));
}
public CouldNotReadInputFile(String file, String message) {
super(String.format("Couldn't read file %s because %s", file, message));
}
public CouldNotReadInputFile(File file, String message, Exception e) {
super(String.format("Couldn't read file %s because %s with exception %s", file.getAbsolutePath(), message, getMessage(e)));
}
public CouldNotReadInputFile(File file, Exception e) {
this(file, getMessage(e));
}
public CouldNotReadInputFile(String message) {
super(message);
}
}
public static class CouldNotCreateOutputFile extends UserException {
public CouldNotCreateOutputFile(File file, String message, Exception e) {
super(String.format("Couldn't write file %s because %s with exception %s", file.getAbsolutePath(), message, getMessage(e)));
}
public CouldNotCreateOutputFile(File file, String message) {
super(String.format("Couldn't write file %s because %s", file.getAbsolutePath(), message));
}
public CouldNotCreateOutputFile(String filename, String message, Exception e) {
super(String.format("Couldn't write file %s because %s with exception %s", filename, message, getMessage(e)));
}
public CouldNotCreateOutputFile(File file, Exception e) {
super(String.format("Couldn't write file %s because exception %s", file.getAbsolutePath(), getMessage(e)));
}
public CouldNotCreateOutputFile(String message, Exception e) {
super(message, e);
}
}
public static class MissortedBAM extends UserException {
public MissortedBAM(SAMFileHeader.SortOrder order, File file, SAMFileHeader header) {
super(String.format("Missorted Input SAM/BAM files: %s is must be sorted in %s order but order was: %s", file, order, header.getSortOrder()));
}
public MissortedBAM(SAMFileHeader.SortOrder order, String message) {
super(String.format("Missorted Input SAM/BAM files: files are not sorted in %s order; %s", order, message));
}
public MissortedBAM(SAMFileHeader.SortOrder order, SAMRecord read, String message) {
super(String.format("Missorted Input SAM/BAM file %s: file sorted in %s order but %s is required; %s",
read.getFileSource().getReader(), read.getHeader().getSortOrder(), order, message));
}
public MissortedBAM(String message) {
super(String.format("Missorted Input SAM/BAM files: %s", message));
}
}
public static class MalformedBAM extends UserException {
public MalformedBAM(SAMRecord read, String message) {
this(read.getFileSource() != null ? read.getFileSource().getReader().toString() : "(none)", message);
}
public MalformedBAM(File file, String message) {
this(file.toString(), message);
}
public MalformedBAM(String source, String message) {
super(String.format("SAM/BAM file %s is malformed: %s", source, message));
}
}
public static class MalformedVCF extends UserException {
public MalformedVCF(String message, String line) {
super(String.format("The provided VCF file is malformed at line %s: %s", line, message));
}
public MalformedVCF(String message) {
super(String.format("The provided VCF file is malformed: %s", message));
}
public MalformedVCF(String message, int lineNo) {
super(String.format("The provided VCF file is malformed at approximately line number %d: %s", lineNo, message));
}
}
public static class MalformedBCF2 extends UserException {
public MalformedBCF2( String message ) {
super(String.format("Malformed BCF2 file: %s", message));
}
}
public static class MalformedVCFHeader extends UserException {
public MalformedVCFHeader(String message) {
super(String.format("The provided VCF file has a malformed header: %s", message));
}
}
public static class ReadMissingReadGroup extends MalformedBAM {
public ReadMissingReadGroup(SAMRecord read) {
super(read, String.format("Read %s is either missing the read group or its read group is not defined in the BAM header, both of which are required by the GATK. Please use " + HelpUtils.GATK_FORUM_URL + "discussion/59/companion-utilities-replacereadgroups to fix this problem", read.getReadName()));
}
}
public static class VariantContextMissingRequiredField extends UserException {
public VariantContextMissingRequiredField(String field, VariantContext vc) {
super(String.format("Variant at %s:%d is is missing the required field %s", vc.getChr(), vc.getStart(), field));
}
}
public static class MissortedFile extends UserException {
public MissortedFile(File file, String message, Exception e) {
super(String.format("Missorted Input file: %s is must be sorted in coordinate order. %s and got error %s", file, message, getMessage(e)));
}
}
public static class FailsStrictValidation extends UserException {
public FailsStrictValidation(File f, String message) {
super(String.format("File %s fails strict validation: %s", f.getAbsolutePath(), message));
}
}
public static class MalformedFile extends UserException {
public MalformedFile(String message) {
super(String.format("Unknown file is malformed: %s", message));
}
public MalformedFile(String message, Exception e) {
super(String.format("Unknown file is malformed: %s caused by %s", message, getMessage(e)));
}
public MalformedFile(File f, String message) {
super(String.format("File %s is malformed: %s", f.getAbsolutePath(), message));
}
public MalformedFile(File f, String message, Exception e) {
super(String.format("File %s is malformed: %s caused by %s", f.getAbsolutePath(), message, getMessage(e)));
}
public MalformedFile(String name, String message) {
super(String.format("File associated with name %s is malformed: %s", name, message));
}
public MalformedFile(String name, String message, Exception e) {
super(String.format("File associated with name %s is malformed: %s caused by %s", name, message, getMessage(e)));
}
}
public static class CannotExecuteRScript extends UserException {
public CannotExecuteRScript(String message) {
super(String.format("Unable to execute RScript command: " + message));
}
public CannotExecuteRScript(String message, Exception e) {
super(String.format("Unable to execute RScript command: " + message), e);
}
}
public static class DeprecatedArgument extends CommandLineException {
public DeprecatedArgument(String param, String doc) {
super(String.format("The parameter %s is deprecated. %s",param,doc));
}
}
public static class IncompatibleSequenceDictionaries extends UserException {
public IncompatibleSequenceDictionaries(String message, String name1, SAMSequenceDictionary dict1, String name2, SAMSequenceDictionary dict2) {
super(String.format("Input files %s and %s have incompatible contigs: %s.\n %s contigs = %s\n %s contigs = %s",
name1, name2, message, name1, ReadUtils.prettyPrintSequenceRecords(dict1), name2, ReadUtils.prettyPrintSequenceRecords(dict2)));
}
}
public static class LexicographicallySortedSequenceDictionary extends UserException {
public LexicographicallySortedSequenceDictionary(String name, SAMSequenceDictionary dict) {
super(String.format("Lexicographically sorted human genome sequence detected in %s."
+ "\nFor safety's sake the GATK requires human contigs in karyotypic order: 1, 2, ..., 10, 11, ..., 20, 21, 22, X, Y with M either leading or trailing these contigs."
+ "\nThis is because all distributed GATK resources are sorted in karyotypic order, and your processing will fail when you need to use these files."
+ "\nYou can use the ReorderSam utility to fix this problem: " + HelpUtils.GATK_FORUM_URL + "discussion/58/companion-utilities-reordersam"
+ "\n %s contigs = %s",
name, name, ReadUtils.prettyPrintSequenceRecords(dict)));
}
}
public static class DeprecatedWalker extends UserException {
public DeprecatedWalker(String walkerName, String version) {
super(String.format("Walker %s is no longer available in the GATK; it has been deprecated since version %s", walkerName, version));
}
}
public static class CannotExecuteQScript extends UserException {
public CannotExecuteQScript(String message) {
super(String.format("Unable to execute QScript: " + message));
}
public CannotExecuteQScript(String message, Exception e) {
super(String.format("Unable to execute QScript: " + message), e);
}
}
public static class CouldNotCreateReferenceIndexFile extends UserException {
public CouldNotCreateReferenceIndexFile(File f, Exception e) {
this(f, "", e);
}
public CouldNotCreateReferenceIndexFile(File f, String message, Exception e) {
super(String.format("Index file %s does not exist but could not be created because: %s. ", f, message)
+ (e == null ? "" : getMessage(e)));
}
}
public static class CouldNotCreateReferenceFAIorDictForGzippedRef extends UserException {
public CouldNotCreateReferenceFAIorDictForGzippedRef(final File f) {
super("Although the GATK can process .gz reference sequences, it currently cannot create FAI " +
"or DICT files for them. In order to use the GATK with reference.fasta.gz you will need to " +
"create .dict and .fai files for reference.fasta.gz and name them reference.fasta.gz.fai and " +
"reference.dict. Potentially the easiest way to do this is to uncompress reference.fasta, " +
"run the GATK to create the .dict and .fai files, and copy them to the appropriate location. " +
"Sorry for the inconvenience.");
}
}
public static class CouldNotCreateReferenceIndexFileBecauseOfLock extends UserException.CouldNotCreateReferenceIndexFile {
public CouldNotCreateReferenceIndexFileBecauseOfLock(File f) {
super(f, "could not be written because an exclusive file lock could not be obtained. " +
"If you are running multiple instances of GATK, another GATK process is " +
"probably creating this file now, and has locked it. Please wait until this process finishes " +
"and try again.", null);
}
}
public static class UnreadableKeyException extends UserException {
public UnreadableKeyException ( File f, Exception e ) {
super(String.format("Key file %s cannot be read (possibly the key file is corrupt?). Error was: %s. " +
"Please see %s for help.",
f.getAbsolutePath(), getMessage(e), GATKRunReport.PHONE_HOME_DOCS_URL));
}
public UnreadableKeyException ( String message, Exception e ) {
this(String.format("%s. Error was: %s", message, getMessage(e)));
}
public UnreadableKeyException ( String message ) {
super(String.format("Key file cannot be read (possibly the key file is corrupt?): %s. " +
"Please see %s for help.",
message, GATKRunReport.PHONE_HOME_DOCS_URL));
}
}
public static class KeySignatureVerificationException extends UserException {
public KeySignatureVerificationException ( File f ) {
super(String.format("The signature in key file %s failed cryptographic verification. " +
"If this key was valid in the past, it's likely been revoked. " +
"Please see %s for help.",
f.getAbsolutePath(), GATKRunReport.PHONE_HOME_DOCS_URL));
}
}
}