Search in sources :

Example 11 with Node

use of jebl.evolution.graphs.Node in project beast-mcmc by beast-dev.

the class TreeKMLGenerator method generateTree.

private Element generateTree(RootedTree tree, Settings settings, TreeSettings treeSettings, List<Element> styles) {
    BranchStyle branchStyle = treeSettings.getBranchStyle();
    Element element = generateContainer("Folder", treeSettings.getName(), treeSettings.getDescription(), true, null);
    double scaleFactor = settings.getPlotAltitude() / tree.getHeight(tree.getRootNode());
    int nodeNumber = 0;
    for (Node node : tree.getNodes()) {
        nodeNumber++;
        double latitude;
        double longitude;
        Object[] location = getArrayNodeAttribute(node, settings.getTraitName());
        if (location != null) {
            latitude = (Double) location[0];
            longitude = (Double) location[0];
        } else {
            latitude = getDoubleNodeAttribute(node, settings.getLatitudeName());
            longitude = getDoubleNodeAttribute(node, settings.getLongitudeName());
        }
        double altitude = (tree.getHeight(node) * scaleFactor);
        double date = settings.getMostRecentDate() - tree.getHeight(node);
        if (tree.isExternal(node)) {
            System.out.println(tree.getTaxon(node).getName() + "\t" + latitude + "\t" + longitude);
        }
        if (!tree.isRoot(node)) {
            // Create each branch of the tree..
            Element branch;
            String nodeName = treeSettings.getName() + "_node" + nodeNumber;
            if (tree.isExternal(node)) {
                Element tip = generateTaxonLabel(tree, node, tree.getTaxon(node).getName(), tree.getHeight(node), date, latitude, longitude);
                element.addContent(tip);
            }
            Node parentNode = tree.getParent(node);
            double parentLatitude = getDoubleNodeAttribute(parentNode, settings.getLatitudeName());
            double parentLongitude = getDoubleNodeAttribute(parentNode, settings.getLongitudeName());
            double parentAltitude = (tree.getHeight(parentNode) * scaleFactor);
            double parentDate = settings.getMostRecentDate() - tree.getHeight(parentNode);
            double width = branchStyle.getWidthBase();
            if (branchStyle.getWidthProperty() != null) {
                double property = getDoubleNodeAttribute(node, branchStyle.getWidthProperty(), 0.0);
                width += ((property - branchStyle.getWidthPropertyMinimum()) / (branchStyle.getWidthPropertyMaximum() - branchStyle.getWidthPropertyMinimum())) * branchStyle.getWidthScale();
            }
            Color color = branchStyle.getColorStart();
            if (branchStyle.getColorProperty() != null) {
                double property;
                if (branchStyle.getColorProperty().equalsIgnoreCase("height")) {
                    property = tree.getHeight(node) / maxHeight;
                } else {
                    property = getDoubleNodeAttribute(node, branchStyle.getColorProperty());
                    property = ((property - branchStyle.getWidthPropertyMinimum()) / (branchStyle.getWidthPropertyMaximum() - branchStyle.getWidthPropertyMinimum())) * branchStyle.getWidthScale();
                }
                color = getBlendedColor((float) property, branchStyle.getColorStart(), branchStyle.getColorFinish());
            }
            LineStyle lineStyle = new LineStyle(width, color);
            if (treeSettings.getTreeType() == TreeType.RECTANGLE_TREE || treeSettings.getTreeType() == TreeType.TRIANGLE_TREE) {
                branch = generateBranch(treeSettings.getTreeType(), tree, node, nodeName, parentLatitude, latitude, parentLongitude, longitude, parentAltitude, altitude, 0.0, parentAltitude, date, date, settings.getAgeCutOff(), lineStyle, null, 0, styles);
            } else if (treeSettings.getTreeType() == TreeType.ARC_TREE) {
                LineStyle lineStyle2 = null;
                // color range from the parent height to the node height.
                if (branchStyle.getColorProperty() != null && branchStyle.getColorProperty().equalsIgnoreCase("height")) {
                    double divisor = (settings.getAgeCutOff() > 0 ? settings.getMostRecentDate() - settings.getAgeCutOff() : maxHeight);
                    color = getBlendedColor((float) (tree.getHeight(parentNode) / divisor), branchStyle.getColorStart(), branchStyle.getColorFinish());
                    lineStyle = new LineStyle(width, color);
                    color = getBlendedColor((float) (tree.getHeight(node) / divisor), branchStyle.getColorStart(), branchStyle.getColorFinish());
                    lineStyle2 = new LineStyle(width, color);
                }
                branch = generateBranch(treeSettings.getTreeType(), tree, node, nodeName, parentLatitude, latitude, parentLongitude, longitude, parentAltitude, altitude, 0.0, parentAltitude, parentDate, date, settings.getAgeCutOff(), lineStyle, lineStyle2, 50, styles);
            } else if (treeSettings.getTreeType() == TreeType.SURFACE_TREE) {
                double maxAltitude = settings.getPlotAltitude() * (tree.getHeight(parentNode) - tree.getHeight(node)) / maxBranchLength;
                LineStyle lineStyle2 = null;
                // color range from the parent height to the node height.
                if (branchStyle.getColorProperty() != null && branchStyle.getColorProperty().equalsIgnoreCase("height")) {
                    double divisor = (settings.getAgeCutOff() > 0 ? settings.getMostRecentDate() - settings.getAgeCutOff() : maxHeight);
                    color = getBlendedColor((float) (tree.getHeight(parentNode) / divisor), branchStyle.getColorStart(), branchStyle.getColorFinish());
                    lineStyle = new LineStyle(width, color);
                    color = getBlendedColor((float) (tree.getHeight(node) / divisor), branchStyle.getColorStart(), branchStyle.getColorFinish());
                    lineStyle2 = new LineStyle(width, color);
                }
                branch = generateBranch(treeSettings.getTreeType(), tree, node, nodeName, parentLatitude, latitude, parentLongitude, longitude, 0.0, 0.0, 0.5, maxAltitude, parentDate, date, settings.getAgeCutOff(), lineStyle, lineStyle2, settings.getTimeDivisionCount(), styles);
            } else {
                throw new IllegalArgumentException("Unknown TreeType");
            }
            element.addContent(branch);
        }
    }
    return element;
}
Also used : Node(jebl.evolution.graphs.Node)

