Search in sources :

Example 1 with RootedTree

use of jebl.evolution.trees.RootedTree in project beast-mcmc by beast-dev.

the class ContinuousTreeToKML method main.

public static void main(String[] args) {
    // altitutude of the root of the 3D trees
    double altitude = 0;
    // required to convert heights to calendar dates
    double mostRecentDate = 2010;
    String coordinateLabel = "loc";
    boolean makeTreeSlices = false;
    double[] sliceTimes = null;
    double treeSliceBranchWidth = 3;
    // shows complete branch for slice if time is more recent than the branch's midpoint
    boolean showBranchAtMidPoint = false;
    Arguments arguments = new Arguments(new Arguments.Option[] { new Arguments.StringOption(ANNOTATION, "location annotation label", "specifies the label used for location coordinates annotation [default=location]"), new Arguments.RealOption(ALTITUDE, "specifies the altitude of the root of the 3D tree [default=no 3D tree]"), new Arguments.RealOption(MRSD, "specifies the most recent sampling data in fractional years to rescale time [default=2010]"), new Arguments.StringOption(SLICES, "time", "specifies a slice time-list [default=none]"), new Arguments.StringOption(SLICEMIDPOINT, falseTrue, false, "shows complete branch for sliced tree if time is more recent than the branch's midpoint [default=false"), new Arguments.Option(HELP, "option to print this message") });
    try {
        arguments.parseArguments(args);
    } catch (Arguments.ArgumentException ae) {
        progressStream.println(ae);
        printUsage(arguments);
        System.exit(1);
    }
    if (args.length == 0 || arguments.hasOption(HELP)) {
        printUsage(arguments);
        System.exit(0);
    }
    if (arguments.hasOption(MRSD)) {
        mostRecentDate = arguments.getRealOption(MRSD);
    }
    if (arguments.hasOption(ALTITUDE)) {
        altitude = arguments.getRealOption(ALTITUDE);
    }
    String annotationLabel = arguments.getStringOption(ANNOTATION);
    if (annotationLabel != null) {
        coordinateLabel = annotationLabel;
    }
    String sliceString = arguments.getStringOption(SLICES);
    if (sliceString != null) {
        makeTreeSlices = true;
        try {
            sliceTimes = DiscreteTreeToKML.parseVariableLengthDoubleArray(sliceString);
        } catch (Arguments.ArgumentException ae) {
            System.err.println("error reading slice heights");
            ae.printStackTrace();
            return;
        }
        makeTreeSlices = true;
    }
    if (arguments.hasOption(SLICEBW)) {
        treeSliceBranchWidth = arguments.getRealOption(SLICEBW);
    }
    String midpointString = arguments.getStringOption(SLICEMIDPOINT);
    if (midpointString != null && midpointString.compareToIgnoreCase("true") == 0) {
        showBranchAtMidPoint = true;
    }
    final String[] args2 = arguments.getLeftoverArguments();
    String inputFileName = null;
    String outputFileName = null;
    switch(args2.length) {
        case 0:
            printUsage(arguments);
            System.exit(1);
        case 1:
            inputFileName = args2[0];
            outputFileName = inputFileName + ".kml";
            break;
        case 2:
            inputFileName = args2[0];
            outputFileName = args2[1];
            break;
        default:
            {
                System.err.println("Unknown option: " + args2[2]);
                System.err.println();
                printUsage(arguments);
                System.exit(1);
            }
    }
    RootedTree tree = null;
    try {
        TreeImporter importer = new NexusImporter(new FileReader(inputFileName));
        tree = (RootedTree) importer.importNextTree();
    } catch (ImportException e) {
        e.printStackTrace();
        return;
    } catch (IOException e) {
        e.printStackTrace();
        return;
    }
    ContinuousKML exporter = new ContinuousKML(tree, inputFileName, altitude, mostRecentDate, coordinateLabel);
    try {
        BufferedWriter out1 = new BufferedWriter(new FileWriter(outputFileName));
        StringBuffer buffer = new StringBuffer();
        //we write the general tree stuff, but when making slices we do not include everything in the buffer compilation
        exporter.writeTreeToKML();
        if (makeTreeSlices) {
            for (int i = 0; i < sliceTimes.length; i++) {
                //                    System.out.println(sliceTimes[i]);
                exporter.writeTreeToKML(sliceTimes[i], treeSliceBranchWidth, showBranchAtMidPoint);
            }
        }
        exporter.compileBuffer(buffer, makeTreeSlices);
        out1.write(buffer.toString());
        out1.close();
    } catch (IOException e) {
        e.printStackTrace();
        return;
    }
}
Also used : NexusImporter(jebl.evolution.io.NexusImporter) Arguments(dr.app.util.Arguments) ImportException(jebl.evolution.io.ImportException) RootedTree(jebl.evolution.trees.RootedTree) TreeImporter(jebl.evolution.io.TreeImporter)

