diff --git a/java/src/org/broadinstitute/sting/gatk/io/StingSAMFileWriter.java b/java/src/org/broadinstitute/sting/gatk/io/StingSAMFileWriter.java index ada006e07..8701ecf3c 100644 --- a/java/src/org/broadinstitute/sting/gatk/io/StingSAMFileWriter.java +++ b/java/src/org/broadinstitute/sting/gatk/io/StingSAMFileWriter.java @@ -22,4 +22,10 @@ public interface StingSAMFileWriter extends SAMFileWriter { * @param presorted True if the BAM file is presorted. False otherwise. */ public void setPresorted(boolean presorted); + + /** + * Set how many records in RAM the BAM file stores when sorting on-the-fly. + * @param maxRecordsInRam Max number of records in RAM. + */ + public void setMaxRecordsInRam(int maxRecordsInRam); } \ 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 d516066f6..b8dd1553d 100644 --- a/java/src/org/broadinstitute/sting/gatk/io/storage/SAMFileWriterStorage.java +++ b/java/src/org/broadinstitute/sting/gatk/io/storage/SAMFileWriterStorage.java @@ -49,14 +49,18 @@ public class SAMFileWriterStorage implements SAMFileWriter, Storage, StingSAMFileWrite */ private boolean presorted = true; + /** + * How many records should the BAM writer store in RAM while + * sorting the BAM on-the-fly? + */ + private Integer maxRecordsInRam = null; + /** * Connects this stub with an external stream capable of serving the * requests of the consumer of this stub. @@ -166,6 +172,24 @@ public class SAMFileWriterStub implements Stub, StingSAMFileWrite this.presorted = presorted; } + /** + * Get the maximum number of reads to hold in RAM when sorting a BAM on-the-fly. + * @return Max records in RAM, or null if unset. + */ + public Integer getMaxRecordsInRam() { + return this.maxRecordsInRam; + } + + /** + * Sets the maximum number of reads to hold in RAM when sorting a BAM on-the-fly. + * @param maxRecordsInRam Max number of records in RAM. + */ + public void setMaxRecordsInRam(int maxRecordsInRam) { + if(writeStarted) + throw new StingException("User attempted to change the max records in RAM of a file with alignments already in it."); + this.maxRecordsInRam = maxRecordsInRam; + } + /** * Registers the given streamConnector with this stub. * @param outputTracker The connector used to provide an appropriate stream.