Search in sources :

Example 16 with Microsatellite

use of dr.evolution.datatype.Microsatellite in project beast-mcmc by beast-dev.

the class MicrosatelliteSimulatorParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    Microsatellite msatDataType = (Microsatellite) xo.getChild(Microsatellite.class);
    Taxa taxa = (Taxa) xo.getChild(Taxa.class);
    Tree tree = (Tree) xo.getChild(Tree.class);
    MicrosatelliteModel msatModel = (MicrosatelliteModel) xo.getChild(MicrosatelliteModel.class);
    BranchRateModel brModel = (BranchRateModel) xo.getChild(BranchRateModel.class);
    if (brModel == null) {
        brModel = new DefaultBranchRateModel();
    }
    MicrosatelliteSimulator msatSim = new MicrosatelliteSimulator(msatDataType, taxa, tree, new GammaSiteModel(msatModel), brModel);
    Patterns patterns = msatSim.simulateMsatPattern();
    String msatPatId = xo.getAttribute("id", "simMsatPat");
    patterns.setId(msatPatId);
    MicrosatellitePatternParser.printDetails(patterns);
    MicrosatellitePatternParser.printMicrosatContent(patterns);
    return patterns;
}
Also used : Microsatellite(dr.evolution.datatype.Microsatellite) Taxa(dr.evolution.util.Taxa) MicrosatelliteModel(dr.oldevomodel.substmodel.MicrosatelliteModel) GammaSiteModel(dr.oldevomodel.sitemodel.GammaSiteModel) BranchRateModel(dr.evomodel.branchratemodel.BranchRateModel) DefaultBranchRateModel(dr.evomodel.branchratemodel.DefaultBranchRateModel) MicrosatelliteSimulator(dr.app.seqgen.MicrosatelliteSimulator) Tree(dr.evolution.tree.Tree) Patterns(dr.evolution.alignment.Patterns) DefaultBranchRateModel(dr.evomodel.branchratemodel.DefaultBranchRateModel)

Example 17 with Microsatellite

use of dr.evolution.datatype.Microsatellite in project beast-mcmc by beast-dev.

the class LinearBiasModelParser method parseXMLObject.

//AbstractXMLObjectParser implementation
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    OnePhaseModel subModel = (OnePhaseModel) xo.getElementFirstChild(SUBMODEL);
    Microsatellite dataType = (Microsatellite) subModel.getDataType();
    Parameter biasConst = null;
    if (xo.hasChildNamed(BIAS_CONSTANT)) {
        biasConst = (Parameter) xo.getElementFirstChild(BIAS_CONSTANT);
    }
    Parameter biasLin = null;
    if (xo.hasChildNamed(BIAS_LINEAR)) {
        biasLin = (Parameter) xo.getElementFirstChild(BIAS_LINEAR);
    }
    //get FrequencyModel
    FrequencyModel freqModel = null;
    if (xo.hasChildNamed(FrequencyModelParser.FREQUENCIES)) {
        freqModel = (FrequencyModel) xo.getElementFirstChild(FrequencyModelParser.FREQUENCIES);
    }
    boolean estimateSubmodelParams = false;
    if (xo.hasAttribute(ESTIMATE_SUBMODEL_PARAMS)) {
        estimateSubmodelParams = xo.getBooleanAttribute(ESTIMATE_SUBMODEL_PARAMS);
    }
    System.out.println("Is estimating submodel parameter(s): " + estimateSubmodelParams);
    boolean logistics = false;
    if (xo.hasAttribute(LOGISTICS)) {
        logistics = xo.getBooleanAttribute(LOGISTICS);
    }
    System.out.println("Using logistic regression: " + logistics);
    boolean isSubmodel = false;
    if (xo.hasAttribute(IS_SUBMODEL)) {
        isSubmodel = xo.getBooleanAttribute(IS_SUBMODEL);
    }
    System.out.println("Is a submodel: " + isSubmodel);
    return new LinearBiasModel(dataType, freqModel, subModel, biasConst, biasLin, logistics, estimateSubmodelParams, isSubmodel);
}
Also used : FrequencyModel(dr.oldevomodel.substmodel.FrequencyModel) Microsatellite(dr.evolution.datatype.Microsatellite) Parameter(dr.inference.model.Parameter) OnePhaseModel(dr.oldevomodel.substmodel.OnePhaseModel) LinearBiasModel(dr.oldevomodel.substmodel.LinearBiasModel)

