diff --git a/java/src/org/broadinstitute/sting/gatk/io/StingSAMFileWriter.java b/java/src/org/broadinstitute/sting/gatk/io/StingSAMFileWriter.java new file mode 100644 index 000000000..ada006e07 --- /dev/null +++ b/java/src/org/broadinstitute/sting/gatk/io/StingSAMFileWriter.java @@ -0,0 +1,25 @@ +package org.broadinstitute.sting.gatk.io; + +import net.sf.samtools.SAMFileWriter; +import net.sf.samtools.SAMFileHeader; + +/** + * A writer that will allow unsorted BAM files to be written + * and sorted on-the-fly. + * + * @author mhanna + * @version 0.1 + */ +public interface StingSAMFileWriter extends SAMFileWriter { + /** + * Writes the given custom header to SAM file output. + * @param header The header to write. + */ + public void writeHeader(SAMFileHeader header); + + /** + * Set Whether the BAM file to create is actually presorted. + * @param presorted True if the BAM file is presorted. False otherwise. + */ + public void setPresorted(boolean presorted); +} \ No newline at end of file diff --git a/java/src/org/broadinstitute/sting/gatk/io/storage/SAMFileWriterStorage.java b/java/src/org/broadinstitute/sting/gatk/io/storage/SAMFileWriterStorage.java index ea3d61d4f..2b5cf2b8c 100644 --- a/java/src/org/broadinstitute/sting/gatk/io/storage/SAMFileWriterStorage.java +++ b/java/src/org/broadinstitute/sting/gatk/io/storage/SAMFileWriterStorage.java @@ -49,19 +49,19 @@ public class SAMFileWriterStorage implements SAMFileWriter, Storage, SAMFileWriter { +public class SAMFileWriterStub implements Stub, StingSAMFileWriter { /** * Engine to use for collecting attributes for the output SAM file. */ private final GenomeAnalysisEngine engine; + /** + * A header supplied by the user that overrides the merged header from the input BAM. + */ + private SAMFileHeader headerOverride = null; + /** * The sam file that this stub should write to. Should be passed along to * whatever happens to create the StreamConnector. @@ -57,6 +63,11 @@ public class SAMFileWriterStub implements Stub, SAMFileWriter { */ private Integer compressionLevel = null; + /** + * Should this BAM be presorted? + */ + private boolean presorted = true; + /** * Connects this stub with an external stream capable of serving the * requests of the consumer of this stub. @@ -66,7 +77,7 @@ public class SAMFileWriterStub implements Stub, SAMFileWriter { /** * Create a new stub given the requested SAM file and compression level. * @param engine source of header data, maybe other data about input files. - * @param samFile SAM file to (ultimately) cerate. + * @param samFile SAM file to (ultimately) create. */ public SAMFileWriterStub( GenomeAnalysisEngine engine, File samFile ) { this.engine = engine; @@ -85,12 +96,8 @@ public class SAMFileWriterStub implements Stub, SAMFileWriter { * Retrieves the header to use when creating the new SAM file. * @return header to use when creating the new SAM file. */ - public SAMFileHeader getSAMFileHeader() { - return engine.getSAMFileHeader(); - } - public SAMFileHeader getFileHeader() { - return getSAMFileHeader(); + return headerOverride != null ? headerOverride : engine.getSAMFileHeader(); } /** @@ -109,6 +116,22 @@ public class SAMFileWriterStub implements Stub, SAMFileWriter { this.compressionLevel = compressionLevel; } + /** + * Whether the BAM file to create is actually presorted. + * @return True if the BAM file is presorted. False otherwise. + */ + public boolean isPresorted() { + return this.presorted; + } + + /** + * Set Whether the BAM file to create is actually presorted. + * @param presorted True if the BAM file is presorted. False otherwise. + */ + public void setPresorted(boolean presorted) { + this.presorted = presorted; + } + /** * Registers the given streamConnector with this stub. * @param outputTracker The connector used to provide an appropriate stream. @@ -117,6 +140,14 @@ public class SAMFileWriterStub implements Stub, SAMFileWriter { this.outputTracker = outputTracker; } + /** + * Use the given header as the target for this writer. + * @param header The header to write. + */ + public void writeHeader(SAMFileHeader header) { + this.headerOverride = header; + } + /** * @{inheritDoc} */ diff --git a/java/src/org/broadinstitute/sting/gatk/walkers/ClipReadsWalker.java b/java/src/org/broadinstitute/sting/gatk/walkers/ClipReadsWalker.java index a35f7484f..d11ae8d0c 100755 --- a/java/src/org/broadinstitute/sting/gatk/walkers/ClipReadsWalker.java +++ b/java/src/org/broadinstitute/sting/gatk/walkers/ClipReadsWalker.java @@ -8,6 +8,7 @@ import org.broadinstitute.sting.utils.cmdLine.Argument; import org.broadinstitute.sting.utils.Utils; import org.broadinstitute.sting.utils.Pair; import org.broadinstitute.sting.utils.BaseUtils; +import org.broadinstitute.sting.gatk.io.StingSAMFileWriter; import java.util.*; import java.util.regex.Pattern; @@ -26,7 +27,7 @@ public class ClipReadsWalker extends ReadWalker seqClipCounts = new HashMap(); - public ClippingData(SAMFileWriter output, List clipSeqs) { - this.output = output; + public ClippingData(List clipSeqs) { for (SeqToClip clipSeq : clipSeqs) { seqClipCounts.put(clipSeq.seq, 0L); }