Search in sources :

Example 1 with DistanceMatrix

use of dr.evolution.distance.DistanceMatrix in project beast-mcmc by beast-dev.

the class OldTreesPanel method createTree.

private void createTree() {
    if (generateTreeDialog == null) {
        generateTreeDialog = new GenerateTreeDialog(frame);
    }
    int result = generateTreeDialog.showDialog(options);
    if (result != JOptionPane.CANCEL_OPTION) {
        GenerateTreeDialog.MethodTypes methodType = generateTreeDialog.getMethodType();
        PartitionData partition = generateTreeDialog.getDataPartition();
        Patterns patterns = new Patterns(partition.getAlignment());
        DistanceMatrix distances = new F84DistanceMatrix(patterns);
        Tree tree;
        TemporalRooting temporalRooting;
        switch(methodType) {
            case NJ:
                tree = new NeighborJoiningTree(distances);
                temporalRooting = new TemporalRooting(tree);
                tree = temporalRooting.findRoot(tree, TemporalRooting.RootingFunction.CORRELATION);
                break;
            case UPGMA:
                tree = new UPGMATree(distances);
                temporalRooting = new TemporalRooting(tree);
                break;
            default:
                throw new IllegalArgumentException("unknown method type");
        }
        tree.setId(generateTreeDialog.getName());
        options.userTrees.add(tree);
        treesTableModel.fireTableDataChanged();
        int row = options.userTrees.size() - 1;
        treesTable.getSelectionModel().setSelectionInterval(row, row);
    }
    fireTreePriorsChanged();
}
Also used : F84DistanceMatrix(dr.evolution.distance.F84DistanceMatrix) NeighborJoiningTree(dr.evolution.tree.NeighborJoiningTree) PartitionData(dr.app.beauti.options.PartitionData) UPGMATree(dr.evolution.tree.UPGMATree) NeighborJoiningTree(dr.evolution.tree.NeighborJoiningTree) Tree(dr.evolution.tree.Tree) TemporalRooting(dr.app.pathogen.TemporalRooting) F84DistanceMatrix(dr.evolution.distance.F84DistanceMatrix) DistanceMatrix(dr.evolution.distance.DistanceMatrix) UPGMATree(dr.evolution.tree.UPGMATree) Patterns(dr.evolution.alignment.Patterns)

Example 2 with DistanceMatrix

use of dr.evolution.distance.DistanceMatrix in project beast-mcmc by beast-dev.

the class ApproximatePoissonTreeLikelihoodParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    int sequenceLength = xo.getIntegerAttribute("sequenceLength");
    TreeModel treeModel = (TreeModel) xo.getChild(TreeModel.class);
    BranchLengthProvider branchLengthProvider;
    if (xo.getElementFirstChild(DATA) instanceof Tree) {
        Tree dataTree = (Tree) xo.getElementFirstChild(DATA);
        CladeNodeModel cladeNodeModel = null;
        try {
            cladeNodeModel = new CladeNodeModel(dataTree, treeModel);
        } catch (TreeUtils.MissingTaxonException e) {
            e.printStackTrace();
        }
        branchLengthProvider = new ConstrainedTreeBranchLengthProvider(cladeNodeModel);
    } else if (xo.getElementFirstChild(DATA) instanceof CladeNodeModel) {
        CladeNodeModel cladeNodeModel = (CladeNodeModel) xo.getElementFirstChild(DATA);
        branchLengthProvider = new ConstrainedTreeBranchLengthProvider(cladeNodeModel);
    } else {
        DistanceMatrix dataMatrix = (DistanceMatrix) xo.getElementFirstChild(DATA);
        branchLengthProvider = new RzhetskyNeiBranchLengthProvider(dataMatrix, treeModel);
    }
    BranchRateModel branchRateModel = (BranchRateModel) xo.getChild(BranchRateModel.class);
    return new ApproximatePoissonTreeLikelihood(TREE_LIKELIHOOD, sequenceLength, treeModel, branchRateModel, branchLengthProvider);
}
Also used : TreeModel(dr.evomodel.tree.TreeModel) BranchRateModel(dr.evomodel.branchratemodel.BranchRateModel) ConstrainedTreeBranchLengthProvider(dr.evomodel.bigfasttree.constrainedtree.ConstrainedTreeBranchLengthProvider) Tree(dr.evolution.tree.Tree) CladeNodeModel(dr.evomodel.bigfasttree.constrainedtree.CladeNodeModel) ConstrainedTreeBranchLengthProvider(dr.evomodel.bigfasttree.constrainedtree.ConstrainedTreeBranchLengthProvider) DistanceMatrix(dr.evolution.distance.DistanceMatrix) TreeUtils(dr.evolution.tree.TreeUtils)

