use of org.geneontology.minerva.json.MolecularModelJsonRenderer in project minerva by geneontology.
the class CommandLineInterface method owl2LegoJson.
/**
* Convert a GO-CAM owl file to a minerva json structure
* --owl-lego-to-json
*
* @param input
* @param output
* @param usePretty
* @throws Exception
*/
public static void owl2LegoJson(String input, String output, boolean usePretty) throws Exception {
// minimal inputs
if (input == null) {
System.err.println("No input model was configured.");
System.exit(-1);
return;
}
if (output == null) {
System.err.println("No output file was configured.");
System.exit(-1);
return;
}
// configuration
CurieHandler curieHandler = DefaultCurieHandler.getDefaultHandler();
GsonBuilder gsonBuilder = new GsonBuilder();
if (usePretty) {
gsonBuilder.setPrettyPrinting();
}
Gson gson = gsonBuilder.create();
// process each model
if (LOGGER.isInfoEnabled()) {
LOGGER.info("Loading model from file: " + input);
}
OWLOntology model = null;
final JsonModel jsonModel;
ParserWrapper pw = new ParserWrapper();
try {
// load model
model = pw.parseOWL(IRI.create(new File(input).getCanonicalFile()));
// TODO decide if we need reasoning
InferenceProvider inferenceProvider = null;
String modelId = null;
Optional<IRI> ontologyIRI = model.getOntologyID().getOntologyIRI();
if (ontologyIRI.isPresent()) {
modelId = curieHandler.getCuri(ontologyIRI.get());
}
// render json
final MolecularModelJsonRenderer renderer = new MolecularModelJsonRenderer(modelId, model, inferenceProvider, curieHandler);
jsonModel = renderer.renderModel();
} finally {
if (model != null) {
pw.getManager().removeOntology(model);
model = null;
}
}
// save as json string
final String json = gson.toJson(jsonModel);
final File outputFile = new File(output).getCanonicalFile();
try (OutputStream outputStream = new FileOutputStream(outputFile)) {
if (LOGGER.isInfoEnabled()) {
LOGGER.info("Saving json to file: " + outputFile);
}
IOUtils.write(json, outputStream);
}
}
use of org.geneontology.minerva.json.MolecularModelJsonRenderer in project minerva by geneontology.
the class ModelARTHandler method addToModel.
private void addToModel(String modelId, ModelARTResult result) throws Exception {
IRI modelIri = curieHandler.getIRI(modelId);
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
OWLOntology currentOntology = m3.getModelAbox(modelIri);
OWLOntology storedOntology = m3.loadModelABox(modelIri, manager);
// OWLOntology stored_ontology = man1.copyOntology(storedOntology, OntologyCopy.DEEP);
ModelContainer storedMC = new ModelContainer(modelIri, null, storedOntology);
final MolecularModelJsonRenderer storedRenderer = createModelRenderer(storedMC, go_lego, null, curieHandler);
JsonModel jsonStoredModel = storedRenderer.renderModel();
ModelContainer activeMC = new ModelContainer(modelIri, null, currentOntology);
InferenceProvider inferenceProvider = ipc.create(activeMC);
final MolecularModelJsonRenderer renderer = createModelRenderer(activeMC, go_lego, inferenceProvider, curieHandler);
JsonModel jsonActiveModel = renderer.renderModel();
result.storedModel = jsonStoredModel;
result.activeModel = jsonActiveModel;
result.diffModel = getDiff(jsonStoredModel, jsonActiveModel);
}
use of org.geneontology.minerva.json.MolecularModelJsonRenderer in project minerva by geneontology.
the class UndoAwareMolecularModelManagerTest method testUndoRedo.
@Test
public void testUndoRedo() throws Exception {
OWLOntology tbox = OWLManager.createOWLOntologyManager().loadOntologyFromOntologyDocument(this.getClass().getResourceAsStream("/go-mgi-signaling-test.obo"));
m3 = new UndoAwareMolecularModelManager(tbox, curieHandler, "http://testmodel.geneontology.org/", folder.newFile().getAbsolutePath(), null, go_lego_journal_file, true);
String userId = "test-user-id";
ModelContainer model = m3.generateBlankModel(null);
// GO:0001158 ! enhancer sequence-specific DNA binding
OWLNamedIndividual bindingIdividual = m3.createIndividual(model.getModelId(), "GO:0001158", null, new UndoMetadata(userId));
String bindingId = bindingIdividual.getIRI().toString();
// BFO:0000066 GO:0005654 ! occurs_in nucleoplasm
m3.addType(model.getModelId(), bindingId, "BFO:0000066", "GO:0005654", new UndoMetadata(userId));
MolecularModelJsonRenderer renderer = new MolecularModelJsonRenderer(model, null, curieHandler);
JsonOwlIndividual render1 = renderer.renderObject(bindingIdividual);
assertEquals(2, render1.type.length);
// check event count
Pair<List<ChangeEvent>, List<ChangeEvent>> undoRedoEvents = m3.getUndoRedoEvents(model.getModelId());
List<ChangeEvent> undoEvents = undoRedoEvents.getLeft();
List<ChangeEvent> redoEvents = undoRedoEvents.getRight();
assertEquals(0, redoEvents.size());
assertEquals(2, undoEvents.size());
// undo
assertTrue(m3.undo(model, userId));
JsonOwlIndividual render2 = renderer.renderObject(bindingIdividual);
assertEquals(1, render2.type.length);
// redo
assertTrue(m3.redo(model, userId));
JsonOwlIndividual render3 = renderer.renderObject(bindingIdividual);
assertEquals(2, render3.type.length);
// undo again
assertTrue(m3.undo(model, userId));
JsonOwlIndividual render4 = renderer.renderObject(bindingIdividual);
assertEquals(1, render4.type.length);
// add new type
// GO:0001664 ! G-protein coupled receptor binding
m3.addType(model.getModelId(), bindingId, "GO:0001664", new UndoMetadata(userId));
// redo again, should fail
assertFalse(m3.redo(model, userId));
if (m3 != null) {
m3.dispose();
}
}
Aggregations