VariantEval optimization
-- Use a LinkedHashMap not a TreeMap so iteration is faster. -- Note that with a lot of stratifications the update0 is taking up a lot of time. For example, with 822 samples and functional class and sample on there are 100K contexts and 30% of the runtime is just in the update0 call
This commit is contained in:
parent
a0602e534c
commit
fee8d86f63
|
|
@ -326,7 +326,7 @@ public class VariantEvalWalker extends RodWalker<Integer, Integer> implements Tr
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Integer map(RefMetaDataTracker tracker, ReferenceContext ref, AlignmentContext context) {
|
public Integer map(RefMetaDataTracker tracker, ReferenceContext ref, AlignmentContext context) {
|
||||||
for ( NewEvaluationContext nec : evaluationContexts.values() ) {
|
for ( final NewEvaluationContext nec : evaluationContexts.values() ) {
|
||||||
synchronized (nec) {
|
synchronized (nec) {
|
||||||
nec.update0(tracker, ref, context);
|
nec.update0(tracker, ref, context);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,29 +10,17 @@ import org.broadinstitute.sting.utils.exceptions.ReviewedStingException;
|
||||||
import org.broadinstitute.sting.utils.exceptions.StingException;
|
import org.broadinstitute.sting.utils.exceptions.StingException;
|
||||||
import org.broadinstitute.sting.utils.variantcontext.VariantContext;
|
import org.broadinstitute.sting.utils.variantcontext.VariantContext;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.*;
|
||||||
import java.util.Set;
|
|
||||||
import java.util.TreeMap;
|
|
||||||
|
|
||||||
public class NewEvaluationContext extends HashMap<VariantStratifier, String> {
|
public class NewEvaluationContext extends HashMap<VariantStratifier, String> {
|
||||||
public TreeMap<String, VariantEvaluator> evaluationInstances;
|
private Map<String, VariantEvaluator> evaluationInstances;
|
||||||
|
|
||||||
public String toString() {
|
|
||||||
String value = "";
|
|
||||||
|
|
||||||
for ( VariantStratifier key : this.keySet() ) {
|
|
||||||
value += "\t" + key.getName() + ":" + this.get(key) + "\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addEvaluationClassList(VariantEvalWalker walker, StateKey stateKey, Set<Class<? extends VariantEvaluator>> evaluationClasses) {
|
public void addEvaluationClassList(VariantEvalWalker walker, StateKey stateKey, Set<Class<? extends VariantEvaluator>> evaluationClasses) {
|
||||||
evaluationInstances = new TreeMap<String, VariantEvaluator>();
|
evaluationInstances = new LinkedHashMap<String, VariantEvaluator>(evaluationClasses.size());
|
||||||
|
|
||||||
for ( Class<? extends VariantEvaluator> c : evaluationClasses ) {
|
for ( final Class<? extends VariantEvaluator> c : evaluationClasses ) {
|
||||||
try {
|
try {
|
||||||
VariantEvaluator eval = c.newInstance();
|
final VariantEvaluator eval = c.newInstance();
|
||||||
eval.initialize(walker);
|
eval.initialize(walker);
|
||||||
|
|
||||||
if (eval.stateIsApplicable(stateKey)) {
|
if (eval.stateIsApplicable(stateKey)) {
|
||||||
|
|
@ -47,11 +35,11 @@ public class NewEvaluationContext extends HashMap<VariantStratifier, String> {
|
||||||
}
|
}
|
||||||
|
|
||||||
public TreeMap<String, VariantEvaluator> getEvaluationClassList() {
|
public TreeMap<String, VariantEvaluator> getEvaluationClassList() {
|
||||||
return evaluationInstances;
|
return new TreeMap<String, VariantEvaluator>(evaluationInstances);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void apply(RefMetaDataTracker tracker, ReferenceContext ref, AlignmentContext context, VariantContext comp, VariantContext eval) {
|
public void apply(RefMetaDataTracker tracker, ReferenceContext ref, AlignmentContext context, VariantContext comp, VariantContext eval) {
|
||||||
for ( VariantEvaluator evaluation : evaluationInstances.values() ) {
|
for ( final VariantEvaluator evaluation : evaluationInstances.values() ) {
|
||||||
// we always call update0 in case the evaluation tracks things like number of bases covered
|
// we always call update0 in case the evaluation tracks things like number of bases covered
|
||||||
|
|
||||||
// the other updateN methods don't see a null context
|
// the other updateN methods don't see a null context
|
||||||
|
|
@ -79,7 +67,7 @@ public class NewEvaluationContext extends HashMap<VariantStratifier, String> {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void update0(RefMetaDataTracker tracker, ReferenceContext ref, AlignmentContext context) {
|
public void update0(RefMetaDataTracker tracker, ReferenceContext ref, AlignmentContext context) {
|
||||||
for ( VariantEvaluator evaluation : evaluationInstances.values() ) {
|
for ( final VariantEvaluator evaluation : evaluationInstances.values() ) {
|
||||||
evaluation.update0(tracker, ref, context);
|
evaluation.update0(tracker, ref, context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -191,7 +191,7 @@ public class VariantEvalUtils {
|
||||||
* @return a map of all the evaluation contexts
|
* @return a map of all the evaluation contexts
|
||||||
*/
|
*/
|
||||||
public HashMap<StateKey, NewEvaluationContext> initializeEvaluationContexts(Set<VariantStratifier> stratificationObjects, Set<Class<? extends VariantEvaluator>> evaluationObjects, Stack<VariantStratifier> stratStack, NewEvaluationContext ec) {
|
public HashMap<StateKey, NewEvaluationContext> initializeEvaluationContexts(Set<VariantStratifier> stratificationObjects, Set<Class<? extends VariantEvaluator>> evaluationObjects, Stack<VariantStratifier> stratStack, NewEvaluationContext ec) {
|
||||||
HashMap<StateKey, NewEvaluationContext> ecs = new HashMap<StateKey, NewEvaluationContext>();
|
HashMap<StateKey, NewEvaluationContext> ecs = new LinkedHashMap<StateKey, NewEvaluationContext>();
|
||||||
|
|
||||||
if (stratStack == null) {
|
if (stratStack == null) {
|
||||||
stratStack = new Stack<VariantStratifier>();
|
stratStack = new Stack<VariantStratifier>();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue