Search in sources :

Example 46 with XMLOutputter

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

the class AntigenicPlotter method writeKML.

/**
     * Discrete KML
     * @param fileName
     * @param labels
     * @param data
     * @param clusterIndices
     * @param clusterSizes
     */
private void writeKML(String fileName, String[] labels, double[][][] data, int[][] clusterIndices, int[][] clusterSizes) {
    int[] traceOrder = sortTraces(labels);
    Element traceSchema = new Element("Schema");
    traceSchema.setAttribute("id", "Cluster_Schema");
    traceSchema.addContent(new Element("SimpleField").setAttribute("name", "Label").setAttribute("type", "string").addContent(new Element("displayName").addContent("Label")));
    traceSchema.addContent(new Element("SimpleField").setAttribute("name", "Number").setAttribute("type", "double").addContent(new Element("displayName").addContent("Number")));
    traceSchema.addContent(new Element("SimpleField").setAttribute("name", "Year").setAttribute("type", "double").addContent(new Element("displayName").addContent("Year")));
    traceSchema.addContent(new Element("SimpleField").setAttribute("name", "State").setAttribute("type", "double").addContent(new Element("displayName").addContent("State")));
    Element virusSchema = new Element("Schema");
    virusSchema.setAttribute("id", "Virus_Schema");
    virusSchema.addContent(new Element("SimpleField").setAttribute("name", "Label").setAttribute("type", "string").addContent(new Element("displayName").addContent("Label")));
    virusSchema.addContent(new Element("SimpleField").setAttribute("name", "Year").setAttribute("type", "double").addContent(new Element("displayName").addContent("Year")));
    virusSchema.addContent(new Element("SimpleField").setAttribute("name", "Trace").setAttribute("type", "double").addContent(new Element("displayName").addContent("Trace")));
    //        final Element contourFolderElement = new Element("Folder");
    //        Element contourFolderNameElement = new Element("name");
    //        contourFolderNameElement.addContent("HPDs");
    //        contourFolderElement.addContent(contourFolderNameElement);
    final Element traceFolderElement = new Element("Folder");
    Element traceFolderNameElement = new Element("name");
    traceFolderNameElement.addContent("traces");
    traceFolderElement.addContent(traceFolderNameElement);
    final Element clustersFolderElement = new Element("Folder");
    Element clustersFolderNameElement = new Element("name");
    clustersFolderNameElement.addContent("clusters");
    clustersFolderElement.addContent(clustersFolderNameElement);
    Element documentNameElement = new Element("name");
    String documentName = fileName;
    if (documentName.endsWith(".kml"))
        documentName = documentName.replace(".kml", "");
    documentNameElement.addContent(documentName);
    final Element documentElement = new Element("Document");
    documentElement.addContent(documentNameElement);
    documentElement.addContent(traceSchema);
    documentElement.addContent(virusSchema);
    //        documentElement.addContent(hpdSchema);
    documentElement.addContent(clustersFolderElement);
    documentElement.addContent(traceFolderElement);
    //        documentElement.addContent(contourFolderElement);
    final Element rootElement = new Element("kml");
    rootElement.addContent(documentElement);
    Element traceElement = generateTraceElement(labels, data, traceOrder);
    traceFolderElement.addContent(traceElement);
    Element clustersElement = generateClusterElement(labels, data, clusterIndices, clusterSizes, traceOrder);
    clustersFolderElement.addContent(clustersElement);
    //        Element contourElement = generateKDEElement(0.95, labels, data, traceOrder);
    //        contourFolderElement.addContent(contourElement);
    PrintStream resultsStream;
    try {
        resultsStream = new PrintStream(new File(fileName));
        XMLOutputter xmlOutputter = new XMLOutputter(Format.getPrettyFormat().setTextMode(Format.TextMode.PRESERVE));
        xmlOutputter.output(rootElement, resultsStream);
    } catch (IOException e) {
        System.err.println("Error opening file: " + fileName);
        System.exit(-1);
    }
}
Also used : XMLOutputter(org.jdom.output.XMLOutputter) Element(org.jdom.Element)

Example 47 with XMLOutputter

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

the class TreeKMLGenerator method main.

public static void main(String[] args) {
    String inputTreeFile = args[0];
    RootedTree tree = null;
    try {
        TreeImporter importer = new NexusImporter(new FileReader(inputTreeFile));
        tree = (RootedTree) importer.importNextTree();
    } catch (ImportException e) {
        e.printStackTrace();
        return;
    } catch (IOException e) {
        e.printStackTrace();
        return;
    }
    TreeKMLGenerator generator = new TreeKMLGenerator(tree);
    Settings settings = new Settings(AnalysisType.CONTINUOUS);
    //        settings.getAltitudeTreeSettings().setTreeType(TreeType.ARC_TREE);
    //        settings.getAltitudeTreeSettings().getBranchStyle().setColorProperty("height");
    settings.getGroundTreeSettings().setTreeType(TreeType.SURFACE_TREE);
    settings.getGroundTreeSettings().getBranchStyle().setColorProperty("height");
    settings.setPlotAltitude(0);
    settings.setMostRecentDate(2003);
    //settings.setAgeCutOff(1995);
    settings.setTimeDivisionCount(0);
    settings.setTraitName("antigenic");
    settings.setLatitudeName("antigenic1");
    settings.setLongitudeName("antigenic2");
    try {
        BufferedWriter out = new BufferedWriter(new FileWriter(args[0] + ".kml"));
        Document doc = new Document(generator.generate(args[0], settings));
        try {
            XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat());
            outputter.output(doc, out);
        } catch (IOException e) {
            System.err.println(e);
        }
        out.close();
    } catch (IOException e) {
        e.printStackTrace();
        return;
    }
}
Also used : XMLOutputter(org.jdom.output.XMLOutputter) NexusImporter(jebl.evolution.io.NexusImporter) FileWriter(java.io.FileWriter) IOException(java.io.IOException) BufferedWriter(java.io.BufferedWriter) ImportException(jebl.evolution.io.ImportException) RootedTree(jebl.evolution.trees.RootedTree) TreeImporter(jebl.evolution.io.TreeImporter) FileReader(java.io.FileReader)

Example 48 with XMLOutputter

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

the class XMLModelCombiner method writeXML.

public void writeXML(OutputStream ostream) {
    from.prefixIdentifiedNames("from", mapping.getFromNames(), true);
    to.prefixIdentifiedNames("to", mapping.getToNames(), false);
    XMLOutputter outputter = new XMLOutputter();
    from.print(outputter, ostream);
    to.print(outputter, ostream);
}
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