use of javax.json.stream.JsonGeneratorFactory in project beast-mcmc by beast-dev.
the class AuspiceGenerator method writeMetaJSON.
private void writeMetaJSON(String filename, RootedTree tree) throws IOException {
FileWriter writer = new FileWriter(filename);
HashMap<String, Object> config = new HashMap<>();
config.put(JsonGenerator.PRETTY_PRINTING, true);
JsonGeneratorFactory factory = Json.createGeneratorFactory(config);
JsonGenerator generator = factory.createGenerator(writer);
generator.writeStartObject();
generator.writeStartObject("author_info").writeEnd();
generator.writeStartObject("color_options");
for (String attribute : attributeNames) {
generator.writeStartObject(attribute);
generator.writeStartArray("color_map");
for (String value : attributeValues.get(attribute)) {
generator.writeStartArray().write(value).write("#000000").writeEnd();
}
// color_map array
generator.writeEnd();
generator.write("key", attribute).write("legendTitle", attribute).write("menuItem", attribute).write("type", "discrete");
// attribute object
generator.writeEnd();
}
generator.writeStartObject("num_date").write("key", "num_date").write("legendTitle", "Sampling Date").write("menuItem", "date").write("type", "continuous").writeEnd();
// color_options object
generator.writeEnd();
generator.writeStartObject("defaults").write("mapTriplicate", true).writeEnd();
generator.writeStartArray("filters");
for (String attribute : attributeNames) {
generator.write("attributes");
}
// filters array
generator.writeEnd();
generator.writeStartObject("geo");
for (String attribute : attributeNames) {
generator.writeStartObject(attribute);
for (String value : attributeValues.get(attribute)) {
generator.writeStartObject(value).write("latitude", 0.0).write("longitude", 0.0).writeEnd();
}
// attribute object
generator.writeEnd();
}
// geo object
generator.writeEnd();
generator.writeStartArray("maintainer").writeEnd();
generator.writeStartArray("panels").write("tree").write("map").writeEnd();
generator.write("title", "").write("updated", LocalDate.now().toString()).write("virus_count", tree.getExternalNodes().size());
// outer object
generator.writeEnd();
generator.close();
}
Aggregations