Make Indel Realigner exceptions related to not enough space on disk or a too low file-handle limit UserExceptions.

git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@4801 348d0f76-0448-11de-a6fe-93d51630548a
This commit is contained in:
ebanks 2010-12-07 16:37:31 +00:00
parent 70980b659a
commit e2d45ec2af
3 changed files with 29 additions and 26 deletions

View File

@ -90,7 +90,11 @@ public class SAMFileWriterStorage implements SAMFileWriter, Storage<SAMFileWrite
}
public void close() {
writer.close();
try {
writer.close();
} catch (RuntimeIOException e) {
throw new UserException.ErrorWritingBamFile(e.getMessage());
}
}
public void mergeInto( SAMFileWriter targetStream ) {

View File

@ -26,6 +26,7 @@
package org.broadinstitute.sting.gatk.walkers.indels;
import net.sf.samtools.*;
import net.sf.samtools.util.RuntimeIOException;
import net.sf.samtools.util.StringUtil;
import net.sf.samtools.util.SequenceUtil;
import net.sf.picard.reference.IndexedFastaSequenceFile;
@ -304,8 +305,7 @@ public class IndelRealigner extends ReadWalker<Integer, Integer> {
throw new StingException("nWayOut mode: Reader id for input sam file "+fName+" is already registered");
File f = new File(outName);
SAMFileWriter sw = new SAMFileWriterFactory().makeSAMOrBAMWriter(setupHeader(getToolkit().getSAMFileHeader(rid)),
false,f);
SAMFileWriter sw = new SAMFileWriterFactory().makeSAMOrBAMWriter(setupHeader(getToolkit().getSAMFileHeader(rid)), false, f);
nwayWriters.put(rid,sw);
}
@ -379,28 +379,10 @@ public class IndelRealigner extends ReadWalker<Integer, Integer> {
}
private void emit(final SAMRecord read) {
if ( writer != null )
writer.addAlignment(read);
if ( N_WAY_OUT != null ) {
SAMReaderID rid = getToolkit().getReaderIDForRead(read);
SAMFileWriter w = nwayWriters.get(rid);
// reset read's read group from merged to original if read group id collision has happened in merging:
if ( getToolkit().getReadsDataSource().hasReadGroupCollisions() ) {
read.setAttribute("RG",
getToolkit().getReadsDataSource().getOriginalReadGroupId((String)read.getAttribute("RG")));
}
w.addAlignment(read);
}
}
private void emit(final List<SAMRecord> reads) {
if ( writer != null ) {
for ( SAMRecord read : reads )
try {
if ( writer != null )
writer.addAlignment(read);
}
if ( N_WAY_OUT != null ) {
for ( SAMRecord read : reads ) {
// in initialize() we ensured that every reader has exactly one tag, so the following line is safe:
else if ( N_WAY_OUT != null ) {
SAMReaderID rid = getToolkit().getReaderIDForRead(read);
SAMFileWriter w = nwayWriters.get(rid);
// reset read's read group from merged to original if read group id collision has happened in merging:
@ -409,11 +391,17 @@ public class IndelRealigner extends ReadWalker<Integer, Integer> {
getToolkit().getReadsDataSource().getOriginalReadGroupId((String)read.getAttribute("RG")));
}
w.addAlignment(read);
}
} catch (RuntimeIOException e) {
throw new UserException.ErrorWritingBamFile(e.getMessage());
}
}
private void emit(final List<SAMRecord> reads) {
for ( SAMRecord read : reads )
emit(read);
}
public Integer map(ReferenceContext ref, SAMRecord read, ReadMetaDataTracker metaDataTracker) {
if ( currentInterval == null ) {
emit(read);
@ -544,7 +532,12 @@ public class IndelRealigner extends ReadWalker<Integer, Integer> {
}
if ( N_WAY_OUT != null ) {
for ( SAMFileWriter w : nwayWriters.values() ) w.close();
try {
for ( SAMFileWriter w : nwayWriters.values() )
w.close();
} catch (RuntimeIOException e) {
throw new UserException.ErrorWritingBamFile(e.getMessage());
}
}
if ( CHECKEARLY ) {
logger.info("SW alignments runs: "+SWalignmentRuns);

View File

@ -77,6 +77,12 @@ public class UserException extends ReviewedStingException {
}
}
public static class ErrorWritingBamFile extends UserException {
public ErrorWritingBamFile(String message) {
super(String.format("An error occurred when trying to write the BAM file. Usually this happens when there is not enough space in the directory to which the data is being written (generally the temp directory) or when your system's open file handle limit is too small. To tell Java to use a bigger/better file system use -Djava.io.tmpdir=X on the command line. The exact error was %s", message));
}
}
public static class CouldNotReadInputFile extends UserException {
public CouldNotReadInputFile(String message, Exception e) {
super(String.format("Couldn't read file because %s caused by %s", message, e.getMessage()));