Search in sources :

Example 26 with DefaultTreeModel

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

the class BeagleSeqSimTest method simulateThreePartitions.

// END: simulateTwoPartitions
static void simulateThreePartitions(int i, int N) {
    try {
        MathUtils.setSeed(666);
        System.out.println("Test case 3: simulateThreePartitions");
        int sequenceLength = 100000;
        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);
        DefaultTreeModel treeModel = new DefaultTreeModel(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 substitution model
        Parameter kappa = new Parameter.Default(1, 10);
        HKY hky = new HKY(kappa, freqModel);
        HomogeneousBranchModel substitutionModel = new HomogeneousBranchModel(hky);
        // create site model
        GammaSiteRateModel siteRateModel = new GammaSiteRateModel("siteModel");
        // create branch rate model
        BranchRateModel branchRateModel = new DefaultBranchRateModel();
        // create partition
        Partition partition1 = new // 
        Partition(// 
        treeModel, // 
        substitutionModel, // 
        siteRateModel, // 
        branchRateModel, // 
        freqModel, // from
        0, // to
        sequenceLength - 1, // every
        3);
        // create partition
        Partition Partition = new // 
        Partition(// 
        treeModel, // 
        substitutionModel, // 
        siteRateModel, // 
        branchRateModel, // 
        freqModel, // from
        1, // to
        sequenceLength - 1, // every
        3);
        // create partition
        Partition partition3 = new // 
        Partition(// 
        treeModel, // 
        substitutionModel, // 
        siteRateModel, // 
        branchRateModel, // 
        freqModel, // from
        2, // to
        sequenceLength - 1, // every
        3);
        partitionsList.add(partition1);
        partitionsList.add(Partition);
        partitionsList.add(partition3);
        // feed to sequence simulator and generate data
        BeagleSequenceSimulator simulator = new BeagleSequenceSimulator(partitionsList);
        if (i == (N - 1)) {
            System.out.println(simulator.simulate(simulateInPar, false).toString());
        } else {
            simulator.simulate(simulateInPar, false);
        }
    } 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) ArrayList(java.util.ArrayList) HomogeneousBranchModel(dr.evomodel.branchmodel.HomogeneousBranchModel) GammaSiteRateModel(dr.evomodel.siteratemodel.GammaSiteRateModel) DefaultTreeModel(dr.evomodel.tree.DefaultTreeModel) BeagleSequenceSimulator(dr.app.beagle.tools.BeagleSequenceSimulator) ImportException(dr.evolution.io.Importer.ImportException) IOException(java.io.IOException) DefaultBranchRateModel(dr.evomodel.branchratemodel.DefaultBranchRateModel) 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 27 with DefaultTreeModel

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

the class BeagleSeqSimTest method ancestralSequenceTree.

// END: simulateRandomBranchAssignment
static void ancestralSequenceTree() {
    try {
        LinkedHashMap<NodeRef, int[]> sequenceMap = new LinkedHashMap<NodeRef, int[]>();
        DataType dataType = Nucleotides.INSTANCE;
        // create tree
        NewickImporter importer = new NewickImporter("(SimSeq1:73.7468,(SimSeq2:25.256989999999995,SimSeq3:45.256989999999995):18.48981);");
        Tree tree = importer.importTree(null);
        DefaultTreeModel treeModel = new DefaultTreeModel(tree);
        for (NodeRef node : treeModel.getNodes()) {
            if (treeModel.isExternal(node)) {
                int[] seq = new int[] { 1, 1, 1 };
                sequenceMap.put(node, seq);
            } else {
                int[] seq = new int[] { 2, 2, 2 };
                sequenceMap.put(node, seq);
            }
        }
        // END: nodes loop
        AncestralSequenceTrait ancestralSequence = new AncestralSequenceTrait(sequenceMap, dataType);
        TreeTraitProvider[] treeTraitProviders = new TreeTraitProvider[] { ancestralSequence };
        StringBuffer buffer = new StringBuffer();
        NumberFormat format = NumberFormat.getNumberInstance(Locale.ENGLISH);
        boolean useTipLabels = true;
        // 
        TreeUtils.newick(// 
        treeModel, // 
        treeModel.getRoot(), // 
        useTipLabels, // 
        TreeUtils.BranchLengthType.LENGTHS_AS_TIME, // 
        format, // 
        null, // 
        treeTraitProviders, null, buffer);
        System.out.println(buffer);
    } catch (IOException e) {
        e.printStackTrace();
    } catch (ImportException e) {
        e.printStackTrace();
    }
// END: try-catch
}
Also used : TreeTraitProvider(dr.evolution.tree.TreeTraitProvider) DefaultTreeModel(dr.evomodel.tree.DefaultTreeModel) IOException(java.io.IOException) LinkedHashMap(java.util.LinkedHashMap) ImportException(dr.evolution.io.Importer.ImportException) NodeRef(dr.evolution.tree.NodeRef) NewickImporter(dr.evolution.io.NewickImporter) DataType(dr.evolution.datatype.DataType) Tree(dr.evolution.tree.Tree) NumberFormat(java.text.NumberFormat)

