Search in sources :

Example 36 with Taxa

use of dr.evolution.util.Taxa 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 DefaultTreeModel(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) DefaultTreeModel(dr.evomodel.tree.DefaultTreeModel) 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) DefaultTreeModel(dr.evomodel.tree.DefaultTreeModel) 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 37 with Taxa

use of dr.evolution.util.Taxa 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 DefaultTreeModel(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 : Microsatellite(dr.evolution.datatype.Microsatellite) Taxon(dr.evolution.util.Taxon) ArrayList(java.util.ArrayList) TreeLikelihood(dr.oldevomodel.treelikelihood.TreeLikelihood) DefaultTreeModel(dr.evomodel.tree.DefaultTreeModel) Taxa(dr.evolution.util.Taxa) TreeModel(dr.evomodel.tree.TreeModel) DefaultTreeModel(dr.evomodel.tree.DefaultTreeModel) GammaSiteModel(dr.oldevomodel.sitemodel.GammaSiteModel) NewickImporter(dr.evolution.io.NewickImporter) AsymmetricQuadraticModel(dr.oldevomodel.substmodel.AsymmetricQuadraticModel) Tree(dr.evolution.tree.Tree) Patterns(dr.evolution.alignment.Patterns)

Example 38 with Taxa

use of dr.evolution.util.Taxa 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 DefaultTreeModel(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 : Microsatellite(dr.evolution.datatype.Microsatellite) Taxon(dr.evolution.util.Taxon) ArrayList(java.util.ArrayList) TreeLikelihood(dr.oldevomodel.treelikelihood.TreeLikelihood) DefaultTreeModel(dr.evomodel.tree.DefaultTreeModel) Taxa(dr.evolution.util.Taxa) TreeModel(dr.evomodel.tree.TreeModel) DefaultTreeModel(dr.evomodel.tree.DefaultTreeModel) GammaSiteModel(dr.oldevomodel.sitemodel.GammaSiteModel) NewickImporter(dr.evolution.io.NewickImporter) AsymmetricQuadraticModel(dr.oldevomodel.substmodel.AsymmetricQuadraticModel) Tree(dr.evolution.tree.Tree) Patterns(dr.evolution.alignment.Patterns)

Example 39 with Taxa

use of dr.evolution.util.Taxa in project beast-mcmc by beast-dev.

the class SpeciesSetPanel method setupTaxonSetsComboBox.

protected void setupTaxonSetsComboBox(JComboBox comboBox, List<Taxon> availableTaxa) {
    comboBox.removeAllItems();
    comboBox.addItem(TAXON.toLowerCase() + "...");
    for (Taxa taxa : options.speciesSets) {
        if (taxa != currentTaxonSet) {
            if (isCompatible(taxa, availableTaxa)) {
                comboBox.addItem(taxa);
            }
        }
    }
}
Also used : Taxa(dr.evolution.util.Taxa)

Example 40 with Taxa

use of dr.evolution.util.Taxa in project beast-mcmc by beast-dev.

the class LogGenerator method writeLogToFile.

/**
     * write log to file
     *
     * @param writer                     XMLWriter
     * @param treePriorGenerator         TreePriorGenerator
     * @param clockModelGenerator  ClockModelGenerator
     * @param substitutionModelGenerator SubstitutionModelGenerator
     * @param treeLikelihoodGenerator    TreeLikelihoodGenerator
     */
public void writeLogToFile(XMLWriter writer, TreePriorGenerator treePriorGenerator, ClockModelGenerator clockModelGenerator, SubstitutionModelGenerator substitutionModelGenerator, TreeLikelihoodGenerator treeLikelihoodGenerator) {
    writer.writeComment("write log to file");
    if (options.logFileName == null) {
        options.logFileName = options.fileNameStem + ".log";
    }
    writer.writeOpenTag(LoggerParser.LOG, new Attribute[] { new Attribute.Default<String>(XMLParser.ID, "fileLog"), new Attribute.Default<String>(LoggerParser.LOG_EVERY, options.logEvery + ""), new Attribute.Default<String>(LoggerParser.FILE_NAME, options.logFileName), new Attribute.Default<Boolean>(LoggerParser.ALLOW_OVERWRITE_LOG, options.allowOverwriteLog) });
    if (options.hasData()) {
        writer.writeIDref(CompoundLikelihoodParser.POSTERIOR, "posterior");
    }
    writer.writeIDref(CompoundLikelihoodParser.PRIOR, "prior");
    if (options.hasData()) {
        writer.writeIDref(CompoundLikelihoodParser.LIKELIHOOD, "likelihood");
    }
    if (options.useStarBEAST) {
        // species
        // coalescent prior
        writer.writeIDref(MultiSpeciesCoalescentParser.SPECIES_COALESCENT, TraitData.TRAIT_SPECIES + "." + COALESCENT);
        // prior on population sizes
        //            if (options.speciesTreePrior == TreePriorType.SPECIES_YULE) {
        writer.writeIDref(MixedDistributionLikelihoodParser.DISTRIBUTION_LIKELIHOOD, SPOPS);
        //            } else {
        //                writer.writeIDref(SpeciesTreeBMPrior.STPRIOR, STP);
        //            }
        // prior on species tree
        writer.writeIDref(SpeciationLikelihoodParser.SPECIATION_LIKELIHOOD, SPECIATION_LIKE);
        writer.writeIDref(ParameterParser.PARAMETER, TraitData.TRAIT_SPECIES + "." + options.starBEASTOptions.POP_MEAN);
        writer.writeIDref(ParameterParser.PARAMETER, SpeciesTreeModelParser.SPECIES_TREE + "." + SPLIT_POPS);
        if (options.getPartitionTreePriors().get(0).getNodeHeightPrior() == TreePriorType.SPECIES_BIRTH_DEATH) {
            writer.writeIDref(ParameterParser.PARAMETER, TraitData.TRAIT_SPECIES + "." + BirthDeathModelParser.MEAN_GROWTH_RATE_PARAM_NAME);
            writer.writeIDref(ParameterParser.PARAMETER, TraitData.TRAIT_SPECIES + "." + BirthDeathModelParser.RELATIVE_DEATH_RATE_PARAM_NAME);
        } else if (options.getPartitionTreePriors().get(0).getNodeHeightPrior() == TreePriorType.SPECIES_YULE || options.getPartitionTreePriors().get(0).getNodeHeightPrior() == TreePriorType.SPECIES_YULE_CALIBRATION) {
            writer.writeIDref(ParameterParser.PARAMETER, TraitData.TRAIT_SPECIES + "." + YuleModelParser.YULE + "." + YuleModelParser.BIRTH_RATE);
        } else {
            throw new IllegalArgumentException("Get wrong species tree prior using *BEAST : " + options.getPartitionTreePriors().get(0).getNodeHeightPrior().toString());
        }
        //Species Tree: tmrcaStatistic
        writer.writeIDref(TMRCAStatisticParser.TMRCA_STATISTIC, SpeciesTreeModelParser.SPECIES_TREE + "." + TreeModelParser.ROOT_HEIGHT);
    }
    for (PartitionTreeModel model : options.getPartitionTreeModels()) {
        writer.writeIDref(ParameterParser.PARAMETER, model.getPrefix() + TreeModel.TREE_MODEL + "." + TreeModelParser.ROOT_HEIGHT);
    }
    // @todo check for redundancy with rootHeight - if no tip dates or given as heights (time before present)
    for (PartitionTreeModel model : options.getPartitionTreeModels()) {
        if (model.hasTipCalibrations()) {
            writer.writeIDref(TMRCAStatisticParser.TMRCA_STATISTIC, model.getPrefix() + TreeModel.TREE_MODEL + ".rootAge");
        }
    }
    if (options.useStarBEAST) {
        for (Taxa taxa : options.speciesSets) {
            // make tmrca(tree.name) eay to read in log for Tracer
            writer.writeIDref(TMRCAStatisticParser.TMRCA_STATISTIC, "tmrca(" + taxa.getId() + ")");
        }
    } else {
        for (Taxa taxa : options.taxonSets) {
            // make tmrca(tree.name) eay to read in log for Tracer
            PartitionTreeModel treeModel = options.taxonSetsTreeModel.get(taxa);
            writer.writeIDref(TMRCAStatisticParser.TMRCA_STATISTIC, "tmrca(" + treeModel.getPrefix() + taxa.getId() + ")");
        }
    }
    for (PartitionTreePrior prior : options.getPartitionTreePriors()) {
        treePriorGenerator.writeParameterLog(prior, writer);
    }
    for (PartitionSubstitutionModel model : options.getPartitionSubstitutionModels()) {
        substitutionModelGenerator.writeLog(model, writer);
    }
    for (PartitionClockModel model : options.getPartitionClockModels()) {
        clockModelGenerator.writeLog(model, writer);
    }
    for (PartitionClockModel model : options.getPartitionClockModels()) {
        clockModelGenerator.writeLogStatistic(model, writer);
    }
    generateInsertionPoint(ComponentGenerator.InsertionPoint.IN_FILE_LOG_PARAMETERS, writer);
    treeLikelihoodGenerator.writeTreeLikelihoodReferences(writer);
    clockModelGenerator.writeClockLikelihoodReferences(writer);
    generateInsertionPoint(ComponentGenerator.InsertionPoint.IN_FILE_LOG_LIKELIHOODS, writer);
    // coalescentLikelihood
    for (PartitionTreeModel model : options.getPartitionTreeModels()) {
        PartitionTreePrior prior = model.getPartitionTreePrior();
        treePriorGenerator.writePriorLikelihoodReferenceLog(prior, model, writer);
        writer.writeText("");
    }
    for (PartitionTreePrior prior : options.getPartitionTreePriors()) {
        if (prior.getNodeHeightPrior() == TreePriorType.EXTENDED_SKYLINE) {
            // only 1 coalescent
            writer.writeIDref(CoalescentLikelihoodParser.COALESCENT_LIKELIHOOD, prior.getPrefix() + COALESCENT);
        } else if (prior.getNodeHeightPrior() == TreePriorType.SKYGRID) {
            writer.writeIDref(GMRFSkyrideLikelihoodParser.SKYGRID_LIKELIHOOD, prior.getPrefix() + "skygrid");
        }
    }
    writer.writeCloseTag(LoggerParser.LOG);
    generateInsertionPoint(ComponentGenerator.InsertionPoint.AFTER_FILE_LOG, writer);
}
Also used : Taxa(dr.evolution.util.Taxa) Attribute(dr.util.Attribute)

Aggregations

Taxa (dr.evolution.util.Taxa)75 Taxon (dr.evolution.util.Taxon)34 ArrayList (java.util.ArrayList)23 Tree (dr.evolution.tree.Tree)19 TaxonList (dr.evolution.util.TaxonList)15 Attribute (dr.util.Attribute)13 DefaultTreeModel (dr.evomodel.tree.DefaultTreeModel)10 TreeModel (dr.evomodel.tree.TreeModel)10 Patterns (dr.evolution.alignment.Patterns)9 Microsatellite (dr.evolution.datatype.Microsatellite)9 IOException (java.io.IOException)8 NewickImporter (dr.evolution.io.NewickImporter)7 Parameter (dr.inference.model.Parameter)6 Date (dr.evolution.util.Date)5 GammaSiteModel (dr.oldevomodel.sitemodel.GammaSiteModel)5 SimpleAlignment (dr.evolution.alignment.SimpleAlignment)4 ImportException (dr.evolution.io.Importer.ImportException)4 BranchRateModel (dr.evomodel.branchratemodel.BranchRateModel)4 CoalescentSimulator (dr.evomodel.coalescent.CoalescentSimulator)4 PartitionTreeModel (dr.app.beauti.options.PartitionTreeModel)3