diff --git a/src/main/java/org/broadinstitute/hellbender/tools/walkers/GenotypeGVCFsEngine.java b/src/main/java/org/broadinstitute/hellbender/tools/walkers/GenotypeGVCFsEngine.java index 6dc1d38c4dc..c6270834ebb 100644 --- a/src/main/java/org/broadinstitute/hellbender/tools/walkers/GenotypeGVCFsEngine.java +++ b/src/main/java/org/broadinstitute/hellbender/tools/walkers/GenotypeGVCFsEngine.java @@ -176,7 +176,8 @@ private VariantContext regenotypeVC(final VariantContext originalVC, final Refer // For polymorphic sites we need to make sure e.g. the SB tag is sent to the annotation engine and then removed later. // For monomorphic sites we need to make sure e.g. the hom ref genotypes are created and only then are passed to the annotation engine. // We could theoretically make 2 passes to re-create the genotypes, but that gets extremely expensive with large sample sizes. - if (result.isPolymorphicInSamples()) { + // Note that we also check depth because the previous conditions were also contingent on depth + if (result.isPolymorphicInSamples() && result.getAttributeAsInt(VCFConstants.DEPTH_KEY,0) > 0) { // For polymorphic sites we need to make sure e.g. the SB tag is sent to the annotation engine and then removed later. final VariantContextBuilder vcBuilder = new VariantContextBuilder(result); //don't count sites with no depth and no confidence towards things like AN and InbreedingCoeff diff --git a/src/main/java/org/broadinstitute/hellbender/tools/walkers/annotator/VariantAnnotatorEngine.java b/src/main/java/org/broadinstitute/hellbender/tools/walkers/annotator/VariantAnnotatorEngine.java index 228bc02ac8c..949cfa82a50 100644 --- a/src/main/java/org/broadinstitute/hellbender/tools/walkers/annotator/VariantAnnotatorEngine.java +++ b/src/main/java/org/broadinstitute/hellbender/tools/walkers/annotator/VariantAnnotatorEngine.java @@ -234,9 +234,9 @@ public Map combineAnnotations(final List allelesList, Ma final Map annotationsFromCurrentType = currentASannotation.combineRawData(allelesList, annotationValue); if (annotationsFromCurrentType != null) { combinedAnnotations.putAll(annotationsFromCurrentType); - //remove all the raw keys for the annotation because we already used all of them in combineRawData - annotationMap.keySet().removeAll(currentASannotation.getRawKeyNames()); } + //remove all the raw keys for the annotation because we already used all of them in combineRawData + annotationMap.keySet().removeAll(currentASannotation.getRawKeyNames()); } } } diff --git a/src/main/java/org/broadinstitute/hellbender/tools/walkers/annotator/allelespecific/AS_QualByDepth.java b/src/main/java/org/broadinstitute/hellbender/tools/walkers/annotator/allelespecific/AS_QualByDepth.java index 04b15685d7a..bc487d093d1 100644 --- a/src/main/java/org/broadinstitute/hellbender/tools/walkers/annotator/allelespecific/AS_QualByDepth.java +++ b/src/main/java/org/broadinstitute/hellbender/tools/walkers/annotator/allelespecific/AS_QualByDepth.java @@ -66,7 +66,7 @@ public boolean hasSecondaryRawKeys() { } @Override - public List getSecondaryRawKeys() { return Arrays.asList(GATKVCFConstants.AS_QUAL_KEY);} + public List getSecondaryRawKeys() { return Arrays.asList(GATKVCFConstants.AS_QUAL_KEY, GATKVCFConstants.AS_VARIANT_DEPTH_KEY);} @Override public List getRawDescriptions() { diff --git a/src/test/java/org/broadinstitute/hellbender/tools/walkers/GenotypeGVCFsIntegrationTest.java b/src/test/java/org/broadinstitute/hellbender/tools/walkers/GenotypeGVCFsIntegrationTest.java index f9a18f7d3c9..7aa6d7cad57 100644 --- a/src/test/java/org/broadinstitute/hellbender/tools/walkers/GenotypeGVCFsIntegrationTest.java +++ b/src/test/java/org/broadinstitute/hellbender/tools/walkers/GenotypeGVCFsIntegrationTest.java @@ -14,6 +14,7 @@ import org.broadinstitute.barclay.argparser.Argument; import org.broadinstitute.barclay.argparser.CommandLineException; import org.broadinstitute.hellbender.CommandLineProgramTest; +import org.broadinstitute.hellbender.cmdline.GATKPlugin.DefaultGATKVariantAnnotationArgumentCollection; import org.broadinstitute.hellbender.cmdline.StandardArgumentDefinitions; import org.broadinstitute.hellbender.exceptions.UserException; import org.broadinstitute.hellbender.testutils.ArgumentsBuilder; @@ -22,6 +23,8 @@ import org.broadinstitute.hellbender.tools.genomicsdb.GenomicsDBArgumentCollection; import org.broadinstitute.hellbender.tools.genomicsdb.GenomicsDBImport; import org.broadinstitute.hellbender.tools.walkers.annotator.RMSMappingQuality; +import org.broadinstitute.hellbender.tools.walkers.annotator.allelespecific.AS_QualByDepth; +import org.broadinstitute.hellbender.tools.walkers.genotyper.GenotypeCalculationArgumentCollection; import org.broadinstitute.hellbender.utils.SimpleInterval; import org.broadinstitute.hellbender.utils.Utils; import org.broadinstitute.hellbender.utils.io.IOUtils; @@ -734,4 +737,41 @@ public void testWithReblockedGVCF() { Assert.assertEquals(ic1, ic2, 0.1); //there will be some difference because the old version zeros out low depth hom-refs and makes them no-calls Assert.assertEquals(vcWithoutPLs.getAttributeAsInt(VCFConstants.ALLELE_NUMBER_KEY, 0), 114); //don't count no-calls that are PL=[0,0,0] in classic VCF } + + @Test + public void testMissingDPVariant() { + final File inputNoDP = getTestFile("homVarNoDP.g.vcf"); + final File outputNoDP = createTempFile("outputNoDP", ".vcf"); + + final ArgumentsBuilder args = new ArgumentsBuilder(); + args.addReference(hg38Reference) + .addVCF(inputNoDP) + .addOutput(outputNoDP) + .add(GenotypeCalculationArgumentCollection.CALL_CONFIDENCE_SHORT_NAME, 0); + runCommandLine(args); + + final List noDPVCs = VariantContextTestUtils.getVariantContexts(outputNoDP); + Assert.assertEquals(noDPVCs.size(), 0); + + final File input1DP = getTestFile("homVar1DP.g.vcf"); + final File output1DP = createTempFile("output1DP" ,".vcf"); + + final ArgumentsBuilder args2 = new ArgumentsBuilder(); + args2.addReference(hg38Reference) + .addVCF(input1DP) + .addOutput(output1DP) + .add(StandardArgumentDefinitions.ANNOTATION_GROUP_SHORT_NAME, "StandardAnnotation") + .add(StandardArgumentDefinitions.ANNOTATION_GROUP_SHORT_NAME, "AS_StandardAnnotation"); + runCommandLine(args2); + + //interfaces can't have static methods, so we have to create an annotation class to query its keys + final AS_QualByDepth annotation = new AS_QualByDepth(); + final List oneDPVCs = VariantContextTestUtils.getVariantContexts(output1DP); + Assert.assertEquals(oneDPVCs.size(), 1); + final VariantContext vc = oneDPVCs.get(0); + Assert.assertTrue(vc.getAttributes().keySet().containsAll(annotation.getKeyNames())); + Assert.assertFalse(vc.getAttributes().keySet().contains(annotation.getPrimaryRawKey())); + Assert.assertFalse(vc.getAttributes().keySet().contains(annotation.getSecondaryRawKeys().get(0))); + Assert.assertFalse(vc.getAttributes().keySet().contains(annotation.getSecondaryRawKeys().get(1))); + } } diff --git a/src/test/resources/org/broadinstitute/hellbender/tools/walkers/GenotypeGVCFs/homVar1DP.g.vcf b/src/test/resources/org/broadinstitute/hellbender/tools/walkers/GenotypeGVCFs/homVar1DP.g.vcf new file mode 100644 index 00000000000..f6ce6dfe675 --- /dev/null +++ b/src/test/resources/org/broadinstitute/hellbender/tools/walkers/GenotypeGVCFs/homVar1DP.g.vcf @@ -0,0 +1,62 @@ +##fileformat=VCFv4.2 +##ALT= +##FILTER= +##FILTER= +##FORMAT= +##FORMAT= +##FORMAT= +##FORMAT= +##FORMAT= +##FORMAT= +##FORMAT= +##FORMAT= +##FORMAT= +##GATKCommandLine= +##GATKCommandLine= +##GVCFBlock0-10=minGQ=0(inclusive),maxGQ=10(exclusive) +##GVCFBlock10-20=minGQ=10(inclusive),maxGQ=20(exclusive) +##GVCFBlock20-30=minGQ=20(inclusive),maxGQ=30(exclusive) +##GVCFBlock30-40=minGQ=30(inclusive),maxGQ=40(exclusive) +##GVCFBlock40-50=minGQ=40(inclusive),maxGQ=50(exclusive) +##GVCFBlock50-60=minGQ=50(inclusive),maxGQ=60(exclusive) +##GVCFBlock60-100=minGQ=60(inclusive),maxGQ=100(exclusive) +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##contig= +##reference=file:///Users/gauthier/workspaces/gatk/src/test/resources/large/Homo_sapiens_assembly38.fasta.gz +##source=GenomicsDBImport +##source=SelectVariants +#CHROM POS ID REF ALT QUAL FILTER INFO FORMAT CHMI_CHMI3_Nex1 NA12878 NA12891 NA12892 NA19238 NA20845 NA20846 NA20847 NA20849 NA20850 NA20851 NA20852 NA20853 NA20854 NA20856 NA20858 NA20859 NA20861 NA20862 NA20866 NA20869 NA20870 NA20871 NA20872 NA20873 NA20874 NA20875 NA20876 NA20877 NA20878 NA20881 NA20885 NA20886 NA20887 NA20888 NA20889 NA20890 NA20891 NA20892 NA20893 NA20894 NA20895 NA20896 NA20897 NA20898 NA20899 NA20901 NA20902 NA20903 NA20904 NA20905 NA20906 NA20908 NA20910 NA20911 NA21086 NA21087 NA21088 NA21093 NA21095 NA21114 NA21124 NA21126 NA21129 NA21137 +chr4 189917428 . C G, . . AS_QUALapprox=|45|;AS_RAW_BaseQRankSum=||;AS_RAW_MQ=0.000|0.000|0.000;AS_RAW_MQRankSum=||;AS_RAW_ReadPosRankSum=||;AS_SB_TABLE=0,0|0,0|0,0;AS_VarDP=0|0|0;DP=1;MQ_DP=0;QUALapprox=45;RAW_GT_COUNT=0,0,1;RAW_MQandDP=0,0;VarDP=1 GT:AD:GQ:PGT:PID:PL:SB:DP .:.:.:.:.:.:.:. .:.:.:.:.:.:.:. .:.:.:.:.:.:.:. .:.:.:.:.:.:.:. .:.:.:.:.:.:.:. .:.:.:.:.:.:.:. .:.:.:.:.:.:.:. .:.:.:.:.:.:.:. .:.:.:.:.:.:.:. .:.:.:.:.:.:.:. .:.:.:.:.:.:.:. .:.:.:.:.:.:.:. .:.:.:.:.:.:.:. .:.:.:.:.:.:.:. .:.:.:.:.:.:.:. .:.:.:.:.:.:.:. .:.:.:.:.:.:.:. .:.:.:.:.:.:.:. .:.:.:.:.:.:.:. .:.:.:.:.:.:.:. .:.:.:.:.:.:.:. .:.:.:.:.:.:.:. .:.:.:.:.:.:.:. .:.:.:.:.:.:.:. .:.:.:.:.:.:.:. .:.:.:.:.:.:.:. .:.:.:.:.:.:.:. .:.:.:.:.:.:.:. .:.:.:.:.:.:.:. .:.:.:.:.:.:.:. .:.:.:.:.:.:.:. .:.:.:.:.:.:.:. .:.:.:.:.:.:.:. .:.:.:.:.:.:.:. .:.:.:.:.:.:.:. .:.:.:.:.:.:.:. .:.:.:.:.:.:.:. .:.:.:.:.:.:.:. .:.:.:.:.:.:.:. .:.:.:.:.:.:.:. .:.:.:.:.:.:.:. .:.:.:.:.:.:.:. .:.:.:.:.:.:.:. .:.:.:.:.:.:.:. .:.:.:.:.:.:.:. .:.:.:.:.:.:.:. .:.:.:.:.:.:.:. .:.:.:.:.:.:.:. .:.:.:.:.:.:.:. .:.:.:.:.:.:.:. .:.:.:.:.:.:.:. .:.:.:.:.:.:.:. .:.:.:.:.:.:.:. .:.:.:.:.:.:.:. .:.:.:.:.:.:.:. .:.:.:.:.:.:.:. .:.:.:.:.:.:.:. .:.:.:.:.:.:.:. .:.:.:.:.:.:.:. .:.:.:.:.:.:.:. .:.:.:.:.:.:.:. 1/1:0,0,0:3:0|1:189917424_A_G:45,3,0,45,3,45:0,0,0,0:0 .:.:.:.:.:.:.:. .:.:.:.:.:.:.:. .:.:.:.:.:.:.:. diff --git a/src/test/resources/org/broadinstitute/hellbender/tools/walkers/GenotypeGVCFs/homVar1DP.g.vcf.idx b/src/test/resources/org/broadinstitute/hellbender/tools/walkers/GenotypeGVCFs/homVar1DP.g.vcf.idx new file mode 100644 index 00000000000..6022d01bfd8 Binary files /dev/null and b/src/test/resources/org/broadinstitute/hellbender/tools/walkers/GenotypeGVCFs/homVar1DP.g.vcf.idx differ diff --git a/src/test/resources/org/broadinstitute/hellbender/tools/walkers/GenotypeGVCFs/homVarNoDP.g.vcf b/src/test/resources/org/broadinstitute/hellbender/tools/walkers/GenotypeGVCFs/homVarNoDP.g.vcf new file mode 100644 index 00000000000..e886184b6e6 --- /dev/null +++ b/src/test/resources/org/broadinstitute/hellbender/tools/walkers/GenotypeGVCFs/homVarNoDP.g.vcf @@ -0,0 +1,62 @@ +##fileformat=VCFv4.2 +##ALT= +##FILTER= +##FILTER= +##FORMAT= +##FORMAT= +##FORMAT= +##FORMAT= +##FORMAT= +##FORMAT= +##FORMAT= +##FORMAT= +##FORMAT= +##GATKCommandLine= +##GATKCommandLine= +##GVCFBlock0-10=minGQ=0(inclusive),maxGQ=10(exclusive) +##GVCFBlock10-20=minGQ=10(inclusive),maxGQ=20(exclusive) +##GVCFBlock20-30=minGQ=20(inclusive),maxGQ=30(exclusive) +##GVCFBlock30-40=minGQ=30(inclusive),maxGQ=40(exclusive) +##GVCFBlock40-50=minGQ=40(inclusive),maxGQ=50(exclusive) +##GVCFBlock50-60=minGQ=50(inclusive),maxGQ=60(exclusive) +##GVCFBlock60-100=minGQ=60(inclusive),maxGQ=100(exclusive) +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##contig= +##reference=file:///Users/gauthier/workspaces/gatk/src/test/resources/large/Homo_sapiens_assembly38.fasta.gz +##source=GenomicsDBImport +##source=SelectVariants +#CHROM POS ID REF ALT QUAL FILTER INFO FORMAT CHMI_CHMI3_Nex1 NA12878 NA12891 NA12892 NA19238 NA20845 NA20846 NA20847 NA20849 NA20850 NA20851 NA20852 NA20853 NA20854 NA20856 NA20858 NA20859 NA20861 NA20862 NA20866 NA20869 NA20870 NA20871 NA20872 NA20873 NA20874 NA20875 NA20876 NA20877 NA20878 NA20881 NA20885 NA20886 NA20887 NA20888 NA20889 NA20890 NA20891 NA20892 NA20893 NA20894 NA20895 NA20896 NA20897 NA20898 NA20899 NA20901 NA20902 NA20903 NA20904 NA20905 NA20906 NA20908 NA20910 NA20911 NA21086 NA21087 NA21088 NA21093 NA21095 NA21114 NA21124 NA21126 NA21129 NA21137 +chr4 189917428 .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.:.:.:.:.:.:.:. .:.:.:.:.:.:.:. .:.:.:.:.:.:.:. .:.:.:.:.:.:.:. .:.:.:.:.:.:.:. .:.:.:.:.:.:.:. .:.:.:.:.:.:.:. 1/1:0,0,0:3:0|1:189917424_A_G:45,3,0,45,3,45:0,0,0,0:0 .:.:.:.:.:.:.:. .:.:.:.:.:.:.:. .:.:.:.:.:.:.:. diff --git a/src/test/resources/org/broadinstitute/hellbender/tools/walkers/GenotypeGVCFs/homVarNoDP.g.vcf.idx b/src/test/resources/org/broadinstitute/hellbender/tools/walkers/GenotypeGVCFs/homVarNoDP.g.vcf.idx new file mode 100644 index 00000000000..243b82c214a Binary files /dev/null and b/src/test/resources/org/broadinstitute/hellbender/tools/walkers/GenotypeGVCFs/homVarNoDP.g.vcf.idx differ