Search in sources :

Example 6 with TreeTrait

use of dr.evolution.tree.TreeTrait in project beast-mcmc by beast-dev.

the class TreeTransform method setupTraits.

private void setupTraits() {
    TreeTrait baseTrait = new TreeTrait.D() {

        public String getTraitName() {
            return TREE_TRANSFORM_PREFIX;
        }

        public Intent getIntent() {
            return Intent.BRANCH;
        }

        public Double getTrait(Tree tree, NodeRef node) {
            return getScaleForNode(tree, node);
        }

        public boolean getLoggable() {
            return true;
        }
    };
    treeTraits.addTrait(baseTrait);
}
Also used : NodeRef(dr.evolution.tree.NodeRef) Tree(dr.evolution.tree.Tree) TreeTrait(dr.evolution.tree.TreeTrait)

Example 7 with TreeTrait

use of dr.evolution.tree.TreeTrait in project beast-mcmc by beast-dev.

the class DnDsLoggerParser method parseXMLObject.

@Override
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    String[] names = DnDsLogger.traitNames;
    TreeTrait[] foundTraits = new TreeTrait[names.length];
    for (int i = 0; i < xo.getChildCount(); i++) {
        Object obj = xo.getChild(i);
        if (obj instanceof CodonPartitionedRobustCounting) {
            CodonPartitionedRobustCounting thisCount = (CodonPartitionedRobustCounting) obj;
            for (int j = 0; j < names.length; j++) {
                TreeTrait trait = thisCount.getTreeTrait(names[j]);
                if (trait != null) {
                    foundTraits[j] = trait;
                }
            }
        }
    }
    for (int i = 0; i < foundTraits.length; i++) {
        if (foundTraits[i] == null) {
            throw new XMLParseException("Unable to find trait '" + names[i] + "'");
        }
    }
    Tree tree = (Tree) xo.getChild(Tree.class);
    // Use AttributeRules for options here
    boolean useSmoothing = xo.getAttribute(USE_SMOOTHING, true);
    boolean useDnMinusDs = xo.getAttribute(USE_DNMINUSDS, false);
    boolean conditionalCounts = xo.getAttribute(COUNTS, false);
    boolean synonymous = xo.getAttribute(SYNONYMOUS, false);
    return new DnDsLogger(xo.getId(), tree, foundTraits, useSmoothing, useDnMinusDs, conditionalCounts, synonymous);
}
Also used : CodonPartitionedRobustCounting(dr.evomodel.substmodel.CodonPartitionedRobustCounting) Tree(dr.evolution.tree.Tree) DnDsLogger(dr.evomodel.treelikelihood.utilities.DnDsLogger) TreeTrait(dr.evolution.tree.TreeTrait)

Example 8 with TreeTrait

use of dr.evolution.tree.TreeTrait in project beast-mcmc by beast-dev.

the class StratifiedTraitLoggerParser method parseXMLObject.

//public static final String LOG_FORMAT = "format";
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    TreeModel treeModel = (TreeModel) xo.getChild(TreeModel.class);
    TreeTraitProvider traitProvider = (TreeTraitProvider) xo.getChild(TreeTraitProvider.class);
    String traitName = (String) xo.getAttribute(TRAIT_NAME);
    TreeTrait trait = traitProvider.getTreeTrait(traitName);
    if (trait == null || trait.getIntent() != TreeTrait.Intent.WHOLE_TREE) {
        StringBuilder sb = new StringBuilder("Unable to find whole tree trait '" + traitName + "' in '" + xo.getId() + "\n");
        sb.append("\tPossible traits:");
        for (TreeTrait existingTrait : traitProvider.getTreeTraits()) {
            if (existingTrait.getIntent() == TreeTrait.Intent.WHOLE_TREE) {
                sb.append(" " + existingTrait.getTraitName());
            }
        }
        sb.append("\n");
        throw new XMLParseException(sb.toString());
    }
    boolean partition = xo.getAttribute(PARTITION, false);
    if (trait.getTraitClass() == Double.class || trait.getTraitClass() == Integer.class || !partition) {
        return new TreeTraitLogger(treeModel, new TreeTrait[] { trait });
    }
    int length;
    Object obj = trait.getTrait(treeModel, treeModel.getNode(0));
    if (obj instanceof double[]) {
        length = ((double[]) obj).length;
    } else if (obj instanceof int[]) {
        length = ((int[]) obj).length;
    } else {
        throw new XMLParseException("Unknown trait type for partitioning");
    }
    TreeTrait[] partitionedTraits = new TreeTrait[length];
    for (int i = 0; i < length; i++) {
        partitionedTraits[i] = new TreeTrait.PickEntryD(trait, i);
    }
    return new TreeTraitLogger(treeModel, partitionedTraits);
}
Also used : TreeTraitLogger(dr.evomodel.treelikelihood.utilities.TreeTraitLogger) TreeTraitProvider(dr.evolution.tree.TreeTraitProvider) TreeTrait(dr.evolution.tree.TreeTrait) TreeModel(dr.evomodel.tree.TreeModel)

Aggregations

TreeTrait (dr.evolution.tree.TreeTrait)8 Tree (dr.evolution.tree.Tree)5 NodeRef (dr.evolution.tree.NodeRef)3 TreeTraitProvider (dr.evolution.tree.TreeTraitProvider)3 PatternList (dr.evolution.alignment.PatternList)2 TreeModel (dr.evomodel.tree.TreeModel)2 TreeTraitLogger (dr.evomodel.treelikelihood.utilities.TreeTraitLogger)2 DataType (dr.evolution.datatype.DataType)1 TreeUtils (dr.evolution.tree.TreeUtils)1 TaxonList (dr.evolution.util.TaxonList)1 DiscreteTraitBranchRateModel (dr.evomodel.branchratemodel.DiscreteTraitBranchRateModel)1 CodonPartitionedRobustCounting (dr.evomodel.substmodel.CodonPartitionedRobustCounting)1 MarkovJumpsSubstitutionModel (dr.evomodel.substmodel.MarkovJumpsSubstitutionModel)1 SubstitutionModel (dr.evomodel.substmodel.SubstitutionModel)1 UniformizedSubstitutionModel (dr.evomodel.substmodel.UniformizedSubstitutionModel)1 AncestralTrait (dr.evomodel.tree.AncestralTrait)1 DnDsLogger (dr.evomodel.treelikelihood.utilities.DnDsLogger)1 LogColumn (dr.inference.loggers.LogColumn)1 Parameter (dr.inference.model.Parameter)1 ArrayList (java.util.ArrayList)1