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
This commit is contained in:
hanna 2010-09-10 21:16:03 +00:00
parent 7b113a4886
commit 87aca64716
3 changed files with 48 additions and 2 deletions

View File

@ -52,7 +52,7 @@ public class SAMFileWriterStorage implements SAMFileWriter, Storage<SAMFileWrite
this.file = file;
SAMFileWriterFactory factory = new SAMFileWriterFactory();
// Enable automatic index creation for pre-sorted BAMs.
if (stub.getFileHeader().getSortOrder().equals(SAMFileHeader.SortOrder.coordinate))
if (stub.getFileHeader().getSortOrder().equals(SAMFileHeader.SortOrder.coordinate) && stub.getIndexOnTheFly())
factory.setCreateIndex(true);
// Adjust max records in RAM.
if(stub.getMaxRecordsInRam() != null)

View File

@ -48,6 +48,8 @@ public class SAMFileWriterArgumentTypeDescriptor extends ArgumentTypeDescriptor
private static final String COMPRESSION_FULLNAME = "bam_compression";
private static final String COMPRESSION_SHORTNAME = "compress";
private static final String CREATE_INDEX_FULLNAME = "index_output_bam_on_the_fly";
/**
* The engine into which output stubs should be fed.
*/
@ -76,7 +78,8 @@ public class SAMFileWriterArgumentTypeDescriptor extends ArgumentTypeDescriptor
@Override
public List<ArgumentDefinition> 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 );
}
}

View File

@ -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<SAMFileWriter>, 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<SAMFileWriter>, 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.