Example 18 with Microsatellite

use of dr.evolution.datatype.Microsatellite in project beast-mcmc by beast-dev.

the class AsymQuadTest method testAsymmetricQuadraticModel.

public void testAsymmetricQuadraticModel() {
    for (Instance test : all) {
        Parameter expanConst = new Parameter.Default(1, test.getExpanConst());
        Parameter expanLin = new Parameter.Default(1, test.getExpanLin());
        Parameter expanQuad = new Parameter.Default(1, test.getExpanQuad());
        Parameter contractConst = new Parameter.Default(1, test.getContractConst());
        Parameter contractLin = new Parameter.Default(1, test.getContractLin());
        Parameter contractQuad = new Parameter.Default(1, test.getContractQuad());
        Microsatellite microsat = test.getDataType();
        AsymmetricQuadraticModel aqm = new AsymmetricQuadraticModel(microsat, null, expanConst, expanLin, expanQuad, contractConst, contractLin, contractQuad, false);
        aqm.computeStationaryDistribution();
        double[] statDist = aqm.getStationaryDistribution();
        final double[] expectedStatDist = test.getExpectedPi();
        for (int k = 0; k < statDist.length; ++k) {
            assertEquals(statDist[k], expectedStatDist[k], 1e-10);
        }
        double[] mat = new double[4 * 4];
        aqm.getTransitionProbabilities(test.getDistance(), mat);
        final double[] result = test.getExpectedResult();
        int k;
        for (k = 0; k < mat.length; ++k) {
            assertEquals(result[k], mat[k], 1e-10);
        // System.out.print(" " + (mat[k] - result[k]));
        }
        k = 0;
        for (int i = 0; i < microsat.getStateCount(); i++) {
            for (int j = 0; j < microsat.getStateCount(); j++) {
                assertEquals(result[k++], aqm.getOneTransitionProbabilityEntry(test.getDistance(), i, j), 1e-10);
            }
        }
        for (int j = 0; j < microsat.getStateCount(); j++) {
            double[] colTransitionProb = aqm.getColTransitionProbabilities(test.getDistance(), j);
            for (int i = 0; i < microsat.getStateCount(); i++) {
                assertEquals(result[i * microsat.getStateCount() + j], colTransitionProb[i], 1e-10);
            }
        }
        for (int i = 0; i < microsat.getStateCount(); i++) {
            double[] rowTransitionProb = aqm.getRowTransitionProbabilities(test.getDistance(), i);
            for (int j = 0; j < microsat.getStateCount(); j++) {
                assertEquals(result[i * microsat.getStateCount() + j], rowTransitionProb[j], 1e-10);
            }
        }
    }
}
Also used : Microsatellite(dr.evolution.datatype.Microsatellite) AsymmetricQuadraticModel(dr.oldevomodel.substmodel.AsymmetricQuadraticModel) Parameter(dr.inference.model.Parameter)

Example 19 with Microsatellite

use of dr.evolution.datatype.Microsatellite in project beast-mcmc by beast-dev.

the class MsatFullLikelihoodTest method setUpExample3.

