From 8bc60eb792f377481bdc3485c8f3d0dcf0d1cc6d 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 --- .../tools/walkers/varianteval/VariantEval.java | 8 ++++++-- .../varianteval/evaluators/VariantEvaluator.java | 4 ++++ .../walkers/varianteval/util/EvaluationContext.java | 12 +++++++++--- 3 files changed, 19 insertions(+), 5 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..3bdf0ebb40f 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,15 @@ 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 = getEvaluationContext(evaluationObjects); stratManager.set(i, ec); } } + protected EvaluationContext getEvaluationContext(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..11822151b37 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,8 +27,11 @@ 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 = initializeEvaluationInstances(doInitialize); + } + protected List initializeEvaluationInstances(boolean doInitialize) { + List ret = new ArrayList<>(evaluationClasses.size()); for ( final Class c : evaluationClasses ) { try { final VariantEvaluator eval = c.newInstance(); @@ -39,6 +43,8 @@ private EvaluationContext(final VariantEval walker, final Set