Example 2 with RootedTree

use of jebl.evolution.trees.RootedTree in project beast-mcmc by beast-dev.

the class DiscreteTreeToKML method readTree.

private static RootedTree readTree(String inString) throws Arguments.ArgumentException {
    RootedTree tree;
    try {
        TreeImporter importer = new NexusImporter(new FileReader(inString));
        tree = (RootedTree) importer.importNextTree();
    } catch (ImportException e) {
        e.printStackTrace();
        return null;
    } catch (IOException e) {
        e.printStackTrace();
        return null;
    }
    return tree;
}
Also used : ImportException(jebl.evolution.io.ImportException) NexusImporter(jebl.evolution.io.NexusImporter) RootedTree(jebl.evolution.trees.RootedTree) TreeImporter(jebl.evolution.io.TreeImporter) FileReader(java.io.FileReader) IOException(java.io.IOException)

Example 3 with RootedTree

use of jebl.evolution.trees.RootedTree in project beast-mcmc by beast-dev.

the class TempestPanel method setupPanel.

public void setupPanel() {
    StringBuilder sb = new StringBuilder();
    NumberFormatter nf = new NumberFormatter(6);
    if (tree != null) {
        temporalRooting = new TemporalRooting(tree);
        currentTree = this.tree;
        if (bestFittingRoot && bestFittingRootTree != null) {
            currentTree = bestFittingRootTree;
            sb.append("Best-fitting root");
        } else {
            sb.append("User root");
        }
        if (temporalRooting.isContemporaneous()) {
            if (tabbedPane.getSelectedIndex() == 2) {
                tabbedPane.setSelectedIndex(1);
            }
            tabbedPane.setEnabledAt(2, false);
        } else {
            tabbedPane.setEnabledAt(2, true);
        }
        RootedTree jtree = dr.evolution.tree.TreeUtils.asJeblTree(currentTree);
        List<Color> colours = new ArrayList<Color>();
        for (Node tip : jtree.getExternalNodes()) {
            Taxon taxon = jtree.getTaxon(tip);
            colours.add((Color) taxon.getAttribute("!color"));
        }
        if (temporalRooting.isContemporaneous()) {
            double[] dv = temporalRooting.getRootToTipDistances(currentTree);
            List<Double> values = new ArrayList<Double>();
            for (double d : dv) {
                values.add(d);
            }
            rootToTipChart.removeAllPlots();
            NumericalDensityPlot dp = new NumericalDensityPlot(values, 20, null);
            dp.setLineColor(new Color(9, 70, 15));
            double yOffset = (Double) dp.getYData().getMax() / 2;
            List<Double> dummyValues = new ArrayList<Double>();
            for (int i = 0; i < values.size(); i++) {
                // add a random y offset to give some visual spread
                double y = MathUtils.nextGaussian() * ((Double) dp.getYData().getMax() * 0.05);
                dummyValues.add(yOffset + y);
            }
            rootToTipPlot = new ScatterPlot(values, dummyValues);
            rootToTipPlot.setColours(colours);
            rootToTipPlot.setMarkStyle(Plot.CIRCLE_MARK, 8, new BasicStroke(0.0F), new Color(44, 44, 44), new Color(129, 149, 149));
            rootToTipPlot.setHilightedMarkStyle(new BasicStroke(0.5F), new Color(44, 44, 44), UIManager.getColor("List.selectionBackground"));
            rootToTipPlot.addListener(new Plot.Adaptor() {

                @Override
                public void markClicked(int index, double x, double y, boolean isShiftDown) {
                    rootToTipPlot.selectPoint(index, isShiftDown);
                }

                public void selectionChanged(final Set<Integer> selectedPoints) {
                    plotSelectionChanged(selectedPoints);
                }
            });
            rootToTipChart.addPlot(rootToTipPlot);
            rootToTipChart.addPlot(dp);
            rootToTipPanel.setXAxisTitle("root-to-tip divergence");
            rootToTipPanel.setYAxisTitle("proportion");
            residualChart.removeAllPlots();
            sb.append(", contemporaneous tips");
            sb.append(", mean root-tip distance: " + nf.format(DiscreteStatistics.mean(dv)));
            sb.append(", coefficient of variation: " + nf.format(DiscreteStatistics.stdev(dv) / DiscreteStatistics.mean(dv)));
            sb.append(", stdev: " + nf.format(DiscreteStatistics.stdev(dv)));
            sb.append(", variance: " + nf.format(DiscreteStatistics.variance(dv)));
            showMRCACheck.setVisible(false);
        } else {
            Regression r = temporalRooting.getRootToTipRegression(currentTree);
            double[] residuals = temporalRooting.getRootToTipResiduals(currentTree, r);
            pointMap.clear();
            for (int i = 0; i < currentTree.getExternalNodeCount(); i++) {
                NodeRef tip = currentTree.getExternalNode(i);
                Node node = jtree.getNode(Taxon.getTaxon(currentTree.getNodeTaxon(tip).getId()));
                node.setAttribute("residual", residuals[i]);
                pointMap.put(node, i);
            }
            rootToTipChart.removeAllPlots();
            if (showMRCACheck.isSelected()) {
                double[] dv = temporalRooting.getParentRootToTipDistances(currentTree);
                List<Double> parentDistances = new ArrayList<Double>();
                for (int i = 0; i < dv.length; i++) {
                    parentDistances.add(i, dv[i]);
                }
                List<Double> parentTimes = new ArrayList<Double>();
                for (int i = 0; i < parentDistances.size(); i++) {
                    parentTimes.add(i, r.getX(parentDistances.get(i)));
                }
                mrcaPlot = new ParentPlot(r.getXData(), r.getYData(), parentTimes, parentDistances);
                mrcaPlot.setLineColor(new Color(105, 202, 105));
                mrcaPlot.setLineStroke(new BasicStroke(0.5F));
                rootToTipChart.addPlot(mrcaPlot);
            }
            if (true) {
                double[] datePrecisions = temporalRooting.getTipDatePrecisions(currentTree);
                Variate.D ed = new Variate.D();
                for (int i = 0; i < datePrecisions.length; i++) {
                    ed.add(datePrecisions[i]);
                }
                errorBarPlot = new ErrorBarPlot(ErrorBarPlot.Orientation.HORIZONTAL, r.getXData(), r.getYData(), ed);
                errorBarPlot.setLineColor(new Color(44, 44, 44));
                errorBarPlot.setLineStroke(new BasicStroke(1.0F));
                rootToTipChart.addPlot(errorBarPlot);
            }
            rootToTipPlot = new ScatterPlot(r.getXData(), r.getYData());
            rootToTipPlot.addListener(new Plot.Adaptor() {

                public void selectionChanged(final Set<Integer> selectedPoints) {
                    plotSelectionChanged(selectedPoints);
                }
            });
            rootToTipPlot.setColours(colours);
            rootToTipPlot.setMarkStyle(Plot.CIRCLE_MARK, 8, new BasicStroke(0.0F), new Color(44, 44, 44), new Color(129, 149, 149));
            rootToTipPlot.setHilightedMarkStyle(new BasicStroke(0.5F), new Color(44, 44, 44), UIManager.getColor("List.selectionBackground"));
            rootToTipChart.addPlot(rootToTipPlot);
            rootToTipChart.addPlot(new RegressionPlot(r));
            rootToTipChart.getXAxis().addRange(r.getXIntercept(), (Double) r.getXData().getMax());
            rootToTipPanel.setXAxisTitle("time");
            rootToTipPanel.setYAxisTitle("root-to-tip divergence");
            residualChart.removeAllPlots();
            Variate.D values = (Variate.D) r.getYResidualData();
            NumericalDensityPlot dp = new NumericalDensityPlot(values, 20);
            dp.setLineColor(new Color(103, 128, 144));
            double yOffset = (Double) dp.getYData().getMax() / 2;
            Double[] dummyValues = new Double[values.getCount()];
            for (int i = 0; i < dummyValues.length; i++) {
                // add a random y offset to give some visual spread
                double y = MathUtils.nextGaussian() * ((Double) dp.getYData().getMax() * 0.05);
                dummyValues[i] = yOffset + y;
            }
            Variate.D yOffsetValues = new Variate.D(dummyValues);
            residualPlot = new ScatterPlot(values, yOffsetValues);
            residualPlot.addListener(new Plot.Adaptor() {

                @Override
                public void markClicked(int index, double x, double y, boolean isShiftDown) {
                    rootToTipPlot.selectPoint(index, isShiftDown);
                }

                @Override
                public void selectionChanged(final Set<Integer> selectedPoints) {
                    plotSelectionChanged(selectedPoints);
                }
            });
            residualPlot.setColours(colours);
            residualPlot.setMarkStyle(Plot.CIRCLE_MARK, 8, new BasicStroke(0.0F), new Color(44, 44, 44), new Color(129, 149, 149));
            residualPlot.setHilightedMarkStyle(new BasicStroke(0.5F), new Color(44, 44, 44), UIManager.getColor("List.selectionBackground"));
            residualChart.addPlot(residualPlot);
            residualChart.addPlot(dp);
            residualPanel.setXAxisTitle("residual");
            residualPanel.setYAxisTitle("proportion");
            if (SHOW_NODE_DENSITY) {
                Regression r2 = temporalRooting.getNodeDensityRegression(currentTree);
                nodeDensityChart.removeAllPlots();
                nodeDensityPlot = new ScatterPlot(r2.getXData(), r2.getYData());
                nodeDensityPlot.addListener(new Plot.Adaptor() {

                    public void selectionChanged(final Set<Integer> selectedPoints) {
                        plotSelectionChanged(selectedPoints);
                    }
                });
                nodeDensityPlot.setColours(colours);
                nodeDensityPlot.setMarkStyle(Plot.CIRCLE_MARK, 8, new BasicStroke(0.0F), new Color(44, 44, 44), new Color(129, 149, 149));
                nodeDensityPlot.setHilightedMarkStyle(new BasicStroke(0.5F), new Color(44, 44, 44), UIManager.getColor("List.selectionBackground"));
                nodeDensityChart.addPlot(nodeDensityPlot);
                nodeDensityChart.addPlot(new RegressionPlot(r2));
                nodeDensityChart.getXAxis().addRange(r2.getXIntercept(), (Double) r2.getXData().getMax());
                nodeDensityPanel.setXAxisTitle("time");
                nodeDensityPanel.setYAxisTitle("node density");
            }
            sb.append(", dated tips");
            sb.append(", date range: " + nf.format(temporalRooting.getDateRange()));
            sb.append(", slope (rate): " + nf.format(r.getGradient()));
            sb.append(", x-intercept (TMRCA): " + nf.format(r.getXIntercept()));
            sb.append(", corr. coeff: " + nf.format(r.getCorrelationCoefficient()));
            sb.append(", R^2: " + nf.format(r.getRSquared()));
            showMRCACheck.setVisible(true);
        }
        treePanel.setTree(jtree);
        treePanel.setColourBy("residual");
    } else {
        treePanel.setTree(null);
        rootToTipChart.removeAllPlots();
        sb.append("No trees loaded");
    }
    textArea.setText(sb.toString());
    statisticsModel.fireTableStructureChanged();
    repaint();
}
Also used : Variate(dr.stats.Variate) Node(jebl.evolution.graphs.Node) Taxon(jebl.evolution.taxa.Taxon) Regression(dr.stats.Regression) RootedTree(jebl.evolution.trees.RootedTree) NumberFormatter(dr.util.NumberFormatter)