private void setUpExample3() throws Exception {
    //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, 4);
    Patterns msatPatterns = new Patterns(msat, taxa3);
    //pattern in the correct code form.
    msatPatterns.addPattern(new int[] { 0, 3, 1, 2, 3, 0, 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 aqm3 = new AsymmetricQuadraticModel(msat, null);
    //siteModel
    GammaSiteModel siteModel = new GammaSiteModel(aqm3);
    //treeLikelihood
    treeLikelihood3 = 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)

Example 20 with Microsatellite

use of dr.evolution.datatype.Microsatellite in project beast-mcmc by beast-dev.

the class TwoPhaseModelTest method testTwoPhaseModel.

public void testTwoPhaseModel() {
    for (Instance test : all) {
        OnePhaseModel subModel = test.getSubModel();
        Microsatellite microsat = (Microsatellite) subModel.getDataType();
        Parameter pParam = new Parameter.Default(test.getPParam());
        Parameter mParam = new Parameter.Default(test.getMParam());
        TwoPhaseModel tpm = new TwoPhaseModel(microsat, null, subModel, pParam, mParam, null, false);
        int k;
        tpm.computeStationaryDistribution();
        double[] statDist = tpm.getStationaryDistribution();
        final double[] expectedStatDist = test.getPi();
        for (k = 0; k < statDist.length; ++k) {
            assertEquals(statDist[k], expectedStatDist[k], 1e-10);
        }
        int stateCount = microsat.getStateCount();
        double[] mat = new double[stateCount * stateCount];
        tpm.getTransitionProbabilities(test.getDistance(), mat);
        final double[] result = test.getExpectedResult();
        for (k = 0; k < mat.length; ++k) {
            assertEquals(result[k], mat[k], 5e-9);
        //System.out.print(" " + (mat[k]));// - result[k]));
        }
        k = 0;
        for (int i = 0; i < microsat.getStateCount(); i++) {
            for (int j = 0; j < microsat.getStateCount(); j++) {
                assertEquals(result[k++], tpm.getOneTransitionProbabilityEntry(test.getDistance(), i, j), 1e-10);
            }
        }
        for (int j = 0; j < microsat.getStateCount(); j++) {
            double[] colTransitionProb = tpm.getColTransitionProbabilities(test.getDistance(), j);
            for (int i = 0; i < microsat.getStateCount(); i++) {
                assertEquals(result[i * microsat.getStateCount() + j], colTransitionProb[i], 1e-10);
            }
        }
        for (int i = 0; i < microsat.getStateCount(); i++) {
            double[] rowTransitionProb = tpm.getRowTransitionProbabilities(test.getDistance(), i);
            for (int j = 0; j < microsat.getStateCount(); j++) {
                assertEquals(result[i * microsat.getStateCount() + j], rowTransitionProb[j], 1e-10);
            }
        }
    }
}
Also used : Microsatellite(dr.evolution.datatype.Microsatellite) Parameter(dr.inference.model.Parameter) OnePhaseModel(dr.oldevomodel.substmodel.OnePhaseModel) TwoPhaseModel(dr.oldevomodel.substmodel.TwoPhaseModel)

Aggregations

Microsatellite (dr.evolution.datatype.Microsatellite)20 Patterns (dr.evolution.alignment.Patterns)9 Taxa (dr.evolution.util.Taxa)9 Parameter (dr.inference.model.Parameter)8 Taxon (dr.evolution.util.Taxon)6 AsymmetricQuadraticModel (dr.oldevomodel.substmodel.AsymmetricQuadraticModel)6 Tree (dr.evolution.tree.Tree)5 ArrayList (java.util.ArrayList)5 NewickImporter (dr.evolution.io.NewickImporter)4 TreeModel (dr.evomodel.tree.TreeModel)4 GammaSiteModel (dr.oldevomodel.sitemodel.GammaSiteModel)4 FrequencyModel (dr.oldevomodel.substmodel.FrequencyModel)4 OnePhaseModel (dr.oldevomodel.substmodel.OnePhaseModel)4 LinearBiasModel (dr.oldevomodel.substmodel.LinearBiasModel)3 TwoPhaseModel (dr.oldevomodel.substmodel.TwoPhaseModel)3 TreeLikelihood (dr.oldevomodel.treelikelihood.TreeLikelihood)3 BranchRateModel (dr.evomodel.branchratemodel.BranchRateModel)2 HashMap (java.util.HashMap)2 AncestralStatesComponentOptions (dr.app.beauti.components.ancestralstates.AncestralStatesComponentOptions)1 PartitionSubstitutionModel (dr.app.beauti.options.PartitionSubstitutionModel)1