From 40e61799117e9d5573d916da948b9af70f4cb9d6 Mon Sep 17 00:00:00 2001 From: depristo Date: Sun, 12 Sep 2010 14:02:43 +0000 Subject: [PATCH] Penultimate step in exception system overhaul. UserError is now UserException. This class should be used for all communication with the USER for problems with their inputs. Engine now validates sequence dictionaries for compatibility, detecting not only lack of overlap but now inconsistent headers (b36 ref with v37 BAM, for example) as well as ref / bam order inconsistency. New -U option to allow users to tolerate dangerous seq dict issues. WalkerTest system now supports testing for exceptions (see email and wiki for docs). Tests for vcf and bam vs. ref incompatibility. Waiting on Tribble seq dict improvements to detect b36 VCF with b37 ref (currently cannot tell this is wrong. git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@4258 348d0f76-0448-11de-a6fe-93d51630548a --- .../reference/FastaSequenceIndexBuilder.java | 20 +- .../sting/commandline/ArgumentException.java | 4 +- .../commandline/ArgumentTypeDescriptor.java | 5 +- .../sting/commandline/CommandLineProgram.java | 13 +- .../sting/commandline/ParsingEngine.java | 5 +- .../sting/gatk/CommandLineExecutable.java | 15 +- .../sting/gatk/CommandLineGATK.java | 5 +- .../sting/gatk/DownsamplingMethod.java | 9 +- .../sting/gatk/GenomeAnalysisEngine.java | 77 +---- .../gatk/arguments/ValidationExclusion.java | 1 + .../contexts/StratifiedAlignmentContext.java | 7 +- .../variantcontext/VariantContextUtils.java | 10 +- .../variantcontext/VariantJEXLContext.java | 6 +- .../ReferenceDataSource.java | 5 +- .../ReferenceOrderedDataSource.java | 5 +- .../simpleDataSources/SAMDataSource.java | 5 +- .../sting/gatk/executive/MicroScheduler.java | 10 +- .../gatk/filters/PlatformUnitFilter.java | 5 +- .../filters/PlatformUnitFilterHelper.java | 5 +- .../filters/ReadGroupBlackListFilter.java | 7 +- .../gatk/io/ThreadLocalOutputTracker.java | 5 +- .../gatk/io/storage/OutputStreamStorage.java | 12 +- .../gatk/io/storage/SAMFileWriterStorage.java | 5 +- .../gatk/io/storage/VCFWriterStorage.java | 9 +- .../SAMFileReaderArgumentTypeDescriptor.java | 6 +- .../SAMFileWriterArgumentTypeDescriptor.java | 5 +- .../gatk/io/stubs/SAMFileWriterStub.java | 5 +- .../gatk/iterators/LocusIteratorByState.java | 8 +- .../sting/gatk/refdata/RODRecordIterator.java | 11 +- .../gatk/refdata/RefMetaDataTracker.java | 5 +- .../gatk/refdata/ReferenceOrderedData.java | 7 +- .../gatk/refdata/SeekableRODIterator.java | 7 +- .../refdata/features/refseq/RefSeqCodec.java | 7 +- .../gatk/refdata/tracks/RMDTrackManager.java | 6 +- .../gatk/refdata/tracks/TribbleTrack.java | 5 +- .../builders/TribbleRMDTrackBuilder.java | 14 +- .../AnnotationDataManager.java | 7 +- .../annotator/VariantAnnotatorEngine.java | 7 +- .../genomicannotator/GenomicAnnotation.java | 7 +- .../genomicannotator/GenomicAnnotator.java | 21 +- .../annotator/genomicannotator/JoinTable.java | 7 +- .../genomicannotator/JoinTableParser.java | 5 +- .../TranscriptToGenomicInfo.java | 7 +- .../genomicannotator/TranscriptToInfo.java | 5 +- .../walkers/coverage/CallableLociWalker.java | 8 +- .../coverage/CompareCallableLociWalker.java | 5 +- .../gatk/walkers/coverage/CoverageUtils.java | 5 +- .../coverage/DepthOfCoverageWalker.java | 6 +- .../indels/IndelGenotyperV2Walker.java | 28 +- .../gatk/walkers/indels/IndelRealigner.java | 14 +- .../indels/RealignerTargetCreator.java | 6 +- .../gatk/walkers/qc/CycleQualityWalker.java | 17 +- .../walkers/qc/ReadClippingStatsWalker.java | 5 +- .../walkers/qc/ValidatingPileupWalker.java | 4 +- .../recalibration/CovariateCounterWalker.java | 8 +- .../walkers/recalibration/CycleCovariate.java | 6 +- .../recalibration/RecalDataManager.java | 18 +- .../TableRecalibrationWalker.java | 20 +- .../walkers/recalibration/TileCovariate.java | 5 +- .../varianteval/GenotypeConcordance.java | 5 +- .../varianteval/VariantEvalWalker.java | 14 +- .../ApplyVariantCuts.java | 6 +- .../GenerateVariantClustersWalker.java | 13 +- .../VariantDataManager.java | 9 +- .../VariantGaussianMixtureModel.java | 11 +- .../VariantRecalibrator.java | 12 +- .../walkers/variantutils/CombineVariants.java | 8 +- .../AnnotationByAlleleFrequencyWalker.java | 7 +- ...seTransitionTableCalculatorJavaWalker.java | 8 +- .../oneoffprojects/walkers/DSBWalkerV3.java | 4 +- .../walkers/DbSNPWindowCounter.java | 8 +- .../walkers/IndelAnnotator.java | 5 +- .../walkers/IndelDBRateWalker.java | 5 +- .../walkers/QualityScoreByStrandWalker.java | 5 +- .../walkers/ReadQualityScoreWalker.java | 17 +- .../walkers/TestReadFishingWalker.java | 5 +- .../varianteval/AminoAcidTransition.java | 9 +- .../examples/SampleXmlMarshaller.java | 2 - .../diagnostics/MatePairLibrarySize.java | 5 +- .../HybSelPerformanceWalker.java | 6 +- .../sting/playground/utils/GenomicMap.java | 26 +- .../utils/report/templates/GrepFormat.java | 5 +- .../report/templates/TableBasedFormat.java | 7 +- .../utils/report/templates/TextTable.java | 7 +- .../sting/utils/GATKException.java | 2 +- .../sting/utils/GenomeLocParser.java | 12 +- .../sting/utils/SequenceDictionaryUtils.java | 312 ++++++++++++++++++ .../sting/utils/bed/BedParser.java | 10 +- .../DynamicClassResolutionException.java | 9 +- .../{UserError.java => UserException.java} | 58 ++-- .../sting/utils/fastq/FastqReader.java | 11 +- .../sting/utils/genotype/glf/GLFReader.java | 9 +- .../interval/IntervalFileMergingIterator.java | 7 +- .../sting/utils/interval/IntervalUtils.java | 11 +- .../sting/utils/sam/GATKSAMRecord.java | 5 +- .../sting/utils/wiggle/WiggleWriter.java | 7 +- .../org/broadinstitute/sting/BaseTest.java | 10 +- .../org/broadinstitute/sting/WalkerTest.java | 87 +++-- .../commandline/ParsingEngineUnitTest.java | 7 +- .../providers/ShardDataProviderUnitTest.java | 5 +- .../ReadGroupBlackListFilterUnitTest.java | 7 +- .../tracks/RMDTrackManagerUnitTest.java | 5 +- .../DictionaryConsistencyIntegrationTest.java | 79 +++++ .../qc/ValidatingPileupIntegrationTest.java | 2 +- .../ValidateRODForReadsIntegrationTest.java | 2 +- .../sting/utils/GenomeLocParserUnitTest.java | 12 +- .../utils/GenomeLocSortedSetUnitTest.java | 2 +- .../sting/utils/PathUtilsUnitTest.java | 2 +- .../utils/genotype/vcf/VCFWriterUnitTest.java | 5 +- .../IntervalFileMergingIteratorUnitTest.java | 3 +- 110 files changed, 865 insertions(+), 582 deletions(-) create mode 100755 java/src/org/broadinstitute/sting/utils/SequenceDictionaryUtils.java rename java/src/org/broadinstitute/sting/utils/exceptions/{UserError.java => UserException.java} (75%) mode change 100644 => 100755 create mode 100755 java/test/org/broadinstitute/sting/gatk/walkers/qc/DictionaryConsistencyIntegrationTest.java diff --git a/java/src/net/sf/picard/reference/FastaSequenceIndexBuilder.java b/java/src/net/sf/picard/reference/FastaSequenceIndexBuilder.java index 628501603..2bfea3c23 100644 --- a/java/src/net/sf/picard/reference/FastaSequenceIndexBuilder.java +++ b/java/src/net/sf/picard/reference/FastaSequenceIndexBuilder.java @@ -27,14 +27,12 @@ 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.*; import java.io.*; -import java.util.Iterator; -import net.sf.picard.reference.FastaSequenceIndex; -import org.broadinstitute.sting.utils.exceptions.UserError; +import org.broadinstitute.sting.utils.exceptions.UserException; /** * Builds FastaSequenceIndex from fasta file. @@ -85,7 +83,7 @@ public class FastaSequenceIndexBuilder { in = new DataInputStream(new BufferedInputStream(new FileInputStream(fastaFile))); } catch (Exception e) { - throw new UserError.CouldNotReadInputFile(fastaFile, "Could not read fasta file", e); + throw new UserException.CouldNotReadInputFile(fastaFile, "Could not read fasta file", e); } /* @@ -168,7 +166,7 @@ public class FastaSequenceIndexBuilder { // validate base character else { if (!isValidBase(currentByte)) - throw new UserError.MalformedFile(fastaFile, String.format("An invalid base was found in the contig: %s", contig)); + throw new UserException.MalformedFile(fastaFile, String.format("An invalid base was found in the contig: %s", contig)); } break; @@ -194,7 +192,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 UserError.MalformedFile(fastaFile, String.format("An invalid line was found in the contig: %s", contig)); + throw new UserException.MalformedFile(fastaFile, String.format("An invalid line was found in the contig: %s", contig)); } else finishReadingContig(sequenceIndex); @@ -206,7 +204,7 @@ public class FastaSequenceIndexBuilder { // validate base character else { if (!isValidBase(currentByte)) - throw new UserError.MalformedFile(fastaFile, String.format("An invalid base was found in the contig: %s", contig)); + throw new UserException.MalformedFile(fastaFile, String.format("An invalid base was found in the contig: %s", contig)); } break; } @@ -214,7 +212,7 @@ public class FastaSequenceIndexBuilder { return sequenceIndex; } catch (IOException e) { - throw new UserError.CouldNotReadInputFile(fastaFile, String.format("Could not read fasta file"), e); + throw new UserException.CouldNotReadInputFile(fastaFile, String.format("Could not read fasta file"), e); } catch (Exception e) { throw new GATKException(e.getMessage(), e); @@ -273,7 +271,7 @@ public class FastaSequenceIndexBuilder { out = new BufferedWriter(new FileWriter(faiFile)); } catch (Exception e) { - throw new UserError.CouldNotCreateOutputFile(faiFile, e); + throw new UserException.CouldNotCreateOutputFile(faiFile, e); } try { @@ -284,7 +282,7 @@ public class FastaSequenceIndexBuilder { out.close(); } catch (Exception e) { - throw new UserError.CouldNotCreateOutputFile(faiFile, e); + throw new UserException.CouldNotCreateOutputFile(faiFile, e); } } diff --git a/java/src/org/broadinstitute/sting/commandline/ArgumentException.java b/java/src/org/broadinstitute/sting/commandline/ArgumentException.java index ae9d34a87..bf85b0603 100755 --- a/java/src/org/broadinstitute/sting/commandline/ArgumentException.java +++ b/java/src/org/broadinstitute/sting/commandline/ArgumentException.java @@ -25,12 +25,12 @@ package org.broadinstitute.sting.commandline; -import org.broadinstitute.sting.utils.exceptions.UserError; +import org.broadinstitute.sting.utils.exceptions.UserException; /** * Generic class for handling misc parsing exceptions. */ -public class ArgumentException extends UserError { +public class ArgumentException extends UserException { public ArgumentException( String message ) { super( message ); } diff --git a/java/src/org/broadinstitute/sting/commandline/ArgumentTypeDescriptor.java b/java/src/org/broadinstitute/sting/commandline/ArgumentTypeDescriptor.java index 4323190d4..4c76e7958 100644 --- a/java/src/org/broadinstitute/sting/commandline/ArgumentTypeDescriptor.java +++ b/java/src/org/broadinstitute/sting/commandline/ArgumentTypeDescriptor.java @@ -26,13 +26,12 @@ 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.DynamicClassResolutionException; -import org.broadinstitute.sting.utils.exceptions.UserError; +import org.broadinstitute.sting.utils.exceptions.UserException; import java.lang.annotation.Annotation; import java.lang.reflect.*; @@ -222,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 UserError.CommandLineError("Multiple values associated with given definition, but this argument expects only one: " + definition.fullName); + throw new UserException.CommandLineException("Multiple values associated with given definition, but this argument expects only one: " + definition.fullName); return argumentValues.size() > 0 ? argumentValues.iterator().next() : null; } diff --git a/java/src/org/broadinstitute/sting/commandline/CommandLineProgram.java b/java/src/org/broadinstitute/sting/commandline/CommandLineProgram.java index 24d88a791..4c320582a 100644 --- a/java/src/org/broadinstitute/sting/commandline/CommandLineProgram.java +++ b/java/src/org/broadinstitute/sting/commandline/CommandLineProgram.java @@ -26,14 +26,11 @@ package org.broadinstitute.sting.commandline; import org.apache.log4j.*; -import org.broadinstitute.sting.gatk.phonehome.GATKRunReport; -import org.broadinstitute.sting.utils.exceptions.UserError; +import org.broadinstitute.sting.utils.exceptions.UserException; import org.broadinstitute.sting.utils.help.ApplicationDetails; import org.broadinstitute.sting.utils.help.HelpFormatter; -import java.io.File; import java.io.IOException; -import java.io.PrintStream; import java.util.*; public abstract class CommandLineProgram { @@ -253,12 +250,6 @@ public abstract class CommandLineProgram { // Rethrow the exception to exit with an error. throw e; } - catch (Exception e) { - // we catch all exceptions here. if it makes it to this level, we're in trouble. Let's bail! - // TODO: what if the logger is the exception? hmm... - logger.fatal("\n"); - throw e; - } } /** @@ -376,7 +367,7 @@ public abstract class CommandLineProgram { System.exit(1); } - public static void exitSystemWithUserError(UserError e) { + public static void exitSystemWithUserError(UserException e) { errorPrintf("------------------------------------------------------------------------------------------%n"); errorPrintf("A USER ERROR has occurred. The invalid arguments or inputs must be corrected before the GATK can proceed%n"); errorPrintf("%n"); diff --git a/java/src/org/broadinstitute/sting/commandline/ParsingEngine.java b/java/src/org/broadinstitute/sting/commandline/ParsingEngine.java index 7f5fe35cd..c112db695 100755 --- a/java/src/org/broadinstitute/sting/commandline/ParsingEngine.java +++ b/java/src/org/broadinstitute/sting/commandline/ParsingEngine.java @@ -26,11 +26,10 @@ 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.exceptions.UserException; import org.broadinstitute.sting.utils.help.ApplicationDetails; import org.broadinstitute.sting.utils.help.HelpFormatter; import org.apache.log4j.Logger; @@ -297,7 +296,7 @@ public class ParsingEngine { if(definitions.size() < 1) throw new GATKException("Internal error. Argument source creates no definitions."); ArgumentDefinition definition = definitions.get(0); - throw new UserError.DeprecatedArgument(definition.fullName,definition.doc); + throw new UserException.DeprecatedArgument(definition.fullName,definition.doc); } /** diff --git a/java/src/org/broadinstitute/sting/gatk/CommandLineExecutable.java b/java/src/org/broadinstitute/sting/gatk/CommandLineExecutable.java index 672a1ca1a..766b769b2 100644 --- a/java/src/org/broadinstitute/sting/gatk/CommandLineExecutable.java +++ b/java/src/org/broadinstitute/sting/gatk/CommandLineExecutable.java @@ -72,15 +72,16 @@ public abstract class CommandLineExecutable extends CommandLineProgram { */ protected int execute() throws Exception { Walker mWalker = GATKEngine.getWalkerByName(getAnalysisName()); - Collection filters = GATKEngine.createFiltersForWalker(getArgumentCollection(),mWalker); - // load the arguments into the walker / filters. - loadArgumentsIntoObject(mWalker); - for (SamRecordFilter filter: filters) - loadArgumentsIntoObject(filter); - - // set the analysis name in the argument collection try { + Collection filters = GATKEngine.createFiltersForWalker(getArgumentCollection(),mWalker); + + // load the arguments into the walker / filters. + loadArgumentsIntoObject(mWalker); + for (SamRecordFilter filter: filters) + loadArgumentsIntoObject(filter); + + // set the analysis name in the argument collection GATKResult = GATKEngine.execute(getArgumentCollection(), mWalker, filters); generateGATKRunReport(mWalker); } catch ( Exception e ) { diff --git a/java/src/org/broadinstitute/sting/gatk/CommandLineGATK.java b/java/src/org/broadinstitute/sting/gatk/CommandLineGATK.java index 3da263afb..f3973d236 100755 --- a/java/src/org/broadinstitute/sting/gatk/CommandLineGATK.java +++ b/java/src/org/broadinstitute/sting/gatk/CommandLineGATK.java @@ -26,13 +26,12 @@ package org.broadinstitute.sting.gatk; import org.broadinstitute.sting.gatk.arguments.GATKArgumentCollection; -import org.broadinstitute.sting.utils.exceptions.UserError; +import org.broadinstitute.sting.utils.exceptions.UserException; import org.broadinstitute.sting.utils.text.TextFormattingUtils; import org.broadinstitute.sting.utils.help.ApplicationDetails; import org.broadinstitute.sting.commandline.*; import org.broadinstitute.sting.gatk.walkers.Walker; -import java.io.PrintStream; import java.util.*; /** @@ -92,7 +91,7 @@ public class CommandLineGATK extends CommandLineExecutable { CommandLineGATK instance = new CommandLineGATK(); start(instance, argv); System.exit(CommandLineProgram.result); // todo -- this is a painful hack - } catch (UserError e) { + } catch (UserException e) { exitSystemWithUserError(e); } catch (Exception e) { exitSystemWithError(e); diff --git a/java/src/org/broadinstitute/sting/gatk/DownsamplingMethod.java b/java/src/org/broadinstitute/sting/gatk/DownsamplingMethod.java index 4985fa08d..6d9e79156 100644 --- a/java/src/org/broadinstitute/sting/gatk/DownsamplingMethod.java +++ b/java/src/org/broadinstitute/sting/gatk/DownsamplingMethod.java @@ -1,7 +1,6 @@ package org.broadinstitute.sting.gatk; -import org.broadinstitute.sting.utils.StingException; -import org.broadinstitute.sting.utils.exceptions.UserError; +import org.broadinstitute.sting.utils.exceptions.UserException; /** * Describes the method for downsampling reads at a given locus. @@ -36,15 +35,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 UserError.CommandLineError("Must specify either toFraction or toCoverage when downsampling."); + throw new UserException.CommandLineException("Must specify either toFraction or toCoverage when downsampling."); // Fraction and coverage cannot both be specified. if(toFraction != null && toCoverage != null) - throw new UserError.CommandLineError("Downsampling coverage and fraction are both specified. Please choose only one."); + throw new UserException.CommandLineException("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 UserError.CommandLineError("Cannot downsample to fraction with new EXPERIMENTAL_BY_SAMPLE method"); + throw new UserException.CommandLineException("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 3c763724b..b1cda6547 100755 --- a/java/src/org/broadinstitute/sting/gatk/GenomeAnalysisEngine.java +++ b/java/src/org/broadinstitute/sting/gatk/GenomeAnalysisEngine.java @@ -31,7 +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.exceptions.UserException; import org.broadinstitute.sting.utils.interval.IntervalMergingRule; import org.broadinstitute.sting.utils.interval.IntervalUtils; import org.broadinstitute.sting.gatk.arguments.ValidationExclusion; @@ -267,7 +267,7 @@ public class GenomeAnalysisEngine { // check to make sure we have a rod of that name if (!rodNames.containsKey(rodName)) - throw new UserError.CommandLineError("--rodToIntervalTrackName (-BTI) was passed the name '"+rodName+"', which wasn't given as a ROD name in the -B option"); + throw new UserException.CommandLineException("--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) { - throw new UserError.CommandLineError("Read-based traversals require a reference file but none was given"); + throw new UserException.CommandLineException("Read-based traversals require a reference file but none was given"); } return MicroScheduler.create(this,my_walker,readsDataSource,referenceDataSource.getReference(),rodDataSources,argCollection.numberOfThreads); @@ -661,11 +661,6 @@ public class GenomeAnalysisEngine { // Compile a set of sequence names that exist in the reference file. SAMSequenceDictionary referenceDictionary = reference.getSequenceDictionary(); - Set referenceSequenceNames = new TreeSet(); - for (SAMSequenceRecord dictionaryEntry : referenceDictionary.getSequences()) - referenceSequenceNames.add(dictionaryEntry.getSequenceName()); - - if (!reads.isEmpty()) { // Compile a set of sequence names that exist in the BAM files. SAMSequenceDictionary readsDictionary = reads.getHeader().getSequenceDictionary(); @@ -681,7 +676,7 @@ public class GenomeAnalysisEngine { } // compare the reads to the reference - compareTwoDictionaries("reads", readsDictionary, readsSequenceNames, referenceDictionary, referenceSequenceNames); + SequenceDictionaryUtils.validateDictionaries(logger, "reads", readsDictionary, "reference", referenceDictionary); } // compare the tracks to the reference, if they have a sequence dictionary @@ -693,57 +688,15 @@ public class GenomeAnalysisEngine { logger.info("Track " + track.getName() + " doesn't have a sequence dictionary built in, skipping dictionary validation"); continue; } + Set trackSequences = new TreeSet(); for (SAMSequenceRecord dictionaryEntry : trackDict.getSequences()) trackSequences.add(dictionaryEntry.getSequenceName()); - compareTwoDictionaries(track.getName(), trackDict, trackSequences, referenceDictionary, referenceSequenceNames); + SequenceDictionaryUtils.validateDictionaries(logger, track.getName(), trackDict, "reference", referenceDictionary); } } - /** - * compare two dictionaries, warning if one isn't a subset of the other, or erroring out if they have no overlap - * @param compareToName the name of the track or bam (used in the output to the user) - * @param comparedToDictionary the dictionary to compare to - * @param compareToSequenceNames the unique sequence names in the compared to dictionary - * @param referenceDictionary the reference dictionary - * @param referenceSequenceNames the reference unique sequence names - */ - private void compareTwoDictionaries(String compareToName, SAMSequenceDictionary comparedToDictionary, Set compareToSequenceNames, SAMSequenceDictionary referenceDictionary, Set referenceSequenceNames) { - // If there's no overlap between reads and reference, data will be bogus. Throw an exception. - Set intersectingSequenceNames = new HashSet(compareToSequenceNames); - intersectingSequenceNames.retainAll(referenceSequenceNames); - if (intersectingSequenceNames.size() == 0) { - StringBuilder error = new StringBuilder(); - error.append("No overlap exists between sequence dictionary of the " + compareToName + " and the sequence dictionary of the reference. Perhaps you're using the wrong reference?\n"); - error.append(System.getProperty("line.separator")); - error.append(String.format(compareToName + " contigs: %s%n", prettyPrintSequenceRecords(comparedToDictionary))); - error.append(String.format("Reference contigs: %s%n", prettyPrintSequenceRecords(referenceDictionary))); - logger.error(error.toString()); - 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. - if (!compareToSequenceNames.equals(referenceSequenceNames) && - !compareToSequenceNames.containsAll(referenceSequenceNames) && - !referenceSequenceNames.containsAll(compareToSequenceNames)) { - StringBuilder warning = new StringBuilder(); - warning.append("Limited overlap exists between sequence dictionary of the " + compareToName + " and the sequence dictionary of the reference. Perhaps you're using the wrong reference?\n"); - warning.append(System.getProperty("line.separator")); - warning.append(String.format(compareToName + " contigs: %s%n", prettyPrintSequenceRecords(comparedToDictionary))); - warning.append(String.format("Reference contigs: %s%n", prettyPrintSequenceRecords(referenceDictionary))); - logger.warn(warning.toString()); - } - } - - private String prettyPrintSequenceRecords(SAMSequenceDictionary sequenceDictionary) { - String[] sequenceRecordNames = new String[sequenceDictionary.size()]; - int sequenceRecordIndex = 0; - for (SAMSequenceRecord sequenceRecord : sequenceDictionary.getSequences()) - sequenceRecordNames[sequenceRecordIndex++] = sequenceRecord.getSequenceName(); - return Arrays.deepToString(sequenceRecordNames); - } - /** * Convenience function that binds RODs using the old-style command line parser to the new style list for @@ -773,20 +726,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 UserError.CommandLineError("The GATK cannot currently process unindexed BAM files without the -U ALLOW_UNINDEXED_BAM"); + throw new UserException.CommandLineException("The GATK cannot currently process unindexed BAM files without the -U ALLOW_UNINDEXED_BAM"); if(intervals != null && WalkerManager.getWalkerDataSource(walker) != DataSource.REFERENCE) - throw new UserError.CommandLineError("Cannot perform interval processing when walker is not driven by reference and no index is available."); + throw new UserException.CommandLineException("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) - throw new UserError.MissortedBAM(SAMFileHeader.SortOrder.coordinate, "Locus walkers can only walk over coordinate-sorted data. Please resort your input BAM file(s)."); + throw new UserException.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 UserError.CommandLineError("The GATK cannot currently process unindexed BAM files"); + throw new UserException.CommandLineException("The GATK cannot currently process unindexed BAM files"); List region; if(intervals != null) @@ -810,7 +763,7 @@ public class GenomeAnalysisEngine { if (intervals != null && !intervals.isEmpty()) { if(!readsDataSource.isEmpty() && readsDataSource.getSortOrder() != SAMFileHeader.SortOrder.coordinate) - throw new UserError.MissortedBAM(SAMFileHeader.SortOrder.coordinate, "Locus walkers can only walk over coordinate-sorted data. Please resort your input BAM file(s)."); + throw new UserException.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 +797,9 @@ public class GenomeAnalysisEngine { } } else if (walker instanceof ReadPairWalker) { if(readsDataSource != null && readsDataSource.getSortOrder() != SAMFileHeader.SortOrder.queryname) - throw new UserError.MissortedBAM(SAMFileHeader.SortOrder.queryname, "Read pair walkers can only walk over query name-sorted data. Please resort your input BAM file."); + throw new UserException.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()) - throw new UserError.CommandLineError("Pairs traversal cannot be used in conjunction with intervals."); + throw new UserException.CommandLineException("Pairs traversal cannot be used in conjunction with intervals."); shardStrategy = ShardStrategyFactory.shatter(readsDataSource, referenceDataSource.getReference(), @@ -996,7 +949,7 @@ public class GenomeAnalysisEngine { unpackedReads.add(new SAMReaderID(new File(fileName),getTags(inputFile))); } catch( FileNotFoundException ex ) { - throw new UserError.CouldNotReadInputFile(inputFile, "Unable to find file while unpacking reads", ex); + throw new UserException.CouldNotReadInputFile(inputFile, "Unable to find file while unpacking reads", ex); } } else if(inputFile.getName().toLowerCase().endsWith(".bam")) { @@ -1006,7 +959,7 @@ public class GenomeAnalysisEngine { unpackedReads.add(new SAMReaderID(new File("/dev/stdin"),Collections.emptyList())); } else { - throw new UserError.CommandLineError(String.format("The GATK reads argument (-I) supports only BAM files with the .bam extension and lists of BAM files " + + throw new UserException.CommandLineException(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())); } diff --git a/java/src/org/broadinstitute/sting/gatk/arguments/ValidationExclusion.java b/java/src/org/broadinstitute/sting/gatk/arguments/ValidationExclusion.java index 9c4387e58..0d5a23f1d 100644 --- a/java/src/org/broadinstitute/sting/gatk/arguments/ValidationExclusion.java +++ b/java/src/org/broadinstitute/sting/gatk/arguments/ValidationExclusion.java @@ -40,6 +40,7 @@ public class ValidationExclusion { ALLOW_EMPTY_INTERVAL_LIST, // allow the user to pass in an empty interval list ALLOW_UNSET_BAM_SORT_ORDER, // assume that the bam is sorted, even if the SO (sort-order) flag is not set NO_READ_ORDER_VERIFICATION, // do not validate that the reads are in order as we take them from the bam file + ALLOW_SEQ_DICT_INCOMPATIBILITY, // allow dangerous, but not fatal, sequence dictionary incompabilities @EnumerationArgumentDefault // set the ALL value to the default value, so if they specify just -U, we get the ALL ALL // do not check for all of the above conditions, DEFAULT } diff --git a/java/src/org/broadinstitute/sting/gatk/contexts/StratifiedAlignmentContext.java b/java/src/org/broadinstitute/sting/gatk/contexts/StratifiedAlignmentContext.java index 26ca3d7a0..5893238bc 100755 --- a/java/src/org/broadinstitute/sting/gatk/contexts/StratifiedAlignmentContext.java +++ b/java/src/org/broadinstitute/sting/gatk/contexts/StratifiedAlignmentContext.java @@ -25,12 +25,9 @@ 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.exceptions.UserException; import org.broadinstitute.sting.utils.pileup.*; import java.util.*; @@ -116,7 +113,7 @@ public class StratifiedAlignmentContext { contexts.put(sampleName,new StratifiedAlignmentContext(loc,pileupBySample)); else { if(assumedSingleSample == null) { - throw new UserError.MalformedBam(pileupBySample.iterator().next().getRead(), "Missing read group for read"); + throw new UserException.MalformedBam(pileupBySample.iterator().next().getRead(), "Missing read group for read"); } contexts.put(assumedSingleSample,new StratifiedAlignmentContext(loc,pileupBySample)); } 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 30c8ee6ab..21231ed93 100755 --- a/java/src/org/broadinstitute/sting/gatk/contexts/variantcontext/VariantContextUtils.java +++ b/java/src/org/broadinstitute/sting/gatk/contexts/variantcontext/VariantContextUtils.java @@ -30,7 +30,7 @@ import org.broad.tribble.util.popgen.HardyWeinbergCalculation; import org.broad.tribble.util.variantcontext.*; import org.broadinstitute.sting.utils.*; import org.broad.tribble.vcf.VCFConstants; -import org.broadinstitute.sting.utils.exceptions.UserError; +import org.broadinstitute.sting.utils.exceptions.UserException; public class VariantContextUtils { final public static JexlEngine engine = new JexlEngine(); @@ -113,7 +113,7 @@ public class VariantContextUtils { 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)); + throw new UserException("Inconsistent number of provided filter names and expressions: names=" + Arrays.toString(names) + " exps=" + Arrays.toString(exps)); Map map = new HashMap(); for ( int i = 0; i < names.length; i++ ) { map.put(names[i], exps[i]); } @@ -149,7 +149,7 @@ public class VariantContextUtils { Expression exp = engine.createExpression(expStr); exps.add(new JexlVCMatchExp(name, exp)); } catch (Exception e) { - throw new UserError.BadArgumentValue(name, "Invalid expression used (" + expStr + "). Please see the JEXL docs for correct syntax.") ; + throw new UserException.BadArgumentValue(name, "Invalid expression used (" + expStr + "). Please see the JEXL docs for correct syntax.") ; } } @@ -433,7 +433,7 @@ public class VariantContextUtils { for ( String name : vc.getSampleNames() ) { //System.out.printf("Checking %s %b%n", name, names.contains(name)); if ( names.contains(name) ) - throw new UserError("REQUIRE_UNIQUE sample names is true but duplicate names were discovered " + name); + throw new UserException("REQUIRE_UNIQUE sample names is true but duplicate names were discovered " + name); } names.addAll(vc.getSampleNames()); @@ -642,7 +642,7 @@ public class VariantContextUtils { private int getIndex(VariantContext vc) { int i = priorityListOfVCs.indexOf(vc.getName()); - if ( i == -1 ) throw new UserError.BadArgumentValue(Utils.join(",", priorityListOfVCs), "Priority list " + priorityListOfVCs + " doesn't contain variant context " + vc.getName()); + if ( i == -1 ) throw new UserException.BadArgumentValue(Utils.join(",", priorityListOfVCs), "Priority list " + priorityListOfVCs + " doesn't contain variant context " + vc.getName()); return i; } 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 c1c8cd0fe..ee9ec24ec 100644 --- a/java/src/org/broadinstitute/sting/gatk/contexts/variantcontext/VariantJEXLContext.java +++ b/java/src/org/broadinstitute/sting/gatk/contexts/variantcontext/VariantJEXLContext.java @@ -27,11 +27,9 @@ 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 org.broadinstitute.sting.utils.exceptions.UserException; import java.util.*; @@ -274,7 +272,7 @@ class JEXLMap implements Map { try { jexl.put (exp, (Boolean) exp.exp.evaluate(jContext)); } catch (Exception e) { - throw new UserError.CommandLineError(String.format("Invalid JEXL expression detected for %s with message %s", exp.name, e.getMessage())); + throw new UserException.CommandLineException(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/simpleDataSources/ReferenceDataSource.java b/java/src/org/broadinstitute/sting/gatk/datasources/simpleDataSources/ReferenceDataSource.java index 03d8f496d..a70123371 100644 --- a/java/src/org/broadinstitute/sting/gatk/datasources/simpleDataSources/ReferenceDataSource.java +++ b/java/src/org/broadinstitute/sting/gatk/datasources/simpleDataSources/ReferenceDataSource.java @@ -26,12 +26,11 @@ 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; import net.sf.picard.reference.IndexedFastaSequenceFile; import net.sf.picard.reference.FastaSequenceIndex; -import org.broadinstitute.sting.utils.exceptions.UserError; +import org.broadinstitute.sting.utils.exceptions.UserException; import org.broadinstitute.sting.utils.file.FSLockWithShared; import org.broadinstitute.sting.utils.file.FileSystemInabilityToLockException; @@ -172,7 +171,7 @@ public class ReferenceDataSource implements ReferenceDataSourceProgressListener } catch (Exception e) { - throw new UserError.CouldNotReadInputFile(fastaFile, e); + throw new UserException.CouldNotReadInputFile(fastaFile, e); } finally { dictLock.unlock(); 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 c57cb670a..70fce919d 100755 --- a/java/src/org/broadinstitute/sting/gatk/datasources/simpleDataSources/ReferenceOrderedDataSource.java +++ b/java/src/org/broadinstitute/sting/gatk/datasources/simpleDataSources/ReferenceOrderedDataSource.java @@ -13,8 +13,7 @@ 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 org.broadinstitute.sting.utils.exceptions.UserException; import java.io.IOException; import java.util.List; @@ -225,7 +224,7 @@ class ReferenceOrderedQueryDataPool extends ResourcePool rods, int nThreadsToUse) { if (walker instanceof TreeReducible && nThreadsToUse > 1) { if(walker.isReduceByInterval()) - throw new UserError.BadArgumentValue("nt", String.format("The analysis %s aggregates results by interval. Due to a current limitation of the GATK, analyses of this type do not currently support parallel execution. Please run your analysis without the -nt option.", engine.getWalkerName(walker.getClass()))); + throw new UserException.BadArgumentValue("nt", String.format("The analysis %s aggregates results by interval. Due to a current limitation of the GATK, analyses of this type do not currently support parallel execution. Please run your analysis without the -nt option.", engine.getWalkerName(walker.getClass()))); if(walker instanceof ReadWalker) - throw new UserError.BadArgumentValue("nt", String.format("The analysis %s is a read walker. Due to a current limitation of the GATK, analyses of this type do not currently support parallel execution. Please run your analysis without the -nt option.", engine.getWalkerName(walker.getClass()))); + throw new UserException.BadArgumentValue("nt", String.format("The analysis %s is a read walker. Due to a current limitation of the GATK, analyses of this type do not currently support parallel execution. Please run your analysis without the -nt option.", engine.getWalkerName(walker.getClass()))); logger.info(String.format("Running the GATK in parallel mode with %d concurrent threads",nThreadsToUse)); return new HierarchicalMicroScheduler(engine, walker, reads, reference, rods, nThreadsToUse); } else { if(nThreadsToUse > 1) - throw new UserError.BadArgumentValue("nt", String.format("The analysis %s currently does not support parallel execution. Please run your analysis without the -nt option.", engine.getWalkerName(walker.getClass()))); + throw new UserException.BadArgumentValue("nt", String.format("The analysis %s currently does not support parallel execution. Please run your analysis without the -nt option.", engine.getWalkerName(walker.getClass()))); return new LinearMicroScheduler(engine, walker, reads, reference, rods); } } diff --git a/java/src/org/broadinstitute/sting/gatk/filters/PlatformUnitFilter.java b/java/src/org/broadinstitute/sting/gatk/filters/PlatformUnitFilter.java index e15333f7a..2a4c49c04 100644 --- a/java/src/org/broadinstitute/sting/gatk/filters/PlatformUnitFilter.java +++ b/java/src/org/broadinstitute/sting/gatk/filters/PlatformUnitFilter.java @@ -7,8 +7,7 @@ import net.sf.samtools.SAMReadGroupRecord; import java.util.Set; import java.util.HashSet; -import org.broadinstitute.sting.utils.StingException; -import org.broadinstitute.sting.utils.exceptions.UserError; +import org.broadinstitute.sting.utils.exceptions.UserException; /** * Created by IntelliJ IDEA. @@ -30,7 +29,7 @@ public class PlatformUnitFilter implements SamRecordFilter { if ( pu_attr == null ) { // no platform unit in the record, go get from read group SAMReadGroupRecord rgr = samRecord.getReadGroup(); - if ( rgr == null ) throw new UserError.MalformedBam(samRecord, "Read " + samRecord.getReadName() +" has NO associated read group record"); + if ( rgr == null ) throw new UserException.MalformedBam(samRecord, "Read " + samRecord.getReadName() +" has NO associated read group record"); pu_attr = rgr.getAttribute("PU") ; } if ( pu_attr == null ) return false; // could not get PU, forget about the filtering... diff --git a/java/src/org/broadinstitute/sting/gatk/filters/PlatformUnitFilterHelper.java b/java/src/org/broadinstitute/sting/gatk/filters/PlatformUnitFilterHelper.java index f0d37e8c4..f4a8756e0 100644 --- a/java/src/org/broadinstitute/sting/gatk/filters/PlatformUnitFilterHelper.java +++ b/java/src/org/broadinstitute/sting/gatk/filters/PlatformUnitFilterHelper.java @@ -25,9 +25,8 @@ package org.broadinstitute.sting.gatk.filters; -import org.broadinstitute.sting.utils.exceptions.UserError; +import org.broadinstitute.sting.utils.exceptions.UserException; import org.broadinstitute.sting.utils.text.XReadLines; -import org.broadinstitute.sting.utils.StingException; import java.io.File; import java.io.FileNotFoundException; @@ -76,7 +75,7 @@ public class PlatformUnitFilterHelper { if ( EMPTYLINE_PATTERN.matcher(line).matches() ) continue; // skip empty lines PlatformUnitFilter.addBlackListedLane(line); // PlatformUnitFilter will trim the line as needed } - } catch ( FileNotFoundException e) { throw new UserError.CouldNotReadInputFile(f, e); } // this should NEVER happen + } catch ( FileNotFoundException e) { throw new UserException.CouldNotReadInputFile(f, e); } // this should NEVER happen return; } diff --git a/java/src/org/broadinstitute/sting/gatk/filters/ReadGroupBlackListFilter.java b/java/src/org/broadinstitute/sting/gatk/filters/ReadGroupBlackListFilter.java index 009546c38..965fca0dd 100644 --- a/java/src/org/broadinstitute/sting/gatk/filters/ReadGroupBlackListFilter.java +++ b/java/src/org/broadinstitute/sting/gatk/filters/ReadGroupBlackListFilter.java @@ -33,8 +33,7 @@ import java.io.FileNotFoundException; import net.sf.picard.filter.SamRecordFilter; import net.sf.samtools.SAMRecord; import net.sf.samtools.SAMReadGroupRecord; -import org.broadinstitute.sting.utils.StingException; -import org.broadinstitute.sting.utils.exceptions.UserError; +import org.broadinstitute.sting.utils.exceptions.UserException; import org.broadinstitute.sting.utils.text.XReadLines; /** @@ -94,7 +93,7 @@ public class ReadGroupBlackListFilter implements SamRecordFilter { if (parentFile != null) { message += ", " + parentFile.getAbsolutePath() + ":" + parentLineNum; } - throw new UserError(message); + throw new UserException(message); } } else { String[] filterEntry = filter.split(":", 2); @@ -111,7 +110,7 @@ public class ReadGroupBlackListFilter implements SamRecordFilter { message += ", " + parentFile.getAbsolutePath() + ":" + parentLineNum; } message += ", format is :"; - throw new UserError(message); + throw new UserException(message); } if (!filters.containsKey(filterEntry[0])) diff --git a/java/src/org/broadinstitute/sting/gatk/io/ThreadLocalOutputTracker.java b/java/src/org/broadinstitute/sting/gatk/io/ThreadLocalOutputTracker.java index cc162424b..36960246a 100644 --- a/java/src/org/broadinstitute/sting/gatk/io/ThreadLocalOutputTracker.java +++ b/java/src/org/broadinstitute/sting/gatk/io/ThreadLocalOutputTracker.java @@ -29,8 +29,7 @@ import org.broadinstitute.sting.gatk.io.stubs.Stub; import org.broadinstitute.sting.gatk.io.storage.StorageFactory; import org.broadinstitute.sting.gatk.io.storage.Storage; import org.broadinstitute.sting.gatk.executive.OutputMergeTask; -import org.broadinstitute.sting.utils.StingException; -import org.broadinstitute.sting.utils.exceptions.UserError; +import org.broadinstitute.sting.utils.exceptions.UserException; import java.util.*; import java.io.File; @@ -122,7 +121,7 @@ public class ThreadLocalOutputTracker extends OutputTracker { tempFile.deleteOnExit(); } catch( IOException ex ) { - throw new UserError.BadTmpDir("Unable to create temporary file for stub: " + stub.getClass().getName() ); + throw new UserException.BadTmpDir("Unable to create temporary file for stub: " + stub.getClass().getName() ); } return tempFile; 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 d8be881fe..fd47b88e7 100644 --- a/java/src/org/broadinstitute/sting/gatk/io/storage/OutputStreamStorage.java +++ b/java/src/org/broadinstitute/sting/gatk/io/storage/OutputStreamStorage.java @@ -26,10 +26,8 @@ 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; -import org.broadinstitute.sting.utils.exceptions.UserError; +import org.broadinstitute.sting.utils.exceptions.UserException; import java.io.*; import java.nio.channels.FileChannel; @@ -74,7 +72,7 @@ public class OutputStreamStorage extends OutputStream implements Storage, VCFWriter { stream = new PrintStream(file); } catch(IOException ex) { - throw new UserError.CouldNotCreateOutputFile(file, "Unable to open target output stream", ex); + throw new UserException.CouldNotCreateOutputFile(file, "Unable to open target output stream", ex); } } else if ( stub.getOutputStream() != null ) { @@ -65,7 +64,7 @@ public class VCFWriterStorage implements Storage, VCFWriter { this.stream = new PrintStream(file); } catch(IOException ex) { - throw new UserError.CouldNotCreateOutputFile(file, "Unable to open target output stream",ex); + throw new UserException.CouldNotCreateOutputFile(file, "Unable to open target output stream",ex); } writer = new StandardVCFWriter(this.stream); writer.writeHeader(stub.getVCFHeader()); @@ -108,7 +107,7 @@ public class VCFWriterStorage implements Storage, VCFWriter { reader.close(); } catch (IOException e) { - throw new UserError.CouldNotReadInputFile(file, "Error reading file in VCFWriterStorage: ", e); + throw new UserException.CouldNotReadInputFile(file, "Error reading file in VCFWriterStorage: ", e); } } } 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 1380a2f01..d847015ed 100644 --- a/java/src/org/broadinstitute/sting/gatk/io/stubs/SAMFileReaderArgumentTypeDescriptor.java +++ b/java/src/org/broadinstitute/sting/gatk/io/stubs/SAMFileReaderArgumentTypeDescriptor.java @@ -28,14 +28,12 @@ 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.exceptions.UserException; import org.broadinstitute.sting.utils.sam.SAMFileReaderBuilder; -import org.broadinstitute.sting.utils.StingException; import org.broadinstitute.sting.gatk.GenomeAnalysisEngine; import net.sf.samtools.SAMFileReader; import java.io.File; -import java.io.OutputStream; /** * Describe how to parse SAMFileReaders. @@ -67,7 +65,7 @@ public class SAMFileReaderArgumentTypeDescriptor extends ArgumentTypeDescriptor String readerFileName = getArgumentValue( createDefaultArgumentDefinition(source), matches ); if( readerFileName == null ) - throw new UserError.CommandLineError("SAM file compression was supplied, but no associated writer was supplied with it."); + throw new UserException.CommandLineException("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 c1a699fe0..ffa6ac2b7 100644 --- a/java/src/org/broadinstitute/sting/gatk/io/stubs/SAMFileWriterArgumentTypeDescriptor.java +++ b/java/src/org/broadinstitute/sting/gatk/io/stubs/SAMFileWriterArgumentTypeDescriptor.java @@ -26,11 +26,10 @@ package org.broadinstitute.sting.gatk.io.stubs; import org.broadinstitute.sting.commandline.*; -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 org.broadinstitute.sting.utils.exceptions.UserException; import java.lang.annotation.Annotation; import java.util.List; @@ -98,7 +97,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 UserError.CommandLineError("SAM file compression was supplied, but no associated writer was supplied with it."); + throw new UserException.CommandLineException("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 280888d76..6af299975 100644 --- a/java/src/org/broadinstitute/sting/gatk/io/stubs/SAMFileWriterStub.java +++ b/java/src/org/broadinstitute/sting/gatk/io/stubs/SAMFileWriterStub.java @@ -36,8 +36,7 @@ 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; -import org.broadinstitute.sting.utils.exceptions.UserError; +import org.broadinstitute.sting.utils.exceptions.UserException; /** * A stub for routing and management of SAM file reading and writing. @@ -175,7 +174,7 @@ public class SAMFileWriterStub implements Stub, StingSAMFileWrite */ public void setIndexOnTheFly( boolean indexOnTheFly ) { if(writeStarted) - throw new UserError("Attempted to index a BAM on the fly of a file with alignments already in it."); + throw new UserException("Attempted to index a BAM on the fly of a file with alignments already in it."); this.indexOnTheFly = indexOnTheFly; } diff --git a/java/src/org/broadinstitute/sting/gatk/iterators/LocusIteratorByState.java b/java/src/org/broadinstitute/sting/gatk/iterators/LocusIteratorByState.java index 44334983c..e0e7b040b 100755 --- a/java/src/org/broadinstitute/sting/gatk/iterators/LocusIteratorByState.java +++ b/java/src/org/broadinstitute/sting/gatk/iterators/LocusIteratorByState.java @@ -34,7 +34,7 @@ import org.broadinstitute.sting.gatk.DownsamplingMethod; import org.broadinstitute.sting.gatk.DownsampleType; import org.broadinstitute.sting.gatk.contexts.AlignmentContext; import org.broadinstitute.sting.utils.*; -import org.broadinstitute.sting.utils.exceptions.UserError; +import org.broadinstitute.sting.utils.exceptions.UserException; import org.broadinstitute.sting.utils.pileup.*; import java.util.*; @@ -198,7 +198,7 @@ public class LocusIteratorByState extends LocusIterator { if ( generateExtendedEvents ) { // we see insertions only once, when we step right onto them; the position on the read is scrolled // past the insertion right after that - if ( eventDelayedFlag > 1 ) throw new UserError.MalformedBam(read, "Adjacent I/D events in read "+read.getReadName()); + if ( eventDelayedFlag > 1 ) throw new UserException.MalformedBam(read, "Adjacent I/D events in read "+read.getReadName()); insertedBases = Arrays.copyOfRange(read.getReadBases(),readOffset+1,readOffset+1+curElement.getLength()); eventLength = curElement.getLength() ; eventStart = readOffset; @@ -214,7 +214,7 @@ public class LocusIteratorByState extends LocusIterator { if ( cigarElementCounter == 1) { // generate an extended event only if we just stepped into the deletion (i.e. don't // generate the event at every deleted position on the ref, that's what cigarElementCounter==1 is for!) - if ( eventDelayedFlag > 1 ) throw new UserError.MalformedBam(read, "Adjacent I/D events in read "+read.getReadName()); + if ( eventDelayedFlag > 1 ) throw new UserException.MalformedBam(read, "Adjacent I/D events in read "+read.getReadName()); eventLength = curElement.getLength(); eventDelayedFlag = 2; // deletion on the ref causes an immediate return, so we have to delay by 1 only eventStart = readOffset; @@ -546,7 +546,7 @@ public class LocusIteratorByState extends LocusIterator { switch(this.downsamplingMethod.type) { case BY_SAMPLE: if(downsamplingMethod.toCoverage == null) - throw new UserError.BadArgumentValue("dcov", "Downsampling coverage (-dcov) must be specified when downsampling by sample"); + throw new UserException.BadArgumentValue("dcov", "Downsampling coverage (-dcov) must be specified when downsampling by sample"); this.targetCoverage = downsamplingMethod.toCoverage; break; default: diff --git a/java/src/org/broadinstitute/sting/gatk/refdata/RODRecordIterator.java b/java/src/org/broadinstitute/sting/gatk/refdata/RODRecordIterator.java index acb8273c4..25e49aa94 100644 --- a/java/src/org/broadinstitute/sting/gatk/refdata/RODRecordIterator.java +++ b/java/src/org/broadinstitute/sting/gatk/refdata/RODRecordIterator.java @@ -27,17 +27,14 @@ package org.broadinstitute.sting.gatk.refdata; import org.broadinstitute.sting.utils.GATKException; import org.broadinstitute.sting.utils.exceptions.DynamicClassResolutionException; -import org.broadinstitute.sting.utils.exceptions.UserError; +import org.broadinstitute.sting.utils.exceptions.UserException; import org.broadinstitute.sting.utils.text.XReadLines; -import org.broadinstitute.sting.utils.Utils; -import org.broadinstitute.sting.utils.StingException; import org.broadinstitute.sting.gatk.iterators.PushbackIterator; import java.util.Iterator; import java.util.regex.Pattern; import java.io.FileNotFoundException; import java.io.File; -import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Constructor; /** @@ -117,7 +114,7 @@ public class RODRecordIterator implements Ite try { reader = new PushbackIterator(new XReadLines(file)); } catch (FileNotFoundException e) { - throw new UserError.CouldNotReadInputFile(file, e); + throw new UserException.CouldNotReadInputFile(file, e); } this.file = file; this.name = name; @@ -133,7 +130,7 @@ public class RODRecordIterator implements Ite try { header = rod.initialize(file); } catch (FileNotFoundException e) { - throw new UserError.CouldNotReadInputFile(file, "ROD "+type.getName() + " failed to initialize properly from file "+file); + throw new UserException.CouldNotReadInputFile(file, "ROD "+type.getName() + " failed to initialize properly from file "+file); } } @@ -197,7 +194,7 @@ public class RODRecordIterator implements Ite parsed_ok = n.parseLine(header,parts) ; } catch ( Exception e ) { - throw new UserError.MalformedFile(file, "Failed to parse ROD data ("+type.getName()+") from file "+ file + " at line #"+linenum+ + throw new UserException.MalformedFile(file, "Failed to parse ROD data ("+type.getName()+") from file "+ file + " at line #"+linenum+ "\nOffending line: "+line+ "\nReason ("+e.getClass().getName()+")", e); } diff --git a/java/src/org/broadinstitute/sting/gatk/refdata/RefMetaDataTracker.java b/java/src/org/broadinstitute/sting/gatk/refdata/RefMetaDataTracker.java index 512621b2f..a0eea556b 100644 --- a/java/src/org/broadinstitute/sting/gatk/refdata/RefMetaDataTracker.java +++ b/java/src/org/broadinstitute/sting/gatk/refdata/RefMetaDataTracker.java @@ -7,8 +7,7 @@ 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 org.broadinstitute.sting.utils.exceptions.UserException; import java.util.*; @@ -108,7 +107,7 @@ public class RefMetaDataTracker { Object obj = objects.get(0).getUnderlyingObject(); if (!(clazz.isAssignableFrom(obj.getClass()))) - throw new UserError.CommandLineError("Unable to case track named " + name + " to type of " + clazz.toString() + throw new UserException.CommandLineException("Unable to case track named " + name + " to type of " + clazz.toString() + " it's of type " + obj.getClass()); return (T)obj; diff --git a/java/src/org/broadinstitute/sting/gatk/refdata/ReferenceOrderedData.java b/java/src/org/broadinstitute/sting/gatk/refdata/ReferenceOrderedData.java index eaa8ab01f..5cdb6e9f7 100644 --- a/java/src/org/broadinstitute/sting/gatk/refdata/ReferenceOrderedData.java +++ b/java/src/org/broadinstitute/sting/gatk/refdata/ReferenceOrderedData.java @@ -1,8 +1,7 @@ package org.broadinstitute.sting.gatk.refdata; import org.apache.log4j.Logger; -import org.broadinstitute.sting.utils.StingException; -import org.broadinstitute.sting.utils.exceptions.UserError; +import org.broadinstitute.sting.utils.exceptions.UserException; import java.io.*; import java.lang.reflect.Method; @@ -42,7 +41,7 @@ public class ReferenceOrderedData implements try { str = new BufferedReader(new FileReader(new File(filename))); } catch (FileNotFoundException e) { - throw new UserError.CouldNotReadInputFile(new File(filename), "Unable to load the ROD input file", e); + throw new UserException.CouldNotReadInputFile(new File(filename), "Unable to load the ROD input file", e); } String line = "NO LINES READ IN"; try { @@ -51,7 +50,7 @@ public class ReferenceOrderedData implements else logger.warn("the following file line didn't parsing into a triplet -> " + line); } } catch (IOException e) { - throw new UserError.CouldNotReadInputFile(new File(filename), "Failed reading the input rod file; last line read was " + line, e); + throw new UserException.CouldNotReadInputFile(new File(filename), "Failed reading the input rod file; last line read was " + line, e); } } diff --git a/java/src/org/broadinstitute/sting/gatk/refdata/SeekableRODIterator.java b/java/src/org/broadinstitute/sting/gatk/refdata/SeekableRODIterator.java index 524e6def2..404082354 100644 --- a/java/src/org/broadinstitute/sting/gatk/refdata/SeekableRODIterator.java +++ b/java/src/org/broadinstitute/sting/gatk/refdata/SeekableRODIterator.java @@ -8,8 +8,7 @@ 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; -import org.broadinstitute.sting.utils.exceptions.UserError; +import org.broadinstitute.sting.utils.exceptions.UserException; import java.util.Iterator; import java.util.LinkedList; @@ -166,12 +165,12 @@ public class SeekableRODIterator implements LocationAwareSeekableRODIterator { } int that_contig = r.getLocation().getContigIndex(); if ( curr_contig > that_contig ) - throw new UserError("LocationAwareSeekableRODIterator: contig " +r.getLocation().getContig() + + throw new UserException("LocationAwareSeekableRODIterator: contig " +r.getLocation().getContig() + " occurs out of order in track " + r.getName() ); if ( curr_contig < that_contig ) break; // next record is on a higher contig, we do not need it yet... if ( r.getLocation().getStart() < curr_position ) - throw new UserError("LocationAwareSeekableRODIterator: track "+r.getName() + + throw new UserException("LocationAwareSeekableRODIterator: track "+r.getName() + " is out of coordinate order on contig "+r.getLocation() + " compared to " + curr_contig + ":" + curr_position); if ( r.getLocation().getStart() > curr_position ) break; // next record starts after the current position; we do not need it yet diff --git a/java/src/org/broadinstitute/sting/gatk/refdata/features/refseq/RefSeqCodec.java b/java/src/org/broadinstitute/sting/gatk/refdata/features/refseq/RefSeqCodec.java index d1c7142f0..f46d41b9a 100644 --- a/java/src/org/broadinstitute/sting/gatk/refdata/features/refseq/RefSeqCodec.java +++ b/java/src/org/broadinstitute/sting/gatk/refdata/features/refseq/RefSeqCodec.java @@ -6,12 +6,9 @@ import org.broad.tribble.TribbleException; import org.broad.tribble.readers.LineReader; import org.broadinstitute.sting.utils.GenomeLoc; import org.broadinstitute.sting.utils.GenomeLocParser; -import org.broadinstitute.sting.utils.StingException; -import org.broadinstitute.sting.utils.exceptions.UserError; +import org.broadinstitute.sting.utils.exceptions.UserException; -import java.io.IOException; import java.util.ArrayList; -import java.util.List; /** * the ref seq codec @@ -41,7 +38,7 @@ public class RefSeqCodec implements FeatureCodec { feature.setTranscript_id(fields[1]); if ( fields[3].length()==1 && fields[3].charAt(0)=='+') feature.setStrand(1); else if ( fields[3].length()==1 && fields[3].charAt(0)=='-') feature.setStrand(-1); - else throw new UserError.MalformedFile("Expected strand symbol (+/-), found: "+fields[3]); + else throw new UserException.MalformedFile("Expected strand symbol (+/-), found: "+fields[3]); feature.setTranscript_interval(GenomeLocParser.parseGenomeLoc(contig_name, Integer.parseInt(fields[4])+1, Integer.parseInt(fields[5]))); 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 cfeae8d5b..b96ff102c 100644 --- a/java/src/org/broadinstitute/sting/gatk/refdata/tracks/RMDTrackManager.java +++ b/java/src/org/broadinstitute/sting/gatk/refdata/tracks/RMDTrackManager.java @@ -28,10 +28,8 @@ 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 org.broadinstitute.sting.utils.exceptions.UserException; import java.io.File; import java.util.*; @@ -177,7 +175,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 UserError.CommandLineError("Unable to find track for " + trip.getType()); + if (b == null) throw new UserException.CommandLineException("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 8d24c63a9..3079a6023 100644 --- a/java/src/org/broadinstitute/sting/gatk/refdata/tracks/TribbleTrack.java +++ b/java/src/org/broadinstitute/sting/gatk/refdata/tracks/TribbleTrack.java @@ -32,8 +32,7 @@ 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; +import org.broadinstitute.sting.utils.exceptions.UserException; import java.io.File; import java.io.IOException; @@ -82,7 +81,7 @@ public class TribbleTrack extends RMDTrack implements QueryableTrack { try { return new FeatureToGATKFeatureIterator(reader.iterator(),this.getName()); } catch (IOException e) { - throw new UserError.CouldNotReadInputFile(getFile(), "Unable to read from file", e); + throw new UserException.CouldNotReadInputFile(getFile(), "Unable to read from file", e); } } 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 38a7ab295..3c636ff2d 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 @@ -30,10 +30,7 @@ import net.sf.samtools.SAMSequenceRecord; import org.apache.log4j.Logger; import org.broad.tribble.*; import org.broad.tribble.index.Index; -import org.broad.tribble.index.IndexCreator; import org.broad.tribble.index.IndexFactory; -import org.broad.tribble.index.interval.IntervalIndexCreator; -import org.broad.tribble.index.linear.LinearIndexCreator; import org.broad.tribble.source.BasicFeatureSource; import org.broad.tribble.util.LittleEndianOutputStream; import org.broadinstitute.sting.gatk.refdata.tracks.TribbleTrack; @@ -42,8 +39,7 @@ 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; -import org.broadinstitute.sting.utils.exceptions.UserError; +import org.broadinstitute.sting.utils.exceptions.UserException; import org.broadinstitute.sting.utils.file.FSLockWithShared; import org.broadinstitute.sting.utils.file.FileSystemInabilityToLockException; @@ -104,7 +100,7 @@ public class TribbleRMDTrackBuilder extends PluginManager implemen public RMDTrack createInstanceOfTrack(Class targetClass, String name, File inputFile) throws RMDTrackCreationException { // return a feature reader track Pair pair = createFeatureReader(targetClass, name, inputFile); - if (pair == null) throw new UserError.CouldNotReadInputFile(inputFile, "Unable to make the feature reader for input file"); + if (pair == null) throw new UserException.CouldNotReadInputFile(inputFile, "Unable to make the feature reader for input file"); return new TribbleTrack(targetClass, name, inputFile, pair.first, pair.second, createCodec(targetClass, name)); } @@ -150,7 +146,7 @@ public class TribbleRMDTrackBuilder extends PluginManager implemen try { return new Pair(BasicFeatureSource.getFeatureSource(inputFile.getAbsolutePath(), createCodec(targetClass, name)),null); } catch (IOException e) { - throw new UserError.CouldNotReadInputFile(inputFile, "Unable to create feature reader from file", e); + throw new UserException.CouldNotReadInputFile(inputFile, "Unable to create feature reader from file", e); } } @@ -183,9 +179,9 @@ public class TribbleRMDTrackBuilder extends PluginManager implemen createCodec(targetClass, name)), sequenceSetToDictionary(index.getSequenceNames())); } catch (FileNotFoundException e) { - throw new UserError.CouldNotReadInputFile(inputFile, "Unable to create reader with file", e); + throw new UserException.CouldNotReadInputFile(inputFile, "Unable to create reader with file", e); } catch (IOException e) { - throw new UserError("Unable to make the index file for " + inputFile, e); + throw new UserException("Unable to make the index file for " + inputFile, e); } return reader; } diff --git a/java/src/org/broadinstitute/sting/gatk/walkers/analyzeannotations/AnnotationDataManager.java b/java/src/org/broadinstitute/sting/gatk/walkers/analyzeannotations/AnnotationDataManager.java index 49377e8f4..d8a8267e4 100755 --- a/java/src/org/broadinstitute/sting/gatk/walkers/analyzeannotations/AnnotationDataManager.java +++ b/java/src/org/broadinstitute/sting/gatk/walkers/analyzeannotations/AnnotationDataManager.java @@ -2,8 +2,7 @@ package org.broadinstitute.sting.gatk.walkers.analyzeannotations; import org.broad.tribble.util.variantcontext.VariantContext; import org.broadinstitute.sting.utils.BaseUtils; -import org.broadinstitute.sting.utils.StingException; -import org.broadinstitute.sting.utils.exceptions.UserError; +import org.broadinstitute.sting.utils.exceptions.UserException; import java.io.File; import java.util.*; @@ -113,7 +112,7 @@ public class AnnotationDataManager { try { output = new PrintStream(filename); // Create the intermediate data file for this annotation } catch ( FileNotFoundException e ) { - throw new UserError.CouldNotCreateOutputFile(new File(filename), "Can't create intermediate output annotation data file. Does the output directory exist?", e); + throw new UserException.CouldNotCreateOutputFile(new File(filename), "Can't create intermediate output annotation data file. Does the output directory exist?", e); } // Output a header line @@ -164,7 +163,7 @@ public class AnnotationDataManager { try { Runtime.getRuntime().exec( rScriptCommandLine ); } catch ( IOException e ) { - throw new UserError.CannotExecuteRScript( rScriptCommandLine, e ); + throw new UserException.CannotExecuteRScript( rScriptCommandLine, e ); } } } 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 e7abae70a..3d0db37a7 100755 --- a/java/src/org/broadinstitute/sting/gatk/walkers/annotator/VariantAnnotatorEngine.java +++ b/java/src/org/broadinstitute/sting/gatk/walkers/annotator/VariantAnnotatorEngine.java @@ -50,9 +50,8 @@ 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; +import org.broadinstitute.sting.utils.exceptions.UserException; public class VariantAnnotatorEngine { @@ -106,7 +105,7 @@ public class VariantAnnotatorEngine { if ( interfaceClass == null ) interfaceClass = classMap.get(group + "Annotation"); if ( interfaceClass == null ) - throw new UserError.BadArgumentValue("group", "Class " + group + " is not found; please check that you have specified the class name correctly"); + throw new UserException.BadArgumentValue("group", "Class " + group + " is not found; please check that you have specified the class name correctly"); classes.addAll(PackageUtils.getClassesImplementingInterface(interfaceClass)); } // get the specific classes provided @@ -115,7 +114,7 @@ public class VariantAnnotatorEngine { if ( annotationClass == null ) annotationClass = classMap.get(annotation + "Annotation"); if ( annotationClass == null ) - throw new UserError.BadArgumentValue("annotation", "Class " + annotation + " is not found; please check that you have specified the class name correctly"); + throw new UserException.BadArgumentValue("annotation", "Class " + annotation + " is not found; please check that you have specified the class name correctly"); classes.add(annotationClass); } } diff --git a/java/src/org/broadinstitute/sting/gatk/walkers/annotator/genomicannotator/GenomicAnnotation.java b/java/src/org/broadinstitute/sting/gatk/walkers/annotator/genomicannotator/GenomicAnnotation.java index 6bff652fd..a7f4a08fc 100644 --- a/java/src/org/broadinstitute/sting/gatk/walkers/annotator/genomicannotator/GenomicAnnotation.java +++ b/java/src/org/broadinstitute/sting/gatk/walkers/annotator/genomicannotator/GenomicAnnotation.java @@ -40,8 +40,7 @@ import org.broadinstitute.sting.gatk.refdata.utils.GATKFeature; import org.broadinstitute.sting.gatk.walkers.annotator.VariantAnnotatorEngine; import org.broadinstitute.sting.gatk.walkers.annotator.interfaces.InfoFieldAnnotation; import org.broadinstitute.sting.utils.BaseUtils; -import org.broadinstitute.sting.utils.StingException; -import org.broadinstitute.sting.utils.exceptions.UserError; +import org.broadinstitute.sting.utils.exceptions.UserException; /** * This plugin for {@link VariantAnnotatorEngine} serves as the core @@ -135,7 +134,7 @@ public class GenomicAnnotation implements InfoFieldAnnotation { //continue; //TODO If this site is monomorphic in the VC, and the current record specifies a particular alternate allele, skip this record. Right? //} else if(alternateAlleles.size() > 1) { - throw new UserError.MalformedFile("File associated with " + vc.getName() + " contains record [" + vc + "] contains " + alternateAlleles.size() + " alternate alleles. GenomicAnnotion currently only supports annotating 1 alternate allele."); + throw new UserException.MalformedFile("File associated with " + vc.getName() + " contains record [" + vc + "] contains " + alternateAlleles.size() + " alternate alleles. GenomicAnnotion currently only supports annotating 1 alternate allele."); } boolean positiveStrand = true; //if HAPLOTYPE_STRAND_COLUMN isn't specified, assume positive strand. @@ -145,7 +144,7 @@ public class GenomicAnnotation implements InfoFieldAnnotation { if(hapStrandValue.equals("-") || hapStrandValue.equals("r")) { positiveStrand = false; } else if(!hapStrandValue.equals("+") && !hapStrandValue.equals("f")) { - throw new UserError.MalformedFile("Record (" + gatkFeature.getUnderlyingObject() + ") in " + name + " has an invalid value for " + HAPLOTYPE_STRAND_COLUMN + ". This value is: \"" + hapStrandValue + "\""); + throw new UserException.MalformedFile("Record (" + gatkFeature.getUnderlyingObject() + ") in " + name + " has an invalid value for " + HAPLOTYPE_STRAND_COLUMN + ". This value is: \"" + hapStrandValue + "\""); } } diff --git a/java/src/org/broadinstitute/sting/gatk/walkers/annotator/genomicannotator/GenomicAnnotator.java b/java/src/org/broadinstitute/sting/gatk/walkers/annotator/genomicannotator/GenomicAnnotator.java index ea43b274c..008e2ce74 100644 --- a/java/src/org/broadinstitute/sting/gatk/walkers/annotator/genomicannotator/GenomicAnnotator.java +++ b/java/src/org/broadinstitute/sting/gatk/walkers/annotator/genomicannotator/GenomicAnnotator.java @@ -46,8 +46,7 @@ import org.broadinstitute.sting.gatk.refdata.features.annotator.AnnotatorInputTa import org.broadinstitute.sting.gatk.walkers.*; import org.broadinstitute.sting.gatk.walkers.annotator.VariantAnnotatorEngine; import org.broadinstitute.sting.utils.SampleUtils; -import org.broadinstitute.sting.utils.StingException; -import org.broadinstitute.sting.utils.exceptions.UserError; +import org.broadinstitute.sting.utils.exceptions.UserException; import org.broadinstitute.sting.utils.vcf.VCFUtils; /** @@ -107,7 +106,7 @@ public class GenomicAnnotator extends RodWalker implements Tre allFullyQualifiedColumnNames.add(bindingName + "." + columnName); } } catch(IOException e) { - throw new UserError.CouldNotReadInputFile(file, "Failed when attempting to read file header. ", e); + throw new UserException.CouldNotReadInputFile(file, "Failed when attempting to read file header. ", e); } } @@ -118,25 +117,25 @@ public class GenomicAnnotator extends RodWalker implements Tre //parse the tokens final String[] arg = joinArg.split(","); if(arg.length != 3) { - throw new UserError.BadArgumentValue("-J", "The following -J arg: \"" + joinArg + "\" must contain 3 comma-separated values. (ex: -J name,/path/to/file,name.columnName=name2.columnName2)"); + throw new UserException.BadArgumentValue("-J", "The following -J arg: \"" + joinArg + "\" must contain 3 comma-separated values. (ex: -J name,/path/to/file,name.columnName=name2.columnName2)"); } final String bindingName = arg[0]; final String filename = arg[1]; final String columnsToJoin = arg[2]; if(allBindingNames.contains(bindingName)) { - throw new UserError.BadArgumentValue("-J", "The name \"" + bindingName + "\" in the -J arg: \"" + joinArg + "\" has already been used in another binding."); + throw new UserException.BadArgumentValue("-J", "The name \"" + bindingName + "\" in the -J arg: \"" + joinArg + "\" has already been used in another binding."); } String[] splitOnEquals = columnsToJoin.split("=+"); if(splitOnEquals.length != 2) { - throw new UserError.BadArgumentValue("-J", "The -J arg: \"" + joinArg + "\" must specify the columns to join on. (ex: -J name,/path/to/file,name.columnName=name2.columnName2)"); + throw new UserException.BadArgumentValue("-J", "The -J arg: \"" + joinArg + "\" must specify the columns to join on. (ex: -J name,/path/to/file,name.columnName=name2.columnName2)"); } String[] splitOnDot1 = splitOnEquals[0].split("\\."); String[] splitOnDot2 = splitOnEquals[1].split("\\."); if(splitOnDot1.length != 2 || splitOnDot2.length != 2) { - throw new UserError.BadArgumentValue("-J", "The -J arg: \"" + joinArg + "\" must fully specify the columns to join on. (ex: -J name,/path/to/file,name.columnName=name2.columnName2)"); + throw new UserException.BadArgumentValue("-J", "The -J arg: \"" + joinArg + "\" must fully specify the columns to join on. (ex: -J name,/path/to/file,name.columnName=name2.columnName2)"); } final String bindingName1 = splitOnDot1[0]; @@ -158,13 +157,13 @@ public class GenomicAnnotator extends RodWalker implements Tre externalBindingName = bindingName1; externalColumnName = columnName1; } else { - throw new UserError.BadArgumentValue("-J", "The name \"" + bindingName + "\" in the -J arg: \"" + joinArg + "\" must be specified in one the columns to join on. (ex: -J name,/path/to/file,name.columnName=name2.columnName2)"); + throw new UserException.BadArgumentValue("-J", "The name \"" + bindingName + "\" in the -J arg: \"" + joinArg + "\" must be specified in one the columns to join on. (ex: -J name,/path/to/file,name.columnName=name2.columnName2)"); } //validate externalColumnName final String fullyQualifiedExternalColumnName = externalBindingName + '.' + externalColumnName; if( !allFullyQualifiedColumnNames.contains(fullyQualifiedExternalColumnName) ) { - throw new UserError.BadArgumentValue("-J", "The -J arg: \"" + joinArg + "\" specifies an unknown column name: \"" + fullyQualifiedExternalColumnName + "\""); + throw new UserException.BadArgumentValue("-J", "The -J arg: \"" + joinArg + "\" specifies an unknown column name: \"" + fullyQualifiedExternalColumnName + "\""); } //read in the file contents into a JoinTable object @@ -182,7 +181,7 @@ public class GenomicAnnotator extends RodWalker implements Tre fullyQualifiedColumnNames.add(localBindingName + '.' + columnName); } if ( !found ) - throw new UserError.BadArgumentValue("-J", "The -J arg: \"" + joinArg + "\" specifies an unknown column name: \"" + localColumnName + "\". It's not one of the column names in the header " + columnNames + " of the file: " + filename); + throw new UserException.BadArgumentValue("-J", "The -J arg: \"" + joinArg + "\" specifies an unknown column name: \"" + localColumnName + "\". It's not one of the column names in the header " + columnNames + " of the file: " + filename); allFullyQualifiedColumnNames.addAll(fullyQualifiedColumnNames); } @@ -195,7 +194,7 @@ public class GenomicAnnotator extends RodWalker implements Tre for ( String columnName : SELECT_COLUMNS ) { if ( !allFullyQualifiedColumnNames.contains(columnName) ) - throw new UserError.BadArgumentValue("-s", "The column name '" + columnName + "' provided to -s doesn't match any of the column names in any of the -B files. Here is the list of available column names: " + allFullyQualifiedColumnNames); + throw new UserException.BadArgumentValue("-s", "The column name '" + columnName + "' provided to -s doesn't match any of the column names in any of the -B files. Here is the list of available column names: " + allFullyQualifiedColumnNames); } //instantiate the VariantAnnotatorEngine 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 57fd8b355..d1b0ded9d 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 @@ -34,8 +34,7 @@ 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; +import org.broadinstitute.sting.utils.exceptions.UserException; /** * This is a container that holds all data corresponding to a single join table as specified by one -J arg (ex: -J bindingName1,/path/to/file,bindingName1.columnName=bindingName2.columnName2). @@ -112,7 +111,7 @@ public class JoinTable } if(localColumnNameIdx == -1) { - throw new UserError.BadArgumentValue("-J", "The -J arg specifies an unknown column name: \"" + localColumnName + "\". It's not one of the column names in the header " + columnNames + " of the file: " + filename); + throw new UserException.BadArgumentValue("-J", "The -J arg specifies an unknown column name: \"" + localColumnName + "\". It's not one of the column names in the header " + columnNames + " of the file: " + filename); } //read in all records and create a map entry for each @@ -127,7 +126,7 @@ public class JoinTable } catch(IOException e) { - throw new UserError.CouldNotReadInputFile(new File(filename), "Unable to parse file", e); + throw new UserException.CouldNotReadInputFile(new File(filename), "Unable to parse file", e); } finally { 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 cfe1478f3..2b603286f 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 @@ -32,9 +32,8 @@ 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; +import org.broadinstitute.sting.utils.exceptions.UserException; /** * Used to parse files passed to the GenomicAnnotator via the -J arg. @@ -92,7 +91,7 @@ public class JoinTableParser final ArrayList values = Utils.split(line, DELIMITER, header.size()); if ( values.size() != header.size() ) { - throw new UserError.MalformedFile(String.format("Encountered a row with %d columns which is different from the number or columns in the header: %d\nHeader: " + header + "\nLine: " + values, values.size(), header.size())); + throw new UserException.MalformedFile(String.format("Encountered a row with %d columns which is different from the number or columns in the header: %d\nHeader: " + header + "\nLine: " + values, values.size(), header.size())); } return values; 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 3b852132c..1a6b3e80f 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 @@ -45,8 +45,7 @@ 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.exceptions.UserError; - +import org.broadinstitute.sting.utils.exceptions.UserException; /** * Takes a table of transcripts (eg. UCSC refGene, knownGene, and CCDS tables) and generates the big table which contains @@ -174,12 +173,12 @@ public class TranscriptToGenomicInfo extends RodWalker { try { header = AnnotatorInputTableCodec.readHeader(transcriptsDataSource.getReferenceOrderedData().getFile()); } catch(Exception e) { - throw new UserError.MalformedFile(transcriptsDataSource.getReferenceOrderedData().getFile(), "Failed when attempting to read header from file", e); + throw new UserException.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 UserError.CommandLineError("The column name '" + columnName + "' provided to -n doesn't match any of the column names in: " + transcriptsDataSource.getReferenceOrderedData().getFile()); + throw new UserException.CommandLineException("The column name '" + columnName + "' provided to -n doesn't match any of the column names in: " + transcriptsDataSource.getReferenceOrderedData().getFile()); } //init outputColumnNames list 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 002c6d68e..c305592c5 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 @@ -41,8 +41,7 @@ import org.broadinstitute.sting.gatk.walkers.Requires; 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; +import org.broadinstitute.sting.utils.exceptions.UserException; /** @@ -71,7 +70,7 @@ public class TranscriptToInfo extends RodWalker implements Tre private String[] GENE_NAME_COLUMNS = {}; public void initialize() { - 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."); + throw new UserException.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 39fe1b922..8f31eab30 100755 --- a/java/src/org/broadinstitute/sting/gatk/walkers/coverage/CallableLociWalker.java +++ b/java/src/org/broadinstitute/sting/gatk/walkers/coverage/CallableLociWalker.java @@ -29,13 +29,11 @@ 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.exceptions.UserException; import org.broadinstitute.sting.utils.pileup.PileupElement; import org.broadinstitute.sting.commandline.Argument; import org.broadinstitute.sting.commandline.Output; -import java.util.EnumMap; -import java.util.Map; import java.io.File; import java.io.PrintStream; import java.io.FileNotFoundException; @@ -92,7 +90,7 @@ public class CallableLociWalker extends LocusWalker bindings = tracker.getReferenceMetaData(track); if ( bindings.size() != 1 || ! (bindings.get(0) instanceof FullBEDFeature)) { - throw new UserError.MalformedFile(String.format("%s track isn't a properly formated CallableBases object!", track)); + throw new UserException.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 6f11d0d15..72be5a6ee 100644 --- a/java/src/org/broadinstitute/sting/gatk/walkers/coverage/CoverageUtils.java +++ b/java/src/org/broadinstitute/sting/gatk/walkers/coverage/CoverageUtils.java @@ -5,8 +5,7 @@ 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.exceptions.UserException; import org.broadinstitute.sting.utils.pileup.PileupElement; import java.util.*; @@ -129,7 +128,7 @@ public class CoverageUtils { SAMReadGroupRecord rg = r.getReadGroup(); if ( rg == null ) { String msg = "Read "+r.getReadName()+" lacks read group information; Please associate all reads with read groups"; - throw new UserError.MalformedBam(r, msg); + throw new UserException.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 d393ccb77..84812469d 100644 --- a/java/src/org/broadinstitute/sting/gatk/walkers/coverage/DepthOfCoverageWalker.java +++ b/java/src/org/broadinstitute/sting/gatk/walkers/coverage/DepthOfCoverageWalker.java @@ -40,7 +40,7 @@ import org.broadinstitute.sting.utils.*; import org.broadinstitute.sting.utils.collections.Pair; import org.broadinstitute.sting.commandline.Argument; import org.broadinstitute.sting.commandline.Output; -import org.broadinstitute.sting.utils.exceptions.UserError; +import org.broadinstitute.sting.utils.exceptions.UserException; import java.io.File; import java.io.IOException; @@ -403,7 +403,7 @@ public class DepthOfCoverageWalker extends LocusWalker { normal_context = new WindowContext(0,WINDOW_SIZE); if ( bedOutput != null && output_file != null ) { - throw new UserError.DeprecatedArgument("-O", "-O option is deprecated and -bed option replaces it; you can not use both at the same time"); + throw new UserException.DeprecatedArgument("-O", "-O option is deprecated and -bed option replaces it; you can not use both at the same time"); } if ( RefseqFileName != null ) { @@ -223,7 +221,7 @@ public class IndelGenotyperV2Walker extends ReadWalker { try { refseqIterator = new SeekableRODIterator(new FeatureToGATKFeatureIterator(refseq.iterator(),"refseq")); } catch (IOException e) { - throw new UserError.CouldNotReadInputFile(new File(RefseqFileName), "Write failed", e); + throw new UserException.CouldNotReadInputFile(new File(RefseqFileName), "Write failed", e); } } @@ -264,12 +262,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 UserError.CouldNotReadInputFile(bedOutput, "Failed to open BED file for writing.", e); + throw new UserException.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 UserError.CouldNotReadInputFile(verboseOutput, "Failed to open BED file for writing.", e); + throw new UserException.CouldNotReadInputFile(verboseOutput, "Failed to open BED file for writing.", e); } vcf_writer.writeHeader(new VCFHeader(getVCFHeaderInfo(), SampleUtils.getSAMFileSamples(getToolkit().getSAMFileHeader()))) ; @@ -299,7 +297,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 UserError.MissortedBAM(SAMFileHeader.SortOrder.coordinate, read, "Read "+read.getReadName()+": contig is out of order; input BAM file is unsorted"); + throw new UserException.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); @@ -327,7 +325,7 @@ 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 UserError.MissortedBAM(SAMFileHeader.SortOrder.coordinate, read, "Read "+read.getReadName() +" out of order on the contig\n"+ + throw new UserException.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()); @@ -382,7 +380,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 UserError.MissortedBAM(SAMFileHeader.SortOrder.coordinate, read, "Read "+read.getReadName()+": out of coverage window bounds. Probably window is too small.\n"+ + throw new UserException.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()+ @@ -394,14 +392,14 @@ public class IndelGenotyperV2Walker extends ReadWalker { String rg = (String)read.getAttribute("RG"); if ( rg == null ) - throw new UserError.MalformedBam(read, "Read "+read.getReadName()+" has no read group in merged stream. RG is required for somatic calls."); + throw new UserException.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 UserError.MalformedBam(read, "Unrecognized read group in merged stream: "+rg); + throw new UserException.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 "+ @@ -503,7 +501,7 @@ public class IndelGenotyperV2Walker extends ReadWalker { verboseWriter.write(fullRecord.toString()); verboseWriter.write('\n'); } catch (IOException e) { - throw new UserError.CouldNotCreateOutputFile(verboseOutput, "Write failed", e); + throw new UserException.CouldNotCreateOutputFile(verboseOutput, "Write failed", e); } } } @@ -663,7 +661,7 @@ public class IndelGenotyperV2Walker extends ReadWalker { verboseWriter.write(fullRecord + "\t"+ annotationString); verboseWriter.write('\n'); } catch (IOException e) { - throw new UserError.CouldNotCreateOutputFile(verboseOutput, "Write failed", e); + throw new UserException.CouldNotCreateOutputFile(verboseOutput, "Write failed", e); } } } @@ -1222,7 +1220,7 @@ public class IndelGenotyperV2Walker extends ReadWalker { try { bed.write(message.toString()+"\n"); } catch (IOException e) { - throw new UserError.CouldNotCreateOutputFile(bedOutput, "Error encountered while writing into output BED file", e); + throw new UserException.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 603c154d4..736efa908 100755 --- a/java/src/org/broadinstitute/sting/gatk/walkers/indels/IndelRealigner.java +++ b/java/src/org/broadinstitute/sting/gatk/walkers/indels/IndelRealigner.java @@ -31,7 +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.exceptions.UserException; import org.broadinstitute.sting.utils.interval.IntervalMergingRule; import org.broadinstitute.sting.utils.interval.IntervalUtils; import org.broadinstitute.sting.gatk.contexts.ReferenceContext; @@ -334,7 +334,7 @@ public class IndelRealigner extends ReadWalker { currentInterval = intervals.hasNext() ? intervals.next() : null; } while ( currentInterval != null && (readLoc == null || currentInterval.isBefore(readLoc)) ); } catch (GATKException e) { - 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); + throw new UserException.MissortedFile(new File(intervalsFile), " *** Are you sure that your interval file is sorted? If not, you must use the --targetIntervalsAreNotSorted argument. ***", e); } @@ -532,7 +532,7 @@ public class IndelRealigner extends ReadWalker { statsOutput.write("\n"); statsOutput.flush(); } catch (Exception e) { - throw new UserError.CouldNotCreateOutputFile("statsOutput", "Failed to write stats output file", e); + throw new UserException.CouldNotCreateOutputFile("statsOutput", "Failed to write stats output file", e); } } } else { @@ -559,7 +559,7 @@ public class IndelRealigner extends ReadWalker { indelOutput.write(str.toString()); indelOutput.flush(); } catch (Exception e) { - throw new UserError.CouldNotCreateOutputFile("indelOutput", "Failed to write indel output file", e); + throw new UserException.CouldNotCreateOutputFile("indelOutput", "Failed to write indel output file", e); } } if ( statsOutput != null ) { @@ -573,7 +573,7 @@ public class IndelRealigner extends ReadWalker { statsOutput.write("\n"); statsOutput.flush(); } catch (Exception e) { - throw new UserError.CouldNotCreateOutputFile("statsOutput", "Failed to write stats output file", e); + throw new UserException.CouldNotCreateOutputFile("statsOutput", "Failed to write stats output file", e); } } @@ -619,7 +619,7 @@ public class IndelRealigner extends ReadWalker { currentInterval.toString(), improvement)); statsOutput.flush(); } catch (Exception e) { - throw new UserError.CouldNotCreateOutputFile("statsOutput", "Failed to write stats output file", e); + throw new UserException.CouldNotCreateOutputFile("statsOutput", "Failed to write stats output file", e); } } } @@ -1059,7 +1059,7 @@ public class IndelRealigner extends ReadWalker { snpsOutput.write(sb.toString()); snpsOutput.flush(); } catch (Exception e) { - throw new UserError.CouldNotCreateOutputFile("snpsOutput", "Failed to write SNPs output file", e); + throw new UserException.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 3d090e87c..6a39f36b6 100755 --- a/java/src/org/broadinstitute/sting/gatk/walkers/indels/RealignerTargetCreator.java +++ b/java/src/org/broadinstitute/sting/gatk/walkers/indels/RealignerTargetCreator.java @@ -33,13 +33,11 @@ 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.exceptions.UserException; import org.broadinstitute.sting.utils.pileup.ExtendedEventPileupElement; import org.broadinstitute.sting.utils.pileup.PileupElement; import org.broadinstitute.sting.utils.pileup.ReadBackedExtendedEventPileup; @@ -85,7 +83,7 @@ public class RealignerTargetCreator extends RodWalker { SAMReadGroupRecord rg = read.getReadGroup(); - if ( rg == null ) throw new UserError.ReadMissingReadGroup(read); + if ( rg == null ) throw new UserException.ReadMissingReadGroup(read); String lane = read.getReadGroup().getPlatformUnit(); String library = read.getReadGroup().getLibrary(); - 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"); + if ( lane == null ) throw new UserException.MalformedBam(read, "Read "+read.getReadName()+" has no platform unit information"); + if ( library == null ) throw new UserException.MalformedBam(read, "Read "+read.getReadName()+" has no library information"); int end = 0; @@ -110,11 +109,11 @@ public class CycleQualityWalker extends ReadWalker { if ( read.getFirstOfPairFlag() ) { if ( read.getSecondOfPairFlag() ) - throw new UserError.MalformedBam(read, "Read "+read.getReadName()+" has conflicting first/second in pair attributes"); + throw new UserException.MalformedBam(read, "Read "+read.getReadName()+" has conflicting first/second in pair attributes"); end = 1; } else { if ( ! read.getSecondOfPairFlag() ) - throw new UserError.MalformedBam(read, "Read "+read.getReadName()+" has conflicting first/second in pair attributes"); + throw new UserException.MalformedBam(read, "Read "+read.getReadName()+" has conflicting first/second in pair attributes"); end = 2; } } @@ -361,7 +360,7 @@ public class CycleQualityWalker extends ReadWalker { } } catch (IOException ioe) { - throw new UserError.CouldNotCreateOutputFile(f, "Failed to write report", ioe); + throw new UserException.CouldNotCreateOutputFile(f, "Failed to write report", ioe); } } @@ -408,7 +407,7 @@ public class CycleQualityWalker extends ReadWalker { public void add(byte[] quals) { if ( quals.length > cycleQualsAv.length ) - throw new UserError("A read of length "+quals.length+" encountered, which exceeds specified maximum read length"); + throw new UserException("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 f552e9ea9..2f1773d01 100755 --- a/java/src/org/broadinstitute/sting/gatk/walkers/qc/ReadClippingStatsWalker.java +++ b/java/src/org/broadinstitute/sting/gatk/walkers/qc/ReadClippingStatsWalker.java @@ -27,10 +27,9 @@ import org.broadinstitute.sting.gatk.walkers.DataSource; import org.broadinstitute.sting.gatk.walkers.ReadWalker; import org.broadinstitute.sting.gatk.refdata.ReadMetaDataTracker; 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.exceptions.UserException; import org.broadinstitute.sting.utils.sam.AlignmentUtils; import org.broadinstitute.sting.commandline.Argument; import org.broadinstitute.sting.commandline.Output; @@ -77,7 +76,7 @@ public class ReadClippingStatsWalker extends ReadWalker argument and the default platform using the --default_platform argument." ); } } @@ -260,7 +260,7 @@ public class RecalDataManager { } readGroup.setPlatform( RAC.DEFAULT_PLATFORM ); } else { - throw new UserError.MalformedBam(read, "The input .bam file contains reads with no platform information. First observed at read with name = " + read.getReadName() + + throw new UserException.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." ); } } @@ -281,7 +281,7 @@ public class RecalDataManager { if( attr instanceof String ) { colorSpace = ((String)attr).getBytes(); } else { - throw new UserError.MalformedBam(read, String.format("Value encoded by %s in %s isn't a string!", RecalDataManager.COLOR_SPACE_ATTRIBUTE_TAG, read.getReadName())); + throw new UserException.MalformedBam(read, 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 @@ -300,7 +300,7 @@ public class RecalDataManager { read.setAttribute( RecalDataManager.COLOR_SPACE_INCONSISTENCY_TAG, inconsistency ); } else { - throw new UserError.MalformedBam(read, "Unable to find color space information in SOLiD read. First observed at read with name = " + read.getReadName() + + throw new UserException.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."); } } @@ -357,7 +357,7 @@ public class RecalDataManager { } } else { - throw new UserError.MalformedBam(read, "Unable to find color space information in SOLiD read. First observed at read with name = " + read.getReadName() + + throw new UserException.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."); } @@ -382,7 +382,7 @@ public class RecalDataManager { } } else { - throw new UserError.MalformedBam(read, "Unable to find color space information in SOLiD read. First observed at read with name = " + read.getReadName() + + throw new UserException.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."); } } @@ -492,7 +492,7 @@ public class RecalDataManager { } read.setReadBases( readBases ); } else { // No color space quality tag in file - throw new UserError.MalformedBam(read, "REMOVE_REF_BIAS recal mode requires color space qualities but they can't be found for read: " + read.getReadName()); + throw new UserException.MalformedBam(read, "REMOVE_REF_BIAS recal mode requires color space qualities but they can't be found for read: " + read.getReadName()); } } @@ -513,7 +513,7 @@ public class RecalDataManager { case '3': return performColorThree( prevBase ); default: - throw new UserError.MalformedBam(read, "Unrecognized color space in SOLID read, color = " + (char)color + + throw new UserException.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 6cf593c1a..c1435f52e 100644 --- a/java/src/org/broadinstitute/sting/gatk/walkers/recalibration/TableRecalibrationWalker.java +++ b/java/src/org/broadinstitute/sting/gatk/walkers/recalibration/TableRecalibrationWalker.java @@ -27,7 +27,6 @@ package org.broadinstitute.sting.gatk.walkers.recalibration; import java.io.File; import java.io.FileNotFoundException; -import java.io.PrintStream; import java.util.*; import java.util.regex.Pattern; @@ -46,9 +45,8 @@ import org.broadinstitute.sting.gatk.contexts.ReferenceContext; 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.DynamicClassResolutionException; -import org.broadinstitute.sting.utils.exceptions.UserError; +import org.broadinstitute.sting.utils.exceptions.UserException; import org.broadinstitute.sting.utils.text.TextFormattingUtils; import org.broadinstitute.sting.utils.Utils; import org.broadinstitute.sting.utils.text.XReadLines; @@ -181,7 +179,7 @@ public class TableRecalibrationWalker extends ReadWalker { } ReportFormat.AcceptableOutputType type = (outputLocation == null) ? ReportFormat.AcceptableOutputType.STREAM : ReportFormat.AcceptableOutputType.FILE; if (!VE2ReportFactory.isCompatibleWithOutputType(type,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); + throw new UserException.CommandLineException("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(); @@ -378,7 +376,7 @@ public class VariantEvalWalker extends RodWalker { for ( String line : new XReadLines(rsIDFile) ) { String parts[] = line.split(" "); if ( parts.length != 2 ) - throw new UserError.MalformedFile(rsIDFile, "Invalid rsID / build pair at " + n + " line = " + line ); + throw new UserException.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); @@ -390,7 +388,7 @@ public class VariantEvalWalker extends RodWalker { logger.info(String.format("Read %d rsIDs from rsID -> build file", n)); } } catch (FileNotFoundException e) { - throw new UserError.CouldNotReadInputFile(rsIDFile, e); + throw new UserException.CouldNotReadInputFile(rsIDFile, e); } logger.info(String.format("Excluding %d of %d (%.2f%%) rsIDs found from builds > %d", @@ -425,7 +423,7 @@ public class VariantEvalWalker extends RodWalker { // get the specific classes provided for ( String module : modulesToUse ) { if ( !classMap.containsKey(module) ) - throw new UserError.CommandLineError("Module " + module + " could not be found; please check that you have specified the class name correctly"); + throw new UserException.CommandLineException("Module " + module + " could not be found; please check that you have specified the class name correctly"); evaluationClasses.add(classMap.get(module)); } @@ -672,7 +670,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 UserError.CommandLineError("Found multiple variant contexts found in " + name + " at " + context.getLocation() + "; VariantEval assumes one variant per position"); + throw new UserException.CommandLineException("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; diff --git a/java/src/org/broadinstitute/sting/gatk/walkers/variantrecalibration/ApplyVariantCuts.java b/java/src/org/broadinstitute/sting/gatk/walkers/variantrecalibration/ApplyVariantCuts.java index 7eaf9247f..57196d17f 100755 --- a/java/src/org/broadinstitute/sting/gatk/walkers/variantrecalibration/ApplyVariantCuts.java +++ b/java/src/org/broadinstitute/sting/gatk/walkers/variantrecalibration/ApplyVariantCuts.java @@ -37,7 +37,7 @@ import org.broadinstitute.sting.gatk.walkers.RodWalker; import org.broadinstitute.sting.utils.*; import org.broadinstitute.sting.utils.collections.ExpandingArrayList; import org.broadinstitute.sting.commandline.Argument; -import org.broadinstitute.sting.utils.exceptions.UserError; +import org.broadinstitute.sting.utils.exceptions.UserException; import org.broadinstitute.sting.utils.vcf.VCFUtils; import org.broadinstitute.sting.utils.text.XReadLines; @@ -128,7 +128,7 @@ public class ApplyVariantCuts extends RodWalker { return tranches; } catch( FileNotFoundException e ) { - throw new UserError.CouldNotCreateOutputFile(f, e); + throw new UserException.CouldNotCreateOutputFile(f, e); } } @@ -156,7 +156,7 @@ public class ApplyVariantCuts extends RodWalker { firstLine = false; } } catch( FileNotFoundException e ) { - throw new UserError.CouldNotCreateOutputFile(TRANCHES_FILE, e); + throw new UserException.CouldNotCreateOutputFile(TRANCHES_FILE, e); } // setup the header fields diff --git a/java/src/org/broadinstitute/sting/gatk/walkers/variantrecalibration/GenerateVariantClustersWalker.java b/java/src/org/broadinstitute/sting/gatk/walkers/variantrecalibration/GenerateVariantClustersWalker.java index e7acd71e4..172bc0309 100755 --- a/java/src/org/broadinstitute/sting/gatk/walkers/variantrecalibration/GenerateVariantClustersWalker.java +++ b/java/src/org/broadinstitute/sting/gatk/walkers/variantrecalibration/GenerateVariantClustersWalker.java @@ -30,21 +30,14 @@ import org.broad.tribble.util.variantcontext.VariantContext; import org.broadinstitute.sting.commandline.Output; import org.broadinstitute.sting.gatk.contexts.AlignmentContext; import org.broadinstitute.sting.gatk.contexts.ReferenceContext; -import org.broadinstitute.sting.gatk.contexts.variantcontext.VariantContextUtils; import org.broadinstitute.sting.gatk.datasources.simpleDataSources.ReferenceOrderedDataSource; import org.broadinstitute.sting.gatk.refdata.RefMetaDataTracker; -import org.broadinstitute.sting.gatk.refdata.tracks.RMDTrack; import org.broadinstitute.sting.gatk.refdata.utils.helpers.DbSNPHelper; import org.broadinstitute.sting.gatk.walkers.RodWalker; -import org.broadinstitute.sting.utils.BaseUtils; import org.broadinstitute.sting.utils.collections.ExpandingArrayList; -import org.broadinstitute.sting.utils.StingException; -import org.broadinstitute.sting.utils.Utils; import org.broadinstitute.sting.commandline.Argument; -import org.broadinstitute.sting.utils.exceptions.UserError; +import org.broadinstitute.sting.utils.exceptions.UserException; -import java.io.File; -import java.io.IOException; import java.io.PrintStream; import java.util.*; @@ -148,7 +141,7 @@ public class GenerateVariantClustersWalker extends RodWalker 0 clustering weight! Please provide sets of known polymorphic loci to be used as training data using the dbsnp, hapmap, or 1kg rod bindings. Clustering weights can be specified using -weightDBSNP, -weightHapMap, and -weight1KG" ); + throw new UserException.BadInput("There are zero variants with > 0 clustering weight! Please provide sets of known polymorphic loci to be used as training data using the dbsnp, hapmap, or 1kg rod bindings. Clustering weights can be specified using -weightDBSNP, -weightHapMap, and -weight1KG" ); } if( _annotationKeys == null ) { numAnnotations = 0; @@ -63,7 +62,7 @@ public class VariantDataManager { } else { numAnnotations = _annotationKeys.size(); if( numAnnotations <= 0 ) { - throw new UserError.BadInput("There are zero annotations. At least one annotation must be provided to use this walker!" ); + throw new UserException.BadInput("There are zero annotations. At least one annotation must be provided to use this walker!" ); } meanVector = new double[numAnnotations]; varianceVector = new double[numAnnotations]; @@ -111,7 +110,7 @@ public class VariantDataManager { } isNormalized = true; // Each data point is now [ (x - mean) / standard deviation ] if( foundZeroVarianceAnnotation ) { - throw new UserError.BadInput("Found annotations with zero variance. They must be excluded before proceeding."); + throw new UserException.BadInput("Found annotations with zero variance. They must be excluded before proceeding."); } } diff --git a/java/src/org/broadinstitute/sting/gatk/walkers/variantrecalibration/VariantGaussianMixtureModel.java b/java/src/org/broadinstitute/sting/gatk/walkers/variantrecalibration/VariantGaussianMixtureModel.java index 3328a44ec..d8ec9547b 100755 --- a/java/src/org/broadinstitute/sting/gatk/walkers/variantrecalibration/VariantGaussianMixtureModel.java +++ b/java/src/org/broadinstitute/sting/gatk/walkers/variantrecalibration/VariantGaussianMixtureModel.java @@ -31,8 +31,7 @@ import org.broadinstitute.sting.gatk.contexts.variantcontext.VariantContextUtils import org.broadinstitute.sting.utils.GATKException; import org.broadinstitute.sting.utils.MathUtils; import org.broadinstitute.sting.utils.collections.ExpandingArrayList; -import org.broadinstitute.sting.utils.StingException; -import org.broadinstitute.sting.utils.exceptions.UserError; +import org.broadinstitute.sting.utils.exceptions.UserException; import org.broadinstitute.sting.utils.text.XReadLines; import Jama.*; @@ -132,11 +131,11 @@ public final class VariantGaussianMixtureModel extends VariantOptimizationModel } else if( CLUSTER_PATTERN.matcher(line).matches() ) { clusterLines.add(line); } else { - throw new UserError.MalformedFile(clusterFile, "Could not parse line: " + line); + throw new UserException.MalformedFile(clusterFile, "Could not parse line: " + line); } } } catch ( FileNotFoundException e ) { - throw new UserError.CouldNotReadInputFile(clusterFile, e); + throw new UserException.CouldNotReadInputFile(clusterFile, e); } dataManager = new VariantDataManager( annotationLines ); @@ -430,7 +429,7 @@ public final class VariantGaussianMixtureModel extends VariantOptimizationModel try { value = Double.parseDouble( (String)vc.getAttribute( annotationKey ) ); } catch( NumberFormatException e ) { - throw new UserError.MalformedFile(vc.getName(), "No double value detected for annotation = " + annotationKey + " in variant at " + VariantContextUtils.getLocation(vc) + ", reported annotation value = " + vc.getAttribute( annotationKey ), e ); + throw new UserException.MalformedFile(vc.getName(), "No double value detected for annotation = " + annotationKey + " in variant at " + VariantContextUtils.getLocation(vc) + ", reported annotation value = " + vc.getAttribute( annotationKey ), e ); } } return value; @@ -493,7 +492,7 @@ public final class VariantGaussianMixtureModel extends VariantOptimizationModel try { outputFile = new PrintStream( file ); } catch (FileNotFoundException e) { - throw new UserError.CouldNotCreateOutputFile( file, e ); + throw new UserException.CouldNotCreateOutputFile( file, e ); } outputFile.println("annotationValue,knownDist,novelDist"); diff --git a/java/src/org/broadinstitute/sting/gatk/walkers/variantrecalibration/VariantRecalibrator.java b/java/src/org/broadinstitute/sting/gatk/walkers/variantrecalibration/VariantRecalibrator.java index ae7bbf644..73a87f3ff 100755 --- a/java/src/org/broadinstitute/sting/gatk/walkers/variantrecalibration/VariantRecalibrator.java +++ b/java/src/org/broadinstitute/sting/gatk/walkers/variantrecalibration/VariantRecalibrator.java @@ -35,18 +35,16 @@ import org.broadinstitute.sting.gatk.contexts.ReferenceContext; import org.broadinstitute.sting.gatk.contexts.variantcontext.VariantContextUtils; import org.broadinstitute.sting.gatk.datasources.simpleDataSources.ReferenceOrderedDataSource; import org.broadinstitute.sting.gatk.refdata.RefMetaDataTracker; -import org.broadinstitute.sting.gatk.refdata.tracks.RMDTrack; import org.broadinstitute.sting.gatk.refdata.utils.helpers.DbSNPHelper; import org.broadinstitute.sting.gatk.walkers.RodWalker; import org.broadinstitute.sting.utils.*; import org.broadinstitute.sting.utils.collections.ExpandingArrayList; import org.broadinstitute.sting.commandline.Argument; -import org.broadinstitute.sting.utils.exceptions.UserError; +import org.broadinstitute.sting.utils.exceptions.UserException; import org.broadinstitute.sting.utils.vcf.VCFUtils; import java.io.File; import java.io.FileNotFoundException; -import java.io.IOException; import java.io.PrintStream; import java.util.*; @@ -144,7 +142,7 @@ public class VariantRecalibrator extends RodWalker(Arrays.asList(PRIORITY_STRING.split(","))); @@ -115,10 +115,10 @@ public class CombineVariants extends RodWalker { priority = new ArrayList(rodNames); if ( rodNames.size() != priority.size() ) - throw new UserError.BadArgumentValue("rod_priority_list", "The priority list must contain exactly one rod binding per ROD provided to the GATK: rodNames=" + rodNames + " priority=" + priority); + throw new UserException.BadArgumentValue("rod_priority_list", "The priority list must contain exactly one rod binding per ROD provided to the GATK: rodNames=" + rodNames + " priority=" + priority); if ( ! rodNames.containsAll(priority) ) - throw new UserError.BadArgumentValue("rod_priority_list", "Not all priority elements provided as input RODs: " + PRIORITY_STRING); + throw new UserException.BadArgumentValue("rod_priority_list", "Not all priority elements provided as input RODs: " + PRIORITY_STRING); } public Integer map(RefMetaDataTracker tracker, ReferenceContext ref, AlignmentContext context) { diff --git a/java/src/org/broadinstitute/sting/oneoffprojects/walkers/AnnotationByAlleleFrequencyWalker.java b/java/src/org/broadinstitute/sting/oneoffprojects/walkers/AnnotationByAlleleFrequencyWalker.java index f296b4817..0e10b2c6c 100755 --- a/java/src/org/broadinstitute/sting/oneoffprojects/walkers/AnnotationByAlleleFrequencyWalker.java +++ b/java/src/org/broadinstitute/sting/oneoffprojects/walkers/AnnotationByAlleleFrequencyWalker.java @@ -35,10 +35,9 @@ import org.broadinstitute.sting.gatk.walkers.annotator.interfaces.AnnotationType import org.broadinstitute.sting.gatk.walkers.annotator.interfaces.GenotypeAnnotation; import org.broadinstitute.sting.gatk.walkers.annotator.interfaces.InfoFieldAnnotation; import org.broadinstitute.sting.utils.GenomeLoc; -import org.broadinstitute.sting.utils.StingException; import org.broadinstitute.sting.utils.classloader.PackageUtils; import org.broadinstitute.sting.utils.exceptions.DynamicClassResolutionException; -import org.broadinstitute.sting.utils.exceptions.UserError; +import org.broadinstitute.sting.utils.exceptions.UserException; import java.util.*; @@ -92,7 +91,7 @@ public class AnnotationByAlleleFrequencyWalker extends RodWalker 3 || ( nPreviousReadBases > 3 && readBasesMustMatchRef ) ) { - throw new UserError.CommandLineError("You have opted to use a number of previous bases in excess of 3. In order to do this you must change the reference window size in the walker itself."); + throw new UserException.CommandLineException("You have opted to use a number of previous bases in excess of 3. In order to do this you must change the reference window size in the walker itself."); } UnifiedArgumentCollection uac = new UnifiedArgumentCollection(); uac.baseModel = BaseMismatchModel.THREE_STATE; @@ -151,7 +151,7 @@ public class BaseTransitionTableCalculatorJavaWalker extends LocusWalker { } else if ( controlReadGroups.contains( read.getReadGroup().getReadGroupId() )) { addControl(read); } else { - throw new UserError.MalformedBam(read, "Read "+read + " belongs to unrecognized read group"); + throw new UserException.MalformedBam(read, "Read "+read + " belongs to unrecognized read group"); } return 1; } diff --git a/java/src/org/broadinstitute/sting/oneoffprojects/walkers/DbSNPWindowCounter.java b/java/src/org/broadinstitute/sting/oneoffprojects/walkers/DbSNPWindowCounter.java index e07227d29..dcc96d66f 100644 --- a/java/src/org/broadinstitute/sting/oneoffprojects/walkers/DbSNPWindowCounter.java +++ b/java/src/org/broadinstitute/sting/oneoffprojects/walkers/DbSNPWindowCounter.java @@ -1,7 +1,5 @@ package org.broadinstitute.sting.oneoffprojects.walkers; -import net.sf.samtools.util.CloseableIterator; -import org.broad.tribble.FeatureIterator; import org.broad.tribble.FeatureSource; import org.broad.tribble.dbsnp.DbSNPCodec; import org.broad.tribble.dbsnp.DbSNPFeature; @@ -16,11 +14,9 @@ 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.gatk.walkers.Requires; -import org.broadinstitute.sting.utils.StingException; -import org.broadinstitute.sting.utils.exceptions.UserError; +import org.broadinstitute.sting.utils.exceptions.UserException; import java.io.File; -import java.io.FileNotFoundException; import java.io.IOException; import java.io.PrintStream; @@ -69,7 +65,7 @@ public class DbSNPWindowCounter extends LocusWalker { windowStart, windowStop); } catch (IOException e) { - throw new UserError.CouldNotReadInputFile(myDbSNPFile, e); + throw new UserException.CouldNotReadInputFile(myDbSNPFile, e); } // count the number of dbSNPs we've seen diff --git a/java/src/org/broadinstitute/sting/oneoffprojects/walkers/IndelAnnotator.java b/java/src/org/broadinstitute/sting/oneoffprojects/walkers/IndelAnnotator.java index eda664699..2c8df083c 100644 --- a/java/src/org/broadinstitute/sting/oneoffprojects/walkers/IndelAnnotator.java +++ b/java/src/org/broadinstitute/sting/oneoffprojects/walkers/IndelAnnotator.java @@ -18,8 +18,7 @@ import org.broadinstitute.sting.gatk.walkers.RodWalker; import org.broadinstitute.sting.utils.GenomeLoc; import org.broadinstitute.sting.utils.GenomeLocParser; import org.broadinstitute.sting.utils.SampleUtils; -import org.broadinstitute.sting.utils.StingException; -import org.broadinstitute.sting.utils.exceptions.UserError; +import org.broadinstitute.sting.utils.exceptions.UserException; import org.broadinstitute.sting.utils.vcf.VCFUtils; import java.io.File; @@ -43,7 +42,7 @@ public class IndelAnnotator extends RodWalker { try { refseqIterator = new SeekableRODIterator(new FeatureToGATKFeatureIterator(refseq.iterator(),"refseq")); } catch (IOException e) { - throw new UserError.CouldNotReadInputFile(RefseqFileName, e); + throw new UserException.CouldNotReadInputFile(RefseqFileName, e); } logger.info("Using RefSeq annotations from " + RefseqFileName); diff --git a/java/src/org/broadinstitute/sting/oneoffprojects/walkers/IndelDBRateWalker.java b/java/src/org/broadinstitute/sting/oneoffprojects/walkers/IndelDBRateWalker.java index 9852130f4..5bc71c8cf 100644 --- a/java/src/org/broadinstitute/sting/oneoffprojects/walkers/IndelDBRateWalker.java +++ b/java/src/org/broadinstitute/sting/oneoffprojects/walkers/IndelDBRateWalker.java @@ -16,9 +16,8 @@ import org.broadinstitute.sting.gatk.walkers.Reference; import org.broadinstitute.sting.gatk.walkers.RodWalker; import org.broadinstitute.sting.gatk.walkers.Window; import org.broadinstitute.sting.utils.SampleUtils; -import org.broadinstitute.sting.utils.StingException; import org.broadinstitute.sting.utils.collections.ExpandingArrayList; -import org.broadinstitute.sting.utils.exceptions.UserError; +import org.broadinstitute.sting.utils.exceptions.UserException; import org.broadinstitute.sting.utils.vcf.VCFUtils; import java.io.PrintStream; @@ -46,7 +45,7 @@ public class IndelDBRateWalker extends RodWalker public void initialize() { if ( indelWindow > 40 ) { - throw new UserError.CommandLineError("Indel windows have a maximum size of 40"); + throw new UserException.CommandLineException("Indel windows have a maximum size of 40"); } if ( outVCF != null ) { diff --git a/java/src/org/broadinstitute/sting/oneoffprojects/walkers/QualityScoreByStrandWalker.java b/java/src/org/broadinstitute/sting/oneoffprojects/walkers/QualityScoreByStrandWalker.java index 3f519f1c3..735da661a 100644 --- a/java/src/org/broadinstitute/sting/oneoffprojects/walkers/QualityScoreByStrandWalker.java +++ b/java/src/org/broadinstitute/sting/oneoffprojects/walkers/QualityScoreByStrandWalker.java @@ -30,8 +30,7 @@ import java.io.IOException; import org.broadinstitute.sting.utils.GATKException; import org.broadinstitute.sting.utils.QualityUtils; -import org.broadinstitute.sting.utils.StingException; -import org.broadinstitute.sting.utils.exceptions.UserError; +import org.broadinstitute.sting.utils.exceptions.UserException; import org.broadinstitute.sting.utils.pileup.ReadBackedPileup; import org.broadinstitute.sting.utils.pileup.PileupElement; import org.broadinstitute.sting.commandline.Argument; @@ -170,7 +169,7 @@ public class QualityScoreByStrandWalker extends LocusWalker try { inputReader = new BufferedReader( new FileReader ( inputQualityFile ) ); } catch ( FileNotFoundException e) { - throw new UserError.CouldNotReadInputFile(new File(inputQualityFile), e); + throw new UserException.CouldNotReadInputFile(new File(inputQualityFile), e); } catch (IOException e) { - throw new UserError.CouldNotReadInputFile(new File(inputQualityFile), e); + throw new UserException.CouldNotReadInputFile(new File(inputQualityFile), e); } return outputBamFile; } @@ -104,13 +103,13 @@ public class ReadQualityScoreWalker extends ReadWalker try { if( line == null ) { line = inputReader.readLine(); - if( line == null ) { throw new UserError.MalformedFile(new File(inputQualityFile), "Input file is empty" ); } + if( line == null ) { throw new UserException.MalformedFile(new File(inputQualityFile), "Input file is empty" ); } } String[] halves = line.split( " ", 2 ); GenomeLoc curLoc = GenomeLocParser.parseGenomeLoc( halves[0] ); while( curLoc.isBefore( readLoc ) ) { // Loop until the beginning of the read line = inputReader.readLine(); - if( line == null ) { throw new UserError.MalformedFile(new File(inputQualityFile), "Input file doesn't encompass all reads. Can't find beginning of read: " + readLoc ); } + if( line == null ) { throw new UserException.MalformedFile(new File(inputQualityFile), "Input file doesn't encompass all reads. Can't find beginning of read: " + readLoc ); } halves = line.split( " ", 2 ); curLoc = GenomeLocParser.parseGenomeLoc( halves[0] ); } @@ -123,7 +122,7 @@ public class ReadQualityScoreWalker extends ReadWalker sumNeighborhoodQuality += Float.parseFloat( halves[1] ); numLines++; line = inputReader.readLine(); - if( line == null ) { throw new UserError.MalformedFile(new File(inputQualityFile), "Input file doesn't encompass all reads. Can't find end of read: " + readLoc ); } + if( line == null ) { throw new UserException.MalformedFile(new File(inputQualityFile), "Input file doesn't encompass all reads. Can't find end of read: " + readLoc ); } halves = line.split( " ", 2 ); curLoc = GenomeLocParser.parseGenomeLoc( halves[0] ); } @@ -133,9 +132,9 @@ public class ReadQualityScoreWalker extends ReadWalker line = savedLine; } catch ( FileNotFoundException e ) { - throw new UserError.CouldNotReadInputFile(new File(inputQualityFile), e); + throw new UserException.CouldNotReadInputFile(new File(inputQualityFile), e); } catch (IOException e ) { - throw new UserError.CouldNotReadInputFile(new File(inputQualityFile), e); + throw new UserException.CouldNotReadInputFile(new File(inputQualityFile), e); } meanNeighborhoodQuality = sumNeighborhoodQuality / ((float) numLines); diff --git a/java/src/org/broadinstitute/sting/oneoffprojects/walkers/TestReadFishingWalker.java b/java/src/org/broadinstitute/sting/oneoffprojects/walkers/TestReadFishingWalker.java index 1e3a0acb1..3b949f384 100644 --- a/java/src/org/broadinstitute/sting/oneoffprojects/walkers/TestReadFishingWalker.java +++ b/java/src/org/broadinstitute/sting/oneoffprojects/walkers/TestReadFishingWalker.java @@ -35,14 +35,13 @@ import org.broadinstitute.sting.alignment.Alignment; import org.broadinstitute.sting.commandline.Argument; import org.broadinstitute.sting.commandline.Output; import org.broadinstitute.sting.utils.GATKException; -import org.broadinstitute.sting.utils.StingException; import org.broadinstitute.sting.utils.GenomeLoc; import org.broadinstitute.sting.utils.GenomeLocParser; import net.sf.samtools.SAMRecord; import net.sf.samtools.util.StringUtil; import net.sf.picard.reference.ReferenceSequence; import net.sf.picard.reference.IndexedFastaSequenceFile; -import org.broadinstitute.sting.utils.exceptions.UserError; +import org.broadinstitute.sting.utils.exceptions.UserException; import java.io.File; import java.io.FileInputStream; @@ -87,7 +86,7 @@ public class TestReadFishingWalker extends ReadWalker { indelCallInputStream = new FileInputStream(indelCalls); } catch(IOException ex) { - throw new UserError.CouldNotReadInputFile(indelCalls, ex); + throw new UserException.CouldNotReadInputFile(indelCalls, ex); } Scanner indelCallReader = new Scanner(indelCallInputStream); diff --git a/java/src/org/broadinstitute/sting/oneoffprojects/walkers/varianteval/AminoAcidTransition.java b/java/src/org/broadinstitute/sting/oneoffprojects/walkers/varianteval/AminoAcidTransition.java index e42fb6b02..edd2d40b1 100755 --- a/java/src/org/broadinstitute/sting/oneoffprojects/walkers/varianteval/AminoAcidTransition.java +++ b/java/src/org/broadinstitute/sting/oneoffprojects/walkers/varianteval/AminoAcidTransition.java @@ -1,6 +1,5 @@ package org.broadinstitute.sting.gatk.walkers.varianteval; -import org.apache.log4j.Logger; import org.broad.tribble.util.variantcontext.VariantContext; import org.broadinstitute.sting.gatk.contexts.AlignmentContext; import org.broadinstitute.sting.gatk.contexts.ReferenceContext; @@ -9,12 +8,10 @@ import org.broadinstitute.sting.gatk.refdata.RefMetaDataTracker; import org.broadinstitute.sting.playground.utils.report.tags.Analysis; import org.broadinstitute.sting.playground.utils.report.tags.DataPoint; import org.broadinstitute.sting.playground.utils.report.utils.TableType; -import org.broadinstitute.sting.utils.GATKException; -import org.broadinstitute.sting.utils.StingException; import org.broadinstitute.sting.utils.analysis.AminoAcid; import org.broadinstitute.sting.utils.analysis.AminoAcidTable; import org.broadinstitute.sting.utils.analysis.AminoAcidUtils; -import org.broadinstitute.sting.utils.exceptions.UserError; +import org.broadinstitute.sting.utils.exceptions.UserException; /* * Copyright (c) 2010 The Broad Institute @@ -145,11 +142,11 @@ public class AminoAcidTransition extends VariantEvaluator { infoValueSplit = parent.aminoAcidTransitionSplit; useCodons = parent.aatUseCodons; if ( infoKey == null ) { - throw new UserError.CommandLineError("No info-field key provided for amino acid tabulation. Please provide the appropriate key with -aatk."); + throw new UserException.CommandLineException("No info-field key provided for amino acid tabulation. Please provide the appropriate key with -aatk."); } if ( infoValueSplit == null ) { - throw new UserError.CommandLineError("No split string provided for amino acid tabulation. Please provide the split string with -aats"); + throw new UserException.CommandLineException("No split string provided for amino acid tabulation. Please provide the split string with -aats"); } } } diff --git a/java/src/org/broadinstitute/sting/playground/examples/SampleXmlMarshaller.java b/java/src/org/broadinstitute/sting/playground/examples/SampleXmlMarshaller.java index 57a43011b..0699305ea 100755 --- a/java/src/org/broadinstitute/sting/playground/examples/SampleXmlMarshaller.java +++ b/java/src/org/broadinstitute/sting/playground/examples/SampleXmlMarshaller.java @@ -2,8 +2,6 @@ package org.broadinstitute.sting.playground.examples; import org.apache.log4j.BasicConfigurator; import org.broadinstitute.sting.utils.GATKException; -import org.broadinstitute.sting.utils.StingException; -import org.broadinstitute.sting.utils.exceptions.UserError; import org.simpleframework.xml.Element; import org.simpleframework.xml.Root; import org.simpleframework.xml.Serializer; diff --git a/java/src/org/broadinstitute/sting/playground/gatk/walkers/diagnostics/MatePairLibrarySize.java b/java/src/org/broadinstitute/sting/playground/gatk/walkers/diagnostics/MatePairLibrarySize.java index 51c502faa..2df6b8b06 100755 --- a/java/src/org/broadinstitute/sting/playground/gatk/walkers/diagnostics/MatePairLibrarySize.java +++ b/java/src/org/broadinstitute/sting/playground/gatk/walkers/diagnostics/MatePairLibrarySize.java @@ -4,10 +4,9 @@ import org.broadinstitute.sting.gatk.walkers.ReadWalker; import org.broadinstitute.sting.gatk.refdata.ReadMetaDataTracker; import org.broadinstitute.sting.gatk.contexts.ReferenceContext; import org.broadinstitute.sting.commandline.Argument; -import org.broadinstitute.sting.utils.StingException; import net.sf.samtools.SAMRecord; import net.sf.samtools.SAMReadGroupRecord; -import org.broadinstitute.sting.utils.exceptions.UserError; +import org.broadinstitute.sting.utils.exceptions.UserException; import java.util.*; import java.io.File; @@ -79,7 +78,7 @@ public class MatePairLibrarySize extends ReadWalker { pw.close(); } } catch (IOException e) { - throw new UserError.CouldNotCreateOutputFile(file, e); + throw new UserException.CouldNotCreateOutputFile(file, e); } } } diff --git a/java/src/org/broadinstitute/sting/playground/gatk/walkers/hybridselection/HybSelPerformanceWalker.java b/java/src/org/broadinstitute/sting/playground/gatk/walkers/hybridselection/HybSelPerformanceWalker.java index 6fde9662a..067c30571 100755 --- a/java/src/org/broadinstitute/sting/playground/gatk/walkers/hybridselection/HybSelPerformanceWalker.java +++ b/java/src/org/broadinstitute/sting/playground/gatk/walkers/hybridselection/HybSelPerformanceWalker.java @@ -36,7 +36,6 @@ import org.broad.tribble.FeatureSource; import org.broadinstitute.sting.gatk.contexts.AlignmentContext; import org.broadinstitute.sting.gatk.contexts.ReferenceContext; import org.broadinstitute.sting.gatk.refdata.RefMetaDataTracker; -import org.broadinstitute.sting.gatk.refdata.ReferenceOrderedData; import org.broadinstitute.sting.gatk.refdata.SeekableRODIterator; import org.broadinstitute.sting.gatk.refdata.features.refseq.RefSeqCodec; import org.broadinstitute.sting.gatk.refdata.features.refseq.RefSeqFeature; @@ -47,11 +46,10 @@ import org.broadinstitute.sting.gatk.walkers.DataSource; import org.broadinstitute.sting.gatk.walkers.LocusWalker; import org.broadinstitute.sting.gatk.walkers.TreeReducible; import org.broadinstitute.sting.utils.GenomeLoc; -import org.broadinstitute.sting.utils.StingException; import org.broadinstitute.sting.utils.collections.Pair; import org.broadinstitute.sting.commandline.Argument; import org.broadinstitute.sting.commandline.Output; -import org.broadinstitute.sting.utils.exceptions.UserError; +import org.broadinstitute.sting.utils.exceptions.UserException; import java.io.File; import java.io.IOException; @@ -121,7 +119,7 @@ public class HybSelPerformanceWalker extends LocusWalker segments = new ArrayList( coord_parts.length / 3 ); @@ -136,9 +136,9 @@ public class GenomicMap implements Iterable segments = getContigMapping(r.getReferenceName()); - if ( segments == null ) throw new UserError.MalformedBam(r, "Can not remap a record: unknown custom contig name "+r.getReferenceName()); + if ( segments == null ) throw new UserException.MalformedBam(r, "Can not remap a record: unknown custom contig name "+r.getReferenceName()); // scroll the list of intervals until we find the interval that the alignment start falls into: Pair, Integer> p = seekForward(segments,customStart); @@ -316,7 +316,7 @@ public class GenomicMap implements Iterable 0 && refPos > currStop + 1 ) { // add "panning" N's w/respect to the master ref over the region between adjacent segments diff --git a/java/src/org/broadinstitute/sting/playground/utils/report/templates/GrepFormat.java b/java/src/org/broadinstitute/sting/playground/utils/report/templates/GrepFormat.java index 966cc1087..4735dfa6f 100644 --- a/java/src/org/broadinstitute/sting/playground/utils/report/templates/GrepFormat.java +++ b/java/src/org/broadinstitute/sting/playground/utils/report/templates/GrepFormat.java @@ -1,8 +1,7 @@ package org.broadinstitute.sting.playground.utils.report.templates; import org.broadinstitute.sting.playground.utils.report.utils.Node; -import org.broadinstitute.sting.utils.StingException; -import org.broadinstitute.sting.utils.exceptions.UserError; +import org.broadinstitute.sting.utils.exceptions.UserException; import java.io.File; import java.io.FileNotFoundException; @@ -32,7 +31,7 @@ public class GrepFormat implements ReportFormat { try { stream = new PrintWriter(baseFile); } catch (FileNotFoundException e) { - throw new UserError.CouldNotCreateOutputFile(baseFile, e); + throw new UserException.CouldNotCreateOutputFile(baseFile, e); } privateWrite(baseNode); } diff --git a/java/src/org/broadinstitute/sting/playground/utils/report/templates/TableBasedFormat.java b/java/src/org/broadinstitute/sting/playground/utils/report/templates/TableBasedFormat.java index e1922eae7..75cc72122 100644 --- a/java/src/org/broadinstitute/sting/playground/utils/report/templates/TableBasedFormat.java +++ b/java/src/org/broadinstitute/sting/playground/utils/report/templates/TableBasedFormat.java @@ -1,8 +1,7 @@ package org.broadinstitute.sting.playground.utils.report.templates; import org.broadinstitute.sting.playground.utils.report.utils.Node; -import org.broadinstitute.sting.utils.StingException; -import org.broadinstitute.sting.utils.exceptions.UserError; +import org.broadinstitute.sting.utils.exceptions.UserException; import java.io.*; import java.util.*; @@ -37,7 +36,7 @@ public abstract class TableBasedFormat implements ReportFormat { * @param baseNode the root node */ public void write(Writer writeLocation, Node baseNode) { - if (splitFilesByAnalysis()) throw new UserError.CommandLineError("Unable to write output report, we require a file input for multi-file formats"); + if (splitFilesByAnalysis()) throw new UserException.CommandLineException("Unable to write output report, we require a file input for multi-file formats"); // if there is only a single output file, create it stream = new PrintWriter(writeLocation); traverseAnalysisNodes(baseNode); @@ -229,7 +228,7 @@ public abstract class TableBasedFormat implements ReportFormat { try { stream = new PrintWriter(file); } catch (FileNotFoundException e) { - throw new UserError.CouldNotCreateOutputFile(file, e); + throw new UserException.CouldNotCreateOutputFile(file, e); } } } diff --git a/java/src/org/broadinstitute/sting/playground/utils/report/templates/TextTable.java b/java/src/org/broadinstitute/sting/playground/utils/report/templates/TextTable.java index b03e41b86..eb332b7b4 100644 --- a/java/src/org/broadinstitute/sting/playground/utils/report/templates/TextTable.java +++ b/java/src/org/broadinstitute/sting/playground/utils/report/templates/TextTable.java @@ -1,7 +1,6 @@ package org.broadinstitute.sting.playground.utils.report.templates; -import org.broadinstitute.sting.utils.StingException; -import org.broadinstitute.sting.utils.exceptions.UserError; +import org.broadinstitute.sting.utils.exceptions.UserException; import java.io.IOException; import java.io.Writer; @@ -104,7 +103,7 @@ class TextTable { try { writer.append("\n"); } catch (IOException e) { - throw new UserError.CouldNotCreateOutputFile(writer.toString(), "Unable to write to the Writer", e); + throw new UserException.CouldNotCreateOutputFile(writer.toString(), "Unable to write to the Writer", e); } } @@ -129,7 +128,7 @@ class TextTable { if (y != rows.size() - 1) writer.append(seperator); } catch (IOException e) { - throw new UserError.CouldNotCreateOutputFile(writer.toString(), "Unable to write to the Writer", e); + throw new UserException.CouldNotCreateOutputFile(writer.toString(), "Unable to write to the Writer", e); } } diff --git a/java/src/org/broadinstitute/sting/utils/GATKException.java b/java/src/org/broadinstitute/sting/utils/GATKException.java index 722fcdb64..883dba7ab 100644 --- a/java/src/org/broadinstitute/sting/utils/GATKException.java +++ b/java/src/org/broadinstitute/sting/utils/GATKException.java @@ -25,7 +25,7 @@ package org.broadinstitute.sting.utils; /** - * Temp class to track split from Sting exception to UserError + * Temp class to track split from Sting exception to UserException */ public class GATKException extends StingException { public GATKException(String msg) { diff --git a/java/src/org/broadinstitute/sting/utils/GenomeLocParser.java b/java/src/org/broadinstitute/sting/utils/GenomeLocParser.java index f385decec..9a7141086 100644 --- a/java/src/org/broadinstitute/sting/utils/GenomeLocParser.java +++ b/java/src/org/broadinstitute/sting/utils/GenomeLocParser.java @@ -42,7 +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.exceptions.UserException; import org.broadinstitute.sting.utils.interval.IntervalMergingRule; import org.broadinstitute.sting.utils.text.XReadLines; @@ -97,7 +97,7 @@ public class GenomeLocParser { */ public static int getContigIndex(final String contig, boolean exceptionOut) { if (contigInfo.getSequenceIndex(contig) == -1 && exceptionOut) - throw new UserError.CommandLineError(String.format("Contig %s given as location, but this contig isn't present in the Fasta sequence dictionary", contig)); + throw new UserException.CommandLineException(String.format("Contig %s given as location, but this contig isn't present in the Fasta sequence dictionary", contig)); return contigInfo.getSequenceIndex(contig); } @@ -123,7 +123,7 @@ 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"); - throw new UserError.CommandLineError("Failed to load reference dictionary"); + throw new UserException.CommandLineException("Failed to load reference dictionary"); } else if (contigInfo == null) { contigInfo = seqDict; logger.debug(String.format("Prepared reference sequence contig dictionary")); @@ -193,13 +193,13 @@ public class GenomeLocParser { stop = parsePosition(str.substring(dashIndex + 1)); } } catch(Exception e) { - throw new UserError("Failed to parse Genome Location string: " + str, e); + throw new UserException("Failed to parse Genome Location string: " + str, e); } } // is the contig valid? if (!isContigValid(contig)) - throw new UserError("Contig '" + contig + "' does not match any contig in the GATK sequence dictionary derived from the reference; are you sure you are using the correct reference fasta file?"); + throw new UserException("Contig '" + contig + "' does not match any contig in the GATK sequence dictionary derived from the reference; are you sure you are using the correct reference fasta file?"); if (stop == Integer.MAX_VALUE && hasKnownContigOrdering()) // lookup the actually stop position! @@ -371,7 +371,7 @@ public class GenomeLocParser { return ret.isEmpty() ? null : ret; } catch (IOException e2) { - throw new UserError.CouldNotReadInputFile(new File(file_name), e); + throw new UserException.CouldNotReadInputFile(new File(file_name), e); } } } diff --git a/java/src/org/broadinstitute/sting/utils/SequenceDictionaryUtils.java b/java/src/org/broadinstitute/sting/utils/SequenceDictionaryUtils.java new file mode 100755 index 000000000..1ca720e53 --- /dev/null +++ b/java/src/org/broadinstitute/sting/utils/SequenceDictionaryUtils.java @@ -0,0 +1,312 @@ +/* + * 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; + +import net.sf.samtools.SAMSequenceDictionary; +import net.sf.samtools.SAMSequenceRecord; +import org.apache.log4j.Logger; +import org.broadinstitute.sting.gatk.GenomeAnalysisEngine; +import org.broadinstitute.sting.gatk.arguments.ValidationExclusion; +import org.broadinstitute.sting.utils.exceptions.UserException; + +import java.util.*; + +/** + * Created by IntelliJ IDEA. + * User: depristo + * Date: Sep 10, 2010 + * Time: 1:56:24 PM + * + * A series of utility functions that enable the GATK to compare two sequence dictionaries -- from the reference, + * from BAMs, or from RODs -- for consistency. The system supports two basic modes: get an enum state that + * describes at a high level the consistency between two dictionaries, or a validateDictionaries that will + * blow up with a UserException if the dicts are too incompatible. + * + * Dictionaries are tested for contig name overlaps, consistency in ordering in these overlap set, and length, + * if available. Examines the Engine arguments to decided if the -U option to allow danger seq dict inconsistency + * is enabled before it blows up. + */ +public class SequenceDictionaryUtils { + public enum SequenceDictionaryCompatability { + IDENTICAL, // the dictionaries are identical + COMMON_SUBSET, // there exists a common subset of equivalent contigs + NO_COMMON_CONTIGS, // no overlap between dictionaries + UNEQUAL_COMMON_CONTIGS, // common subset has contigs that have the same name but aren't equivalent + NON_CANONICAL_HUMAN_ORDER, // human reference detected but the order of the contigs is non-standard (lexicographic, for examine) + OUT_OF_ORDER // the two dictionaries overlap but the contigs occur out of order w.r.t each other + } + + /** + * @return Returns true if the engine is in tolerant mode and we'll let through dangerous but not fatal dictionary inconsistency + */ + public static boolean allowNonFatalIncompabilities() { + return GenomeAnalysisEngine.instance != null && + ( GenomeAnalysisEngine.instance.getArguments().unsafe == ValidationExclusion.TYPE.ALLOW_SEQ_DICT_INCOMPATIBILITY || + GenomeAnalysisEngine.instance.getArguments().unsafe == ValidationExclusion.TYPE.ALL ); + } + + /** + * Testings for compatbility between dict1 and dict2. If the dictionaries are incompatible, then UserExceptions are + * thrown with detailed error messages. If the engine is in permissive mode, then logger.warnings of generated instead + * + * @param logger for warnings + * @param name1 name associated with dict1 + * @param dict1 the sequence dictionary dict1 + * @param name2 name associated with dict2 + * @param dict2 the sequence dictionary dict2 + */ + public static void validateDictionaries(Logger logger, String name1, SAMSequenceDictionary dict1, String name2, SAMSequenceDictionary dict2) { + switch ( compareDictionaries(dict1, dict2) ) { + case IDENTICAL: + return; + case COMMON_SUBSET: + return; + case NO_COMMON_CONTIGS: + throw new UserException.IncompatibleSequenceDictionaries("No overlapping contigs found", name1, dict1, name2, dict2); + case UNEQUAL_COMMON_CONTIGS: { + List x = findDisequalCommonContigs(getCommonContigsByName(dict1, dict2), dict1, dict2); + SAMSequenceRecord elt1 = x.get(0); + SAMSequenceRecord elt2 = x.get(1); + + // todo -- replace with toString when SAMSequenceRecord has a nice toString routine + UserException ex = new UserException.IncompatibleSequenceDictionaries(String.format("Found contigs with the same name but different lengths:\n contig %s = %s / %d\n contig %s = %s / %d", + name1, elt1.getSequenceName(), elt1.getSequenceLength(), + name2, elt2.getSequenceName(), elt2.getSequenceLength()), + name1, dict1, name2, dict2); + + if ( allowNonFatalIncompabilities() ) + logger.warn(ex.getMessage()); + else + throw ex; + break; + } + + case NON_CANONICAL_HUMAN_ORDER: + UserException ex = new UserException.IncompatibleSequenceDictionaries("Human genome sequence provided in non-canonical ordering. For safety's sake the GATK requires contigs in karyotypic order: 1, 2, ..., 10, 11, ..., 20, 21, 22, X, Y with M either leading or trailing these contigs", + name1, dict1, name2, dict2); + + if ( allowNonFatalIncompabilities() ) + logger.warn(ex.getMessage()); + else + throw ex; + + case OUT_OF_ORDER: + throw new UserException.IncompatibleSequenceDictionaries("Order of contigs differences, which is unsafe", name1, dict1, name2, dict2); + default: + throw new GATKException("Unexpected SequenceDictionaryComparison type"); + } + } + + /** + * Workhorse routine that takes two dictionaries and returns their compatibility. + * + * @param dict1 + * @param dict2 + * @return + */ + public static SequenceDictionaryCompatability compareDictionaries(SAMSequenceDictionary dict1, SAMSequenceDictionary dict2) { + // If there's no overlap between reads and reference, data will be bogus. Throw an exception. + Set commonContigs = getCommonContigsByName(dict1, dict2); + + if (commonContigs.size() == 0) + return SequenceDictionaryCompatability.NO_COMMON_CONTIGS; + else if ( ! commonContigsAreEquivalent( commonContigs, dict1, dict2 ) ) + return SequenceDictionaryCompatability.UNEQUAL_COMMON_CONTIGS; + else if ( nonCanonicalHumanContigOrder( commonContigs, dict1, dict2 ) ) + return SequenceDictionaryCompatability.NON_CANONICAL_HUMAN_ORDER; + else if ( ! commonContigsAreInOrder( commonContigs, dict1, dict2 ) ) + return SequenceDictionaryCompatability.OUT_OF_ORDER; + else if ( commonContigs.size() == dict1.size() && commonContigs.size() == dict2.size() ) + return SequenceDictionaryCompatability.IDENTICAL; + else { + return SequenceDictionaryCompatability.COMMON_SUBSET; + } + } + + /** + * Utility function that tests whether the commonContigs in both dicts are equivalent. Equivalece means + * that the seq records have the same length, if both are non-zero. + * + * @param commonContigs + * @param dict1 + * @param dict2 + * @return true if all of the common contigs are equivalent + */ + private static boolean commonContigsAreEquivalent(Set commonContigs, SAMSequenceDictionary dict1, SAMSequenceDictionary dict2) { + return findDisequalCommonContigs(commonContigs, dict1, dict2) == null; + } + + /** + * Returns a List(x,y) that contains two disequal sequence records among the common contigs in both dicts. Returns + * null if all common contigs are equivalent + * + * @param commonContigs + * @param dict1 + * @param dict2 + * @return + */ + private static List findDisequalCommonContigs(Set commonContigs, SAMSequenceDictionary dict1, SAMSequenceDictionary dict2) { + for ( String name : commonContigs ) { + SAMSequenceRecord elt1 = dict1.getSequence(name); + SAMSequenceRecord elt2 = dict2.getSequence(name); + if ( ! SequenceRecordsAreEquivalent(elt1, elt2) ) + return Arrays.asList(elt1,elt2); + } + + return null; + } + + /** + * Helper routine that returns two sequence records are equivalent, defined as having the same name and + * lengths, if both are non-zero + * + * @param me + * @param that + * @return + */ + private static boolean SequenceRecordsAreEquivalent(final SAMSequenceRecord me, final SAMSequenceRecord that) { + if (me == that) return true; + if (that == null) return false; + + // I don't care if the indices are difference + //if (me.getSequenceIndex() != that.getSequenceIndex()) return false; + if (me.getSequenceLength() != 0 && that.getSequenceLength() != 0 && me.getSequenceLength() != that.getSequenceLength()) + return false; + + // todo -- reenable if we want to be really strict here +// if (me.getAttribute(SAMSequenceRecord.MD5_TAG) != null && that.getAttribute(SAMSequenceRecord.MD5_TAG) != null) { +// final BigInteger thisMd5 = new BigInteger((String)me.getAttribute(SAMSequenceRecord.MD5_TAG), 16); +// final BigInteger thatMd5 = new BigInteger((String)that.getAttribute(SAMSequenceRecord.MD5_TAG), 16); +// if (!thisMd5.equals(thatMd5)) { +// return false; +// } +// } +// else { + if (me.getSequenceName() != that.getSequenceName()) + return false; // Compare using == since we intern() the Strings +// } + + return true; + } + + /** + * Placeholder for function that determines if the dicts come from the human genome that's been sorted in a + * non-canonical order. Returns just returns false (function not enabled). + * + * @param commonContigs + * @param dict1 + * @param dict2 + * @return + */ + private static boolean nonCanonicalHumanContigOrder(Set commonContigs, SAMSequenceDictionary dict1, SAMSequenceDictionary dict2) { + // todo -- implement me if we decide to detect this case + return false; + } + + /** + * Returns true if the common contigs in dict1 and dict2 are in the same order. This is accomplished by getting the + * common contigs in both dictionaries, sorting these according to their indices, and the walking through + * the sorted list to ensure that each ordered contig is equivalent + * + * @param commonContigs + * @param dict1 + * @param dict2 + * @return + */ + public static boolean commonContigsAreInOrder(Set commonContigs, SAMSequenceDictionary dict1, SAMSequenceDictionary dict2) { + List list1 = sortSequenceListByIndex(getSequencesOfName(commonContigs, dict1)); + List list2 = sortSequenceListByIndex(getSequencesOfName(commonContigs, dict2)); + + for ( int i = 0; i < list1.size(); i++ ) { + SAMSequenceRecord elt1 = list1.get(i); + SAMSequenceRecord elt2 = list2.get(i); + if ( ! elt1.getSequenceName().equals(elt2.getSequenceName()) ) + return false; + } + + return true; + } + + /** + * Gets the subset of SAMSequenceRecords in commonContigs in dict + * + * @param commonContigs + * @param dict + * @return + */ + private static List getSequencesOfName(Set commonContigs, SAMSequenceDictionary dict) { + List l = new ArrayList(commonContigs.size()); + for ( String name : commonContigs ) { + l.add(dict.getSequence(name) ); + } + + return l; + } + + // -------------------------------------------------------------------------------------------------------------- + // Utilities for comparing the order of sequence records + // -------------------------------------------------------------------------------------------------------------- + + /** + * Compares sequence records by their order + */ + private static class CompareSequenceRecordsByIndex implements Comparator { + public int compare(SAMSequenceRecord x, SAMSequenceRecord y) { + return new Integer(x.getSequenceIndex()).compareTo(y.getSequenceIndex()); + } + } + + /** + * Returns a sorted list of SAMSequenceRecords sorted by their indices. Note that the + * list is modified in place, so the returned list is == to the unsorted list. + * + * @param unsorted + * @return + */ + private static List sortSequenceListByIndex(List unsorted) { + Collections.sort(unsorted, new CompareSequenceRecordsByIndex()); + return unsorted; + } + + + /** + * Returns the set of contig names found in both dicts. + * @param dict1 + * @param dict2 + * @return + */ + public static Set getCommonContigsByName(SAMSequenceDictionary dict1, SAMSequenceDictionary dict2) { + Set intersectingSequenceNames = new HashSet(getContigNames(dict1)); + intersectingSequenceNames.retainAll(getContigNames(dict2)); + return intersectingSequenceNames; + } + + public static List getContigNames(SAMSequenceDictionary dict) { + List contigNames = new ArrayList(); + for (SAMSequenceRecord dictionaryEntry : dict.getSequences()) + contigNames.add(dictionaryEntry.getSequenceName()); + return contigNames; + } +} diff --git a/java/src/org/broadinstitute/sting/utils/bed/BedParser.java b/java/src/org/broadinstitute/sting/utils/bed/BedParser.java index 3c599b0fe..31ffdaf81 100644 --- a/java/src/org/broadinstitute/sting/utils/bed/BedParser.java +++ b/java/src/org/broadinstitute/sting/utils/bed/BedParser.java @@ -1,8 +1,6 @@ package org.broadinstitute.sting.utils.bed; -import org.broadinstitute.sting.utils.exceptions.UserError; -import org.broadinstitute.sting.utils.interval.IntervalMergingRule; -import org.broadinstitute.sting.utils.StingException; +import org.broadinstitute.sting.utils.exceptions.UserException; import org.broadinstitute.sting.utils.GenomeLoc; import org.broadinstitute.sting.utils.GenomeLocParser; @@ -34,7 +32,7 @@ public class BedParser { try { mIn = new BufferedReader(new FileReader(fl)); } catch (FileNotFoundException e) { - throw new UserError.CouldNotReadInputFile(fl, e); + throw new UserException.CouldNotReadInputFile(fl, e); } mLocations = parseLocations(); } @@ -62,7 +60,7 @@ public class BedParser { locArray.add(parseLocation(line)); } } catch (IOException e) { - throw new UserError.MalformedFile("Unable to parse line in BED file."); + throw new UserException.MalformedFile("Unable to parse line in BED file."); } return locArray; } @@ -83,7 +81,7 @@ public class BedParser { start = Integer.valueOf(parts[1]) + TO_ONE_BASED_ADDITION; stop = Integer.valueOf(parts[2]); // the ending point is an open interval } catch (Exception e) { - throw new UserError.MalformedFile("Unable to process bed file line = " + line, e); + throw new UserException.MalformedFile("Unable to process bed file line = " + line, e); } // we currently drop the rest of the bed record, which can contain names, scores, etc diff --git a/java/src/org/broadinstitute/sting/utils/exceptions/DynamicClassResolutionException.java b/java/src/org/broadinstitute/sting/utils/exceptions/DynamicClassResolutionException.java index f973c00b0..f31cf689b 100755 --- a/java/src/org/broadinstitute/sting/utils/exceptions/DynamicClassResolutionException.java +++ b/java/src/org/broadinstitute/sting/utils/exceptions/DynamicClassResolutionException.java @@ -24,13 +24,6 @@ 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.GATKException; -import org.broadinstitute.sting.utils.StingException; - -import java.io.File; import java.lang.reflect.InvocationTargetException; /** @@ -40,7 +33,7 @@ import java.lang.reflect.InvocationTargetException; * Date: Sep 3, 2010 * Time: 2:24:09 PM */ -public class DynamicClassResolutionException extends UserError { +public class DynamicClassResolutionException extends UserException { public DynamicClassResolutionException(Class c, Exception ex) { super(String.format("Could not create module %s because %s caused by exception %s", c.getSimpleName(), moreInfo(ex), ex.getMessage())); diff --git a/java/src/org/broadinstitute/sting/utils/exceptions/UserError.java b/java/src/org/broadinstitute/sting/utils/exceptions/UserException.java old mode 100644 new mode 100755 similarity index 75% rename from java/src/org/broadinstitute/sting/utils/exceptions/UserError.java rename to java/src/org/broadinstitute/sting/utils/exceptions/UserException.java index e957a1d84..4e61d7245 --- a/java/src/org/broadinstitute/sting/utils/exceptions/UserError.java +++ b/java/src/org/broadinstitute/sting/utils/exceptions/UserException.java @@ -27,11 +27,11 @@ package org.broadinstitute.sting.utils.exceptions; import net.sf.samtools.SAMFileHeader; import net.sf.samtools.SAMRecord; import net.sf.samtools.SAMSequenceDictionary; +import net.sf.samtools.SAMSequenceRecord; import org.broadinstitute.sting.utils.GATKException; -import org.broadinstitute.sting.utils.StingException; import java.io.File; -import java.lang.reflect.InvocationTargetException; +import java.util.Arrays; /** * Represents the common user errors detected by Sting / GATK @@ -42,43 +42,43 @@ import java.lang.reflect.InvocationTargetException; * Date: Sep 3, 2010 * Time: 2:24:09 PM */ -public class UserError extends GATKException { - public UserError(String msg) { super(msg); } - public UserError(String msg, Throwable e) { super(msg, e); } - private UserError(Throwable e) { super("", e); } // cannot be called, private access +public class UserException extends GATKException { + public UserException(String msg) { super(msg); } + public UserException(String msg, Throwable e) { super(msg, e); } + private UserException(Throwable e) { super("", e); } // cannot be called, private access - public static class CommandLineError extends UserError { - public CommandLineError(String message) { + public static class CommandLineException extends UserException { + public CommandLineException(String message) { super(String.format("Invalid command line: %s", message)); } } - public static class BadInput extends UserError { + public static class BadInput extends UserException { public BadInput(String message) { super(String.format("Bad input: %s", message)); } } // todo -- fix up exception cause passing - public static class MissingArgument extends CommandLineError { + public static class MissingArgument extends CommandLineException { public MissingArgument(String arg, String message) { super(String.format("Argument %s was missing: %s", arg, message)); } } - public static class BadArgumentValue extends CommandLineError { + public static class BadArgumentValue extends CommandLineException { public BadArgumentValue(String arg, String message) { super(String.format("Argument %s has a bad value: %s", arg, message)); } } - public static class BadTmpDir extends UserError { + public static class BadTmpDir extends UserException { public BadTmpDir(String message) { super(String.format("Failure working with the tmp directory %s. Override with -Djava.io.tmpdir=X on the command line to a bigger/better file system. Exact error was %s", System.getProperties().get("java.io. tmpdir"), message)); } } - public static class CouldNotReadInputFile extends UserError { + public static class CouldNotReadInputFile extends UserException { public CouldNotReadInputFile(String message, Exception e) { super(String.format("Couldn't read file because %s caused by %s", message, e.getMessage())); } @@ -97,7 +97,7 @@ public class UserError extends GATKException { } - public static class CouldNotCreateOutputFile extends UserError { + public static class CouldNotCreateOutputFile extends UserException { public CouldNotCreateOutputFile(File file, String message, Exception e) { super(String.format("Couldn't write file %s because %s with exception %s", file.getAbsolutePath(), message, e.getMessage())); } @@ -111,7 +111,7 @@ public class UserError extends GATKException { } } - public static class MalformedBam extends UserError { + public static class MalformedBam extends UserException { public MalformedBam(SAMRecord read, String message) { super(String.format("SAM/BAM file %s is malformed: %s", read.getFileSource(), message)); } @@ -123,7 +123,7 @@ public class UserError extends GATKException { } } - public static class MissortedBAM extends UserError { + public static class MissortedBAM extends UserException { public MissortedBAM(SAMFileHeader.SortOrder order, File file, SAMFileHeader header) { super(String.format("Missorted Input SAM/BAM files: %s is must be sorted in %s order but order was: %s", file, order, header.getSortOrder())); } @@ -142,13 +142,13 @@ public class UserError extends GATKException { } } - public static class MissortedFile extends UserError { + public static class MissortedFile extends UserException { public MissortedFile(File file, String message, Exception e) { super(String.format("Missorted Input file: %s is must be sorted in coordinate order. %s and got error %s", file, message, e.getMessage())); } } - public static class MalformedFile extends UserError { + public static class MalformedFile extends UserException { public MalformedFile(String message) { super(String.format("Unknown file is malformed: %s", message)); } @@ -170,27 +170,35 @@ public class UserError extends GATKException { } } - public static class CannotExecuteRScript extends UserError { + public static class CannotExecuteRScript extends UserException { public CannotExecuteRScript(String message, Exception e) { super(String.format("Unable to execute RScript command: " + message), e); } } - public static class DeprecatedArgument extends CommandLineError { + public static class DeprecatedArgument extends CommandLineException { public DeprecatedArgument(String param, String doc) { super(String.format("The parameter %s is deprecated. %s",param,doc)); } } - public static class IncompatibleSequenceDictionaries extends 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 IncompatibleSequenceDictionaries extends UserException { + public IncompatibleSequenceDictionaries(String message, String name1, SAMSequenceDictionary dict1, String name2, SAMSequenceDictionary dict2) { + super(String.format("Input files %s and %s have incompatible contigs: %s.\n %s contigs = %s\n %s contigs = %s", + name1, name2, message, name1, prettyPrintSequenceRecords(dict1), name2, prettyPrintSequenceRecords(dict2))); + } + + private static String prettyPrintSequenceRecords(SAMSequenceDictionary sequenceDictionary) { + String[] sequenceRecordNames = new String[sequenceDictionary.size()]; + int sequenceRecordIndex = 0; + for (SAMSequenceRecord sequenceRecord : sequenceDictionary.getSequences()) + sequenceRecordNames[sequenceRecordIndex++] = sequenceRecord.getSequenceName(); + return Arrays.deepToString(sequenceRecordNames); } } - public static class MissingWalker extends UserError { + public static class MissingWalker extends UserException { public MissingWalker(String walkerName, String message) { super(String.format("Walker %s is not available: %s", walkerName, message)); } diff --git a/java/src/org/broadinstitute/sting/utils/fastq/FastqReader.java b/java/src/org/broadinstitute/sting/utils/fastq/FastqReader.java index 876a08aee..5e221aca4 100755 --- a/java/src/org/broadinstitute/sting/utils/fastq/FastqReader.java +++ b/java/src/org/broadinstitute/sting/utils/fastq/FastqReader.java @@ -1,7 +1,6 @@ package org.broadinstitute.sting.utils.fastq; -import org.broadinstitute.sting.utils.StingException; -import org.broadinstitute.sting.utils.exceptions.UserError; +import org.broadinstitute.sting.utils.exceptions.UserException; import java.util.Iterator; import java.util.zip.GZIPInputStream; @@ -24,7 +23,7 @@ public class FastqReader implements Iterator, Iterable nextRecord = readNextRecord(); } catch (IOException e) { - throw new UserError.CouldNotReadInputFile(file, String.format("Error opening '%s'", fastqFile.getAbsolutePath())); + throw new UserException.CouldNotReadInputFile(file, String.format("Error opening '%s'", fastqFile.getAbsolutePath())); } } @@ -37,7 +36,7 @@ public class FastqReader implements Iterator, Iterable return new FastqRecord(seqHeader, seqLine, qualHeader, qualLine); } catch (IOException e) { - throw new UserError.CouldNotReadInputFile(fastqFile, e); + throw new UserException.CouldNotReadInputFile(fastqFile, e); } } @@ -53,7 +52,7 @@ public class FastqReader implements Iterator, Iterable nextRecord = null; } } catch (IOException e) { - throw new UserError.CouldNotReadInputFile(fastqFile, e); + throw new UserException.CouldNotReadInputFile(fastqFile, e); } return rec; @@ -67,7 +66,7 @@ public class FastqReader implements Iterator, Iterable try { in.close(); } catch (IOException e) { - throw new UserError.CouldNotReadInputFile(fastqFile, e); + throw new UserException.CouldNotReadInputFile(fastqFile, e); } } } diff --git a/java/src/org/broadinstitute/sting/utils/genotype/glf/GLFReader.java b/java/src/org/broadinstitute/sting/utils/genotype/glf/GLFReader.java index 0951afb09..7120d118b 100644 --- a/java/src/org/broadinstitute/sting/utils/genotype/glf/GLFReader.java +++ b/java/src/org/broadinstitute/sting/utils/genotype/glf/GLFReader.java @@ -4,8 +4,7 @@ import net.sf.samtools.util.BinaryCodec; import net.sf.samtools.util.BlockCompressedInputStream; import net.sf.samtools.util.RuntimeEOFException; import org.broadinstitute.sting.utils.GATKException; -import org.broadinstitute.sting.utils.StingException; -import org.broadinstitute.sting.utils.exceptions.UserError; +import org.broadinstitute.sting.utils.exceptions.UserException; import org.broadinstitute.sting.utils.genotype.LikelihoodObject; import java.io.DataInputStream; @@ -78,7 +77,7 @@ public class GLFReader implements Iterator { try { inputBinaryCodec = new BinaryCodec(new DataInputStream(new BlockCompressedInputStream(readFrom))); } catch (IOException e) { - throw new UserError.CouldNotReadInputFile(myFile, e); + throw new UserException.CouldNotReadInputFile(myFile, e); } inputBinaryCodec.setInputFileName(readFrom.getName()); @@ -86,7 +85,7 @@ public class GLFReader implements Iterator { // first verify that it's a valid GLF for (short s : glfMagic) { if (inputBinaryCodec.readUByte() != s) - throw new UserError.MalformedFile(myFile, "Verification of GLF format failed: magic string doesn't match)"); + throw new UserException.MalformedFile(myFile, "Verification of GLF format failed: magic string doesn't match)"); } // get the header string @@ -177,7 +176,7 @@ public class GLFReader implements Iterator { } //nextRecord = null; } else { - throw new UserError.MalformedFile(myFile, "Unknown GLF record type (type = " + recordType + ")"); + throw new UserException.MalformedFile(myFile, "Unknown GLF record type (type = " + recordType + ")"); } if (nextRecord != null) currentLocation = nextRecord.getPosition(); return ret; diff --git a/java/src/org/broadinstitute/sting/utils/interval/IntervalFileMergingIterator.java b/java/src/org/broadinstitute/sting/utils/interval/IntervalFileMergingIterator.java index f98f28926..ee5064289 100644 --- a/java/src/org/broadinstitute/sting/utils/interval/IntervalFileMergingIterator.java +++ b/java/src/org/broadinstitute/sting/utils/interval/IntervalFileMergingIterator.java @@ -26,8 +26,7 @@ package org.broadinstitute.sting.utils.interval; import org.broadinstitute.sting.utils.GenomeLoc; -import org.broadinstitute.sting.utils.StingException; -import org.broadinstitute.sting.utils.exceptions.UserError; +import org.broadinstitute.sting.utils.exceptions.UserException; import org.broadinstitute.sting.utils.text.XReadLines; import org.broadinstitute.sting.gatk.iterators.PushbackIterator; import org.broadinstitute.sting.gatk.refdata.utils.StringToGenomeLocIteratorAdapter; @@ -71,7 +70,7 @@ public class IntervalFileMergingIterator implements Iterator { StringToGenomeLocIteratorAdapter.FORMAT.GATK ) ) ; } } catch ( FileNotFoundException e ) { - throw new UserError.CouldNotReadInputFile(f, e); + throw new UserException.CouldNotReadInputFile(f, e); } myRule = rule; } @@ -94,7 +93,7 @@ public class IntervalFileMergingIterator implements Iterator { GenomeLoc next = it.next(); if ( next.isBefore(current)) { - throw new UserError.MalformedFile(myFile, "Interval "+next+" in the interval file is out of order."); + throw new UserException.MalformedFile(myFile, "Interval "+next+" in the interval file is out of order."); } if (current.overlapsP(next)) { diff --git a/java/src/org/broadinstitute/sting/utils/interval/IntervalUtils.java b/java/src/org/broadinstitute/sting/utils/interval/IntervalUtils.java index 90e9b7f5c..16494b56d 100644 --- a/java/src/org/broadinstitute/sting/utils/interval/IntervalUtils.java +++ b/java/src/org/broadinstitute/sting/utils/interval/IntervalUtils.java @@ -2,9 +2,8 @@ package org.broadinstitute.sting.utils.interval; import org.broadinstitute.sting.utils.GenomeLocSortedSet; import org.broadinstitute.sting.utils.GenomeLoc; -import org.broadinstitute.sting.utils.StingException; import org.broadinstitute.sting.utils.GenomeLocParser; -import org.broadinstitute.sting.utils.exceptions.UserError; +import org.broadinstitute.sting.utils.exceptions.UserException; import java.util.LinkedList; import java.util.List; @@ -40,7 +39,7 @@ public class IntervalUtils { if (argument.equals("all")) { if (argList.size() != 1) { // throw error if '-L all' is not only interval - potentially conflicting commands - throw new UserError.CommandLineError(String.format("Conflicting arguments: Intervals given along with \"-L all\"")); + throw new UserException.CommandLineException(String.format("Conflicting arguments: Intervals given along with \"-L all\"")); } return null; } @@ -54,7 +53,7 @@ public class IntervalUtils { rawIntervals.addAll(GenomeLocParser.intervalFileToList(fileOrInterval)); } catch (Exception e) { - throw new UserError.MalformedFile(fileOrInterval, "Interval file could not be parsed in either format.", e); + throw new UserException.MalformedFile(fileOrInterval, "Interval file could not be parsed in either format.", e); } } @@ -146,11 +145,11 @@ public class IntervalUtils { if (file.exists()) return true; else - throw new UserError.CouldNotReadInputFile(file, "The interval file does not exist."); + throw new UserException.CouldNotReadInputFile(file, "The interval file does not exist."); } if(file.exists()) - throw new UserError.CouldNotReadInputFile(file, String.format("The interval file %s does not have one of " + + throw new UserException.CouldNotReadInputFile(file, String.format("The interval file %s does not have one of " + "the supported extensions (.bed, .list, .picard, .interval_list, or .intervals). " + "Please rename your file with the appropriate extension. If %s is NOT supposed to be a file, " + "please move or rename the file at location %s", str, str, file.getAbsolutePath())); diff --git a/java/src/org/broadinstitute/sting/utils/sam/GATKSAMRecord.java b/java/src/org/broadinstitute/sting/utils/sam/GATKSAMRecord.java index 063f36860..fc58ea7af 100755 --- a/java/src/org/broadinstitute/sting/utils/sam/GATKSAMRecord.java +++ b/java/src/org/broadinstitute/sting/utils/sam/GATKSAMRecord.java @@ -3,9 +3,8 @@ package org.broadinstitute.sting.utils.sam; import java.util.*; import net.sf.samtools.*; -import org.broadinstitute.sting.utils.StingException; import org.broadinstitute.sting.gatk.GenomeAnalysisEngine; -import org.broadinstitute.sting.utils.exceptions.UserError; +import org.broadinstitute.sting.utils.exceptions.UserException; /** * @author ebanks @@ -65,7 +64,7 @@ public class GATKSAMRecord extends SAMRecord { // sanity check that the lengths of the base and quality strings are equal if ( getBaseQualities().length != getReadLength() ) - throw new UserError.MalformedBam(this, String.format("Error: the number of base qualities does not match the number of bases in %s (and the GATK does not currently support '*' for the quals)", mRecord.getReadName())); + throw new UserException.MalformedBam(this, String.format("Error: the number of base qualities does not match the number of bases in %s (and the GATK does not currently support '*' for the quals)", mRecord.getReadName())); } /////////////////////////////////////////////////////////////////////////////// diff --git a/java/src/org/broadinstitute/sting/utils/wiggle/WiggleWriter.java b/java/src/org/broadinstitute/sting/utils/wiggle/WiggleWriter.java index 7cd892d4e..693fe80d5 100755 --- a/java/src/org/broadinstitute/sting/utils/wiggle/WiggleWriter.java +++ b/java/src/org/broadinstitute/sting/utils/wiggle/WiggleWriter.java @@ -2,8 +2,7 @@ package org.broadinstitute.sting.utils.wiggle; 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.exceptions.UserException; import java.io.*; @@ -50,7 +49,7 @@ public class WiggleWriter { try { outputStream = new FileOutputStream(outputFile); } catch ( FileNotFoundException e ) { - throw new UserError.CouldNotCreateOutputFile(outputFile, "Unable to create a wiggle file ", e); + throw new UserException.CouldNotCreateOutputFile(outputFile, "Unable to create a wiggle file ", e); } wWriter = new BufferedWriter(new OutputStreamWriter(outputStream)); @@ -87,7 +86,7 @@ public class WiggleWriter { w.flush(); // flush required so writing to output stream will work } catch (IOException e) { - throw new UserError.CouldNotCreateOutputFile(myFile, String.format("Error writing the wiggle line %s", s), e); + throw new UserException.CouldNotCreateOutputFile(myFile, String.format("Error writing the wiggle line %s", s), e); } } } diff --git a/java/test/org/broadinstitute/sting/BaseTest.java b/java/test/org/broadinstitute/sting/BaseTest.java index d31c89dbe..a613e0e24 100755 --- a/java/test/org/broadinstitute/sting/BaseTest.java +++ b/java/test/org/broadinstitute/sting/BaseTest.java @@ -2,6 +2,7 @@ package org.broadinstitute.sting; import org.apache.log4j.*; import org.apache.log4j.spi.LoggingEvent; +import org.broadinstitute.sting.utils.GATKException; import org.broadinstitute.sting.utils.StingException; import org.junit.*; @@ -45,6 +46,7 @@ public abstract class BaseTest { protected static String hg18Reference = "/seq/references/Homo_sapiens_assembly18/v0/Homo_sapiens_assembly18.fasta"; protected static String hg19Reference = "/seq/references/Homo_sapiens_assembly19/v0/Homo_sapiens_assembly19.fasta"; protected static String b36KGReference = "/humgen/1kg/reference/human_b36_both.fasta"; + protected static String b37KGReference = "/humgen/1kg/reference/human_g1k_v37.fasta"; protected static String GATKDataLocation = "/humgen/gsa-hpprojects/GATK/data/"; protected static String validationDataLocation = GATKDataLocation + "Validation_Data/"; protected static String evaluationDataLocation = GATKDataLocation + "Evaluation_Data/"; @@ -140,13 +142,13 @@ public abstract class BaseTest { try { digest = MessageDigest.getInstance("MD5"); } catch (NoSuchAlgorithmException e) { - throw new StingException("Unable to find MD5 digest"); + throw new GATKException("Unable to find MD5 digest"); } InputStream is; try { is = new FileInputStream(file); } catch (FileNotFoundException e) { - throw new StingException("Unable to open file " + file); + throw new GATKException("Unable to open file " + file); } byte[] buffer = new byte[8192]; int read; @@ -160,14 +162,14 @@ public abstract class BaseTest { } catch (IOException e) { - throw new StingException("Unable to process file for MD5", e); + throw new GATKException("Unable to process file for MD5", e); } finally { try { is.close(); } catch (IOException e) { - throw new StingException("Unable to close input stream for MD5 calculation", e); + throw new GATKException("Unable to close input stream for MD5 calculation", e); } } } diff --git a/java/test/org/broadinstitute/sting/WalkerTest.java b/java/test/org/broadinstitute/sting/WalkerTest.java index 36224c9b3..d0d0582b5 100755 --- a/java/test/org/broadinstitute/sting/WalkerTest.java +++ b/java/test/org/broadinstitute/sting/WalkerTest.java @@ -28,6 +28,7 @@ package org.broadinstitute.sting; import junit.framework.Assert; import org.broadinstitute.sting.gatk.CommandLineExecutable; import org.broadinstitute.sting.gatk.CommandLineGATK; +import org.broadinstitute.sting.utils.GATKException; import org.broadinstitute.sting.utils.collections.Pair; import org.broadinstitute.sting.utils.StingException; import org.broadinstitute.sting.utils.Utils; @@ -62,7 +63,7 @@ public class WalkerTest extends BaseTest { if ( ! dir.exists() ) { System.out.printf("##### Creating MD5 db %s%n", MD5_FILE_DB_SUBDIR); if ( ! dir.mkdir() ) { - throw new StingException("Infrastructure failure: failed to create md5 directory " + MD5_FILE_DB_SUBDIR); + throw new GATKException("Infrastructure failure: failed to create md5 directory " + MD5_FILE_DB_SUBDIR); } } } @@ -81,7 +82,7 @@ public class WalkerTest extends BaseTest { try { FileUtils.copyFile(resultsFile, dbFile); } catch ( IOException e ) { - throw new StingException(e.getMessage()); + throw new GATKException(e.getMessage()); } } else { System.out.printf("##### MD5 file is up to date: %s%n", dbFile.getPath()); @@ -185,6 +186,7 @@ public class WalkerTest extends BaseTest { int nOutputFiles = -1; List md5s = null; List exts = null; + Class expectedException = null; protected Map auxillaryFiles = new HashMap(); @@ -201,6 +203,21 @@ public class WalkerTest extends BaseTest { this.exts = exts; } + public WalkerTestSpec(String args, int nOutputFiles, Class expectedException) { + this.args = args; + this.nOutputFiles = nOutputFiles; + this.expectedException = expectedException; + } + + public boolean expectsException() { + return expectedException != null; + } + + public Class getExpectedException() { + if ( ! expectsException() ) throw new GATKException("Tried to get expection for walker test that doesn't expect one"); + return expectedException; + } + public void addAuxFile(String expectededMD5sum, File outputfile) { auxillaryFiles.put(expectededMD5sum, outputfile); } @@ -223,16 +240,20 @@ public class WalkerTest extends BaseTest { final String args = String.format(spec.args, tmpFiles.toArray()); System.out.println(Utils.dupString('-', 80)); - List md5s = new LinkedList(); - md5s.addAll(spec.md5s); + if ( spec.expectsException() ) { + // this branch handles the case were we are testing that a walker will fail as expected + return executeTest(name, null, tmpFiles, args, spec.getExpectedException()); + } else { + List md5s = new LinkedList(); + md5s.addAll(spec.md5s); - // check to see if they included any auxillary files, if so add them to the list - for (String md5 : spec.auxillaryFiles.keySet()) { - md5s.add(md5); - tmpFiles.add(spec.auxillaryFiles.get(md5)); + // check to see if they included any auxillary files, if so add them to the list + for (String md5 : spec.auxillaryFiles.keySet()) { + md5s.add(md5); + tmpFiles.add(spec.auxillaryFiles.get(md5)); + } + return executeTest(name, md5s, tmpFiles, args, null); } - - return executeTest(name, md5s, tmpFiles, args); } public File createTempFile(String name, String extension) { @@ -241,7 +262,7 @@ public class WalkerTest extends BaseTest { fl.deleteOnExit(); return fl; } catch (IOException ex) { - throw new StingException("Cannot create temp file: " + ex.getMessage(), ex); + throw new GATKException("Cannot create temp file: " + ex.getMessage(), ex); } } @@ -253,7 +274,7 @@ public class WalkerTest extends BaseTest { * @param args the argument list * @return a pair of file and string lists */ - private Pair, List> executeTest(String name, List md5s, List tmpFiles, String args) { + private Pair, List> executeTest(String name, List md5s, List tmpFiles, String args, Class expectedException) { CommandLineGATK instance = new CommandLineGATK(); String[] command; @@ -271,7 +292,6 @@ public class WalkerTest extends BaseTest { cmd2[command.length + 1] = this.outputFileLocation.getAbsolutePath(); command = cmd2; } - System.out.println(String.format("Executing test %s with GATK arguments: %s", name, Utils.join(" ",command))); // add the logging level to each of the integration test commands String[] cmd2 = Arrays.copyOf(command, command.length + 4); @@ -281,20 +301,47 @@ public class WalkerTest extends BaseTest { cmd2[command.length+3] = ENABLE_REPORTING ? "STANDARD" : "NO_ET"; // run the executable + boolean gotAnException = false; try { + System.out.println(String.format("Executing test %s with GATK arguments: %s", name, Utils.join(" ",cmd2))); CommandLineExecutable.start(instance, cmd2); } catch (Exception e) { - throw new RuntimeException(e); + gotAnException = true; + if ( expectedException != null ) { + // we expect an exception + System.out.println(String.format("Wanted exception %s, saw %s", expectedException, e.getClass())); + if ( expectedException.isInstance(e) ) { + // it's the type we expected + System.out.println(String.format(" => %s PASSED", name)); + } else { + e.printStackTrace(); + Assert.fail(String.format("Test %s expected exception %s but got %s instead", + name, expectedException, e.getClass())); + } + } else { + // we didn't expect an exception but we got one :-( + throw new RuntimeException(e); + } } // catch failures from the integration test - if (CommandLineExecutable.result != 0) { - throw new RuntimeException("Error running the GATK with arguments: " + args); + if ( expectedException != null ) { + if ( ! gotAnException ) + // we expected an exception but didn't see it + Assert.fail(String.format("Test %s expected exception %s but none was thrown", name, expectedException.toString())); + return null; + } else { + if ( CommandLineExecutable.result != 0) { + throw new RuntimeException("Error running the GATK with arguments: " + args); + } + + // clean up some memory + instance = null; + cmd2 = null; + + // we need to check MD5s + return new Pair, List>(tmpFiles, assertMatchingMD5s(name, tmpFiles, md5s)); } - // clean up some memory - instance = null; - cmd2 = null; - return new Pair, List>(tmpFiles, assertMatchingMD5s(name, tmpFiles, md5s)); } private static String[] escapeExpressions(String args, String delimiter) { diff --git a/java/test/org/broadinstitute/sting/commandline/ParsingEngineUnitTest.java b/java/test/org/broadinstitute/sting/commandline/ParsingEngineUnitTest.java index e5dad416b..c97761897 100755 --- a/java/test/org/broadinstitute/sting/commandline/ParsingEngineUnitTest.java +++ b/java/test/org/broadinstitute/sting/commandline/ParsingEngineUnitTest.java @@ -26,6 +26,7 @@ package org.broadinstitute.sting.commandline; import org.broadinstitute.sting.BaseTest; +import org.broadinstitute.sting.utils.GATKException; import org.broadinstitute.sting.utils.StingException; import org.junit.Test; import org.junit.Before; @@ -355,7 +356,7 @@ public class ParsingEngineUnitTest extends BaseTest { parsingEngine.validate(); } - @Test(expected=StingException.class) + @Test(expected= GATKException.class) public void duplicateLongNameTest() { parsingEngine.addArgumentSource( DuplicateLongNameProvider.class ); } @@ -368,7 +369,7 @@ public class ParsingEngineUnitTest extends BaseTest { public Integer bar; } - @Test(expected=StingException.class) + @Test(expected=GATKException.class) public void duplicateShortNameTest() { parsingEngine.addArgumentSource( DuplicateShortNameProvider.class ); } @@ -593,7 +594,7 @@ public class ParsingEngineUnitTest extends BaseTest { RequiredArgProvider rap = new RequiredArgProvider(); } - @Test(expected=StingException.class) + @Test(expected=GATKException.class) public void multipleArgumentCollectionTest() { parsingEngine.addArgumentSource( MultipleArgumentCollectionProvider.class ); } diff --git a/java/test/org/broadinstitute/sting/gatk/datasources/providers/ShardDataProviderUnitTest.java b/java/test/org/broadinstitute/sting/gatk/datasources/providers/ShardDataProviderUnitTest.java index fb79ff2b3..c4aef7351 100755 --- a/java/test/org/broadinstitute/sting/gatk/datasources/providers/ShardDataProviderUnitTest.java +++ b/java/test/org/broadinstitute/sting/gatk/datasources/providers/ShardDataProviderUnitTest.java @@ -1,5 +1,6 @@ package org.broadinstitute.sting.gatk.datasources.providers; +import org.broadinstitute.sting.utils.GATKException; import org.junit.Before; import org.junit.Assert; import org.junit.Test; @@ -66,7 +67,7 @@ public class ShardDataProviderUnitTest extends BaseTest { /** * Try adding a view which conflicts with some other view that's already been registered. */ - @Test(expected=StingException.class) + @Test(expected= GATKException.class) public void testAddViewWithExistingConflict() { View initial = new ConflictingTestView( provider ); View conflictsWithInitial = new TestView( provider ); @@ -75,7 +76,7 @@ public class ShardDataProviderUnitTest extends BaseTest { /** * Try adding a view which has a conflict with a previously registered view. */ - @Test(expected=StingException.class) + @Test(expected=GATKException.class) public void testAddViewWithNewConflict() { View conflictsWithInitial = new TestView( provider ); View initial = new ConflictingTestView( provider ); diff --git a/java/test/org/broadinstitute/sting/gatk/filters/ReadGroupBlackListFilterUnitTest.java b/java/test/org/broadinstitute/sting/gatk/filters/ReadGroupBlackListFilterUnitTest.java index 1ddaeec63..3982e3542 100644 --- a/java/test/org/broadinstitute/sting/gatk/filters/ReadGroupBlackListFilterUnitTest.java +++ b/java/test/org/broadinstitute/sting/gatk/filters/ReadGroupBlackListFilterUnitTest.java @@ -1,6 +1,7 @@ package org.broadinstitute.sting.gatk.filters; import org.broadinstitute.sting.BaseTest; +import org.broadinstitute.sting.utils.GATKException; import org.broadinstitute.sting.utils.sam.ArtificialSAMUtils; import org.broadinstitute.sting.utils.GenomeLocParser; import org.broadinstitute.sting.utils.StingException; @@ -46,18 +47,18 @@ public class ReadGroupBlackListFilterUnitTest extends BaseTest { GenomeLocParser.setupRefContigOrdering(header.getSequenceDictionary()); } - @Test(expected = StingException.class) + @Test(expected = GATKException.class) public void testBadFilter() { List badFilters = Collections.singletonList("bad"); new ReadGroupBlackListFilter(badFilters); } - @Test(expected = StingException.class) + @Test(expected = GATKException.class) public void testBadFilterTag() { List badFilters = Collections.singletonList("bad:filter"); new ReadGroupBlackListFilter(badFilters); } - @Test(expected = StingException.class) + @Test(expected = GATKException.class) public void testBadFilterFile() { List badFilters = Collections.singletonList("/foo/bar/rgbl.txt"); new ReadGroupBlackListFilter(badFilters); diff --git a/java/test/org/broadinstitute/sting/gatk/refdata/tracks/RMDTrackManagerUnitTest.java b/java/test/org/broadinstitute/sting/gatk/refdata/tracks/RMDTrackManagerUnitTest.java index 72fddea15..9b327f7a1 100644 --- a/java/test/org/broadinstitute/sting/gatk/refdata/tracks/RMDTrackManagerUnitTest.java +++ b/java/test/org/broadinstitute/sting/gatk/refdata/tracks/RMDTrackManagerUnitTest.java @@ -27,6 +27,7 @@ import net.sf.samtools.SAMSequenceRecord; import net.sf.picard.reference.IndexedFastaSequenceFile; import org.broadinstitute.sting.BaseTest; import org.broadinstitute.sting.gatk.refdata.utils.GATKFeature; +import org.broadinstitute.sting.utils.GATKException; import org.broadinstitute.sting.utils.GenomeLocParser; import org.broadinstitute.sting.utils.StingException; import org.junit.Assert; @@ -72,7 +73,7 @@ public class RMDTrackManagerUnitTest extends BaseTest { try { fIter = ((TribbleTrack) t).query("1", 1, 5000); } catch (IOException e) { - throw new StingException("blah I/O exception"); + throw new GATKException("blah I/O exception"); } while (fIter.hasNext()) { fIter.next(); @@ -123,7 +124,7 @@ public class RMDTrackManagerUnitTest extends BaseTest { try { fIter = ((TribbleTrack) t).query("1", x, x + intervalSize); } catch (IOException e) { - throw new StingException("blah I/O exception"); + throw new GATKException("blah I/O exception"); } while (fIter.hasNext()) { fIter.next(); diff --git a/java/test/org/broadinstitute/sting/gatk/walkers/qc/DictionaryConsistencyIntegrationTest.java b/java/test/org/broadinstitute/sting/gatk/walkers/qc/DictionaryConsistencyIntegrationTest.java new file mode 100755 index 000000000..e3a94bc6c --- /dev/null +++ b/java/test/org/broadinstitute/sting/gatk/walkers/qc/DictionaryConsistencyIntegrationTest.java @@ -0,0 +1,79 @@ +/* + * 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.gatk.walkers.qc; + +import org.broadinstitute.sting.BaseTest; +import org.broadinstitute.sting.WalkerTest; +import org.broadinstitute.sting.utils.exceptions.UserException; +import org.junit.Test; + +/** + * + */ +public class DictionaryConsistencyIntegrationTest extends WalkerTest { + private static final String callsHG18 = BaseTest.validationDataLocation + "HiSeq.WGS.cleaned.ug.snpfiltered.indelfiltered.optimized.cut.vcf"; + private static final String callsB36 = BaseTest.validationDataLocation + "lowpass.N3.chr1.raw.vcf"; + private static final String lexHG18 = BaseTest.validationDataLocation + "lexFasta/lex.hg18.fasta"; + private static final String b36BAM = BaseTest.validationDataLocation + "NA12878.1kg.p2.chr1_10mb_11_mb.allTechs.bam"; + private static final String hg18BAM = BaseTest.validationDataLocation + "NA12878.WEx.downsampled20x.bam"; + + // testing hg18 calls + @Test public void fail1() { executeTest("b36xhg18", testVCF(b36KGReference, callsHG18)); } + @Test public void fail2() { executeTest("b37xhg18", testVCF(b37KGReference, callsHG18)); } + @Test public void fail3() { executeTest("hg19xhg18", testVCF(hg19Reference, callsHG18)); } + @Test public void fail4() { executeTest("hg18lex-v-hg18", testVCF(lexHG18, callsHG18)); } + + // testing b36 calls + @Test public void fail5() { executeTest("b36xb36", testVCF(hg18Reference, callsB36)); } + // todo -- Matt I get really weird behavior when I enable these two tests. They generate + // command line errors but I don't understand how. +// @Test public void fail6() { executeTest("b37xb36", testVCF(b37KGReference, callsB36)); } +// @Test public void fail7() { executeTest("hg19xb36", testVCF(hg19Reference, callsB36)); } + @Test public void fail8() { executeTest("hg18lex-v-b36", testVCF(lexHG18, callsB36)); } + + private WalkerTest.WalkerTestSpec testVCF(String ref, String vcf) { + return new WalkerTest.WalkerTestSpec("-T VariantsToTable -M 10 -B:two,vcf " + + vcf + " -F POS,CHROM -R " + + ref + " -o %s", + 1, UserException.IncompatibleSequenceDictionaries.class); + + } + + @Test public void failBAM1() { executeTest("b36bam-v-b37", testBAM(b37KGReference, b36BAM)); } + @Test public void failBAM2() { executeTest("b36bam-v-hg18", testBAM(hg18Reference, b36BAM)); } + @Test public void failBAM3() { executeTest("b36bam-v-hg19", testBAM(hg19Reference, b36BAM)); } + @Test public void failBAM4() { executeTest("b36bam-v-lexhg18", testBAM(lexHG18, b36BAM)); } + + @Test public void failBAM5() { executeTest("hg18bam-v-b36", testBAM(b36KGReference, hg18BAM)); } + @Test public void failBAM6() { executeTest("hg18bam-v-b37", testBAM(b37KGReference, hg18BAM)); } + @Test public void failBAM7() { executeTest("hg18bam-v-hg19", testBAM(hg19Reference, hg18BAM)); } + @Test public void failBAM8() { executeTest("hg18bam-v-lexhg18", testBAM(lexHG18, hg18BAM)); } + + private WalkerTest.WalkerTestSpec testBAM(String ref, String bam) { + return new WalkerTest.WalkerTestSpec("-T UnifiedGenotyper -I " + bam + " -R " + ref + " -L 1:10,000,000-11,000,000 -o %s", + 1, UserException.IncompatibleSequenceDictionaries.class); + + } +} diff --git a/java/test/org/broadinstitute/sting/gatk/walkers/qc/ValidatingPileupIntegrationTest.java b/java/test/org/broadinstitute/sting/gatk/walkers/qc/ValidatingPileupIntegrationTest.java index 48413d941..34a6fb06b 100644 --- a/java/test/org/broadinstitute/sting/gatk/walkers/qc/ValidatingPileupIntegrationTest.java +++ b/java/test/org/broadinstitute/sting/gatk/walkers/qc/ValidatingPileupIntegrationTest.java @@ -19,7 +19,7 @@ public class ValidatingPileupIntegrationTest extends WalkerTest { " -I " + validationDataLocation + "MV1994.selected.bam" + " -R " + validationDataLocation + "Escherichia_coli_K12_MG1655.fasta" + " -B:pileup,SAMPileup "+ validationDataLocation + "MV1994.selected.pileup" + - " -S SILENT -nt 8",0, Collections.emptyList()); + " -S SILENT -nt 8 -U ALLOW_SEQ_DICT_INCOMPATIBILITY",0, Collections.emptyList()); executeTest("testEcoliThreaded",spec); } } diff --git a/java/test/org/broadinstitute/sting/oneoffprojects/walkers/ValidateRODForReadsIntegrationTest.java b/java/test/org/broadinstitute/sting/oneoffprojects/walkers/ValidateRODForReadsIntegrationTest.java index 8e1438cbf..eaa0570c5 100644 --- a/java/test/org/broadinstitute/sting/oneoffprojects/walkers/ValidateRODForReadsIntegrationTest.java +++ b/java/test/org/broadinstitute/sting/oneoffprojects/walkers/ValidateRODForReadsIntegrationTest.java @@ -14,7 +14,7 @@ public class ValidateRODForReadsIntegrationTest extends WalkerTest { private final String dbSNPFile = GATKDataLocation + "dbsnp_129_hg18.rod"; public static String baseTestString1KG() { - return "-T ValidateRODForReads -o %s -R testdata/exampleFASTA.fasta -I testdata/exampleBAM.bam"; + return "-T ValidateRODForReads -o %s -R testdata/exampleFASTA.fasta -U ALLOW_SEQ_DICT_INCOMPATIBILITY -I testdata/exampleBAM.bam"; } diff --git a/java/test/org/broadinstitute/sting/utils/GenomeLocParserUnitTest.java b/java/test/org/broadinstitute/sting/utils/GenomeLocParserUnitTest.java index 595ebb655..42d5b3eac 100644 --- a/java/test/org/broadinstitute/sting/utils/GenomeLocParserUnitTest.java +++ b/java/test/org/broadinstitute/sting/utils/GenomeLocParserUnitTest.java @@ -19,7 +19,7 @@ import org.junit.Test; * Test out the functionality of the new genome loc parser */ public class GenomeLocParserUnitTest extends BaseTest { - @Test(expected = StingException.class) + @Test(expected = GATKException.class) public void testUnsetupException() { GenomeLocParser.contigInfo = null; GenomeLocParser.createGenomeLoc(0, 0, 0); @@ -65,7 +65,7 @@ public class GenomeLocParserUnitTest extends BaseTest { assertEquals("chr1".compareTo(GenomeLocParser.getContigInfo("chr1").getSequenceName()), 0); // should be in the reference } - @Test(expected = StingException.class) + @Test(expected = GATKException.class) public void testParseBadString() { GenomeLocParser.parseGenomeLoc("Bad:0-1"); } @@ -143,7 +143,7 @@ public class GenomeLocParserUnitTest extends BaseTest { assertEquals(1, loc.getStart()); } - @Test(expected = StingException.class) + @Test(expected = GATKException.class) public void testGenomeLocParseOnlyBadChrome() { GenomeLoc loc = GenomeLocParser.parseGenomeLoc("chr12"); assertEquals(0, loc.getContigIndex()); @@ -151,7 +151,7 @@ public class GenomeLocParserUnitTest extends BaseTest { assertEquals(1, loc.getStart()); } - @Test(expected = StingException.class) + @Test(expected = GATKException.class) public void testGenomeLocBad() { GenomeLoc loc = GenomeLocParser.parseGenomeLoc("chr1:1-"); assertEquals(0, loc.getContigIndex()); @@ -159,7 +159,7 @@ public class GenomeLocParserUnitTest extends BaseTest { assertEquals(1, loc.getStart()); } - @Test(expected = StingException.class) + @Test(expected = GATKException.class) public void testGenomeLocBad2() { GenomeLoc loc = GenomeLocParser.parseGenomeLoc("chr1:1-500-0"); assertEquals(0, loc.getContigIndex()); @@ -167,7 +167,7 @@ public class GenomeLocParserUnitTest extends BaseTest { assertEquals(1, loc.getStart()); } - @Test(expected = StingException.class) + @Test(expected = GATKException.class) public void testGenomeLocBad3() { GenomeLoc loc = GenomeLocParser.parseGenomeLoc("chr1:1--0"); assertEquals(0, loc.getContigIndex()); diff --git a/java/test/org/broadinstitute/sting/utils/GenomeLocSortedSetUnitTest.java b/java/test/org/broadinstitute/sting/utils/GenomeLocSortedSetUnitTest.java index f28d3f350..80468c720 100755 --- a/java/test/org/broadinstitute/sting/utils/GenomeLocSortedSetUnitTest.java +++ b/java/test/org/broadinstitute/sting/utils/GenomeLocSortedSetUnitTest.java @@ -80,7 +80,7 @@ public class GenomeLocSortedSetUnitTest extends BaseTest { } - @Test(expected = StingException.class) + @Test(expected = GATKException.class) public void testAddDupplicate() { assertTrue(mSortedSet.size() == 0); GenomeLoc g = GenomeLocParser.createGenomeLoc(1, 0, 0); diff --git a/java/test/org/broadinstitute/sting/utils/PathUtilsUnitTest.java b/java/test/org/broadinstitute/sting/utils/PathUtilsUnitTest.java index ca9e8d486..478fed7da 100755 --- a/java/test/org/broadinstitute/sting/utils/PathUtilsUnitTest.java +++ b/java/test/org/broadinstitute/sting/utils/PathUtilsUnitTest.java @@ -27,7 +27,7 @@ public class PathUtilsUnitTest extends BaseTest { try { PathUtils.refreshVolume(new File(filename)); - } catch (StingException e) { + } catch (GATKException e) { result = false; } diff --git a/java/test/org/broadinstitute/sting/utils/genotype/vcf/VCFWriterUnitTest.java b/java/test/org/broadinstitute/sting/utils/genotype/vcf/VCFWriterUnitTest.java index de18053ef..f3477139e 100644 --- a/java/test/org/broadinstitute/sting/utils/genotype/vcf/VCFWriterUnitTest.java +++ b/java/test/org/broadinstitute/sting/utils/genotype/vcf/VCFWriterUnitTest.java @@ -7,6 +7,7 @@ import org.broad.tribble.util.variantcontext.VariantContext; import org.broad.tribble.vcf.*; import org.broadinstitute.sting.BaseTest; import org.broadinstitute.sting.gatk.refdata.tracks.builders.TribbleRMDTrackBuilder; +import org.broadinstitute.sting.utils.GATKException; import org.broadinstitute.sting.utils.GenomeLoc; import org.broadinstitute.sting.utils.StingException; import org.broadinstitute.sting.utils.GenomeLocParser; @@ -58,7 +59,7 @@ public class VCFWriterUnitTest extends BaseTest { headerFromFile = (VCFHeader)reader.readHeader(lineReader); } catch (FileNotFoundException e ) { - throw new StingException(e.getMessage()); + throw new GATKException(e.getMessage()); } int counter = 0; @@ -80,7 +81,7 @@ public class VCFWriterUnitTest extends BaseTest { fakeVCFFile.delete(); } catch (IOException e ) { - throw new StingException(e.getMessage()); + throw new GATKException(e.getMessage()); } } diff --git a/java/test/org/broadinstitute/sting/utils/interval/IntervalFileMergingIteratorUnitTest.java b/java/test/org/broadinstitute/sting/utils/interval/IntervalFileMergingIteratorUnitTest.java index 5631b2b5a..b915e9222 100644 --- a/java/test/org/broadinstitute/sting/utils/interval/IntervalFileMergingIteratorUnitTest.java +++ b/java/test/org/broadinstitute/sting/utils/interval/IntervalFileMergingIteratorUnitTest.java @@ -25,6 +25,7 @@ package org.broadinstitute.sting.utils.interval; +import org.broadinstitute.sting.utils.GATKException; import org.junit.BeforeClass; import org.junit.Test; import org.junit.Assert; @@ -102,7 +103,7 @@ public class IntervalFileMergingIteratorUnitTest extends BaseTest { GenomeLoc l_expected = check_it.next(); // System.out.println("int: "+l+" expected: "+l_expected) ; } - } catch ( StingException e) { + } catch ( GATKException e) { Assert.assertEquals( e.getMessage(), "Interval chr5:7414 in the interval file is out of order."); } }