At Picard team's request, generate md5s for generated BAM files.
git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@5954 348d0f76-0448-11de-a6fe-93d51630548a
This commit is contained in:
parent
311dfa0998
commit
ca48ea78df
|
|
@ -60,16 +60,13 @@ public class SAMFileWriterStorage implements SAMFileWriter, Storage<SAMFileWrite
|
||||||
// Enable automatic index creation for pre-sorted BAMs.
|
// Enable automatic index creation for pre-sorted BAMs.
|
||||||
if (stub.getFileHeader().getSortOrder().equals(SAMFileHeader.SortOrder.coordinate) && stub.getIndexOnTheFly())
|
if (stub.getFileHeader().getSortOrder().equals(SAMFileHeader.SortOrder.coordinate) && stub.getIndexOnTheFly())
|
||||||
factory.setCreateIndex(true);
|
factory.setCreateIndex(true);
|
||||||
|
if (stub.getGenerateMD5())
|
||||||
|
factory.setCreateMd5File(true);
|
||||||
// Adjust max records in RAM.
|
// Adjust max records in RAM.
|
||||||
if(stub.getMaxRecordsInRam() != null)
|
if(stub.getMaxRecordsInRam() != null)
|
||||||
factory.setMaxRecordsInRam(stub.getMaxRecordsInRam());
|
factory.setMaxRecordsInRam(stub.getMaxRecordsInRam());
|
||||||
|
|
||||||
if(stub.getSAMFile() != null) {
|
if(stub.getSAMFile() != null) {
|
||||||
// HACK: Turn setCreateIndex off if the SAM file is null. Picard has pledged to fix this
|
|
||||||
// during the week of 14 Sept 2010. Eliminate this check when they do.
|
|
||||||
if(stub.getSAMFile().getPath().equals("/dev/null"))
|
|
||||||
factory.setCreateIndex(false);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
this.writer = createBAMWriter(factory,stub.getFileHeader(),stub.isPresorted(),file,stub.getCompressionLevel());
|
this.writer = createBAMWriter(factory,stub.getFileHeader(),stub.isPresorted(),file,stub.getCompressionLevel());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -52,6 +52,7 @@ public class SAMFileWriterArgumentTypeDescriptor extends ArgumentTypeDescriptor
|
||||||
public static final String SIMPLIFY_BAM_SHORTNAME = SIMPLIFY_BAM_FULLNAME;
|
public static final String SIMPLIFY_BAM_SHORTNAME = SIMPLIFY_BAM_FULLNAME;
|
||||||
|
|
||||||
public static final String DISABLE_INDEXING_FULLNAME = "disable_bam_indexing";
|
public static final String DISABLE_INDEXING_FULLNAME = "disable_bam_indexing";
|
||||||
|
public static final String ENABLE_MD5_FULLNAME = "generate_md5";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The engine into which output stubs should be fed.
|
* The engine into which output stubs should be fed.
|
||||||
|
|
@ -83,6 +84,7 @@ public class SAMFileWriterArgumentTypeDescriptor extends ArgumentTypeDescriptor
|
||||||
return Arrays.asList( createBAMArgumentDefinition(source),
|
return Arrays.asList( createBAMArgumentDefinition(source),
|
||||||
createBAMCompressionArgumentDefinition(source),
|
createBAMCompressionArgumentDefinition(source),
|
||||||
disableWriteIndexArgumentDefinition(source),
|
disableWriteIndexArgumentDefinition(source),
|
||||||
|
enableMD5GenerationArgumentDefinition(source),
|
||||||
createSimplifyBAMArgumentDefinition(source));
|
createSimplifyBAMArgumentDefinition(source));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -102,23 +104,39 @@ public class SAMFileWriterArgumentTypeDescriptor extends ArgumentTypeDescriptor
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object parse( ParsingEngine parsingEngine, ArgumentSource source, Class type, ArgumentMatches matches ) {
|
public Object parse( ParsingEngine parsingEngine, ArgumentSource source, Class type, ArgumentMatches matches ) {
|
||||||
|
// Extract all possible parameters that could be passed to a BAM file writer?
|
||||||
ArgumentDefinition bamArgumentDefinition = createBAMArgumentDefinition(source);
|
ArgumentDefinition bamArgumentDefinition = createBAMArgumentDefinition(source);
|
||||||
String writerFileName = getArgumentValue( bamArgumentDefinition, matches );
|
String writerFileName = getArgumentValue( bamArgumentDefinition, matches );
|
||||||
|
|
||||||
// This parser has been passed a null filename and the GATK is not responsible for creating a type default for the object;
|
|
||||||
// therefore, the user must have failed to specify a type default
|
|
||||||
if(writerFileName == null && !source.isRequired())
|
|
||||||
throw new MissingArgumentValueException(bamArgumentDefinition);
|
|
||||||
|
|
||||||
SAMFileWriterStub stub = new SAMFileWriterStub(engine, new File(writerFileName));
|
|
||||||
|
|
||||||
String compressionLevelText = getArgumentValue( createBAMCompressionArgumentDefinition(source), matches );
|
String compressionLevelText = getArgumentValue( createBAMCompressionArgumentDefinition(source), matches );
|
||||||
Integer compressionLevel = compressionLevelText != null ? Integer.valueOf(compressionLevelText) : null;
|
Integer compressionLevel = compressionLevelText != null ? Integer.valueOf(compressionLevelText) : null;
|
||||||
|
|
||||||
|
Boolean indexOnTheFly = !argumentIsPresent(disableWriteIndexArgumentDefinition(source),matches) ? true : null;
|
||||||
|
Boolean generateMD5 = argumentIsPresent(this.enableMD5GenerationArgumentDefinition(source),matches) ? true : null;
|
||||||
|
Boolean simplifyBAM = argumentIsPresent(createSimplifyBAMArgumentDefinition(source),matches);
|
||||||
|
|
||||||
|
// Validate the combination of parameters passed in.
|
||||||
|
|
||||||
|
// This parser has been passed a null filename and the GATK is not responsible for creating a type default for the object;
|
||||||
|
// therefore, the user must have failed to specify a type default
|
||||||
|
if(writerFileName == null) {
|
||||||
|
if(!source.isRequired())
|
||||||
|
throw new MissingArgumentValueException(bamArgumentDefinition);
|
||||||
|
if(generateMD5)
|
||||||
|
throw new ArgumentException("MD5 generation specified, but no output file specified. If md5 generation is desired, please specify a BAM output file and an md5 file will be written alongside.");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create the stub and set parameters.
|
||||||
|
SAMFileWriterStub stub = new SAMFileWriterStub(engine, new File(writerFileName));
|
||||||
|
|
||||||
if( compressionLevel != null )
|
if( compressionLevel != null )
|
||||||
stub.setCompressionLevel(compressionLevel);
|
stub.setCompressionLevel(compressionLevel);
|
||||||
|
if(indexOnTheFly != null)
|
||||||
stub.setIndexOnTheFly(!argumentIsPresent(disableWriteIndexArgumentDefinition(source),matches));
|
stub.setIndexOnTheFly(indexOnTheFly);
|
||||||
stub.setSimplifyBAM(argumentIsPresent(createSimplifyBAMArgumentDefinition(source),matches));
|
if(generateMD5 != null)
|
||||||
|
stub.setGenerateMD5(generateMD5);
|
||||||
|
if(simplifyBAM != null)
|
||||||
|
stub.setSimplifyBAM(simplifyBAM);
|
||||||
|
|
||||||
// WARNING: Side effects required by engine!
|
// WARNING: Side effects required by engine!
|
||||||
parsingEngine.addTags(stub,getArgumentTags(matches));
|
parsingEngine.addTags(stub,getArgumentTags(matches));
|
||||||
|
|
@ -187,6 +205,23 @@ public class SAMFileWriterArgumentTypeDescriptor extends ArgumentTypeDescriptor
|
||||||
null );
|
null );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private ArgumentDefinition enableMD5GenerationArgumentDefinition(ArgumentSource source) {
|
||||||
|
return new ArgumentDefinition( ArgumentIOType.ARGUMENT,
|
||||||
|
boolean.class,
|
||||||
|
ENABLE_MD5_FULLNAME,
|
||||||
|
null,
|
||||||
|
"Enable on-the-fly creation of md5s for output BAM files.",
|
||||||
|
false,
|
||||||
|
true,
|
||||||
|
false,
|
||||||
|
source.isHidden(),
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
null );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private ArgumentDefinition createSimplifyBAMArgumentDefinition(ArgumentSource source) {
|
private ArgumentDefinition createSimplifyBAMArgumentDefinition(ArgumentSource source) {
|
||||||
return new ArgumentDefinition( ArgumentIOType.ARGUMENT,
|
return new ArgumentDefinition( ArgumentIOType.ARGUMENT,
|
||||||
boolean.class,
|
boolean.class,
|
||||||
|
|
|
||||||
|
|
@ -77,6 +77,11 @@ public class SAMFileWriterStub implements Stub<SAMFileWriter>, StingSAMFileWrite
|
||||||
*/
|
*/
|
||||||
private boolean indexOnTheFly = false;
|
private boolean indexOnTheFly = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Should the GATK generate an md5 for the output BAM?
|
||||||
|
*/
|
||||||
|
private boolean generateMD5 = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Should this BAM be presorted?
|
* Should this BAM be presorted?
|
||||||
*/
|
*/
|
||||||
|
|
@ -198,6 +203,24 @@ public class SAMFileWriterStub implements Stub<SAMFileWriter>, StingSAMFileWrite
|
||||||
this.indexOnTheFly = indexOnTheFly;
|
this.indexOnTheFly = indexOnTheFly;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets whether to generate an md5 on-the-fly for this BAM.
|
||||||
|
* @return True generates the md5. False means skip writing the file.
|
||||||
|
*/
|
||||||
|
public Boolean getGenerateMD5() {
|
||||||
|
return generateMD5;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets whether to generate an md5 on-the-fly for this BAM.
|
||||||
|
* @return True generates the md5. False means skip writing the file.
|
||||||
|
*/
|
||||||
|
public void setGenerateMD5(boolean generateMD5) {
|
||||||
|
if(writeStarted)
|
||||||
|
throw new UserException("Attempted to turn on md5 generation for BAM file with alignments already in it.");
|
||||||
|
this.generateMD5 = generateMD5;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether the BAM file to create is actually presorted.
|
* Whether the BAM file to create is actually presorted.
|
||||||
* @return True if the BAM file is presorted. False otherwise.
|
* @return True if the BAM file is presorted. False otherwise.
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue