From 87aca647167a91430f867fd65554924b4513b73b Mon Sep 17 00:00:00 2001 From: hanna Date: Fri, 10 Sep 2010 21:16:03 +0000 Subject: [PATCH] Jumped the gun a bit on bam on-the-fly indexing -- Tim says it's not ready yet. Turned it off by default and added a property to turn it back on. git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@4254 348d0f76-0448-11de-a6fe-93d51630548a --- .../gatk/io/storage/SAMFileWriterStorage.java | 2 +- .../SAMFileWriterArgumentTypeDescriptor.java | 24 ++++++++++++++++++- .../gatk/io/stubs/SAMFileWriterStub.java | 24 +++++++++++++++++++ 3 files changed, 48 insertions(+), 2 deletions(-) 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 e20ac7675..d5507f626 100644 --- a/java/src/org/broadinstitute/sting/gatk/io/storage/SAMFileWriterStorage.java +++ b/java/src/org/broadinstitute/sting/gatk/io/storage/SAMFileWriterStorage.java @@ -52,7 +52,7 @@ public class SAMFileWriterStorage implements SAMFileWriter, Storage createArgumentDefinitions( ArgumentSource source ) { return Arrays.asList( createBAMArgumentDefinition(source), - createBAMCompressionArgumentDefinition(source) ); + createBAMCompressionArgumentDefinition(source), + createWriteIndexArgumentDefinition(source)); } @Override @@ -104,6 +107,8 @@ public class SAMFileWriterArgumentTypeDescriptor extends ArgumentTypeDescriptor if( compressionLevel != null ) stub.setCompressionLevel(compressionLevel); + stub.setIndexOnTheFly(argumentIsPresent(createWriteIndexArgumentDefinition(source),matches)); + // WARNING: Side effects required by engine! parsingEngine.addTags(stub,getArgumentTags(matches)); engine.addOutput(stub); @@ -155,4 +160,21 @@ public class SAMFileWriterArgumentTypeDescriptor extends ArgumentTypeDescriptor null, null ); } + + private ArgumentDefinition createWriteIndexArgumentDefinition(ArgumentSource source) { + Annotation annotation = this.getArgumentAnnotation(source); + return new ArgumentDefinition( ArgumentIOType.getIOType(annotation), + boolean.class, + CREATE_INDEX_FULLNAME, + null, + "Create a BAM index on-the-fly while writing the resulting file.", + false, + false, + false, + source.isHidden(), + null, + null, + null, + null ); + } } 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 12929214a..280888d76 100644 --- a/java/src/org/broadinstitute/sting/gatk/io/stubs/SAMFileWriterStub.java +++ b/java/src/org/broadinstitute/sting/gatk/io/stubs/SAMFileWriterStub.java @@ -37,6 +37,7 @@ import org.broadinstitute.sting.gatk.io.StingSAMFileWriter; import org.broadinstitute.sting.gatk.GenomeAnalysisEngine; import org.broadinstitute.sting.utils.GATKException; import org.broadinstitute.sting.utils.StingException; +import org.broadinstitute.sting.utils.exceptions.UserError; /** * A stub for routing and management of SAM file reading and writing. @@ -71,6 +72,11 @@ public class SAMFileWriterStub implements Stub, StingSAMFileWrite */ private Integer compressionLevel = null; + /** + * Should the GATK index the output BAM on-the-fly? + */ + private boolean indexOnTheFly = false; + /** * Should this BAM be presorted? */ @@ -155,6 +161,24 @@ public class SAMFileWriterStub implements Stub, StingSAMFileWrite this.compressionLevel = compressionLevel; } + /** + * Gets whether to index this output stream on-the-fly. + * @return True means create an index. False means skip index creation. + */ + public Boolean getIndexOnTheFly() { + return indexOnTheFly; + } + + /** + * Controls whether to index this output stream on-the-fly. + * @param indexOnTheFly True means create an index. False means skip index creation. + */ + public void setIndexOnTheFly( boolean indexOnTheFly ) { + if(writeStarted) + throw new UserError("Attempted to index a BAM on the fly of a file with alignments already in it."); + this.indexOnTheFly = indexOnTheFly; + } + /** * Whether the BAM file to create is actually presorted. * @return True if the BAM file is presorted. False otherwise.