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);
}
}
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;
}
}
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);
}
Aggregations