Search in sources :

Example 56 with Tree

use of dr.evolution.tree.Tree 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 57 with Tree

use of dr.evolution.tree.Tree in project beast-mcmc by beast-dev.

the class NormalizedSequenceLikelihoodTest method createSillyTreeModel.

protected TreeModel createSillyTreeModel(int numTaxa) {
    SimpleNode[] nodes = new SimpleNode[2 * numTaxa - 1];
    for (int n = 0; n < 2 * numTaxa - 1; n++) {
        nodes[n] = new SimpleNode();
    }
    nodes[0].setTaxon(taxa[0]);
    nodes[1].setTaxon(taxa[1]);
    nodes[2].setHeight(1);
    nodes[2].addChild(nodes[0]);
    nodes[2].addChild(nodes[1]);
    SimpleNode root = nodes[2];
    if (numTaxa == 3) {
        nodes[3].setTaxon(taxa[2]);
        nodes[4].setHeight(2);
        nodes[4].addChild(nodes[2]);
        nodes[4].addChild(nodes[3]);
        root = nodes[4];
    }
    Tree tree = new SimpleTree(root);
    tree.setUnits(Units.Type.YEARS);
    //treeModel
    return new TreeModel(tree);
}
Also used : TreeModel(dr.evomodel.tree.TreeModel) Tree(dr.evolution.tree.Tree) SimpleTree(dr.evolution.tree.SimpleTree) SimpleTree(dr.evolution.tree.SimpleTree) SimpleNode(dr.evolution.tree.SimpleNode)

Example 58 with Tree

use of dr.evolution.tree.Tree in project beast-mcmc by beast-dev.

the class PathogenFrame method readFromFile.

protected boolean readFromFile(File file) throws IOException {
    Reader reader = new FileReader(file);
    BufferedReader bufferedReader = new BufferedReader(reader);
    String line = bufferedReader.readLine();
    while (line != null && line.length() == 0) {
        line = bufferedReader.readLine();
    }
    boolean isNexus = (line != null && line.toUpperCase().contains("#NEXUS"));
    reader = new FileReader(file);
    Tree tree = null;
    try {
        if (isNexus) {
            NexusImporter importer = new NexusImporter(reader);
            tree = importer.importTree(taxa);
        } else {
            NewickImporter importer = new NewickImporter(reader);
            tree = importer.importTree(taxa);
        }
    } catch (Importer.ImportException ime) {
        JOptionPane.showMessageDialog(this, "Error parsing imported file: " + ime, "Error reading file", JOptionPane.ERROR_MESSAGE);
        ime.printStackTrace();
        return false;
    } catch (IOException ioex) {
        JOptionPane.showMessageDialog(this, "File I/O Error: " + ioex, "File I/O Error", JOptionPane.ERROR_MESSAGE);
        ioex.printStackTrace();
        return false;
    } catch (Exception ex) {
        JOptionPane.showMessageDialog(this, "Fatal exception: " + ex, "Error reading file", JOptionPane.ERROR_MESSAGE);
        ex.printStackTrace();
        return false;
    }
    if (tree == null) {
        JOptionPane.showMessageDialog(this, "The file is not in a suitable format or contains no trees.", "Error reading file", JOptionPane.ERROR_MESSAGE);
        return false;
    }
    FlexibleTree binaryTree = new FlexibleTree(tree, true);
    binaryTree.resolveTree();
    trees.add(binaryTree);
    if (taxa == null) {
        taxa = binaryTree;
    }
    getExportTreeAction().setEnabled(true);
    getExportDataAction().setEnabled(true);
    return true;
}
Also used : FlexibleTree(dr.evolution.tree.FlexibleTree) FlexibleTree(dr.evolution.tree.FlexibleTree) Tree(dr.evolution.tree.Tree)

Example 59 with Tree

use of dr.evolution.tree.Tree in project beast-mcmc by beast-dev.

the class PathogenFrame method setStatusMessage.