Example 4 with RootedTree

use of jebl.evolution.trees.RootedTree in project beast-mcmc by beast-dev.

the class TreeSpaceFrame method loadTrees.

private TreeLineages loadTrees(InputFile inputFile) throws IOException {
    PrintStream progressStream = System.out;
    int totalTrees = 10000;
    int totalTreesUsed = 0;
    progressStream.println("Reading trees (bar assumes 10,000 trees)...");
    progressStream.println("0              25             50             75            100");
    progressStream.println("|--------------|--------------|--------------|--------------|");
    int stepSize = totalTrees / 60;
    if (stepSize < 1)
        stepSize = 1;
    TreeLineages treeLineages = new TreeLineages();
    FileReader fileReader = new FileReader(inputFile.getFile());
    jebl.evolution.io.NexusImporter importer = new NexusImporter(fileReader);
    try {
        totalTrees = 0;
        while (importer.hasTree()) {
            RootedTree tree = (RootedTree) importer.importNextTree();
            if (totalTrees >= inputFile.getBurnin()) {
                treeLineages.addTree(tree);
                totalTreesUsed += 1;
            }
            if (totalTrees > 0 && totalTrees % stepSize == 0) {
                progressStream.print("*");
                progressStream.flush();
            }
            totalTrees++;
        }
    } catch (ImportException e) {
        System.err.println("Error Parsing Input Tree: " + e.getMessage());
        return null;
    }
    fileReader.close();
    progressStream.println();
    progressStream.println();
    if (totalTrees < 1) {
        System.err.println("No trees");
        return null;
    }
    if (totalTreesUsed <= 1) {
        if (inputFile.getBurnin() > 0) {
            System.err.println("No trees to use: burnin too high");
            return null;
        }
    }
    progressStream.println("Total trees read: " + totalTrees);
    if (inputFile.getBurnin() > 0) {
        progressStream.println("Ignoring first " + inputFile.getBurnin() + " trees.");
    }
    treeLineages.setupTrees();
    return treeLineages;
}
Also used : ImportException(jebl.evolution.io.ImportException) NexusImporter(jebl.evolution.io.NexusImporter) RootedTree(jebl.evolution.trees.RootedTree) java.io(java.io) NexusImporter(jebl.evolution.io.NexusImporter)

