Search in sources :

Example 1 with TreeModel

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

the class BeagleTreeLikelihood method main.

public static void main(String[] args) {
    try {
        MathUtils.setSeed(666);
        System.out.println("Test case 1: simulateOnePartition");
        int sequenceLength = 1000;
        ArrayList<Partition> partitionsList = new ArrayList<Partition>();
        // create tree
        NewickImporter importer = new NewickImporter("(SimSeq1:73.7468,(SimSeq2:25.256989999999995,SimSeq3:45.256989999999995):18.48981);");
        Tree tree = importer.importTree(null);
        TreeModel treeModel = new TreeModel(tree);
        // create Frequency Model
        Parameter freqs = new Parameter.Default(new double[] { 0.25, 0.25, 0.25, 0.25 });
        FrequencyModel freqModel = new FrequencyModel(Nucleotides.INSTANCE, freqs);
        // create branch model
        Parameter kappa1 = new Parameter.Default(1, 1);
        Parameter kappa2 = new Parameter.Default(1, 1);
        HKY hky1 = new HKY(kappa1, freqModel);
        HKY hky2 = new HKY(kappa2, freqModel);
        HomogeneousBranchModel homogenousBranchSubstitutionModel = new HomogeneousBranchModel(hky1);
        List<SubstitutionModel> substitutionModels = new ArrayList<SubstitutionModel>();
        substitutionModels.add(hky1);
        substitutionModels.add(hky2);
        List<FrequencyModel> freqModels = new ArrayList<FrequencyModel>();
        freqModels.add(freqModel);
        Parameter epochTimes = new Parameter.Default(1, 20);
        // create branch rate model
        Parameter rate = new Parameter.Default(1, 0.001);
        BranchRateModel branchRateModel = new StrictClockBranchRates(rate);
        // create site model
        GammaSiteRateModel siteRateModel = new GammaSiteRateModel("siteModel");
        BranchModel homogeneousBranchModel = new HomogeneousBranchModel(hky1);
        BranchModel epochBranchModel = new EpochBranchModel(treeModel, substitutionModels, epochTimes);
        // create partition
        Partition partition1 = new //
        Partition(//
        treeModel, //
        homogenousBranchSubstitutionModel, //
        siteRateModel, //
        branchRateModel, //
        freqModel, // from
        0, // to
        sequenceLength - 1, // every
        1);
        partitionsList.add(partition1);
        // feed to sequence simulator and generate data
        BeagleSequenceSimulator simulator = new BeagleSequenceSimulator(partitionsList);
        Alignment alignment = simulator.simulate(false, false);
        BeagleTreeLikelihood nbtl = new BeagleTreeLikelihood(alignment, treeModel, homogeneousBranchModel, siteRateModel, branchRateModel, null, false, PartialsRescalingScheme.DEFAULT, false);
        System.out.println("nBTL(homogeneous) = " + nbtl.getLogLikelihood());
        nbtl = new BeagleTreeLikelihood(alignment, treeModel, epochBranchModel, siteRateModel, branchRateModel, null, false, PartialsRescalingScheme.DEFAULT, false);
        System.out.println("nBTL(epoch) = " + nbtl.getLogLikelihood());
    } catch (Exception e) {
        e.printStackTrace();
        System.exit(-1);
    }
// END: try-catch block
}
Also used : FrequencyModel(dr.evomodel.substmodel.FrequencyModel) Partition(dr.app.beagle.tools.Partition) EpochBranchModel(dr.evomodel.branchmodel.EpochBranchModel) HomogeneousBranchModel(dr.evomodel.branchmodel.HomogeneousBranchModel) GammaSiteRateModel(dr.evomodel.siteratemodel.GammaSiteRateModel) HomogeneousBranchModel(dr.evomodel.branchmodel.HomogeneousBranchModel) BranchModel(dr.evomodel.branchmodel.BranchModel) EpochBranchModel(dr.evomodel.branchmodel.EpochBranchModel) StrictClockBranchRates(dr.evomodel.branchratemodel.StrictClockBranchRates) SubstitutionModel(dr.evomodel.substmodel.SubstitutionModel) MarkovModulatedSubstitutionModel(dr.evomodel.substmodel.MarkovModulatedSubstitutionModel) BeagleSequenceSimulator(dr.app.beagle.tools.BeagleSequenceSimulator) TreeModel(dr.evomodel.tree.TreeModel) Alignment(dr.evolution.alignment.Alignment) DefaultBranchRateModel(dr.evomodel.branchratemodel.DefaultBranchRateModel) BranchRateModel(dr.evomodel.branchratemodel.BranchRateModel) NewickImporter(dr.evolution.io.NewickImporter) HKY(dr.evomodel.substmodel.nucleotide.HKY) Tree(dr.evolution.tree.Tree) Parameter(dr.inference.model.Parameter)

Example 2 with TreeModel

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

the class BranchAssignmentModelParser method parseXMLObject.

