Search in sources :

Example 21 with XMLOutputter

use of org.jdom.output.XMLOutputter in project intellij-plugins by JetBrains.

the class BaseExtension method getContent.

protected static String getContent(XmlPullParser parser, String tagName) {
    StringBuffer sb = new StringBuffer();
    try {
        int event = parser.getEventType();
        // get the content
        XMLOutputter xmlOutputter = new XMLOutputter();
        while (true) {
            switch(event) {
                case XmlPullParser.TEXT:
                    sb.append(xmlOutputter.escapeElementEntities(parser.getText()));
                    break;
                case XmlPullParser.START_TAG:
                    sb.append('<' + parser.getName());
                    int attributeCount = parser.getAttributeCount();
                    for (int i = 0; i < attributeCount; i++) {
                        String attributeValue = xmlOutputter.escapeAttributeEntities(parser.getAttributeValue(i));
                        sb.append(' ').append(parser.getAttributeName(i)).append('=').append('"').append(attributeValue).append('"');
                    }
                    sb.append(" xmlns=\"").append(parser.getNamespace()).append('"');
                    sb.append('>');
                    break;
                case XmlPullParser.END_TAG:
                    sb.append("</" + parser.getName() + '>');
                    break;
                default:
            }
            if (event == parser.END_TAG && tagName.equals(parser.getName()))
                break;
            event = parser.next();
        }
    } catch (XmlPullParserException e) {
        e.printStackTrace(System.err);
    } catch (IOException e) {
        e.printStackTrace(System.err);
    }
    return sb.toString();
}
Also used : XMLOutputter(org.jdom.output.XMLOutputter) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) IOException(java.io.IOException)

Example 22 with XMLOutputter

use of org.jdom.output.XMLOutputter in project beast-mcmc by beast-dev.

the class RateIndicatorBF method outputKML.

public void outputKML(String KMLoutputFile, String lowerLinkColor, String upperLinkColor, double branchWidthConstant, double branchWidthMultiplier, double altitudeFactor) {
    double divider = 100;
    PrintStream resultsStream = System.out;
    if (KMLoutputFile != null) {
        try {
            resultsStream = new PrintStream(new File(KMLoutputFile));
        } catch (IOException e) {
            System.err.println("Error opening file: " + KMLoutputFile);
            System.exit(-1);
        }
    }
    Element rootElement = new Element("kml");
    Element documentElement = new Element("Document");
    Element folderElement = new Element("Folder");
    Element documentNameElement = new Element("name");
    documentNameElement.addContent(KMLoutputFile);
    documentElement.addContent(documentNameElement);
    List<Element> schema = new ArrayList<Element>();
    Element locationSchema = new Element("Schema");
    locationSchema.setAttribute("id", "Locations_Schema");
    locationSchema.addContent(new Element("SimpleField").setAttribute("name", "Name").setAttribute("type", "string"));
    locationSchema.addContent(new Element("SimpleField").setAttribute("name", "In").setAttribute("type", "number"));
    locationSchema.addContent(new Element("SimpleField").setAttribute("name", "Out").setAttribute("type", "number"));
    locationSchema.addContent(new Element("SimpleField").setAttribute("name", "Total").setAttribute("type", "number"));
    Element ratesSchema = new Element("Schema");
    ratesSchema.setAttribute("id", "Rates_Schema");
    ratesSchema.addContent(new Element("SimpleField").setAttribute("name", "Name").setAttribute("type", "string"));
    ratesSchema.addContent(new Element("SimpleField").setAttribute("name", "BF").setAttribute("type", "double"));
    ratesSchema.addContent(new Element("SimpleField").setAttribute("name", "Indicator").setAttribute("type", "double"));
    if (calculateRates) {
        ratesSchema.addContent(new Element("SimpleField").setAttribute("name", "meanRate").setAttribute("type", "double"));
    }
    schema.add(ratesSchema);
    documentElement.addContent(schema);
    Element folderNameElement = new Element("name");
    String cutoffString;
    if (bayesFactor) {
        cutoffString = "bayes factor";
    } else {
        cutoffString = "indicator";
    }
    folderNameElement.addContent("discrete rates with " + cutoffString + " larger than " + cutoff);
    folderElement.addContent(folderNameElement);
    double[] minMax = new double[2];
    if (supportedRateIndicators.length > 0) {
        minMax[0] = supportedRateIndicators[supportedRateIndicators.length - 1];
        minMax[1] = supportedRateIndicators[0];
    } else {
        minMax[0] = minMax[1] = 0;
        System.err.println("No rate indicators above the specified cut-off!");
    }
    for (int p = 0; p < supportedRateIndicators.length; p++) {
        if (calculateRates) {
            addRateWithData(supportedRateIndicators[p], supportedBFs[p], supportedActualRates[p], supportedLocations[p][0], supportedLocations[p][1], supportedLongitudes[p][0], supportedLatitudes[p][0], supportedLongitudes[p][1], supportedLatitudes[p][1], p + 1, folderElement);
        } else {
            addRateWithData(supportedRateIndicators[p], supportedBFs[p], supportedLocations[p][0], supportedLocations[p][1], supportedLongitudes[p][0], supportedLatitudes[p][0], supportedLongitudes[p][1], supportedLatitudes[p][1], p + 1, folderElement);
        }
    }
    //add locations
    Element folder2Element = new Element("Folder");
    Element folderName2Element = new Element("name");
    folderName2Element.addContent("Locations");
    folder2Element.addContent(folderName2Element);
    addLocations(folder2Element);
    documentElement.addContent(folder2Element);
    documentElement.addContent(folderElement);
    rootElement.addContent(documentElement);
    XMLOutputter xmlOutputter = new XMLOutputter(Format.getPrettyFormat().setTextMode(Format.TextMode.PRESERVE));
    try {
        xmlOutputter.output(rootElement, resultsStream);
    } catch (IOException e) {
        System.err.println("IO Exception encountered: " + e.getMessage());
        System.exit(-1);
    }
}
Also used : XMLOutputter(org.jdom.output.XMLOutputter) Element(org.jdom.Element) ArrayList(java.util.ArrayList)

