diff --git a/java/src/org/broad/tribble/vcf/VCFCompoundHeaderLine.java b/java/src/org/broad/tribble/vcf/VCFCompoundHeaderLine.java index dff77e24d..e337791f8 100644 --- a/java/src/org/broad/tribble/vcf/VCFCompoundHeaderLine.java +++ b/java/src/org/broad/tribble/vcf/VCFCompoundHeaderLine.java @@ -137,15 +137,22 @@ public abstract class VCFCompoundHeaderLine extends VCFHeaderLine implements VCF return false; VCFCompoundHeaderLine other = (VCFCompoundHeaderLine)o; return name.equals(other.name) && - count == other.count && - description.equals(other.description) && - type == other.type; + count == other.count && + description.equals(other.description) && + type == other.type && + lineType == other.lineType; } public boolean equalsExcludingDescription(VCFCompoundHeaderLine other) { return count == other.count && - type == other.type && - name.equals(other.name); + type == other.type && + lineType == other.lineType && + name.equals(other.name); + } + + public boolean sameLineTypeAndName(VCFCompoundHeaderLine other) { + return lineType == other.lineType && + name.equals(other.name); } /** diff --git a/java/src/org/broadinstitute/sting/gatk/walkers/annotator/VariantAnnotator.java b/java/src/org/broadinstitute/sting/gatk/walkers/annotator/VariantAnnotator.java index 671778b04..77e84768f 100755 --- a/java/src/org/broadinstitute/sting/gatk/walkers/annotator/VariantAnnotator.java +++ b/java/src/org/broadinstitute/sting/gatk/walkers/annotator/VariantAnnotator.java @@ -27,6 +27,7 @@ package org.broadinstitute.sting.gatk.walkers.annotator; import org.broad.tribble.vcf.VCFHeader; import org.broad.tribble.vcf.VCFHeaderLine; +import org.broad.tribble.vcf.VCFCompoundHeaderLine; import org.broadinstitute.sting.gatk.contexts.AlignmentContext; import org.broadinstitute.sting.gatk.contexts.ReferenceContext; import org.broadinstitute.sting.gatk.contexts.StratifiedAlignmentContext; @@ -134,10 +135,14 @@ public class VariantAnnotator extends RodWalker { engine = new VariantAnnotatorEngine(getToolkit(), annotationGroupsToUse, annotationsToUse); // setup the header fields + // note that if any of the definitions conflict with our new ones, then we want to overwrite the old ones Set hInfo = new HashSet(); - hInfo.addAll(VCFUtils.getHeaderFields(getToolkit(), Arrays.asList("variant"))); - hInfo.add(new VCFHeaderLine("source", "VariantAnnotator")); hInfo.addAll(engine.getVCFAnnotationDescriptions()); + hInfo.add(new VCFHeaderLine("source", "VariantAnnotator")); + for ( VCFHeaderLine line : VCFUtils.getHeaderFields(getToolkit(), Arrays.asList("variant")) ) { + if ( isUniqueHeaderLine(line, hInfo) ) + hInfo.add(line); + } vcfWriter = new VCFWriter(out); VCFHeader vcfHeader = new VCFHeader(hInfo, samples); @@ -148,6 +153,18 @@ public class VariantAnnotator extends RodWalker { } } + private static boolean isUniqueHeaderLine(VCFHeaderLine line, Set currentSet) { + if ( !(line instanceof VCFCompoundHeaderLine) ) + return true; + + for ( VCFHeaderLine hLine : currentSet ) { + if ( hLine instanceof VCFCompoundHeaderLine && ((VCFCompoundHeaderLine)line).sameLineTypeAndName((VCFCompoundHeaderLine)hLine) ) + return false; + } + + return true; + } + /** * Initialize the number of loci processed to zero. * diff --git a/java/test/org/broadinstitute/sting/gatk/walkers/annotator/VariantAnnotatorIntegrationTest.java b/java/test/org/broadinstitute/sting/gatk/walkers/annotator/VariantAnnotatorIntegrationTest.java index 9c2a989e5..801da7cb3 100755 --- a/java/test/org/broadinstitute/sting/gatk/walkers/annotator/VariantAnnotatorIntegrationTest.java +++ b/java/test/org/broadinstitute/sting/gatk/walkers/annotator/VariantAnnotatorIntegrationTest.java @@ -75,6 +75,14 @@ public class VariantAnnotatorIntegrationTest extends WalkerTest { executeTest("test file doesn't have annotations, asking for annotations, #2", spec); } + @Test + public void testOverwritingHeader() { + WalkerTestSpec spec = new WalkerTestSpec( + baseTestString() + " -G \"Standard\" -B variant,VCF," + validationDataLocation + "vcfexample4.vcf -I " + validationDataLocation + "NA12878.1kg.p2.chr1_10mb_11_mb.SLX.bam -L 1:10,001,292", 1, + Arrays.asList("87d124ddfee8537e2052c495777d2b3b")); + executeTest("test overwriting header", spec); + } + @Test public void testNoReads() { WalkerTestSpec spec = new WalkerTestSpec(