@Override
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    Logger.getLogger("dr.evomodel").info("\nUsing branch assignment branch model.");
    TreeModel treeModel = (TreeModel) xo.getChild(TreeModel.class);
    String annotation = xo.getStringAttribute(ANNOTATION);
    LinkedHashMap<Integer, SubstitutionModel> modelIndexMap = new LinkedHashMap<Integer, SubstitutionModel>();
    for (int i = 0; i < xo.getChildCount(); i++) {
        if (xo.getChild(i) instanceof XMLObject) {
            XMLObject xoc = (XMLObject) xo.getChild(i);
            if (xoc.getName().equals(ASSIGNMENT)) {
                Integer index = null;
                if (xoc.hasAttribute(ANNOTATION_VALUE)) {
                    index = xoc.getIntegerAttribute(ANNOTATION_VALUE);
                }
                SubstitutionModel model = (SubstitutionModel) xoc.getChild(SubstitutionModel.class);
                modelIndexMap.put(index, model);
            }
        }
    }
    SubstitutionModel baseModel = (SubstitutionModel) xo.getElementFirstChild(BASE_MODEL);
    return new BranchAssignmentModel(treeModel, annotation, modelIndexMap, baseModel);
}
Also used : TreeModel(dr.evomodel.tree.TreeModel) BranchAssignmentModel(dr.evomodel.branchmodel.BranchAssignmentModel) XMLObject(dr.xml.XMLObject) SubstitutionModel(dr.evomodel.substmodel.SubstitutionModel) LinkedHashMap(java.util.LinkedHashMap)

Example 3 with TreeModel

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

the class BranchSpecificBranchModelParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    Logger.getLogger("dr.evomodel").info("\nUsing clade-specific branch model.");
    TreeModel tree = (TreeModel) xo.getChild(TreeModel.class);
    SubstitutionModel substitutionModel = (SubstitutionModel) xo.getChild(SubstitutionModel.class);
    BranchSpecificBranchModel branchModel = new BranchSpecificBranchModel(tree, substitutionModel);
    for (int i = 0; i < xo.getChildCount(); i++) {
        if (xo.getChild(i) instanceof XMLObject) {
            XMLObject xoc = (XMLObject) xo.getChild(i);
            if (xoc.getName().equals(CLADE)) {
                double stemWeight = xoc.getAttribute(STEM_WEIGHT, 0.0);
                substitutionModel = (SubstitutionModel) xoc.getChild(SubstitutionModel.class);
                TaxonList taxonList = (TaxonList) xoc.getChild(TaxonList.class);
                if (taxonList.getTaxonCount() == 1) {
                    throw new XMLParseException("A clade must be defined by at least two taxa");
                }
                try {
                    branchModel.addClade(taxonList, substitutionModel, stemWeight);
                } catch (TreeUtils.MissingTaxonException mte) {
                    throw new XMLParseException("Taxon, " + mte + ", in " + getParserName() + " was not found in the tree.");
                }
            } else if (xoc.getName().equals(EXTERNAL_BRANCHES)) {
                substitutionModel = (SubstitutionModel) xoc.getChild(SubstitutionModel.class);
                TaxonList taxonList = (TaxonList) xoc.getChild(TaxonList.class);
                try {
                    branchModel.addExternalBranches(taxonList, substitutionModel);
                } catch (TreeUtils.MissingTaxonException mte) {
                    throw new XMLParseException("Taxon, " + mte + ", in " + getParserName() + " was not found in the tree.");
                }
            } else if (xoc.getName().equals(BACKBONE)) {
                substitutionModel = (SubstitutionModel) xoc.getChild(SubstitutionModel.class);
                TaxonList taxonList = (TaxonList) xoc.getChild(TaxonList.class);
                try {
                    branchModel.addBackbone(taxonList, substitutionModel);
                } catch (TreeUtils.MissingTaxonException mte) {
                    throw new XMLParseException("Taxon, " + mte + ", in " + getParserName() + " was not found in the tree.");
                }
            }
        }
    }
    return branchModel;
}
Also used : TreeModel(dr.evomodel.tree.TreeModel) TaxonList(dr.evolution.util.TaxonList) BranchSpecificBranchModel(dr.evomodel.branchmodel.BranchSpecificBranchModel) SubstitutionModel(dr.evomodel.substmodel.SubstitutionModel) TreeUtils(dr.evolution.tree.TreeUtils)

Example 4 with TreeModel

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

the class ExternalInternalBranchModelParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    Logger.getLogger("dr.evomodel").info("\nUsing external-internal branch model.");
    TreeModel tree = (TreeModel) xo.getChild(TreeModel.class);
    SubstitutionModel internalSubstitutionModel = (SubstitutionModel) xo.getChild(SubstitutionModel.class);
    SubstitutionModel externalSubstitutionModel = (SubstitutionModel) xo.getElementFirstChild(EXTERNAL_BRANCHES);
    return new ExternalInternalBranchModel(tree, externalSubstitutionModel, internalSubstitutionModel);
}
Also used : ExternalInternalBranchModel(dr.evomodel.branchmodel.ExternalInternalBranchModel) TreeModel(dr.evomodel.tree.TreeModel) SubstitutionModel(dr.evomodel.substmodel.SubstitutionModel)

Example 5 with TreeModel

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

the class RandomBranchAssignmentModelParser method parseXMLObject.

@Override
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    Logger.getLogger("dr.evomodel").info("\nUsing random assignment branch model.");
    TreeModel treeModel = (TreeModel) xo.getChild(TreeModel.class);
    XMLObject cxo = xo.getChild(MODELS);
    List<SubstitutionModel> substitutionModels = new ArrayList<SubstitutionModel>();
    for (int i = 0; i < cxo.getChildCount(); i++) {
        SubstitutionModel substModel = (SubstitutionModel) cxo.getChild(i);
        substitutionModels.add(substModel);
    }
    return new RandomBranchAssignmentModel(treeModel, substitutionModels);
}
Also used : TreeModel(dr.evomodel.tree.TreeModel) ArrayList(java.util.ArrayList) XMLObject(dr.xml.XMLObject) RandomBranchAssignmentModel(dr.evomodel.branchmodel.RandomBranchAssignmentModel) 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