Skip to content

Commit

Permalink
Return root type for complement classes. (#451)
Browse files Browse the repository at this point in the history
  • Loading branch information
balhoff authored Feb 4, 2022
1 parent 2fb0d61 commit 8241a3a
Show file tree
Hide file tree
Showing 5 changed files with 541,892 additions and 103 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,7 @@
import org.openrdf.rio.RDFParseException;
import org.openrdf.rio.helpers.StatementCollector;
import org.semanticweb.owlapi.apibinding.OWLManager;
import org.semanticweb.owlapi.model.IRI;
import org.semanticweb.owlapi.model.OWLAnnotation;
import org.semanticweb.owlapi.model.OWLAnnotationProperty;
import org.semanticweb.owlapi.model.OWLAxiom;
import org.semanticweb.owlapi.model.OWLClass;
import org.semanticweb.owlapi.model.OWLClassExpression;
import org.semanticweb.owlapi.model.OWLDataFactory;
import org.semanticweb.owlapi.model.OWLNamedIndividual;
import org.semanticweb.owlapi.model.OWLNamedObject;
import org.semanticweb.owlapi.model.OWLOntology;
import org.semanticweb.owlapi.model.OWLOntologyCreationException;
import org.semanticweb.owlapi.model.OWLOntologyManager;
import org.semanticweb.owlapi.model.*;
import org.semanticweb.owlapi.rio.RioRenderer;
import org.semanticweb.owlapi.search.EntitySearcher;
import org.semarglproject.vocab.OWL;
Expand Down Expand Up @@ -397,14 +386,16 @@ public Map<OWLNamedIndividual, Set<String>> getSuperCategoryMapForIndividuals(Se
Map<OWLNamedIndividual, Set<String>> ind_roots = new HashMap<OWLNamedIndividual, Set<String>>();
Set<String> all_types = new HashSet<String>();
Map<OWLNamedIndividual, Set<String>> ind_types = new HashMap<OWLNamedIndividual, Set<String>>();
for(OWLNamedIndividual ind : inds) {
for (OWLNamedIndividual ind : inds) {
Set<String> types = new HashSet<String>();
for(OWLClassExpression oc : EntitySearcher.getTypes(ind, ont)) {
if(!oc.isAnonymous()) {
if (oc.isNamed()) {
types.add(oc.asOWLClass().getIRI().toString());
all_types.addAll(types);
} else if (oc instanceof OWLObjectComplementOf) {
types.add(((OWLObjectComplementOf)oc).getOperand().asOWLClass().getIRI().toString());
}
}
all_types.addAll(types);
if(fix_deprecated) {
ind_types.put(ind, replaceDeprecated(types));
}else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,27 +60,27 @@ public GoCamModel(OWLOntology abox, BlazegraphMolecularModelManager m3) throws I
}

private void setIndTypesWithSparql(BlazegraphMolecularModelManager m3, String graph_id) throws MalformedQueryException, QueryEvaluationException, RepositoryException, IOException {
Map<OWLNamedIndividual, Set<String>> i_types = new HashMap<OWLNamedIndividual, Set<String>>();
Map<OWLNamedIndividual, Set<String>> iTypesAndComplementTypes = new HashMap<OWLNamedIndividual, Set<String>>();
Set<String> all_types = new HashSet<String>();
TupleQueryResult r = (TupleQueryResult) m3.executeSPARQLQuery(""
+ "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> "
+ "select ?instance ?type where {"
+ "GRAPH <"+graph_id+"> { "
+ "?instance rdf:type <http://www.w3.org/2002/07/owl#NamedIndividual> ."
+ "?instance rdf:type ?type ."
+ "filter (?type != <http://www.w3.org/2002/07/owl#NamedIndividual> ) "
+ "{ ?instance rdf:type ?type . } UNION { ?instance rdf:type ?complement . ?complement owl:complementOf ?type . }"
+ "FILTER (isIRI(?type)) "
+ "FILTER (?type != <http://www.w3.org/2002/07/owl#NamedIndividual> ) "
+ "}}", 100);
while(r.hasNext()) {
BindingSet bs = r.next();
String instance = bs.getBinding("instance").getValue().stringValue();
String type = bs.getBinding("type").getValue().stringValue();
OWLNamedIndividual i = ont.getOWLOntologyManager().getOWLDataFactory().getOWLNamedIndividual(IRI.create(instance));
Set<String> types = i_types.get(i);
if(types==null) {
types = new HashSet<String>();
if (!iTypesAndComplementTypes.containsKey(i)) {
iTypesAndComplementTypes.put(i, new HashSet<String>());
}
Set<String> types = iTypesAndComplementTypes.get(i);
types.add(type);
i_types.put(i, types);
all_types.add(type);
}
r.close();
Expand All @@ -89,9 +89,9 @@ private void setIndTypesWithSparql(BlazegraphMolecularModelManager m3, String gr
Map<String, Set<String>> type_roots = go_lego.getSuperCategoryMap(corrected_types);
//set global
ind_types = new HashMap<OWLNamedIndividual, Set<String>>();
for(OWLNamedIndividual ind : i_types.keySet()) {
for(OWLNamedIndividual ind : iTypesAndComplementTypes.keySet()) {
//fix deprecated
Set<String> types = go_lego.replaceDeprecated(i_types.get(ind), old_new);
Set<String> types = go_lego.replaceDeprecated(iTypesAndComplementTypes.get(ind), old_new);
//convert to root types
Set<String> roots = new HashSet<String>();
for(String type : types) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
package org.geneontology.minerva.model;

import static org.junit.Assert.*;

import java.io.File;
import java.io.IOException;
import org.geneontology.minerva.BlazegraphOntologyManager;
import org.geneontology.minerva.ModelContainer;
import org.geneontology.minerva.UndoAwareMolecularModelManager;
Expand All @@ -12,92 +8,109 @@
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.openrdf.query.BindingSet;
import org.openrdf.query.MalformedQueryException;
import org.openrdf.query.QueryEvaluationException;
import org.openrdf.query.QueryResult;
import org.openrdf.query.TupleQueryResult;
import org.openrdf.repository.RepositoryException;
import org.openrdf.rio.RDFHandlerException;
import org.openrdf.rio.RDFParseException;
import org.semanticweb.owlapi.apibinding.OWLManager;
import org.semanticweb.owlapi.model.IRI;
import org.semanticweb.owlapi.model.OWLObjectProperty;
import org.semanticweb.owlapi.model.OWLOntology;
import org.semanticweb.owlapi.model.OWLOntologyCreationException;
import org.semanticweb.owlapi.model.OWLOntologyManager;

import java.io.File;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

public class GoCamModelTest {
static final String ontology_journal_file = "/tmp/test-go-lego-blazegraph.jnl";
static final String gocam_dir = "src/test/resources/validation/model_test/";
static BlazegraphOntologyManager onto_repo;
static final String ontology_journal_file = "/tmp/test-go-lego-blazegraph.jnl";
static final String gocam_dir = "src/test/resources/validation/model_test/";
static BlazegraphOntologyManager onto_repo;

@BeforeClass
public static void setUpBeforeClass() throws Exception {

@BeforeClass
public static void setUpBeforeClass() throws Exception {
}

}
@AfterClass
public static void tearDownAfterClass() throws Exception {
if (onto_repo != null) {
onto_repo.dispose();
}
}

@AfterClass
public static void tearDownAfterClass() throws Exception {
if(onto_repo!=null) {
onto_repo.dispose();
}
}
@Test
public void testRootTypesForComplements() throws Exception {
String ontologyJournalFile = "/tmp/test-go-lego-blazegraph-complements.jnl";
OWLOntologyManager man = OWLManager.createOWLOntologyManager();
OWLOntology tboxOntology = man.loadOntologyFromOntologyDocument(new File("src/test/resources/go-basic.obo"));
CurieHandler curieHandler = new MappedCurieHandler();
String inputDB = "/tmp/test-blazegraph-models-complements.jnl";
UndoAwareMolecularModelManager m3 = null;
m3 = new UndoAwareMolecularModelManager(tboxOntology, curieHandler, "gomodel", inputDB, null, ontologyJournalFile, true);
m3.importModelToDatabase(new File("src/test/resources/test-complement-roots.ttl"), true);
ModelContainer mc = m3.getModel(IRI.create("http://model.geneontology.org/61f3310500000003"));
OWLOntology gocam_via_mc = mc.getAboxOntology();
GoCamModel g = new GoCamModel(gocam_via_mc, m3);
assertTrue("Can get roots for classes and complements",
g.ind_types.get(man.getOWLDataFactory().getOWLNamedIndividual(IRI.create("http://model.geneontology.org/61f3310500000003/61f3310500000004")))
.contains("http://purl.obolibrary.org/obo/GO_0008150"));
assertTrue("Can get roots for classes and complements",
g.ind_types.get(man.getOWLDataFactory().getOWLNamedIndividual(IRI.create("http://model.geneontology.org/61f3310500000003/61f3310500000005")))
.contains("http://purl.obolibrary.org/obo/GO_0008150"));
m3.getGolego_repo().dispose();
}

@Test
public void testGoModelStats() throws Exception {
OWLOntologyManager man = OWLManager.createOWLOntologyManager();
OWLOntology tbox_ontology = man.loadOntology(IRI.create("http://purl.obolibrary.org/obo/go/extensions/go-lego.owl"));
CurieHandler curieHandler = new MappedCurieHandler();
String inputDB = "/tmp/test-blazegraph-models.jnl";
@Test
public void testGoModelStats() throws Exception {
OWLOntologyManager man = OWLManager.createOWLOntologyManager();
OWLOntology tbox_ontology = man.loadOntology(IRI.create("http://purl.obolibrary.org/obo/go/extensions/go-lego.owl"));
CurieHandler curieHandler = new MappedCurieHandler();
String inputDB = "/tmp/test-blazegraph-models.jnl";
//load it into a journal and launch an m3
UndoAwareMolecularModelManager m3 = null;
File f = new File(gocam_dir);
if(f.isDirectory()) {
//remove anything that existed from previous runs
File bgdb = new File(inputDB);
if(bgdb.exists()) {
bgdb.delete();
}
//set it up with empty db
m3 = new UndoAwareMolecularModelManager(tbox_ontology, curieHandler, "gomodel", inputDB, null, ontology_journal_file, true);
onto_repo = m3.getGolego_repo();
//load the db
for(File file : f.listFiles()) {
if(file.getName().endsWith("ttl")) {
m3.importModelToDatabase(file, true);
}
}
}
UndoAwareMolecularModelManager m3 = null;
File f = new File(gocam_dir);
if (f.isDirectory()) {
//remove anything that existed from previous runs
File bgdb = new File(inputDB);
if (bgdb.exists()) {
bgdb.delete();
}
//set it up with empty db
m3 = new UndoAwareMolecularModelManager(tbox_ontology, curieHandler, "gomodel", inputDB, null, ontology_journal_file, true);
onto_repo = m3.getGolego_repo();
//load the db
for (File file : f.listFiles()) {
if (file.getName().endsWith("ttl")) {
m3.importModelToDatabase(file, true);
}
}
}
//read it back out and check on stats
for(IRI modelIRI : m3.getAvailableModelIds()) {
ModelContainer mc = m3.getModel(modelIRI);
OWLOntology gocam_via_mc = mc.getAboxOntology();
GoCamModel g = new GoCamModel(gocam_via_mc, m3);
//testing for an issue with the OWL blazegraph loader
assertFalse("title not read out of M3 retrieved model "+modelIRI, (g.getTitle()==null));
//note these test cases from reactome contain some reactions that are not officially 'part of' the model
//these reactions are not counted as activities, but causal relations coming from them are counted.
if(modelIRI.toString().contains("R-HSA-5654719")) {
//SHC-mediated cascade:FGFR4
assertTrue("wrong n activities "+g.getStats().n_activity_units, g.getStats().n_activity_units==4);
assertTrue("wrong n complete activities "+g.getStats().n_complete_activity_units, g.getStats().n_complete_activity_units==2);
assertTrue("wrong n unenabled activities "+g.getStats().n_no_enabler, g.getStats().n_no_enabler==2);
assertTrue("wrong n causal relations "+g.getStats().n_causal_in_relation_assertions, g.getStats().n_causal_in_relation_assertions==6);
}else if(modelIRI.toString().contains("R-HSA-201688")) {
//WNT mediated activation of DVL
assertTrue("wrong n activities "+g.getStats().n_activity_units, g.getStats().n_activity_units==4);
assertTrue("wrong n complete activities "+g.getStats().n_complete_activity_units, g.getStats().n_complete_activity_units==3);
assertTrue("wrong n unenabled activities "+g.getStats().n_no_enabler, g.getStats().n_no_enabler==1);
assertTrue("wrong n causal relations "+g.getStats().n_causal_in_relation_assertions, g.getStats().n_causal_in_relation_assertions==3);
}else if(modelIRI.toString().contains("R-HSA-5654733")) {
//Negative regulation of FGFR4 signaling
assertTrue("wrong n activities "+g.getStats().n_activity_units, g.getStats().n_activity_units==3);
assertTrue("wrong n complete activities "+g.getStats().n_complete_activity_units, g.getStats().n_complete_activity_units==2);
assertTrue("wrong n unenabled activities "+g.getStats().n_no_enabler, g.getStats().n_no_enabler==1);
assertTrue("wrong n causal relations "+g.getStats().n_causal_in_relation_assertions, g.getStats().n_causal_in_relation_assertions==3);
}
}
}
for (IRI modelIRI : m3.getAvailableModelIds()) {
ModelContainer mc = m3.getModel(modelIRI);
OWLOntology gocam_via_mc = mc.getAboxOntology();
GoCamModel g = new GoCamModel(gocam_via_mc, m3);
//testing for an issue with the OWL blazegraph loader
assertFalse("title not read out of M3 retrieved model " + modelIRI, (g.getTitle() == null));
//note these test cases from reactome contain some reactions that are not officially 'part of' the model
//these reactions are not counted as activities, but causal relations coming from them are counted.
if (modelIRI.toString().contains("R-HSA-5654719")) {
//SHC-mediated cascade:FGFR4
assertTrue("wrong n activities " + g.getStats().n_activity_units, g.getStats().n_activity_units == 4);
assertTrue("wrong n complete activities " + g.getStats().n_complete_activity_units, g.getStats().n_complete_activity_units == 2);
assertTrue("wrong n unenabled activities " + g.getStats().n_no_enabler, g.getStats().n_no_enabler == 2);
assertTrue("wrong n causal relations " + g.getStats().n_causal_in_relation_assertions, g.getStats().n_causal_in_relation_assertions == 6);
} else if (modelIRI.toString().contains("R-HSA-201688")) {
//WNT mediated activation of DVL
assertTrue("wrong n activities " + g.getStats().n_activity_units, g.getStats().n_activity_units == 4);
assertTrue("wrong n complete activities " + g.getStats().n_complete_activity_units, g.getStats().n_complete_activity_units == 3);
assertTrue("wrong n unenabled activities " + g.getStats().n_no_enabler, g.getStats().n_no_enabler == 1);
assertTrue("wrong n causal relations " + g.getStats().n_causal_in_relation_assertions, g.getStats().n_causal_in_relation_assertions == 3);
} else if (modelIRI.toString().contains("R-HSA-5654733")) {
//Negative regulation of FGFR4 signaling
assertTrue("wrong n activities " + g.getStats().n_activity_units, g.getStats().n_activity_units == 3);
assertTrue("wrong n complete activities " + g.getStats().n_complete_activity_units, g.getStats().n_complete_activity_units == 2);
assertTrue("wrong n unenabled activities " + g.getStats().n_no_enabler, g.getStats().n_no_enabler == 1);
assertTrue("wrong n causal relations " + g.getStats().n_causal_in_relation_assertions, g.getStats().n_causal_in_relation_assertions == 3);
}
}
}

}
Loading

0 comments on commit 8241a3a

Please sign in to comment.