From 8507cd7440f3aa58b9f47bbc8a2d434eeb5de9d3 Mon Sep 17 00:00:00 2001 From: Mark DePristo Date: Tue, 10 Apr 2012 07:22:43 -0400 Subject: [PATCH 1/2] Throw UserException for bad dict / chain files --- .../sting/gatk/walkers/variantutils/LiftoverVariants.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/public/java/src/org/broadinstitute/sting/gatk/walkers/variantutils/LiftoverVariants.java b/public/java/src/org/broadinstitute/sting/gatk/walkers/variantutils/LiftoverVariants.java index 50fafa202..43aa273c6 100755 --- a/public/java/src/org/broadinstitute/sting/gatk/walkers/variantutils/LiftoverVariants.java +++ b/public/java/src/org/broadinstitute/sting/gatk/walkers/variantutils/LiftoverVariants.java @@ -24,7 +24,6 @@ package org.broadinstitute.sting.gatk.walkers.variantutils; -import net.sf.picard.PicardException; import net.sf.picard.liftover.LiftOver; import net.sf.picard.util.Interval; import net.sf.samtools.SAMFileHeader; @@ -73,7 +72,7 @@ public class LiftoverVariants extends RodWalker { public void initialize() { try { liftOver = new LiftOver(CHAIN); - } catch (PicardException e) { + } catch (RuntimeException e) { throw new UserException.BadInput("there is a problem with the chain file you are using: " + e.getMessage()); } @@ -82,7 +81,7 @@ public class LiftoverVariants extends RodWalker { try { final SAMFileHeader toHeader = new SAMFileReader(NEW_SEQ_DICT).getFileHeader(); liftOver.validateToSequences(toHeader.getSequenceDictionary()); - } catch (PicardException e) { + } catch (RuntimeException e) { throw new UserException.BadInput("the chain file you are using is not compatible with the reference you are trying to lift over to; please use the appropriate chain file for the given reference"); } From 6885e2d065d32dfa1dc5786560b83aeed6982969 Mon Sep 17 00:00:00 2001 From: Mark DePristo Date: Tue, 10 Apr 2012 07:37:42 -0400 Subject: [PATCH 2/2] UserException fixes for GATK_logs recent errors -- SamFileReader.java:525 -- BlockCompressedInputStream:376 These were both instances were we weren't catching and rethrowing picard exceptions as UserExceptions. --- .../gatk/datasources/reads/SAMDataSource.java | 31 +++++++++---------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/public/java/src/org/broadinstitute/sting/gatk/datasources/reads/SAMDataSource.java b/public/java/src/org/broadinstitute/sting/gatk/datasources/reads/SAMDataSource.java index bf7afe4f0..bbcbe6dbc 100755 --- a/public/java/src/org/broadinstitute/sting/gatk/datasources/reads/SAMDataSource.java +++ b/public/java/src/org/broadinstitute/sting/gatk/datasources/reads/SAMDataSource.java @@ -51,11 +51,10 @@ import org.broadinstitute.sting.utils.recalibration.BaseRecalibration; import org.broadinstitute.sting.utils.sam.GATKSamRecordFactory; import java.io.File; -import java.io.FileNotFoundException; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.*; -import java.util.concurrent.*; +import java.util.concurrent.Callable; /** * User: aaron @@ -474,7 +473,6 @@ public class SAMDataSource { /** * Fill the given buffering shard with reads. * @param shard Shard to fill. - * @return true if at the end of the stream. False otherwise. */ public void fillShard(Shard shard) { if(!shard.buffersReads()) @@ -569,15 +567,19 @@ public class SAMDataSource { if(shard.getFileSpans().get(id) == null) throw new ReviewedStingException("SAMDataSource: received null location for reader " + id + ", but null locations are no longer supported."); - if(threadAllocation.getNumIOThreads() > 0) { - BlockInputStream inputStream = readers.getInputStream(id); - inputStream.submitAccessPlan(new BAMAccessPlan(id, inputStream, (GATKBAMFileSpan) shard.getFileSpans().get(id))); - BAMRecordCodec codec = new BAMRecordCodec(getHeader(id),factory); - codec.setInputStream(inputStream); - iterator = new BAMCodecIterator(inputStream,readers.getReader(id),codec); - } - else { - iterator = readers.getReader(id).iterator(shard.getFileSpans().get(id)); + try { + if(threadAllocation.getNumIOThreads() > 0) { + BlockInputStream inputStream = readers.getInputStream(id); + inputStream.submitAccessPlan(new BAMAccessPlan(id, inputStream, (GATKBAMFileSpan) shard.getFileSpans().get(id))); + BAMRecordCodec codec = new BAMRecordCodec(getHeader(id),factory); + codec.setInputStream(inputStream); + iterator = new BAMCodecIterator(inputStream,readers.getReader(id),codec); + } + else { + iterator = readers.getReader(id).iterator(shard.getFileSpans().get(id)); + } + } catch ( RuntimeException e ) { // we need to catch RuntimeExceptions here because the Picard code is throwing them (among SAMFormatExceptions) sometimes + throw new UserException.MalformedBAM(id.samFile, e.getMessage()); } iterator = new MalformedBAMErrorReformatingIterator(id.samFile, iterator); @@ -932,10 +934,7 @@ public class SAMDataSource { blockInputStream = new BlockInputStream(dispatcher,readerID,false); reader = new SAMFileReader(readerID.samFile,indexFile,false); } catch ( RuntimeIOException e ) { - if ( e.getCause() != null && e.getCause() instanceof FileNotFoundException ) - throw new UserException.CouldNotReadInputFile(readerID.samFile, e); - else - throw e; + throw new UserException.CouldNotReadInputFile(readerID.samFile, e); } catch ( SAMFormatException e ) { throw new UserException.MalformedBAM(readerID.samFile, e.getMessage()); }