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);
}
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);
}
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);
}
Aggregations