Example 3 with DistanceMatrix

use of dr.evolution.distance.DistanceMatrix in project beast-mcmc by beast-dev.

the class DistanceMatrixParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    PatternList patterns = (PatternList) xo.getChild(PatternList.class);
    DistanceMatrix matrix = null;
    String type = xo.getStringAttribute(CORRECTION);
    if (type.equals(Nucleotides.JC)) {
        Logger.getLogger("dr.evoxml").info("Creating Jukes-Cantor distance matrix");
        matrix = new JukesCantorDistanceMatrix(patterns);
    } else if (type.equals(Nucleotides.F84)) {
        Logger.getLogger("dr.evoxml").info("Creating F84 distance matrix");
        matrix = new F84DistanceMatrix(patterns);
    } else if (type.equals("SMM")) {
        Logger.getLogger("dr.evoxml").info("Creating SMM distance matrix");
        matrix = new SMMDistanceMatrix(patterns);
    } else {
        matrix = new DistanceMatrix(patterns);
    }
    return matrix;
}
Also used : F84DistanceMatrix(dr.evolution.distance.F84DistanceMatrix) SMMDistanceMatrix(dr.evolution.distance.SMMDistanceMatrix) PatternList(dr.evolution.alignment.PatternList) F84DistanceMatrix(dr.evolution.distance.F84DistanceMatrix) JukesCantorDistanceMatrix(dr.evolution.distance.JukesCantorDistanceMatrix) DistanceMatrix(dr.evolution.distance.DistanceMatrix) SMMDistanceMatrix(dr.evolution.distance.SMMDistanceMatrix) JukesCantorDistanceMatrix(dr.evolution.distance.JukesCantorDistanceMatrix)

Example 4 with DistanceMatrix

use of dr.evolution.distance.DistanceMatrix in project beast-mcmc by beast-dev.

the class UPGMATreeParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    boolean usingDatesSpecified = false;
    boolean usingDates = true;
    double rootHeight = xo.getAttribute(ROOT_HEIGHT, -1.0);
    if (xo.hasAttribute(SimpleTreeParser.USING_DATES)) {
        usingDatesSpecified = true;
        usingDates = xo.getBooleanAttribute(SimpleTreeParser.USING_DATES);
    }
    DistanceMatrix distances = (DistanceMatrix) xo.getChild(DistanceMatrix.class);
    UPGMATree tree = new UPGMATree(distances);
    if (rootHeight > 0) {
        double scaleFactor = rootHeight / tree.getNodeHeight(tree.getRoot());
        for (int i = 0; i < tree.getInternalNodeCount(); i++) {
            NodeRef node = tree.getInternalNode(i);
            double height = tree.getNodeHeight(node);
            tree.setNodeHeight(node, height * scaleFactor);
        }
    }
    if (usingDates) {
        dr.evolution.util.Date mostRecent = null;
        for (int i = 0; i < tree.getTaxonCount(); i++) {
            dr.evolution.util.Date date = (dr.evolution.util.Date) tree.getTaxonAttribute(i, dr.evolution.util.Date.DATE);
            if (date == null) {
                date = (dr.evolution.util.Date) tree.getNodeAttribute(tree.getExternalNode(i), dr.evolution.util.Date.DATE);
            }
            if (date != null && ((mostRecent == null) || date.after(mostRecent))) {
                mostRecent = date;
            }
        }
        for (int i = 0; i < tree.getInternalNodeCount(); i++) {
            dr.evolution.util.Date date = (dr.evolution.util.Date) tree.getNodeAttribute(tree.getInternalNode(i), dr.evolution.util.Date.DATE);
            if (date != null && ((mostRecent == null) || date.after(mostRecent))) {
                mostRecent = date;
            }
        }
        if (mostRecent == null) {
            if (usingDatesSpecified) {
                throw new XMLParseException("no date elements in tree (and usingDates attribute set)");
            }
        } else {
            TimeScale timeScale = new TimeScale(mostRecent.getUnits(), true, mostRecent.getAbsoluteTimeValue());
            for (int i = 0; i < tree.getTaxonCount(); i++) {
                dr.evolution.util.Date date = (dr.evolution.util.Date) tree.getTaxonAttribute(i, dr.evolution.util.Date.DATE);
                if (date == null) {
                    date = (dr.evolution.util.Date) tree.getNodeAttribute(tree.getExternalNode(i), dr.evolution.util.Date.DATE);
                }
                if (date != null) {
                    double height = timeScale.convertTime(date.getTimeValue(), date);
                    tree.setNodeHeight(tree.getExternalNode(i), height);
                }
            }
            for (int i = 0; i < tree.getInternalNodeCount(); i++) {
                dr.evolution.util.Date date = (dr.evolution.util.Date) tree.getNodeAttribute(tree.getInternalNode(i), dr.evolution.util.Date.DATE);
                if (date != null) {
                    double height = timeScale.convertTime(date.getTimeValue(), date);
                    tree.setNodeHeight(tree.getInternalNode(i), height);
                }
            }
            MutableTree.Utils.correctHeightsForTips(tree);
        }
    }
    if (rootHeight > 0) {
        double scaleFactor = rootHeight / tree.getNodeHeight(tree.getRoot());
        for (int i = 0; i < tree.getInternalNodeCount(); i++) {
            NodeRef node = tree.getInternalNode(i);
            double height = tree.getNodeHeight(node);
            tree.setNodeHeight(node, height * scaleFactor);
        }
    }
    if (xo.getAttribute(RANDOMIZE, false)) {
        shakeTree(tree);
    }
    return tree;
}
Also used : UPGMATree(dr.evolution.tree.UPGMATree) TimeScale(dr.evolution.util.TimeScale) NodeRef(dr.evolution.tree.NodeRef) DistanceMatrix(dr.evolution.distance.DistanceMatrix)

