use of org.geneontology.minerva.MinervaOWLGraphWrapper in project minerva by geneontology.
the class M3ExpressionParserTest method init.
static void init(ParserWrapper pw) throws OWLOntologyCreationException, IOException {
/* File file = new File("src/test/resources/go-lego-module.omn.gz").getCanonicalFile(); */
File file = new File("src/test/resources/go-lego-module-compact.omn.gz").getCanonicalFile();
graph = new MinervaOWLGraphWrapper(pw.parseOWL(IRI.create(file)));
}
use of org.geneontology.minerva.MinervaOWLGraphWrapper in project minerva by geneontology.
the class MolecularModelJsonRendererTest method testSimpleClassExpression.
private void testSimpleClassExpression(OWLClassExpression ce, String expectedJsonType) throws Exception {
// setup test model/ontology
OWLOntology o = m.createOntology();
OWLImportsDeclaration importDeclaration = f.getOWLImportsDeclaration(g.getSourceOntology().getOntologyID().getOntologyIRI().get());
m.applyChange(new AddImport(o, importDeclaration));
// create indivdual with a ce type
final IRI i1IRI = IRI.generateDocumentIRI();
final OWLNamedIndividual ni1 = f.getOWLNamedIndividual(i1IRI);
// declare individual
m.addAxiom(o, f.getOWLDeclarationAxiom(ni1));
// declare type
m.addAxiom(o, f.getOWLClassAssertionAxiom(ce, ni1));
MolecularModelJsonRenderer r = new MolecularModelJsonRenderer(null, o, null, curieHandler);
JsonOwlIndividual jsonOwlIndividualOriginal = r.renderObject(ni1);
String json = MolecularModelJsonRenderer.renderToJson(jsonOwlIndividualOriginal, true);
assertTrue(json, json.contains("\"type\": \"" + expectedJsonType + "\""));
JsonOwlIndividual jsonOwlIndividualParse = MolecularModelJsonRenderer.parseFromJson(json, JsonOwlIndividual.class);
assertNotNull(jsonOwlIndividualParse);
assertEquals(jsonOwlIndividualOriginal, jsonOwlIndividualParse);
Set<OWLClassExpression> ces = TestJsonOwlObjectParser.parse(new MinervaOWLGraphWrapper(o), jsonOwlIndividualParse.type);
assertEquals(1, ces.size());
assertEquals(ce, ces.iterator().next());
}
use of org.geneontology.minerva.MinervaOWLGraphWrapper in project minerva by geneontology.
the class FindTaxonTool method getEntityTaxon.
public String getEntityTaxon(String curie, OWLOntology model) throws UnknownIdentifierException {
if (curie == null || curie.isEmpty()) {
return null;
}
OWLDataFactory df = model.getOWLOntologyManager().getOWLDataFactory();
OWLClass cls = df.getOWLClass(curieHandler.getIRI(curie));
String taxon = getEntityTaxon(cls, model);
if (taxon == null) {
MinervaOWLGraphWrapper g = new MinervaOWLGraphWrapper(model);
cls = g.getOWLClassByIdentifier(curie);
if (cls != null) {
taxon = getEntityTaxon(cls, model);
}
IOUtils.closeQuietly(g);
}
return taxon;
}
use of org.geneontology.minerva.MinervaOWLGraphWrapper in project minerva by geneontology.
the class MolecularModelJsonRenderer method renderEvidences.
public static List<JsonEvidenceInfo> renderEvidences(OWLOntologyManager manager, CurieHandler curieHandler) throws OWLException, IOException {
// TODO remove the hard coded ECO dependencies
OntologyMapperPair<EcoMapper> pair;
synchronized (ecoMutex) {
if (eco == null) {
eco = EcoMapperFactory.createEcoMapper(manager);
}
pair = eco;
}
final MinervaOWLGraphWrapper graph = pair.getGraph();
final EcoMapper mapper = pair.getMapper();
Set<OWLClass> ecoClasses = graph.getAllOWLClasses();
Map<OWLClass, String> codesForEcoClasses = mapper.getCodesForEcoClasses();
List<JsonEvidenceInfo> relList = new ArrayList<JsonEvidenceInfo>();
for (OWLClass ecoClass : ecoClasses) {
if (ecoClass.isBuiltIn()) {
continue;
}
JsonEvidenceInfo json = new JsonEvidenceInfo();
json.id = curieHandler.getCuri(ecoClass);
json.label = graph.getLabel(ecoClass);
String code = codesForEcoClasses.get(ecoClass);
if (code != null) {
json.code = code;
}
relList.add(json);
}
return relList;
}
use of org.geneontology.minerva.MinervaOWLGraphWrapper in project minerva by geneontology.
the class MolecularModelJsonRenderer method renderProperties.
public static Pair<List<JsonRelationInfo>, List<JsonRelationInfo>> renderProperties(MolecularModelManager<?> mmm, Set<OWLObjectProperty> importantRelations, CurieHandler curieHandler) throws OWLOntologyCreationException {
/* [{
* id: {String}
* label: {String}
* relevant: {boolean} // flag to indicate if this is a relation to be used in the model
* ?color: {String} // TODO in the future?
* ?glyph: {String} // TODO in the future?
* }]
*/
// retrieve (or load) all ontologies
// put in a new wrapper
MinervaOWLGraphWrapper wrapper = new MinervaOWLGraphWrapper(mmm.getOntology());
Collection<IRI> imports = mmm.getImports();
OWLOntologyManager manager = wrapper.getManager();
for (IRI iri : imports) {
OWLOntology ontology = manager.getOntology(iri);
if (ontology == null) {
// only try to load it, if it isn't already loaded
try {
ontology = manager.loadOntology(iri);
} catch (OWLOntologyDocumentAlreadyExistsException e) {
IRI existing = e.getOntologyDocumentIRI();
ontology = manager.getOntology(existing);
} catch (OWLOntologyAlreadyExistsException e) {
OWLOntologyID id = e.getOntologyID();
ontology = manager.getOntology(id);
}
}
if (ontology == null) {
LOG.warn("Could not find an ontology for IRI: " + iri);
} else {
wrapper.addSupportOntology(ontology);
}
}
// get all properties from all loaded ontologies
Set<OWLObjectProperty> properties = new HashSet<OWLObjectProperty>();
Set<OWLDataProperty> dataProperties = new HashSet<OWLDataProperty>();
Set<OWLOntology> allOntologies = wrapper.getAllOntologies();
for (OWLOntology o : allOntologies) {
properties.addAll(o.getObjectPropertiesInSignature());
dataProperties.addAll(o.getDataPropertiesInSignature());
}
// sort properties
List<OWLObjectProperty> propertyList = new ArrayList<OWLObjectProperty>(properties);
List<OWLDataProperty> dataPropertyList = new ArrayList<OWLDataProperty>(dataProperties);
Collections.sort(propertyList);
Collections.sort(dataPropertyList);
// retrieve id and label for all properties
List<JsonRelationInfo> relList = new ArrayList<JsonRelationInfo>();
for (OWLObjectProperty p : propertyList) {
if (p.isBuiltIn()) {
// skip owl:topObjectProperty
continue;
}
JsonRelationInfo json = new JsonRelationInfo();
json.id = curieHandler.getCuri(p);
json.label = wrapper.getLabel(p);
if (importantRelations != null && (importantRelations.contains(p))) {
json.relevant = true;
} else {
json.relevant = false;
}
relList.add(json);
}
// retrieve id and label for all data properties
List<JsonRelationInfo> dataList = new ArrayList<JsonRelationInfo>();
for (OWLDataProperty p : dataPropertyList) {
if (p.isBuiltIn()) {
continue;
}
JsonRelationInfo json = new JsonRelationInfo();
json.id = curieHandler.getCuri(p);
json.label = wrapper.getLabel(p);
dataList.add(json);
}
IOUtils.closeQuietly(wrapper);
return Pair.of(relList, dataList);
}
Aggregations