From 35a4fcc48138c91307ed64ee6647767e9c76ab72 Mon Sep 17 00:00:00 2001 From: hanna Date: Tue, 12 Jan 2010 18:39:41 +0000 Subject: [PATCH] Additional sanity checking: make sure the user can't alter the header / compression level / presorted state of a file to which SAMRecords have already been written. git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@2562 348d0f76-0448-11de-a6fe-93d51630548a --- .../sting/gatk/io/stubs/SAMFileWriterStub.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) 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 8512f9873..da3237e26 100644 --- a/java/src/org/broadinstitute/sting/gatk/io/stubs/SAMFileWriterStub.java +++ b/java/src/org/broadinstitute/sting/gatk/io/stubs/SAMFileWriterStub.java @@ -34,6 +34,7 @@ import java.io.File; 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.StingException; /** * A stub for routing and management of SAM file reading and writing. @@ -74,6 +75,13 @@ public class SAMFileWriterStub implements Stub, StingSAMFileWrite */ private OutputTracker outputTracker = null; + /** + * Has the write started? If so, throw an exception if someone tries to + * change write parameters to the file (compression level, presorted flag, + * header, etc). + */ + private boolean writeStarted = false; + /** * Create a new stub given the requested SAM file and compression level. * @param engine source of header data, maybe other data about input files. @@ -113,6 +121,8 @@ public class SAMFileWriterStub implements Stub, StingSAMFileWrite * @param compressionLevel The suggested compression level. */ public void setCompressionLevel( Integer compressionLevel ) { + if(writeStarted) + throw new StingException("User attempted to change the compression level of a file with alignments already in it."); this.compressionLevel = compressionLevel; } @@ -129,6 +139,8 @@ public class SAMFileWriterStub implements Stub, StingSAMFileWrite * @param presorted True if the BAM file is presorted. False otherwise. */ public void setPresorted(boolean presorted) { + if(writeStarted) + throw new StingException("User attempted to change the presorted state of a file with alignments already in it."); this.presorted = presorted; } @@ -145,6 +157,8 @@ public class SAMFileWriterStub implements Stub, StingSAMFileWrite * @param header The header to write. */ public void writeHeader(SAMFileHeader header) { + if(writeStarted) + throw new StingException("User attempted to change the header of a file with alignments already in it."); this.headerOverride = header; } @@ -152,6 +166,7 @@ public class SAMFileWriterStub implements Stub, StingSAMFileWrite * @{inheritDoc} */ public void addAlignment( SAMRecord alignment ) { + writeStarted = true; outputTracker.getStorage(this).addAlignment(alignment); }