Example 5 with DistanceMatrix

use of dr.evolution.distance.DistanceMatrix in project beast-mcmc by beast-dev.

the class RzhetskyNeiBranchLengthsTreeTrest method setUp.

// +------------------------------------------------ 0
// +----------------------- |
// |                        +------------------------------------------------ 1
// |
// +-------------------------------------------------------------------------------------------------- 2
public void setUp() throws Exception {
    super.setUp();
    MathUtils.setSeed(1);
    NewickImporter importer = new NewickImporter("((0:1,1:1):0.5,2:2);");
    timeTree = new BigFastTreeModel(importer.importTree(null));
    m = new DistanceMatrix(timeTree);
    m.setElement(0, 0, 0);
    m.setElement(0, 1, 2);
    m.setElement(0, 2, 3.5);
    m.setElement(1, 0, 2);
    m.setElement(1, 1, 0);
    m.setElement(1, 2, 3.5);
    m.setElement(2, 0, 3.5);
    m.setElement(2, 1, 3.5);
    m.setElement(2, 2, 0);
}
Also used : NewickImporter(dr.evolution.io.NewickImporter) BigFastTreeModel(dr.evomodel.bigfasttree.BigFastTreeModel) DistanceMatrix(dr.evolution.distance.DistanceMatrix)

Aggregations

DistanceMatrix (dr.evolution.distance.DistanceMatrix)5 F84DistanceMatrix (dr.evolution.distance.F84DistanceMatrix)2 Tree (dr.evolution.tree.Tree)2 UPGMATree (dr.evolution.tree.UPGMATree)2 PartitionData (dr.app.beauti.options.PartitionData)1 TemporalRooting (dr.app.pathogen.TemporalRooting)1 PatternList (dr.evolution.alignment.PatternList)1 Patterns (dr.evolution.alignment.Patterns)1 JukesCantorDistanceMatrix (dr.evolution.distance.JukesCantorDistanceMatrix)1 SMMDistanceMatrix (dr.evolution.distance.SMMDistanceMatrix)1 NewickImporter (dr.evolution.io.NewickImporter)1 NeighborJoiningTree (dr.evolution.tree.NeighborJoiningTree)1 NodeRef (dr.evolution.tree.NodeRef)1 TreeUtils (dr.evolution.tree.TreeUtils)1 TimeScale (dr.evolution.util.TimeScale)1 BigFastTreeModel (dr.evomodel.bigfasttree.BigFastTreeModel)1 CladeNodeModel (dr.evomodel.bigfasttree.constrainedtree.CladeNodeModel)1 ConstrainedTreeBranchLengthProvider (dr.evomodel.bigfasttree.constrainedtree.ConstrainedTreeBranchLengthProvider)1 BranchRateModel (dr.evomodel.branchratemodel.BranchRateModel)1 TreeModel (dr.evomodel.tree.TreeModel)1