First version of VariantEval that runs (approximately correctly) with new StratificationManager
This commit is contained in:
parent
8971b54b21
commit
d37f31e349
|
|
@ -21,6 +21,8 @@ import org.broadinstitute.sting.gatk.walkers.Window;
|
|||
import org.broadinstitute.sting.gatk.walkers.varianteval.evaluators.VariantEvaluator;
|
||||
import org.broadinstitute.sting.gatk.walkers.varianteval.stratifications.IntervalStratification;
|
||||
import org.broadinstitute.sting.gatk.walkers.varianteval.stratifications.VariantStratifier;
|
||||
import org.broadinstitute.sting.gatk.walkers.varianteval.stratifications.manager.SetOfStates;
|
||||
import org.broadinstitute.sting.gatk.walkers.varianteval.stratifications.manager.StratificationManager;
|
||||
import org.broadinstitute.sting.gatk.walkers.varianteval.util.*;
|
||||
import org.broadinstitute.sting.utils.GenomeLoc;
|
||||
import org.broadinstitute.sting.utils.GenomeLocParser;
|
||||
|
|
@ -199,10 +201,7 @@ public class VariantEvalWalker extends RodWalker<Integer, Integer> implements Tr
|
|||
private int numSamples = 0;
|
||||
|
||||
// The list of stratifiers and evaluators to use
|
||||
private TreeSet<VariantStratifier> stratificationObjects = null;
|
||||
|
||||
// The set of all possible evaluation contexts
|
||||
private HashMap<StateKey, NewEvaluationContext> evaluationContexts = null;
|
||||
private List<VariantStratifier> stratificationObjects = null;
|
||||
|
||||
// important stratifications
|
||||
private boolean byFilterIsEnabled = false;
|
||||
|
|
@ -223,6 +222,9 @@ public class VariantEvalWalker extends RodWalker<Integer, Integer> implements Tr
|
|||
// Ancestral alignments
|
||||
private IndexedFastaSequenceFile ancestralAlignments = null;
|
||||
|
||||
// The set of all possible evaluation contexts
|
||||
StratificationManager<VariantStratifier, NewEvaluationContext> stratManager;
|
||||
|
||||
/**
|
||||
* Initialize the stratifications, evaluations, evaluation contexts, and reporting object
|
||||
*/
|
||||
|
|
@ -269,6 +271,7 @@ public class VariantEvalWalker extends RodWalker<Integer, Integer> implements Tr
|
|||
// Initialize the set of stratifications and evaluations to use
|
||||
stratificationObjects = variantEvalUtils.initializeStratificationObjects(this, NO_STANDARD_STRATIFICATIONS, STRATIFICATIONS_TO_USE);
|
||||
Set<Class<? extends VariantEvaluator>> evaluationObjects = variantEvalUtils.initializeEvaluationObjects(NO_STANDARD_MODULES, MODULES_TO_USE);
|
||||
|
||||
for ( VariantStratifier vs : stratificationObjects ) {
|
||||
if ( vs.getName().equals("Filter") )
|
||||
byFilterIsEnabled = true;
|
||||
|
|
@ -287,7 +290,7 @@ public class VariantEvalWalker extends RodWalker<Integer, Integer> implements Tr
|
|||
}
|
||||
|
||||
// Initialize the evaluation contexts
|
||||
evaluationContexts = variantEvalUtils.initializeEvaluationContexts(stratificationObjects, evaluationObjects, null, null);
|
||||
createStratificationStates(stratificationObjects, evaluationObjects);
|
||||
|
||||
// Initialize report table
|
||||
report = variantEvalUtils.initializeGATKReport(stratificationObjects, evaluationObjects);
|
||||
|
|
@ -306,7 +309,6 @@ public class VariantEvalWalker extends RodWalker<Integer, Integer> implements Tr
|
|||
knownCNVsByContig = createIntervalTreeByContig(knownCNVsFile);
|
||||
}
|
||||
|
||||
//createStratificationStates(stratificationObjects);
|
||||
}
|
||||
|
||||
public final Map<String, IntervalTree<GenomeLoc>> createIntervalTreeByContig(final IntervalBinding<Feature> intervals) {
|
||||
|
|
@ -372,8 +374,7 @@ public class VariantEvalWalker extends RodWalker<Integer, Integer> implements Tr
|
|||
// find the comp
|
||||
final VariantContext comp = findMatchingComp(eval, compSet);
|
||||
|
||||
for ( StateKey stateKey : getApplicableStates(tracker, ref, eval, evalRod.getName(), comp, compRod.getName(), sampleName) ) {
|
||||
NewEvaluationContext nec = evaluationContexts.get(stateKey);
|
||||
for ( NewEvaluationContext nec : getEvaluationContexts(tracker, ref, eval, evalRod.getName(), comp, compRod.getName(), sampleName) ) {
|
||||
|
||||
// eval against the comp
|
||||
synchronized (nec) {
|
||||
|
|
@ -400,37 +401,19 @@ public class VariantEvalWalker extends RodWalker<Integer, Integer> implements Tr
|
|||
return null;
|
||||
}
|
||||
|
||||
// private Iterable<StateKey> getApplicableStates(final RefMetaDataTracker tracker,
|
||||
// final ReferenceContext ref,
|
||||
// final VariantContext eval,
|
||||
// final String evalName,
|
||||
// final VariantContext comp,
|
||||
// final String compName,
|
||||
// final String sampleName ) {
|
||||
// Set<StateKey> oldKeys = new HashSet<StateKey>(Utils.makeCollection(getApplicableStatesOld(tracker, ref, eval, evalName, comp, compName, sampleName)));
|
||||
//
|
||||
// int n = 0;
|
||||
// for ( final StateKey newKey : getApplicableStatesNew(tracker, ref, eval, evalName, comp, compName, sampleName) ) {
|
||||
// n++;
|
||||
// if ( ! oldKeys.contains(newKey) )
|
||||
// throw new ReviewedStingException("New key " + newKey + " missing from previous algorithm");
|
||||
// }
|
||||
//
|
||||
// if ( n != oldKeys.size() )
|
||||
// throw new ReviewedStingException("New keyset has " + n + " elements but previous algorithm had " + oldKeys.size());
|
||||
//
|
||||
// return oldKeys;
|
||||
// }
|
||||
final void createStratificationStates(final List<VariantStratifier> stratificationObjects, final Set<Class<? extends VariantEvaluator>> evaluationObjects) {
|
||||
final List<VariantStratifier> strats = new ArrayList<VariantStratifier>(stratificationObjects);
|
||||
stratManager =
|
||||
new StratificationManager<VariantStratifier, NewEvaluationContext>(strats);
|
||||
|
||||
// private Iterable<StateKey> getApplicableStatesNew(final RefMetaDataTracker tracker,
|
||||
// final ReferenceContext ref,
|
||||
// final VariantContext eval,
|
||||
// final String evalName,
|
||||
// final VariantContext comp,
|
||||
// final String compName,
|
||||
// final String sampleName ) {
|
||||
// // todo -- implement optimized version
|
||||
// }
|
||||
logger.info("Creating " + stratManager.size() + " combinatorial stratification states");
|
||||
for ( int i = 0; i < stratManager.size(); i++ ) {
|
||||
NewEvaluationContext ec = new NewEvaluationContext();
|
||||
ec.putAll(stratManager.getStateForKey(i));
|
||||
ec.addEvaluationClassList(this, null, evaluationObjects);
|
||||
stratManager.set(i, ec);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Given specific eval and comp VCs and the sample name, return an iterable
|
||||
|
|
@ -447,23 +430,19 @@ public class VariantEvalWalker extends RodWalker<Integer, Integer> implements Tr
|
|||
* @param sampleName
|
||||
* @return
|
||||
*/
|
||||
private Iterable<StateKey> getApplicableStates(final RefMetaDataTracker tracker,
|
||||
final ReferenceContext ref,
|
||||
final VariantContext eval,
|
||||
final String evalName,
|
||||
final VariantContext comp,
|
||||
final String compName,
|
||||
final String sampleName ) {
|
||||
final HashMap<VariantStratifier, List<String>> stateMap = new HashMap<VariantStratifier, List<String>>(stratificationObjects.size());
|
||||
private Collection<NewEvaluationContext> getEvaluationContexts(final RefMetaDataTracker tracker,
|
||||
final ReferenceContext ref,
|
||||
final VariantContext eval,
|
||||
final String evalName,
|
||||
final VariantContext comp,
|
||||
final String compName,
|
||||
final String sampleName ) {
|
||||
final List<List<Object>> states = new LinkedList<List<Object>>();
|
||||
for ( final VariantStratifier vs : stratificationObjects ) {
|
||||
List<String> states = vs.getRelevantStates(ref, tracker, comp, compName, eval, evalName, sampleName);
|
||||
stateMap.put(vs, states);
|
||||
states.add(vs.getRelevantStates(ref, tracker, comp, compName, eval, evalName, sampleName));
|
||||
}
|
||||
|
||||
ArrayList<StateKey> stateKeys = new ArrayList<StateKey>();
|
||||
variantEvalUtils.initializeStateKeys(stateMap, null, null, stateKeys);
|
||||
|
||||
return new HashSet<StateKey>(stateKeys);
|
||||
return stratManager.values(states);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -539,9 +518,14 @@ public class VariantEvalWalker extends RodWalker<Integer, Integer> implements Tr
|
|||
public void onTraversalDone(Integer result) {
|
||||
logger.info("Finalizing variant report");
|
||||
|
||||
for ( Map.Entry<StateKey, NewEvaluationContext> ecElt : evaluationContexts.entrySet() ) {
|
||||
final StateKey stateKey = ecElt.getKey();
|
||||
final NewEvaluationContext nec = ecElt.getValue();
|
||||
// TODO -- clean up -- this is deeply unsafe
|
||||
for ( int key = 0; key < stratManager.size(); key++ ) {
|
||||
final Map<VariantStratifier, Object> stateValues = stratManager.getStateForKey(key);
|
||||
final NewEvaluationContext nec = stratManager.get(key);
|
||||
|
||||
final Map<String, Object> stateKey = new HashMap<String, Object>(stateValues.size());
|
||||
for ( Map.Entry<VariantStratifier, Object> elt : stateValues.entrySet() )
|
||||
stateKey.put(elt.getKey().getName(), elt.getValue());
|
||||
|
||||
for ( VariantEvaluator ve : nec.getEvaluationClassList().values() ) {
|
||||
ve.finalizeEvaluation();
|
||||
|
|
@ -626,7 +610,7 @@ public class VariantEvalWalker extends RodWalker<Integer, Integer> implements Tr
|
|||
|
||||
public double getMendelianViolationQualThreshold() { return MENDELIAN_VIOLATION_QUAL_THRESHOLD; }
|
||||
|
||||
public TreeSet<VariantStratifier> getStratificationObjects() { return stratificationObjects; }
|
||||
public List<VariantStratifier> getStratificationObjects() { return stratificationObjects; }
|
||||
|
||||
public static String getAllSampleName() { return ALL_SAMPLE_NAME; }
|
||||
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import org.broadinstitute.sting.utils.variantcontext.Allele;
|
|||
import org.broadinstitute.sting.utils.variantcontext.VariantContext;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
|
@ -32,15 +33,13 @@ public class AlleleCount extends VariantStratifier {
|
|||
|
||||
// create an array containing each of the allele counts
|
||||
for( int ac = 0; ac <= nchrom; ac++ ) {
|
||||
states.add(String.format("%d", ac));
|
||||
states.add(ac);
|
||||
}
|
||||
|
||||
getVariantEvalWalker().getLogger().info("AlleleCount using " + nchrom + " chromosomes");
|
||||
}
|
||||
|
||||
public List<String> getRelevantStates(ReferenceContext ref, RefMetaDataTracker tracker, VariantContext comp, String compName, VariantContext eval, String evalName, String sampleName) {
|
||||
ArrayList<String> relevantStates = new ArrayList<String>(1);
|
||||
|
||||
public List<Object> getRelevantStates(ReferenceContext ref, RefMetaDataTracker tracker, VariantContext comp, String compName, VariantContext eval, String evalName, String sampleName) {
|
||||
if (eval != null) {
|
||||
int AC = -1;
|
||||
if ( eval.hasAttribute("AC") && eval.getAttribute("AC") instanceof Integer ) {
|
||||
|
|
@ -51,9 +50,9 @@ public class AlleleCount extends VariantStratifier {
|
|||
} else
|
||||
// by default, the site is considered monomorphic
|
||||
AC = 0;
|
||||
relevantStates.add(String.format("%d", AC));
|
||||
return Collections.singletonList((Object)AC);
|
||||
} else {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
return relevantStates;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import org.broadinstitute.sting.utils.MathUtils;
|
|||
import org.broadinstitute.sting.utils.variantcontext.VariantContext;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
|
@ -17,23 +18,20 @@ import java.util.List;
|
|||
public class AlleleFrequency extends VariantStratifier {
|
||||
@Override
|
||||
public void initialize() {
|
||||
states = new ArrayList<String>();
|
||||
for( double a = 0.000; a <= 1.005; a += 0.005 ) {
|
||||
states.add(String.format("%.3f", a));
|
||||
}
|
||||
}
|
||||
|
||||
public List<String> getRelevantStates(ReferenceContext ref, RefMetaDataTracker tracker, VariantContext comp, String compName, VariantContext eval, String evalName, String sampleName) {
|
||||
ArrayList<String> relevantStates = new ArrayList<String>();
|
||||
|
||||
public List<Object> getRelevantStates(ReferenceContext ref, RefMetaDataTracker tracker, VariantContext comp, String compName, VariantContext eval, String evalName, String sampleName) {
|
||||
if (eval != null) {
|
||||
try {
|
||||
relevantStates.add(String.format("%.3f", (5.0 * MathUtils.round(eval.getAttributeAsDouble("AF", 0.0) / 5.0, 3))));
|
||||
return Collections.singletonList((Object)String.format("%.3f", (5.0 * MathUtils.round(eval.getAttributeAsDouble("AF", 0.0) / 5.0, 3))));
|
||||
} catch (Exception e) {
|
||||
return relevantStates;
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
return relevantStates;
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import org.broadinstitute.sting.gatk.refdata.RefMetaDataTracker;
|
|||
import org.broadinstitute.sting.utils.variantcontext.VariantContext;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
|
|
@ -15,16 +16,12 @@ import java.util.List;
|
|||
public class CompRod extends VariantStratifier implements RequiredStratification {
|
||||
@Override
|
||||
public void initialize() {
|
||||
for ( RodBinding<VariantContext> rod : getVariantEvalWalker().getComps() )
|
||||
for ( RodBinding<VariantContext> rod : getVariantEvalWalker().getComps() ) {
|
||||
states.add(rod.getName());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public List<String> getRelevantStates(ReferenceContext ref, RefMetaDataTracker tracker, VariantContext comp, String compName, VariantContext eval, String evalName, String sampleName) {
|
||||
ArrayList<String> relevantStates = new ArrayList<String>();
|
||||
|
||||
relevantStates.add(compName);
|
||||
|
||||
return relevantStates;
|
||||
public List<Object> getRelevantStates(ReferenceContext ref, RefMetaDataTracker tracker, VariantContext comp, String compName, VariantContext eval, String evalName, String sampleName) {
|
||||
return Collections.singletonList((Object)compName);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@ import org.broadinstitute.sting.gatk.refdata.RefMetaDataTracker;
|
|||
import org.broadinstitute.sting.utils.variantcontext.VariantContext;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
|
@ -17,14 +19,12 @@ public class Contig extends VariantStratifier {
|
|||
states.add("all");
|
||||
}
|
||||
|
||||
public List<String> getRelevantStates(ReferenceContext ref, RefMetaDataTracker tracker, VariantContext comp, String compName, VariantContext eval, String evalName, String sampleName) {
|
||||
ArrayList<String> relevantStates = new ArrayList<String>();
|
||||
|
||||
@Override
|
||||
public List<Object> getRelevantStates(ReferenceContext ref, RefMetaDataTracker tracker, VariantContext comp, String compName, VariantContext eval, String evalName, String sampleName) {
|
||||
if (eval != null) {
|
||||
relevantStates.add("all");
|
||||
relevantStates.add(eval.getChr());
|
||||
return Arrays.asList((Object)"all", eval.getChr());
|
||||
} else {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
return relevantStates;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,7 +27,8 @@ public class CpG extends VariantStratifier {
|
|||
states.add("non_CpG");
|
||||
}
|
||||
|
||||
public List<String> getRelevantStates(ReferenceContext ref, RefMetaDataTracker tracker, VariantContext comp, String compName, VariantContext eval, String evalName, String sampleName) {
|
||||
@Override
|
||||
public List<Object> getRelevantStates(ReferenceContext ref, RefMetaDataTracker tracker, VariantContext comp, String compName, VariantContext eval, String evalName, String sampleName) {
|
||||
boolean isCpG = false;
|
||||
if (ref != null && ref.getBases() != null) {
|
||||
String fwRefBases = new String(ref.getBases());
|
||||
|
|
@ -41,7 +42,7 @@ public class CpG extends VariantStratifier {
|
|||
}
|
||||
}
|
||||
|
||||
ArrayList<String> relevantStates = new ArrayList<String>();
|
||||
ArrayList<Object> relevantStates = new ArrayList<Object>(2);
|
||||
relevantStates.add("all");
|
||||
relevantStates.add(isCpG ? "CpG" : "non_CpG");
|
||||
|
||||
|
|
|
|||
|
|
@ -17,7 +17,6 @@ public class Degeneracy extends VariantStratifier {
|
|||
|
||||
@Override
|
||||
public void initialize() {
|
||||
states = new ArrayList<String>();
|
||||
states.add("1-fold");
|
||||
states.add("2-fold");
|
||||
states.add("3-fold");
|
||||
|
|
@ -79,8 +78,8 @@ public class Degeneracy extends VariantStratifier {
|
|||
}
|
||||
}
|
||||
|
||||
public List<String> getRelevantStates(ReferenceContext ref, RefMetaDataTracker tracker, VariantContext comp, String compName, VariantContext eval, String evalName, String sampleName) {
|
||||
ArrayList<String> relevantStates = new ArrayList<String>();
|
||||
public List<Object> getRelevantStates(ReferenceContext ref, RefMetaDataTracker tracker, VariantContext comp, String compName, VariantContext eval, String evalName, String sampleName) {
|
||||
ArrayList<Object> relevantStates = new ArrayList<Object>();
|
||||
|
||||
relevantStates.add("all");
|
||||
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import org.broadinstitute.sting.gatk.refdata.RefMetaDataTracker;
|
|||
import org.broadinstitute.sting.utils.variantcontext.VariantContext;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
|
@ -14,7 +15,6 @@ import java.util.List;
|
|||
public class EvalRod extends VariantStratifier implements RequiredStratification {
|
||||
@Override
|
||||
public void initialize() {
|
||||
states = new ArrayList<String>();
|
||||
for ( RodBinding<VariantContext> rod : getVariantEvalWalker().getEvals() ) {
|
||||
states.add(rod.getName());
|
||||
if ( getVariantEvalWalker().mergeEvals )
|
||||
|
|
@ -22,11 +22,7 @@ public class EvalRod extends VariantStratifier implements RequiredStratification
|
|||
}
|
||||
}
|
||||
|
||||
public List<String> getRelevantStates(ReferenceContext ref, RefMetaDataTracker tracker, VariantContext comp, String compName, VariantContext eval, String evalName, String sampleName) {
|
||||
ArrayList<String> relevantStates = new ArrayList<String>();
|
||||
|
||||
relevantStates.add(evalName);
|
||||
|
||||
return relevantStates;
|
||||
public List<Object> getRelevantStates(ReferenceContext ref, RefMetaDataTracker tracker, VariantContext comp, String compName, VariantContext eval, String evalName, String sampleName) {
|
||||
return Arrays.asList((Object)evalName);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,8 +18,8 @@ public class Filter extends VariantStratifier {
|
|||
states.add("raw");
|
||||
}
|
||||
|
||||
public List<String> getRelevantStates(ReferenceContext ref, RefMetaDataTracker tracker, VariantContext comp, String compName, VariantContext eval, String evalName, String sampleName) {
|
||||
ArrayList<String> relevantStates = new ArrayList<String>();
|
||||
public List<Object> getRelevantStates(ReferenceContext ref, RefMetaDataTracker tracker, VariantContext comp, String compName, VariantContext eval, String evalName, String sampleName) {
|
||||
ArrayList<Object> relevantStates = new ArrayList<Object>();
|
||||
|
||||
relevantStates.add("raw");
|
||||
if (eval != null) {
|
||||
|
|
|
|||
|
|
@ -28,8 +28,8 @@ public class FunctionalClass extends VariantStratifier {
|
|||
}
|
||||
|
||||
|
||||
public List<String> getRelevantStates(ReferenceContext ref, RefMetaDataTracker tracker, VariantContext comp, String compName, VariantContext eval, String evalName, String sampleName) {
|
||||
ArrayList<String> relevantStates = new ArrayList<String>();
|
||||
public List<Object> getRelevantStates(ReferenceContext ref, RefMetaDataTracker tracker, VariantContext comp, String compName, VariantContext eval, String evalName, String sampleName) {
|
||||
ArrayList<Object> relevantStates = new ArrayList<Object>();
|
||||
|
||||
relevantStates.add("all");
|
||||
|
||||
|
|
@ -52,8 +52,8 @@ public List<String> getRelevantStates(ReferenceContext ref, RefMetaDataTracker t
|
|||
try {
|
||||
FunctionalType newType = FunctionalType.valueOf(newtypeStr);
|
||||
if ( type == null ||
|
||||
( type == FunctionalType.silent && newType != FunctionalType.silent ) ||
|
||||
( type == FunctionalType.missense && newType == FunctionalType.nonsense ) ) {
|
||||
( type == FunctionalType.silent && newType != FunctionalType.silent ) ||
|
||||
( type == FunctionalType.missense && newType == FunctionalType.nonsense ) ) {
|
||||
type = newType;
|
||||
}
|
||||
} catch ( Exception e ) {} // don't error out if the type isn't supported
|
||||
|
|
@ -71,7 +71,7 @@ public List<String> getRelevantStates(ReferenceContext ref, RefMetaDataTracker t
|
|||
type = FunctionalType.missense;
|
||||
else if ( snpEffFunctionalClass == SnpEff.EffectFunctionalClass.SILENT )
|
||||
type = FunctionalType.silent;
|
||||
}
|
||||
}
|
||||
catch ( Exception e ) {} // don't error out if the type isn't supported
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import org.broadinstitute.sting.gatk.refdata.RefMetaDataTracker;
|
|||
import org.broadinstitute.sting.utils.variantcontext.VariantContext;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
|
@ -17,15 +18,12 @@ public class IndelSize extends VariantStratifier {
|
|||
static final int MAX_INDEL_SIZE = 100;
|
||||
@Override
|
||||
public void initialize() {
|
||||
states = new ArrayList<String>();
|
||||
for( int a=-MAX_INDEL_SIZE; a <=MAX_INDEL_SIZE; a++ ) {
|
||||
states.add(String.format("%d", a));
|
||||
states.add(a);
|
||||
}
|
||||
}
|
||||
|
||||
public List<String> getRelevantStates(ReferenceContext ref, RefMetaDataTracker tracker, VariantContext comp, String compName, VariantContext eval, String evalName, String sampleName) {
|
||||
ArrayList<String> relevantStates = new ArrayList<String>();
|
||||
|
||||
public List<Object> getRelevantStates(ReferenceContext ref, RefMetaDataTracker tracker, VariantContext comp, String compName, VariantContext eval, String evalName, String sampleName) {
|
||||
if (eval != null && eval.isIndel() && eval.isBiallelic()) {
|
||||
try {
|
||||
int eventLength = 0;
|
||||
|
|
@ -40,12 +38,12 @@ public class IndelSize extends VariantStratifier {
|
|||
else if (eventLength < -MAX_INDEL_SIZE)
|
||||
eventLength = -MAX_INDEL_SIZE;
|
||||
|
||||
relevantStates.add(String.format("%d",eventLength));
|
||||
return Collections.singletonList((Object)eventLength);
|
||||
} catch (Exception e) {
|
||||
return relevantStates;
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
return relevantStates;
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -70,20 +70,18 @@ public class IntervalStratification extends VariantStratifier {
|
|||
logger.info(String.format("Creating IntervalStratification %s containing %d intervals covering %d bp",
|
||||
getVariantEvalWalker().intervalsFile.getSource(), locs.size(), IntervalUtils.intervalSize(locs)));
|
||||
|
||||
states = new ArrayList<String>(Arrays.asList("all", "overlaps.intervals", "outside.intervals"));
|
||||
states.addAll(Arrays.asList("all", "overlaps.intervals", "outside.intervals"));
|
||||
}
|
||||
|
||||
public List<String> getRelevantStates(ReferenceContext ref, RefMetaDataTracker tracker, VariantContext comp, String compName, VariantContext eval, String evalName, String sampleName) {
|
||||
final ArrayList<String> relevantStates = new ArrayList<String>(Arrays.asList("all"));
|
||||
|
||||
public List<Object> getRelevantStates(ReferenceContext ref, RefMetaDataTracker tracker, VariantContext comp, String compName, VariantContext eval, String evalName, String sampleName) {
|
||||
if (eval != null) {
|
||||
final GenomeLoc loc = getVariantEvalWalker().getGenomeLocParser().createGenomeLoc(eval, true);
|
||||
IntervalTree<GenomeLoc> intervalTree = intervalTreeByContig.get(loc.getContig());
|
||||
IntervalTree.Node<GenomeLoc> node = intervalTree.minOverlapper(loc.getStart(), loc.getStop());
|
||||
//logger.info(String.format("Overlap %s found %s", loc, node));
|
||||
relevantStates.add( node != null ? "overlaps.intervals" : "outside.intervals");
|
||||
return Collections.singletonList((Object)(node != null ? "overlaps.intervals" : "outside.intervals"));
|
||||
}
|
||||
|
||||
return relevantStates;
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,8 +29,8 @@ public class JexlExpression extends VariantStratifier implements StandardStratif
|
|||
}
|
||||
}
|
||||
|
||||
public List<String> getRelevantStates(ReferenceContext ref, RefMetaDataTracker tracker, VariantContext comp, String compName, VariantContext eval, String evalName, String sampleName) {
|
||||
ArrayList<String> relevantStates = new ArrayList<String>();
|
||||
public List<Object> getRelevantStates(ReferenceContext ref, RefMetaDataTracker tracker, VariantContext comp, String compName, VariantContext eval, String evalName, String sampleName) {
|
||||
ArrayList<Object> relevantStates = new ArrayList<Object>();
|
||||
relevantStates.add("none");
|
||||
|
||||
for ( SortableJexlVCMatchExp jexlExpression : jexlExpressions ) {
|
||||
|
|
|
|||
|
|
@ -14,24 +14,26 @@ public class Novelty extends VariantStratifier implements StandardStratification
|
|||
// needs the variant contexts and known names
|
||||
private List<RodBinding<VariantContext>> knowns;
|
||||
|
||||
private final static List<Object> KNOWN_STATES = Arrays.asList((Object)"all", (Object)"known");
|
||||
private final static List<Object> NOVEL_STATES = Arrays.asList((Object)"all", (Object)"novel");
|
||||
|
||||
@Override
|
||||
public void initialize() {
|
||||
states = new ArrayList<String>(Arrays.asList("all", "known", "novel"));
|
||||
states.addAll(Arrays.asList("all", "known", "novel"));
|
||||
knowns = getVariantEvalWalker().getKnowns();
|
||||
}
|
||||
|
||||
public List<String> getRelevantStates(ReferenceContext ref, RefMetaDataTracker tracker, VariantContext comp, String compName, VariantContext eval, String evalName, String sampleName) {
|
||||
public List<Object> getRelevantStates(ReferenceContext ref, RefMetaDataTracker tracker, VariantContext comp, String compName, VariantContext eval, String evalName, String sampleName) {
|
||||
if (tracker != null && eval != null) {
|
||||
final Collection<VariantContext> knownComps = tracker.getValues(knowns, ref.getLocus());
|
||||
for ( final VariantContext c : knownComps ) {
|
||||
// loop over sites, looking for something that matches the type eval
|
||||
if ( eval.getType() == c.getType() ) {
|
||||
return Arrays.asList("all", "known");
|
||||
return KNOWN_STATES;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Arrays.asList("all", "novel");
|
||||
}
|
||||
|
||||
return NOVEL_STATES;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -5,6 +5,7 @@ import org.broadinstitute.sting.gatk.refdata.RefMetaDataTracker;
|
|||
import org.broadinstitute.sting.utils.variantcontext.VariantContext;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
|
@ -20,7 +21,7 @@ public class Sample extends VariantStratifier {
|
|||
states.addAll(getVariantEvalWalker().getSampleNamesForStratification());
|
||||
}
|
||||
|
||||
public List<String> getRelevantStates(ReferenceContext ref, RefMetaDataTracker tracker, VariantContext comp, String compName, VariantContext eval, String evalName, String sampleName) {
|
||||
return Arrays.asList(sampleName);
|
||||
public List<Object> getRelevantStates(ReferenceContext ref, RefMetaDataTracker tracker, VariantContext comp, String compName, VariantContext eval, String evalName, String sampleName) {
|
||||
return Collections.singletonList((Object)sampleName);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,24 +3,41 @@ package org.broadinstitute.sting.gatk.walkers.varianteval.stratifications;
|
|||
import org.broadinstitute.sting.gatk.contexts.ReferenceContext;
|
||||
import org.broadinstitute.sting.gatk.refdata.RefMetaDataTracker;
|
||||
import org.broadinstitute.sting.gatk.walkers.varianteval.VariantEvalWalker;
|
||||
import org.broadinstitute.sting.gatk.walkers.varianteval.stratifications.manager.SetOfStates;
|
||||
import org.broadinstitute.sting.utils.variantcontext.VariantContext;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class VariantStratifier implements Comparable<VariantStratifier> {
|
||||
public abstract class VariantStratifier implements Comparable<VariantStratifier>, SetOfStates {
|
||||
private VariantEvalWalker variantEvalWalker;
|
||||
final private String name;
|
||||
protected ArrayList<String> states = new ArrayList<String>();
|
||||
final protected ArrayList<Object> states = new ArrayList<Object>();
|
||||
|
||||
protected VariantStratifier() {
|
||||
name = this.getClass().getSimpleName();
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------------
|
||||
//
|
||||
// to be overloaded
|
||||
//
|
||||
// -------------------------------------------------------------------------------------
|
||||
|
||||
public abstract void initialize();
|
||||
|
||||
public abstract List<Object> getRelevantStates(ReferenceContext ref, RefMetaDataTracker tracker, VariantContext comp, String compName, VariantContext eval, String evalName, String sampleName);
|
||||
|
||||
// -------------------------------------------------------------------------------------
|
||||
//
|
||||
// final capabilities
|
||||
//
|
||||
// -------------------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* @return a reference to the parent VariantEvalWalker running this stratification
|
||||
*/
|
||||
public VariantEvalWalker getVariantEvalWalker() {
|
||||
public final VariantEvalWalker getVariantEvalWalker() {
|
||||
return variantEvalWalker;
|
||||
}
|
||||
|
||||
|
|
@ -28,17 +45,11 @@ public abstract class VariantStratifier implements Comparable<VariantStratifier>
|
|||
* Should only be called by VariantEvalWalker itself
|
||||
* @param variantEvalWalker
|
||||
*/
|
||||
public void setVariantEvalWalker(VariantEvalWalker variantEvalWalker) {
|
||||
public final void setVariantEvalWalker(VariantEvalWalker variantEvalWalker) {
|
||||
this.variantEvalWalker = variantEvalWalker;
|
||||
}
|
||||
|
||||
public abstract void initialize();
|
||||
|
||||
public List<String> getRelevantStates(ReferenceContext ref, RefMetaDataTracker tracker, VariantContext comp, String compName, VariantContext eval, String evalName, String sampleName) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public int compareTo(VariantStratifier o1) {
|
||||
public final int compareTo(VariantStratifier o1) {
|
||||
return this.getName().compareTo(o1.getName());
|
||||
}
|
||||
|
||||
|
|
@ -46,7 +57,7 @@ public abstract class VariantStratifier implements Comparable<VariantStratifier>
|
|||
return name;
|
||||
}
|
||||
|
||||
public ArrayList<String> getAllStates() {
|
||||
public final ArrayList<Object> getAllStates() {
|
||||
return states;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,12 +38,10 @@ import java.util.List;
|
|||
public class VariantType extends VariantStratifier {
|
||||
@Override
|
||||
public void initialize() {
|
||||
for ( VariantContext.Type t : VariantContext.Type.values() ) {
|
||||
states.add(t.toString());
|
||||
}
|
||||
states.addAll(Arrays.asList(VariantContext.Type.values()));
|
||||
}
|
||||
|
||||
public List<String> getRelevantStates(ReferenceContext ref, RefMetaDataTracker tracker, VariantContext comp, String compName, VariantContext eval, String evalName, String sampleName) {
|
||||
return eval == null ? Collections.<String>emptyList() : Arrays.asList(eval.getType().toString());
|
||||
public List<Object> getRelevantStates(ReferenceContext ref, RefMetaDataTracker tracker, VariantContext comp, String compName, VariantContext eval, String evalName, String sampleName) {
|
||||
return eval == null ? Collections.emptyList() : Collections.singletonList((Object)eval.getType());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,7 +39,12 @@ import java.util.*;
|
|||
public class StratificationManager<K extends SetOfStates, V> implements Map<List<Object>, V> {
|
||||
private final StratNode<K> root;
|
||||
private final int size;
|
||||
private final ArrayList<V> values;
|
||||
|
||||
private final ArrayList<K> stratifiers;
|
||||
|
||||
// values associated with each key
|
||||
private final ArrayList<V> valuesByKey;
|
||||
private final ArrayList<List<Object>> stratifierValuesByKey;
|
||||
|
||||
// -------------------------------------------------------------------------------------
|
||||
//
|
||||
|
|
@ -49,15 +54,21 @@ public class StratificationManager<K extends SetOfStates, V> implements Map<List
|
|||
|
||||
@Requires("!strats.isEmpty()")
|
||||
public StratificationManager(final List<K> strats) {
|
||||
stratifiers = new ArrayList<K>(strats);
|
||||
this.root = buildStratificationTree(new LinkedList<K>(strats));
|
||||
assignKeys(root);
|
||||
|
||||
this.size = root.size();
|
||||
if ( this.size == 0 )
|
||||
throw new ReviewedStingException("Size == 0 in StratificationManager");
|
||||
|
||||
this.values = new ArrayList<V>(size());
|
||||
for ( int i = 0; i < size(); i++ )
|
||||
this.values().add(null);
|
||||
this.valuesByKey = new ArrayList<V>(size());
|
||||
this.stratifierValuesByKey = new ArrayList<List<Object>>(size());
|
||||
for ( int i = 0; i < size(); i++ ) {
|
||||
this.valuesByKey.add(null);
|
||||
this.stratifierValuesByKey.add(null);
|
||||
}
|
||||
assignStratifierValuesByKey(root);
|
||||
}
|
||||
|
||||
private StratNode<K> buildStratificationTree(final Queue<K> strats) {
|
||||
|
|
@ -91,6 +102,28 @@ public class StratificationManager<K extends SetOfStates, V> implements Map<List
|
|||
}
|
||||
}
|
||||
|
||||
public void assignStratifierValuesByKey(final StratNode<K> root) {
|
||||
assignStratifierValuesByKey(root, new LinkedList<Object>());
|
||||
|
||||
for ( List<Object> stateValues : stratifierValuesByKey )
|
||||
if ( stateValues == null )
|
||||
throw new ReviewedStingException("Found a null state value set that's null");
|
||||
}
|
||||
|
||||
public void assignStratifierValuesByKey(final StratNode<K> node, final LinkedList<Object> states) {
|
||||
if ( node.isLeaf() ) { // we're here!
|
||||
if ( states.isEmpty() )
|
||||
throw new ReviewedStingException("Found a leaf node with an empty state values vector");
|
||||
stratifierValuesByKey.set(node.getKey(), new ArrayList<Object>(states));
|
||||
} else {
|
||||
for ( Map.Entry<Object, StratNode<K>> entry : node.getSubnodes().entrySet() ) {
|
||||
final LinkedList<Object> newStates = new LinkedList<Object>(states);
|
||||
newStates.addLast(entry.getKey());
|
||||
assignStratifierValuesByKey(entry.getValue(), newStates);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------------
|
||||
//
|
||||
// simple accessors
|
||||
|
|
@ -127,27 +160,45 @@ public class StratificationManager<K extends SetOfStates, V> implements Map<List
|
|||
return keys;
|
||||
}
|
||||
|
||||
public Map<K, Object> getStateForKey(final int key) {
|
||||
final Map<K, Object> states = new HashMap<K, Object>(stratifiers.size());
|
||||
for ( int i = 0; i < stratifiers.size(); i++ ) {
|
||||
final K strat = stratifiers.get(i);
|
||||
final Object stratValue = stratifierValuesByKey.get(key).get(i);
|
||||
states.put(strat, stratValue);
|
||||
}
|
||||
return states;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------------
|
||||
//
|
||||
// values
|
||||
// valuesByKey
|
||||
//
|
||||
// -------------------------------------------------------------------------------------
|
||||
|
||||
@Override
|
||||
@Ensures("result != null")
|
||||
public ArrayList<V> values() {
|
||||
return values;
|
||||
return valuesByKey;
|
||||
}
|
||||
|
||||
public Collection<V> values(List<List<Object>> states) {
|
||||
// TODO -- SHOULD BE INLINE TO AVOID CREATING LIST OF KEYS JUST TO ITERATE OVER IT
|
||||
Collection<V> vals = new LinkedList<V>();
|
||||
for ( int key : getKeys(states) )
|
||||
vals.add(get(key));
|
||||
return vals;
|
||||
}
|
||||
|
||||
@Requires("key >= 0 && key <= size()")
|
||||
@Ensures("get(key) == value")
|
||||
public void set(final int key, final V value) {
|
||||
values.set(key, value);
|
||||
valuesByKey.set(key, value);
|
||||
}
|
||||
|
||||
@Requires("key >= 0 && key <= size()")
|
||||
public V get(final int key) {
|
||||
return values.get(key);
|
||||
return valuesByKey.get(key);
|
||||
}
|
||||
|
||||
@Requires("getKey(states) != -1")
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ import org.broadinstitute.sting.utils.variantcontext.VariantContext;
|
|||
|
||||
import java.util.*;
|
||||
|
||||
public class NewEvaluationContext extends HashMap<VariantStratifier, String> {
|
||||
public class NewEvaluationContext extends HashMap<VariantStratifier, Object> {
|
||||
private Map<String, VariantEvaluator> evaluationInstances;
|
||||
|
||||
public void addEvaluationClassList(VariantEvalWalker walker, StateKey stateKey, Set<Class<? extends VariantEvaluator>> evaluationClasses) {
|
||||
|
|
@ -37,9 +37,9 @@ public class NewEvaluationContext extends HashMap<VariantStratifier, String> {
|
|||
}
|
||||
|
||||
public StateKey makeStateKey() {
|
||||
Map<String, String> map = new HashMap<String, String>(size());
|
||||
Map<String, Object> map = new HashMap<String, Object>(size());
|
||||
|
||||
for (Map.Entry<VariantStratifier, String> elt : this.entrySet() ) {
|
||||
for (Map.Entry<VariantStratifier, Object> elt : this.entrySet() ) {
|
||||
map.put(elt.getKey().getName(), elt.getValue());
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -47,18 +47,18 @@ import java.util.TreeMap;
|
|||
public final class StateKey {
|
||||
/** High-performance cache of the toString operation for a constant class */
|
||||
private final String string;
|
||||
private final TreeMap<String, String> states;
|
||||
private final TreeMap<String, Object> states;
|
||||
|
||||
public StateKey(final Map<String, String> states) {
|
||||
this.states = new TreeMap<String, String>(states);
|
||||
public StateKey(final Map<String, Object> states) {
|
||||
this.states = new TreeMap<String, Object>(states);
|
||||
this.string = formatString();
|
||||
}
|
||||
|
||||
public StateKey(final StateKey toOverride, final String keyOverride, final String valueOverride) {
|
||||
public StateKey(final StateKey toOverride, final String keyOverride, final Object valueOverride) {
|
||||
if ( toOverride == null ) {
|
||||
this.states = new TreeMap<String, String>();
|
||||
this.states = new TreeMap<String, Object>();
|
||||
} else {
|
||||
this.states = new TreeMap<String, String>(toOverride.states);
|
||||
this.states = new TreeMap<String, Object>(toOverride.states);
|
||||
}
|
||||
|
||||
this.states.put(keyOverride, valueOverride);
|
||||
|
|
@ -90,7 +90,7 @@ public final class StateKey {
|
|||
private final String formatString() {
|
||||
StringBuilder b = new StringBuilder();
|
||||
|
||||
for ( Map.Entry<String, String> entry : states.entrySet() ) {
|
||||
for ( Map.Entry<String, Object> entry : states.entrySet() ) {
|
||||
b.append(String.format("%s:%s;", entry.getKey(), entry.getValue()));
|
||||
}
|
||||
|
||||
|
|
@ -98,7 +98,7 @@ public final class StateKey {
|
|||
}
|
||||
|
||||
// TODO -- might be slow because of tree map
|
||||
public String get(final String key) {
|
||||
public Object get(final String key) {
|
||||
return states.get(key);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -87,8 +87,8 @@ public class VariantEvalUtils {
|
|||
* @param modulesToUse the list of stratification modules to use
|
||||
* @return set of stratifications to use
|
||||
*/
|
||||
public TreeSet<VariantStratifier> initializeStratificationObjects(VariantEvalWalker variantEvalWalker, boolean noStandardStrats, String[] modulesToUse) {
|
||||
TreeSet<VariantStratifier> strats = new TreeSet<VariantStratifier>();
|
||||
public List<VariantStratifier> initializeStratificationObjects(VariantEvalWalker variantEvalWalker, boolean noStandardStrats, String[] modulesToUse) {
|
||||
List<VariantStratifier> strats = new ArrayList<VariantStratifier>();
|
||||
Set<String> stratsToUse = new HashSet<String>();
|
||||
|
||||
// Create a map for all stratification modules for easy lookup.
|
||||
|
|
@ -181,47 +181,6 @@ public class VariantEvalUtils {
|
|||
return evals;
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursively initialize the evaluation contexts
|
||||
*
|
||||
* @param stratificationObjects the stratifications to use
|
||||
* @param evaluationObjects the evaluations to use
|
||||
* @param stratStack a stack of stratifications to apply
|
||||
* @param ec evaluation context
|
||||
* @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) {
|
||||
HashMap<StateKey, NewEvaluationContext> ecs = new LinkedHashMap<StateKey, NewEvaluationContext>();
|
||||
|
||||
if (stratStack == null) {
|
||||
stratStack = new Stack<VariantStratifier>();
|
||||
stratStack.addAll(stratificationObjects);
|
||||
}
|
||||
|
||||
if (!stratStack.isEmpty()) {
|
||||
Stack<VariantStratifier> newStratStack = new Stack<VariantStratifier>();
|
||||
newStratStack.addAll(stratStack);
|
||||
|
||||
VariantStratifier vs = newStratStack.pop();
|
||||
|
||||
for (String state : vs.getAllStates()) {
|
||||
NewEvaluationContext nec = new NewEvaluationContext();
|
||||
if (ec != null) {
|
||||
nec.putAll(ec);
|
||||
}
|
||||
nec.put(vs, state);
|
||||
|
||||
ecs.putAll(initializeEvaluationContexts(stratificationObjects, evaluationObjects, newStratStack, nec));
|
||||
}
|
||||
} else {
|
||||
final StateKey stateKey = ec.makeStateKey();
|
||||
ec.addEvaluationClassList(variantEvalWalker, stateKey, evaluationObjects);
|
||||
return new HashMap<StateKey, NewEvaluationContext>(Collections.singletonMap(stateKey, ec));
|
||||
}
|
||||
|
||||
return ecs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the output report
|
||||
*
|
||||
|
|
@ -229,7 +188,7 @@ public class VariantEvalUtils {
|
|||
* @param evaluationObjects the evaluations to use
|
||||
* @return an initialized report object
|
||||
*/
|
||||
public GATKReport initializeGATKReport(Set<VariantStratifier> stratificationObjects, Set<Class<? extends VariantEvaluator>> evaluationObjects) {
|
||||
public GATKReport initializeGATKReport(Collection<VariantStratifier> stratificationObjects, Set<Class<? extends VariantEvaluator>> evaluationObjects) {
|
||||
GATKReport report = new GATKReport();
|
||||
|
||||
for (Class<? extends VariantEvaluator> ve : evaluationObjects) {
|
||||
|
|
@ -387,44 +346,4 @@ public class VariantEvalUtils {
|
|||
mappings.put(sample, new ArrayList<VariantContext>(1));
|
||||
mappings.get(sample).add(vc);
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursively initialize the state keys used to look up the right evaluation context based on the state of the
|
||||
* variant context
|
||||
*
|
||||
* @param stateMap the map of allowable states
|
||||
* @param stateStack a stack of the states
|
||||
* @param stateKey a state key object
|
||||
* @param stateKeys all the state keys
|
||||
* @return a list of state keys
|
||||
*/
|
||||
public ArrayList<StateKey> initializeStateKeys(HashMap<VariantStratifier, List<String>> stateMap, Stack<HashMap<VariantStratifier, List<String>>> stateStack, StateKey stateKey, ArrayList<StateKey> stateKeys) {
|
||||
if (stateStack == null) {
|
||||
stateStack = new Stack<HashMap<VariantStratifier, List<String>>>();
|
||||
|
||||
for (VariantStratifier vs : stateMap.keySet()) {
|
||||
HashMap<VariantStratifier, List<String>> oneSetOfStates = new HashMap<VariantStratifier, List<String>>();
|
||||
oneSetOfStates.put(vs, stateMap.get(vs));
|
||||
|
||||
stateStack.add(oneSetOfStates);
|
||||
}
|
||||
}
|
||||
|
||||
if (!stateStack.isEmpty()) {
|
||||
Stack<HashMap<VariantStratifier, List<String>>> newStateStack = new Stack<HashMap<VariantStratifier, List<String>>>();
|
||||
newStateStack.addAll(stateStack);
|
||||
|
||||
HashMap<VariantStratifier, List<String>> oneSetOfStates = newStateStack.pop();
|
||||
VariantStratifier vs = oneSetOfStates.keySet().iterator().next();
|
||||
|
||||
for (final String state : oneSetOfStates.get(vs)) {
|
||||
final StateKey newStateKey = new StateKey(stateKey, vs.getName(), state);
|
||||
initializeStateKeys(stateMap, newStateStack, newStateKey, stateKeys);
|
||||
}
|
||||
} else {
|
||||
stateKeys.add(stateKey);
|
||||
}
|
||||
|
||||
return stateKeys;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue