Search in sources :

Example 11 with Patterns

use of dr.evolution.alignment.Patterns in project beast-mcmc by beast-dev.

the class BEAUTiImporter method importMicroSatFile.

// micro-sat
private void importMicroSatFile(File file) throws IOException, ImportException {
    try {
        Reader reader = new FileReader(file);
        BufferedReader bufferedReader = new BufferedReader(reader);
        MicroSatImporter importer = new MicroSatImporter(bufferedReader);
        List<Patterns> microsatPatList = importer.importPatterns();
        Taxa unionSetTaxonList = importer.getUnionSetTaxonList();
        Microsatellite microsatellite = importer.getMicrosatellite();
        //            options.allowDifferentTaxa = importer.isHasDifferentTaxon();
        bufferedReader.close();
        PartitionSubstitutionModel substModel = new PartitionSubstitutionModel(options, microsatPatList.get(0).getId());
        substModel.setMicrosatellite(microsatellite);
        for (Patterns patterns : microsatPatList) {
            setData(file.getName(), unionSetTaxonList, patterns, substModel, null);
        }
        // has to call after data is imported
        options.microsatelliteOptions.initModelParametersAndOpererators();
    } catch (ImportException e) {
        throw new ImportException(e.getMessage());
    } catch (IOException e) {
        throw new IOException(e.getMessage());
    }
}
Also used : ImportException(dr.evolution.io.Importer.ImportException) Taxa(dr.evolution.util.Taxa) Microsatellite(dr.evolution.datatype.Microsatellite) MicroSatImporter(dr.evolution.io.MicroSatImporter) Patterns(dr.evolution.alignment.Patterns)

Example 12 with Patterns

use of dr.evolution.alignment.Patterns 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 TreeModel(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 : 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 13 with Patterns

use of dr.evolution.alignment.Patterns 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 TreeModel(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 : 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 14 with Patterns

use of dr.evolution.alignment.Patterns 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 15 with Patterns

use of dr.evolution.alignment.Patterns in project beast-mcmc by beast-dev.

the class FitchParsimony method main.

public static void main(String[] argv) {
    FlexibleNode tip1 = new FlexibleNode(new Taxon("tip1"));
    FlexibleNode tip2 = new FlexibleNode(new Taxon("tip2"));
    FlexibleNode tip3 = new FlexibleNode(new Taxon("tip3"));
    FlexibleNode tip4 = new FlexibleNode(new Taxon("tip4"));
    FlexibleNode tip5 = new FlexibleNode(new Taxon("tip5"));
    FlexibleNode node1 = new FlexibleNode();
    node1.addChild(tip1);
    node1.addChild(tip2);
    FlexibleNode node2 = new FlexibleNode();
    node2.addChild(tip4);
    node2.addChild(tip5);
    FlexibleNode node3 = new FlexibleNode();
    node3.addChild(tip3);
    node3.addChild(node2);
    FlexibleNode root = new FlexibleNode();
    root.addChild(node1);
    root.addChild(node3);
    FlexibleTree tree = new FlexibleTree(root);
    Patterns patterns = new Patterns(Nucleotides.INSTANCE, tree);
    patterns.addPattern(new int[] { 1, 0, 1, 2, 2 });
    FitchParsimony fitch = new FitchParsimony(patterns, false);
    System.out.println("No. Steps = " + fitch.getScore(tree));
    System.out.println(" state(node1) = " + fitch.getStates(tree, node1)[0]);
    System.out.println(" state(node2) = " + fitch.getStates(tree, node2)[0]);
    System.out.println(" state(node3) = " + fitch.getStates(tree, node3)[0]);
    System.out.println(" state(root) = " + fitch.getStates(tree, root)[0]);
    System.out.println("\nParsimony static methods:");
    System.out.println("No. Steps = " + Parsimony.getParsimonySteps(tree, patterns));
    Parsimony.reconstructParsimonyStates(tree, patterns);
    System.out.println(" state(node1) = " + tree.getNodeAttribute(node1, "rstate1"));
    System.out.println(" state(node2) = " + tree.getNodeAttribute(node2, "rstate1"));
    System.out.println(" state(node3) = " + tree.getNodeAttribute(node3, "rstate1"));
    System.out.println(" state(root) = " + tree.getNodeAttribute(root, "rstate1"));
}
Also used : Taxon(dr.evolution.util.Taxon) Patterns(dr.evolution.alignment.Patterns)

Aggregations

Patterns (dr.evolution.alignment.Patterns)21 Microsatellite (dr.evolution.datatype.Microsatellite)9 Taxa (dr.evolution.util.Taxa)9 Taxon (dr.evolution.util.Taxon)9 TreeModel (dr.evomodel.tree.TreeModel)9 ArrayList (java.util.ArrayList)9 Tree (dr.evolution.tree.Tree)7 BranchRateModel (dr.evomodel.branchratemodel.BranchRateModel)6 PatternList (dr.evolution.alignment.PatternList)4 NewickImporter (dr.evolution.io.NewickImporter)4 BranchModel (dr.evomodel.branchmodel.BranchModel)4 GammaSiteRateModel (dr.evomodel.siteratemodel.GammaSiteRateModel)4 PartialsRescalingScheme (dr.evomodel.treelikelihood.PartialsRescalingScheme)4 Parameter (dr.inference.model.Parameter)4 GammaSiteModel (dr.oldevomodel.sitemodel.GammaSiteModel)4 AsymmetricQuadraticModel (dr.oldevomodel.substmodel.AsymmetricQuadraticModel)4 SitePatterns (dr.evolution.alignment.SitePatterns)3 TaxonList (dr.evolution.util.TaxonList)3 HomogeneousBranchModel (dr.evomodel.branchmodel.HomogeneousBranchModel)3 FrequencyModel (dr.evomodel.substmodel.FrequencyModel)3