Search in sources :

Example 56 with TreeModel

use of dr.evomodel.tree.TreeModel 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 57 with TreeModel

use of dr.evomodel.tree.TreeModel in project beast-mcmc by beast-dev.

the class TreeUniformParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    TreeModel treeModel = (TreeModel) xo.getChild(TreeModel.class);
    final double weight = xo.getDoubleAttribute(MCMCOperator.WEIGHT);
    final int n = xo.getAttribute(COUNT, 2);
    if (!(n == 2 || n == 3)) {
        throw new XMLParseException("Sorry, only moves of 2 or 3 nodes implemented.");
    }
    return new TreeUniform(n, treeModel, weight);
}
Also used : TreeModel(dr.evomodel.tree.TreeModel) TreeUniform(dr.evomodel.operators.TreeUniform)

Example 58 with TreeModel

use of dr.evomodel.tree.TreeModel in project beast-mcmc by beast-dev.

the class CTMCScalePriorParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    TreeModel treeModel = (TreeModel) xo.getChild(TreeModel.class);
    Parameter ctmcScale = (Parameter) xo.getElementFirstChild(SCALEPARAMETER);
    boolean reciprocal = xo.getAttribute(RECIPROCAL, false);
    boolean trial = xo.getAttribute(TRIAL, false);
    SubstitutionModel substitutionModel = (SubstitutionModel) xo.getChild(SubstitutionModel.class);
    Logger.getLogger("dr.evolution").info("Creating CTMC Scale Reference Prior model.");
    return new CTMCScalePrior(MODEL_NAME, ctmcScale, treeModel, reciprocal, substitutionModel, trial);
}
Also used : TreeModel(dr.evomodel.tree.TreeModel) CTMCScalePrior(dr.evomodel.tree.CTMCScalePrior) Parameter(dr.inference.model.Parameter) SubstitutionModel(dr.evomodel.substmodel.SubstitutionModel)

Example 59 with TreeModel

use of dr.evomodel.tree.TreeModel in project beast-mcmc by beast-dev.

the class MsatFullLikelihoodTest method setUp.

public void setUp() throws Exception {
    super.setUp();
    //taxa
    ArrayList<Taxon> taxonList1 = new ArrayList<Taxon>();
    Collections.addAll(taxonList1, new Taxon("taxon1"), new Taxon("taxon2"), new Taxon("taxon3"));
    Taxa taxa1 = new Taxa(taxonList1);
    //msat datatype
    Microsatellite msat = new Microsatellite(1, 3);
    Patterns msatPatterns = new Patterns(msat, taxa1);
    //pattern in the correct code form.
    msatPatterns.addPattern(new int[] { 0, 1, 2 });
    //create tree
    NewickImporter importer = new NewickImporter("(taxon1:7.5,(taxon2:5.3,taxon3:5.3):2.2);");
    Tree tree = importer.importTree(null);
    //treeModel
    TreeModel treeModel = new TreeModel(tree);
    //msatsubstModel
    AsymmetricQuadraticModel aqm1 = new AsymmetricQuadraticModel(msat, null);
    //siteModel
    GammaSiteModel siteModel = new GammaSiteModel(aqm1);
    //treeLikelihood
    treeLikelihood1 = new TreeLikelihood(msatPatterns, treeModel, siteModel, null, null, false, false, true, false, false);
    setUpExample2();
    setUpExample3();
}
Also used : Taxa(dr.evolution.util.Taxa) Microsatellite(dr.evolution.datatype.Microsatellite) TreeModel(dr.evomodel.tree.TreeModel) GammaSiteModel(dr.oldevomodel.sitemodel.GammaSiteModel) Taxon(dr.evolution.util.Taxon) NewickImporter(dr.evolution.io.NewickImporter) ArrayList(java.util.ArrayList) AsymmetricQuadraticModel(dr.oldevomodel.substmodel.AsymmetricQuadraticModel) TreeLikelihood(dr.oldevomodel.treelikelihood.TreeLikelihood) Tree(dr.evolution.tree.Tree) Patterns(dr.evolution.alignment.Patterns)

Example 60 with TreeModel

use of dr.evomodel.tree.TreeModel in project beast-mcmc by beast-dev.

the class MsatFullLikelihoodTest method setUpExample2.

private void setUpExample2() throws Exception {
    //taxa
    ArrayList<Taxon> taxonList2 = new ArrayList<Taxon>();
    Collections.addAll(taxonList2, new Taxon("taxon1"), new Taxon("taxon2"), new Taxon("taxon3"), new Taxon("taxon4"), new Taxon("taxon5"));
    Taxa taxa2 = new Taxa(taxonList2);
    //msat datatype
    Microsatellite msat = new Microsatellite(1, 3);
    Patterns msatPatterns = new Patterns(msat, taxa2);
    //pattern in the correct code form.
    msatPatterns.addPattern(new int[] { 0, 1, 2, 1, 2 });
    //create tree
    NewickImporter importer = new NewickImporter("(((taxon1:1.5,taxon2:1.5):1.5,(taxon3:2.1,taxon4:2.1):0.9):0.7,taxon5:3.7);");
    Tree tree = importer.importTree(null);
    //treeModel
    TreeModel treeModel = new TreeModel(tree);
    //msatsubstModel
    AsymmetricQuadraticModel aqm2 = new AsymmetricQuadraticModel(msat, null);
    //siteModel
    GammaSiteModel siteModel = new GammaSiteModel(aqm2);
    //treeLikelihood
    treeLikelihood2 = new TreeLikelihood(msatPatterns, treeModel, siteModel, null, null, false, false, true, false, false);
}
Also used : Taxa(dr.evolution.util.Taxa) Microsatellite(dr.evolution.datatype.Microsatellite) TreeModel(dr.evomodel.tree.TreeModel) GammaSiteModel(dr.oldevomodel.sitemodel.GammaSiteModel) Taxon(dr.evolution.util.Taxon) NewickImporter(dr.evolution.io.NewickImporter) ArrayList(java.util.ArrayList) AsymmetricQuadraticModel(dr.oldevomodel.substmodel.AsymmetricQuadraticModel) TreeLikelihood(dr.oldevomodel.treelikelihood.TreeLikelihood) Tree(dr.evolution.tree.Tree) Patterns(dr.evolution.alignment.Patterns)

Aggregations

TreeModel (dr.evomodel.tree.TreeModel)142 Parameter (dr.inference.model.Parameter)62 BranchRateModel (dr.evomodel.branchratemodel.BranchRateModel)28 ArrayList (java.util.ArrayList)28 Tree (dr.evolution.tree.Tree)26 NewickImporter (dr.evolution.io.NewickImporter)21 GammaSiteRateModel (dr.evomodel.siteratemodel.GammaSiteRateModel)20 FrequencyModel (dr.evomodel.substmodel.FrequencyModel)19 HomogeneousBranchModel (dr.evomodel.branchmodel.HomogeneousBranchModel)18 DefaultBranchRateModel (dr.evomodel.branchratemodel.DefaultBranchRateModel)15 SubstitutionModel (dr.evomodel.substmodel.SubstitutionModel)15 PatternList (dr.evolution.alignment.PatternList)14 NodeRef (dr.evolution.tree.NodeRef)14 Partition (dr.app.beagle.tools.Partition)12 BranchModel (dr.evomodel.branchmodel.BranchModel)12 IOException (java.io.IOException)12 BeagleSequenceSimulator (dr.app.beagle.tools.BeagleSequenceSimulator)11 Taxon (dr.evolution.util.Taxon)11 TaxonList (dr.evolution.util.TaxonList)11 Patterns (dr.evolution.alignment.Patterns)9