Example 23 with XMLOutputter

use of org.jdom.output.XMLOutputter in project beast-mcmc by beast-dev.

the class DiscreteRatePriorGenerator method outputArray.

private void outputArray(double[] array, OutputFormat outputFormat, Model model, int predictor, boolean nonreversible) {
    StringBuilder sb1 = new StringBuilder();
    StringBuilder sb2 = new StringBuilder();
    String sep;
    if (outputFormat == OutputFormat.TAB) {
        sep = "\t";
    } else {
        sep = " ";
    }
    //       }
    for (double anArray : array) {
        sb1.append(anArray + sep);
        sb2.append(1 + sep);
    }
    if (outputFormat == OutputFormat.XML) {
        if (model == model.GLM) {
            Element parameter = new Element("parameter");
            parameter.setAttribute("id", "predictor" + predictor);
            if (nonreversible) {
                parameter.setAttribute("value", (sb1.toString() + sb1.toString()));
            } else {
                parameter.setAttribute("value", sb1.toString());
            }
            XMLOutputter xmlOutputter = new XMLOutputter(Format.getPrettyFormat().setTextMode(Format.TextMode.PRESERVE));
            try {
                xmlOutputter.output(parameter, resultsStream);
            } catch (IOException e) {
                System.err.println("IO Exception encountered: " + e.getMessage());
                System.exit(-1);
            }
            resultsStream.print("\r");
        } else if (model == model.PRIOR) {
            Element priorElement = new Element("multivariateGammaPrior");
            Element data = new Element("data");
            Element parameter1 = new Element("parameter");
            parameter1.setAttribute("idref", "rates");
            data.addContent(parameter1);
            Element meanParameter = new Element("meanParameter");
            Element parameter2 = new Element("parameter");
            if (nonreversible) {
                parameter2.setAttribute("value", (sb1.toString() + sb1.toString()));
            } else {
                parameter2.setAttribute("value", sb1.toString());
            }
            meanParameter.addContent(parameter2);
            Element coefficientOfVariation = new Element("coefficientOfVariation");
            Element parameter3 = new Element("parameter");
            if (nonreversible) {
                parameter3.setAttribute("value", sb2.toString() + sb2.toString());
            } else {
                parameter3.setAttribute("value", sb2.toString());
            }
            coefficientOfVariation.addContent(parameter3);
            priorElement.addContent(data);
            priorElement.addContent(meanParameter);
            priorElement.addContent(coefficientOfVariation);
            XMLOutputter xmlOutputter = new XMLOutputter(Format.getPrettyFormat().setTextMode(Format.TextMode.PRESERVE));
            try {
                xmlOutputter.output(priorElement, resultsStream);
            } catch (IOException e) {
                System.err.println("IO Exception encountered: " + e.getMessage());
                System.exit(-1);
            }
            resultsStream.print("\r");
        } else if (model == model.JUMP) {
            Element parameter = new Element("parameter");
            parameter.setAttribute("id", "jump" + predictor);
            parameter.setAttribute("value", sb1.toString());
            XMLOutputter xmlOutputter = new XMLOutputter(Format.getPrettyFormat().setTextMode(Format.TextMode.PRESERVE));
            try {
                xmlOutputter.output(parameter, resultsStream);
            } catch (IOException e) {
                System.err.println("IO Exception encountered: " + e.getMessage());
                System.exit(-1);
            }
            resultsStream.print("\r");
        }
    } else {
        if (nonreversible) {
            resultsStream.print(sb1.toString() + sb1.toString() + "\r");
        } else {
            resultsStream.print(sb1 + "\r");
        }
    }
}
Also used : XMLOutputter(org.jdom.output.XMLOutputter) Element(org.jdom.Element)

