Search in sources :

Example 1 with TipDatesRandomWalker

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);
    }
}
Also used : Operator(beast.core.Operator) Input(beast.core.Input) MRCAPrior(beast.math.distributions.MRCAPrior) BEASTInterface(beast.core.BEASTInterface) ArrayList(java.util.ArrayList) List(java.util.List) TaxonSet(beast.evolution.alignment.TaxonSet) TipDatesRandomWalker(beast.evolution.operators.TipDatesRandomWalker)

Example 2 with TipDatesRandomWalker

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);
}
Also used : MRCAPrior(beast.math.distributions.MRCAPrior) BEASTInterface(beast.core.BEASTInterface) TaxonSet(beast.evolution.alignment.TaxonSet) TipDatesRandomWalker(beast.evolution.operators.TipDatesRandomWalker)

Example 3 with TipDatesRandomWalker

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);
    }
}
Also used : Taxon(beast.evolution.alignment.Taxon) MCMC(beast.core.MCMC) TaxonSet(beast.evolution.alignment.TaxonSet) Normal(beast.math.distributions.Normal) CompoundDistribution(beast.core.util.CompoundDistribution) ParametricDistribution(beast.math.distributions.ParametricDistribution) TraitSet(beast.evolution.tree.TraitSet) Tree(beast.evolution.tree.Tree) TipDatesRandomWalker(beast.evolution.operators.TipDatesRandomWalker)

Aggregations

TaxonSet (beast.evolution.alignment.TaxonSet)3 TipDatesRandomWalker (beast.evolution.operators.TipDatesRandomWalker)3 BEASTInterface (beast.core.BEASTInterface)2 MRCAPrior (beast.math.distributions.MRCAPrior)2 Input (beast.core.Input)1 MCMC (beast.core.MCMC)1 Operator (beast.core.Operator)1 CompoundDistribution (beast.core.util.CompoundDistribution)1 Taxon (beast.evolution.alignment.Taxon)1 TraitSet (beast.evolution.tree.TraitSet)1 Tree (beast.evolution.tree.Tree)1 Normal (beast.math.distributions.Normal)1 ParametricDistribution (beast.math.distributions.ParametricDistribution)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1