From 1de713f354da34ce7803454d3461a70489d4b76b Mon Sep 17 00:00:00 2001 From: depristo Date: Thu, 9 Sep 2010 23:21:17 +0000 Subject: [PATCH] Massive review of maybe 50% of the exceptions in the GATK. GATKException is a tmp. tracker so that I can tell which StingExceptions I've reviewed. Please don't use it. If you are working on new code and are considering throwing exceptions, it's either UserError or StingException, please git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@4246 348d0f76-0448-11de-a6fe-93d51630548a --- .../reference/FastaSequenceIndexBuilder.java | 20 ++--- .../sting/alignment/Alignment.java | 3 +- .../alignment/AlignmentValidationWalker.java | 3 +- .../sting/alignment/bwa/BWTFiles.java | 9 ++- .../sting/alignment/bwa/c/BWACAligner.java | 27 ++++--- .../bwa/java/AlignerTestHarness.java | 3 +- .../bwa/java/AlignmentMatchSequence.java | 7 +- .../alignment/bwa/java/BWAAlignment.java | 3 +- .../sting/alignment/reference/bwt/BWT.java | 3 +- .../alignment/reference/bwt/BWTReader.java | 5 +- .../alignment/reference/bwt/BWTWriter.java | 7 +- .../sting/alignment/reference/bwt/Bases.java | 3 +- .../sting/alignment/reference/bwt/Counts.java | 3 +- .../reference/bwt/CreateBWTFromReference.java | 5 +- .../alignment/reference/bwt/SuffixArray.java | 5 +- .../reference/bwt/SuffixArrayReader.java | 7 +- .../reference/bwt/SuffixArrayWriter.java | 7 +- .../packing/BasePackedInputStream.java | 3 +- .../packing/BasePackedOutputStream.java | 3 +- .../reference/packing/PackUtils.java | 11 +-- .../commandline/ArgumentDefinitionGroup.java | 3 +- .../commandline/ArgumentDefinitions.java | 5 +- .../sting/commandline/ArgumentIOType.java | 3 +- .../sting/commandline/ArgumentSource.java | 3 +- .../commandline/ArgumentTypeDescriptor.java | 40 +++++----- .../sting/commandline/CommandLineUtils.java | 3 +- .../sting/commandline/ParsingEngine.java | 8 +- .../sting/gatk/DownsamplingMethod.java | 7 +- .../sting/gatk/GenomeAnalysisEngine.java | 36 ++++----- .../sting/gatk/ReadMetrics.java | 3 +- .../sting/gatk/WalkerManager.java | 5 +- .../arguments/GATKArgumentCollection.java | 9 ++- .../sting/gatk/contexts/AlignmentContext.java | 9 ++- .../sting/gatk/contexts/ReferenceContext.java | 3 +- .../contexts/StratifiedAlignmentContext.java | 13 +-- .../variantcontext/VariantContextUtils.java | 12 +-- .../variantcontext/VariantJEXLContext.java | 4 +- .../providers/LocusReferenceView.java | 7 +- .../datasources/providers/ReferenceView.java | 7 +- .../providers/ShardDataProvider.java | 5 +- .../datasources/shards/IntervalSharder.java | 6 +- .../datasources/shards/MonolithicShard.java | 3 +- .../shards/ShardStrategyFactory.java | 5 +- .../ReferenceDataSource.java | 15 ++-- .../ReferenceOrderedDataSource.java | 6 +- .../simpleDataSources/ResourcePool.java | 5 +- .../simpleDataSources/SAMDataSource.java | 16 ++-- .../datasources/utilities/BAMFileStat.java | 5 +- .../sting/gatk/executive/Accumulator.java | 3 +- .../executive/HierarchicalMicroScheduler.java | 9 ++- .../sting/gatk/executive/ShardTraverser.java | 5 +- .../sting/gatk/executive/TreeReducer.java | 5 +- .../sting/gatk/io/OutputTracker.java | 3 +- .../gatk/io/storage/OutputStreamStorage.java | 3 +- .../sting/gatk/io/storage/StorageFactory.java | 3 +- .../gatk/io/storage/VCFWriterStorage.java | 3 +- .../OutputStreamArgumentTypeDescriptor.java | 7 +- .../SAMFileReaderArgumentTypeDescriptor.java | 3 +- .../SAMFileWriterArgumentTypeDescriptor.java | 3 +- .../gatk/io/stubs/SAMFileWriterStub.java | 9 ++- .../gatk/iterators/BufferingReadIterator.java | 3 +- .../sting/gatk/phonehome/GATKRunReport.java | 3 +- .../sting/gatk/refdata/IntervalRod.java | 3 +- .../sting/gatk/refdata/PlinkRod.java | 23 +++--- .../sting/gatk/refdata/RODRecordIterator.java | 11 +-- .../sting/gatk/refdata/RODRecordListImpl.java | 7 +- .../gatk/refdata/RefMetaDataTracker.java | 8 +- .../gatk/refdata/SeekableRODIterator.java | 11 +-- .../features/refseq/RefSeqFeature.java | 3 +- .../gatk/refdata/tracks/RMDTrackManager.java | 4 +- .../gatk/refdata/tracks/TribbleTrack.java | 3 +- .../builders/TribbleRMDTrackBuilder.java | 5 +- .../analyzeannotations/AnnotationDatum.java | 3 +- .../walkers/annotator/HaplotypeScore.java | 2 +- .../annotator/VariantAnnotatorEngine.java | 3 +- .../annotator/genomicannotator/JoinTable.java | 5 +- .../genomicannotator/JoinTableParser.java | 3 +- .../TranscriptToGenomicInfo.java | 8 +- .../genomicannotator/TranscriptToInfo.java | 3 +- .../walkers/coverage/CallableLociWalker.java | 5 +- .../coverage/CompareCallableLociWalker.java | 3 +- .../gatk/walkers/coverage/CoverageUtils.java | 12 +-- .../coverage/DepthOfCoverageWalker.java | 18 ++--- .../gatk/walkers/fasta/FastaSequence.java | 3 +- .../filters/FiltrationContextWindow.java | 5 +- .../DiploidGenotypeCalculationModel.java | 4 +- .../SimpleIndelCalculationModel.java | 2 +- .../indels/IndelGenotyperV2Walker.java | 37 +++++---- .../gatk/walkers/indels/IndelRealigner.java | 13 +-- .../indels/RealignerTargetCreator.java | 4 +- .../gatk/walkers/qc/CycleQualityWalker.java | 22 +++--- .../walkers/qc/ReadClippingStatsWalker.java | 3 +- .../gatk/walkers/qc/ReadValidationWalker.java | 3 +- .../walkers/qc/ValidatingPileupWalker.java | 12 ++- .../recalibration/CovariateCounterWalker.java | 15 ++-- .../walkers/recalibration/CycleCovariate.java | 3 +- .../recalibration/RecalDataManager.java | 29 +++---- .../TableRecalibrationWalker.java | 25 +++--- .../walkers/recalibration/TileCovariate.java | 3 +- .../walkers/varianteval/CountVariants.java | 5 +- .../varianteval/GenotypeConcordance.java | 8 +- .../varianteval/IndelLengthHistogram.java | 5 +- .../MendelianViolationEvaluator.java | 3 +- .../varianteval/SimpleMetricsByAC.java | 3 +- .../varianteval/VariantEvalWalker.java | 14 ++-- .../sting/utils/GATKException.java | 39 +++++++++ .../broadinstitute/sting/utils/GenomeLoc.java | 4 +- .../sting/utils/GenomeLocParser.java | 8 +- .../org/broadinstitute/sting/utils/Utils.java | 25 +++--- .../sting/utils/exceptions/UserError.java | 79 ++++++++++++++++++- 110 files changed, 587 insertions(+), 377 deletions(-) create mode 100644 java/src/org/broadinstitute/sting/utils/GATKException.java diff --git a/java/src/net/sf/picard/reference/FastaSequenceIndexBuilder.java b/java/src/net/sf/picard/reference/FastaSequenceIndexBuilder.java index 49929fcfc..628501603 100644 --- a/java/src/net/sf/picard/reference/FastaSequenceIndexBuilder.java +++ b/java/src/net/sf/picard/reference/FastaSequenceIndexBuilder.java @@ -26,6 +26,7 @@ package net.sf.picard.reference; import org.broadinstitute.sting.gatk.datasources.simpleDataSources.ReferenceDataSourceProgressListener; +import org.broadinstitute.sting.utils.GATKException; import org.broadinstitute.sting.utils.StingException; import static net.sf.picard.reference.FastaSequenceIndexBuilder.Status.*; @@ -33,6 +34,7 @@ import java.io.*; import java.util.Iterator; import net.sf.picard.reference.FastaSequenceIndex; +import org.broadinstitute.sting.utils.exceptions.UserError; /** * Builds FastaSequenceIndex from fasta file. @@ -83,7 +85,7 @@ public class FastaSequenceIndexBuilder { in = new DataInputStream(new BufferedInputStream(new FileInputStream(fastaFile))); } catch (Exception e) { - throw new StingException(String.format("Could not read fasta file %s", fastaFile.getAbsolutePath())); + throw new UserError.CouldNotReadInputFile(fastaFile, "Could not read fasta file", e); } /* @@ -166,7 +168,7 @@ public class FastaSequenceIndexBuilder { // validate base character else { if (!isValidBase(currentByte)) - throw new StingException(String.format("An invalid base was found in the contig: %s", contig)); + throw new UserError.MalformedFile(fastaFile, String.format("An invalid base was found in the contig: %s", contig)); } break; @@ -192,7 +194,7 @@ public class FastaSequenceIndexBuilder { // error if next char is a valid base, end of contig otherwise else if (basesThisLine != basesPerLine || bytesPerLine != bytesRead - endOfLastLine) { if (isValidBase(nextByte) && nextByte != -1) { - throw new StingException(String.format("An invalid line was found in the contig: %s", contig)); + throw new UserError.MalformedFile(fastaFile, String.format("An invalid line was found in the contig: %s", contig)); } else finishReadingContig(sequenceIndex); @@ -204,7 +206,7 @@ public class FastaSequenceIndexBuilder { // validate base character else { if (!isValidBase(currentByte)) - throw new StingException(String.format("An invalid base was found in the contig: %s", contig)); + throw new UserError.MalformedFile(fastaFile, String.format("An invalid base was found in the contig: %s", contig)); } break; } @@ -212,9 +214,10 @@ public class FastaSequenceIndexBuilder { return sequenceIndex; } catch (IOException e) { - throw new StingException(String.format("Could not read fasta file %s", fastaFile.getAbsolutePath()), e); } + throw new UserError.CouldNotReadInputFile(fastaFile, String.format("Could not read fasta file"), e); + } catch (Exception e) { - throw new StingException(e.getMessage(), e); + throw new GATKException(e.getMessage(), e); } } @@ -270,8 +273,7 @@ public class FastaSequenceIndexBuilder { out = new BufferedWriter(new FileWriter(faiFile)); } catch (Exception e) { - throw new StingException(String.format("Could not open file %s for writing. Check that GATK is permitted to write to disk.", - faiFile.getAbsolutePath()), e); + throw new UserError.CouldNotCreateOutputFile(faiFile, e); } try { @@ -282,7 +284,7 @@ public class FastaSequenceIndexBuilder { out.close(); } catch (Exception e) { - throw new StingException(String.format("An error occurred while writing file %s", e)); + throw new UserError.CouldNotCreateOutputFile(faiFile, e); } } diff --git a/java/src/org/broadinstitute/sting/alignment/Alignment.java b/java/src/org/broadinstitute/sting/alignment/Alignment.java index 49ae57f0a..e2ce1fab7 100644 --- a/java/src/org/broadinstitute/sting/alignment/Alignment.java +++ b/java/src/org/broadinstitute/sting/alignment/Alignment.java @@ -1,6 +1,7 @@ package org.broadinstitute.sting.alignment; import net.sf.samtools.*; +import org.broadinstitute.sting.utils.GATKException; import org.broadinstitute.sting.utils.StingException; import org.broadinstitute.sting.utils.BaseUtils; import org.broadinstitute.sting.utils.Utils; @@ -189,7 +190,7 @@ public class Alignment { read = (SAMRecord)unmappedRead.clone(); } catch(CloneNotSupportedException ex) { - throw new StingException("Unable to create aligned read from template."); + throw new GATKException("Unable to create aligned read from template."); } if(newSAMHeader != null) diff --git a/java/src/org/broadinstitute/sting/alignment/AlignmentValidationWalker.java b/java/src/org/broadinstitute/sting/alignment/AlignmentValidationWalker.java index 2656ea554..aad9dd6b5 100644 --- a/java/src/org/broadinstitute/sting/alignment/AlignmentValidationWalker.java +++ b/java/src/org/broadinstitute/sting/alignment/AlignmentValidationWalker.java @@ -29,6 +29,7 @@ import org.broadinstitute.sting.gatk.refdata.ReadMetaDataTracker; import org.broadinstitute.sting.gatk.walkers.ReadWalker; import org.broadinstitute.sting.gatk.contexts.ReferenceContext; import org.broadinstitute.sting.utils.BaseUtils; +import org.broadinstitute.sting.utils.GATKException; import org.broadinstitute.sting.utils.StingException; import org.broadinstitute.sting.commandline.Argument; import org.broadinstitute.sting.alignment.bwa.c.BWACAligner; @@ -120,7 +121,7 @@ public class AlignmentValidationWalker extends ReadWalker { logger.error(String.format(" Mapping quality: %s%n", alignmentsByScore[i].getMappingQuality())); } } - throw new StingException(String.format("Read %s mismatches!", read.getReadName())); + throw new GATKException(String.format("Read %s mismatches!", read.getReadName())); } return 1; diff --git a/java/src/org/broadinstitute/sting/alignment/bwa/BWTFiles.java b/java/src/org/broadinstitute/sting/alignment/bwa/BWTFiles.java index c79ffb4a3..e015a192b 100644 --- a/java/src/org/broadinstitute/sting/alignment/bwa/BWTFiles.java +++ b/java/src/org/broadinstitute/sting/alignment/bwa/BWTFiles.java @@ -1,5 +1,6 @@ package org.broadinstitute.sting.alignment.bwa; +import org.broadinstitute.sting.utils.GATKException; import org.broadinstitute.sting.utils.StingException; import org.broadinstitute.sting.utils.BaseUtils; import org.broadinstitute.sting.utils.Utils; @@ -76,7 +77,7 @@ public class BWTFiles { */ public BWTFiles(String prefix) { if(prefix == null) - throw new StingException("Prefix must not be null."); + throw new GATKException("Prefix must not be null."); annFile = new File(prefix + ".ann"); ambFile = new File(prefix + ".amb"); pacFile = new File(prefix + ".pac"); @@ -135,7 +136,7 @@ public class BWTFiles { success &= reverseSAFile.delete(); if(!success) - throw new StingException("Unable to clean up autogenerated representation"); + throw new GATKException("Unable to clean up autogenerated representation"); } } @@ -183,7 +184,7 @@ public class BWTFiles { writeEncodedReferenceSequence(reverseReferenceSequence,rpacFile,rbwtFile,rsaFile); } catch(IOException ex) { - throw new StingException("Unable to write autogenerated reference sequence to temporary files"); + throw new GATKException("Unable to write autogenerated reference sequence to temporary files"); } // Make sure that, at the very least, all temporary files are deleted on exit. @@ -235,7 +236,7 @@ public class BWTFiles { StringUtil.toUpperCase(referenceSequence); for(byte base: referenceSequence) { if(base != 'A' && base != 'C' && base != 'G' && base != 'T') - throw new StingException(String.format("Base type %c is not supported when building references on-the-fly",(char)base)); + throw new GATKException(String.format("Base type %c is not supported when building references on-the-fly",(char)base)); } } } diff --git a/java/src/org/broadinstitute/sting/alignment/bwa/c/BWACAligner.java b/java/src/org/broadinstitute/sting/alignment/bwa/c/BWACAligner.java index 40478af7e..01c4672e9 100644 --- a/java/src/org/broadinstitute/sting/alignment/bwa/c/BWACAligner.java +++ b/java/src/org/broadinstitute/sting/alignment/bwa/c/BWACAligner.java @@ -2,6 +2,7 @@ package org.broadinstitute.sting.alignment.bwa.c; import net.sf.samtools.SAMRecord; import net.sf.samtools.SAMFileHeader; +import org.broadinstitute.sting.utils.GATKException; import org.broadinstitute.sting.utils.StingException; import org.broadinstitute.sting.alignment.Alignment; import org.broadinstitute.sting.alignment.bwa.BWAConfiguration; @@ -29,15 +30,15 @@ public class BWACAligner extends BWAAligner { public BWACAligner(BWTFiles bwtFiles, BWAConfiguration configuration) { super(bwtFiles,configuration); if(thunkPointer != 0) - throw new StingException("BWA/C attempting to reinitialize."); + throw new GATKException("BWA/C attempting to reinitialize."); - if(!bwtFiles.annFile.exists()) throw new StingException("ANN file is missing; please rerun 'bwa aln' to regenerate it."); - if(!bwtFiles.ambFile.exists()) throw new StingException("AMB file is missing; please rerun 'bwa aln' to regenerate it."); - if(!bwtFiles.pacFile.exists()) throw new StingException("PAC file is missing; please rerun 'bwa aln' to regenerate it."); - if(!bwtFiles.forwardBWTFile.exists()) throw new StingException("Forward BWT file is missing; please rerun 'bwa aln' to regenerate it."); - if(!bwtFiles.forwardSAFile.exists()) throw new StingException("Forward SA file is missing; please rerun 'bwa aln' to regenerate it."); - if(!bwtFiles.reverseBWTFile.exists()) throw new StingException("Reverse BWT file is missing; please rerun 'bwa aln' to regenerate it."); - if(!bwtFiles.reverseSAFile.exists()) throw new StingException("Reverse SA file is missing; please rerun 'bwa aln' to regenerate it."); + if(!bwtFiles.annFile.exists()) throw new GATKException("ANN file is missing; please rerun 'bwa aln' to regenerate it."); + if(!bwtFiles.ambFile.exists()) throw new GATKException("AMB file is missing; please rerun 'bwa aln' to regenerate it."); + if(!bwtFiles.pacFile.exists()) throw new GATKException("PAC file is missing; please rerun 'bwa aln' to regenerate it."); + if(!bwtFiles.forwardBWTFile.exists()) throw new GATKException("Forward BWT file is missing; please rerun 'bwa aln' to regenerate it."); + if(!bwtFiles.forwardSAFile.exists()) throw new GATKException("Forward SA file is missing; please rerun 'bwa aln' to regenerate it."); + if(!bwtFiles.reverseBWTFile.exists()) throw new GATKException("Reverse BWT file is missing; please rerun 'bwa aln' to regenerate it."); + if(!bwtFiles.reverseSAFile.exists()) throw new GATKException("Reverse SA file is missing; please rerun 'bwa aln' to regenerate it."); thunkPointer = create(bwtFiles,configuration); } @@ -60,7 +61,7 @@ public class BWACAligner extends BWAAligner { @Override public void updateConfiguration(BWAConfiguration configuration) { if(thunkPointer != 0) - throw new StingException("BWA/C: attempting to update configuration of uninitialized aligner."); + throw new GATKException("BWA/C: attempting to update configuration of uninitialized aligner."); updateConfiguration(thunkPointer,configuration); } @@ -70,7 +71,7 @@ public class BWACAligner extends BWAAligner { @Override public void close() { if(thunkPointer == 0) - throw new StingException("BWA/C close attempted, but BWA/C is not properly initialized."); + throw new GATKException("BWA/C close attempted, but BWA/C is not properly initialized."); destroy(thunkPointer); } @@ -82,7 +83,7 @@ public class BWACAligner extends BWAAligner { @Override public Alignment getBestAlignment(final byte[] bases) { if(thunkPointer == 0) - throw new StingException("BWA/C getBestAlignment attempted, but BWA/C is not properly initialized."); + throw new GATKException("BWA/C getBestAlignment attempted, but BWA/C is not properly initialized."); return getBestAlignment(thunkPointer,bases); } @@ -193,7 +194,7 @@ public class BWACAligner extends BWAAligner { */ public BWAPath[] getPaths(byte[] bases) { if(thunkPointer == 0) - throw new StingException("BWA/C getPaths attempted, but BWA/C is not properly initialized."); + throw new GATKException("BWA/C getPaths attempted, but BWA/C is not properly initialized."); return getPaths(thunkPointer,bases); } @@ -226,7 +227,7 @@ public class BWACAligner extends BWAAligner { */ protected Alignment[] convertPathsToAlignments(byte[] bases, BWAPath[] paths) { if(thunkPointer == 0) - throw new StingException("BWA/C convertPathsToAlignments attempted, but BWA/C is not properly initialized."); + throw new GATKException("BWA/C convertPathsToAlignments attempted, but BWA/C is not properly initialized."); return convertPathsToAlignments(thunkPointer,bases,paths); } diff --git a/java/src/org/broadinstitute/sting/alignment/bwa/java/AlignerTestHarness.java b/java/src/org/broadinstitute/sting/alignment/bwa/java/AlignerTestHarness.java index 1365f9e2b..f8bb35f08 100644 --- a/java/src/org/broadinstitute/sting/alignment/bwa/java/AlignerTestHarness.java +++ b/java/src/org/broadinstitute/sting/alignment/bwa/java/AlignerTestHarness.java @@ -2,6 +2,7 @@ package org.broadinstitute.sting.alignment.bwa.java; import org.broadinstitute.sting.alignment.Aligner; import org.broadinstitute.sting.alignment.Alignment; +import org.broadinstitute.sting.utils.GATKException; import org.broadinstitute.sting.utils.StingException; import org.broadinstitute.sting.utils.BaseUtils; @@ -61,7 +62,7 @@ public class AlignerTestHarness { alignmentCleaned = (SAMRecord)read.clone(); } catch( CloneNotSupportedException ex ) { - throw new StingException("SAMRecord clone not supported", ex); + throw new GATKException("SAMRecord clone not supported", ex); } if( alignmentCleaned.getReadNegativeStrandFlag() ) diff --git a/java/src/org/broadinstitute/sting/alignment/bwa/java/AlignmentMatchSequence.java b/java/src/org/broadinstitute/sting/alignment/bwa/java/AlignmentMatchSequence.java index f05ce48b1..b91c18416 100644 --- a/java/src/org/broadinstitute/sting/alignment/bwa/java/AlignmentMatchSequence.java +++ b/java/src/org/broadinstitute/sting/alignment/bwa/java/AlignmentMatchSequence.java @@ -1,6 +1,7 @@ package org.broadinstitute.sting.alignment.bwa.java; import org.broadinstitute.sting.alignment.bwa.java.AlignmentState; +import org.broadinstitute.sting.utils.GATKException; import org.broadinstitute.sting.utils.StingException; import java.util.Deque; @@ -33,7 +34,7 @@ public class AlignmentMatchSequence implements Cloneable { copy = (AlignmentMatchSequence)super.clone(); } catch( CloneNotSupportedException ex ) { - throw new StingException("Unable to clone AlignmentMatchSequence."); + throw new GATKException("Unable to clone AlignmentMatchSequence."); } copy.entries = new ArrayDeque(); @@ -53,7 +54,7 @@ public class AlignmentMatchSequence implements Cloneable { case MATCH_MISMATCH: operator = CigarOperator.MATCH_OR_MISMATCH; break; case INSERTION: operator = CigarOperator.INSERTION; break; case DELETION: operator = CigarOperator.DELETION; break; - default: throw new StingException("convertToCigar: cannot process state: " + entry.getAlignmentState()); + default: throw new GATKException("convertToCigar: cannot process state: " + entry.getAlignmentState()); } cigar.add( new CigarElement(entry.count,operator) ); } @@ -129,7 +130,7 @@ public class AlignmentMatchSequence implements Cloneable { return (AlignmentMatchSequenceEntry)super.clone(); } catch( CloneNotSupportedException ex ) { - throw new StingException("Unable to clone AlignmentMatchSequenceEntry."); + throw new GATKException("Unable to clone AlignmentMatchSequenceEntry."); } } diff --git a/java/src/org/broadinstitute/sting/alignment/bwa/java/BWAAlignment.java b/java/src/org/broadinstitute/sting/alignment/bwa/java/BWAAlignment.java index 7cbc362a0..eed0edaac 100644 --- a/java/src/org/broadinstitute/sting/alignment/bwa/java/BWAAlignment.java +++ b/java/src/org/broadinstitute/sting/alignment/bwa/java/BWAAlignment.java @@ -4,6 +4,7 @@ import org.broadinstitute.sting.alignment.Alignment; import org.broadinstitute.sting.alignment.bwa.java.BWAJavaAligner; import org.broadinstitute.sting.alignment.bwa.java.AlignmentMatchSequence; import org.broadinstitute.sting.alignment.bwa.java.AlignmentState; +import org.broadinstitute.sting.utils.GATKException; import org.broadinstitute.sting.utils.StingException; import net.sf.samtools.Cigar; @@ -151,7 +152,7 @@ public class BWAAlignment extends Alignment implements Cloneable { newAlignment = (BWAAlignment)super.clone(); } catch( CloneNotSupportedException ex ) { - throw new StingException("Unable to clone BWAAlignment."); + throw new GATKException("Unable to clone BWAAlignment."); } newAlignment.creationNumber = numCreated++; newAlignment.alignmentMatchSequence = alignmentMatchSequence.clone(); diff --git a/java/src/org/broadinstitute/sting/alignment/reference/bwt/BWT.java b/java/src/org/broadinstitute/sting/alignment/reference/bwt/BWT.java index ca1720339..f84385cca 100644 --- a/java/src/org/broadinstitute/sting/alignment/reference/bwt/BWT.java +++ b/java/src/org/broadinstitute/sting/alignment/reference/bwt/BWT.java @@ -1,6 +1,7 @@ package org.broadinstitute.sting.alignment.reference.bwt; import org.broadinstitute.sting.alignment.reference.packing.PackUtils; +import org.broadinstitute.sting.utils.GATKException; import org.broadinstitute.sting.utils.StingException; /** @@ -124,7 +125,7 @@ public class BWT { */ protected byte getBase(long index) { if(index == inverseSA0) - throw new StingException(String.format("Base at index %d does not have a text representation",index)); + throw new GATKException(String.format("Base at index %d does not have a text representation",index)); SequenceBlock block = getSequenceBlock(index); int position = getSequencePosition(index); diff --git a/java/src/org/broadinstitute/sting/alignment/reference/bwt/BWTReader.java b/java/src/org/broadinstitute/sting/alignment/reference/bwt/BWTReader.java index 1205b8589..97bdd21b8 100644 --- a/java/src/org/broadinstitute/sting/alignment/reference/bwt/BWTReader.java +++ b/java/src/org/broadinstitute/sting/alignment/reference/bwt/BWTReader.java @@ -1,5 +1,6 @@ package org.broadinstitute.sting.alignment.reference.bwt; +import org.broadinstitute.sting.utils.GATKException; import org.broadinstitute.sting.utils.StingException; import org.broadinstitute.sting.alignment.reference.packing.UnsignedIntPackedInputStream; import org.broadinstitute.sting.alignment.reference.packing.BasePackedInputStream; @@ -28,7 +29,7 @@ public class BWTReader { this.inputStream = new FileInputStream(inputFile); } catch( FileNotFoundException ex ) { - throw new StingException("Unable to open input file", ex); + throw new GATKException("Unable to open input file", ex); } } @@ -80,7 +81,7 @@ public class BWTReader { inputStream.close(); } catch( IOException ex ) { - throw new StingException("Unable to close input file", ex); + throw new GATKException("Unable to close input file", ex); } } } diff --git a/java/src/org/broadinstitute/sting/alignment/reference/bwt/BWTWriter.java b/java/src/org/broadinstitute/sting/alignment/reference/bwt/BWTWriter.java index 113eff4fa..d1d9f0de0 100644 --- a/java/src/org/broadinstitute/sting/alignment/reference/bwt/BWTWriter.java +++ b/java/src/org/broadinstitute/sting/alignment/reference/bwt/BWTWriter.java @@ -1,5 +1,6 @@ package org.broadinstitute.sting.alignment.reference.bwt; +import org.broadinstitute.sting.utils.GATKException; import org.broadinstitute.sting.utils.StingException; import org.broadinstitute.sting.alignment.reference.packing.UnsignedIntPackedOutputStream; import org.broadinstitute.sting.alignment.reference.packing.BasePackedOutputStream; @@ -28,7 +29,7 @@ public class BWTWriter { this.outputStream = new BufferedOutputStream(new FileOutputStream(outputFile)); } catch( FileNotFoundException ex ) { - throw new StingException("Unable to open output file", ex); + throw new GATKException("Unable to open output file", ex); } } @@ -53,7 +54,7 @@ public class BWTWriter { intPackedOutputStream.write(bwt.counts.toArray(false)); } catch( IOException ex ) { - throw new StingException("Unable to read BWT from input stream.", ex); + throw new GATKException("Unable to read BWT from input stream.", ex); } } @@ -65,7 +66,7 @@ public class BWTWriter { outputStream.close(); } catch( IOException ex ) { - throw new StingException("Unable to close input file", ex); + throw new GATKException("Unable to close input file", ex); } } } diff --git a/java/src/org/broadinstitute/sting/alignment/reference/bwt/Bases.java b/java/src/org/broadinstitute/sting/alignment/reference/bwt/Bases.java index b348ad547..47e0cba8b 100644 --- a/java/src/org/broadinstitute/sting/alignment/reference/bwt/Bases.java +++ b/java/src/org/broadinstitute/sting/alignment/reference/bwt/Bases.java @@ -1,5 +1,6 @@ package org.broadinstitute.sting.alignment.reference.bwt; +import org.broadinstitute.sting.utils.GATKException; import org.broadinstitute.sting.utils.StingException; import java.util.*; @@ -87,7 +88,7 @@ public class Bases implements Iterable if( entry.getValue().equals(ascii) ) return entry.getKey(); } - throw new StingException(String.format("Base %c is an invalid base to pack", (char)ascii)); + throw new GATKException(String.format("Base %c is an invalid base to pack", (char)ascii)); } /** diff --git a/java/src/org/broadinstitute/sting/alignment/reference/bwt/Counts.java b/java/src/org/broadinstitute/sting/alignment/reference/bwt/Counts.java index cf07cb173..3dc2d794f 100644 --- a/java/src/org/broadinstitute/sting/alignment/reference/bwt/Counts.java +++ b/java/src/org/broadinstitute/sting/alignment/reference/bwt/Counts.java @@ -1,5 +1,6 @@ package org.broadinstitute.sting.alignment.reference.bwt; +import org.broadinstitute.sting.utils.GATKException; import org.broadinstitute.sting.utils.StingException; import java.util.HashMap; @@ -96,7 +97,7 @@ public class Counts implements Cloneable { other = (Counts)super.clone(); } catch(CloneNotSupportedException ex) { - throw new StingException("Unable to clone counts object", ex); + throw new GATKException("Unable to clone counts object", ex); } other.counts = new HashMap(counts); other.cumulativeCounts = new HashMap(cumulativeCounts); diff --git a/java/src/org/broadinstitute/sting/alignment/reference/bwt/CreateBWTFromReference.java b/java/src/org/broadinstitute/sting/alignment/reference/bwt/CreateBWTFromReference.java index aa4033231..dbed5145e 100755 --- a/java/src/org/broadinstitute/sting/alignment/reference/bwt/CreateBWTFromReference.java +++ b/java/src/org/broadinstitute/sting/alignment/reference/bwt/CreateBWTFromReference.java @@ -31,6 +31,7 @@ import net.sf.picard.reference.ReferenceSequence; import java.io.*; +import org.broadinstitute.sting.utils.GATKException; import org.broadinstitute.sting.utils.StingException; import org.broadinstitute.sting.alignment.reference.packing.PackUtils; @@ -182,7 +183,7 @@ public class CreateBWTFromReference { for( int i = 0; i < bwt.length(); i++ ) { if( bwtSequence[i] != existingBWTSequence[i] ) - throw new StingException("BWT mismatch at " + i); + throw new GATKException("BWT mismatch at " + i); } File existingSAFile = new File(inputFileName+".sa"); @@ -193,7 +194,7 @@ public class CreateBWTFromReference { if( i % 10000 == 0 ) System.out.printf("Validating suffix array entry %d%n", i); if( suffixArray.get(i) != existingSuffixArray.get(i) ) - throw new StingException(String.format("Suffix array mismatch at %d; SA is %d; should be %d",i,existingSuffixArray.get(i),suffixArray.get(i))); + throw new GATKException(String.format("Suffix array mismatch at %d; SA is %d; should be %d",i,existingSuffixArray.get(i),suffixArray.get(i))); } } diff --git a/java/src/org/broadinstitute/sting/alignment/reference/bwt/SuffixArray.java b/java/src/org/broadinstitute/sting/alignment/reference/bwt/SuffixArray.java index 69ba44bcb..e19c35374 100644 --- a/java/src/org/broadinstitute/sting/alignment/reference/bwt/SuffixArray.java +++ b/java/src/org/broadinstitute/sting/alignment/reference/bwt/SuffixArray.java @@ -1,5 +1,6 @@ package org.broadinstitute.sting.alignment.reference.bwt; +import org.broadinstitute.sting.utils.GATKException; import org.broadinstitute.sting.utils.StingException; import java.util.Comparator; @@ -53,7 +54,7 @@ public class SuffixArray { this.bwt = bwt; if(sequenceInterval != 1 && bwt == null) - throw new StingException("A BWT must be provided if the sequence interval is not 1"); + throw new GATKException("A BWT must be provided if the sequence interval is not 1"); } /** @@ -118,7 +119,7 @@ public class SuffixArray { inverseSA0 = i; } if(inverseSA0 < 0) - throw new StingException("Unable to find first inverse SA entry in generated suffix array."); + throw new GATKException("Unable to find first inverse SA entry in generated suffix array."); return new SuffixArray(inverseSA0,occurrences,suffixArray); } diff --git a/java/src/org/broadinstitute/sting/alignment/reference/bwt/SuffixArrayReader.java b/java/src/org/broadinstitute/sting/alignment/reference/bwt/SuffixArrayReader.java index afec6890f..e9a95d66f 100644 --- a/java/src/org/broadinstitute/sting/alignment/reference/bwt/SuffixArrayReader.java +++ b/java/src/org/broadinstitute/sting/alignment/reference/bwt/SuffixArrayReader.java @@ -1,5 +1,6 @@ package org.broadinstitute.sting.alignment.reference.bwt; +import org.broadinstitute.sting.utils.GATKException; import org.broadinstitute.sting.utils.StingException; import org.broadinstitute.sting.alignment.reference.packing.UnsignedIntPackedInputStream; import org.broadinstitute.sting.alignment.reference.packing.PackUtils; @@ -35,7 +36,7 @@ public class SuffixArrayReader { this.bwt = bwt; } catch( FileNotFoundException ex ) { - throw new StingException("Unable to open input file", ex); + throw new GATKException("Unable to open input file", ex); } } @@ -61,7 +62,7 @@ public class SuffixArrayReader { uintPackedInputStream.read(suffixArray); } catch( IOException ex ) { - throw new StingException("Unable to read BWT from input stream.", ex); + throw new GATKException("Unable to read BWT from input stream.", ex); } return new SuffixArray(inverseSA0, new Counts(occurrences,true), suffixArray, suffixArrayInterval, bwt); @@ -76,7 +77,7 @@ public class SuffixArrayReader { inputStream.close(); } catch( IOException ex ) { - throw new StingException("Unable to close input file", ex); + throw new GATKException("Unable to close input file", ex); } } } diff --git a/java/src/org/broadinstitute/sting/alignment/reference/bwt/SuffixArrayWriter.java b/java/src/org/broadinstitute/sting/alignment/reference/bwt/SuffixArrayWriter.java index 3cb45c738..6baf79cf1 100644 --- a/java/src/org/broadinstitute/sting/alignment/reference/bwt/SuffixArrayWriter.java +++ b/java/src/org/broadinstitute/sting/alignment/reference/bwt/SuffixArrayWriter.java @@ -1,5 +1,6 @@ package org.broadinstitute.sting.alignment.reference.bwt; +import org.broadinstitute.sting.utils.GATKException; import org.broadinstitute.sting.utils.StingException; import org.broadinstitute.sting.alignment.reference.packing.UnsignedIntPackedOutputStream; @@ -27,7 +28,7 @@ public class SuffixArrayWriter { this.outputStream = new BufferedOutputStream(new FileOutputStream(outputFile)); } catch( FileNotFoundException ex ) { - throw new StingException("Unable to open input file", ex); + throw new GATKException("Unable to open input file", ex); } } @@ -48,7 +49,7 @@ public class SuffixArrayWriter { uintPackedOutputStream.write(suffixArray.sequence,1,suffixArray.sequence.length-1); } catch( IOException ex ) { - throw new StingException("Unable to read BWT from input stream.", ex); + throw new GATKException("Unable to read BWT from input stream.", ex); } } @@ -61,7 +62,7 @@ public class SuffixArrayWriter { outputStream.close(); } catch( IOException ex ) { - throw new StingException("Unable to close input file", ex); + throw new GATKException("Unable to close input file", ex); } } } diff --git a/java/src/org/broadinstitute/sting/alignment/reference/packing/BasePackedInputStream.java b/java/src/org/broadinstitute/sting/alignment/reference/packing/BasePackedInputStream.java index 7bf446693..85cd9f47a 100644 --- a/java/src/org/broadinstitute/sting/alignment/reference/packing/BasePackedInputStream.java +++ b/java/src/org/broadinstitute/sting/alignment/reference/packing/BasePackedInputStream.java @@ -1,5 +1,6 @@ package org.broadinstitute.sting.alignment.reference.packing; +import org.broadinstitute.sting.utils.GATKException; import org.broadinstitute.sting.utils.StingException; import java.io.*; @@ -51,7 +52,7 @@ public class BasePackedInputStream { public BasePackedInputStream( Class type, FileInputStream inputStream, ByteOrder byteOrder ) { if( type != Integer.class ) - throw new StingException("Only bases packed into 32-bit words are currently supported by this input stream. Type specified: " + type.getName()); + throw new GATKException("Only bases packed into 32-bit words are currently supported by this input stream. Type specified: " + type.getName()); this.type = type; this.targetInputStream = inputStream; this.targetInputChannel = inputStream.getChannel(); diff --git a/java/src/org/broadinstitute/sting/alignment/reference/packing/BasePackedOutputStream.java b/java/src/org/broadinstitute/sting/alignment/reference/packing/BasePackedOutputStream.java index a6296bf40..fd0eac58a 100644 --- a/java/src/org/broadinstitute/sting/alignment/reference/packing/BasePackedOutputStream.java +++ b/java/src/org/broadinstitute/sting/alignment/reference/packing/BasePackedOutputStream.java @@ -1,5 +1,6 @@ package org.broadinstitute.sting.alignment.reference.packing; +import org.broadinstitute.sting.utils.GATKException; import org.broadinstitute.sting.utils.StingException; import java.io.*; @@ -134,7 +135,7 @@ public class BasePackedOutputStream { else if( type == Byte.class ) buffer.put((byte)packedBases); else - throw new StingException("Cannot pack bases into type " + type.getName()); + throw new GATKException("Cannot pack bases into type " + type.getName()); targetOutputStream.write(buffer.array()); } } diff --git a/java/src/org/broadinstitute/sting/alignment/reference/packing/PackUtils.java b/java/src/org/broadinstitute/sting/alignment/reference/packing/PackUtils.java index abe2ae7e2..75dd6bd31 100644 --- a/java/src/org/broadinstitute/sting/alignment/reference/packing/PackUtils.java +++ b/java/src/org/broadinstitute/sting/alignment/reference/packing/PackUtils.java @@ -1,5 +1,6 @@ package org.broadinstitute.sting.alignment.reference.packing; +import org.broadinstitute.sting.utils.GATKException; import org.broadinstitute.sting.utils.StingException; import java.io.File; @@ -58,14 +59,14 @@ public class PackUtils { long typeSize = type.getField("MAX_VALUE").getLong(null) - type.getField("MIN_VALUE").getLong(null)+1; long intTypeSize = (long)Integer.MAX_VALUE - (long)Integer.MIN_VALUE + 1; if( typeSize > intTypeSize ) - throw new StingException("Cannot determine number of bits available in type: " + type.getName()); + throw new GATKException("Cannot determine number of bits available in type: " + type.getName()); return (int)(Math.log(typeSize)/Math.log(2)); } catch( NoSuchFieldException ex ) { - throw new StingException("Cannot determine number of bits available in type: " + type.getName(),ex); + throw new GATKException("Cannot determine number of bits available in type: " + type.getName(),ex); } catch( IllegalAccessException ex ) { - throw new StingException("Cannot determine number of bits available in type: " + type.getName(),ex); + throw new GATKException("Cannot determine number of bits available in type: " + type.getName(),ex); } } @@ -85,7 +86,7 @@ public class PackUtils { case 'T': return 3; default: - throw new StingException("Unknown base type: " + base); + throw new GATKException("Unknown base type: " + base); } } @@ -105,7 +106,7 @@ public class PackUtils { case 3: return 'T'; default: - throw new StingException("Unknown pack type: " + pack); + throw new GATKException("Unknown pack type: " + pack); } } diff --git a/java/src/org/broadinstitute/sting/commandline/ArgumentDefinitionGroup.java b/java/src/org/broadinstitute/sting/commandline/ArgumentDefinitionGroup.java index 1cc3c9c8c..4ae6f7803 100644 --- a/java/src/org/broadinstitute/sting/commandline/ArgumentDefinitionGroup.java +++ b/java/src/org/broadinstitute/sting/commandline/ArgumentDefinitionGroup.java @@ -25,6 +25,7 @@ package org.broadinstitute.sting.commandline; +import org.broadinstitute.sting.utils.GATKException; import org.broadinstitute.sting.utils.StingException; import java.util.List; @@ -69,7 +70,7 @@ public class ArgumentDefinitionGroup implements Iterable { */ public ArgumentDefinitionGroup merge( ArgumentDefinitionGroup other ) { if( !groupNameMatches(other) ) - throw new StingException("Unable to merge two argument groups with differing names."); + throw new GATKException("Unable to merge two argument groups with differing names."); // Create a merged definition group. List mergedDefinitions = new ArrayList(); diff --git a/java/src/org/broadinstitute/sting/commandline/ArgumentDefinitions.java b/java/src/org/broadinstitute/sting/commandline/ArgumentDefinitions.java index 6c703fd4f..2d161ce5a 100755 --- a/java/src/org/broadinstitute/sting/commandline/ArgumentDefinitions.java +++ b/java/src/org/broadinstitute/sting/commandline/ArgumentDefinitions.java @@ -25,6 +25,7 @@ package org.broadinstitute.sting.commandline; +import org.broadinstitute.sting.utils.GATKException; import org.broadinstitute.sting.utils.StingException; import java.util.Set; @@ -56,9 +57,9 @@ public class ArgumentDefinitions implements Iterable { if( definition.fullName.length() == 0 ) throw new IllegalArgumentException( "Argument cannot have 0-length fullname." ); if( hasArgumentDefinition( definition.fullName, FullNameDefinitionMatcher ) ) - throw new StingException("Duplicate definition of argument with full name: " + definition.fullName); + throw new GATKException("Duplicate definition of argument with full name: " + definition.fullName); if( definition.shortName != null && hasArgumentDefinition( definition.shortName, ShortNameDefinitionMatcher ) ) - throw new StingException("Duplicate definition of argument with short name: " + definition.shortName); + throw new GATKException("Duplicate definition of argument with short name: " + definition.shortName); argumentDefinitions.add( definition ); } diff --git a/java/src/org/broadinstitute/sting/commandline/ArgumentIOType.java b/java/src/org/broadinstitute/sting/commandline/ArgumentIOType.java index 03e3066fb..daa2ea5d6 100644 --- a/java/src/org/broadinstitute/sting/commandline/ArgumentIOType.java +++ b/java/src/org/broadinstitute/sting/commandline/ArgumentIOType.java @@ -24,6 +24,7 @@ package org.broadinstitute.sting.commandline; +import org.broadinstitute.sting.utils.GATKException; import org.broadinstitute.sting.utils.StingException; import java.lang.annotation.Annotation; @@ -46,6 +47,6 @@ public enum ArgumentIOType { for (ArgumentIOType ioType: ArgumentIOType.values()) if (ioType.annotationClass.isAssignableFrom(annotation.getClass())) return ioType; - throw new StingException("Unknown annotation type: " + annotation); + throw new GATKException("Unknown annotation type: " + annotation); } } diff --git a/java/src/org/broadinstitute/sting/commandline/ArgumentSource.java b/java/src/org/broadinstitute/sting/commandline/ArgumentSource.java index 7ee086813..8c2c149cb 100644 --- a/java/src/org/broadinstitute/sting/commandline/ArgumentSource.java +++ b/java/src/org/broadinstitute/sting/commandline/ArgumentSource.java @@ -25,6 +25,7 @@ package org.broadinstitute.sting.commandline; +import org.broadinstitute.sting.utils.GATKException; import org.broadinstitute.sting.utils.StingException; import java.lang.reflect.Field; @@ -209,7 +210,7 @@ public class ArgumentSource { */ public MultiplexArgumentTypeDescriptor createDependentTypeDescriptor(Object containingObject) { if(!isDependent()) - throw new StingException("Field " + field.getName() + " is independent; no dependent type descriptor can be derived."); + throw new GATKException("Field " + field.getName() + " is independent; no dependent type descriptor can be derived."); return ((MultiplexArgumentTypeDescriptor)typeDescriptor).createCustomTypeDescriptor(this,containingObject); } diff --git a/java/src/org/broadinstitute/sting/commandline/ArgumentTypeDescriptor.java b/java/src/org/broadinstitute/sting/commandline/ArgumentTypeDescriptor.java index 091ab78a4..663168242 100644 --- a/java/src/org/broadinstitute/sting/commandline/ArgumentTypeDescriptor.java +++ b/java/src/org/broadinstitute/sting/commandline/ArgumentTypeDescriptor.java @@ -25,11 +25,13 @@ package org.broadinstitute.sting.commandline; +import org.broadinstitute.sting.utils.GATKException; import org.broadinstitute.sting.utils.StingException; import org.broadinstitute.sting.utils.classloader.JVMUtils; import org.broadinstitute.sting.gatk.walkers.Multiplex; import org.broadinstitute.sting.gatk.walkers.Multiplexer; import org.apache.log4j.Logger; +import org.broadinstitute.sting.utils.exceptions.UserError; import java.lang.annotation.Annotation; import java.lang.reflect.*; @@ -81,7 +83,7 @@ public abstract class ArgumentTypeDescriptor { if( descriptor.supports(type) ) return descriptor; } - throw new StingException("Can't process command-line arguments of type: " + type.getName()); + throw new GATKException("Can't process command-line arguments of type: " + type.getName()); } /** @@ -219,7 +221,7 @@ public abstract class ArgumentTypeDescriptor { protected String getArgumentValue( ArgumentDefinition definition, ArgumentMatches matches ) { Collection argumentValues = getArgumentValues( definition, matches ); if( argumentValues.size() > 1 ) - throw new StingException("Multiple values associated with given definition, but this argument expects only one: " + definition.fullName); + throw new UserError.CommandLineError("Multiple values associated with given definition, but this argument expects only one: " + definition.fullName); return argumentValues.size() > 0 ? argumentValues.iterator().next() : null; } @@ -263,7 +265,7 @@ public abstract class ArgumentTypeDescriptor { for (Class annotation: ARGUMENT_ANNOTATIONS) if (source.field.isAnnotationPresent(annotation)) return source.field.getAnnotation(annotation); - throw new StingException("ArgumentAnnotation is not present for the argument field: " + source.field.getName()); + throw new GATKException("ArgumentAnnotation is not present for the argument field: " + source.field.getName()); } /** @@ -331,7 +333,7 @@ class SimpleArgumentTypeDescriptor extends ArgumentTypeDescriptor { for (Object val : vals) { if (String.valueOf(val).equalsIgnoreCase(value)) return val; try { if (type.getField(val.toString()).isAnnotationPresent(EnumerationArgumentDefault.class)) defaultEnumeration = val; } - catch (NoSuchFieldException e) { throw new StingException("parsing " + type.toString() + "doesn't contain the field " + val.toString()); } + catch (NoSuchFieldException e) { throw new GATKException("parsing " + type.toString() + "doesn't contain the field " + val.toString()); } } // if their argument has no value (null), and there's a default, return that default for the enum value if (defaultEnumeration != null && value == null) @@ -348,13 +350,13 @@ class SimpleArgumentTypeDescriptor extends ArgumentTypeDescriptor { } } catch (NoSuchMethodException e) { - throw new StingException("constructFromString:NoSuchMethodException: Failed conversion " + e.getMessage()); + throw new GATKException("constructFromString:NoSuchMethodException: Failed conversion " + e.getMessage()); } catch (IllegalAccessException e) { - throw new StingException("constructFromString:IllegalAccessException: Failed conversion " + e.getMessage()); + throw new GATKException("constructFromString:IllegalAccessException: Failed conversion " + e.getMessage()); } catch (InvocationTargetException e) { - throw new StingException("constructFromString:InvocationTargetException: Failed conversion - this is most likely caused by using an incorrect data type (e.g. a double when an int is required)"); + throw new GATKException("constructFromString:InvocationTargetException: Failed conversion - this is most likely caused by using an incorrect data type (e.g. a double when an int is required)"); } catch (InstantiationException e) { - throw new StingException("constructFromString:InstantiationException: Failed conversion " + e.getMessage()); + throw new GATKException("constructFromString:InstantiationException: Failed conversion " + e.getMessage()); } // WARNING: Side effect! parsingEngine.addTags(result,tags); @@ -417,11 +419,11 @@ class CompoundArgumentTypeDescriptor extends ArgumentTypeDescriptor { } catch (InstantiationException e) { logger.fatal("ArgumentParser: InstantiationException: cannot convert field " + source.field.getName()); - throw new StingException("constructFromString:InstantiationException: Failed conversion " + e.getMessage()); + throw new GATKException("constructFromString:InstantiationException: Failed conversion " + e.getMessage()); } catch (IllegalAccessException e) { logger.fatal("ArgumentParser: IllegalAccessException: cannot convert field " + source.field.getName()); - throw new StingException("constructFromString:IllegalAccessException: Failed conversion " + e.getMessage()); + throw new GATKException("constructFromString:IllegalAccessException: Failed conversion " + e.getMessage()); } for( ArgumentMatch match: matches ) { @@ -453,7 +455,7 @@ class CompoundArgumentTypeDescriptor extends ArgumentTypeDescriptor { } } else - throw new StingException("Unsupported compound argument type: " + type); + throw new GATKException("Unsupported compound argument type: " + type); // WARNING: Side effect! parsingEngine.addTags(result,tags); @@ -521,7 +523,7 @@ class MultiplexArgumentTypeDescriptor extends ArgumentTypeDescriptor { @Override public Object createTypeDefault(ArgumentSource source,Class type) { if(multiplexer == null || multiplexedIds == null) - throw new StingException("No multiplexed ids available"); + throw new GATKException("No multiplexed ids available"); Map multiplexedMapping = new HashMap(); Class componentType = getCollectionComponentType(source.field); @@ -540,7 +542,7 @@ class MultiplexArgumentTypeDescriptor extends ArgumentTypeDescriptor { @Override public Object parse(ParsingEngine parsingEngine, ArgumentSource source, Class type, ArgumentMatches matches) { if(multiplexedIds == null) - throw new StingException("Cannot directly parse a MultiplexArgumentTypeDescriptor; must create a derivative type descriptor first."); + throw new GATKException("Cannot directly parse a MultiplexArgumentTypeDescriptor; must create a derivative type descriptor first."); Map multiplexedMapping = new HashMap(); @@ -571,14 +573,14 @@ class MultiplexArgumentTypeDescriptor extends ArgumentTypeDescriptor { if(!source.field.getName().equals(sourceField)) continue; if(source.field.isAnnotationPresent(Multiplex.class)) - throw new StingException("Command-line arguments can only depend on independent fields"); + throw new GATKException("Command-line arguments can only depend on independent fields"); sourceTypes[currentField] = source.field.getType(); sourceValues[currentField] = JVMUtils.getFieldValue(source.field,containingObject); currentField++; fieldFound = true; } if(!fieldFound) - throw new StingException(String.format("Unable to find source field %s, referred to by dependent field %s",sourceField,dependentArgument.field.getName())); + throw new GATKException(String.format("Unable to find source field %s, referred to by dependent field %s",sourceField,dependentArgument.field.getName())); } Class multiplexerType = dependentArgument.field.getAnnotation(Multiplex.class).value(); @@ -588,7 +590,7 @@ class MultiplexArgumentTypeDescriptor extends ArgumentTypeDescriptor { multiplexerConstructor.setAccessible(true); } catch(NoSuchMethodException ex) { - throw new StingException(String.format("Unable to find constructor for class %s with parameters %s",multiplexerType.getName(),Arrays.deepToString(sourceFields)),ex); + throw new GATKException(String.format("Unable to find constructor for class %s with parameters %s",multiplexerType.getName(),Arrays.deepToString(sourceFields)),ex); } Multiplexer multiplexer = null; @@ -596,13 +598,13 @@ class MultiplexArgumentTypeDescriptor extends ArgumentTypeDescriptor { multiplexer = multiplexerConstructor.newInstance(sourceValues); } catch(IllegalAccessException ex) { - throw new StingException(String.format("Constructor for class %s with parameters %s is inaccessible",multiplexerType.getName(),Arrays.deepToString(sourceFields)),ex); + throw new GATKException(String.format("Constructor for class %s with parameters %s is inaccessible",multiplexerType.getName(),Arrays.deepToString(sourceFields)),ex); } catch(InstantiationException ex) { - throw new StingException(String.format("Can't create class %s with parameters %s",multiplexerType.getName(),Arrays.deepToString(sourceFields)),ex); + throw new GATKException(String.format("Can't create class %s with parameters %s",multiplexerType.getName(),Arrays.deepToString(sourceFields)),ex); } catch(InvocationTargetException ex) { - throw new StingException(String.format("Can't invoke constructor of class %s with parameters %s",multiplexerType.getName(),Arrays.deepToString(sourceFields)),ex); + throw new GATKException(String.format("Can't invoke constructor of class %s with parameters %s",multiplexerType.getName(),Arrays.deepToString(sourceFields)),ex); } return new MultiplexArgumentTypeDescriptor(multiplexer,multiplexer.multiplex()); diff --git a/java/src/org/broadinstitute/sting/commandline/CommandLineUtils.java b/java/src/org/broadinstitute/sting/commandline/CommandLineUtils.java index 746486b2b..6d1d07c85 100644 --- a/java/src/org/broadinstitute/sting/commandline/CommandLineUtils.java +++ b/java/src/org/broadinstitute/sting/commandline/CommandLineUtils.java @@ -25,6 +25,7 @@ package org.broadinstitute.sting.commandline; +import org.broadinstitute.sting.utils.GATKException; import org.broadinstitute.sting.utils.classloader.JVMUtils; import org.broadinstitute.sting.utils.StingException; import org.broadinstitute.sting.gatk.GenomeAnalysisEngine; @@ -124,7 +125,7 @@ public class CommandLineUtils { try { return annotation.getClass().getMethod(method).invoke(annotation); } catch (Exception e) { - throw new StingException("Unable to access method " + method + " on annotation " + annotation.getClass(), e); + throw new GATKException("Unable to access method " + method + " on annotation " + annotation.getClass(), e); } } } diff --git a/java/src/org/broadinstitute/sting/commandline/ParsingEngine.java b/java/src/org/broadinstitute/sting/commandline/ParsingEngine.java index ffb1b766b..7f5fe35cd 100755 --- a/java/src/org/broadinstitute/sting/commandline/ParsingEngine.java +++ b/java/src/org/broadinstitute/sting/commandline/ParsingEngine.java @@ -25,10 +25,12 @@ package org.broadinstitute.sting.commandline; +import org.broadinstitute.sting.utils.GATKException; import org.broadinstitute.sting.utils.StingException; import org.broadinstitute.sting.utils.collections.Pair; import org.broadinstitute.sting.utils.classloader.JVMUtils; import org.broadinstitute.sting.utils.Utils; +import org.broadinstitute.sting.utils.exceptions.UserError; import org.broadinstitute.sting.utils.help.ApplicationDetails; import org.broadinstitute.sting.utils.help.HelpFormatter; import org.apache.log4j.Logger; @@ -293,9 +295,9 @@ public class ParsingEngine { // Grab the first argument definition and report that one as the failure. Theoretically, we should notify of all failures. List definitions = argumentSource.createArgumentDefinitions(); if(definitions.size() < 1) - throw new StingException("Internal error. Argument source creates no definitions."); + throw new GATKException("Internal error. Argument source creates no definitions."); ArgumentDefinition definition = definitions.get(0); - throw new StingException(String.format("The parameter %s is deprecated. %s",definition.fullName,definition.doc)); + throw new UserError.DeprecatedArgument(definition.fullName,definition.doc); } /** @@ -314,7 +316,7 @@ public class ParsingEngine { // Abort if no home is found for the object. if( targets.size() == 0 ) - throw new StingException("Internal command-line parser error: unable to find a home for argument matches " + argumentMatches); + throw new GATKException("Internal command-line parser error: unable to find a home for argument matches " + argumentMatches); for( Object target: targets ) { Object value = (argumentMatches.size() != 0) ? source.parse(this,argumentMatches) : source.createDefault(); diff --git a/java/src/org/broadinstitute/sting/gatk/DownsamplingMethod.java b/java/src/org/broadinstitute/sting/gatk/DownsamplingMethod.java index 4c4a54643..4985fa08d 100644 --- a/java/src/org/broadinstitute/sting/gatk/DownsamplingMethod.java +++ b/java/src/org/broadinstitute/sting/gatk/DownsamplingMethod.java @@ -1,6 +1,7 @@ package org.broadinstitute.sting.gatk; import org.broadinstitute.sting.utils.StingException; +import org.broadinstitute.sting.utils.exceptions.UserError; /** * Describes the method for downsampling reads at a given locus. @@ -35,15 +36,15 @@ public class DownsamplingMethod { // Can't leave toFraction and toCoverage null unless type is experimental naive duplicate eliminator. if(type != DownsampleType.NONE && toFraction == null && toCoverage == null) - throw new StingException("Must specify either toFraction or toCoverage when downsampling."); + throw new UserError.CommandLineError("Must specify either toFraction or toCoverage when downsampling."); // Fraction and coverage cannot both be specified. if(toFraction != null && toCoverage != null) - throw new StingException("Downsampling coverage and fraction are both specified. Please choose only one."); + throw new UserError.CommandLineError("Downsampling coverage and fraction are both specified. Please choose only one."); // Experimental by sample downsampling does not work with a fraction of reads. if(type == DownsampleType.BY_SAMPLE && toFraction != null) - throw new StingException("Cannot downsample to fraction with new EXPERIMENTAL_BY_SAMPLE method"); + throw new UserError.CommandLineError("Cannot downsample to fraction with new EXPERIMENTAL_BY_SAMPLE method"); this.type = type; this.toCoverage = toCoverage; diff --git a/java/src/org/broadinstitute/sting/gatk/GenomeAnalysisEngine.java b/java/src/org/broadinstitute/sting/gatk/GenomeAnalysisEngine.java index 6d8b062e9..3c763724b 100755 --- a/java/src/org/broadinstitute/sting/gatk/GenomeAnalysisEngine.java +++ b/java/src/org/broadinstitute/sting/gatk/GenomeAnalysisEngine.java @@ -31,6 +31,7 @@ import net.sf.samtools.*; import org.apache.log4j.Logger; import org.broadinstitute.sting.gatk.arguments.GATKArgumentCollection; import org.broadinstitute.sting.gatk.refdata.utils.helpers.DbSNPHelper; +import org.broadinstitute.sting.utils.exceptions.UserError; import org.broadinstitute.sting.utils.interval.IntervalMergingRule; import org.broadinstitute.sting.utils.interval.IntervalUtils; import org.broadinstitute.sting.gatk.arguments.ValidationExclusion; @@ -42,7 +43,6 @@ import org.broadinstitute.sting.gatk.datasources.simpleDataSources.*; import org.broadinstitute.sting.gatk.executive.MicroScheduler; import org.broadinstitute.sting.gatk.filters.FilterManager; import org.broadinstitute.sting.gatk.filters.ReadGroupBlackListFilter; -import org.broadinstitute.sting.gatk.filters.ZeroMappingQualityReadFilter; import org.broadinstitute.sting.gatk.io.OutputTracker; import org.broadinstitute.sting.gatk.io.stubs.*; import org.broadinstitute.sting.gatk.refdata.tracks.RMDTrack; @@ -155,12 +155,12 @@ public class GenomeAnalysisEngine { // validate our parameters if (args == null) { - throw new StingException("The GATKArgumentCollection passed to GenomeAnalysisEngine can not be null."); + throw new GATKException("The GATKArgumentCollection passed to GenomeAnalysisEngine can not be null."); } // validate our parameters if (my_walker == null) - throw new StingException("The walker passed to GenomeAnalysisEngine can not be null."); + throw new GATKException("The walker passed to GenomeAnalysisEngine can not be null."); // save our argument parameter this.argCollection = args; @@ -267,7 +267,7 @@ public class GenomeAnalysisEngine { // check to make sure we have a rod of that name if (!rodNames.containsKey(rodName)) - throw new StingException("--rodToIntervalTrackName (-BTI) was pass the name '"+rodName+"', which wasn't given as a ROD name in the -B option"); + throw new UserError.CommandLineError("--rodToIntervalTrackName (-BTI) was passed the name '"+rodName+"', which wasn't given as a ROD name in the -B option"); for (String str : rodNames.keySet()) if (str.equals(rodName)) { @@ -400,7 +400,7 @@ public class GenomeAnalysisEngine { // Temporarily require all walkers to have a reference, even if that reference is not conceptually necessary. if ((my_walker instanceof ReadWalker || my_walker instanceof DuplicateWalker || my_walker instanceof ReadPairWalker) && argCollection.referenceFile == null) { - Utils.scareUser(String.format("Read-based traversals require a reference file but none was given")); + throw new UserError.CommandLineError("Read-based traversals require a reference file but none was given"); } return MicroScheduler.create(this,my_walker,readsDataSource,referenceDataSource.getReference(),rodDataSources,argCollection.numberOfThreads); @@ -720,7 +720,7 @@ public class GenomeAnalysisEngine { error.append(String.format(compareToName + " contigs: %s%n", prettyPrintSequenceRecords(comparedToDictionary))); error.append(String.format("Reference contigs: %s%n", prettyPrintSequenceRecords(referenceDictionary))); logger.error(error.toString()); - Utils.scareUser("No overlap exists between sequence dictionary of " + compareToName + " and the sequence dictionary of the reference."); + throw new UserError.IncompatibleSequenceDictionaries(referenceDictionary, comparedToDictionary, compareToName); } // If the two datasets are not equal and neither is a strict subset of the other, warn the user. @@ -773,20 +773,20 @@ public class GenomeAnalysisEngine { // sharding system; it's required with the new sharding system only for locus walkers. if(readsDataSource != null && !readsDataSource.hasIndex() ) { if(!exclusions.contains(ValidationExclusion.TYPE.ALLOW_UNINDEXED_BAM)) - throw new StingException("The GATK cannot currently process unindexed BAM files without the -U ALLOW_UNINDEXED_BAM"); + throw new UserError.CommandLineError("The GATK cannot currently process unindexed BAM files without the -U ALLOW_UNINDEXED_BAM"); if(intervals != null && WalkerManager.getWalkerDataSource(walker) != DataSource.REFERENCE) - throw new StingException("Cannot shard input by interval when walker is not driven by reference."); + throw new UserError.CommandLineError("Cannot perform interval processing when walker is not driven by reference and no index is available."); Shard.ShardType shardType; if(walker instanceof LocusWalker) { if (readsDataSource.getSortOrder() != SAMFileHeader.SortOrder.coordinate) - Utils.scareUser("Locus walkers can only walk over coordinate-sorted data. Please resort your input BAM file."); + throw new UserError.MissortedBAM(SAMFileHeader.SortOrder.coordinate, "Locus walkers can only walk over coordinate-sorted data. Please resort your input BAM file(s)."); shardType = Shard.ShardType.LOCUS; } else if(walker instanceof ReadWalker || walker instanceof DuplicateWalker || walker instanceof ReadPairWalker) shardType = Shard.ShardType.READ; else - throw new StingException("The GATK cannot currently process unindexed BAM files"); + throw new UserError.CommandLineError("The GATK cannot currently process unindexed BAM files"); List region; if(intervals != null) @@ -810,7 +810,7 @@ public class GenomeAnalysisEngine { if (intervals != null && !intervals.isEmpty()) { if(!readsDataSource.isEmpty() && readsDataSource.getSortOrder() != SAMFileHeader.SortOrder.coordinate) - Utils.scareUser("Locus walkers can only walk over coordinate-sorted data. Please resort your input BAM file."); + throw new UserError.MissortedBAM(SAMFileHeader.SortOrder.coordinate, "Locus walkers can only walk over coordinate-sorted data. Please resort your input BAM file(s)."); shardStrategy = ShardStrategyFactory.shatter(readsDataSource, referenceDataSource.getReference(), @@ -844,9 +844,9 @@ public class GenomeAnalysisEngine { } } else if (walker instanceof ReadPairWalker) { if(readsDataSource != null && readsDataSource.getSortOrder() != SAMFileHeader.SortOrder.queryname) - Utils.scareUser("Read pair walkers can only walk over query name-sorted data. Please resort your input BAM file."); + throw new UserError.MissortedBAM(SAMFileHeader.SortOrder.queryname, "Read pair walkers can only walk over query name-sorted data. Please resort your input BAM file."); if(intervals != null && !intervals.isEmpty()) - Utils.scareUser("Pairs traversal cannot be used in conjunction with intervals."); + throw new UserError.CommandLineError("Pairs traversal cannot be used in conjunction with intervals."); shardStrategy = ShardStrategyFactory.shatter(readsDataSource, referenceDataSource.getReference(), @@ -854,7 +854,7 @@ public class GenomeAnalysisEngine { drivingDataSource.getSequenceDictionary(), SHARD_SIZE); } else - throw new StingException("Unable to support walker of type" + walker.getClass().getName()); + throw new GATKException("Unable to support walker of type" + walker.getClass().getName()); return shardStrategy; } @@ -996,7 +996,7 @@ public class GenomeAnalysisEngine { unpackedReads.add(new SAMReaderID(new File(fileName),getTags(inputFile))); } catch( FileNotFoundException ex ) { - throw new StingException("Unable to find file while unpacking reads", ex); + throw new UserError.CouldNotReadInputFile(inputFile, "Unable to find file while unpacking reads", ex); } } else if(inputFile.getName().toLowerCase().endsWith(".bam")) { @@ -1006,9 +1006,9 @@ public class GenomeAnalysisEngine { unpackedReads.add(new SAMReaderID(new File("/dev/stdin"),Collections.emptyList())); } else { - Utils.scareUser(String.format("The GATK reads argument (-I) supports only BAM files with the .bam extension and lists of BAM files " + - "with the .list extension, but the file %s has neither extension. Please ensure that your BAM file or list " + - "of BAM files is in the correct format, update the extension, and try again.",inputFile.getName())); + throw new UserError.CommandLineError(String.format("The GATK reads argument (-I) supports only BAM files with the .bam extension and lists of BAM files " + + "with the .list extension, but the file %s has neither extension. Please ensure that your BAM file or list " + + "of BAM files is in the correct format, update the extension, and try again.",inputFile.getName())); } } return unpackedReads; diff --git a/java/src/org/broadinstitute/sting/gatk/ReadMetrics.java b/java/src/org/broadinstitute/sting/gatk/ReadMetrics.java index fbdca4c13..a790c9188 100755 --- a/java/src/org/broadinstitute/sting/gatk/ReadMetrics.java +++ b/java/src/org/broadinstitute/sting/gatk/ReadMetrics.java @@ -30,6 +30,7 @@ import java.util.Map; import java.util.HashMap; import java.util.Collections; +import org.broadinstitute.sting.utils.GATKException; import org.broadinstitute.sting.utils.StingException; /** @@ -78,7 +79,7 @@ public class ReadMetrics implements Cloneable { newMetrics = (ReadMetrics)super.clone(); } catch(CloneNotSupportedException ex) { - throw new StingException("Unable to clone runtime metrics",ex); + throw new GATKException("Unable to clone runtime metrics",ex); } newMetrics.nRecords = nRecords; newMetrics.nReads = nReads; diff --git a/java/src/org/broadinstitute/sting/gatk/WalkerManager.java b/java/src/org/broadinstitute/sting/gatk/WalkerManager.java index e2e32647b..4474eafe9 100755 --- a/java/src/org/broadinstitute/sting/gatk/WalkerManager.java +++ b/java/src/org/broadinstitute/sting/gatk/WalkerManager.java @@ -30,6 +30,7 @@ import org.broadinstitute.sting.commandline.Hidden; import org.broadinstitute.sting.gatk.filters.FilterManager; import org.broadinstitute.sting.gatk.refdata.tracks.RMDTrack; import org.broadinstitute.sting.gatk.walkers.*; +import org.broadinstitute.sting.utils.GATKException; import org.broadinstitute.sting.utils.classloader.PluginManager; import org.broadinstitute.sting.utils.StingException; import org.broadinstitute.sting.utils.text.TextFormattingUtils; @@ -168,7 +169,7 @@ public class WalkerManager extends PluginManager { public static DataSource getWalkerDataSource(Class walkerClass) { By byDataSource = walkerClass.getAnnotation(By.class); if( byDataSource == null ) - throw new StingException("Unable to find By annotation for walker class " + walkerClass.getName()); + throw new GATKException("Unable to find By annotation for walker class " + walkerClass.getName()); return byDataSource.value(); } @@ -397,7 +398,7 @@ public class WalkerManager extends PluginManager { private static Requires getWalkerRequirements(Class walkerClass) { Requires requiresDataSource = walkerClass.getAnnotation(Requires.class); if( requiresDataSource == null ) - throw new StingException( "Unable to find data types required by walker class " + walkerClass.getName()); + throw new GATKException( "Unable to find data types required by walker class " + walkerClass.getName()); return requiresDataSource; } diff --git a/java/src/org/broadinstitute/sting/gatk/arguments/GATKArgumentCollection.java b/java/src/org/broadinstitute/sting/gatk/arguments/GATKArgumentCollection.java index 7ca4dfb5c..d54757d4e 100755 --- a/java/src/org/broadinstitute/sting/gatk/arguments/GATKArgumentCollection.java +++ b/java/src/org/broadinstitute/sting/gatk/arguments/GATKArgumentCollection.java @@ -27,6 +27,7 @@ package org.broadinstitute.sting.gatk.arguments; import net.sf.samtools.SAMFileReader; import org.broadinstitute.sting.gatk.phonehome.GATKRunReport; +import org.broadinstitute.sting.utils.GATKException; import org.broadinstitute.sting.utils.StingException; import org.broadinstitute.sting.utils.interval.IntervalMergingRule; import org.broadinstitute.sting.commandline.Argument; @@ -191,7 +192,7 @@ public class GATKArgumentCollection { try { serializer.write(collection, result); } catch (Exception e) { - throw new StingException("Failed to marshal the data to the file " + outputFile, e); + throw new GATKException("Failed to marshal the data to the file " + outputFile, e); } } @@ -206,7 +207,7 @@ public class GATKArgumentCollection { try { serializer.write(collection, outputFile); } catch (Exception e) { - throw new StingException("Failed to marshal the data to the file " + outputFile, e); + throw new GATKException("Failed to marshal the data to the file " + outputFile, e); } } @@ -222,7 +223,7 @@ public class GATKArgumentCollection { GATKArgumentCollection example = serializer.read(GATKArgumentCollection.class, source); return example; } catch (Exception e) { - throw new StingException("Failed to marshal the data from file " + filename, e); + throw new GATKException("Failed to marshal the data from file " + filename, e); } } @@ -237,7 +238,7 @@ public class GATKArgumentCollection { GATKArgumentCollection example = serializer.read(GATKArgumentCollection.class, file); return example; } catch (Exception e) { - throw new StingException("Failed to marshal the data from file " + file.toString(), e); + throw new GATKException("Failed to marshal the data from file " + file.toString(), e); } } diff --git a/java/src/org/broadinstitute/sting/gatk/contexts/AlignmentContext.java b/java/src/org/broadinstitute/sting/gatk/contexts/AlignmentContext.java index 4298ad628..238c5fe23 100755 --- a/java/src/org/broadinstitute/sting/gatk/contexts/AlignmentContext.java +++ b/java/src/org/broadinstitute/sting/gatk/contexts/AlignmentContext.java @@ -26,6 +26,7 @@ package org.broadinstitute.sting.gatk.contexts; import net.sf.samtools.SAMRecord; +import org.broadinstitute.sting.utils.GATKException; import org.broadinstitute.sting.utils.GenomeLoc; import org.broadinstitute.sting.utils.StingException; import org.broadinstitute.sting.utils.pileup.ReadBackedPileup; @@ -68,8 +69,8 @@ public class AlignmentContext { public AlignmentContext(GenomeLoc loc, ReadBackedPileup basePileup, long skippedBases,boolean hasPileupBeenDownsampled ) { if ( loc == null ) throw new StingException("BUG: GenomeLoc in Alignment context is null"); - if ( basePileup == null ) throw new StingException("BUG: ReadBackedPileup in Alignment context is null"); - if ( skippedBases < 0 ) throw new StingException("BUG: skippedBases is -1 in Alignment context"); + if ( basePileup == null ) throw new GATKException("BUG: ReadBackedPileup in Alignment context is null"); + if ( skippedBases < 0 ) throw new GATKException("BUG: skippedBases is -1 in Alignment context"); this.loc = loc; this.basePileup = basePileup; @@ -90,7 +91,7 @@ public class AlignmentContext { */ public ReadBackedPileup getBasePileup() { if(!hasBasePileup()) - throw new StingException("No base pileup is available. Please check for a base pileup with hasBasePileup() before attempting to retrieve a pileup."); + throw new GATKException("No base pileup is available. Please check for a base pileup with hasBasePileup() before attempting to retrieve a pileup."); return basePileup; } @@ -100,7 +101,7 @@ public class AlignmentContext { */ public ReadBackedExtendedEventPileup getExtendedEventPileup() { if(!hasExtendedEventPileup()) - throw new StingException("No extended event pileup is present."); + throw new GATKException("No extended event pileup is present."); return (ReadBackedExtendedEventPileup)basePileup; } diff --git a/java/src/org/broadinstitute/sting/gatk/contexts/ReferenceContext.java b/java/src/org/broadinstitute/sting/gatk/contexts/ReferenceContext.java index 1acd4082f..2bb02493e 100644 --- a/java/src/org/broadinstitute/sting/gatk/contexts/ReferenceContext.java +++ b/java/src/org/broadinstitute/sting/gatk/contexts/ReferenceContext.java @@ -25,6 +25,7 @@ package org.broadinstitute.sting.gatk.contexts; +import org.broadinstitute.sting.utils.GATKException; import org.broadinstitute.sting.utils.GenomeLoc; import org.broadinstitute.sting.utils.StingException; import org.broadinstitute.sting.utils.BaseUtils; @@ -191,7 +192,7 @@ public class ReferenceContext { byte[] b = new byte[stop-start]; if ( stop > bases.length ) - throw new StingException("Bases beyond the current window requested: window="+window+", requested="+n); + throw new GATKException("Bases beyond the current window requested: window="+window+", requested="+n); int i = 0; for ( int j = start ; j < stop ; j++) b[i++]=bases[j]; diff --git a/java/src/org/broadinstitute/sting/gatk/contexts/StratifiedAlignmentContext.java b/java/src/org/broadinstitute/sting/gatk/contexts/StratifiedAlignmentContext.java index bb817f854..26ca3d7a0 100755 --- a/java/src/org/broadinstitute/sting/gatk/contexts/StratifiedAlignmentContext.java +++ b/java/src/org/broadinstitute/sting/gatk/contexts/StratifiedAlignmentContext.java @@ -27,8 +27,10 @@ package org.broadinstitute.sting.gatk.contexts; import net.sf.samtools.SAMRecord; import net.sf.samtools.SAMReadGroupRecord; +import org.broadinstitute.sting.utils.GATKException; import org.broadinstitute.sting.utils.GenomeLoc; import org.broadinstitute.sting.utils.StingException; +import org.broadinstitute.sting.utils.exceptions.UserError; import org.broadinstitute.sting.utils.pileup.*; import java.util.*; @@ -73,7 +75,7 @@ public class StratifiedAlignmentContext { case REVERSE: return new AlignmentContext(loc,basePileup.getNegativeStrandPileup()); default: - throw new StingException("Unable to get alignment context for type = " + type); + throw new GATKException("Unable to get alignment context for type = " + type); } } @@ -113,8 +115,9 @@ public class StratifiedAlignmentContext { if(sampleName != null) contexts.put(sampleName,new StratifiedAlignmentContext(loc,pileupBySample)); else { - if(assumedSingleSample == null) - throw new StingException("Missing read group for read " + pileupBySample.iterator().next().getRead()); + if(assumedSingleSample == null) { + throw new UserError.MalformedBam(pileupBySample.iterator().next().getRead(), "Missing read group for read"); + } contexts.put(assumedSingleSample,new StratifiedAlignmentContext(loc,pileupBySample)); } } @@ -144,9 +147,9 @@ public class StratifiedAlignmentContext { boolean isExtended = contexts.iterator().next().basePileup instanceof ReadBackedExtendedEventPileup; for(StratifiedAlignmentContext context: contexts) { if(!loc.equals(context.getLocation())) - throw new StingException("Illegal attempt to join contexts from different genomic locations"); + throw new GATKException("Illegal attempt to join contexts from different genomic locations"); if(isExtended != (context.basePileup instanceof ReadBackedExtendedEventPileup)) - throw new StingException("Illegal attempt to join simple and extended contexts"); + throw new GATKException("Illegal attempt to join simple and extended contexts"); } AlignmentContext jointContext; diff --git a/java/src/org/broadinstitute/sting/gatk/contexts/variantcontext/VariantContextUtils.java b/java/src/org/broadinstitute/sting/gatk/contexts/variantcontext/VariantContextUtils.java index 47fb981db..30c8ee6ab 100755 --- a/java/src/org/broadinstitute/sting/gatk/contexts/variantcontext/VariantContextUtils.java +++ b/java/src/org/broadinstitute/sting/gatk/contexts/variantcontext/VariantContextUtils.java @@ -110,7 +110,7 @@ public class VariantContextUtils { */ public static List initializeMatchExps(String[] names, String[] exps) { if ( names == null || exps == null ) - throw new StingException("BUG: neither names nor exps can be null: names " + Arrays.toString(names) + " exps=" + Arrays.toString(exps) ); + throw new GATKException("BUG: neither names nor exps can be null: names " + Arrays.toString(names) + " exps=" + Arrays.toString(exps) ); if ( names.length != exps.length ) throw new UserError("Inconsistent number of provided filter names and expressions: names=" + Arrays.toString(names) + " exps=" + Arrays.toString(exps)); @@ -322,7 +322,7 @@ public class VariantContextUtils { for ( VariantContext vc : VCs ) { if ( loc.getStart() != vc.getStart() ) // || !first.getReference().equals(vc.getReference()) ) - throw new StingException("BUG: attempting to merge VariantContexts with different start sites: first="+ first.toString() + " second=" + vc.toString()); + throw new GATKException("BUG: attempting to merge VariantContexts with different start sites: first="+ first.toString() + " second=" + vc.toString()); if ( getLocation(vc).size() > loc.size() ) loc = getLocation(vc); // get the longest location @@ -449,7 +449,7 @@ public class VariantContextUtils { if ( ref == null || ref.length() < myRef.length() ) ref = myRef; else if ( ref.length() == myRef.length() && ! ref.equals(myRef) ) - throw new StingException("BUG: equal length references with difference bases: "+ ref + " " + myRef); + throw new GATKException("BUG: equal length references with difference bases: "+ ref + " " + myRef); } return ref; @@ -471,7 +471,7 @@ public class VariantContextUtils { // Allele myRef = vc.getReference(); - if ( refAllele.length() <= myRef.length() ) throw new StingException("BUG: myRef="+myRef+" is longer than refAllele="+refAllele); + if ( refAllele.length() <= myRef.length() ) throw new GATKException("BUG: myRef="+myRef+" is longer than refAllele="+refAllele); byte[] extraBases = Arrays.copyOfRange(refAllele.getBases(), myRef.length(), refAllele.length()); // System.out.printf("Remapping allele at %s%n", vc); @@ -576,7 +576,7 @@ public class VariantContextUtils { padVC = false; else if (refAllele.length() == locLength-1) padVC = true; - else throw new StingException("Badly formed variant context, reference length must be at most one base shorter than location size"); + else throw new GATKException("Badly formed variant context, reference length must be at most one base shorter than location size"); // nothing to do if we don't need to pad bases @@ -590,7 +590,7 @@ public class VariantContextUtils { else if (attributes.containsKey(VariantContext.REFERENCE_BASE_FOR_INDEL_KEY)) refByte = (Byte)attributes.get(VariantContext.REFERENCE_BASE_FOR_INDEL_KEY); else - throw new StingException("Error when trying to pad Variant Context: either input reference base must be a regular base, or input VC must contain reference base key"); + throw new GATKException("Error when trying to pad Variant Context: either input reference base must be a regular base, or input VC must contain reference base key"); List alleles = new ArrayList(); Map genotypes = new TreeMap(); diff --git a/java/src/org/broadinstitute/sting/gatk/contexts/variantcontext/VariantJEXLContext.java b/java/src/org/broadinstitute/sting/gatk/contexts/variantcontext/VariantJEXLContext.java index 50728ec81..c1c8cd0fe 100644 --- a/java/src/org/broadinstitute/sting/gatk/contexts/variantcontext/VariantJEXLContext.java +++ b/java/src/org/broadinstitute/sting/gatk/contexts/variantcontext/VariantJEXLContext.java @@ -27,9 +27,11 @@ import org.apache.commons.jexl2.JexlContext; import org.apache.commons.jexl2.MapContext; import org.broad.tribble.util.variantcontext.Genotype; import org.broad.tribble.util.variantcontext.VariantContext; +import org.broadinstitute.sting.utils.GATKException; import org.broadinstitute.sting.utils.StingException; import org.broadinstitute.sting.utils.Utils; import org.broad.tribble.vcf.VCFConstants; +import org.broadinstitute.sting.utils.exceptions.UserError; import java.util.*; @@ -272,7 +274,7 @@ class JEXLMap implements Map { try { jexl.put (exp, (Boolean) exp.exp.evaluate(jContext)); } catch (Exception e) { - throw new StingException(e.getMessage()); + throw new UserError.CommandLineError(String.format("Invalid JEXL expression detected for %s with message %s", exp.name, e.getMessage())); } } diff --git a/java/src/org/broadinstitute/sting/gatk/datasources/providers/LocusReferenceView.java b/java/src/org/broadinstitute/sting/gatk/datasources/providers/LocusReferenceView.java index b22170e17..92ef09376 100755 --- a/java/src/org/broadinstitute/sting/gatk/datasources/providers/LocusReferenceView.java +++ b/java/src/org/broadinstitute/sting/gatk/datasources/providers/LocusReferenceView.java @@ -1,5 +1,6 @@ package org.broadinstitute.sting.gatk.datasources.providers; +import org.broadinstitute.sting.utils.GATKException; import org.broadinstitute.sting.utils.GenomeLoc; import org.broadinstitute.sting.utils.GenomeLocParser; import org.broadinstitute.sting.utils.StingException; @@ -88,8 +89,8 @@ public class LocusReferenceView extends ReferenceView { if( walker.getClass().isAnnotationPresent(Reference.class) ) { Window window = walker.getClass().getAnnotation(Reference.class).window(); - if( window.start() > 0 ) throw new StingException( "Reference window starts after current locus" ); - if( window.stop() < 0 ) throw new StingException( "Reference window ends before current locus" ); + if( window.start() > 0 ) throw new GATKException( "Reference window starts after current locus" ); + if( window.stop() < 0 ) throw new GATKException( "Reference window ends before current locus" ); windowStart = window.start(); windowStop = window.stop(); @@ -124,7 +125,7 @@ public class LocusReferenceView extends ReferenceView { if ( bounds==null || loc==null) return; // can bounds be null actually??? if ( isLocationWithinBounds(loc) ) return; if ( loc.getContigIndex() != bounds.getContigIndex() ) - throw new StingException("Illegal attempt to expand reference view bounds to accommodate location on a different contig."); + throw new GATKException("Illegal attempt to expand reference view bounds to accommodate location on a different contig."); bounds = GenomeLocParser.createGenomeLoc(bounds.getContigIndex(), Math.min(bounds.getStart(),loc.getStart()), diff --git a/java/src/org/broadinstitute/sting/gatk/datasources/providers/ReferenceView.java b/java/src/org/broadinstitute/sting/gatk/datasources/providers/ReferenceView.java index be10a8b88..9215f5770 100755 --- a/java/src/org/broadinstitute/sting/gatk/datasources/providers/ReferenceView.java +++ b/java/src/org/broadinstitute/sting/gatk/datasources/providers/ReferenceView.java @@ -1,10 +1,7 @@ package org.broadinstitute.sting.gatk.datasources.providers; import org.broadinstitute.sting.gatk.contexts.ReferenceContext; -import org.broadinstitute.sting.utils.GenomeLoc; -import org.broadinstitute.sting.utils.Utils; -import org.broadinstitute.sting.utils.StingException; -import org.broadinstitute.sting.utils.GenomeLocParser; +import org.broadinstitute.sting.utils.*; import java.util.Collections; import java.util.Collection; @@ -84,7 +81,7 @@ public class ReferenceView implements View { int overhang = (int)(genomeLoc.getStop() - stop); if ( overhang > 0 ) { if ( overhang > BUFFER ) // todo -- this is a bit dangerous - throw new StingException("Insufficient buffer size for Xs overhanging genome -- expand BUFFER"); + throw new GATKException("Insufficient buffer size for Xs overhanging genome -- expand BUFFER"); byte[] all = new byte[subsequence.getBases().length + overhang]; System.arraycopy(subsequence.getBases(), 0, all, 0, subsequence.getBases().length); System.arraycopy(Xs, 0, all, subsequence.getBases().length, overhang); diff --git a/java/src/org/broadinstitute/sting/gatk/datasources/providers/ShardDataProvider.java b/java/src/org/broadinstitute/sting/gatk/datasources/providers/ShardDataProvider.java index e48849f9b..68d9007f9 100755 --- a/java/src/org/broadinstitute/sting/gatk/datasources/providers/ShardDataProvider.java +++ b/java/src/org/broadinstitute/sting/gatk/datasources/providers/ShardDataProvider.java @@ -2,6 +2,7 @@ package org.broadinstitute.sting.gatk.datasources.providers; import org.broadinstitute.sting.gatk.datasources.shards.Shard; import org.broadinstitute.sting.gatk.datasources.simpleDataSources.ReferenceOrderedDataSource; +import org.broadinstitute.sting.utils.GATKException; import org.broadinstitute.sting.utils.StingException; import java.util.ArrayList; @@ -110,7 +111,7 @@ public abstract class ShardDataProvider { Collection> conflicts = registeredView.getConflictingViews(); for( Class conflict: conflicts ) { if( conflict.isInstance(view) ) - throw new StingException(String.format("Tried to register two conflicting views: %s and %s", + throw new GATKException(String.format("Tried to register two conflicting views: %s and %s", registeredView.getClass().getSimpleName(), view.getClass().getSimpleName())); } @@ -120,7 +121,7 @@ public abstract class ShardDataProvider { for( Class conflict: view.getConflictingViews() ) { for( View registeredView: registeredViews ) { if( conflict.isInstance(registeredView) ) - throw new StingException(String.format("Tried to register two conflicting views: %s and %s", + throw new GATKException(String.format("Tried to register two conflicting views: %s and %s", registeredView.getClass().getSimpleName(), view.getClass().getSimpleName())); } diff --git a/java/src/org/broadinstitute/sting/gatk/datasources/shards/IntervalSharder.java b/java/src/org/broadinstitute/sting/gatk/datasources/shards/IntervalSharder.java index 539e44b64..b60c133d0 100644 --- a/java/src/org/broadinstitute/sting/gatk/datasources/shards/IntervalSharder.java +++ b/java/src/org/broadinstitute/sting/gatk/datasources/shards/IntervalSharder.java @@ -123,7 +123,7 @@ public class IntervalSharder { for(GenomeLoc location: loci) { if(!location.getContig().equals(contig)) - throw new StingException("Location outside bounds of contig"); + throw new GATKException("Location outside bounds of contig"); if(!binIterator.hasNext()) break; @@ -190,7 +190,7 @@ public class IntervalSharder { } else { if(lastFilePointer == null) - throw new StingException("Illegal state: initializer failed to create cached file pointer."); + throw new GATKException("Illegal state: initializer failed to create cached file pointer."); // The start of the region overlaps the bin. Add the overlapping subset. final int regionStop = Math.min(locationStop,binStop); @@ -474,7 +474,7 @@ class BinQueueState implements Comparable { // Both BinQueueStates have next bins. Before proceeding, make sure the bin cache is valid. if(this.firstLocusInCurrentBin <= 0 || this.lastLocusInCurrentBin <= 0 || other.firstLocusInCurrentBin <= 0 || other.lastLocusInCurrentBin <= 0) { - throw new StingException("Sharding mechanism error - bin->locus cache is invalid."); + throw new GATKException("Sharding mechanism error - bin->locus cache is invalid."); } // Straight integer subtraction works here because lhsStart, rhsStart always positive. diff --git a/java/src/org/broadinstitute/sting/gatk/datasources/shards/MonolithicShard.java b/java/src/org/broadinstitute/sting/gatk/datasources/shards/MonolithicShard.java index 0a971df2e..1dd4f61d1 100644 --- a/java/src/org/broadinstitute/sting/gatk/datasources/shards/MonolithicShard.java +++ b/java/src/org/broadinstitute/sting/gatk/datasources/shards/MonolithicShard.java @@ -1,5 +1,6 @@ package org.broadinstitute.sting.gatk.datasources.shards; +import org.broadinstitute.sting.utils.GATKException; import org.broadinstitute.sting.utils.StingException; import org.broadinstitute.sting.utils.GenomeLoc; import org.broadinstitute.sting.gatk.ReadMetrics; @@ -42,7 +43,7 @@ public class MonolithicShard implements Shard { public MonolithicShard(SAMDataSource readsDataSource, ShardType shardType, List locs) { this.readsDataSource = readsDataSource; if(shardType != ShardType.LOCUS && shardType != ShardType.READ) - throw new StingException("Invalid shard type for monolithic shard: " + shardType); + throw new GATKException("Invalid shard type for monolithic shard: " + shardType); this.shardType = shardType; this.locs = locs; } diff --git a/java/src/org/broadinstitute/sting/gatk/datasources/shards/ShardStrategyFactory.java b/java/src/org/broadinstitute/sting/gatk/datasources/shards/ShardStrategyFactory.java index c8ff705f1..344f55d69 100644 --- a/java/src/org/broadinstitute/sting/gatk/datasources/shards/ShardStrategyFactory.java +++ b/java/src/org/broadinstitute/sting/gatk/datasources/shards/ShardStrategyFactory.java @@ -2,6 +2,7 @@ package org.broadinstitute.sting.gatk.datasources.shards; import net.sf.samtools.SAMSequenceDictionary; import net.sf.picard.reference.IndexedFastaSequenceFile; +import org.broadinstitute.sting.utils.GATKException; import org.broadinstitute.sting.utils.StingException; import org.broadinstitute.sting.utils.GenomeLocSortedSet; import org.broadinstitute.sting.gatk.datasources.simpleDataSources.SAMDataSource; @@ -71,7 +72,7 @@ public class ShardStrategyFactory { case READS_EXPERIMENTAL: return new ReadShardStrategy(readsDataSource,null); default: - throw new StingException("Strategy: " + strat + " isn't implemented for this type of shatter request"); + throw new GATKException("Strategy: " + strat + " isn't implemented for this type of shatter request"); } } @@ -109,7 +110,7 @@ public class ShardStrategyFactory { case READS_EXPERIMENTAL: return new ReadShardStrategy(readsDataSource,lst); default: - throw new StingException("Strategy: " + strat + " isn't implemented"); + throw new GATKException("Strategy: " + strat + " isn't implemented"); } } diff --git a/java/src/org/broadinstitute/sting/gatk/datasources/simpleDataSources/ReferenceDataSource.java b/java/src/org/broadinstitute/sting/gatk/datasources/simpleDataSources/ReferenceDataSource.java index 6356ed6d2..03d8f496d 100644 --- a/java/src/org/broadinstitute/sting/gatk/datasources/simpleDataSources/ReferenceDataSource.java +++ b/java/src/org/broadinstitute/sting/gatk/datasources/simpleDataSources/ReferenceDataSource.java @@ -25,6 +25,7 @@ package org.broadinstitute.sting.gatk.datasources.simpleDataSources; +import org.broadinstitute.sting.utils.GATKException; import org.broadinstitute.sting.utils.StingException; import net.sf.picard.reference.FastaSequenceIndexBuilder; import net.sf.picard.sam.CreateSequenceDictionary; @@ -68,7 +69,7 @@ public class ReferenceDataSource implements ReferenceDataSourceProgressListener try { // get exclusive lock if (!indexLock.exclusiveLock()) - throw new StingException("Index file could not be written because a lock could not be obtained." + + throw new GATKException("Index file could not be written because a lock could not be obtained." + "If you are running multiple instances of GATK, another process is probably creating this " + "file now. Please wait until it is finished and try again."); FastaSequenceIndexBuilder faiBuilder = new FastaSequenceIndexBuilder(fastaFile, this); @@ -82,7 +83,7 @@ public class ReferenceDataSource implements ReferenceDataSourceProgressListener catch (Exception e) { // If lock creation succeeded, the failure must have been generating the index. // If lock creation failed, just skip over index creation entirely. - throw new StingException("Index file does not exist and could not be created because " + e.getMessage(), e); + throw new GATKException("Index file does not exist and could not be created because " + e.getMessage(), e); } finally { indexLock.unlock(); @@ -108,7 +109,7 @@ public class ReferenceDataSource implements ReferenceDataSourceProgressListener try { // get shared lock on dict file so nobody else can start creating it if (!dictLock.exclusiveLock()) - throw new StingException("Dictionary file could not be written because a lock could not be obtained." + + throw new GATKException("Dictionary file could not be written because a lock could not be obtained." + "If you are running multiple instances of GATK, another process is probably creating this " + "file now. Please wait until it is finished and try again."); // dict will be written to random temporary file in same directory (see note above) @@ -121,7 +122,7 @@ public class ReferenceDataSource implements ReferenceDataSourceProgressListener new CreateSequenceDictionary().instanceMain(args); if (!tempFile.renameTo(dictFile)) - throw new StingException("Error transferring temp file " + tempFile + " to dict file " + dictFile); + throw new GATKException("Error transferring temp file " + tempFile + " to dict file " + dictFile); } catch(FileSystemInabilityToLockException ex) { logger.info("Unable to create write lock: " + ex.getMessage()); @@ -130,7 +131,7 @@ public class ReferenceDataSource implements ReferenceDataSourceProgressListener catch (Exception e) { // If lock creation succeeded, the failure must have been generating the index. // If lock creation failed, just skip over index creation entirely. - throw new StingException("Dictionary file does not exist and could not be created because " + e.getMessage(), e); + throw new GATKException("Dictionary file does not exist and could not be created because " + e.getMessage(), e); } finally { dictLock.unlock(); @@ -149,7 +150,7 @@ public class ReferenceDataSource implements ReferenceDataSourceProgressListener try { try { if (!dictLock.sharedLock()) { - throw new StingException("Could not open dictionary file because a lock could not be obtained."); + throw new GATKException("Could not open dictionary file because a lock could not be obtained."); } } catch(FileSystemInabilityToLockException ex) { @@ -159,7 +160,7 @@ public class ReferenceDataSource implements ReferenceDataSourceProgressListener try { if (!indexLock.sharedLock()) { - throw new StingException("Could not open index file because a lock could not be obtained."); + throw new GATKException("Could not open index file because a lock could not be obtained."); } } catch(FileSystemInabilityToLockException ex) { diff --git a/java/src/org/broadinstitute/sting/gatk/datasources/simpleDataSources/ReferenceOrderedDataSource.java b/java/src/org/broadinstitute/sting/gatk/datasources/simpleDataSources/ReferenceOrderedDataSource.java index ecf8dd8b4..bcacf761f 100755 --- a/java/src/org/broadinstitute/sting/gatk/datasources/simpleDataSources/ReferenceOrderedDataSource.java +++ b/java/src/org/broadinstitute/sting/gatk/datasources/simpleDataSources/ReferenceOrderedDataSource.java @@ -11,8 +11,10 @@ import org.broadinstitute.sting.gatk.refdata.utils.FlashBackIterator; import org.broadinstitute.sting.gatk.refdata.utils.LocationAwareSeekableRODIterator; import org.broadinstitute.sting.gatk.walkers.ReadWalker; import org.broadinstitute.sting.gatk.walkers.Walker; +import org.broadinstitute.sting.utils.GATKException; import org.broadinstitute.sting.utils.GenomeLoc; import org.broadinstitute.sting.utils.StingException; +import org.broadinstitute.sting.utils.exceptions.UserError; import java.io.IOException; import java.util.List; @@ -155,7 +157,7 @@ class ReferenceOrderedDataPool extends ResourcePool { // make sure we actually removed the assignment if (obj == null) - throw new StingException("Failed to remove resource assignment; target key had no associated value in the resource assignment map"); + throw new GATKException("Failed to remove resource assignment; target key had no associated value in the resource assignment map"); // Return the resource to the pool. if( !allResources.contains(resource) ) - throw new StingException("Iterator does not belong to the given pool."); + throw new GATKException("Iterator does not belong to the given pool."); availableResources.add(resource); } } diff --git a/java/src/org/broadinstitute/sting/gatk/datasources/simpleDataSources/SAMDataSource.java b/java/src/org/broadinstitute/sting/gatk/datasources/simpleDataSources/SAMDataSource.java index 8a8c256c6..43329647a 100755 --- a/java/src/org/broadinstitute/sting/gatk/datasources/simpleDataSources/SAMDataSource.java +++ b/java/src/org/broadinstitute/sting/gatk/datasources/simpleDataSources/SAMDataSource.java @@ -41,7 +41,9 @@ import org.broadinstitute.sting.gatk.ReadProperties; import org.broadinstitute.sting.gatk.ReadMetrics; import org.broadinstitute.sting.gatk.arguments.ValidationExclusion; import org.broadinstitute.sting.gatk.filters.CountingFilteringIterator; +import org.broadinstitute.sting.utils.GATKException; import org.broadinstitute.sting.utils.StingException; +import org.broadinstitute.sting.utils.exceptions.UserError; import java.io.File; import java.util.*; @@ -126,7 +128,7 @@ public class SAMDataSource implements SimpleDataSource { // Validate that all input files are sorted in the same order. if(this.sortOrder != null && this.sortOrder != sortOrder) - throw new StingException(String.format("Attempted to process mixed of files sorted as %s and %s.",this.sortOrder,sortOrder)); + throw new UserError.MissortedBAM(String.format("Attempted to process mixed of files sorted as %s and %s.",this.sortOrder,sortOrder)); // Update the sort order. this.sortOrder = sortOrder; @@ -293,7 +295,7 @@ public class SAMDataSource implements SimpleDataSource { */ public void fillShard(BAMFormatAwareShard shard) { if(!shard.buffersReads()) - throw new StingException("Attempting to fill a non-buffering shard."); + throw new GATKException("Attempting to fill a non-buffering shard."); SAMReaders readers = resourcePool.getAvailableReaders(); // Cache the most recently viewed read so that we can check whether we've reached the end of a pair. @@ -325,7 +327,7 @@ public class SAMDataSource implements SimpleDataSource { return seekMonolithic(shard); if(!(shard instanceof BAMFormatAwareShard)) - throw new StingException("BlockDrivenSAMDataSource cannot operate on shards of type: " + shard.getClass()); + throw new GATKException("BlockDrivenSAMDataSource cannot operate on shards of type: " + shard.getClass()); BAMFormatAwareShard bamAwareShard = (BAMFormatAwareShard)shard; if(bamAwareShard.buffersReads()) { @@ -348,7 +350,7 @@ public class SAMDataSource implements SimpleDataSource { if(readers.getReader(id) == read.getFileSource().getReader()) return id; } - throw new StingException("Unable to find id for reader associated with read " + read.getReadName()); + throw new GATKException("Unable to find id for reader associated with read " + read.getReadName()); } /** @@ -507,7 +509,7 @@ public class SAMDataSource implements SimpleDataSource { public synchronized void releaseReaders(SAMReaders readers) { if(!allResources.contains(readers)) - throw new StingException("Tried to return readers from the pool that didn't originate in the pool."); + throw new GATKException("Tried to return readers from the pool that didn't originate in the pool."); availableResources.add(readers); } @@ -522,12 +524,12 @@ public class SAMDataSource implements SimpleDataSource { if(id != null) return id; } - throw new StingException("No such reader id is available"); + throw new GATKException("No such reader id is available"); } private synchronized void createNewResource() { if(allResources.size() > maxEntries) - throw new StingException("Cannot create a new resource pool. All resources are in use."); + throw new GATKException("Cannot create a new resource pool. All resources are in use."); SAMReaders readers = new SAMReaders(readProperties); allResources.add(readers); availableResources.add(readers); diff --git a/java/src/org/broadinstitute/sting/gatk/datasources/utilities/BAMFileStat.java b/java/src/org/broadinstitute/sting/gatk/datasources/utilities/BAMFileStat.java index 5419e18f5..101a0c464 100644 --- a/java/src/org/broadinstitute/sting/gatk/datasources/utilities/BAMFileStat.java +++ b/java/src/org/broadinstitute/sting/gatk/datasources/utilities/BAMFileStat.java @@ -27,6 +27,7 @@ package org.broadinstitute.sting.gatk.datasources.utilities; import org.broadinstitute.sting.commandline.CommandLineProgram; import org.broadinstitute.sting.commandline.Argument; +import org.broadinstitute.sting.utils.GATKException; import org.broadinstitute.sting.utils.StingException; import org.broadinstitute.sting.utils.instrumentation.Sizeof; @@ -58,7 +59,7 @@ public class BAMFileStat extends CommandLineProgram { public int execute() { switch(command) { case ShowBlocks: - throw new StingException("The BAM block inspector has been disabled."); + throw new GATKException("The BAM block inspector has been disabled."); case ShowIndex: showIndexBins(new File(bamFileName),range); break; @@ -171,7 +172,7 @@ public class BAMFileStat extends CommandLineProgram { } } catch(IllegalAccessException ex) { - throw new StingException("Unable to examine cached index",ex); + throw new GATKException("Unable to examine cached index",ex); } System.out.printf("%nOverall: %d bins, %d chunks, %d linear index entries",numBins,numChunks,numLinearIndexEntries); diff --git a/java/src/org/broadinstitute/sting/gatk/executive/Accumulator.java b/java/src/org/broadinstitute/sting/gatk/executive/Accumulator.java index be3ee7524..4776b12f3 100755 --- a/java/src/org/broadinstitute/sting/gatk/executive/Accumulator.java +++ b/java/src/org/broadinstitute/sting/gatk/executive/Accumulator.java @@ -29,6 +29,7 @@ import org.broadinstitute.sting.gatk.walkers.Walker; import org.broadinstitute.sting.gatk.datasources.providers.ShardDataProvider; import org.broadinstitute.sting.gatk.datasources.providers.LocusShardDataProvider; import org.broadinstitute.sting.gatk.GenomeAnalysisEngine; +import org.broadinstitute.sting.utils.GATKException; import org.broadinstitute.sting.utils.GenomeLoc; import org.broadinstitute.sting.utils.collections.Pair; import org.broadinstitute.sting.utils.GenomeLocSortedSet; @@ -184,7 +185,7 @@ public abstract class Accumulator { */ public void accumulate( ShardDataProvider provider, Object result ) { if(!(provider instanceof LocusShardDataProvider)) - throw new StingException("Unable to reduce by interval on reads traversals at this time."); + throw new GATKException("Unable to reduce by interval on reads traversals at this time."); GenomeLoc location = ((LocusShardDataProvider)provider).getLocus(); diff --git a/java/src/org/broadinstitute/sting/gatk/executive/HierarchicalMicroScheduler.java b/java/src/org/broadinstitute/sting/gatk/executive/HierarchicalMicroScheduler.java index 4a8a2d366..f5020bef7 100755 --- a/java/src/org/broadinstitute/sting/gatk/executive/HierarchicalMicroScheduler.java +++ b/java/src/org/broadinstitute/sting/gatk/executive/HierarchicalMicroScheduler.java @@ -9,6 +9,7 @@ import org.broadinstitute.sting.gatk.datasources.simpleDataSources.ReferenceOrde import org.broadinstitute.sting.gatk.io.*; import org.broadinstitute.sting.gatk.GenomeAnalysisEngine; import org.broadinstitute.sting.gatk.ReadMetrics; +import org.broadinstitute.sting.utils.GATKException; import org.broadinstitute.sting.utils.StingException; import org.broadinstitute.sting.utils.threading.ThreadPoolMonitor; @@ -110,7 +111,7 @@ public class HierarchicalMicroScheduler extends MicroScheduler implements Hierar mbs.registerMBean(this, name); } catch (JMException ex) { - throw new StingException("Unable to register microscheduler with JMX", ex); + throw new GATKException("Unable to register microscheduler with JMX", ex); } } @@ -130,7 +131,7 @@ public class HierarchicalMicroScheduler extends MicroScheduler implements Hierar while (isShardTraversePending() || isTreeReducePending()) { // Check for errors during execution. if(hasTraversalErrorOccurred()) - throw new StingException("An error has occurred during the traversal.",getTraversalError()); + throw new GATKException("An error has occurred during the traversal.",getTraversalError()); // Too many files sitting around taking up space? Merge them. if (isMergeLimitExceeded()) @@ -159,7 +160,7 @@ public class HierarchicalMicroScheduler extends MicroScheduler implements Hierar notifyTraversalDone(walker,result); } catch (Exception ex) { - throw new StingException("Unable to retrieve result", ex); + throw new GATKException("Unable to retrieve result", ex); } outputTracker.close(); @@ -359,7 +360,7 @@ public class HierarchicalMicroScheduler extends MicroScheduler implements Hierar private synchronized Throwable getTraversalError() { if(!hasTraversalErrorOccurred()) - throw new StingException("User has attempted to retrieve a traversal error when none exists"); + throw new GATKException("User has attempted to retrieve a traversal error when none exists"); return error; } diff --git a/java/src/org/broadinstitute/sting/gatk/executive/ShardTraverser.java b/java/src/org/broadinstitute/sting/gatk/executive/ShardTraverser.java index ccd54edab..cd2fea839 100755 --- a/java/src/org/broadinstitute/sting/gatk/executive/ShardTraverser.java +++ b/java/src/org/broadinstitute/sting/gatk/executive/ShardTraverser.java @@ -8,6 +8,7 @@ import org.broadinstitute.sting.gatk.traversals.TraversalEngine; import org.broadinstitute.sting.gatk.io.ThreadLocalOutputTracker; import org.broadinstitute.sting.gatk.walkers.Walker; import org.broadinstitute.sting.gatk.walkers.LocusWalker; +import org.broadinstitute.sting.utils.GATKException; import org.broadinstitute.sting.utils.StingException; import java.util.concurrent.Callable; @@ -83,7 +84,7 @@ public class ShardTraverser implements Callable { catch(Throwable t) { // Notify that an exception has occurred and rethrow it. microScheduler.notifyOfTraversalError(t); - throw new StingException("An error has occurred during traversal",t); + throw new GATKException("An error has occurred during traversal",t); } finally { synchronized(this) { @@ -115,7 +116,7 @@ public class ShardTraverser implements Callable { } } catch( InterruptedException ex ) { - throw new StingException("Interrupted while waiting for more output to be finalized.",ex); + throw new GATKException("Interrupted while waiting for more output to be finalized.",ex); } } diff --git a/java/src/org/broadinstitute/sting/gatk/executive/TreeReducer.java b/java/src/org/broadinstitute/sting/gatk/executive/TreeReducer.java index 5b49f762d..99470f19a 100755 --- a/java/src/org/broadinstitute/sting/gatk/executive/TreeReducer.java +++ b/java/src/org/broadinstitute/sting/gatk/executive/TreeReducer.java @@ -1,6 +1,7 @@ package org.broadinstitute.sting.gatk.executive; import org.broadinstitute.sting.gatk.walkers.TreeReducible; +import org.broadinstitute.sting.utils.GATKException; import org.broadinstitute.sting.utils.StingException; import java.util.concurrent.Callable; @@ -90,11 +91,11 @@ public class TreeReducer implements Callable { } catch( InterruptedException ex ) { microScheduler.notifyOfTraversalError(ex); - throw new StingException("Hierarchical reduce interrupted", ex); + throw new GATKException("Hierarchical reduce interrupted", ex); } catch( ExecutionException ex ) { microScheduler.notifyOfTraversalError(ex); - throw new StingException("Hierarchical reduce failed", ex); + throw new GATKException("Hierarchical reduce failed", ex); } long endTime = System.currentTimeMillis(); diff --git a/java/src/org/broadinstitute/sting/gatk/io/OutputTracker.java b/java/src/org/broadinstitute/sting/gatk/io/OutputTracker.java index 3ecf6f115..25641c12f 100755 --- a/java/src/org/broadinstitute/sting/gatk/io/OutputTracker.java +++ b/java/src/org/broadinstitute/sting/gatk/io/OutputTracker.java @@ -25,6 +25,7 @@ package org.broadinstitute.sting.gatk.io; +import org.broadinstitute.sting.utils.GATKException; import org.broadinstitute.sting.utils.classloader.JVMUtils; import org.broadinstitute.sting.utils.StingException; import org.broadinstitute.sting.commandline.ArgumentSource; @@ -140,7 +141,7 @@ public abstract class OutputTracker { */ protected T getTargetStream( Stub stub ) { if( !outputs.containsKey(stub) ) - throw new StingException("OutputTracker was not notified that this stub exists: " + stub); + throw new GATKException("OutputTracker was not notified that this stub exists: " + stub); Storage storage = outputs.get(stub); if( storage == null ) { storage = StorageFactory.createStorage(stub); diff --git a/java/src/org/broadinstitute/sting/gatk/io/storage/OutputStreamStorage.java b/java/src/org/broadinstitute/sting/gatk/io/storage/OutputStreamStorage.java index 1ab1cefde..918f029f8 100644 --- a/java/src/org/broadinstitute/sting/gatk/io/storage/OutputStreamStorage.java +++ b/java/src/org/broadinstitute/sting/gatk/io/storage/OutputStreamStorage.java @@ -25,6 +25,7 @@ package org.broadinstitute.sting.gatk.io.storage; +import org.broadinstitute.sting.utils.GATKException; import org.broadinstitute.sting.utils.StingException; import org.broadinstitute.sting.gatk.io.stubs.OutputStreamStub; import org.broadinstitute.sting.gatk.io.storage.Storage; @@ -60,7 +61,7 @@ public class OutputStreamStorage extends OutputStream implements Storage, VCFWriter { this.stream = stub.getOutputStream(); } else - throw new StingException("Unable to create target to which to write; storage was provided with neither a file nor a stream."); + throw new GATKException("Unable to create target to which to write; storage was provided with neither a file nor a stream."); writer = new StandardVCFWriter(stream); } diff --git a/java/src/org/broadinstitute/sting/gatk/io/stubs/OutputStreamArgumentTypeDescriptor.java b/java/src/org/broadinstitute/sting/gatk/io/stubs/OutputStreamArgumentTypeDescriptor.java index 62bbf405d..ad64260b5 100644 --- a/java/src/org/broadinstitute/sting/gatk/io/stubs/OutputStreamArgumentTypeDescriptor.java +++ b/java/src/org/broadinstitute/sting/gatk/io/stubs/OutputStreamArgumentTypeDescriptor.java @@ -26,6 +26,7 @@ package org.broadinstitute.sting.gatk.io.stubs; import org.broadinstitute.sting.commandline.*; +import org.broadinstitute.sting.utils.GATKException; import org.broadinstitute.sting.utils.StingException; import org.broadinstitute.sting.gatk.GenomeAnalysisEngine; @@ -117,13 +118,13 @@ public class OutputStreamArgumentTypeDescriptor extends ArgumentTypeDescriptor { return getConstructorForClass(type).newInstance(outputStream); } catch( InstantiationException ex ) { - throw new StingException("Could not instantiate class with OutputStream constructor: " + type.getName()); + throw new GATKException("Could not instantiate class with OutputStream constructor: " + type.getName()); } catch( IllegalAccessException ex ) { - throw new StingException("Could not access class with OutputStream constructor: " + type.getName()); + throw new GATKException("Could not access class with OutputStream constructor: " + type.getName()); } catch( InvocationTargetException ex ) { - throw new StingException("Could not invoke constructor for class with OutputStream constructor: " + type.getName()); + throw new GATKException("Could not invoke constructor for class with OutputStream constructor: " + type.getName()); } } } diff --git a/java/src/org/broadinstitute/sting/gatk/io/stubs/SAMFileReaderArgumentTypeDescriptor.java b/java/src/org/broadinstitute/sting/gatk/io/stubs/SAMFileReaderArgumentTypeDescriptor.java index 041bb045d..1380a2f01 100644 --- a/java/src/org/broadinstitute/sting/gatk/io/stubs/SAMFileReaderArgumentTypeDescriptor.java +++ b/java/src/org/broadinstitute/sting/gatk/io/stubs/SAMFileReaderArgumentTypeDescriptor.java @@ -28,6 +28,7 @@ import org.broadinstitute.sting.commandline.ArgumentTypeDescriptor; import org.broadinstitute.sting.commandline.ArgumentSource; import org.broadinstitute.sting.commandline.ArgumentMatches; import org.broadinstitute.sting.commandline.ParsingEngine; +import org.broadinstitute.sting.utils.exceptions.UserError; import org.broadinstitute.sting.utils.sam.SAMFileReaderBuilder; import org.broadinstitute.sting.utils.StingException; import org.broadinstitute.sting.gatk.GenomeAnalysisEngine; @@ -66,7 +67,7 @@ public class SAMFileReaderArgumentTypeDescriptor extends ArgumentTypeDescriptor String readerFileName = getArgumentValue( createDefaultArgumentDefinition(source), matches ); if( readerFileName == null ) - throw new StingException("SAM file compression was supplied, but no associated writer was supplied with it."); + throw new UserError.CommandLineError("SAM file compression was supplied, but no associated writer was supplied with it."); builder.setSAMFile(new File(readerFileName)); diff --git a/java/src/org/broadinstitute/sting/gatk/io/stubs/SAMFileWriterArgumentTypeDescriptor.java b/java/src/org/broadinstitute/sting/gatk/io/stubs/SAMFileWriterArgumentTypeDescriptor.java index 76c009172..7a68f0cc1 100644 --- a/java/src/org/broadinstitute/sting/gatk/io/stubs/SAMFileWriterArgumentTypeDescriptor.java +++ b/java/src/org/broadinstitute/sting/gatk/io/stubs/SAMFileWriterArgumentTypeDescriptor.java @@ -30,6 +30,7 @@ import org.broadinstitute.sting.utils.StingException; import org.broadinstitute.sting.gatk.GenomeAnalysisEngine; import org.broadinstitute.sting.gatk.io.StingSAMFileWriter; import net.sf.samtools.SAMFileWriter; +import org.broadinstitute.sting.utils.exceptions.UserError; import java.lang.annotation.Annotation; import java.util.List; @@ -94,7 +95,7 @@ public class SAMFileWriterArgumentTypeDescriptor extends ArgumentTypeDescriptor public Object parse( ParsingEngine parsingEngine, ArgumentSource source, Class type, ArgumentMatches matches ) { String writerFileName = getArgumentValue( createBAMArgumentDefinition(source), matches ); if( writerFileName == null ) - throw new StingException("SAM file compression was supplied, but no associated writer was supplied with it."); + throw new UserError.CommandLineError("SAM file compression was supplied, but no associated writer was supplied with it."); SAMFileWriterStub stub = new SAMFileWriterStub(engine, new File(writerFileName)); diff --git a/java/src/org/broadinstitute/sting/gatk/io/stubs/SAMFileWriterStub.java b/java/src/org/broadinstitute/sting/gatk/io/stubs/SAMFileWriterStub.java index 0ebcb65ce..12929214a 100644 --- a/java/src/org/broadinstitute/sting/gatk/io/stubs/SAMFileWriterStub.java +++ b/java/src/org/broadinstitute/sting/gatk/io/stubs/SAMFileWriterStub.java @@ -35,6 +35,7 @@ import java.io.OutputStream; import org.broadinstitute.sting.gatk.io.OutputTracker; import org.broadinstitute.sting.gatk.io.StingSAMFileWriter; import org.broadinstitute.sting.gatk.GenomeAnalysisEngine; +import org.broadinstitute.sting.utils.GATKException; import org.broadinstitute.sting.utils.StingException; /** @@ -150,7 +151,7 @@ public class SAMFileWriterStub implements Stub, StingSAMFileWrite */ public void setCompressionLevel( Integer compressionLevel ) { if(writeStarted) - throw new StingException("User attempted to change the compression level of a file with alignments already in it."); + throw new GATKException("Attempted to change the compression level of a file with alignments already in it."); this.compressionLevel = compressionLevel; } @@ -168,7 +169,7 @@ public class SAMFileWriterStub implements Stub, StingSAMFileWrite */ public void setPresorted(boolean presorted) { if(writeStarted) - throw new StingException("User attempted to change the presorted state of a file with alignments already in it."); + throw new GATKException("Attempted to change the presorted state of a file with alignments already in it."); this.presorted = presorted; } @@ -186,7 +187,7 @@ public class SAMFileWriterStub implements Stub, StingSAMFileWrite */ public void setMaxRecordsInRam(int maxRecordsInRam) { if(writeStarted) - throw new StingException("User attempted to change the max records in RAM of a file with alignments already in it."); + throw new GATKException("Attempted to change the max records in RAM of a file with alignments already in it."); this.maxRecordsInRam = maxRecordsInRam; } @@ -204,7 +205,7 @@ public class SAMFileWriterStub implements Stub, StingSAMFileWrite */ public void writeHeader(SAMFileHeader header) { if(writeStarted) - throw new StingException("User attempted to change the header of a file with alignments already in it."); + throw new GATKException("Attempted to change the header of a file with alignments already in it."); this.headerOverride = header; } diff --git a/java/src/org/broadinstitute/sting/gatk/iterators/BufferingReadIterator.java b/java/src/org/broadinstitute/sting/gatk/iterators/BufferingReadIterator.java index 9cb35233a..cb4dd76d5 100644 --- a/java/src/org/broadinstitute/sting/gatk/iterators/BufferingReadIterator.java +++ b/java/src/org/broadinstitute/sting/gatk/iterators/BufferingReadIterator.java @@ -32,6 +32,7 @@ import java.util.LinkedList; import java.util.Iterator; import java.util.NoSuchElementException; +import org.broadinstitute.sting.utils.GATKException; import org.broadinstitute.sting.utils.StingException; /** @@ -67,7 +68,7 @@ public class BufferingReadIterator implements CloseableIterator { } public void remove() { - throw new StingException("Unable to remove from a BufferingReadIterator"); + throw new GATKException("Unable to remove from a BufferingReadIterator"); } /** diff --git a/java/src/org/broadinstitute/sting/gatk/phonehome/GATKRunReport.java b/java/src/org/broadinstitute/sting/gatk/phonehome/GATKRunReport.java index 0687f7001..49146ff1b 100644 --- a/java/src/org/broadinstitute/sting/gatk/phonehome/GATKRunReport.java +++ b/java/src/org/broadinstitute/sting/gatk/phonehome/GATKRunReport.java @@ -30,6 +30,7 @@ import org.broadinstitute.sting.gatk.CommandLineGATK; import org.broadinstitute.sting.gatk.GenomeAnalysisEngine; import org.broadinstitute.sting.gatk.arguments.GATKArgumentCollection; import org.broadinstitute.sting.gatk.walkers.Walker; +import org.broadinstitute.sting.utils.GATKException; import org.broadinstitute.sting.utils.StingException; import org.broadinstitute.sting.utils.Utils; import org.simpleframework.xml.Element; @@ -241,7 +242,7 @@ public class GATKRunReport { serializer.write(this, stream); //throw new StingException("test"); } catch (Exception e) { - throw new StingException("Failed to marshal the data to the file " + stream, e); + throw new GATKException("Failed to marshal the data to the file " + stream, e); } } diff --git a/java/src/org/broadinstitute/sting/gatk/refdata/IntervalRod.java b/java/src/org/broadinstitute/sting/gatk/refdata/IntervalRod.java index f02f1f2a4..9afbba9f6 100755 --- a/java/src/org/broadinstitute/sting/gatk/refdata/IntervalRod.java +++ b/java/src/org/broadinstitute/sting/gatk/refdata/IntervalRod.java @@ -1,5 +1,6 @@ package org.broadinstitute.sting.gatk.refdata; +import org.broadinstitute.sting.utils.GATKException; import org.broadinstitute.sting.utils.GenomeLoc; import org.broadinstitute.sting.utils.StingException; @@ -29,7 +30,7 @@ public class IntervalRod extends BasicReferenceOrderedDatum { } public String repl() { - throw new StingException("repl() is not implemented yet"); + throw new GATKException("repl() is not implemented yet"); } public String toSimpleString() { return loc.toString(); } diff --git a/java/src/org/broadinstitute/sting/gatk/refdata/PlinkRod.java b/java/src/org/broadinstitute/sting/gatk/refdata/PlinkRod.java index 43bd8c4fd..ace6300b8 100644 --- a/java/src/org/broadinstitute/sting/gatk/refdata/PlinkRod.java +++ b/java/src/org/broadinstitute/sting/gatk/refdata/PlinkRod.java @@ -1,6 +1,7 @@ package org.broadinstitute.sting.gatk.refdata; import org.broad.tribble.util.variantcontext.Allele; +import org.broadinstitute.sting.utils.GATKException; import org.broadinstitute.sting.utils.GenomeLoc; import org.broadinstitute.sting.utils.GenomeLocParser; import org.broadinstitute.sting.utils.StingException; @@ -65,7 +66,7 @@ public class PlinkRod extends BasicReferenceOrderedDatum implements Iterator implements Ite try { reader = new PushbackIterator(new XReadLines(file)); } catch (FileNotFoundException e) { - Utils.scareUser("Couldn't open file: " + file); + throw new UserError.CouldNotReadInputFile(file, e); } this.file = file; this.name = name; @@ -124,7 +125,7 @@ public class RODRecordIterator implements Ite named_constructor = type.getConstructor(String.class); } catch (java.lang.NoSuchMethodException e) { - throw new StingException("ROD class "+type.getName()+" does not have constructor that accepts a single String argument (track name)"); + throw new GATKException("ROD class "+type.getName()+" does not have constructor that accepts a single String argument (track name)"); } ROD rod = instantiateROD(name); fieldDelimiter = rod.delimiterRegex(); // get delimiter from the ROD itself @@ -232,11 +233,11 @@ public class RODRecordIterator implements Ite try { return (ROD) named_constructor.newInstance(name); } catch (java.lang.InstantiationException e) { - throw new StingException("Failed to instantiate ROD object of class "+type.getName()); + throw new GATKException("Failed to instantiate ROD object of class "+type.getName()); } catch (java.lang.IllegalAccessException e) { - throw new StingException("Access violation attempt while instantiating ROD object of class "+type.getName()); + throw new GATKException("Access violation attempt while instantiating ROD object of class "+type.getName()); } catch (InvocationTargetException e) { - throw new StingException("InvocationTargetException: Failed to instantiate ROD object of class "+type.getName()); + throw new GATKException("InvocationTargetException: Failed to instantiate ROD object of class "+type.getName()); } } diff --git a/java/src/org/broadinstitute/sting/gatk/refdata/RODRecordListImpl.java b/java/src/org/broadinstitute/sting/gatk/refdata/RODRecordListImpl.java index 6e2ebbd7f..c983e2a34 100644 --- a/java/src/org/broadinstitute/sting/gatk/refdata/RODRecordListImpl.java +++ b/java/src/org/broadinstitute/sting/gatk/refdata/RODRecordListImpl.java @@ -2,6 +2,7 @@ package org.broadinstitute.sting.gatk.refdata; import org.broadinstitute.sting.gatk.refdata.utils.GATKFeature; import org.broadinstitute.sting.gatk.refdata.utils.RODRecordList; +import org.broadinstitute.sting.utils.GATKException; import org.broadinstitute.sting.utils.GenomeLoc; import org.broadinstitute.sting.utils.StingException; @@ -47,10 +48,10 @@ public class RODRecordListImpl extends AbstractList implements Comp records.add(r); if ( r == null ) continue; if ( ! this.name.equals(r.getName() ) ) { - throw new StingException("Attempt to add GATKFeature with non-matching name "+r.getName()+" to the track "+name); + throw new GATKException("Attempt to add GATKFeature with non-matching name "+r.getName()+" to the track "+name); } if ( location != null && ! location.overlapsP(r.getLocation()) ) { - throw new StingException("Attempt to add GATKFeature that lies outside of specified interval "+location+"; offending GATKFeature:\n"+r.toString()); + throw new GATKException("Attempt to add GATKFeature that lies outside of specified interval "+location+"; offending GATKFeature:\n"+r.toString()); } } } @@ -72,7 +73,7 @@ public class RODRecordListImpl extends AbstractList implements Comp public void add(GATKFeature record, boolean allowNameMismatch) { if ( record != null ) { if ( ! allowNameMismatch && ! name.equals(record.getName() ) ) - throw new StingException("Attempt to add GATKFeature with non-matching name "+record.getName()+" to the track "+name); + throw new GATKException("Attempt to add GATKFeature with non-matching name "+record.getName()+" to the track "+name); } records.add(record); } diff --git a/java/src/org/broadinstitute/sting/gatk/refdata/RefMetaDataTracker.java b/java/src/org/broadinstitute/sting/gatk/refdata/RefMetaDataTracker.java index 4efd34cca..512621b2f 100644 --- a/java/src/org/broadinstitute/sting/gatk/refdata/RefMetaDataTracker.java +++ b/java/src/org/broadinstitute/sting/gatk/refdata/RefMetaDataTracker.java @@ -5,8 +5,10 @@ import org.broad.tribble.util.variantcontext.VariantContext; import org.broadinstitute.sting.gatk.contexts.ReferenceContext; import org.broadinstitute.sting.gatk.refdata.utils.GATKFeature; import org.broadinstitute.sting.gatk.refdata.utils.RODRecordList; +import org.broadinstitute.sting.utils.GATKException; import org.broadinstitute.sting.utils.GenomeLoc; import org.broadinstitute.sting.utils.StingException; +import org.broadinstitute.sting.utils.exceptions.UserError; import java.util.*; @@ -106,8 +108,8 @@ public class RefMetaDataTracker { Object obj = objects.get(0).getUnderlyingObject(); if (!(clazz.isAssignableFrom(obj.getClass()))) - throw new StingException("Unable to case track named " + name + " to type of " + clazz.toString() - + " it's of type " + obj.getClass()); + throw new UserError.CommandLineError("Unable to case track named " + name + " to type of " + clazz.toString() + + " it's of type " + obj.getClass()); return (T)obj; } @@ -289,7 +291,7 @@ public class RefMetaDataTracker { Collection contexts = getVariantContexts(ref, name, allowedTypes, curLocation, requireStartHere, false ); if ( contexts.size() > 1 ) - throw new StingException("Requested a single VariantContext object for track " + name + " but multiple variants were present at position " + curLocation); + throw new GATKException("Requested a single VariantContext object for track " + name + " but multiple variants were present at position " + curLocation); else if ( contexts.size() == 0 ) return null; else diff --git a/java/src/org/broadinstitute/sting/gatk/refdata/SeekableRODIterator.java b/java/src/org/broadinstitute/sting/gatk/refdata/SeekableRODIterator.java index 9229a8271..524e6def2 100644 --- a/java/src/org/broadinstitute/sting/gatk/refdata/SeekableRODIterator.java +++ b/java/src/org/broadinstitute/sting/gatk/refdata/SeekableRODIterator.java @@ -5,6 +5,7 @@ import org.broadinstitute.sting.gatk.iterators.PushbackIterator; import org.broadinstitute.sting.gatk.refdata.utils.GATKFeature; import org.broadinstitute.sting.gatk.refdata.utils.LocationAwareSeekableRODIterator; import org.broadinstitute.sting.gatk.refdata.utils.RODRecordList; +import org.broadinstitute.sting.utils.GATKException; import org.broadinstitute.sting.utils.GenomeLoc; import org.broadinstitute.sting.utils.GenomeLocParser; import org.broadinstitute.sting.utils.StingException; @@ -131,7 +132,7 @@ public class SeekableRODIterator implements LocationAwareSeekableRODIterator { */ public RODRecordList next() { if ( ! next_is_allowed ) - throw new StingException("Illegal use of iterator: Can not advance iterator with next() after seek-forward query of length > 1"); + throw new GATKException("Illegal use of iterator: Can not advance iterator with next() after seek-forward query of length > 1"); curr_position++; // curr_query_end = -1; @@ -178,7 +179,7 @@ public class SeekableRODIterator implements LocationAwareSeekableRODIterator { r = it.next(); // we got here only if we do need next record, time to load it for real long stop = r.getLocation().getStop(); - if ( stop < curr_position ) throw new StingException("DEBUG: encountered contig that should have been loaded earlier"); // this should never happen + if ( stop < curr_position ) throw new GATKException("DEBUG: encountered contig that should have been loaded earlier"); // this should never happen if ( stop > max_position ) max_position = stop; // max_position keeps the rightmost stop position across all loaded records records.add(r); } @@ -257,14 +258,14 @@ public class SeekableRODIterator implements LocationAwareSeekableRODIterator { public RODRecordList seekForward(GenomeLoc interval) { if ( interval.getContigIndex() < curr_contig ) - throw new StingException("Out of order query: query contig "+interval.getContig()+" is located before "+ + throw new GATKException("Out of order query: query contig "+interval.getContig()+" is located before "+ "the iterator's current contig"); if ( interval.getContigIndex() == curr_contig ) { if ( interval.getStart() < curr_position ) - throw new StingException("Out of order query: query position "+interval +" is located before "+ + throw new GATKException("Out of order query: query position "+interval +" is located before "+ "the iterator's current position "+curr_contig + ":" + curr_position); if ( interval.getStop() < curr_query_end ) - throw new StingException("Unsupported querying sequence: current query interval " + + throw new GATKException("Unsupported querying sequence: current query interval " + interval+" ends before the end of previous query interval ("+curr_query_end+")"); } diff --git a/java/src/org/broadinstitute/sting/gatk/refdata/features/refseq/RefSeqFeature.java b/java/src/org/broadinstitute/sting/gatk/refdata/features/refseq/RefSeqFeature.java index d593c4dc0..a0c303408 100644 --- a/java/src/org/broadinstitute/sting/gatk/refdata/features/refseq/RefSeqFeature.java +++ b/java/src/org/broadinstitute/sting/gatk/refdata/features/refseq/RefSeqFeature.java @@ -4,6 +4,7 @@ import org.broad.tribble.Feature; import org.broadinstitute.sting.gatk.refdata.Transcript; import org.broadinstitute.sting.gatk.refdata.utils.GATKFeature; import org.broadinstitute.sting.gatk.refdata.utils.RODRecordList; +import org.broadinstitute.sting.utils.GATKException; import org.broadinstitute.sting.utils.GenomeLoc; import org.broadinstitute.sting.utils.GenomeLocParser; import org.broadinstitute.sting.utils.StingException; @@ -60,7 +61,7 @@ public class RefSeqFeature implements Transcript, Feature { /** Genomic location of the n-th exon; throws an exception if n is out of bounds */ public GenomeLoc getExonLocation(int n) { - if ( n >= exons.size() || n < 0 ) throw new StingException("Index out-of-bounds. Transcript has " + exons.size() +" exons; requested: "+n); + if ( n >= exons.size() || n < 0 ) throw new GATKException("Index out-of-bounds. Transcript has " + exons.size() +" exons; requested: "+n); return exons.get(n); } diff --git a/java/src/org/broadinstitute/sting/gatk/refdata/tracks/RMDTrackManager.java b/java/src/org/broadinstitute/sting/gatk/refdata/tracks/RMDTrackManager.java index 91b51a117..cfeae8d5b 100644 --- a/java/src/org/broadinstitute/sting/gatk/refdata/tracks/RMDTrackManager.java +++ b/java/src/org/broadinstitute/sting/gatk/refdata/tracks/RMDTrackManager.java @@ -28,8 +28,10 @@ package org.broadinstitute.sting.gatk.refdata.tracks; import org.broadinstitute.sting.gatk.refdata.tracks.builders.RMDTrackBuilder; import org.broadinstitute.sting.gatk.refdata.utils.RMDTriplet; import org.broadinstitute.sting.gatk.GenomeAnalysisEngine; +import org.broadinstitute.sting.utils.GATKException; import org.broadinstitute.sting.utils.classloader.PluginManager; import org.broadinstitute.sting.utils.StingException; +import org.broadinstitute.sting.utils.exceptions.UserError; import java.io.File; import java.util.*; @@ -175,7 +177,7 @@ public class RMDTrackManager extends PluginManager { // create instances of each of the requested types for (RMDTriplet trip : inputs) { RMDTrackBuilder b = availableTrackBuilders.get(trip.getType().toUpperCase()); - if (b == null) throw new StingException("Unable to find track for " + trip.getType()); + if (b == null) throw new UserError.CommandLineError("Unable to find track for " + trip.getType()); tracks.add(b.createInstanceOfTrack(availableTrackTypes.get(trip.getType().toUpperCase()), trip.getName(), new File(trip.getFile()))); } return tracks; diff --git a/java/src/org/broadinstitute/sting/gatk/refdata/tracks/TribbleTrack.java b/java/src/org/broadinstitute/sting/gatk/refdata/tracks/TribbleTrack.java index ef4d71b59..8d24c63a9 100644 --- a/java/src/org/broadinstitute/sting/gatk/refdata/tracks/TribbleTrack.java +++ b/java/src/org/broadinstitute/sting/gatk/refdata/tracks/TribbleTrack.java @@ -30,6 +30,7 @@ import org.broad.tribble.FeatureSource; import org.broad.tribble.source.BasicFeatureSource; import org.broadinstitute.sting.gatk.refdata.utils.FeatureToGATKFeatureIterator; import org.broadinstitute.sting.gatk.refdata.utils.GATKFeature; +import org.broadinstitute.sting.utils.GATKException; import org.broadinstitute.sting.utils.GenomeLoc; import org.broadinstitute.sting.utils.StingException; import org.broadinstitute.sting.utils.exceptions.UserError; @@ -115,7 +116,7 @@ public class TribbleTrack extends RMDTrack implements QueryableTrack { try { reader.close(); } catch (IOException e) { - throw new StingException("Unable to close reader " + reader.toString(),e); + throw new GATKException("Unable to close reader " + reader.toString(),e); } reader = null; } diff --git a/java/src/org/broadinstitute/sting/gatk/refdata/tracks/builders/TribbleRMDTrackBuilder.java b/java/src/org/broadinstitute/sting/gatk/refdata/tracks/builders/TribbleRMDTrackBuilder.java index 51c9b8306..38a7ab295 100644 --- a/java/src/org/broadinstitute/sting/gatk/refdata/tracks/builders/TribbleRMDTrackBuilder.java +++ b/java/src/org/broadinstitute/sting/gatk/refdata/tracks/builders/TribbleRMDTrackBuilder.java @@ -39,6 +39,7 @@ import org.broad.tribble.util.LittleEndianOutputStream; import org.broadinstitute.sting.gatk.refdata.tracks.TribbleTrack; import org.broadinstitute.sting.gatk.refdata.tracks.RMDTrack; import org.broadinstitute.sting.gatk.refdata.tracks.RMDTrackCreationException; +import org.broadinstitute.sting.utils.GATKException; import org.broadinstitute.sting.utils.collections.Pair; import org.broadinstitute.sting.utils.classloader.PluginManager; import org.broadinstitute.sting.utils.StingException; @@ -230,7 +231,7 @@ public class TribbleRMDTrackBuilder extends PluginManager implemen locked = lock.sharedLock(); } catch(FileSystemInabilityToLockException ex) { - throw new StingException("Unexpected inability to lock exception", ex); + throw new GATKException("Unexpected inability to lock exception", ex); } Index idx; try { @@ -297,7 +298,7 @@ public class TribbleRMDTrackBuilder extends PluginManager implemen return index; } catch(FileSystemInabilityToLockException ex) { - throw new StingException("Unexpected inability to lock exception", ex); + throw new GATKException("Unexpected inability to lock exception", ex); } finally { if (locked) lock.unlock(); diff --git a/java/src/org/broadinstitute/sting/gatk/walkers/analyzeannotations/AnnotationDatum.java b/java/src/org/broadinstitute/sting/gatk/walkers/analyzeannotations/AnnotationDatum.java index 063cf3e62..aa0dce51e 100755 --- a/java/src/org/broadinstitute/sting/gatk/walkers/analyzeannotations/AnnotationDatum.java +++ b/java/src/org/broadinstitute/sting/gatk/walkers/analyzeannotations/AnnotationDatum.java @@ -1,5 +1,6 @@ package org.broadinstitute.sting.gatk.walkers.analyzeannotations; +import org.broadinstitute.sting.utils.GATKException; import org.broadinstitute.sting.utils.StingException; import java.util.Comparator; @@ -114,7 +115,7 @@ public class AnnotationDatum implements Comparator { final public float calcTiTv( final int INDEX ) { if( ti[INDEX] < 0 || tv[INDEX] < 0 ) { - throw new StingException( "Integer overflow detected! There are too many variants piled up in one annotation bin." ); + throw new GATKException( "Integer overflow detected! There are too many variants piled up in one annotation bin." ); } if( tv[INDEX] == 0 ) { // Don't divide by zero diff --git a/java/src/org/broadinstitute/sting/gatk/walkers/annotator/HaplotypeScore.java b/java/src/org/broadinstitute/sting/gatk/walkers/annotator/HaplotypeScore.java index 3ac6d51da..0372eecd3 100644 --- a/java/src/org/broadinstitute/sting/gatk/walkers/annotator/HaplotypeScore.java +++ b/java/src/org/broadinstitute/sting/gatk/walkers/annotator/HaplotypeScore.java @@ -197,7 +197,7 @@ public class HaplotypeScore implements InfoFieldAnnotation, StandardAnnotation { String b = haplotypeB.toString(); if (a.length() != b.length()) - throw new StingException("Haplotypes a and b must be of same length"); + throw new GATKException("Haplotypes a and b must be of same length"); char chA, chB; char wc = REGEXP_WILDCARD.charAt(0); diff --git a/java/src/org/broadinstitute/sting/gatk/walkers/annotator/VariantAnnotatorEngine.java b/java/src/org/broadinstitute/sting/gatk/walkers/annotator/VariantAnnotatorEngine.java index 3a19ed2bb..e7abae70a 100755 --- a/java/src/org/broadinstitute/sting/gatk/walkers/annotator/VariantAnnotatorEngine.java +++ b/java/src/org/broadinstitute/sting/gatk/walkers/annotator/VariantAnnotatorEngine.java @@ -49,6 +49,7 @@ import org.broadinstitute.sting.gatk.refdata.RefMetaDataTracker; import org.broadinstitute.sting.gatk.refdata.utils.helpers.DbSNPHelper; import org.broadinstitute.sting.gatk.walkers.annotator.interfaces.*; import org.broadinstitute.sting.gatk.walkers.annotator.genomicannotator.*; +import org.broadinstitute.sting.utils.GATKException; import org.broadinstitute.sting.utils.StingException; import org.broadinstitute.sting.utils.classloader.PackageUtils; import org.broadinstitute.sting.utils.exceptions.UserError; @@ -168,7 +169,7 @@ public class VariantAnnotatorEngine { Collection results = this.annotateContext(tracker, ref, EMPTY_STRATIFIED_ALIGNMENT_CONTEXT, vc); if ( results.size() != 1 ) - throw new StingException("BUG: annotateContext call requires 1 resulting annotated VC, but got " + results); + throw new GATKException("BUG: annotateContext call requires 1 resulting annotated VC, but got " + results); return results.iterator().next(); diff --git a/java/src/org/broadinstitute/sting/gatk/walkers/annotator/genomicannotator/JoinTable.java b/java/src/org/broadinstitute/sting/gatk/walkers/annotator/genomicannotator/JoinTable.java index e4c09d4f9..57fd8b355 100755 --- a/java/src/org/broadinstitute/sting/gatk/walkers/annotator/genomicannotator/JoinTable.java +++ b/java/src/org/broadinstitute/sting/gatk/walkers/annotator/genomicannotator/JoinTable.java @@ -33,6 +33,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; +import org.broadinstitute.sting.utils.GATKException; import org.broadinstitute.sting.utils.StingException; import org.broadinstitute.sting.utils.exceptions.UserError; @@ -83,7 +84,7 @@ public class JoinTable */ public void parseFromFile(String filename, String localBindingName, String localColumnName, String externalBindingName, String externalColumnName) { if(parsedFromFile) { - throw new StingException("parseFromFile(" + filename +", ..) called more than once"); + throw new GATKException("parseFromFile(" + filename +", ..) called more than once"); } parsedFromFile = true; @@ -135,7 +136,7 @@ public class JoinTable br.close(); } } catch(IOException e) { - throw new StingException("Unable to close file: " + filename, e); + throw new GATKException("Unable to close file: " + filename, e); } } } diff --git a/java/src/org/broadinstitute/sting/gatk/walkers/annotator/genomicannotator/JoinTableParser.java b/java/src/org/broadinstitute/sting/gatk/walkers/annotator/genomicannotator/JoinTableParser.java index a4f25a516..cfe1478f3 100755 --- a/java/src/org/broadinstitute/sting/gatk/walkers/annotator/genomicannotator/JoinTableParser.java +++ b/java/src/org/broadinstitute/sting/gatk/walkers/annotator/genomicannotator/JoinTableParser.java @@ -31,6 +31,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; +import org.broadinstitute.sting.utils.GATKException; import org.broadinstitute.sting.utils.StingException; import org.broadinstitute.sting.utils.Utils; import org.broadinstitute.sting.utils.exceptions.UserError; @@ -63,7 +64,7 @@ public class JoinTableParser public List readHeader(BufferedReader br) throws IOException { if(header != null) { - throw new StingException("readHeader(..) called more than once. Header is currently set to: " + header); + throw new GATKException("readHeader(..) called more than once. Header is currently set to: " + header); } header = Collections.unmodifiableList(parseHeader(br)); diff --git a/java/src/org/broadinstitute/sting/gatk/walkers/annotator/genomicannotator/TranscriptToGenomicInfo.java b/java/src/org/broadinstitute/sting/gatk/walkers/annotator/genomicannotator/TranscriptToGenomicInfo.java index e80a8ca43..402dd76ab 100755 --- a/java/src/org/broadinstitute/sting/gatk/walkers/annotator/genomicannotator/TranscriptToGenomicInfo.java +++ b/java/src/org/broadinstitute/sting/gatk/walkers/annotator/genomicannotator/TranscriptToGenomicInfo.java @@ -44,7 +44,9 @@ import org.broadinstitute.sting.gatk.walkers.Requires; import org.broadinstitute.sting.gatk.walkers.RodWalker; import org.broadinstitute.sting.gatk.walkers.Window; import org.broadinstitute.sting.utils.BaseUtils; +import org.broadinstitute.sting.utils.GATKException; import org.broadinstitute.sting.utils.StingException; +import org.broadinstitute.sting.utils.exceptions.UserError; /** @@ -173,12 +175,12 @@ public class TranscriptToGenomicInfo extends RodWalker { try { header = AnnotatorInputTableCodec.readHeader(transcriptsDataSource.getReferenceOrderedData().getFile()); } catch(Exception e) { - throw new StingException("Failed when attempting to read header from file: " + transcriptsDataSource.getReferenceOrderedData().getFile(), e); + throw new UserError.MalformedFile(transcriptsDataSource.getReferenceOrderedData().getFile(), "Failed when attempting to read header from file", e); } for ( String columnName : GENE_NAME_COLUMNS ) { if ( !header.contains(columnName) ) - throw new StingException("The column name '" + columnName + "' provided to -n doesn't match any of the column names in: " + transcriptsDataSource.getReferenceOrderedData().getFile()); + throw new UserError.CommandLineError("The column name '" + columnName + "' provided to -n doesn't match any of the column names in: " + transcriptsDataSource.getReferenceOrderedData().getFile()); } //init outputColumnNames list @@ -973,7 +975,7 @@ public class TranscriptToGenomicInfo extends RodWalker { */ public int computeInitialCodingCoord() { if(!isProteinCodingTranscript()) { - throw new StingException("This method should only be called for protein-coding transcripts"); + throw new GATKException("This method should only be called for protein-coding transcripts"); } if(positiveStrand) diff --git a/java/src/org/broadinstitute/sting/gatk/walkers/annotator/genomicannotator/TranscriptToInfo.java b/java/src/org/broadinstitute/sting/gatk/walkers/annotator/genomicannotator/TranscriptToInfo.java index a68514eeb..002c6d68e 100755 --- a/java/src/org/broadinstitute/sting/gatk/walkers/annotator/genomicannotator/TranscriptToInfo.java +++ b/java/src/org/broadinstitute/sting/gatk/walkers/annotator/genomicannotator/TranscriptToInfo.java @@ -42,6 +42,7 @@ import org.broadinstitute.sting.gatk.walkers.RodWalker; import org.broadinstitute.sting.gatk.walkers.TreeReducible; import org.broadinstitute.sting.gatk.walkers.Window; import org.broadinstitute.sting.utils.StingException; +import org.broadinstitute.sting.utils.exceptions.UserError; /** @@ -70,7 +71,7 @@ public class TranscriptToInfo extends RodWalker implements Tre private String[] GENE_NAME_COLUMNS = {}; public void initialize() { - throw new StingException("This walker is no longer supported. We are actively working on a bug-free replacement. We thank you for your patience at this time."); + throw new UserError.MissingWalker("TranscriptToInfo", "This walker is no longer supported. We are actively working on a bug-free replacement. We thank you for your patience at this time."); } public Integer reduceInit() { return 0; } diff --git a/java/src/org/broadinstitute/sting/gatk/walkers/coverage/CallableLociWalker.java b/java/src/org/broadinstitute/sting/gatk/walkers/coverage/CallableLociWalker.java index da8706e62..39fe1b922 100755 --- a/java/src/org/broadinstitute/sting/gatk/walkers/coverage/CallableLociWalker.java +++ b/java/src/org/broadinstitute/sting/gatk/walkers/coverage/CallableLociWalker.java @@ -29,6 +29,7 @@ import org.broadinstitute.sting.gatk.walkers.By; import org.broadinstitute.sting.gatk.walkers.DataSource; import org.broadinstitute.sting.gatk.walkers.LocusWalker; import org.broadinstitute.sting.utils.*; +import org.broadinstitute.sting.utils.exceptions.UserError; import org.broadinstitute.sting.utils.pileup.PileupElement; import org.broadinstitute.sting.commandline.Argument; import org.broadinstitute.sting.commandline.Output; @@ -91,7 +92,7 @@ public class CallableLociWalker extends LocusWalker bindings = tracker.getReferenceMetaData(track); if ( bindings.size() != 1 || ! (bindings.get(0) instanceof FullBEDFeature)) { - throw new StingException(String.format("%s track isn't a properly formated CallableBases object!", track)); + throw new UserError.MalformedFile(String.format("%s track isn't a properly formated CallableBases object!", track)); } FullBEDFeature bed = (FullBEDFeature)bindings.get(0); diff --git a/java/src/org/broadinstitute/sting/gatk/walkers/coverage/CoverageUtils.java b/java/src/org/broadinstitute/sting/gatk/walkers/coverage/CoverageUtils.java index c5efe3df6..6f11d0d15 100644 --- a/java/src/org/broadinstitute/sting/gatk/walkers/coverage/CoverageUtils.java +++ b/java/src/org/broadinstitute/sting/gatk/walkers/coverage/CoverageUtils.java @@ -4,7 +4,9 @@ import net.sf.samtools.SAMReadGroupRecord; import net.sf.samtools.SAMRecord; import org.broadinstitute.sting.gatk.contexts.AlignmentContext; import org.broadinstitute.sting.utils.BaseUtils; +import org.broadinstitute.sting.utils.GATKException; import org.broadinstitute.sting.utils.StingException; +import org.broadinstitute.sting.utils.exceptions.UserError; import org.broadinstitute.sting.utils.pileup.PileupElement; import java.util.*; @@ -56,7 +58,7 @@ public class CoverageUtils { } else if ( type == DoCOutputType.Partition.sample_by_platform_by_center ) { return String.format("%s_pl_%s_cn_%s",r.getSample(),r.getPlatform(),r.getSequencingCenter()); } else { - throw new StingException("Invalid type ID sent to getTypeID. This is a BUG!"); + throw new GATKException("Invalid type ID sent to getTypeID. This is a BUG!"); } } @@ -118,7 +120,7 @@ public class CoverageUtils { try { counts[BaseUtils.simpleBaseToBaseIndex(e.getBase())]++; } catch (ArrayIndexOutOfBoundsException exc) { - throw new StingException("Expected a simple base, but actually received"+(char)e.getBase()); + throw new GATKException("Expected a simple base, but actually received"+(char)e.getBase()); } } } @@ -126,10 +128,8 @@ public class CoverageUtils { private static SAMReadGroupRecord getReadGroup(SAMRecord r) { SAMReadGroupRecord rg = r.getReadGroup(); if ( rg == null ) { - String msg = "Read "+r.getReadName()+" lacks read group information."; - msg += " Please associate all reads with read groups [recommended]\n"; - msg += " Or run with -rf MissingReadGroup [not recommended]"; - throw new StingException(msg); + String msg = "Read "+r.getReadName()+" lacks read group information; Please associate all reads with read groups"; + throw new UserError.MalformedBam(r, msg); } return rg; diff --git a/java/src/org/broadinstitute/sting/gatk/walkers/coverage/DepthOfCoverageWalker.java b/java/src/org/broadinstitute/sting/gatk/walkers/coverage/DepthOfCoverageWalker.java index 025458813..d393ccb77 100644 --- a/java/src/org/broadinstitute/sting/gatk/walkers/coverage/DepthOfCoverageWalker.java +++ b/java/src/org/broadinstitute/sting/gatk/walkers/coverage/DepthOfCoverageWalker.java @@ -36,13 +36,11 @@ import org.broadinstitute.sting.gatk.refdata.features.refseq.RefSeqFeature; import org.broadinstitute.sting.gatk.refdata.tracks.builders.TribbleRMDTrackBuilder; import org.broadinstitute.sting.gatk.refdata.utils.*; import org.broadinstitute.sting.gatk.walkers.*; -import org.broadinstitute.sting.utils.BaseUtils; -import org.broadinstitute.sting.utils.GenomeLoc; -import org.broadinstitute.sting.utils.Utils; +import org.broadinstitute.sting.utils.*; import org.broadinstitute.sting.utils.collections.Pair; -import org.broadinstitute.sting.utils.StingException; import org.broadinstitute.sting.commandline.Argument; import org.broadinstitute.sting.commandline.Output; +import org.broadinstitute.sting.utils.exceptions.UserError; import java.io.File; import java.io.IOException; @@ -227,7 +225,7 @@ public class DepthOfCoverageWalker extends LocusWalker maxWindowElements() || elementsToRight > maxWindowElements() ) - throw new StingException("Too large a window requested"); + throw new GATKException("Too large a window requested"); if ( elementsToLeft < 0 || elementsToRight < 0 ) - throw new StingException("Window size cannot be negative"); + throw new GATKException("Window size cannot be negative"); FiltrationContext[] array = new FiltrationContext[elementsToLeft + elementsToRight + 1]; ListIterator iter = window.listIterator(currentContext - elementsToLeft); diff --git a/java/src/org/broadinstitute/sting/gatk/walkers/genotyper/DiploidGenotypeCalculationModel.java b/java/src/org/broadinstitute/sting/gatk/walkers/genotyper/DiploidGenotypeCalculationModel.java index a3be36af0..df4b19ae3 100755 --- a/java/src/org/broadinstitute/sting/gatk/walkers/genotyper/DiploidGenotypeCalculationModel.java +++ b/java/src/org/broadinstitute/sting/gatk/walkers/genotyper/DiploidGenotypeCalculationModel.java @@ -191,7 +191,7 @@ public class DiploidGenotypeCalculationModel extends JointEstimateGenotypeCalcul public void incrementFrequency() { if ( frequency == 2 * N ) - throw new StingException("Frequency was incremented past N; how is this possible?"); + throw new GATKException("Frequency was incremented past N; how is this possible?"); frequency++; double greedy = VALUE_NOT_CALCULATED; @@ -218,7 +218,7 @@ public class DiploidGenotypeCalculationModel extends JointEstimateGenotypeCalcul // so we can ignore that case } if ( greedyIndex == -1 ) - throw new StingException("There is no best choice for a new alternate allele; how is this possible?"); + throw new GATKException("There is no best choice for a new alternate allele; how is this possible?"); if ( indexes[greedyIndex] == GenotypeType.HET.ordinal() ) indexes[greedyIndex] = GenotypeType.HOM.ordinal(); diff --git a/java/src/org/broadinstitute/sting/gatk/walkers/genotyper/SimpleIndelCalculationModel.java b/java/src/org/broadinstitute/sting/gatk/walkers/genotyper/SimpleIndelCalculationModel.java index 7750ebdf1..c93578873 100755 --- a/java/src/org/broadinstitute/sting/gatk/walkers/genotyper/SimpleIndelCalculationModel.java +++ b/java/src/org/broadinstitute/sting/gatk/walkers/genotyper/SimpleIndelCalculationModel.java @@ -71,7 +71,7 @@ public class SimpleIndelCalculationModel extends GenotypeCalculationModel { alleles.add( Allele.create(bestEvent.substring(1), true )); loc = GenomeLocParser.setStop(loc, loc.getStop() + bestEvent.length()-1); } else - throw new StingException("Internal error (probably a bug): event does not conform to expected format: "+ bestEvent); + throw new GATKException("Internal error (probably a bug): event does not conform to expected format: "+ bestEvent); } VariantContext vc = new VariantContext("UG_Indel_call", loc.getContig(), loc.getStart(), loc.getStop(), alleles, new HashMap() /* genotypes */, diff --git a/java/src/org/broadinstitute/sting/gatk/walkers/indels/IndelGenotyperV2Walker.java b/java/src/org/broadinstitute/sting/gatk/walkers/indels/IndelGenotyperV2Walker.java index 77ad9a829..4abe58509 100644 --- a/java/src/org/broadinstitute/sting/gatk/walkers/indels/IndelGenotyperV2Walker.java +++ b/java/src/org/broadinstitute/sting/gatk/walkers/indels/IndelGenotyperV2Walker.java @@ -25,10 +25,7 @@ package org.broadinstitute.sting.gatk.walkers.indels; -import net.sf.samtools.Cigar; -import net.sf.samtools.CigarElement; -import net.sf.samtools.CigarOperator; -import net.sf.samtools.SAMRecord; +import net.sf.samtools.*; import org.broad.tribble.FeatureSource; import org.broad.tribble.util.variantcontext.Allele; import org.broad.tribble.util.variantcontext.VariantContext; @@ -51,6 +48,7 @@ import org.broadinstitute.sting.gatk.contexts.ReferenceContext; import org.broadinstitute.sting.gatk.GenomeAnalysisEngine; import org.broadinstitute.sting.gatk.datasources.simpleDataSources.ReferenceDataSource; import org.broadinstitute.sting.utils.*; +import org.broadinstitute.sting.utils.exceptions.UserError; import org.broadinstitute.sting.utils.vcf.VCFUtils; import org.broadinstitute.sting.utils.sam.AlignmentUtils; import org.broadinstitute.sting.utils.collections.CircularArray; @@ -213,7 +211,7 @@ public class IndelGenotyperV2Walker extends ReadWalker { normal_context = new WindowContext(0,WINDOW_SIZE); if ( bedOutput != null && output_file != null ) { - throw new StingException("-O option is deprecated and -bed option replaces it; you can not use both at the same time"); + throw new UserError.DeprecatedArgument("-O", "-O option is deprecated and -bed option replaces it; you can not use both at the same time"); } if ( RefseqFileName != null ) { @@ -225,7 +223,7 @@ public class IndelGenotyperV2Walker extends ReadWalker { try { refseqIterator = new SeekableRODIterator(new FeatureToGATKFeatureIterator(refseq.iterator(),"refseq")); } catch (IOException e) { - throw new StingException("Unable to open file " + RefseqFileName, e); + throw new UserError.CouldNotReadInputFile(new File(RefseqFileName), "Write failed", e); } } @@ -266,12 +264,12 @@ public class IndelGenotyperV2Walker extends ReadWalker { if ( bedOutput != null ) bedWriter = new FileWriter(bedOutput); if ( output_file != null ) bedWriter = new FileWriter(output_file); } catch (java.io.IOException e) { - throw new StingException("Failed to open BED file for writing. "+ e.getMessage()); + throw new UserError.CouldNotReadInputFile(bedOutput, "Failed to open BED file for writing.", e); } try { if ( verboseOutput != null ) verboseWriter = new FileWriter(verboseOutput); } catch (java.io.IOException e) { - throw new StingException("Failed to open verbose file for writing. "+ e.getMessage()); + throw new UserError.CouldNotReadInputFile(verboseOutput, "Failed to open BED file for writing.", e); } vcf_writer.writeHeader(new VCFHeader(getVCFHeaderInfo(), SampleUtils.getSAMFileSamples(getToolkit().getSAMFileHeader()))) ; @@ -301,7 +299,7 @@ public class IndelGenotyperV2Walker extends ReadWalker { // we just jumped onto a new contig if ( DEBUG ) System.out.println("DEBUG>>> Moved to contig "+read.getReferenceName()); if ( read.getReferenceIndex() < currentContigIndex ) // paranoidal - throw new StingException("Read "+read.getReadName()+": contig is out of order; input BAM file is unsorted"); + throw new UserError.MissortedBAM(SAMFileHeader.SortOrder.coordinate, read, "Read "+read.getReadName()+": contig is out of order; input BAM file is unsorted"); // print remaining indels from the previous contig (if any); if ( call_somatic ) emit_somatic(1000000000, true); @@ -329,10 +327,10 @@ public class IndelGenotyperV2Walker extends ReadWalker { // tumor_context are synchronized exactly (windows are always shifted together by emit_somatic), so it's safe if ( read.getAlignmentStart() < currentPosition ) // oops, read out of order? - throw new StingException("Read "+read.getReadName() +" out of order on the contig\n"+ - "Read starts at "+refName+":"+read.getAlignmentStart()+"; last read seen started at "+refName+":"+currentPosition - +"\nLast read was: "+lastRead.getReadName()+" RG="+lastRead.getAttribute("RG")+" at "+lastRead.getAlignmentStart()+"-" - +lastRead.getAlignmentEnd()+" cigar="+lastRead.getCigarString()); + throw new UserError.MissortedBAM(SAMFileHeader.SortOrder.coordinate, read, "Read "+read.getReadName() +" out of order on the contig\n"+ + "Read starts at "+refName+":"+read.getAlignmentStart()+"; last read seen started at "+refName+":"+currentPosition + +"\nLast read was: "+lastRead.getReadName()+" RG="+lastRead.getAttribute("RG")+" at "+lastRead.getAlignmentStart()+"-" + +lastRead.getAlignmentEnd()+" cigar="+lastRead.getCigarString()); currentPosition = read.getAlignmentStart(); lastRead = read; @@ -384,7 +382,7 @@ public class IndelGenotyperV2Walker extends ReadWalker { // let's double check now that the read fits after the shift if ( read.getAlignmentEnd() > normal_context.getStop()) { // ooops, looks like the read does not fit into the window even after the latter was shifted!! - throw new StingException("Read "+read.getReadName()+": out of coverage window bounds. Probably window is too small.\n"+ + throw new UserError.MissortedBAM(SAMFileHeader.SortOrder.coordinate, read, "Read "+read.getReadName()+": out of coverage window bounds. Probably window is too small.\n"+ "Read length="+read.getReadLength()+"; cigar="+read.getCigarString()+"; start="+ read.getAlignmentStart()+"; end="+read.getAlignmentEnd()+ "; window start (after trying to accomodate the read)="+normal_context.getStart()+ @@ -395,14 +393,15 @@ public class IndelGenotyperV2Walker extends ReadWalker { if ( call_somatic ) { String rg = (String)read.getAttribute("RG"); - if ( rg == null ) throw new StingException("Read "+read.getReadName()+" has no read group in merged stream. RG is required for somatic calls."); + if ( rg == null ) + throw new UserError.MalformedBam(read, "Read "+read.getReadName()+" has no read group in merged stream. RG is required for somatic calls."); if ( normalReadGroups.contains(rg) ) { normal_context.add(read,ref.getBases()); } else if ( tumorReadGroups.contains(rg) ) { tumor_context.add(read,ref.getBases()); } else { - throw new StingException("Unrecognized read group in merged stream: "+rg); + throw new UserError.MalformedBam(read, "Unrecognized read group in merged stream: "+rg); } if ( tumor_context.getReads().size() > MAX_READ_NUMBER ) { System.out.println("WARNING: a count of "+MAX_READ_NUMBER+" reads reached in a window "+ @@ -504,7 +503,7 @@ public class IndelGenotyperV2Walker extends ReadWalker { verboseWriter.write(fullRecord.toString()); verboseWriter.write('\n'); } catch (IOException e) { - throw new StingException("Write failed (verbose writer). "+e.getMessage()); + throw new UserError.CouldNotCreateOutputFile(verboseOutput, "Write failed", e); } } } @@ -664,7 +663,7 @@ public class IndelGenotyperV2Walker extends ReadWalker { verboseWriter.write(fullRecord + "\t"+ annotationString); verboseWriter.write('\n'); } catch (IOException e) { - throw new StingException("Write failed (verbose writer). "+e.getMessage()); + throw new UserError.CouldNotCreateOutputFile(verboseOutput, "Write failed", e); } } } @@ -1223,7 +1222,7 @@ public class IndelGenotyperV2Walker extends ReadWalker { try { bed.write(message.toString()+"\n"); } catch (IOException e) { - throw new StingException("Error encountered while writing into output BED file"); + throw new UserError.CouldNotCreateOutputFile(bedOutput, "Error encountered while writing into output BED file", e); } } diff --git a/java/src/org/broadinstitute/sting/gatk/walkers/indels/IndelRealigner.java b/java/src/org/broadinstitute/sting/gatk/walkers/indels/IndelRealigner.java index 4bd2f408f..e61d7f847 100755 --- a/java/src/org/broadinstitute/sting/gatk/walkers/indels/IndelRealigner.java +++ b/java/src/org/broadinstitute/sting/gatk/walkers/indels/IndelRealigner.java @@ -31,6 +31,7 @@ import net.sf.samtools.util.SequenceUtil; import net.sf.picard.reference.IndexedFastaSequenceFile; import org.broad.tribble.util.variantcontext.VariantContext; import org.broadinstitute.sting.commandline.*; +import org.broadinstitute.sting.utils.exceptions.UserError; import org.broadinstitute.sting.utils.interval.IntervalMergingRule; import org.broadinstitute.sting.utils.interval.IntervalUtils; import org.broadinstitute.sting.gatk.contexts.ReferenceContext; @@ -333,7 +334,7 @@ public class IndelRealigner extends ReadWalker { currentInterval = intervals.hasNext() ? intervals.next() : null; } while ( currentInterval != null && (readLoc == null || currentInterval.isBefore(readLoc)) ); } catch (StingException e) { - throw new StingException(e.getMessage() + " *** Are you sure that your interval file is sorted? If not, you must use the --targetIntervalsAreNotSorted argument. ***"); + throw new UserError.MissortedFile(new File(intervalsFile), " *** Are you sure that your interval file is sorted? If not, you must use the --targetIntervalsAreNotSorted argument. ***", e); } @@ -531,7 +532,7 @@ public class IndelRealigner extends ReadWalker { statsOutput.write("\n"); statsOutput.flush(); } catch (Exception e) { - throw new StingException(e.getMessage()); + throw new UserError.CouldNotCreateOutputFile("statsOutput", "Failed to write stats output file", e); } } } else { @@ -558,7 +559,7 @@ public class IndelRealigner extends ReadWalker { indelOutput.write(str.toString()); indelOutput.flush(); } catch (Exception e) { - throw new StingException(e.getMessage()); + throw new UserError.CouldNotCreateOutputFile("indelOutput", "Failed to write indel output file", e); } } if ( statsOutput != null ) { @@ -572,7 +573,7 @@ public class IndelRealigner extends ReadWalker { statsOutput.write("\n"); statsOutput.flush(); } catch (Exception e) { - throw new StingException(e.getMessage()); + throw new UserError.CouldNotCreateOutputFile("statsOutput", "Failed to write stats output file", e); } } @@ -607,7 +608,7 @@ public class IndelRealigner extends ReadWalker { currentInterval.toString(), improvement)); statsOutput.flush(); } catch (Exception e) { - throw new StingException(e.getMessage()); + throw new UserError.CouldNotCreateOutputFile("statsOutput", "Failed to write stats output file", e); } } } @@ -1047,7 +1048,7 @@ public class IndelRealigner extends ReadWalker { snpsOutput.write(sb.toString()); snpsOutput.flush(); } catch (Exception e) { - throw new StingException(e.getMessage()); + throw new UserError.CouldNotCreateOutputFile("snpsOutput", "Failed to write SNPs output file", e); } } return reduces; diff --git a/java/src/org/broadinstitute/sting/gatk/walkers/indels/RealignerTargetCreator.java b/java/src/org/broadinstitute/sting/gatk/walkers/indels/RealignerTargetCreator.java index a333b570d..3d090e87c 100755 --- a/java/src/org/broadinstitute/sting/gatk/walkers/indels/RealignerTargetCreator.java +++ b/java/src/org/broadinstitute/sting/gatk/walkers/indels/RealignerTargetCreator.java @@ -33,11 +33,13 @@ import org.broadinstitute.sting.gatk.filters.ZeroMappingQualityReadFilter; import org.broadinstitute.sting.gatk.filters.BadMateFilter; import org.broadinstitute.sting.gatk.refdata.RefMetaDataTracker; import org.broadinstitute.sting.gatk.walkers.*; +import org.broadinstitute.sting.utils.GATKException; import org.broadinstitute.sting.utils.GenomeLoc; import org.broadinstitute.sting.utils.GenomeLocParser; import org.broadinstitute.sting.utils.StingException; import org.broadinstitute.sting.commandline.Argument; import org.broadinstitute.sting.commandline.Output; +import org.broadinstitute.sting.utils.exceptions.UserError; import org.broadinstitute.sting.utils.pileup.ExtendedEventPileupElement; import org.broadinstitute.sting.utils.pileup.PileupElement; import org.broadinstitute.sting.utils.pileup.ReadBackedExtendedEventPileup; @@ -83,7 +85,7 @@ public class RealignerTargetCreator extends RodWalker { private Map cyclesByLibraryMapOrig = null; public void initialize() { - if ( PREFIX == null ) throw new StingException("Prefix for output file(s) must be specified"); + if ( PREFIX == null ) throw new GATKException("Prefix for output file(s) must be specified"); cyclesByLaneMap = new HashMap(); cyclesByLibraryMap = new HashMap(); cyclesByLaneMapOrig = new HashMap(); @@ -94,23 +96,25 @@ public class CycleQualityWalker extends ReadWalker { SAMReadGroupRecord rg = read.getReadGroup(); - if ( rg == null ) throw new StingException("Read "+read.getReadName()+" is not assigned to any read group"); + if ( rg == null ) throw new UserError.ReadMissingReadGroup(read); String lane = read.getReadGroup().getPlatformUnit(); String library = read.getReadGroup().getLibrary(); - if ( lane == null ) throw new StingException("Read "+read.getReadName()+" has no platform unit information"); - if ( library == null ) throw new StingException("Read "+read.getReadName()+" has no library information"); + if ( lane == null ) throw new UserError.MalformedBam(read, "Read "+read.getReadName()+" has no platform unit information"); + if ( library == null ) throw new UserError.MalformedBam(read, "Read "+read.getReadName()+" has no library information"); int end = 0; if ( read.getReadPairedFlag() ) { if ( read.getFirstOfPairFlag() ) { - if ( read.getSecondOfPairFlag() ) throw new StingException("Read "+read.getReadName()+" has conflicting first/second in pair attributes"); + if ( read.getSecondOfPairFlag() ) + throw new UserError.MalformedBam(read, "Read "+read.getReadName()+" has conflicting first/second in pair attributes"); end = 1; } else { - if ( ! read.getSecondOfPairFlag() ) throw new StingException("Read "+read.getReadName()+" has conflicting first/second in pair attributes"); + if ( ! read.getSecondOfPairFlag() ) + throw new UserError.MalformedBam(read, "Read "+read.getReadName()+" has conflicting first/second in pair attributes"); end = 2; } } @@ -357,7 +361,7 @@ public class CycleQualityWalker extends ReadWalker { } } catch (IOException ioe) { - throw new StingException("Failed to write report into the file "+f+":\n"+ioe.getMessage()); + throw new UserError.CouldNotCreateOutputFile(f, "Failed to write report", ioe); } } @@ -403,8 +407,8 @@ public class CycleQualityWalker extends ReadWalker { } public void add(byte[] quals) { - if ( quals.length > cycleQualsAv.length ) throw new StingException("A read of length "+quals.length+ - " encountered, which exceeds specified maximum read length"); + if ( quals.length > cycleQualsAv.length ) + throw new UserError("A read of length "+quals.length+" encountered, which exceeds specified maximum read length"); if ( quals.length > maxL ) maxL = quals.length; if ( quals.length < minL ) minL = quals.length; readCount++; diff --git a/java/src/org/broadinstitute/sting/gatk/walkers/qc/ReadClippingStatsWalker.java b/java/src/org/broadinstitute/sting/gatk/walkers/qc/ReadClippingStatsWalker.java index a50129f24..f552e9ea9 100755 --- a/java/src/org/broadinstitute/sting/gatk/walkers/qc/ReadClippingStatsWalker.java +++ b/java/src/org/broadinstitute/sting/gatk/walkers/qc/ReadClippingStatsWalker.java @@ -30,6 +30,7 @@ import org.broadinstitute.sting.gatk.contexts.ReferenceContext; import org.broadinstitute.sting.utils.StingException; import org.broadinstitute.sting.utils.Utils; import org.broadinstitute.sting.utils.MathUtils; +import org.broadinstitute.sting.utils.exceptions.UserError; import org.broadinstitute.sting.utils.sam.AlignmentUtils; import org.broadinstitute.sting.commandline.Argument; import org.broadinstitute.sting.commandline.Output; @@ -76,7 +77,7 @@ public class ReadClippingStatsWalker extends ReadWalker { try { m = MessageDigest.getInstance("MD5"); } catch (NoSuchAlgorithmException e) { - throw new StingException("Unable to get the MD5 algorithm. Get a more eXtreme version of JAVA!@!@!!"); + throw new GATKException("Unable to get the MD5 algorithm. Get a more eXtreme version of JAVA!@!@!!"); } } diff --git a/java/src/org/broadinstitute/sting/gatk/walkers/qc/ValidatingPileupWalker.java b/java/src/org/broadinstitute/sting/gatk/walkers/qc/ValidatingPileupWalker.java index 53685879f..b906d1bd1 100755 --- a/java/src/org/broadinstitute/sting/gatk/walkers/qc/ValidatingPileupWalker.java +++ b/java/src/org/broadinstitute/sting/gatk/walkers/qc/ValidatingPileupWalker.java @@ -30,12 +30,10 @@ import org.broadinstitute.sting.gatk.contexts.ReferenceContext; import org.broadinstitute.sting.gatk.refdata.RefMetaDataTracker; import org.broadinstitute.sting.gatk.refdata.features.sampileup.SAMPileupFeature; import org.broadinstitute.sting.gatk.walkers.*; -import org.broadinstitute.sting.utils.StingException; -import org.broadinstitute.sting.utils.Utils; -import org.broadinstitute.sting.utils.GenomeLoc; -import org.broadinstitute.sting.utils.GenomeLocParser; +import org.broadinstitute.sting.utils.*; import org.broadinstitute.sting.commandline.Argument; import org.broadinstitute.sting.commandline.Output; +import org.broadinstitute.sting.utils.exceptions.UserError; import org.broadinstitute.sting.utils.pileup.ReadBackedPileup; import java.util.Arrays; @@ -61,8 +59,8 @@ public class ValidatingPileupWalker extends LocusWalker argument and the default platform using the --default_platform argument." ); } } @@ -259,7 +260,7 @@ public class RecalDataManager { } readGroup.setPlatform( RAC.DEFAULT_PLATFORM ); } else { - throw new StingException("The input .bam file contains reads with no platform information. First observed at read with name = " + read.getReadName() + + throw new UserError.MalformedBam(read, "The input .bam file contains reads with no platform information. First observed at read with name = " + read.getReadName() + " Users must set the default platform using the --default_platform argument." ); } } @@ -292,14 +293,14 @@ public class RecalDataManager { int iii; byte prevBase = colorSpace[0]; // The sentinel for( iii = 0; iii < readBases.length; iii++ ) { - final byte thisBase = getNextBaseFromColor( prevBase, colorSpace[iii + 1] ); + final byte thisBase = getNextBaseFromColor( read, prevBase, colorSpace[iii + 1] ); inconsistency[iii] = (byte)( thisBase == readBases[iii] ? 0 : 1 ); prevBase = readBases[iii]; } read.setAttribute( RecalDataManager.COLOR_SPACE_INCONSISTENCY_TAG, inconsistency ); } else { - throw new StingException("Unable to find color space information in SOLiD read. First observed at read with name = " + read.getReadName() + + throw new UserError.MalformedBam(read, "Unable to find color space information in SOLiD read. First observed at read with name = " + read.getReadName() + " Unfortunately this .bam file can not be recalibrated without color space information because of potential reference bias."); } } @@ -324,7 +325,7 @@ public class RecalDataManager { if( attr instanceof String ) { colorSpace = ((String)attr).getBytes(); } else { - throw new StingException(String.format("Value encoded by %s in %s isn't a string!", RecalDataManager.COLOR_SPACE_ATTRIBUTE_TAG, read.getReadName())); + throw new GATKException(String.format("Value encoded by %s in %s isn't a string!", RecalDataManager.COLOR_SPACE_ATTRIBUTE_TAG, read.getReadName())); } // Loop over the read and calculate first the inferred bases from the color and then check if it is consistent with the read @@ -338,7 +339,7 @@ public class RecalDataManager { final int[] inconsistency = new int[readBases.length]; byte prevBase = colorSpace[0]; // The sentinel for( int iii = 0; iii < readBases.length; iii++ ) { - final byte thisBase = getNextBaseFromColor( prevBase, colorSpace[iii + 1] ); + final byte thisBase = getNextBaseFromColor( read, prevBase, colorSpace[iii + 1] ); colorImpliedBases[iii] = thisBase; inconsistency[iii] = ( thisBase == readBases[iii] ? 0 : 1 ); prevBase = readBases[iii]; @@ -356,8 +357,8 @@ public class RecalDataManager { } } else { - throw new StingException("Unable to find color space information in SOLiD read. First observed at read with name = " + read.getReadName() + - " Unfortunately this .bam file can not be recalibrated without color space information because of potential reference bias."); + throw new UserError.MalformedBam(read, "Unable to find color space information in SOLiD read. First observed at read with name = " + read.getReadName() + + " Unfortunately this .bam file can not be recalibrated without color space information because of potential reference bias."); } return originalQualScores; @@ -371,7 +372,7 @@ public class RecalDataManager { if( attr instanceof String ) { colorSpace = ((String)attr).substring(1).getBytes(); // trim off the Sentinel } else { - throw new StingException(String.format("Value encoded by %s in %s isn't a string!", RecalDataManager.COLOR_SPACE_ATTRIBUTE_TAG, read.getReadName())); + throw new GATKException(String.format("Value encoded by %s in %s isn't a string!", RecalDataManager.COLOR_SPACE_ATTRIBUTE_TAG, read.getReadName())); } for( byte color : colorSpace ) { @@ -381,7 +382,7 @@ public class RecalDataManager { } } else { - throw new StingException("Unable to find color space information in SOLiD read. First observed at read with name = " + read.getReadName() + + throw new UserError.MalformedBam(read, "Unable to find color space information in SOLiD read. First observed at read with name = " + read.getReadName() + " Unfortunately this .bam file can not be recalibrated without color space information because of potential reference bias."); } } @@ -446,7 +447,7 @@ public class RecalDataManager { colorSpaceQuals = x.getBytes(); SAMUtils.fastqToPhred(colorSpaceQuals); } else { - throw new StingException(String.format("Value encoded by %s in %s isn't a string!", RecalDataManager.COLOR_SPACE_QUAL_ATTRIBUTE_TAG, read.getReadName())); + throw new GATKException(String.format("Value encoded by %s in %s isn't a string!", RecalDataManager.COLOR_SPACE_QUAL_ATTRIBUTE_TAG, read.getReadName())); } for( int iii = 1; iii < inconsistency.length - 1; iii++ ) { @@ -491,7 +492,7 @@ public class RecalDataManager { } read.setReadBases( readBases ); } else { // No color space quality tag in file - throw new StingException("REMOVE_REF_BIAS recal mode requires color space qualities but they can't be found for read: " + read.getReadName()); + throw new UserError.MalformedBam(read, "REMOVE_REF_BIAS recal mode requires color space qualities but they can't be found for read: " + read.getReadName()); } } @@ -501,7 +502,7 @@ public class RecalDataManager { * @param color The color * @return The next base in the sequence */ - private static byte getNextBaseFromColor( final byte prevBase, final byte color ) { + private static byte getNextBaseFromColor( SAMRecord read, final byte prevBase, final byte color ) { switch(color) { case '0': return prevBase; @@ -512,7 +513,7 @@ public class RecalDataManager { case '3': return performColorThree( prevBase ); default: - throw new StingException( "Unrecognized color space in SOLID read, color = " + (char)color + + throw new UserError.MalformedBam(read, "Unrecognized color space in SOLID read, color = " + (char)color + " Unfortunately this bam file can not be recalibrated without full color space information because of potential reference bias."); } } diff --git a/java/src/org/broadinstitute/sting/gatk/walkers/recalibration/TableRecalibrationWalker.java b/java/src/org/broadinstitute/sting/gatk/walkers/recalibration/TableRecalibrationWalker.java index 715a1f177..703ebf650 100644 --- a/java/src/org/broadinstitute/sting/gatk/walkers/recalibration/TableRecalibrationWalker.java +++ b/java/src/org/broadinstitute/sting/gatk/walkers/recalibration/TableRecalibrationWalker.java @@ -47,6 +47,7 @@ import org.broadinstitute.sting.utils.classloader.PackageUtils; import org.broadinstitute.sting.utils.collections.NestedHashMap; import org.broadinstitute.sting.utils.QualityUtils; import org.broadinstitute.sting.utils.StingException; +import org.broadinstitute.sting.utils.exceptions.UserError; import org.broadinstitute.sting.utils.text.TextFormattingUtils; import org.broadinstitute.sting.utils.Utils; import org.broadinstitute.sting.utils.text.XReadLines; @@ -179,7 +180,7 @@ public class TableRecalibrationWalker extends ReadWalker { } ReportFormat.AcceptableOutputType type = (outputLocation == null) ? ReportFormat.AcceptableOutputType.STREAM : ReportFormat.AcceptableOutputType.FILE; if (!VE2ReportFactory.isCompatibleWithOutputType(type,reportType)) - throw new StingException("The report format requested is not compatible with your output location. You specified a " + type + " output type which isn't an option for " + reportType); + throw new UserError.CommandLineError("The report format requested is not compatible with your output location. You specified a " + type + " output type which isn't an option for " + reportType); if ( LIST ) listModulesAndExit(); @@ -375,7 +377,7 @@ public class VariantEvalWalker extends RodWalker { for ( String line : new XReadLines(rsIDFile) ) { String parts[] = line.split(" "); if ( parts.length != 2 ) - throw new StingException("Invalid rsID / build pair at " + n + " line = " + line ); + throw new UserError.MalformedFile(rsIDFile, "Invalid rsID / build pair at " + n + " line = " + line ); //System.out.printf("line %s %s %s%n", line, parts[0], parts[1]); if ( Integer.valueOf(parts[1]) > maxRsIDBuild ) { //System.out.printf("Excluding %s%n", line); @@ -387,7 +389,7 @@ public class VariantEvalWalker extends RodWalker { logger.info(String.format("Read %d rsIDs from rsID -> build file", n)); } } catch (FileNotFoundException e) { - throw new StingException(e.getMessage()); + throw new UserError.CouldNotReadInputFile(rsIDFile, e); } logger.info(String.format("Excluding %d of %d (%.2f%%) rsIDs found from builds > %d", @@ -422,7 +424,7 @@ public class VariantEvalWalker extends RodWalker { // get the specific classes provided for ( String module : modulesToUse ) { if ( !classMap.containsKey(module) ) - throw new StingException("Class " + module + " is not found; please check that you have specified the class name correctly"); + throw new UserError.CommandLineError("Module " + module + " could not be found; please check that you have specified the class name correctly"); evaluationClasses.add(classMap.get(module)); } @@ -675,7 +677,7 @@ public class VariantEvalWalker extends RodWalker { for ( String name : names ) { Collection contexts = tracker.getVariantContexts(ref, name, ALLOW_VARIANT_CONTEXT_TYPES, context.getLocation(), true, true); if ( contexts.size() > 1 ) - throw new StingException("Found multiple variant contexts at " + context.getLocation()); + throw new UserError.CommandLineError("Found multiple variant contexts found in " + name + " at " + context.getLocation() + "; VariantEval assumes one variant per position"); VariantContext vc = contexts.size() == 1 ? contexts.iterator().next() : null; @@ -713,7 +715,7 @@ public class VariantEvalWalker extends RodWalker { for ( EvaluationContext group : contexts ) { String[] parts = group.getDisplayName().split(CONTEXT_SEPARATOR); if ( parts.length != N_CONTEXT_NAME_PARTS ) { - throw new StingException("Unexpected number of eval name parts " + group.getDisplayName() + " length = " + parts.length + ", expected " + N_CONTEXT_NAME_PARTS); + throw new GATKException("Unexpected number of eval name parts " + group.getDisplayName() + " length = " + parts.length + ", expected " + N_CONTEXT_NAME_PARTS); } else { for ( int i = 0; i < parts.length; i++ ) nameSizes[i] = Math.max(nameSizes[i], parts[i].length()); diff --git a/java/src/org/broadinstitute/sting/utils/GATKException.java b/java/src/org/broadinstitute/sting/utils/GATKException.java new file mode 100644 index 000000000..722fcdb64 --- /dev/null +++ b/java/src/org/broadinstitute/sting/utils/GATKException.java @@ -0,0 +1,39 @@ +/* + * 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; + +/** + * Temp class to track split from Sting exception to UserError + */ +public class GATKException extends StingException { + public GATKException(String msg) { + super(msg); + } + + public GATKException(String message, Throwable throwable) { + super(message, throwable); + } +} + diff --git a/java/src/org/broadinstitute/sting/utils/GenomeLoc.java b/java/src/org/broadinstitute/sting/utils/GenomeLoc.java index 3a24da611..dc1988fd1 100644 --- a/java/src/org/broadinstitute/sting/utils/GenomeLoc.java +++ b/java/src/org/broadinstitute/sting/utils/GenomeLoc.java @@ -162,7 +162,7 @@ public class GenomeLoc implements Comparable, Cloneable, Serializable return ! discontinuousP( that ); } - public GenomeLoc merge( GenomeLoc that ) throws StingException { + public GenomeLoc merge( GenomeLoc that ) throws GATKException { if (!(this.contiguousP(that))) { throw new StingException("The two genome loc's need to be contigous"); } @@ -172,7 +172,7 @@ public class GenomeLoc implements Comparable, Cloneable, Serializable Math.max( getStop(), that.getStop()) ); } - public GenomeLoc intersect( GenomeLoc that ) throws StingException { + public GenomeLoc intersect( GenomeLoc that ) throws GATKException { if (!(this.overlapsP(that))) { throw new StingException("GenomeLoc::intersect(): The two genome loc's need to overlap"); } diff --git a/java/src/org/broadinstitute/sting/utils/GenomeLocParser.java b/java/src/org/broadinstitute/sting/utils/GenomeLocParser.java index a947256d6..f23feef96 100644 --- a/java/src/org/broadinstitute/sting/utils/GenomeLocParser.java +++ b/java/src/org/broadinstitute/sting/utils/GenomeLocParser.java @@ -42,6 +42,7 @@ import org.apache.log4j.Logger; import org.broadinstitute.sting.gatk.GenomeAnalysisEngine; import org.broadinstitute.sting.gatk.arguments.ValidationExclusion; import org.broadinstitute.sting.utils.bed.BedParser; +import org.broadinstitute.sting.utils.exceptions.UserError; import org.broadinstitute.sting.utils.interval.IntervalMergingRule; import org.broadinstitute.sting.utils.text.XReadLines; @@ -96,7 +97,7 @@ public class GenomeLocParser { */ public static int getContigIndex(final String contig, boolean exceptionOut) { if (contigInfo.getSequenceIndex(contig) == -1 && exceptionOut) - Utils.scareUser(String.format("Contig %s given as location, but this contig isn't present in the Fasta sequence dictionary", contig)); + throw new UserError.CommandLineError(String.format("Contig %s given as location, but this contig isn't present in the Fasta sequence dictionary", contig)); return contigInfo.getSequenceIndex(contig); } @@ -121,9 +122,8 @@ public class GenomeLocParser { */ public static boolean setupRefContigOrdering(final SAMSequenceDictionary seqDict) { if (seqDict == null) { // we couldn't load the reference dictionary - logger.info("Failed to load reference dictionary, falling back to lexicographic order for contigs"); - Utils.scareUser("Failed to load reference dictionary"); - return false; + //logger.info("Failed to load reference dictionary, falling back to lexicographic order for contigs"); + throw new UserError.CommandLineError("Failed to load reference dictionary"); } else if (contigInfo == null) { contigInfo = seqDict; logger.debug(String.format("Prepared reference sequence contig dictionary")); diff --git a/java/src/org/broadinstitute/sting/utils/Utils.java b/java/src/org/broadinstitute/sting/utils/Utils.java index c6f27c527..f902100ef 100755 --- a/java/src/org/broadinstitute/sting/utils/Utils.java +++ b/java/src/org/broadinstitute/sting/utils/Utils.java @@ -74,23 +74,7 @@ public class Utils { return fullyQualifiedName.substring (0, lastDot); } - public static void warnUser(final String msg) { - logger.warn(String.format("********************************************************************************")); - logger.warn(String.format("* WARNING:")); - logger.warn(String.format("*")); - prettyPrintWarningMessage(msg); - logger.warn(String.format("********************************************************************************")); - } - public static void scareUser(final String msg) { - //System.out.printf("********************************************************************************%n"); - //System.out.printf("* ERROR:%n"); - //System.out.printf("*%n"); - //System.out.printf("* %s%n", msg); - //System.out.printf("********************************************************************************%n"); - logger.fatal(msg); - throw new StingException(msg); - } /** * Compares two objects, either of which might be null. @@ -113,6 +97,15 @@ public class Utils { return l2; } + public static void warnUser(final String msg) { + logger.warn(String.format("********************************************************************************")); + logger.warn(String.format("* WARNING:")); + logger.warn(String.format("*")); + prettyPrintWarningMessage(msg); + logger.warn(String.format("********************************************************************************")); + } + + /** * pretty print the warning message supplied * diff --git a/java/src/org/broadinstitute/sting/utils/exceptions/UserError.java b/java/src/org/broadinstitute/sting/utils/exceptions/UserError.java index 79f42d4ad..5679c9c2b 100644 --- a/java/src/org/broadinstitute/sting/utils/exceptions/UserError.java +++ b/java/src/org/broadinstitute/sting/utils/exceptions/UserError.java @@ -24,7 +24,9 @@ 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.utils.StingException; import java.io.File; @@ -43,14 +45,20 @@ public class UserError extends StingException { public UserError(String msg, Throwable e) { super(msg, e); } private UserError(Throwable e) { super("", e); } // cannot be called, private access + public static class CommandLineError extends UserError { + public CommandLineError(String message) { + super(String.format("Invalid command line: %s", message)); + } + } + // todo -- fix up exception cause passing - public static class MissingArgument extends UserError { + public static class MissingArgument extends CommandLineError { public MissingArgument(String arg, String message) { super(String.format("Argument %s was missing: %s", arg, message)); } } - public static class BadArgumentValue extends UserError { + public static class BadArgumentValue extends CommandLineError { public BadArgumentValue(String arg, String message) { super(String.format("Argument %s has a bad value: %s", arg, message)); } @@ -63,6 +71,10 @@ public class UserError extends StingException { } public static class CouldNotReadInputFile extends UserError { + public CouldNotReadInputFile(String message, Exception e) { + super(String.format("Couldn't read file because %s caused by %s", message, e.getMessage())); + } + public CouldNotReadInputFile(File file, String message) { super(String.format("Couldn't read file %s because %s", file.getAbsolutePath(), message)); } @@ -81,6 +93,14 @@ public class UserError extends StingException { public CouldNotCreateOutputFile(File file, String message, Exception e) { super(String.format("Couldn't write file %s because %s with exception %s", file.getAbsolutePath(), message, e.getMessage())); } + + public CouldNotCreateOutputFile(String filename, String message, Exception e) { + super(String.format("Couldn't write file %s because %s with exception %s", filename, message, e.getMessage())); + } + + public CouldNotCreateOutputFile(File file, Exception e) { + super(String.format("Couldn't write file %s because exception %s", file.getAbsolutePath(), e.getMessage())); + } } public static class MalformedBam extends UserError { @@ -89,6 +109,37 @@ public class UserError extends StingException { } } + public static class ReadMissingReadGroup extends MalformedBam { + public ReadMissingReadGroup(SAMRecord read) { + super(read, String.format("Read %s is missing the read group, which is required by the GATK", read.getReadName())); + } + } + + public static class MissortedBAM extends UserError { + 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(), read.getHeader().getSortOrder(), order, message)); + } + + public MissortedBAM(String message) { + super(String.format("Missorted Input SAM/BAM files: %s", message)); + } + } + + public static class MissortedFile extends UserError { + 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, e.getMessage())); + } + } + public static class MalformedFile extends UserError { public MalformedFile(String message) { super(String.format("Unknown file is malformed: %s", message)); @@ -98,6 +149,10 @@ public class UserError extends StingException { super(String.format("Unknown file is malformed: %s caused by %s", message, e.getMessage())); } + 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, e.getMessage())); } @@ -109,4 +164,24 @@ public class UserError extends StingException { } } + public static class DeprecatedArgument extends CommandLineError { + public DeprecatedArgument(String param, String doc) { + super(String.format("The parameter %s is deprecated. %s",param,doc)); + } + } + + + public static class IncompatibleSequenceDictionaries extends UserError { + public IncompatibleSequenceDictionaries(SAMSequenceDictionary ref, SAMSequenceDictionary alt, String altName) { + // todo -- enumerate all elements in ref and alt + super(String.format("Incompatible input files: no overlap exists between contigs in " + altName + " and the reference.")); + } + } + + public static class MissingWalker extends UserError { + public MissingWalker(String walkerName, String message) { + super(String.format("Walker %s is not available: %s", walkerName, message)); + } + } + }