Example 5 with RootedTree

use of jebl.evolution.trees.RootedTree in project beast-mcmc by beast-dev.

the class PathogenPanel method setupPanel.

public void setupPanel() {
    StringBuilder sb = new StringBuilder();
    NumberFormatter nf = new NumberFormatter(6);
    if (tree != null) {
        temporalRooting = new TemporalRooting(tree);
        currentTree = this.tree;
        if (bestFittingRoot && bestFittingRootTree != null) {
            currentTree = bestFittingRootTree;
            sb.append("Best-fitting root");
        } else {
            sb.append("User root");
        }
        if (temporalRooting.isContemporaneous()) {
            if (tabbedPane.getSelectedIndex() == 2) {
                tabbedPane.setSelectedIndex(1);
            }
            tabbedPane.setEnabledAt(2, false);
        } else {
            tabbedPane.setEnabledAt(2, true);
        }
        RootedTree jtree = dr.evolution.tree.TreeUtils.asJeblTree(currentTree);
        List<Color> colours = new ArrayList<Color>();
        for (Node tip : jtree.getExternalNodes()) {
            Taxon taxon = jtree.getTaxon(tip);
            colours.add((Color) taxon.getAttribute("!color"));
        }
        if (temporalRooting.isContemporaneous()) {
            double[] dv = temporalRooting.getRootToTipDistances(currentTree);
            List<Double> values = new ArrayList<Double>();
            for (double d : dv) {
                values.add(d);
            }
            rootToTipChart.removeAllPlots();
            NumericalDensityPlot dp = new NumericalDensityPlot(values, 20, null);
            dp.setLineColor(new Color(9, 70, 15));
            double yOffset = (Double) dp.getYData().getMax() / 2;
            List<Double> dummyValues = new ArrayList<Double>();
            for (int i = 0; i < values.size(); i++) {
                // add a random y offset to give some visual spread
                double y = MathUtils.nextGaussian() * ((Double) dp.getYData().getMax() * 0.05);
                dummyValues.add(yOffset + y);
            }
            rootToTipPlot = new ScatterPlot(values, dummyValues);
            rootToTipPlot.setColours(colours);
            rootToTipPlot.setMarkStyle(Plot.CIRCLE_MARK, 8, new BasicStroke(0.0F), new Color(44, 44, 44), new Color(129, 149, 149));
            rootToTipPlot.setHilightedMarkStyle(new BasicStroke(0.5F), new Color(44, 44, 44), UIManager.getColor("List.selectionBackground"));
            rootToTipPlot.addListener(new Plot.Adaptor() {

                @Override
                public void markClicked(int index, double x, double y, boolean isShiftDown) {
                    rootToTipPlot.selectPoint(index, isShiftDown);
                }

                public void selectionChanged(final Set<Integer> selectedPoints) {
                    plotSelectionChanged(selectedPoints);
                }
            });
            rootToTipChart.addPlot(rootToTipPlot);
            rootToTipChart.addPlot(dp);
            rootToTipPanel.setXAxisTitle("root-to-tip divergence");
            rootToTipPanel.setYAxisTitle("proportion");
            residualChart.removeAllPlots();
            sb.append(", contemporaneous tips");
            sb.append(", mean root-tip distance: " + nf.format(DiscreteStatistics.mean(dv)));
            sb.append(", coefficient of variation: " + nf.format(DiscreteStatistics.stdev(dv) / DiscreteStatistics.mean(dv)));
            sb.append(", stdev: " + nf.format(DiscreteStatistics.stdev(dv)));
            sb.append(", variance: " + nf.format(DiscreteStatistics.variance(dv)));
            showMRCACheck.setVisible(false);
        } else {
            Regression r = temporalRooting.getRootToTipRegression(currentTree);
            double[] residuals = temporalRooting.getRootToTipResiduals(currentTree, r);
            pointMap.clear();
            for (int i = 0; i < currentTree.getExternalNodeCount(); i++) {
                NodeRef tip = currentTree.getExternalNode(i);
                Node node = jtree.getNode(Taxon.getTaxon(currentTree.getNodeTaxon(tip).getId()));
                node.setAttribute("residual", residuals[i]);
                pointMap.put(node, i);
            }
            rootToTipChart.removeAllPlots();
            if (showMRCACheck.isSelected()) {
                double[] dv = temporalRooting.getParentRootToTipDistances(currentTree);
                List<Double> parentDistances = new ArrayList<Double>();
                for (int i = 0; i < dv.length; i++) {
                    parentDistances.add(i, dv[i]);
                }
                List<Double> parentTimes = new ArrayList<Double>();
                for (int i = 0; i < parentDistances.size(); i++) {
                    parentTimes.add(i, r.getX(parentDistances.get(i)));
                }
                mrcaPlot = new ParentPlot(r.getXData(), r.getYData(), parentTimes, parentDistances);
                mrcaPlot.setLineColor(new Color(105, 202, 105));
                mrcaPlot.setLineStroke(new BasicStroke(0.5F));
                rootToTipChart.addPlot(mrcaPlot);
            }
            if (true) {
                double[] datePrecisions = temporalRooting.getTipDatePrecisions(currentTree);
                Variate.D ed = new Variate.D();
                for (int i = 0; i < datePrecisions.length; i++) {
                    ed.add(datePrecisions[i]);
                }
                errorBarPlot = new ErrorBarPlot(ErrorBarPlot.Orientation.HORIZONTAL, r.getXData(), r.getYData(), ed);
                errorBarPlot.setLineColor(new Color(44, 44, 44));
                errorBarPlot.setLineStroke(new BasicStroke(1.0F));
                rootToTipChart.addPlot(errorBarPlot);
            }
            rootToTipPlot = new ScatterPlot(r.getXData(), r.getYData());
            rootToTipPlot.addListener(new Plot.Adaptor() {

                public void selectionChanged(final Set<Integer> selectedPoints) {
                    plotSelectionChanged(selectedPoints);
                }
            });
            rootToTipPlot.setColours(colours);
            rootToTipPlot.setMarkStyle(Plot.CIRCLE_MARK, 8, new BasicStroke(0.0F), new Color(44, 44, 44), new Color(129, 149, 149));
            rootToTipPlot.setHilightedMarkStyle(new BasicStroke(0.5F), new Color(44, 44, 44), UIManager.getColor("List.selectionBackground"));
            rootToTipChart.addPlot(rootToTipPlot);
            rootToTipChart.addPlot(new RegressionPlot(r));
            rootToTipChart.getXAxis().addRange(r.getXIntercept(), (Double) r.getXData().getMax());
            rootToTipPanel.setXAxisTitle("time");
            rootToTipPanel.setYAxisTitle("root-to-tip divergence");
            residualChart.removeAllPlots();
            Variate.D values = (Variate.D) r.getYResidualData();
            NumericalDensityPlot dp = new NumericalDensityPlot(values, 20);
            dp.setLineColor(new Color(103, 128, 144));
            double yOffset = (Double) dp.getYData().getMax() / 2;
            Double[] dummyValues = new Double[values.getCount()];
            for (int i = 0; i < dummyValues.length; i++) {
                // add a random y offset to give some visual spread
                double y = MathUtils.nextGaussian() * ((Double) dp.getYData().getMax() * 0.05);
                dummyValues[i] = yOffset + y;
            }
            Variate.D yOffsetValues = new Variate.D(dummyValues);
            residualPlot = new ScatterPlot(values, yOffsetValues);
            residualPlot.addListener(new Plot.Adaptor() {

                @Override
                public void markClicked(int index, double x, double y, boolean isShiftDown) {
                    rootToTipPlot.selectPoint(index, isShiftDown);
                }

                @Override
                public void selectionChanged(final Set<Integer> selectedPoints) {
                    plotSelectionChanged(selectedPoints);
                }
            });
            residualPlot.setColours(colours);
            residualPlot.setMarkStyle(Plot.CIRCLE_MARK, 8, new BasicStroke(0.0F), new Color(44, 44, 44), new Color(129, 149, 149));
            residualPlot.setHilightedMarkStyle(new BasicStroke(0.5F), new Color(44, 44, 44), UIManager.getColor("List.selectionBackground"));
            residualChart.addPlot(residualPlot);
            residualChart.addPlot(dp);
            residualPanel.setXAxisTitle("residual");
            residualPanel.setYAxisTitle("proportion");
            if (SHOW_NODE_DENSITY) {
                Regression r2 = temporalRooting.getNodeDensityRegression(currentTree);
                nodeDensityChart.removeAllPlots();
                nodeDensityPlot = new ScatterPlot(r2.getXData(), r2.getYData());
                nodeDensityPlot.addListener(new Plot.Adaptor() {

                    public void selectionChanged(final Set<Integer> selectedPoints) {
                        plotSelectionChanged(selectedPoints);
                    }
                });
                nodeDensityPlot.setColours(colours);
                nodeDensityPlot.setMarkStyle(Plot.CIRCLE_MARK, 8, new BasicStroke(0.0F), new Color(44, 44, 44), new Color(129, 149, 149));
                nodeDensityPlot.setHilightedMarkStyle(new BasicStroke(0.5F), new Color(44, 44, 44), UIManager.getColor("List.selectionBackground"));
                nodeDensityChart.addPlot(nodeDensityPlot);
                nodeDensityChart.addPlot(new RegressionPlot(r2));
                nodeDensityChart.getXAxis().addRange(r2.getXIntercept(), (Double) r2.getXData().getMax());
                nodeDensityPanel.setXAxisTitle("time");
                nodeDensityPanel.setYAxisTitle("node density");
            }
            sb.append(", dated tips");
            sb.append(", date range: " + nf.format(temporalRooting.getDateRange()));
            sb.append(", slope (rate): " + nf.format(r.getGradient()));
            sb.append(", x-intercept (TMRCA): " + nf.format(r.getXIntercept()));
            sb.append(", corr. coeff: " + nf.format(r.getCorrelationCoefficient()));
            sb.append(", R^2: " + nf.format(r.getRSquared()));
            showMRCACheck.setVisible(true);
        }
        treePanel.setTree(jtree);
        treePanel.setColourBy("residual");
    } else {
        treePanel.setTree(null);
        rootToTipChart.removeAllPlots();
        sb.append("No trees loaded");
    }
    textArea.setText(sb.toString());
    statisticsModel.fireTableStructureChanged();
    repaint();
}
Also used : Variate(dr.stats.Variate) Node(jebl.evolution.graphs.Node) Taxon(jebl.evolution.taxa.Taxon) Regression(dr.stats.Regression) RootedTree(jebl.evolution.trees.RootedTree) NumberFormatter(dr.util.NumberFormatter)

Aggregations

RootedTree (jebl.evolution.trees.RootedTree)12 NexusImporter (jebl.evolution.io.NexusImporter)8 ImportException (jebl.evolution.io.ImportException)6 TreeImporter (jebl.evolution.io.TreeImporter)6 Variate (dr.stats.Variate)3 FileReader (java.io.FileReader)3 IOException (java.io.IOException)3 Node (jebl.evolution.graphs.Node)3 Arguments (dr.app.util.Arguments)2 Regression (dr.stats.Regression)2 NumberFormatter (dr.util.NumberFormatter)2 BufferedWriter (java.io.BufferedWriter)2 FileWriter (java.io.FileWriter)2 Taxon (jebl.evolution.taxa.Taxon)2 LogFileTraces (dr.inference.trace.LogFileTraces)1 java.io (java.io)1 BufferedReader (java.io.BufferedReader)1 ArrayList (java.util.ArrayList)1 EmpiricalDemographicFunction (jebl.evolution.coalescent.EmpiricalDemographicFunction)1 NewickExporter (jebl.evolution.io.NewickExporter)1