Example 28 with DefaultTreeModel

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

the class BeagleSeqSimTest method simulateTopology.

// END: annotateTree
static void simulateTopology() {
    try {
        System.out.println("Test case 1: simulateTopology");
        MathUtils.setSeed(666);
        int sequenceLength = 10;
        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);
        // set demographic function
        ExponentialGrowth exponentialGrowth = new ExponentialGrowth(Units.Type.YEARS);
        exponentialGrowth.setN0(10);
        exponentialGrowth.setGrowthRate(0.5);
        Taxa taxa = new Taxa();
        for (Taxon taxon : tree.asList()) {
            double absoluteHeight = Utils.getAbsoluteTaxonHeight(taxon, tree);
            taxon.setAttribute(Utils.ABSOLUTE_HEIGHT, absoluteHeight);
            // taxon.setAttribute("date", new Date(absoluteHeight,
            // Units.Type.YEARS, true));
            taxa.addTaxon(taxon);
        }
        // END: taxon loop
        CoalescentSimulator topologySimulator = new CoalescentSimulator();
        DefaultTreeModel treeModel = new DefaultTreeModel(topologySimulator.simulateTree(taxa, exponentialGrowth));
        System.out.println(treeModel.toString());
        Parameter freqs = new Parameter.Default(new double[] { 0.25, 0.25, 0.25, 0.25 });
        FrequencyModel freqModel = new FrequencyModel(Nucleotides.INSTANCE, freqs);
        // create substitution model
        Parameter kappa = new Parameter.Default(1, 10);
        HKY hky = new HKY(kappa, freqModel);
        HomogeneousBranchModel substitutionModel = new HomogeneousBranchModel(hky);
        // create site model
        GammaSiteRateModel siteRateModel = new GammaSiteRateModel("siteModel");
        // create branch rate model
        BranchRateModel branchRateModel = new DefaultBranchRateModel();
        // create partition
        Partition partition1 = new // 
        Partition(// 
        treeModel, // 
        substitutionModel, // 
        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);
        System.out.println(simulator.simulate(simulateInPar, false).toString());
    } 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) ExponentialGrowth(dr.evolution.coalescent.ExponentialGrowth) Taxon(dr.evolution.util.Taxon) ArrayList(java.util.ArrayList) HomogeneousBranchModel(dr.evomodel.branchmodel.HomogeneousBranchModel) GammaSiteRateModel(dr.evomodel.siteratemodel.GammaSiteRateModel) DefaultTreeModel(dr.evomodel.tree.DefaultTreeModel) CoalescentSimulator(dr.evolution.coalescent.CoalescentSimulator) BeagleSequenceSimulator(dr.app.beagle.tools.BeagleSequenceSimulator) ImportException(dr.evolution.io.Importer.ImportException) IOException(java.io.IOException) DefaultBranchRateModel(dr.evomodel.branchratemodel.DefaultBranchRateModel) Taxa(dr.evolution.util.Taxa) 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 29 with DefaultTreeModel

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

the class LineageSpecificBranchModel method main.

