Search in sources :

Example 61 with TreeModel

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

the class MsatSamplingTreeLikelihoodTest method setUp.

public void setUp() throws Exception {
    super.setUp();
    //taxa
    ArrayList<Taxon> taxonList3 = new ArrayList<Taxon>();
    Collections.addAll(taxonList3, new Taxon("Taxon1"), new Taxon("Taxon2"), new Taxon("Taxon3"), new Taxon("Taxon4"), new Taxon("Taxon5"), new Taxon("Taxon6"), new Taxon("Taxon7"));
    Taxa taxa3 = new Taxa(taxonList3);
    //msat datatype
    Microsatellite msat = new Microsatellite(1, 6);
    Patterns msatPatterns = new Patterns(msat, taxa3);
    //pattern in the correct code form.
    msatPatterns.addPattern(new int[] { 0, 1, 3, 2, 4, 5, 1 });
    //create tree
    NewickImporter importer = new NewickImporter("(((Taxon1:0.3,Taxon2:0.3):0.6,Taxon3:0.9):0.9,((Taxon4:0.5,Taxon5:0.5):0.3,(Taxon6:0.7,Taxon7:0.7):0.1):1.0);");
    Tree tree = importer.importTree(null);
    //treeModel
    TreeModel treeModel = new TreeModel(tree);
    //msatsubstModel
    AsymmetricQuadraticModel eu1 = new AsymmetricQuadraticModel(msat, null);
    //create msatSamplerTreeModel
    Parameter internalVal = new Parameter.Default(new double[] { 2, 3, 4, 2, 1, 5 });
    int[] externalValues = msatPatterns.getPattern(0);
    HashMap<String, Integer> taxaMap = new HashMap<String, Integer>(externalValues.length);
    boolean internalValuesProvided = true;
    for (int i = 0; i < externalValues.length; i++) {
        taxaMap.put(msatPatterns.getTaxonId(i), i);
    }
    MicrosatelliteSamplerTreeModel msatTreeModel = new MicrosatelliteSamplerTreeModel("JUnitTestEx", treeModel, internalVal, msatPatterns, externalValues, taxaMap, internalValuesProvided);
    //create msatSamplerTreeLikelihood
    BranchRateModel branchRateModel = new StrictClockBranchRates(new Parameter.Default(1.0));
    eu1Likelihood = new MicrosatelliteSamplerTreeLikelihood(msatTreeModel, eu1, branchRateModel);
    //eu2
    TwoPhaseModel eu2 = new TwoPhaseModel(msat, null, eu1, new Parameter.Default(0.0), new Parameter.Default(0.4), null, false);
    eu2Likelihood = new MicrosatelliteSamplerTreeLikelihood(msatTreeModel, eu2, branchRateModel);
    //ec1
    LinearBiasModel ec1 = new LinearBiasModel(msat, null, eu1, new Parameter.Default(0.48), new Parameter.Default(0.0), false, false, false);
    ec1Likelihood = new MicrosatelliteSamplerTreeLikelihood(msatTreeModel, ec1, branchRateModel);
    //ec2
    TwoPhaseModel ec2 = new TwoPhaseModel(msat, null, ec1, new Parameter.Default(0.0), new Parameter.Default(0.4), null, false);
    ec2Likelihood = new MicrosatelliteSamplerTreeLikelihood(msatTreeModel, ec2, branchRateModel);
    //el1
    LinearBiasModel el1 = new LinearBiasModel(msat, null, eu1, new Parameter.Default(0.2), new Parameter.Default(-0.018), true, false, false);
    el1Likelihood = new MicrosatelliteSamplerTreeLikelihood(msatTreeModel, el1, branchRateModel);
    AsymmetricQuadraticModel pu1 = new AsymmetricQuadraticModel(msat, null, new Parameter.Default(1.0), new Parameter.Default(0.015), new Parameter.Default(0.0), new Parameter.Default(1.0), new Parameter.Default(0.015), new Parameter.Default(0.0), false);
    pu1Likelihood = new MicrosatelliteSamplerTreeLikelihood(msatTreeModel, pu1, branchRateModel);
    //ec2
    TwoPhaseModel pu2 = new TwoPhaseModel(msat, null, pu1, new Parameter.Default(0.0), new Parameter.Default(0.4), null, false);
    pu2Likelihood = new MicrosatelliteSamplerTreeLikelihood(msatTreeModel, pu2, branchRateModel);
    //ec1
    LinearBiasModel pc1 = new LinearBiasModel(msat, null, pu1, new Parameter.Default(0.48), new Parameter.Default(0.0), false, false, false);
    pc1Likelihood = new MicrosatelliteSamplerTreeLikelihood(msatTreeModel, pc1, branchRateModel);
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) StrictClockBranchRates(dr.evomodel.branchratemodel.StrictClockBranchRates) Taxa(dr.evolution.util.Taxa) MicrosatelliteSamplerTreeModel(dr.evomodel.tree.MicrosatelliteSamplerTreeModel) TreeModel(dr.evomodel.tree.TreeModel) NewickImporter(dr.evolution.io.NewickImporter) AsymmetricQuadraticModel(dr.oldevomodel.substmodel.AsymmetricQuadraticModel) Tree(dr.evolution.tree.Tree) Patterns(dr.evolution.alignment.Patterns) Microsatellite(dr.evolution.datatype.Microsatellite) MicrosatelliteSamplerTreeModel(dr.evomodel.tree.MicrosatelliteSamplerTreeModel) Taxon(dr.evolution.util.Taxon) LinearBiasModel(dr.oldevomodel.substmodel.LinearBiasModel) BranchRateModel(dr.evomodel.branchratemodel.BranchRateModel) Parameter(dr.inference.model.Parameter) MicrosatelliteSamplerTreeLikelihood(dr.oldevomodel.treelikelihood.MicrosatelliteSamplerTreeLikelihood) TwoPhaseModel(dr.oldevomodel.substmodel.TwoPhaseModel)

