Search in sources :

Example 1 with CodonPartitionedRobustCounting

use of dr.evomodel.substmodel.CodonPartitionedRobustCounting in project beast-mcmc by beast-dev.

the class CodonPartitionedRobustCountingParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    AncestralStateBeagleTreeLikelihood[] partition = new AncestralStateBeagleTreeLikelihood[3];
    String[] labels = new String[] { FIRST, SECOND, THIRD };
    int patternCount = -1;
    BranchRateModel testBranchRateModel = null;
    for (int i = 0; i < 3; i++) {
        partition[i] = (AncestralStateBeagleTreeLikelihood) xo.getChild(labels[i]).getChild(AncestralStateBeagleTreeLikelihood.class);
        if (i == 0) {
            patternCount = partition[i].getPatternCount();
        } else {
            if (partition[i].getPatternCount() != patternCount) {
                throw new XMLParseException("Codon-partitioned robust counting requires all partitions to have the same length." + " Make sure that partitions include all unique sites and do not strip gaps.");
            }
        }
        // Ensure that siteRateModel has one category
        if (partition[i].getSiteRateModel().getCategoryCount() > 1) {
            throw new XMLParseException("Robust counting currently only implemented for single category models");
        }
        // Ensure that branchRateModel is the same across all partitions
        if (testBranchRateModel == null) {
            testBranchRateModel = partition[i].getBranchRateModel();
        } else if (testBranchRateModel != partition[i].getBranchRateModel()) {
            throw new XMLParseException("Robust counting currently requires the same branch rate model for all partitions");
        }
    }
    TreeModel tree = (TreeModel) xo.getChild(TreeModel.class);
    Codons codons = Codons.UNIVERSAL;
    if (xo.hasAttribute(GeneticCode.GENETIC_CODE)) {
        String codeStr = xo.getStringAttribute(GeneticCode.GENETIC_CODE);
        codons = Codons.findByName(codeStr);
    }
    String labelingString = (String) xo.getAttribute(LABELING);
    CodonLabeling codonLabeling = CodonLabeling.parseFromString(labelingString);
    if (codonLabeling == null) {
        throw new XMLParseException("Unrecognized codon labeling '" + labelingString + "'");
    }
    String branchFormatString = xo.getAttribute(BRANCH_FORMAT, StratifiedTraitOutputFormat.SUM_OVER_SITES.getText());
    StratifiedTraitOutputFormat branchFormat = StratifiedTraitOutputFormat.parseFromString(branchFormatString);
    if (branchFormat == null) {
        throw new XMLParseException("Unrecognized branch output format '" + branchFormat + "'");
    }
    String logFormatString = xo.getAttribute(LOG_FORMAT, StratifiedTraitOutputFormat.SUM_OVER_SITES.getText());
    StratifiedTraitOutputFormat logFormat = StratifiedTraitOutputFormat.parseFromString(logFormatString);
    if (logFormat == null) {
        throw new XMLParseException("Unrecognized log output format '" + branchFormat + "'");
    }
    boolean useUniformization = xo.getAttribute(USE_UNIFORMIZATION, false);
    boolean includeExternalBranches = xo.getAttribute(INCLUDE_EXTERNAL, true);
    boolean includeInternalBranches = xo.getAttribute(INCLUDE_INTERNAL, true);
    boolean doUnconditionedPerBranch = xo.getAttribute(DO_UNCONDITIONED_PER_BRANCH, false);
    boolean averageRates = xo.getAttribute(AVERAGE_RATES, true);
    boolean saveCompleteHistory = xo.getAttribute(SAVE_HISTORY, false);
    boolean useNewNeutralModel = xo.getAttribute(USE_NEW_NEUTRAL_MODEL, false);
    String prefix = xo.hasAttribute(PREFIX) ? xo.getStringAttribute(PREFIX) : null;
    return new CodonPartitionedRobustCounting(xo.getId(), tree, partition, codons, codonLabeling, useUniformization, includeExternalBranches, includeInternalBranches, doUnconditionedPerBranch, saveCompleteHistory, averageRates, useNewNeutralModel, branchFormat, logFormat, prefix);
}
Also used : StratifiedTraitOutputFormat(dr.evomodel.substmodel.StratifiedTraitOutputFormat) TreeModel(dr.evomodel.tree.TreeModel) CodonPartitionedRobustCounting(dr.evomodel.substmodel.CodonPartitionedRobustCounting) BranchRateModel(dr.evomodel.branchratemodel.BranchRateModel) AncestralStateBeagleTreeLikelihood(dr.evomodel.treelikelihood.AncestralStateBeagleTreeLikelihood) Codons(dr.evolution.datatype.Codons) CodonLabeling(dr.evomodel.substmodel.CodonLabeling)

Example 2 with CodonPartitionedRobustCounting

use of dr.evomodel.substmodel.CodonPartitionedRobustCounting 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)

Aggregations

CodonPartitionedRobustCounting (dr.evomodel.substmodel.CodonPartitionedRobustCounting)2 Codons (dr.evolution.datatype.Codons)1 Tree (dr.evolution.tree.Tree)1 TreeTrait (dr.evolution.tree.TreeTrait)1 BranchRateModel (dr.evomodel.branchratemodel.BranchRateModel)1 CodonLabeling (dr.evomodel.substmodel.CodonLabeling)1 StratifiedTraitOutputFormat (dr.evomodel.substmodel.StratifiedTraitOutputFormat)1 TreeModel (dr.evomodel.tree.TreeModel)1 AncestralStateBeagleTreeLikelihood (dr.evomodel.treelikelihood.AncestralStateBeagleTreeLikelihood)1 DnDsLogger (dr.evomodel.treelikelihood.utilities.DnDsLogger)1