Example 12 with Node

use of jebl.evolution.graphs.Node in project beast-mcmc by beast-dev.

the class PathogenPanel method getSelectedTips.

public List<String> getSelectedTips() {
    List<String> tips = new ArrayList<String>();
    jebl.evolution.trees.Tree tree = treePanel.getTreeViewer().getTrees().get(0);
    for (Node node : treePanel.getTreeViewer().getSelectedTips()) {
        tips.add(tree.getTaxon(node).getName());
    }
    return tips;
}
Also used : Node(jebl.evolution.graphs.Node)

Example 13 with Node

use of jebl.evolution.graphs.Node in project beast-mcmc by beast-dev.

the class BranchScoreMetric method getClades.

private void getClades(Map<Taxon, Integer> taxonMap, RootedTree tree, Node node, List<Clade> clades, BitSet bits) {
    BitSet bits2 = new BitSet();
    if (tree.isExternal(node)) {
        int index = taxonMap.get(tree.getTaxon(node));
        bits2.set(index);
    } else {
        for (Node child : tree.getChildren(node)) {
            getClades(taxonMap, tree, child, clades, bits2);
        }
        clades.add(new Clade(bits2, tree.getHeight(node)));
    }
    if (bits != null) {
        bits.or(bits2);
    }
}
Also used : Node(jebl.evolution.graphs.Node) BitSet(java.util.BitSet)

Example 14 with Node

use of jebl.evolution.graphs.Node in project beast-mcmc by beast-dev.

the class CladeMetric method getClade.

private Clade getClade(Map<Taxon, Integer> taxonMap, RootedTree tree, Node node, BitSet bits) {
    BitSet bits2 = new BitSet();
    Clade c = null;
    if (tree.isExternal(node)) {
        int index = taxonMap.get(tree.getTaxon(node));
        bits2.set(index);
    } else {
        for (Node child : tree.getChildren(node)) {
            getClade(taxonMap, tree, child, bits2);
        }
        c = new Clade(bits2, tree.getHeight(node));
    }
    if (bits != null) {
        bits.or(bits2);
    }
    return c;
}
Also used : Node(jebl.evolution.graphs.Node)

Example 15 with Node

use of jebl.evolution.graphs.Node in project beast-mcmc by beast-dev.

the class CladeMetric method getClades.

private void getClades(Map<Taxon, Integer> taxonMap, RootedTree tree, Node node, List<Clade> clades, BitSet bits) {
    BitSet bits2 = new BitSet();
    if (tree.isExternal(node)) {
        int index = taxonMap.get(tree.getTaxon(node));
        bits2.set(index);
    } else {
        for (Node child : tree.getChildren(node)) {
            getClades(taxonMap, tree, child, clades, bits2);
        }
        clades.add(new Clade(bits2, tree.getHeight(node)));
    }
    if (bits != null) {
        bits.or(bits2);
    }
}
Also used : Node(jebl.evolution.graphs.Node)

Aggregations

Node (jebl.evolution.graphs.Node)23 Variate (dr.stats.Variate)3 RootedTree (jebl.evolution.trees.RootedTree)3 Regression (dr.stats.Regression)2 NumberFormatter (dr.util.NumberFormatter)2 Taxon (jebl.evolution.taxa.Taxon)2 Location (dr.app.phylogeography.tools.kml.Location)1 BufferedReader (java.io.BufferedReader)1 FileReader (java.io.FileReader)1 ArrayList (java.util.ArrayList)1 BitSet (java.util.BitSet)1 NewickImporter (jebl.evolution.io.NewickImporter)1 NexusImporter (jebl.evolution.io.NexusImporter)1 TreeImporter (jebl.evolution.io.TreeImporter)1 Element (org.jdom.Element)1