Skip to content

Commit

Permalink
VariantAnnotator fails when the variant contains too many alleles (#8075
Browse files Browse the repository at this point in the history
)

* protect VariantAnnotator from failing variantOverlapAnnotator
Co-authored-by: Dror Kessler <dror27.kessler@gmail.com>
  • Loading branch information
ilyasoifer authored Nov 3, 2022
1 parent b652c1a commit 63c548b
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -478,4 +478,11 @@ public static final class ValidationFailure extends UserException {

public ValidationFailure(String message) { super(message); }
}

public static final class WarnableAnnotationFailure extends UserException {
private static final long serialVersionUID = 0L;

public WarnableAnnotationFailure(String message) { super(message); }

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.broadinstitute.hellbender.tools.walkers.GenotypeGVCFsAnnotationArgumentCollection;
import org.broadinstitute.hellbender.tools.walkers.annotator.allelespecific.ReducibleAnnotation;
import org.broadinstitute.hellbender.tools.walkers.annotator.allelespecific.ReducibleAnnotationData;
import org.broadinstitute.hellbender.utils.IntervalUtils;
import org.broadinstitute.hellbender.utils.Utils;
import org.broadinstitute.hellbender.utils.genotyper.AlleleLikelihoods;
import org.broadinstitute.hellbender.utils.haplotype.Haplotype;
Expand Down Expand Up @@ -365,7 +366,12 @@ public VariantContext annotateContext(final VariantContext vc,
final VariantContext annotated = builder.attributes(infoAnnotMap).make();

// annotate db occurrences
return variantOverlapAnnotator.annotateOverlaps(features, variantOverlapAnnotator.annotateRsID(features, annotated));
try {
return variantOverlapAnnotator.annotateOverlaps(features, variantOverlapAnnotator.annotateRsID(features, annotated));
} catch (UserException.WarnableAnnotationFailure e) {
logger.warn("failed to apply variantOverlapAnnotator to VC at " + IntervalUtils.locatableToString(annotated) + ": " + e.getMessage());
return annotated;
}
}

private Map<String, Object> addInfoAnnotations(VariantContext vc, FeatureContext features, ReferenceContext ref,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.broadinstitute.hellbender.tools.walkers.genotyper;

import org.broadinstitute.hellbender.exceptions.GATKException;
import org.broadinstitute.hellbender.exceptions.UserException;
import org.broadinstitute.hellbender.utils.MathUtils;
import org.broadinstitute.hellbender.utils.Utils;
import org.apache.logging.log4j.LogManager;
Expand Down Expand Up @@ -273,7 +274,7 @@ private synchronized void calculateGenotypeCountsUsingTablesAndValidate(final in

if (calculateGenotypeCountUsingTables(ploidy, alleleCount) == GENOTYPE_COUNT_OVERFLOW) {
final double largeGenotypeCount = Math.pow(10, MathUtils.log10BinomialCoefficient(ploidy + alleleCount - 1, alleleCount - 1));
throw new IllegalArgumentException(String.format("the number of genotypes is too large for ploidy %d and allele %d: approx. %.0f", ploidy, alleleCount, largeGenotypeCount));
throw new UserException.WarnableAnnotationFailure(String.format("the number of genotypes is too large for ploidy %d and allele %d: approx. %.0f", ploidy, alleleCount, largeGenotypeCount));
}
}

Expand Down Expand Up @@ -368,7 +369,7 @@ public int genotypeCount(final int ploidy, final int alleleCount) {
final int result = calculateGenotypeCountUsingTables(ploidy, alleleCount);
if (result == GENOTYPE_COUNT_OVERFLOW) {
final double largeGenotypeCount = Math.pow(10, MathUtils.log10BinomialCoefficient(ploidy + alleleCount - 1, alleleCount - 1));
throw new IllegalArgumentException(String.format("the number of genotypes is too large for ploidy %d and allele %d: approx. %.0f", ploidy, alleleCount, largeGenotypeCount));
throw new UserException.WarnableAnnotationFailure(String.format("the number of genotypes is too large for ploidy %d and allele %d: approx. %.0f", ploidy, alleleCount, largeGenotypeCount));
}
return result;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.broadinstitute.hellbender.tools.walkers.genotyper;

import org.broadinstitute.hellbender.GATKBaseTest;
import org.broadinstitute.hellbender.exceptions.UserException;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
Expand Down Expand Up @@ -75,7 +76,7 @@ public void testInstanceNewInstance(int ploidy, int alleleCount, int expected) t
}
}

@Test(expectedExceptions = IllegalArgumentException.class)
@Test(expectedExceptions = UserException.WarnableAnnotationFailure.class)
public void testGenotypeCountOverflow() throws Exception {
final int genotypeCount = new GenotypeLikelihoodCalculators().genotypeCount(10_000, 10_000);
}
Expand Down

0 comments on commit 63c548b

Please sign in to comment.