Skip to content

Commit

Permalink
Refactor VariantEval methods to allow subclass to override
Browse files Browse the repository at this point in the history
  • Loading branch information
bbimber authored and bbimber committed Jun 13, 2019
1 parent 4581998 commit 8bc60eb
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ private void checkForIncompatibleEvaluatorsAndStratifiers( final List<VariantStr
for ( Class<? extends VariantEvaluator> 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");
Expand All @@ -427,11 +427,15 @@ final void createStratificationStates(final List<VariantStratifier> 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<Class<? extends VariantEvaluator>> evaluationObjects) {
return new EvaluationContext(this, evaluationObjects);
}

private class PositionAggregator {
private SimpleInterval i = null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ public abstract class VariantEvaluator implements Comparable<VariantEvaluator> {
private VariantEval walker;
private final String simpleName;

protected VariantEvaluator(String simpleName) {
this.simpleName = simpleName;
}

protected VariantEvaluator() {
this.simpleName = getClass().getSimpleName();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<VariantEvaluator> evaluationInstances;
private final List<VariantEvaluator> evaluationInstances;
private final Set<Class<? extends VariantEvaluator>> evaluationClasses;

public EvaluationContext(final VariantEval walker, final Set<Class<? extends VariantEvaluator>> evaluationClasses) {
Expand All @@ -26,8 +27,11 @@ public EvaluationContext(final VariantEval walker, final Set<Class<? extends Var
private EvaluationContext(final VariantEval walker, final Set<Class<? extends VariantEvaluator>> evaluationClasses, final boolean doInitialize) {
this.walker = walker;
this.evaluationClasses = evaluationClasses;
this.evaluationInstances = new ArrayList<VariantEvaluator>(evaluationClasses.size());
this.evaluationInstances = initializeEvaluationInstances(doInitialize);
}

protected List<VariantEvaluator> initializeEvaluationInstances(boolean doInitialize) {
List<VariantEvaluator> ret = new ArrayList<>(evaluationClasses.size());
for ( final Class<? extends VariantEvaluator> c : evaluationClasses ) {
try {
final VariantEvaluator eval = c.newInstance();
Expand All @@ -39,6 +43,8 @@ private EvaluationContext(final VariantEval walker, final Set<Class<? extends Va
throw new GATKException("Illegal access error when trying to instantiate eval module '" + c.getSimpleName() + "'", e);
}
}

return ret;
}

/**
Expand Down

0 comments on commit 8bc60eb

Please sign in to comment.