Example 24 with XMLOutputter

use of org.jdom.output.XMLOutputter in project beast-mcmc by beast-dev.

the class TimeSlicer method output.

public void output(String outFileName, boolean summaryOnly, final boolean summarizeRoot, final boolean summarizeTips, boolean contours, boolean points, OutputFormat outputFormat, double[] hpdValues, String sdrFile, String snrFile) {
    resultsStream = System.out;
    if (outFileName != null) {
        try {
            resultsStream = new PrintStream(new File(outFileName));
        } catch (IOException e) {
            System.err.println("Error opening file: " + outFileName);
            System.exit(-1);
        }
    }
    if (!summaryOnly) {
        outputHeader(traits);
        if (sliceHeights == null || sliceHeights.length == 0) {
            outputSlice(0, Double.NaN);
        } else {
            for (int i = 0; i < sliceHeights.length; i++) {
                outputSlice(i, sliceHeights[i]);
            }
        }
    } else {
        if (outputFormat == OutputFormat.XML) {
            rootElement = new Element("xml");
        } else if (outputFormat == OutputFormat.KML) {
            Element hpdSchema = new Element("Schema");
            hpdSchema.setAttribute("id", "HPD_Schema");
            hpdSchema.addContent(new Element("SimpleField").setAttribute("name", "Name").setAttribute("type", "string").addContent(new Element("displayName").addContent("Name")));
            hpdSchema.addContent(new Element("SimpleField").setAttribute("name", "Description").setAttribute("type", "string").addContent(new Element("displayName").addContent("Description")));
            hpdSchema.addContent(new Element("SimpleField").setAttribute("name", "Time").setAttribute("type", "double").addContent(new Element("displayName").addContent("Time")));
            hpdSchema.addContent(new Element("SimpleField").setAttribute("name", "Height").setAttribute("type", "double").addContent(new Element("displayName").addContent("Height")));
            hpdSchema.addContent(new Element("SimpleField").setAttribute("name", "HPD").setAttribute("type", "double").addContent(new Element("displayName").addContent("HPD")));
            Element nodeSchema = new Element("Schema");
            nodeSchema.setAttribute("id", "Point_Schema");
            nodeSchema.addContent(new Element("SimpleField").setAttribute("name", "Name").setAttribute("type", "string").addContent(new Element("displayName").addContent("Name")));
            nodeSchema.addContent(new Element("SimpleField").setAttribute("name", "Description").setAttribute("type", "string").addContent(new Element("displayName").addContent("Description")));
            nodeSchema.addContent(new Element("SimpleField").setAttribute("name", "Time").setAttribute("type", "double").addContent(new Element("displayName").addContent("Time")));
            nodeSchema.addContent(new Element("SimpleField").setAttribute("name", "Height").setAttribute("type", "double").addContent(new Element("displayName").addContent("Height")));
            if (contours) {
                contourFolderElement = new Element("Folder");
                Element contourFolderNameElement = new Element("name");
                contourFolderNameElement.addContent("surface HPD regions");
                //rootElement.setAttribute("xmlns","http://earth.google.com/kml/2.2");
                contourFolderElement.addContent(contourFolderNameElement);
            }
            if (points) {
                pointsFolderElement = new Element("Folder");
                Element pointsFolderNameElement = new Element("name");
                pointsFolderNameElement.addContent("points");
                //rootElement.setAttribute("xmlns","http://earth.google.com/kml/2.2");
                pointsFolderElement.addContent(pointsFolderNameElement);
            }
            if (sliceMode == TimeSlicer.SliceMode.NODES) {
                nodeFolderElement = new Element("Folder");
                Element nodeFolderNameElement = new Element("name");
                nodeFolderNameElement.addContent("nodes");
                //rootElement.setAttribute("xmlns","http://earth.google.com/kml/2.2");
                nodeFolderElement.addContent(nodeFolderNameElement);
            }
            Element documentNameElement = new Element("name");
            String documentName = outFileName;
            if (documentName == null)
                documentName = "default";
            if (documentName.endsWith(".kml"))
                documentName = documentName.replace(".kml", "");
            documentNameElement.addContent(documentName);
            documentElement = new Element("Document");
            documentElement.addContent(documentNameElement);
            documentElement.addContent(hpdSchema);
            documentElement.addContent(nodeSchema);
            if (contourFolderElement != null) {
                documentElement.addContent(contourFolderElement);
            }
            if (pointsFolderElement != null) {
                documentElement.addContent(pointsFolderElement);
            }
            if (nodeFolderElement != null) {
                documentElement.addContent(nodeFolderElement);
            }
            rootElement = new Element("kml");
            rootElement.addContent(documentElement);
        }
        if (sliceHeights == null) {
            for (double hpdValue : hpdValues) {
                summarizeSlice(0, Double.NaN, contours, points, outputFormat, hpdValue);
            }
        } else {
            if (outputFormat == OutputFormat.TAB) {
                if (mostRecentSamplingDate > 0) {
                    tabOutput.append("trait\t" + "sliceTime\t" + "mean\t" + "stdev\t" + "HPDlow\t" + "HPDup");
                } else {
                    tabOutput.append("trait\t" + "sliceHeight\t" + "mean\t" + "stdev\t" + "HPDlow\t" + "HPDup");
                }
            }
            for (int i = 0; i < sliceHeights.length; i++) {
                for (double hpdValue : hpdValues) {
                    summarizeSlice(i, sliceHeights[i], contours, points, outputFormat, hpdValue);
                }
            }
        }
        if (summarizeRoot) {
            for (double hpdValue : hpdValues) {
                summarizeRoot(contours, points, outputFormat, hpdValue);
            }
        }
        if (summarizeTips) {
            for (double hpdValue : hpdValues) {
                summarizeTips(contours, points, outputFormat, hpdValue);
            }
        }
        if (outputFormat == OutputFormat.TAB) {
            resultsStream.println(tabOutput);
        } else {
            XMLOutputter xmlOutputter = new XMLOutputter(Format.getPrettyFormat().setTextMode(Format.TextMode.PRESERVE));
            try {
                xmlOutputter.output(rootElement, resultsStream);
            } catch (IOException e) {
                System.err.println("IO Exception encountered: " + e.getMessage());
                System.exit(-1);
            }
        }
    }
    if (sdr || snr) {
        double[][] sliceTreeWeightedAverageRates = new double[sliceTreeDistanceArrays.size()][sliceCount];
        double[][] sliceTreeDistancesToSummarize = new double[sliceTreeDistanceArrays.size()][sliceCount];
        //          can be useful for E[N]-E[S]  stuff
        double[][] sliceTreeIntervalDistances = new double[sliceTreeDistanceArrays.size()][sliceCount];
        double[][] sliceTreeMaxPathRates = new double[sliceTreeDistanceArrays.size()][sliceCount];
        double[][] sliceTreeMaxDistanceFromRootRates = new double[sliceTreeDistanceArrays.size()][sliceCount];
        double[][] sliceTreeDistances = new double[sliceCount][sliceTreeDistanceArrays.size()];
        double[][] sliceTreeTimes = new double[sliceCount][sliceTreeDistanceArrays.size()];
        //double[][] sliceTreeMaxDistances = new double[sliceCount][sliceTreeMaxDistanceArrays.size()];
        double[][] sliceTreeMaxDistancesFromRoot = new double[sliceTreeMaxDistanceFromRootArrays.size()][sliceCount];
        double[][] sliceTreeMaxPathDistances = new double[sliceTreeMaxPathDistanceArrays.size()][sliceCount];
        double[][] sliceTreeTimesFromRoot = new double[sliceCount][sliceTreeTimeFromRootArrays.size()];
        double[][] sliceTreeDiffusionCoefficients = new double[sliceTreeDiffusionCoefficientArrays.size()][sliceCount];
        double[][] sliceTreeDiffusionCoefficientVariances = new double[sliceTreeDiffusionCoefficientVarianceArrays.size()][sliceCount];
        //double[][] sliceTreeWeightedAverageDiffusionCoefficients = new double[sliceTreeDistanceArrays.size()][sliceCount];
        for (int q = 0; q < sliceTreeDistanceArrays.size(); q++) {
            double[] distanceArray = (double[]) sliceTreeDistanceArrays.get(q);
            double[] timeArray = (double[]) sliceTreeTimeArrays.get(q);
            double[] maxDistanceFromRootArray = null;
            double[] maxPathDistanceArray = null;
            double[] timeFromRootArray = null;
            double[] diffusionCoefficientArray = null;
            double[] diffusionCoefficientVarianceArray = null;
            if (sdr) {
                maxPathDistanceArray = (double[]) sliceTreeMaxPathDistanceArrays.get(q);
                maxDistanceFromRootArray = (double[]) sliceTreeMaxDistanceFromRootArrays.get(q);
                timeFromRootArray = (double[]) sliceTreeTimeFromRootArrays.get(q);
                diffusionCoefficientArray = (double[]) sliceTreeDiffusionCoefficientArrays.get(q);
                diffusionCoefficientVarianceArray = (double[]) sliceTreeDiffusionCoefficientVarianceArrays.get(q);
            }
            for (int r = 0; r < distanceArray.length; r++) {
                sliceTreeDistances[r][q] = distanceArray[r];
                sliceTreeTimes[r][q] = timeArray[r];
                if (sdr) {
                    sliceTreeMaxPathDistances[q][r] = maxPathDistanceArray[r];
                    sliceTreeMaxDistancesFromRoot[q][r] = maxDistanceFromRootArray[r];
                    sliceTreeTimesFromRoot[r][q] = timeFromRootArray[r];
                    sliceTreeDiffusionCoefficients[q][r] = diffusionCoefficientArray[r];
                    sliceTreeDiffusionCoefficientVariances[q][r] = diffusionCoefficientVarianceArray[r];
                }
            }
        }
        //print2DArray(sliceTreeDistances,"sliceTreeDistances.txt");
        //print2DArray(sliceTreeTimes,"sliceTreeTimes.txt");
        print2DTransposedArray(sliceTreeDiffusionCoefficients, "sliceTreeDiffusionCoefficients.txt");
        print2DTransposedArray(sliceTreeDiffusionCoefficientVariances, "sliceTreeDiffusionCoefficientVariances.txt");
        if (sliceCount > 1) {
            for (int s = 0; s < sliceTreeDistanceArrays.size(); s++) {
                double[] distanceArray = (double[]) sliceTreeDistanceArrays.get(s);
                double[] timeArray = (double[]) sliceTreeTimeArrays.get(s);
                double[] maxDistanceFromRootArray = null;
                double[] maxPathDistanceArray = null;
                double[] timeFromRoot = null;
                if (sdr) {
                    maxPathDistanceArray = (double[]) sliceTreeMaxPathDistanceArrays.get(s);
                    maxDistanceFromRootArray = (double[]) sliceTreeMaxDistanceFromRootArrays.get(s);
                    timeFromRoot = (double[]) sliceTreeTimeFromRootArrays.get(s);
                }
                for (int t = 0; t < (sliceCount - 1); t++) {
                    if (sdr) {
                        sliceTreeMaxDistanceFromRootRates[s][t] = (maxDistanceFromRootArray[t]) / (timeFromRoot[t]);
                        sliceTreeMaxPathRates[s][t] = (maxPathDistanceArray[t]) / (timeFromRoot[t]);
                    }
                    if ((timeArray[t] - timeArray[t + 1]) > ((Double) treeLengths.get(s) * treeLengthPercentage)) {
                        sliceTreeWeightedAverageRates[s][t] = (distanceArray[t] - distanceArray[t + 1]) / (timeArray[t] - timeArray[t + 1]);
                        sliceTreeDistancesToSummarize[s][t] = (distanceArray[t]);
                        sliceTreeIntervalDistances[s][t] = (distanceArray[t] - distanceArray[t + 1]);
                    //sliceTreeWeightedAverageRates[s][t] = (sliceTreeDistances[t][s] - sliceTreeDistances[t+1][s])/(sliceTreeTimes[t][s] - sliceTreeTimes[t+1][s]);
                    //sliceTreeWeightedAverageDiffusionCoefficients[s][t] = Math.pow((distanceArray[t] - distanceArray[t+1]),2.0)/(4.0*(timeArray[t] - timeArray[t+1]));
                    } else {
                        if (timeArray[t] > 0) {
                            if (t == 0) {
                                throw new RuntimeException("Philippe to fix: the time slices are expected in ascending height order");
                            }
                            sliceTreeWeightedAverageRates[s][t] = sliceTreeWeightedAverageRates[s][t - 1];
                            sliceTreeDistancesToSummarize[s][t] = sliceTreeDistancesToSummarize[s][t - 1];
                            sliceTreeIntervalDistances[s][t] = sliceTreeIntervalDistances[s][t - 1];
                        //sliceTreeWeightedAverageDiffusionCoefficients[s][t] = sliceTreeWeightedAverageDiffusionCoefficients[s][t-1];
                        } else {
                            //set it to NaN, we ignore NaNs when getting summary stats
                            sliceTreeWeightedAverageRates[s][t] = Double.NaN;
                            sliceTreeDistancesToSummarize[s][t] = Double.NaN;
                            sliceTreeIntervalDistances[s][t] = Double.NaN;
                        //sliceTreeWeightedAverageDiffusionCoefficients[s][t] = Double.NaN;
                        }
                    }
                }
                if ((timeArray[sliceCount - 1]) > ((Double) treeLengths.get(s) * treeLengthPercentage)) {
                    sliceTreeWeightedAverageRates[s][sliceCount - 1] = (distanceArray[sliceCount - 1]) / (timeArray[sliceCount - 1]);
                    sliceTreeDistancesToSummarize[s][sliceCount - 1] = (distanceArray[sliceCount - 1]);
                    sliceTreeIntervalDistances[s][sliceCount - 1] = (distanceArray[sliceCount - 1]);
                //sliceTreeWeightedAverageDiffusionCoefficients[s][sliceCount-1] = Math.pow(distanceArray[sliceCount-1],2.0)/(4.0*timeArray[sliceCount-1]);
                } else {
                    if ((timeArray[sliceCount - 1]) > 0) {
                        sliceTreeWeightedAverageRates[s][sliceCount - 1] = sliceTreeWeightedAverageRates[s][sliceCount - 2];
                        sliceTreeDistancesToSummarize[s][sliceCount - 1] = sliceTreeDistancesToSummarize[s][sliceCount - 2];
                        sliceTreeIntervalDistances[s][sliceCount - 1] = sliceTreeIntervalDistances[s][sliceCount - 2];
                    //sliceTreeWeightedAverageDiffusionCoefficients[s][sliceCount-1] = sliceTreeWeightedAverageDiffusionCoefficients[s][sliceCount-2];
                    } else {
                        sliceTreeWeightedAverageRates[s][sliceCount - 1] = (distanceArray[sliceCount - 1]) / (timeArray[sliceCount - 1]);
                        sliceTreeDistancesToSummarize[s][sliceCount - 1] = (distanceArray[sliceCount - 1]);
                        sliceTreeIntervalDistances[s][sliceCount - 1] = distanceArray[sliceCount - 1];
                    //sliceTreeWeightedAverageDiffusionCoefficients[s][sliceCount-1] = Math.pow(distanceArray[sliceCount-1],2.0)/(4.0*timeArray[sliceCount-1]);
                    }
                }
                if (sdr) {
                    sliceTreeMaxPathRates[s][sliceCount - 1] = maxPathDistanceArray[sliceCount - 1] / timeFromRoot[sliceCount - 1];
                    sliceTreeMaxDistanceFromRootRates[s][sliceCount - 1] = maxDistanceFromRootArray[sliceCount - 1] / timeFromRoot[sliceCount - 1];
                }
            }
        } else {
            for (int s = 0; s < sliceTreeDistanceArrays.size(); s++) {
                double[] distanceArray = (double[]) sliceTreeDistanceArrays.get(s);
                double[] timeArray = (double[]) sliceTreeTimeArrays.get(s);
                sliceTreeWeightedAverageRates[s][0] = distanceArray[0] / timeArray[0];
                sliceTreeDistancesToSummarize[s][0] = distanceArray[0];
                sliceTreeIntervalDistances[s][0] = distanceArray[0];
                //sliceTreeWeightedAverageDiffusionCoefficients[s][0] = Math.pow(distanceArray[0],2.0)/(4.0*timeArray[0]);
                if (sdr) {
                    double[] maxPathDistanceArray = (double[]) sliceTreeMaxPathDistanceArrays.get(s);
                    double[] maxDistanceFromRootArray = (double[]) sliceTreeMaxDistanceFromRootArrays.get(s);
                    double[] timeFromRoot = (double[]) sliceTreeTimeFromRootArrays.get(s);
                    sliceTreeMaxPathRates[s][0] = maxPathDistanceArray[0] / timeFromRoot[0];
                    sliceTreeMaxDistanceFromRootRates[s][0] = maxDistanceFromRootArray[0] / timeFromRoot[0];
                }
            }
        }
        try {
            String outfile = sdrFile;
            if (!sdr) {
                outfile = snrFile;
            }
            PrintWriter sliceDispersalRateFile = new PrintWriter(new FileWriter(outfile), true);
            sliceDispersalRateFile.print("sliceTime" + "\t");
            if (mostRecentSamplingDate > 0) {
                sliceDispersalRateFile.print("realTime" + "\t");
            }
            sliceDispersalRateFile.print("mean dispersalRate" + "\t" + "hpd low" + "\t" + "hpd up");
            if (sdr) {
                sliceDispersalRateFile.print("\t" + "mean wavefrontRate" + "\t" + "hpd low" + "\t" + "hpd up" + "\t" + "mean wavefrontDistance" + "\t" + "hpd low" + "\t" + "hpd up" + "\t" + "mean cumulative DiffusionCoefficient" + "\t" + "hpd low" + "\t" + "hpd up" + "\r");
            } else if (snr) {
                sliceDispersalRateFile.print("\r");
            }
            double[] meanWeightedAverageDispersalRates = meanColNoNaN(sliceTreeWeightedAverageRates);
            double[][] hpdWeightedAverageDispersalRates = getArrayHPDintervals(sliceTreeWeightedAverageRates);
            //                double[] meanSliceTreeDistancesToSummarize = meanColNoNaN(sliceTreeDistancesToSummarize);
            //                double[][] hpdSliceTreeDistancesToSummarize = getArrayHPDintervals(sliceTreeDistancesToSummarize);
            //                double[] meanMaxDispersalDistances = null;
            //                double[][] hpdMaxDispersalDistances = null;
            //                double[] meanMaxDispersalRates = null;
            //                double[][] hpdMaxDispersalRates = null;
            double[] meanMaxPathDispersalDistances = null;
            double[][] hpdMaxPathDispersalDistances = null;
            double[] meanMaxPathDispersalRates = null;
            double[][] hpdMaxPathDispersalRates = null;
            double[] meanMaxRootDispersalDistances = null;
            double[][] hpdMaxRootDispersalDistances = null;
            double[] meanMaxRootDispersalRates = null;
            double[][] hpdMaxRootDispersalRates = null;
            double[] meanDiffusionCoefficients = null;
            double[][] hpdDiffusionCoefficients = null;
            if (sdr) {
                meanMaxPathDispersalDistances = meanColNoNaN(sliceTreeMaxPathDistances);
                hpdMaxPathDispersalDistances = getArrayHPDintervals(sliceTreeMaxPathDistances);
                meanMaxPathDispersalRates = meanColNoNaN(sliceTreeMaxPathRates);
                hpdMaxPathDispersalRates = getArrayHPDintervals(sliceTreeMaxPathRates);
                meanMaxRootDispersalDistances = meanColNoNaN(sliceTreeMaxDistancesFromRoot);
                hpdMaxRootDispersalDistances = getArrayHPDintervals(sliceTreeMaxDistancesFromRoot);
                meanMaxRootDispersalRates = meanColNoNaN(sliceTreeMaxDistanceFromRootRates);
                hpdMaxRootDispersalRates = getArrayHPDintervals(sliceTreeMaxDistanceFromRootRates);
                meanDiffusionCoefficients = meanColNoNaN(sliceTreeDiffusionCoefficients);
                hpdDiffusionCoefficients = getArrayHPDintervals(sliceTreeDiffusionCoefficients);
            }
            //double[][] hpdWeightedAverageDiffusionCoefficients = getArrayHPDintervals(sliceTreeWeightedAverageDiffusionCoefficients);
            for (int u = 0; u < sliceCount; u++) {
                sliceDispersalRateFile.print(sliceHeights[u] + "\t");
                if (mostRecentSamplingDate > 0) {
                    sliceDispersalRateFile.print((mostRecentSamplingDate - sliceHeights[u]) + "\t");
                }
                sliceDispersalRateFile.print(meanWeightedAverageDispersalRates[u] + "\t" + hpdWeightedAverageDispersalRates[u][0] + "\t" + hpdWeightedAverageDispersalRates[u][1]);
                if (sdr) {
                    sliceDispersalRateFile.print("\t" + meanMaxRootDispersalRates[u] + "\t" + hpdMaxRootDispersalRates[u][0] + "\t" + hpdMaxRootDispersalRates[u][1] + "\t" + meanMaxRootDispersalDistances[u] + "\t" + hpdMaxRootDispersalDistances[u][0] + "\t" + hpdMaxRootDispersalDistances[u][1] + "\t" + meanDiffusionCoefficients[u] + "\t" + hpdDiffusionCoefficients[u][0] + "\t" + hpdDiffusionCoefficients[u][1] + "\r");
                //                        sliceDispersalRateFile.print("\t" + meanMaxPathDispersalRates[u] + "\t" + hpdMaxPathDispersalRates[u][0] + "\t" + hpdMaxPathDispersalRates[u][1] + "\t" + meanMaxPathDispersalDistances[u] + "\t" + hpdMaxPathDispersalDistances[u][0] + "\t" + hpdMaxPathDispersalDistances[u][1] + "\t" + meanDiffusionCoefficients[u] + "\t" + hpdDiffusionCoefficients[u][0] + "\t" + hpdDiffusionCoefficients[u][1] + "\r");
                } else if (snr) {
                    sliceDispersalRateFile.print("\r");
                }
            }
            sliceDispersalRateFile.close();
        } catch (IOException e) {
            System.err.println("IO Exception encountered: " + e.getMessage());
            System.exit(-1);
        }
    }
}
Also used : XMLOutputter(org.jdom.output.XMLOutputter) Element(org.jdom.Element)