Example 62 with TreeModel

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

the class CompleteHistorySimulatorTest method setUp.

public void setUp() throws Exception {
    super.setUp();
    MathUtils.setSeed(666);
    NewickImporter importer = new NewickImporter("(1:2.0,(2:1.0,3:1.0):1.0);");
    tree = importer.importTree(null);
    treeModel = new TreeModel("treeModel", tree);
}
Also used : TreeModel(dr.evomodel.tree.TreeModel) NewickImporter(dr.evolution.io.NewickImporter)

Example 63 with TreeModel

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

the class NormalizedSequenceLikelihoodTest method createSillyTreeModel.

protected TreeModel createSillyTreeModel(int numTaxa) {
    SimpleNode[] nodes = new SimpleNode[2 * numTaxa - 1];
    for (int n = 0; n < 2 * numTaxa - 1; n++) {
        nodes[n] = new SimpleNode();
    }
    nodes[0].setTaxon(taxa[0]);
    nodes[1].setTaxon(taxa[1]);
    nodes[2].setHeight(1);
    nodes[2].addChild(nodes[0]);
    nodes[2].addChild(nodes[1]);
    SimpleNode root = nodes[2];
    if (numTaxa == 3) {
        nodes[3].setTaxon(taxa[2]);
        nodes[4].setHeight(2);
        nodes[4].addChild(nodes[2]);
        nodes[4].addChild(nodes[3]);
        root = nodes[4];
    }
    Tree tree = new SimpleTree(root);
    tree.setUnits(Units.Type.YEARS);
    //treeModel
    return new TreeModel(tree);
}
Also used : TreeModel(dr.evomodel.tree.TreeModel) Tree(dr.evolution.tree.Tree) SimpleTree(dr.evolution.tree.SimpleTree) SimpleTree(dr.evolution.tree.SimpleTree) SimpleNode(dr.evolution.tree.SimpleNode)

