Fix for Kiran: since the Variant Annotator will re-annotate on top of existing annotations it makes sense to remove old headers if they conflict with the definitions being added by VA.

git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@3951 348d0f76-0448-11de-a6fe-93d51630548a
This commit is contained in:
ebanks 2010-08-05 06:44:39 +00:00
parent 1539791a04
commit 07addf1187
3 changed files with 39 additions and 7 deletions

View File

@ -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);
}
/**

View File

@ -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<Integer, Integer> {
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<VCFHeaderLine> hInfo = new HashSet<VCFHeaderLine>();
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<Integer, Integer> {
}
}
private static boolean isUniqueHeaderLine(VCFHeaderLine line, Set<VCFHeaderLine> 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.
*

View File

@ -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(