private void setStatusMessage() {
    Tree tree = pathogenPanel.getTree();
    if (tree != null) {
        String message = "";
        message += "Tree loaded, " + tree.getTaxonCount() + " taxa";
        TemporalRooting tr = pathogenPanel.getTemporalRooting();
        if (tr.isContemporaneous()) {
            message += ", contemporaneous tips";
        } else {
            NumberFormatter nf = new NumberFormatter(3);
            message += ", dated tips with range " + nf.format(tr.getDateRange());
        }
        statusLabel.setText(message);
    }
}
Also used : FlexibleTree(dr.evolution.tree.FlexibleTree) Tree(dr.evolution.tree.Tree) NumberFormatter(dr.util.NumberFormatter)

Example 60 with Tree

use of dr.evolution.tree.Tree in project beast-mcmc by beast-dev.

the class TreeTrace method loadTreeTrace.

/**
     * Loads the trace for with trees from a reader
     *
     * @param r the reader to load the trees from
     * @return the TreeTrace
     * @throws dr.evolution.io.Importer.ImportException
     *                             thrown when tree file is not correctly formatted
     * @throws java.io.IOException if general I/O error occurs
     */
public static TreeTrace loadTreeTrace(Reader r) throws IOException, Importer.ImportException {
    BufferedReader reader = new BufferedReader(r);
    TreeTrace trace = new TreeTrace();
    dr.evolution.util.TaxonList taxonList = null;
    int minState = -1;
    int stepSize = 0;
    String line = reader.readLine();
    if (line.toUpperCase().startsWith("#NEXUS")) {
        NexusImporter importer = new NexusImporter(reader);
        Tree[] trees = importer.importTrees(null);
        if (trees.length < 2) {
            throw new Importer.ImportException("Less than two trees in the trace file");
        }
        String id1 = trees[0].getId();
        String id2 = trees[1].getId();
        minState = getStateNumber(id1);
        stepSize = getStateNumber(id2) - minState;
        for (Tree tree : trees) {
            trace.add(tree);
        }
    } else {
        NewickImporter importer = new NewickImporter(reader);
        while (true) {
            int state = 0;
            Tree tree;
            try {
                state = importer.readInteger();
                tree = importer.importTree(taxonList);
                if (taxonList == null) {
                    // The first tree becomes the taxon list. This means
                    // that all subsequent trees will look up their taxa
                    // in that taxon list rather than creating their own
                    // duplicitous ones.
                    taxonList = tree;
                }
            } catch (Importer.ImportException ie) {
                System.out.println("Error reading tree for state " + state);
                throw ie;
            } catch (EOFException e) {
                break;
            }
            if (minState == -1) {
                minState = state;
            } else if (stepSize == 0) {
                stepSize = state - minState;
            }
            trace.add(tree);
        }
    }
    trace.setMinimumState(minState);
    trace.setStepSize(stepSize);
    return trace;
}
Also used : BufferedReader(java.io.BufferedReader) EOFException(java.io.EOFException) Tree(dr.evolution.tree.Tree)

Aggregations

Tree (dr.evolution.tree.Tree)128 NewickImporter (dr.evolution.io.NewickImporter)32 ArrayList (java.util.ArrayList)31 TreeModel (dr.evomodel.tree.TreeModel)26 Parameter (dr.inference.model.Parameter)26 NexusImporter (dr.evolution.io.NexusImporter)18 TaxonList (dr.evolution.util.TaxonList)18 Taxa (dr.evolution.util.Taxa)17 FlexibleTree (dr.evolution.tree.FlexibleTree)16 Taxon (dr.evolution.util.Taxon)15 BranchRateModel (dr.evomodel.branchratemodel.BranchRateModel)15 NodeRef (dr.evolution.tree.NodeRef)14 SimpleTree (dr.evolution.tree.SimpleTree)13 ImportException (dr.evolution.io.Importer.ImportException)12 Importer (dr.evolution.io.Importer)11 DefaultBranchRateModel (dr.evomodel.branchratemodel.DefaultBranchRateModel)11 BeagleSequenceSimulator (dr.app.beagle.tools.BeagleSequenceSimulator)10 Partition (dr.app.beagle.tools.Partition)10 GammaSiteRateModel (dr.evomodel.siteratemodel.GammaSiteRateModel)10 FrequencyModel (dr.evomodel.substmodel.FrequencyModel)9