Allow user to specify the compression to be used when writing out BAM files.
Updated most of the walkers to reflect this change. Now it won't take forever to write BAMs! git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@909 348d0f76-0448-11de-a6fe-93d51630548a
This commit is contained in:
parent
c1792de44f
commit
36fb6ca3c5
|
|
@ -112,6 +112,10 @@ public class GATKArgumentCollection {
|
|||
@Argument(fullName = "sort_on_the_fly", shortName = "sort", doc = "Maximum number of reads to sort on the fly", required = false)
|
||||
public Integer maximumReadSorts = null;
|
||||
|
||||
@Element(required=false)
|
||||
@Argument(fullName = "bam_compression", shortName = "compress", doc = "Compression level to use for writing BAM files", required = false)
|
||||
public Integer BAMcompression = null;
|
||||
|
||||
@Element(required=false)
|
||||
@Argument(fullName = "filterZeroMappingQualityReads", shortName = "fmq0", doc = "If true, mapping quality zero reads will be filtered at the lowest GATK level. Vastly improves performance at areas with abnormal depth due to mapping Q0 reads", required = false)
|
||||
public Boolean filterZeroMappingQualityReads = false;
|
||||
|
|
@ -245,6 +249,10 @@ public class GATKArgumentCollection {
|
|||
(other.maximumReadSorts != null && !other.maximumReadSorts.equals(this.maximumReadSorts))) {
|
||||
return false;
|
||||
}
|
||||
if ((other.BAMcompression == null && this.BAMcompression != null) ||
|
||||
(other.BAMcompression != null && !other.BAMcompression.equals(this.BAMcompression))) {
|
||||
return false;
|
||||
}
|
||||
if ((other.filterZeroMappingQualityReads == null && this.filterZeroMappingQualityReads != null) ||
|
||||
(other.filterZeroMappingQualityReads != null && !other.filterZeroMappingQualityReads.equals(this.filterZeroMappingQualityReads))) {
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -280,6 +280,17 @@ public class GenomeAnalysisEngine {
|
|||
return strictness;
|
||||
}
|
||||
|
||||
/**
|
||||
* Default to 5 (based on research by Alec Wysoker)
|
||||
*
|
||||
* @return the BAM compression
|
||||
*/
|
||||
public int getBAMCompression() {
|
||||
return (argCollection.BAMcompression == null ||
|
||||
argCollection.BAMcompression < 1 ||
|
||||
argCollection.BAMcompression > 8) ? 5 : argCollection.BAMcompression;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience function that binds RODs using the old-style command line parser to the new style list for
|
||||
* a uniform processing.
|
||||
|
|
|
|||
|
|
@ -2,9 +2,9 @@ package org.broadinstitute.sting.gatk.walkers;
|
|||
|
||||
import net.sf.samtools.SAMRecord;
|
||||
import net.sf.samtools.SAMFileWriter;
|
||||
import net.sf.samtools.SAMFileWriterFactory;
|
||||
import net.sf.samtools.SAMFileHeader;
|
||||
import org.broadinstitute.sting.utils.cmdLine.Argument;
|
||||
import org.broadinstitute.sting.utils.Utils;
|
||||
|
||||
import java.io.PrintStream;
|
||||
import java.io.FileNotFoundException;
|
||||
|
|
@ -22,9 +22,8 @@ public class PrintReadsWalker extends ReadWalker<SAMRecord, SAMFileWriter> {
|
|||
|
||||
public SAMFileWriter reduceInit() {
|
||||
if ( outputBamFile != null ) { // ! outputBamFile.equals("") ) {
|
||||
SAMFileWriterFactory fact = new SAMFileWriterFactory();
|
||||
SAMFileHeader header = this.getToolkit().getEngine().getSAMHeader();
|
||||
return fact.makeBAMWriter(header, true, new File(outputBamFile));
|
||||
return Utils.createSAMFileWriterWithCompression(header, true, outputBamFile, getToolkit().getBAMCompression());
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
|
|
|
|||
|
|
@ -4,9 +4,9 @@ import org.broadinstitute.sting.gatk.LocusContext;
|
|||
import org.broadinstitute.sting.gatk.walkers.ReadWalker;
|
||||
import org.broadinstitute.sting.utils.cmdLine.Argument;
|
||||
import org.broadinstitute.sting.utils.QualityUtils;
|
||||
import org.broadinstitute.sting.utils.Utils;
|
||||
import net.sf.samtools.SAMRecord;
|
||||
import net.sf.samtools.SAMFileWriter;
|
||||
import net.sf.samtools.SAMFileWriterFactory;
|
||||
import net.sf.samtools.SAMFileHeader;
|
||||
import net.sf.picard.reference.ReferenceSequence;
|
||||
|
||||
|
|
@ -48,11 +48,10 @@ public class IOCrusherWalker extends ReadWalker<SAMRecord, ArrayList<SAMFileWrit
|
|||
*
|
||||
*/
|
||||
public ArrayList<SAMFileWriter> reduceInit() {
|
||||
SAMFileWriterFactory fact = new SAMFileWriterFactory();
|
||||
ArrayList<SAMFileWriter> outputs = new ArrayList<SAMFileWriter>(nWaysOut);
|
||||
for ( int i = 0; i < nWaysOut; i++ ) {
|
||||
SAMFileHeader header = this.getToolkit().getSamReader().getFileHeader();
|
||||
outputs.add(fact.makeBAMWriter(header, true, new File(outputBase + "." + i + ".bam")));
|
||||
SAMFileHeader header = this.getToolkit().getEngine().getSAMHeader();
|
||||
outputs.add(Utils.createSAMFileWriterWithCompression(header, true, outputBase + "." + i + ".bam", getToolkit().getBAMCompression()));
|
||||
}
|
||||
return outputs;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -149,9 +149,8 @@ public class LogisticRecalibrationWalker extends ReadWalker<SAMRecord, SAMFileWr
|
|||
|
||||
public SAMFileWriter reduceInit() {
|
||||
if ( outputBamFile != null ) { // ! outputBamFile.equals("") ) {
|
||||
SAMFileWriterFactory fact = new SAMFileWriterFactory();
|
||||
SAMFileHeader header = this.getToolkit().getEngine().getSAMHeader();
|
||||
return fact.makeBAMWriter(header, true, new File(outputBamFile));
|
||||
return Utils.createSAMFileWriterWithCompression(header, true, outputBamFile, getToolkit().getBAMCompression());
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
|
|
|
|||
|
|
@ -4,12 +4,12 @@ import java.io.File;
|
|||
|
||||
import net.sf.samtools.SAMFileHeader;
|
||||
import net.sf.samtools.SAMFileWriter;
|
||||
import net.sf.samtools.SAMFileWriterFactory;
|
||||
import net.sf.samtools.SAMRecord;
|
||||
|
||||
import org.broadinstitute.sting.gatk.LocusContext;
|
||||
import org.broadinstitute.sting.gatk.walkers.ReadWalker;
|
||||
import org.broadinstitute.sting.utils.cmdLine.Argument;
|
||||
import org.broadinstitute.sting.utils.Utils;
|
||||
|
||||
public class ReadFilterWalker extends ReadWalker<Integer,Integer> {
|
||||
@Argument(fullName="output_file", shortName="O",doc="SAM or BAM file to write filtered reads into (will be overwritten if exists)",required=true ) public String output;
|
||||
|
|
@ -18,8 +18,8 @@ public class ReadFilterWalker extends ReadWalker<Integer,Integer> {
|
|||
private SAMFileWriter writer = null;
|
||||
|
||||
public void initialize() {
|
||||
SAMFileHeader header = getToolkit().getSamReader().getFileHeader();
|
||||
writer = new SAMFileWriterFactory().makeSAMOrBAMWriter(header, header.getSortOrder() != SAMFileHeader.SortOrder.unsorted, new File(output));
|
||||
SAMFileHeader header = this.getToolkit().getEngine().getSAMHeader();
|
||||
writer = Utils.createSAMFileWriterWithCompression(header, header.getSortOrder() != SAMFileHeader.SortOrder.unsorted, output, getToolkit().getBAMCompression());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import org.broadinstitute.sting.gatk.walkers.ReadWalker;
|
|||
import org.broadinstitute.sting.utils.cmdLine.Argument;
|
||||
import org.broadinstitute.sting.utils.QualityUtils;
|
||||
import org.broadinstitute.sting.utils.Pair;
|
||||
import org.broadinstitute.sting.utils.Utils;
|
||||
import net.sf.samtools.*;
|
||||
import net.sf.picard.reference.ReferenceSequence;
|
||||
|
||||
|
|
@ -108,9 +109,8 @@ public class ReplaceQuals extends ReadWalker<SAMRecord, SAMFileWriter> {
|
|||
|
||||
public SAMFileWriter reduceInit() {
|
||||
if ( outputFilename != null ) { // ! outputBamFile.equals("") ) {
|
||||
SAMFileWriterFactory fact = new SAMFileWriterFactory();
|
||||
SAMFileHeader header = this.getToolkit().getEngine().getSAMHeader();
|
||||
return fact.makeBAMWriter(header, true, new File(outputFilename));
|
||||
return Utils.createSAMFileWriterWithCompression(header, true, outputFilename, getToolkit().getBAMCompression());
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package org.broadinstitute.sting.playground.gatk.walkers;
|
|||
import org.broadinstitute.sting.gatk.LocusContext;
|
||||
import org.broadinstitute.sting.gatk.walkers.DuplicateWalker;
|
||||
import org.broadinstitute.sting.utils.GenomeLoc;
|
||||
import org.broadinstitute.sting.utils.Utils;
|
||||
import org.broadinstitute.sting.utils.duplicates.DupUtils;
|
||||
import org.broadinstitute.sting.utils.cmdLine.Argument;
|
||||
|
||||
|
|
@ -11,7 +12,6 @@ import java.io.File;
|
|||
|
||||
import net.sf.samtools.SAMRecord;
|
||||
import net.sf.samtools.SAMFileWriter;
|
||||
import net.sf.samtools.SAMFileWriterFactory;
|
||||
import net.sf.samtools.SAMFileHeader;
|
||||
|
||||
/**
|
||||
|
|
@ -49,9 +49,8 @@ public class CombineDuplicatesWalker extends DuplicateWalker<SAMRecord, SAMFileW
|
|||
|
||||
public SAMFileWriter reduceInit() {
|
||||
if ( outputFilename != null ) {
|
||||
SAMFileWriterFactory fact = new SAMFileWriterFactory();
|
||||
SAMFileHeader header = this.getToolkit().getEngine().getSAMHeader();
|
||||
return fact.makeBAMWriter(header, true, new File(outputFilename));
|
||||
return Utils.createSAMFileWriterWithCompression(header, true, outputFilename, getToolkit().getBAMCompression());
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ public class IntervalCleanerWalker extends LocusWindowWalker<Integer, Integer>
|
|||
throw new RuntimeException("LOD threshold cannot be a negative number");
|
||||
|
||||
SAMFileHeader header = getToolkit().getEngine().getSAMHeader();
|
||||
writer = new SAMFileWriterFactory().makeSAMOrBAMWriter(header, false, new File(OUT));
|
||||
writer = Utils.createSAMFileWriterWithCompression(header, false, OUT, getToolkit().getBAMCompression());
|
||||
if ( OUT_INDELS != null ) {
|
||||
try {
|
||||
indelOutput = new FileWriter(new File(OUT_INDELS));
|
||||
|
|
|
|||
|
|
@ -1,8 +1,6 @@
|
|||
package org.broadinstitute.sting.utils;
|
||||
|
||||
import net.sf.samtools.SAMRecord;
|
||||
import net.sf.samtools.SAMSequenceRecord;
|
||||
import net.sf.samtools.SAMSequenceDictionary;
|
||||
import net.sf.samtools.*;
|
||||
import net.sf.samtools.util.StringUtil;
|
||||
import net.sf.picard.reference.ReferenceSequenceFile;
|
||||
|
||||
|
|
@ -45,6 +43,12 @@ public class Utils {
|
|||
throw new RuntimeException(msg);
|
||||
}
|
||||
|
||||
public static SAMFileWriter createSAMFileWriterWithCompression(SAMFileHeader header, boolean presorted, String file, int compression) {
|
||||
if (file.endsWith(".bam"))
|
||||
return new SAMFileWriterFactory().makeBAMWriter(header, presorted, new File(file), compression);
|
||||
return new SAMFileWriterFactory().makeSAMOrBAMWriter(header, presorted, new File(file));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a new list built from those objects found in collection <c> that satisfy the
|
||||
* predicate ( i.e. pred.apply() is true for the objects in th eresulting list ).
|
||||
|
|
|
|||
Loading…
Reference in New Issue