From c09ed609ff15ebab6114522c48bda4bf12188446 Mon Sep 17 00:00:00 2001 From: Megan Shand Date: Tue, 11 Jun 2024 16:22:02 -0400 Subject: [PATCH 1/2] fixing bug when removing annotations from empty map clean up better --- .../walkers/variantutils/ReblockGVCF.java | 5 ++ .../ReblockGVCFIntegrationTest.java | 17 ++++++- .../ReblockGVCF/gvcfWithNoPRI.vcf | 50 +++++++++++++++++++ 3 files changed, 70 insertions(+), 2 deletions(-) create mode 100644 src/test/resources/org/broadinstitute/hellbender/tools/walkers/variantutils/ReblockGVCF/gvcfWithNoPRI.vcf diff --git a/src/main/java/org/broadinstitute/hellbender/tools/walkers/variantutils/ReblockGVCF.java b/src/main/java/org/broadinstitute/hellbender/tools/walkers/variantutils/ReblockGVCF.java index 9b23601c32e..62d417bc4ca 100644 --- a/src/main/java/org/broadinstitute/hellbender/tools/walkers/variantutils/ReblockGVCF.java +++ b/src/main/java/org/broadinstitute/hellbender/tools/walkers/variantutils/ReblockGVCF.java @@ -351,6 +351,11 @@ public void apply(VariantContext variant, ReadsContext reads, ReferenceContext r private VariantContext removeVCFFormatAnnotations(final VariantContext vc) { final Genotype genotype = vc.getGenotype(0); Map extendedAttributes = genotype.getExtendedAttributes(); + // If extendedAttributes is empty, we get an unmodifiable empty map, so skip removing any annotations + if (extendedAttributes.isEmpty()) { + return vc; + } + for (String annotation : annotationsToRemove) { extendedAttributes.remove(annotation); } diff --git a/src/test/java/org/broadinstitute/hellbender/tools/walkers/variantutils/ReblockGVCFIntegrationTest.java b/src/test/java/org/broadinstitute/hellbender/tools/walkers/variantutils/ReblockGVCFIntegrationTest.java index 6cb90c93150..862587d6657 100644 --- a/src/test/java/org/broadinstitute/hellbender/tools/walkers/variantutils/ReblockGVCFIntegrationTest.java +++ b/src/test/java/org/broadinstitute/hellbender/tools/walkers/variantutils/ReblockGVCFIntegrationTest.java @@ -1,6 +1,5 @@ package org.broadinstitute.hellbender.tools.walkers.variantutils; -import htsjdk.samtools.util.IOUtil; import htsjdk.variant.variantcontext.Allele; import htsjdk.variant.variantcontext.Genotype; import htsjdk.variant.variantcontext.VariantContext; @@ -17,7 +16,6 @@ import org.broadinstitute.hellbender.testutils.IntegrationTestSpec; import org.broadinstitute.hellbender.testutils.VariantContextTestUtils; import org.broadinstitute.hellbender.tools.walkers.genotyper.GenotypeCalculationArgumentCollection; -import org.broadinstitute.hellbender.tools.walkers.haplotypecaller.HaplotypeCallerArgumentCollection; import org.broadinstitute.hellbender.utils.variant.GATKVCFConstants; import org.testng.Assert; import org.testng.annotations.DataProvider; @@ -701,4 +699,19 @@ public void testSpanDelRegression() throws IOException { //no more star alleles because deletions are all gone Assert.assertFalse(variants.stream().anyMatch(v -> v.getAlternateAlleles().contains(Allele.SPAN_DEL))); } + + @Test + public void warnWhenRemovingAnnotations() { + final File input = getTestFile("gvcfWithNoPRI.vcf"); + final File output = createTempFile("reblockedgvcf", ".vcf"); + final ArgumentsBuilder args = new ArgumentsBuilder(); + + args.addReference(hg38Reference) + .addVCF(input) + .addOutput(output) + .add("format-annotations-to-remove","PRI"); + + //make sure it doesn't error + runCommandLine(args); + } } diff --git a/src/test/resources/org/broadinstitute/hellbender/tools/walkers/variantutils/ReblockGVCF/gvcfWithNoPRI.vcf b/src/test/resources/org/broadinstitute/hellbender/tools/walkers/variantutils/ReblockGVCF/gvcfWithNoPRI.vcf new file mode 100644 index 00000000000..31da4b8498f --- /dev/null +++ b/src/test/resources/org/broadinstitute/hellbender/tools/walkers/variantutils/ReblockGVCF/gvcfWithNoPRI.vcf @@ -0,0 +1,50 @@ +##fileformat=VCFv4.2 +##ALT= +##FILTER= +##FORMAT= +##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-70=minGQ=60(inclusive),maxGQ=70(exclusive) +##GVCFBlock70-80=minGQ=70(inclusive),maxGQ=80(exclusive) +##GVCFBlock80-90=minGQ=80(inclusive),maxGQ=90(exclusive) +##GVCFBlock90-100=minGQ=90(inclusive),maxGQ=100(exclusive) +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##INFO= +##contig= +##source=HaplotypeCaller +##source=SelectVariants +#CHROM POS ID REF ALT QUAL FILTER INFO FORMAT CHMI_CHMI3_Nex1 +chr1 205592383 . T A, 0.01 . AS_RAW_BaseQRankSum=||;AS_RAW_MQ=0.00|0.00|0.00;AS_RAW_MQRankSum=||;AS_RAW_ReadPosRankSum=||;AS_SB_TABLE=0,0|0,0|0,0;ExcessHet=3.0103;MLEAC=0,0;MLEAF=NaN,NaN GT:PL ./.:0,0,0,0,0,0 From 2e995fa1d77b49dcc0fc8dfd0ec0408fcd291b35 Mon Sep 17 00:00:00 2001 From: Megan Shand Date: Fri, 14 Jun 2024 09:08:09 -0400 Subject: [PATCH 2/2] addressing comments --- .../tools/walkers/variantutils/ReblockGVCFIntegrationTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/org/broadinstitute/hellbender/tools/walkers/variantutils/ReblockGVCFIntegrationTest.java b/src/test/java/org/broadinstitute/hellbender/tools/walkers/variantutils/ReblockGVCFIntegrationTest.java index 862587d6657..7d8885044b4 100644 --- a/src/test/java/org/broadinstitute/hellbender/tools/walkers/variantutils/ReblockGVCFIntegrationTest.java +++ b/src/test/java/org/broadinstitute/hellbender/tools/walkers/variantutils/ReblockGVCFIntegrationTest.java @@ -701,7 +701,7 @@ public void testSpanDelRegression() throws IOException { } @Test - public void warnWhenRemovingAnnotations() { + public void testRemovingAnnotationFromEmptyAttributes() { final File input = getTestFile("gvcfWithNoPRI.vcf"); final File output = createTempFile("reblockedgvcf", ".vcf"); final ArgumentsBuilder args = new ArgumentsBuilder();