use of beast.evolution.operators.TipDatesRandomWalker in project beast2 by CompEvol.
the class MRCAPriorInputEditor method disableTipSampling.
// remove TipDatesRandomWalker from list of operators
private static void disableTipSampling(BEASTInterface m_beastObject, BeautiDoc doc) {
// First, find the operator
TipDatesRandomWalker operator = null;
MRCAPrior prior = (MRCAPrior) m_beastObject;
TaxonSet taxonset = prior.taxonsetInput.get();
// However, if there is an TipDatesRandomWalker with taxonset as input, we want to remove it.
for (BEASTInterface o : taxonset.getOutputs()) {
if (o instanceof TipDatesRandomWalker) {
operator = (TipDatesRandomWalker) o;
}
}
if (operator == null) {
// should never happen
return;
}
// remove from list of operators
Object o = doc.mcmc.get().getInput("operator");
if (o instanceof Input<?>) {
Input<List<Operator>> operatorInput = (Input<List<Operator>>) o;
List<Operator> operators = operatorInput.get();
operators.remove(operator);
}
}
use of beast.evolution.operators.TipDatesRandomWalker in project beast2 by CompEvol.
the class MRCAPriorInputEditor method enableTipSampling.
// add TipDatesRandomWalker (if not present) and add to list of operators
private void enableTipSampling() {
// First, create/find the operator
TipDatesRandomWalker operator = null;
MRCAPrior prior = (MRCAPrior) m_beastObject;
TaxonSet taxonset = prior.taxonsetInput.get();
taxonset.initAndValidate();
// see if an old operator still hangs around -- happens when toggling the TipsOnly checkbox a few times
for (BEASTInterface o : taxonset.getOutputs()) {
if (o instanceof TipDatesRandomWalker) {
operator = (TipDatesRandomWalker) o;
}
}
if (operator == null) {
operator = new TipDatesRandomWalker();
operator.initByName("tree", prior.treeInput.get(), "taxonset", taxonset, "windowSize", 1.0, "weight", 1.0);
}
operator.setID("tipDatesSampler." + taxonset.getID());
doc.mcmc.get().setInputValue("operator", operator);
}
use of beast.evolution.operators.TipDatesRandomWalker in project beast2 by CompEvol.
the class BeautiDoc method addMRCAPrior.
public void addMRCAPrior(MRCAPrior mrcaPrior) {
Tree tree = (Tree) pluginmap.get("Tree.t:" + alignments.get(0).getID());
if (tree == null) {
for (String key : pluginmap.keySet()) {
if (key.startsWith("Tree.t:")) {
tree = (Tree) pluginmap.get(key);
break;
}
}
}
// make sure we have the appropriate tree:
if (alignments.size() > 1) {
String testTaxon = mrcaPrior.taxonsetInput.get().toString().split("\n")[1].trim();
// = tree.getTaxaNames();
String[] taxaNames;
int index = -1;
int j = 0;
while (index < 0 && j++ < alignments.size()) {
tree = (Tree) pluginmap.get("Tree.t:" + alignments.get(j - 1).getID());
taxaNames = tree.getTaxaNames();
for (int i = 0; i < taxaNames.length && index < 0; i++) if (testTaxon.equals(taxaNames[i]))
index = i;
}
}
CompoundDistribution prior = (CompoundDistribution) pluginmap.get("prior");
mrcaPrior.treeInput.setValue(tree, mrcaPrior);
ParametricDistribution distr = mrcaPrior.distInput.get();
TaxonSet t = mrcaPrior.taxonsetInput.get();
if (taxaset.keySet().contains(t.getID())) {
Log.warning.println("taxonset " + t.getID() + " already exists: MRCAPrior " + mrcaPrior.getID() + " can not be added");
} else {
taxaset.put(t.getID(), t);
// ensure TaxonSets are not duplicated
List<Taxon> taxa = t.taxonsetInput.get();
for (int i = 0; i < taxa.size(); i++) {
if (taxaset.containsKey(taxa.get(i).getID())) {
taxa.set(i, taxaset.get(taxa.get(i).getID()));
} else {
taxaset.put(taxa.get(i).getID(), taxa.get(i));
}
}
if (distr instanceof Normal && (Double.isInfinite(((Normal) distr).sigmaInput.get().getValue()))) {
// it is a 'fixed' calibration, no need to add a distribution
} else {
prior.pDistributions.setValue(mrcaPrior, prior);
connect(mrcaPrior, "tracelog", "log");
}
}
if (t.taxonsetInput.get().size() == 1 && distr != null) {
// only add operators if it is NOT a 'fixed' calibration
if (!(distr instanceof Normal && (Double.isInfinite(((Normal) distr).sigmaInput.get().getValue())))) {
TipDatesRandomWalker operator = new TipDatesRandomWalker();
t.initAndValidate();
operator.initByName("taxonset", t, "weight", 1.0, "tree", tree, "windowSize", 1.0);
operator.setID("TipDatesRandomWalker." + t.getID());
MCMC mcmc = (MCMC) this.mcmc.get();
mcmc.operatorsInput.setValue(operator, mcmc);
}
// set up date trait
double date = distr.getMean();
TraitSet dateTrait = null;
for (TraitSet ts : tree.m_traitList.get()) {
if (ts.isDateTrait()) {
dateTrait = ts;
}
}
if (dateTrait == null) {
dateTrait = new TraitSet();
dateTrait.setID("traitsetDate");
registerPlugin(dateTrait);
dateTrait.initByName("traitname", TraitSet.DATE_BACKWARD_TRAIT, "taxa", tree.getTaxonset(), "value", t.taxonsetInput.get().get(0).getID() + "=" + date);
tree.m_traitList.setValue(dateTrait, tree);
tree.initAndValidate();
} else {
dateTrait.traitsInput.setValue(dateTrait.traitsInput.get() + ",\n" + t.taxonsetInput.get().get(0).getID() + "=" + date, dateTrait);
}
mrcaPrior.onlyUseTipsInput.setValue(true, mrcaPrior);
}
}
Aggregations