Example 25 with XMLOutputter

use of org.jdom.output.XMLOutputter in project beast-mcmc by beast-dev.

the class XMLModelFile method printIdentified.

public void printIdentified() {
    System.out.println("Identified elements follow");
    XMLOutputter outputter = new XMLOutputter();
    for (Map.Entry<String, XMLModelIdentifiable> stringXMLModelIdentifiableEntry : identifiedElements.entrySet()) {
        System.out.println("Original name: " + stringXMLModelIdentifiableEntry.getKey());
        stringXMLModelIdentifiableEntry.getValue().print(outputter, System.out);
    }
}
Also used : XMLOutputter(org.jdom.output.XMLOutputter)

Aggregations

XMLOutputter (org.jdom.output.XMLOutputter)48 Element (org.jdom.Element)27 Document (org.jdom.Document)16 Format (org.jdom.output.Format)16 IOException (java.io.IOException)15 StringWriter (java.io.StringWriter)13 SAXBuilder (org.jdom.input.SAXBuilder)6 Writer (java.io.Writer)5 ArrayList (java.util.ArrayList)5 StringReader (java.io.StringReader)4 List (java.util.List)3 TreeMap (java.util.TreeMap)3 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)3 JDOMException (org.jdom.JDOMException)3 ElementFilter (org.jdom.filter.ElementFilter)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 FileOutputStream (java.io.FileOutputStream)2 DateFormat (java.text.DateFormat)2 SimpleDateFormat (java.text.SimpleDateFormat)2