// END: acceptState
public static void main(String[] args) {
    try {
        // the seed of the BEAST
        MathUtils.setSeed(666);
        // create tree
        NewickImporter importer = new NewickImporter("(SimSeq1:73.7468,(SimSeq2:25.256989999999995,SimSeq3:45.256989999999995):18.48981);");
        TreeModel tree = new DefaultTreeModel(importer.importTree(null));
        // create site model
        GammaSiteRateModel siteRateModel = new GammaSiteRateModel("siteModel");
        // create branch rate model
        BranchRateModel branchRateModel = new DefaultBranchRateModel();
        int sequenceLength = 10;
        ArrayList<Partition> partitionsList = new ArrayList<Partition>();
        // create Frequency Model
        Parameter freqs = new Parameter.Default(new double[] { // 
        0.0163936, // 
        0.01639344, // 
        0.01639344, // 
        0.01639344, // 
        0.01639344, // 
        0.01639344, // 
        0.01639344, // 
        0.01639344, // 
        0.01639344, // 
        0.01639344, // 
        0.01639344, // 
        0.01639344, // 
        0.01639344, // 
        0.01639344, // 
        0.01639344, // 
        0.01639344, // 
        0.01639344, // 
        0.01639344, // 
        0.01639344, // 
        0.01639344, // 
        0.01639344, // 
        0.01639344, // 
        0.01639344, // 
        0.01639344, // 
        0.01639344, // 
        0.01639344, // 
        0.01639344, // 
        0.01639344, // 
        0.01639344, // 
        0.01639344, // 
        0.01639344, // 
        0.01639344, // 
        0.01639344, // 
        0.01639344, // 
        0.01639344, // 
        0.01639344, // 
        0.01639344, // 
        0.01639344, // 
        0.01639344, // 
        0.01639344, // 
        0.01639344, // 
        0.01639344, // 
        0.01639344, // 
        0.01639344, // 
        0.01639344, // 
        0.01639344, // 
        0.01639344, // 
        0.01639344, // 
        0.01639344, // 
        0.01639344, // 
        0.01639344, // 
        0.01639344, // 
        0.01639344, // 
        0.01639344, // 
        0.01639344, // 
        0.01639344, // 
        0.01639344, // 
        0.01639344, // 
        0.01639344, // 
        0.01639344, // 
        0.01639344 });
        FrequencyModel freqModel = new FrequencyModel(Codons.UNIVERSAL, freqs);
        // create substitution model
        Parameter alpha = new Parameter.Default(1, 10);
        Parameter beta = new Parameter.Default(1, 5);
        MG94HKYCodonModel mg94 = new MG94K80CodonModel(Codons.UNIVERSAL, alpha, beta, freqModel, new CodonOptions());
        HomogeneousBranchModel substitutionModel = new HomogeneousBranchModel(mg94);
        // create partition
        Partition partition1 = new // 
        Partition(// 
        tree, // 
        substitutionModel, // 
        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);
        ConvertAlignment convert = new ConvertAlignment(Nucleotides.INSTANCE, GeneticCode.UNIVERSAL, alignment);
        List<SubstitutionModel> substModels = new ArrayList<SubstitutionModel>();
        for (int i = 0; i < 2; i++) {
            // alpha = new Parameter.Default(1, 10 );
            // beta = new Parameter.Default(1, 5 );
            // mg94 = new MG94HKYCodonModel(Codons.UNIVERSAL, alpha, beta,
            // freqModel);
            substModels.add(mg94);
        }
        Parameter uCategories = new Parameter.Default(2, 0);
        // CountableBranchCategoryProvider provider = new CountableBranchCategoryProvider.IndependentBranchCategoryModel(tree, uCategories);
        LineageSpecificBranchModel branchSpecific = new // provider,
        LineageSpecificBranchModel(// provider,
        tree, // provider,
        freqModel, // provider,
        substModels, uCategories);
        BeagleTreeLikelihood like = new // 
        BeagleTreeLikelihood(// 
        convert, // 
        tree, // 
        branchSpecific, // 
        siteRateModel, // 
        branchRateModel, // 
        null, // 
        false, PartialsRescalingScheme.DEFAULT, true);
        BeagleTreeLikelihood gold = new // 
        BeagleTreeLikelihood(// 
        convert, // 
        tree, // 
        substitutionModel, // 
        siteRateModel, // 
        branchRateModel, // 
        null, // 
        false, PartialsRescalingScheme.DEFAULT, true);
        System.out.println("likelihood (gold) = " + gold.getLogLikelihood());
        System.out.println("likelihood = " + like.getLogLikelihood());
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : FrequencyModel(dr.evomodel.substmodel.FrequencyModel) MG94K80CodonModel(dr.evomodel.substmodel.codon.MG94K80CodonModel) BeagleSequenceSimulator(dr.app.beagle.tools.BeagleSequenceSimulator) DefaultBranchRateModel(dr.evomodel.branchratemodel.DefaultBranchRateModel) TreeModel(dr.evomodel.tree.TreeModel) DefaultTreeModel(dr.evomodel.tree.DefaultTreeModel) ConvertAlignment(dr.evolution.alignment.ConvertAlignment) Alignment(dr.evolution.alignment.Alignment) NewickImporter(dr.evolution.io.NewickImporter) ConvertAlignment(dr.evolution.alignment.ConvertAlignment) Partition(dr.app.beagle.tools.Partition) BeagleTreeLikelihood(dr.evomodel.treelikelihood.BeagleTreeLikelihood) CodonOptions(dr.evomodel.substmodel.codon.CodonOptions) HomogeneousBranchModel(dr.evomodel.branchmodel.HomogeneousBranchModel) GammaSiteRateModel(dr.evomodel.siteratemodel.GammaSiteRateModel) DefaultTreeModel(dr.evomodel.tree.DefaultTreeModel) SubstitutionModel(dr.evomodel.substmodel.SubstitutionModel) DefaultBranchRateModel(dr.evomodel.branchratemodel.DefaultBranchRateModel) BranchRateModel(dr.evomodel.branchratemodel.BranchRateModel) Parameter(dr.inference.model.Parameter) MG94HKYCodonModel(dr.evomodel.substmodel.codon.MG94HKYCodonModel)

Example 30 with DefaultTreeModel

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

the class DataLikelihoodTester method createSpecifiedTree.

private static TreeModel createSpecifiedTree(String t) throws Exception {
    NewickImporter importer = new NewickImporter(t);
    Tree tree = importer.importTree(null);
    // treeModel
    return new DefaultTreeModel(tree);
}
Also used : NewickImporter(dr.evolution.io.NewickImporter) Tree(dr.evolution.tree.Tree) DefaultTreeModel(dr.evomodel.tree.DefaultTreeModel)

Aggregations

DefaultTreeModel (dr.evomodel.tree.DefaultTreeModel)46 Tree (dr.evolution.tree.Tree)21 NewickImporter (dr.evolution.io.NewickImporter)19 Parameter (dr.inference.model.Parameter)19 ArrayList (java.util.ArrayList)14 BranchRateModel (dr.evomodel.branchratemodel.BranchRateModel)10 TreeModel (dr.evomodel.tree.TreeModel)10 GammaSiteModel (dr.oldevomodel.sitemodel.GammaSiteModel)10 HomogeneousBranchModel (dr.evomodel.branchmodel.HomogeneousBranchModel)9 GammaSiteRateModel (dr.evomodel.siteratemodel.GammaSiteRateModel)9 FrequencyModel (dr.evomodel.substmodel.FrequencyModel)9 TreeLikelihood (dr.oldevomodel.treelikelihood.TreeLikelihood)9 BeagleSequenceSimulator (dr.app.beagle.tools.BeagleSequenceSimulator)8 Partition (dr.app.beagle.tools.Partition)8 ImportException (dr.evolution.io.Importer.ImportException)8 Taxa (dr.evolution.util.Taxa)8 Taxon (dr.evolution.util.Taxon)8 DefaultBranchRateModel (dr.evomodel.branchratemodel.DefaultBranchRateModel)8 IOException (java.io.IOException)8 ExchangeOperator (dr.evomodel.operators.ExchangeOperator)7