Example 64 with TreeModel

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

the class Coevolve method runModel2.

private void runModel2(PatternList patternList, PrintWriter pw, Tree tree, SubstitutionModel substModel, final Parameter betaParameter) {
    final Parameter muParameter = new Parameter.Default(1.0);
    muParameter.setId("mu");
    SiteModel siteModel = new GammaSiteModel(substModel, muParameter, null, 1, null);
    TreeModel treeModel = new TreeModel(tree);
    final TreeLikelihood treeLikelihood = new TreeLikelihood(patternList, treeModel, siteModel, null, null, false, false, true, false, false);
    treeLikelihood.setId("likelihood");
    MultivariateFunction function = new MultivariateFunction() {

        public double evaluate(double[] argument) {
            betaParameter.setParameterValue(0, argument[0]);
            betaParameter.setParameterValue(1, argument[1]);
            muParameter.setParameterValue(0, argument[2]);
            double lnL = -treeLikelihood.getLogLikelihood();
            // System.err.println("" + argument[0] + "\t" + argument[1] + "\t" + argument[2] + "\t" + lnL);
            return lnL;
        }

        public int getNumArguments() {
            return 3;
        }

        public double getLowerBound(int n) {
            return 0.0;
        }

        public double getUpperBound(int n) {
            return 100.0;
        }
    };
    MultivariateMinimum optimizer = new ConjugateGradientSearch();
    double lnL = optimizer.findMinimum(function, new double[] { 1.0, 1.0, 1.0 }, 6, 6);
    pw.write(betaParameter.getParameterValue(0) + "\t");
    pw.write(betaParameter.getParameterValue(1) + "\t");
    pw.write(muParameter.getParameterValue(0) + "\t");
    pw.write(lnL + "\n");
    pw.flush();
    System.out.println("" + betaParameter.getParameterValue(0) + "\t" + betaParameter.getParameterValue(1) + "\t" + muParameter.getParameterValue(0) + "\t" + lnL);
}
Also used : TreeModel(dr.evomodel.tree.TreeModel) GammaSiteModel(dr.oldevomodel.sitemodel.GammaSiteModel) TreeLikelihood(dr.oldevomodel.treelikelihood.TreeLikelihood) Parameter(dr.inference.model.Parameter) GammaSiteModel(dr.oldevomodel.sitemodel.GammaSiteModel) SiteModel(dr.oldevomodel.sitemodel.SiteModel)

Example 65 with TreeModel

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

the class LineageSpecificBranchModelParser method parseXMLObject.

@Override
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    TreeModel treeModel = (TreeModel) xo.getChild(TreeModel.class);
    FrequencyModel rootFrequencyModel = (FrequencyModel) xo.getChild(FrequencyModel.class);
    List<SubstitutionModel> substitutionModels = new ArrayList<SubstitutionModel>();
    XMLObject cxo = xo.getChild(MODELS);
    for (int i = 0; i < cxo.getChildCount(); i++) {
        SubstitutionModel substModel = (SubstitutionModel) cxo.getChild(i);
        substitutionModels.add(substModel);
    }
    //END: models loop
    // TODO: check if categories numbering starts from zero
    Parameter categories = (Parameter) xo.getElementFirstChild(CATEGORIES);
    return new //provider, 
    LineageSpecificBranchModel(//provider, 
    treeModel, //provider, 
    rootFrequencyModel, //provider, 
    substitutionModels, categories);
}
Also used : FrequencyModel(dr.evomodel.substmodel.FrequencyModel) TreeModel(dr.evomodel.tree.TreeModel) ArrayList(java.util.ArrayList) XMLObject(dr.xml.XMLObject) Parameter(dr.inference.model.Parameter) SubstitutionModel(dr.evomodel.substmodel.SubstitutionModel)

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