Emit the GATK version number in the VCF header

-- Looks like ##GATKVersion=2.5-159-g3f91d93 in the VCF header line
-- delivers [#51595305]
This commit is contained in:
Mark DePristo 2013-06-13 15:46:16 -04:00
parent d93bed5d61
commit 74f311c973
2 changed files with 34 additions and 0 deletions

View File

@ -27,6 +27,7 @@ package org.broadinstitute.sting.gatk.io.stubs;
import net.sf.samtools.SAMSequenceDictionary;
import org.broadinstitute.sting.gatk.CommandLineExecutable;
import org.broadinstitute.sting.gatk.CommandLineGATK;
import org.broadinstitute.sting.gatk.GenomeAnalysisEngine;
import org.broadinstitute.sting.gatk.io.OutputTracker;
import org.broadinstitute.sting.utils.classloader.JVMUtils;
@ -53,6 +54,7 @@ import java.util.List;
* @version 0.1
*/
public class VariantContextWriterStub implements Stub<VariantContextWriter>, VariantContextWriter {
public final static String GATK_VERSION_KEY = "GATKVersion";
public final static boolean UPDATE_CONTIG_HEADERS = true;
/**
@ -225,6 +227,9 @@ public class VariantContextWriterStub implements Stub<VariantContextWriter>, Var
if ( header.isWriteEngineHeaders() ) {
// skip writing the command line header if requested
if ( ! skipWritingCommandLineHeader && header.isWriteCommandLine() ) {
// write the GATK version if we have command line information enabled
vcfHeader.addMetaDataLine(getGATKVersionHeaderLine());
// Check for the command-line argument header line. If not present, add it in.
final VCFHeaderLine commandLineArgHeaderLine = getCommandLineArgumentHeaderLine();
final boolean foundCommandLineHeaderLine = vcfHeader.getMetaDataLine(commandLineArgHeaderLine.getKey()) != null;
@ -284,4 +289,12 @@ public class VariantContextWriterStub implements Stub<VariantContextWriter>, Var
CommandLineExecutable executable = JVMUtils.getObjectOfType(argumentSources,CommandLineExecutable.class);
return new VCFHeaderLine(executable.getAnalysisName(), "\"" + engine.createApproximateCommandLineArgumentString(argumentSources.toArray()) + "\"");
}
/**
* Gets the GATK version header line for the VCF file
* @return non-null VCFHeaderLine.
*/
private VCFHeaderLine getGATKVersionHeaderLine() {
return new VCFHeaderLine(GATK_VERSION_KEY, CommandLineGATK.getVersionNumber());
}
}

View File

@ -25,10 +25,12 @@
package org.broadinstitute.sting.gatk;
import org.broad.tribble.readers.AsciiLineReader;
import org.broadinstitute.sting.WalkerTest;
import org.broadinstitute.sting.commandline.Output;
import org.broadinstitute.sting.gatk.contexts.ReferenceContext;
import org.broadinstitute.sting.gatk.filters.MappingQualityUnavailableFilter;
import org.broadinstitute.sting.gatk.io.stubs.VariantContextWriterStub;
import org.broadinstitute.sting.gatk.refdata.RefMetaDataTracker;
import org.broadinstitute.sting.gatk.walkers.ReadFilters;
import org.broadinstitute.sting.gatk.walkers.ReadWalker;
@ -36,9 +38,15 @@ import org.broadinstitute.sting.gatk.walkers.qc.ErrorThrowing;
import org.broadinstitute.sting.utils.exceptions.ReviewedStingException;
import org.broadinstitute.sting.utils.exceptions.UserException;
import org.broadinstitute.sting.utils.sam.GATKSAMRecord;
import org.broadinstitute.variant.vcf.VCFCodec;
import org.broadinstitute.variant.vcf.VCFHeader;
import org.broadinstitute.variant.vcf.VCFHeaderLine;
import org.testng.Assert;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import java.io.File;
import java.io.FileInputStream;
import java.io.PrintStream;
import java.util.Arrays;
@ -191,4 +199,17 @@ public class EngineFeaturesIntegrationTest extends WalkerTest {
1, UserException.class);
executeTest("badCompress " + compress, spec);
}
@Test(enabled = true)
public void testGATKVersionInVCF() throws Exception {
WalkerTestSpec spec = new WalkerTestSpec("-T UnifiedGenotyper -R " + b37KGReference + " -I "
+ privateTestDir + "PCRFree.2x250.Illumina.20_10_11.bam"
+ " -o %s -L 20:10,000,000",
1, Arrays.asList(""));
final File vcf = executeTest("testGATKVersionInVCF", spec).first.get(0);
final VCFHeader header = (VCFHeader)new VCFCodec().readHeader(new AsciiLineReader(new FileInputStream(vcf)));
final VCFHeaderLine versionLine = header.getMetaDataLine(VariantContextWriterStub.GATK_VERSION_KEY);
Assert.assertNotNull(versionLine);
Assert.assertEquals(versionLine.getValue(), CommandLineGATK.getVersionNumber());
}
}