From fb3421aab7c9acef5152f324f8dd2abc83e09d63 Mon Sep 17 00:00:00 2001 From: bbimber Date: Wed, 12 Jun 2019 10:30:40 -0700 Subject: [PATCH] Refactor VariantEval methods to allow subclass to override --- .../walkers/varianteval/VariantEval.java | 14 +++++++-- .../evaluators/VariantEvaluator.java | 4 +++ .../varianteval/util/EvaluationContext.java | 29 +++++++++++++++---- 3 files changed, 40 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/broadinstitute/hellbender/tools/walkers/varianteval/VariantEval.java b/src/main/java/org/broadinstitute/hellbender/tools/walkers/varianteval/VariantEval.java index 765e34fb0cd..084bf89ef70 100644 --- a/src/main/java/org/broadinstitute/hellbender/tools/walkers/varianteval/VariantEval.java +++ b/src/main/java/org/broadinstitute/hellbender/tools/walkers/varianteval/VariantEval.java @@ -414,7 +414,7 @@ private void checkForIncompatibleEvaluatorsAndStratifiers( final List ec : evaluationClasses ) if ( vs.getIncompatibleEvaluators().contains(ec) ) throw new CommandLineException.BadArgumentValue("ST and ET", - "The selected stratification " + vs.getName() + + "The selected stratification " + vs.getName() + " and evaluator " + ec.getSimpleName() + " are incompatible due to combinatorial memory requirements." + " Please disable one"); @@ -427,11 +427,21 @@ final void createStratificationStates(final List stratificati logger.info("Creating " + stratManager.size() + " combinatorial stratification states"); for ( int i = 0; i < stratManager.size(); i++ ) { - EvaluationContext ec = new EvaluationContext(this, evaluationObjects); + EvaluationContext ec = createEvaluationContext(evaluationObjects); stratManager.set(i, ec); } } + /** + * Create the EvaluationContext (new instance) for the provided set of VariantEvaluators. + * + * @param evaluationObjects The list of VariantEvaluator classes + * @return The EvaluationContext for this set of VariantEvaluator classes + */ + protected EvaluationContext createEvaluationContext(final Set> evaluationObjects) { + return new EvaluationContext(this, evaluationObjects); + } + private class PositionAggregator { private SimpleInterval i = null; diff --git a/src/main/java/org/broadinstitute/hellbender/tools/walkers/varianteval/evaluators/VariantEvaluator.java b/src/main/java/org/broadinstitute/hellbender/tools/walkers/varianteval/evaluators/VariantEvaluator.java index e14398c9aec..020caf6394e 100644 --- a/src/main/java/org/broadinstitute/hellbender/tools/walkers/varianteval/evaluators/VariantEvaluator.java +++ b/src/main/java/org/broadinstitute/hellbender/tools/walkers/varianteval/evaluators/VariantEvaluator.java @@ -11,6 +11,10 @@ public abstract class VariantEvaluator implements Comparable { private VariantEval walker; private final String simpleName; + protected VariantEvaluator(String simpleName) { + this.simpleName = simpleName; + } + protected VariantEvaluator() { this.simpleName = getClass().getSimpleName(); } diff --git a/src/main/java/org/broadinstitute/hellbender/tools/walkers/varianteval/util/EvaluationContext.java b/src/main/java/org/broadinstitute/hellbender/tools/walkers/varianteval/util/EvaluationContext.java index 60b3656fcdf..1078e6dd134 100644 --- a/src/main/java/org/broadinstitute/hellbender/tools/walkers/varianteval/util/EvaluationContext.java +++ b/src/main/java/org/broadinstitute/hellbender/tools/walkers/varianteval/util/EvaluationContext.java @@ -10,13 +10,14 @@ import org.broadinstitute.hellbender.tools.walkers.varianteval.stratifications.manager.StratificationManager; import java.util.ArrayList; +import java.util.List; import java.util.Set; import java.util.TreeSet; -public final class EvaluationContext { +public class EvaluationContext { // NOTE: must be hashset to avoid O(log n) cost of iteration in the very frequently called apply function final VariantEval walker; - private final ArrayList evaluationInstances; + private final List evaluationInstances; private final Set> evaluationClasses; public EvaluationContext(final VariantEval walker, final Set> evaluationClasses) { @@ -26,7 +27,7 @@ public EvaluationContext(final VariantEval walker, final Set> evaluationClasses, final boolean doInitialize) { this.walker = walker; this.evaluationClasses = evaluationClasses; - this.evaluationInstances = new ArrayList(evaluationClasses.size()); + this.evaluationInstances = new ArrayList<>(evaluationClasses.size()); for ( final Class c : evaluationClasses ) { try { @@ -41,13 +42,31 @@ private EvaluationContext(final VariantEval walker, final Set getEvaluationInstances() { + return evaluationInstances; + } + + /** + * Returns a set of VariantEvaluator classes to be used + * + * @return The set of VariantEvaluator classes to be used + */ + public Set> getEvaluationClasses() { + return evaluationClasses; + } + /** * Returns a sorted set of VariantEvaluators * - * @return + * @return A sorted set of VariantEvaluator instances */ public final TreeSet getVariantEvaluators() { - return new TreeSet(evaluationInstances); + return new TreeSet<>(evaluationInstances); } public final void apply(ReferenceContext referenceContext, ReadsContext readsContext, FeatureContext featureContext, VariantContext comp, VariantContext eval) {