diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml
index 8494a61e..b09c8149 100644
--- a/.github/workflows/maven.yml
+++ b/.github/workflows/maven.yml
@@ -9,7 +9,7 @@ on:
- master
- dev
pull_request:
- branches:
+ branches:
- master
- dev
@@ -19,11 +19,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- - uses: actions/checkout@v2
- - name: Set up JDK 11
- uses: actions/setup-java@v2
- with:
- java-version: '11'
- distribution: 'adopt'
- - name: Build with Maven
- run: mvn test
+ - uses: actions/checkout@v2
+ - name: Set up JDK 11
+ uses: actions/setup-java@v2
+ with:
+ java-version: '11'
+ distribution: 'adopt'
+ - name: Build with Maven
+ run: mvn test
diff --git a/INSTRUCTIONS.md b/INSTRUCTIONS.md
index e3cfc017..59ef9391 100644
--- a/INSTRUCTIONS.md
+++ b/INSTRUCTIONS.md
@@ -1,24 +1,24 @@
- [About this document](#about-this-document)
- - [Building the server](#building-the-server)
- - [Prerequisites to build the code](#prerequisites-to-build-the-code)
- - [Building the Minerva Server](#building-the-minerva-server)
- - [Running the Minerva Server](#running-the-minerva-server)
- - [Prerequisites](#prerequisites)
- - [Start the MolecularModelManager server from the command line](#start-the-molecularmodelmanager-server-from-the-command-line)
- - [Start Server via Eclipse:](#start-server-via-eclipse)
- - [Running Tests](#running-tests)
- - [Failing Tests](#failing-tests)
- - [Quick Test via `curl`](#quick-test-via-curl)
- - [Sonarqube](#Sonarqube)
- - [Obtaining `owl-models` and `go-lego.owl`](#obtaining-owl-models-and-go-legoowl)
- - [Useful source files for learning](#useful-source-files-for-learning)
- - [Using the Blazegraph model store](#using-the-blazegraph-model-store)
- - [Create a new Blazegraph journal from a directory of existing model files](#create-a-new-blazegraph-journal-from-a-directory-of-existing-model-files)
- - [Dump model files from a Blazegraph journal that is not in use](#dump-model-files-from-a-blazegraph-journal-that-is-not-in-use)
- - [Start the Minerva Server with configuration for Blazegraph journal and model dump folder](#start-the-minerva-server-with-configuration-for-blazegraph-journal-and-model-dump-folder)
- - [Request an OWL dump of all models from a running Minerva Server](#request-an-owl-dump-of-all-models-from-a-running-minerva-server)
+ - [Building the server](#building-the-server)
+ - [Prerequisites to build the code](#prerequisites-to-build-the-code)
+ - [Building the Minerva Server](#building-the-minerva-server)
+ - [Running the Minerva Server](#running-the-minerva-server)
+ - [Prerequisites](#prerequisites)
+ - [Start the MolecularModelManager server from the command line](#start-the-molecularmodelmanager-server-from-the-command-line)
+ - [Start Server via Eclipse:](#start-server-via-eclipse)
+ - [Running Tests](#running-tests)
+ - [Failing Tests](#failing-tests)
+ - [Quick Test via `curl`](#quick-test-via-curl)
+ - [Sonarqube](#Sonarqube)
+ - [Obtaining `owl-models` and `go-lego.owl`](#obtaining-owl-models-and-go-legoowl)
+ - [Useful source files for learning](#useful-source-files-for-learning)
+ - [Using the Blazegraph model store](#using-the-blazegraph-model-store)
+ - [Create a new Blazegraph journal from a directory of existing model files](#create-a-new-blazegraph-journal-from-a-directory-of-existing-model-files)
+ - [Dump model files from a Blazegraph journal that is not in use](#dump-model-files-from-a-blazegraph-journal-that-is-not-in-use)
+ - [Start the Minerva Server with configuration for Blazegraph journal and model dump folder](#start-the-minerva-server-with-configuration-for-blazegraph-journal-and-model-dump-folder)
+ - [Request an OWL dump of all models from a running Minerva Server](#request-an-owl-dump-of-all-models-from-a-running-minerva-server)
@@ -30,8 +30,8 @@ This is a quick overview on how to setup a Java server for the MolecularModelMan
### Prerequisites to build the code
- * Java (JDK 1.8 or later) as compiler
- * Maven (3.0.x) Build-Tool
+* Java (JDK 1.8 or later) as compiler
+* Maven (3.0.x) Build-Tool
### Building the Minerva Server
@@ -79,8 +79,8 @@ start-m3-server.sh -c go-trunk/ontology/extensions/catalog-v001.xml \
### Automatically create a catalog file pointing to local copies of the imported ontologies
-If you have [ROBOT](http://robot.obolibrary.org) installed, you can easily create a local mirror of an OWL imports chain, so that large
-imported ontologies don't need to be repeatedly downloaded while you are developing locally:
+If you have [ROBOT](http://robot.obolibrary.org) installed, you can easily create a local mirror of an OWL imports
+chain, so that large imported ontologies don't need to be repeatedly downloaded while you are developing locally:
`robot mirror --input my-ontology.owl --directory my-cache --output my-catalog.xml`
@@ -102,7 +102,6 @@ https://raw.githubusercontent.com/evidenceontology/evidenceontology/master/gaf-e
[Maven CLI](http://maven.apache.org/ref/3.3.9/maven-embedder/cli.html)
-
### Quick Test via `curl`
This assumes you are in the `minerva/` directory, which is the parent of `minerva-server/`.
@@ -113,7 +112,8 @@ curl localhost:6800/`cat minerva-server/src/test/resources/server-test/long-get.
### Sonarqube
-Run sonarqube server locally using docker and ensure it is up and running by visiting [http://localhost:9000](http://localhost:9000)
+Run sonarqube server locally using docker and ensure it is up and running by
+visiting [http://localhost:9000](http://localhost:9000)
```
docker run -d --rm --name sonarqube -p 9000:9000 sonarqube:7.9.6-community
@@ -131,7 +131,8 @@ For static analysis and code coverage:
mvn clean package sonar:sonar
```
-Stopping sonarqube docker container. This would automatically remove the container since the --rm option was used above.
+Stopping sonarqube docker container. This would automatically remove the container since the --rm option was used
+above.
```
docker stop sonarqube
@@ -139,7 +140,8 @@ docker stop sonarqube
## Obtaining `owl-models` and `go-lego.owl`
-See [Monarch Ontology](https://github.com/monarch-initiative/monarch-ontology) and use the instructions there to generate a `catalog-v001.xml`.
+See [Monarch Ontology](https://github.com/monarch-initiative/monarch-ontology) and use the instructions there to
+generate a `catalog-v001.xml`.
- ftp://ftp.geneontology.org/pub/go//experimental/lego/server/owl-models
- ftp://ftp.geneontology.org/pub/go//ontology/extensions/go-lego.owl
@@ -148,7 +150,6 @@ See [Monarch Ontology](https://github.com/monarch-initiative/monarch-ontology) a
- `/minerva-server/src/main/java/org/geneontology/minerva/server/handler/M3BatchHandler.java`
-
## Using the Blazegraph model store
### Create a new Blazegraph journal from a directory of existing model files
@@ -163,7 +164,8 @@ See [Monarch Ontology](https://github.com/monarch-initiative/monarch-ontology) a
`java "-Xmx$MINERVA_MEMORY" -jar minerva-server.jar -c catalog-v001.xml -g http://purl.obolibrary.org/obo/go/extensions/go-lego.owl -f blazegraph.jnl --export-folder exported-models --port 9999 --use-request-logging --slme-elk --skip-class-id-validation --set-important-relation-parent http://purl.obolibrary.org/obo/LEGOREL_0000000`
-Note the options `-f blazegraph.jnl` for specifying the journal file and `--export-folder exported-models` for specifying where to write OWL models in response to a `export-all` operation request.
+Note the options `-f blazegraph.jnl` for specifying the journal file and `--export-folder exported-models` for
+specifying where to write OWL models in response to a `export-all` operation request.
### Request an OWL dump of all models from a running Minerva Server
@@ -173,9 +175,13 @@ This will output to the folder configured in the startup arguments.
### Run a SPARQL Update against the triples in the database
-*This should be handled with care since direct changes to triples will bypass any validations that typically occur when data are edited via the standard Minerva server API.*
+*This should be handled with care since direct changes to triples will bypass any validations that typically occur when
+data are edited via the standard Minerva server API.*
-[SPARQL Update](http://www.w3.org/TR/sparql11-update/) is useful for various bulk maintenance operations that may periodically be necessary, e.g. updating all uses of an obsolete property to the current preferred IRI. Before running the update, the server should be stopped, since the Blazegraph journal can only be used from one Java process at a time. Then simply run the command like this:
+[SPARQL Update](http://www.w3.org/TR/sparql11-update/) is useful for various bulk maintenance operations that may
+periodically be necessary, e.g. updating all uses of an obsolete property to the current preferred IRI. Before running
+the update, the server should be stopped, since the Blazegraph journal can only be used from one Java process at a time.
+Then simply run the command like this:
```bash
java -jar minerva-cli.jar --sparql-update -j blazegraph.jnl -f update.rq
@@ -199,8 +205,11 @@ WHERE {
## SPARQL endpoint service
-Minerva provides a read-only SPARQL query service at the `/sparql` path. Using GET, a URL-encoded query can be submitted as a value for the `query` parameter. Alternatively, POST can be used to submit form data with a `query` parameter, or to submit a SPARQL query directly, using the `application/sparql-query` MIME type.
+Minerva provides a read-only SPARQL query service at the `/sparql` path. Using GET, a URL-encoded query can be submitted
+as a value for the `query` parameter. Alternatively, POST can be used to submit form data with a `query` parameter, or
+to submit a SPARQL query directly, using the `application/sparql-query` MIME type.
### SPARQL endpoint configuration
-The only configurable aspect of the SPARQL endpoint is the query timeout. This can be set with a command-line option to the Minerva server at startup: `--sparql-endpoint-timeout 10`. The value is the time in seconds; the default is `10`.
+The only configurable aspect of the SPARQL endpoint is the query timeout. This can be set with a command-line option to
+the Minerva server at startup: `--sparql-endpoint-timeout 10`. The value is the time in seconds; the default is `10`.
diff --git a/README.md b/README.md
index f02745a5..82490bd7 100644
--- a/README.md
+++ b/README.md
@@ -8,18 +8,16 @@ To build and launch a server, see [INSTRUCTIONS.md](INSTRUCTIONS.md)
## About
-Minerva is a wrapper and server for the OWL API and a triplestore (currently
-blazegraph) that serves as the
-back end for Noctua. It communicates with Noctua via Barista. It gains
-its knowledge of the world through a Golr instance.
+Minerva is a wrapper and server for the OWL API and a triplestore (currently blazegraph) that serves as the back end for
+Noctua. It communicates with Noctua via Barista. It gains its knowledge of the world through a Golr instance.
For specifications, see [specs/](specs)
## Code
- * minerva-core : core logic
- * minerva-json : conversion to and from the JSON-LD esque transport and model exchange format
- * minerva-converter : converter to/from other formats. Primarily GAF/GPAD
- * minerva-lookup : To be deprecated? Non-generic functions for looking up genes in golr
- * minerva-server : JAX-RS server
- * minerva-cli : command line interface
+* minerva-core : core logic
+* minerva-json : conversion to and from the JSON-LD esque transport and model exchange format
+* minerva-converter : converter to/from other formats. Primarily GAF/GPAD
+* minerva-lookup : To be deprecated? Non-generic functions for looking up genes in golr
+* minerva-server : JAX-RS server
+* minerva-cli : command line interface
diff --git a/configuration.md b/configuration.md
index 2258133c..12234cf0 100644
--- a/configuration.md
+++ b/configuration.md
@@ -1,7 +1,11 @@
# Configurable Minerva options
+
This document covers some of the configurable aspects of Minerva.
## Model ID prefix
-The model ID prefix is used when constructing IRIs to name new models and individuals (which are based on their containing model ID). The default is `http://model.geneontology.org/`, however this can be changed via a command-line argument for most CLI commands and the server startup. E.g. `--model-id-prefix 'http://model.myproject.org/'`.
+
+The model ID prefix is used when constructing IRIs to name new models and individuals (which are based on their
+containing model ID). The default is `http://model.geneontology.org/`, however this can be changed via a command-line
+argument for most CLI commands and the server startup. E.g. `--model-id-prefix 'http://model.myproject.org/'`.
*TODO: check consistency of argument names across CLI commands.*
diff --git a/minerva-cli/pom.xml b/minerva-cli/pom.xml
index c7a58e9b..e579b42d 100644
--- a/minerva-cli/pom.xml
+++ b/minerva-cli/pom.xml
@@ -1,105 +1,109 @@
- 4.0.0
-
- minerva
- org.geneontology
- 0.6.1
-
- minerva-cli
- Minerva-CommandLineInterface
-
-
-
-
- pl.project13.maven
- git-commit-id-plugin
- 4.0.3
-
-
- git-commit-id
-
- revision
-
- validate
-
- false
-
- false
-
-
-
-
-
-
- org.apache.maven.plugins
- maven-shade-plugin
-
-
- package
-
- shade
-
-
-
-
- *:*
-
- META-INF/*.SF
- META-INF/*.DSA
- META-INF/*.RSA
-
-
-
- bin/minerva-cli.jar
- false
-
-
-
-
- org.geneontology.minerva.cli.CommandLineInterface
- ${git.commit.id}
- https://github.com/geneontology/minerva/commit/${git.commit.id}
- ${git.branch}
- ${git.dirty}
-
-
-
-
-
-
-
-
-
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ 4.0.0
+
+ minerva
+ org.geneontology
+ 0.6.1
+
+ minerva-cli
+ Minerva-CommandLineInterface
-
-
- org.geneontology
- minerva-converter
- ${project.parent.version}
-
-
- org.geneontology
- minerva-server
- ${project.parent.version}
-
-
- org.geneontology
- whelk_2.12
- 0.1.3
-
-
- org.obolibrary.robot
- robot-core
-
-
- org.apache.logging.log4j
- log4j-core
-
-
- org.apache.logging.log4j
- log4j-1.2-api
-
-
+
+
+
+ pl.project13.maven
+ git-commit-id-plugin
+ 4.0.3
+
+
+ git-commit-id
+
+ revision
+
+ validate
+
+ false
+
+ false
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-shade-plugin
+
+
+ package
+
+ shade
+
+
+
+
+ *:*
+
+ META-INF/*.SF
+ META-INF/*.DSA
+ META-INF/*.RSA
+
+
+
+ bin/minerva-cli.jar
+ false
+
+
+
+
+ org.geneontology.minerva.cli.CommandLineInterface
+ ${git.commit.id}
+
+ https://github.com/geneontology/minerva/commit/${git.commit.id}
+
+ ${git.branch}
+ ${git.dirty}
+
+
+
+
+
+
+
+
+
+
+
+
+ org.geneontology
+ minerva-converter
+ ${project.parent.version}
+
+
+ org.geneontology
+ minerva-server
+ ${project.parent.version}
+
+
+ org.geneontology
+ whelk_2.12
+ 0.1.3
+
+
+ org.obolibrary.robot
+ robot-core
+
+
+ org.apache.logging.log4j
+ log4j-core
+
+
+ org.apache.logging.log4j
+ log4j-1.2-api
+
+
diff --git a/minerva-cli/src/main/java/org/geneontology/minerva/cli/CommandLineInterface.java b/minerva-cli/src/main/java/org/geneontology/minerva/cli/CommandLineInterface.java
index 34aab436..aeafabca 100644
--- a/minerva-cli/src/main/java/org/geneontology/minerva/cli/CommandLineInterface.java
+++ b/minerva-cli/src/main/java/org/geneontology/minerva/cli/CommandLineInterface.java
@@ -1,46 +1,20 @@
package org.geneontology.minerva.cli;
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.io.OutputStreamWriter;
-import java.io.Writer;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.nio.charset.StandardCharsets;
-import java.nio.file.Paths;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-import java.util.Set;
-
-import org.apache.commons.cli.CommandLine;
-import org.apache.commons.cli.CommandLineParser;
-import org.apache.commons.cli.DefaultParser;
-import org.apache.commons.cli.Option;
-import org.apache.commons.cli.OptionGroup;
-import org.apache.commons.cli.Options;
-import org.apache.commons.cli.ParseException;
+import com.bigdata.rdf.sail.BigdataSail;
+import com.bigdata.rdf.sail.BigdataSailRepository;
+import com.bigdata.rdf.sail.BigdataSailRepositoryConnection;
+import com.google.common.base.Optional;
+import com.google.common.collect.Sets;
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import org.apache.commons.cli.*;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
-import org.apache.jena.rdf.model.Model;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
-import org.geneontology.minerva.BlazegraphMolecularModelManager;
-import org.geneontology.minerva.BlazegraphOntologyManager;
-import org.geneontology.minerva.CoreMolecularModelManager;
-import org.geneontology.minerva.ModelContainer;
-import org.geneontology.minerva.UndoAwareMolecularModelManager;
+import org.geneontology.minerva.*;
import org.geneontology.minerva.curie.CurieHandler;
import org.geneontology.minerva.curie.CurieMappings;
import org.geneontology.minerva.curie.DefaultCurieHandler;
@@ -50,9 +24,6 @@
import org.geneontology.minerva.json.MolecularModelJsonRenderer;
import org.geneontology.minerva.legacy.sparql.GPADData;
import org.geneontology.minerva.legacy.sparql.GPADSPARQLExport;
-import org.geneontology.minerva.lookup.GolrExternalLookupService;
-import org.geneontology.minerva.lookup.ExternalLookupService;
-import org.geneontology.minerva.lookup.ExternalLookupService.LookupEntry;
import org.geneontology.minerva.model.ActivityUnit;
import org.geneontology.minerva.model.GoCamModel;
import org.geneontology.minerva.model.GoCamModelStats;
@@ -60,15 +31,11 @@
import org.geneontology.minerva.server.inferences.InferenceProviderCreator;
import org.geneontology.minerva.server.validation.MinervaShexValidator;
import org.geneontology.minerva.util.BlazegraphMutationCounter;
-import org.geneontology.minerva.validation.Enricher;
import org.geneontology.minerva.validation.ShexValidationReport;
-import org.geneontology.minerva.validation.ShexValidator;
import org.geneontology.minerva.validation.ValidationResultSet;
import org.geneontology.minerva.validation.Violation;
import org.geneontology.minerva.validation.pipeline.BatchPipelineValidationReport;
import org.geneontology.minerva.validation.pipeline.ErrorMessage;
-import org.geneontology.whelk.owlapi.WhelkOWLReasoner;
-import org.geneontology.whelk.owlapi.WhelkOWLReasonerFactory;
import org.obolibrary.robot.CatalogXmlIRIMapper;
import org.openrdf.query.MalformedQueryException;
import org.openrdf.query.QueryLanguage;
@@ -76,1336 +43,1320 @@
import org.openrdf.repository.RepositoryException;
import org.openrdf.rio.RDFHandlerException;
import org.openrdf.rio.RDFParseException;
-import org.semanticweb.elk.owlapi.ElkReasonerFactory;
import org.semanticweb.owlapi.apibinding.OWLManager;
import org.semanticweb.owlapi.formats.TurtleDocumentFormat;
import org.semanticweb.owlapi.io.IRIDocumentSource;
-import org.semanticweb.owlapi.model.AxiomType;
-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.OWLClassAssertionAxiom;
-import org.semanticweb.owlapi.model.OWLClassExpression;
-import org.semanticweb.owlapi.model.OWLDataFactory;
-import org.semanticweb.owlapi.model.OWLDocumentFormat;
-import org.semanticweb.owlapi.model.OWLImportsDeclaration;
-import org.semanticweb.owlapi.model.OWLLiteral;
-import org.semanticweb.owlapi.model.OWLNamedIndividual;
-import org.semanticweb.owlapi.model.OWLOntology;
-import org.semanticweb.owlapi.model.OWLOntologyAlreadyExistsException;
-import org.semanticweb.owlapi.model.OWLOntologyCreationException;
-import org.semanticweb.owlapi.model.OWLOntologyIRIMapper;
-import org.semanticweb.owlapi.model.OWLOntologyManager;
-import org.semanticweb.owlapi.model.OWLOntologyStorageException;
+import org.semanticweb.owlapi.model.*;
import org.semanticweb.owlapi.reasoner.InconsistentOntologyException;
import org.semanticweb.owlapi.reasoner.OWLReasoner;
import org.semanticweb.owlapi.reasoner.OWLReasonerFactory;
import org.semanticweb.owlapi.reasoner.structural.StructuralReasonerFactory;
import org.semanticweb.owlapi.search.EntitySearcher;
import org.semanticweb.owlapi.util.InferredOntologyGenerator;
-
-import com.bigdata.rdf.sail.BigdataSail;
-import com.bigdata.rdf.sail.BigdataSailRepository;
-import com.bigdata.rdf.sail.BigdataSailRepositoryConnection;
-import com.google.common.base.Optional;
-import com.google.common.collect.Sets;
-import com.google.gson.Gson;
-import com.google.gson.GsonBuilder;
-
-import fr.inria.lille.shexjava.schema.ShexSchema;
-import fr.inria.lille.shexjava.schema.parsing.GenParser;
-import owltools.cli.Opts;
import owltools.io.ParserWrapper;
+import java.io.*;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Paths;
+import java.util.*;
+
public class CommandLineInterface {
- private static final Logger LOGGER = Logger.getLogger(CommandLineInterface.class);
-
- public static void main(String[] args) {
-
- reportSystemParams();
- Options main_options = new Options();
- OptionGroup methods = new OptionGroup();
- methods.setRequired(true);
- Option dump = Option.builder()
- .longOpt("dump-owl-models")
- .desc("export OWL GO-CAM models from journal")
- .hasArg(false)
- .build();
- methods.addOption(dump);
-
- Option merge_ontologies = Option.builder()
- .longOpt("merge-ontologies")
- .desc("Merge owl ontologies")
- .hasArg(false)
- .build();
- methods.addOption(merge_ontologies);
- Option import_owl = Option.builder()
- .longOpt("import-owl-models")
- .desc("import OWL GO-CAM models into journal")
- .hasArg(false)
- .build();
- methods.addOption(import_owl);
- Option import_tbox_ontologies = Option.builder()
- .longOpt("import-tbox-ontologies")
- .desc("import OWL tbox ontologies into journal")
- .hasArg(false)
- .build();
- methods.addOption(import_tbox_ontologies);
-
- Option add_taxon_metadata = Option.builder()
- .longOpt("add-taxon-metadata")
- .desc("add taxon associated with genes in each model as an annotation on the model")
- .hasArg(false)
- .build();
- methods.addOption(add_taxon_metadata);
-
- Option clean_gocams = Option.builder()
- .longOpt("clean-gocams")
- .desc("remove import statements, add property declarations, remove json-model annotation")
- .hasArg(false)
- .build();
- methods.addOption(clean_gocams);
-
- Option sparql = Option.builder()
- .longOpt("sparql-update")
- .desc("update the blazegraph journal with the given sparql statement")
- .hasArg(false)
- .build();
- methods.addOption(sparql);
- Option json = Option.builder()
- .longOpt("owl-lego-to-json")
- .desc("Given a GO-CAM OWL file, make its minerva json represention")
- .hasArg(false)
- .build();
- methods.addOption(json);
- Option gpad = Option.builder()
- .longOpt("lego-to-gpad-sparql")
- .desc("Given a GO-CAM journal, export GPAD representation for all the go-cams")
- .hasArg(false)
- .build();
- methods.addOption(gpad);
- Option version = Option.builder()
- .longOpt("version")
- .desc("Print the version of the minerva stack used here. Extracts this from JAR file.")
- .hasArg(false)
- .build();
- methods.addOption(version);
- Option validate = Option.builder()
- .longOpt("validate-go-cams")
- .desc("Check a collection of go-cam files or a journal for valid semantics (owl) and structure (shex)")
- .hasArg(false)
- .build();
- methods.addOption(validate);
-
- main_options.addOptionGroup(methods);
-
- CommandLineParser parser = new DefaultParser();
- try {
- CommandLine cmd = parser.parse( main_options, args, true);
-
- if(cmd.hasOption("add-taxon-metadata")) {
- Options add_taxon_options = new Options();
- add_taxon_options.addOption(add_taxon_metadata);
- add_taxon_options.addOption("j", "journal", true, "This is the go-cam journal that will be updated with taxon annotations.");
- add_taxon_options.addOption("ontojournal", "ontojournal", true, "Specify a blazegraph journal file containing the merged, pre-reasoned tbox aka go-lego.owl");
- cmd = parser.parse( add_taxon_options, args, false);
- String journalFilePath = cmd.getOptionValue("j"); //--journal
- String ontojournal = cmd.getOptionValue("ontojournal"); //--folder
- addTaxonMetaData(journalFilePath, ontojournal);
- }
-
- if(cmd.hasOption("clean-gocams")) {
- Options clean_options = new Options();
- clean_options.addOption(clean_gocams);
- clean_options.addOption("i", "input", true, "This is the directory of gocam files to clean.");
- clean_options.addOption("o", "output", true, "This is the directory of cleaned gocam files that are produced.");
- cmd = parser.parse(clean_options, args, false);
- cleanGoCams(cmd.getOptionValue("i"), cmd.getOptionValue("o"));
- }
-
- if(cmd.hasOption("import-tbox-ontologies")) {
- Options import_tbox_options = new Options();
- import_tbox_options.addOption(import_tbox_ontologies);
- import_tbox_options.addOption("j", "journal", true, "Sets the Blazegraph journal file for the database");
- import_tbox_options.addOption("f", "file", true, "Sets the input file containing the ontology to load");
- import_tbox_options.addOption("r", "reset", false, "If present, will clear out the journal, otherwise adds to it");
- cmd = parser.parse( import_tbox_options, args, false);
- String journalFilePath = cmd.getOptionValue("j"); //--journal
- String inputFile = cmd.getOptionValue("f"); //--folder
- importOWLOntologyIntoJournal(journalFilePath, inputFile, cmd.hasOption("r"));
- }
- if(cmd.hasOption("merge-ontologies")) {
- Options merge_options = new Options();
- merge_options.addOption(merge_ontologies);
- merge_options.addOption("i", "input", true, "The input folder containing ontologies to merge");
- merge_options.addOption("o", "output", true, "The file to write the ontology to");
- merge_options.addOption("u", "iri", true, "The base iri for the merged ontology");
- merge_options.addOption("r", "reason", false, "Add inferences to the merged ontology");
- cmd = parser.parse(merge_options, args, false);
- buildMergedOwlOntology(cmd.getOptionValue("i"), cmd.getOptionValue("o"), cmd.getOptionValue("u"), cmd.hasOption("r"));
- }
-
- if(cmd.hasOption("dump-owl-models")) {
- Options dump_options = new Options();
- dump_options.addOption(dump);
- dump_options.addOption("j", "journal", true, "Sets the Blazegraph journal file for the database");
- dump_options.addOption("f", "folder", true, "Sets the output folder the GO-CAM model files");
- dump_options.addOption("p", "model-id-prefix", true, "prefix for GO-CAM model ids");
- cmd = parser.parse( dump_options, args, false);
- String journalFilePath = cmd.getOptionValue("j"); //--journal
- String outputFolder = cmd.getOptionValue("f"); //--folder
- String modelIdPrefix = cmd.getOptionValue("p"); //--prefix
- modelsToOWL(journalFilePath, outputFolder, modelIdPrefix);
- }else if(cmd.hasOption("import-owl-models")) {
- Options import_options = new Options();
- import_options.addOption(import_owl);
- import_options.addOption("j", "journal", true, "Sets the Blazegraph journal file for the database");
- import_options.addOption("f", "folder", true, "Sets the input folder the GO-CAM model files");
- cmd = parser.parse( import_options, args, false);
- String journalFilePath = cmd.getOptionValue("j"); //--journal
- String outputFolder = cmd.getOptionValue("f"); //--folder
- importOWLModels(journalFilePath, outputFolder);
- }else if(cmd.hasOption("sparql-update")) {
- Options sparql_options = new Options();
- sparql_options.addOption(sparql);
- sparql_options.addOption("j", "journal", true, "Sets the Blazegraph journal file for the database");
- sparql_options.addOption("f", "file", true, "Sets the file containing a SPARQL update");
- cmd = parser.parse( sparql_options, args, false);
- String journalFilePath = cmd.getOptionValue("j"); //--journal
- String file = cmd.getOptionValue("f");
- sparqlUpdate(journalFilePath, file);
- }else if(cmd.hasOption("owl-lego-to-json")) {
- Options json_options = new Options();
- json_options.addOption(json);
- json_options.addOption("i", "OWLFile", true, "Input GO-CAM OWL file");
- json_options.addOption("o", "JSONFILE", true, "Output JSON file");
- OptionGroup format = new OptionGroup();
- Option pretty = Option.builder()
- .longOpt("pretty-json")
- .desc("pretty json format")
- .hasArg(false)
- .build();
- format.addOption(pretty);
- Option compact = Option.builder()
- .longOpt("compact-json")
- .desc("compact json format")
- .hasArg(false)
- .build();
- format.addOption(compact);
- json_options.addOptionGroup(format);
- cmd = parser.parse( json_options, args, false);
- String input = cmd.getOptionValue("i");
- String output = cmd.getOptionValue("o");
- boolean usePretty = true;
- if(cmd.hasOption("compact-json")) {
- usePretty = false;
- }
- owl2LegoJson(input, output, usePretty);
- }else if(cmd.hasOption("lego-to-gpad-sparql")) {
- Options gpad_options = new Options();
- gpad_options.addOption(gpad);
- gpad_options.addOption("i", "input", true, "Sets the Blazegraph journal file for the database");
- gpad_options.addOption("o", "gpad-output", true, "Sets the output location for the GPAD");
- gpad_options.addOption("p", "model-id-prefix", true, "prefix for GO-CAM model ids");
- gpad_options.addOption("c", "model-id-curie", true, "prefix for GO-CAM curies");
- gpad_options.addOption("ont", "ontology", true, "IRI of tbox ontology for classification - usually default go-lego.owl");
- gpad_options.addOption("cat", "catalog", true, "Catalog file for tbox ontology. " +
- "Use this to specify local copies of the ontology and or its imports to " +
- "speed and control the process. If not used, will download the tbox and all its imports.");
- gpad_options.addOption("ontojournal", "ontojournal", true, "Specify a blazegraph journal file containing the merged, pre-reasoned tbox aka go-lego.owl");
- cmd = parser.parse(gpad_options, args, false);
- String inputDB = cmd.getOptionValue("input");
- String gpadOutputFolder = cmd.getOptionValue("gpad-output");
- String modelIdPrefix = cmd.getOptionValue("model-id-prefix");
- String modelIdcurie = cmd.getOptionValue("model-id-curie");
- String ontologyIRI = cmd.getOptionValue("ontology");
- String catalog = cmd.getOptionValue("catalog");
- String go_lego_journal_file = null;
- if(cmd.hasOption("ontojournal")) {
- go_lego_journal_file = cmd.getOptionValue("ontojournal");
- }
- if(go_lego_journal_file==null) {
- System.err.println("Missing -- ontojournal . Need to specify location for blazegraph journal file containing the merged go-lego tbox (neo, GO-plus, etc..). If a journal does not exist at that location, the tbox ontology will be used to initialize one.");
- System.exit(-1);
- }
- legoToAnnotationsSPARQL(modelIdPrefix, modelIdcurie, inputDB, gpadOutputFolder, ontologyIRI, catalog, go_lego_journal_file);
- }else if(cmd.hasOption("version")) {
- printVersion();
- }else if(cmd.hasOption("validate-go-cams")) {
- Options validate_options = new Options();
- validate_options.addOption(validate);
- validate_options.addOption("i", "input", true, "Either a blazegraph journal or a folder with go-cams in it");
- validate_options.addOption("shex", "shex", false, "If present, will execute shex validation");
- validate_options.addOption("owl", "owl", false, "If present, will execute shex validation");
- validate_options.addOption("r", "report-folder", true, "Folder where output files will appear");
- validate_options.addOption("p", "model-id-prefix", true, "prefix for GO-CAM model ids");
- validate_options.addOption("cu", "model-id-curie", true, "prefix for GO-CAM curies");
- validate_options.addOption("ont", "ontology", true, "IRI of tbox ontology - usually default go-lego.owl");
- validate_options.addOption("c", "catalog", true, "Catalog file for tbox ontology. "
- + "Use this to specify local copies of the ontology and or its imports to "
- + "speed and control the process. If not used, will download the tbox and all its imports.");
- validate_options.addOption("shouldfail", "shouldfail", false, "When used in travis mode for tests, shouldfail "
- + "parameter will allow a successful run on a folder that only contains incorrect models.");
- validate_options.addOption("t", "travis", false, "If travis, then the program will stop upon a failed "
- + "validation and report an error. Otherwise it will continue to test all the models.");
- validate_options.addOption("m", "shapemap", true, "Specify a shapemap file. Otherwise will download from go_shapes repo.");
- validate_options.addOption("s", "shexpath", true, "Specify a shex schema file. Otherwise will download from go_shapes repo.");
- validate_options.addOption("ontojournal", "ontojournal", true, "Specify a blazegraph journal file containing the merged, pre-reasoned tbox aka go-lego.owl");
- validate_options.addOption("reasoner_report", "reasoner_report", false, "Add a report with reasoning results to the output of the validation. ");
-
-
- cmd = parser.parse(validate_options, args, false);
- String input = cmd.getOptionValue("input");
- String outputFolder = cmd.getOptionValue("report-folder");
- String shexpath = cmd.getOptionValue("s");
- String shapemappath = cmd.getOptionValue("shapemap");
-
- String ontologyIRI = "http://purl.obolibrary.org/obo/go/extensions/go-lego.owl";
- if(cmd.hasOption("ontology")) {
- ontologyIRI = cmd.getOptionValue("ontology");
- }
- String catalog = cmd.getOptionValue("catalog");
- String modelIdPrefix = "http://model.geneontology.org/";
- if(cmd.hasOption("model-id-prefix")) {
- modelIdPrefix = cmd.getOptionValue("model-id-prefix");
- }
- String modelIdcurie = "gomodel";
- if(cmd.hasOption("model-id-curie")) {
- modelIdcurie = cmd.getOptionValue("model-id-curie");
- }
- boolean travisMode = false;
- if(cmd.hasOption("travis")) {
- travisMode = true;
- }
- boolean shouldFail = false;
- if(cmd.hasOption("shouldfail")) {
- shouldFail = true;
- }
- boolean checkShex = false;
- if(cmd.hasOption("shex")) {
- checkShex = true;
- }
- String go_lego_journal_file = null;
- if(cmd.hasOption("ontojournal")) {
- go_lego_journal_file = cmd.getOptionValue("ontojournal");
- }
- if(go_lego_journal_file==null) {
- System.err.println("Missing -- ontojournal . Need to specify blazegraph journal file containing the merged go-lego tbox (neo, GO-plus, etc..)");
- System.exit(-1);
- }
- boolean run_reasoner_report = false;
- if(cmd.hasOption("reasoner_report")) {
- run_reasoner_report = true;
- }
- validateGoCams(input, outputFolder, ontologyIRI, catalog, modelIdPrefix, modelIdcurie, shexpath, shapemappath, travisMode, shouldFail, checkShex, go_lego_journal_file, run_reasoner_report);
- }
- }catch( ParseException exp ) {
- System.out.println( "Parameter parse exception. Note that the first parameter must be one of: "
- + "[--validate-go-cams, --dump-owl-models, --import-owl-models, --sparql-update, --owl-lego-to-json, --lego-to-gpad-sparql, --version, --update-gene-product-types]"
- + "\nSubsequent parameters are specific to each top level command. "
- + "\nError message: " + exp.getMessage() );
- System.exit(-1);
- } catch (Exception e) {
- e.printStackTrace();
- //explicitly exiting to inform travis of failure.
- System.exit(-1);
- }
- }
-
- /**
- * Given a blazegraph journal with go-cams in it, write them all out as OWL files.
- * cli --dump-owl-models
- * @param journalFilePath
- * @param outputFolder
- * @param modelIdPrefix
- * @throws Exception
- */
- public static void modelsToOWL(String journalFilePath, String outputFolder, String modelIdPrefix) throws Exception {
- if(modelIdPrefix==null) {
- modelIdPrefix = "http://model.geneontology.org/";
- }
-
- // minimal inputs
- if (journalFilePath == null) {
- System.err.println("No journal file was configured.");
- System.exit(-1);
- return;
- }
- if (outputFolder == null) {
- System.err.println("No output folder was configured.");
- System.exit(-1);
- return;
- }
-
- OWLOntology dummy = OWLManager.createOWLOntologyManager().createOntology(IRI.create("http://example.org/dummy"));
- CurieHandler curieHandler = new MappedCurieHandler();
- BlazegraphMolecularModelManager m3 = new BlazegraphMolecularModelManager<>(dummy, curieHandler, modelIdPrefix, journalFilePath, outputFolder, null, false);
- m3.dumpAllStoredModels();
- m3.dispose();
- }
-
- /**
- * Load the go-cam files in the input folder into the journal
- * cli import-owl-models
- * @param journalFilePath
- * @param inputFolder
- * @throws Exception
- */
- public static void importOWLModels(String journalFilePath, String inputFolder) throws Exception {
- // minimal inputs
- if (journalFilePath == null) {
- System.err.println("No journal file was configured.");
- System.exit(-1);
- return;
- }
- if (inputFolder == null) {
- System.err.println("No input folder was configured.");
- System.exit(-1);
- return;
- }
- int total_files = 0;
- OWLOntology dummy = OWLManager.createOWLOntologyManager().createOntology(IRI.create("http://example.org/dummy"));
- String modelIdPrefix = "http://model.geneontology.org/"; // this will not be used for anything
- CurieHandler curieHandler = new MappedCurieHandler();
- BlazegraphMolecularModelManager m3 = new BlazegraphMolecularModelManager<>(dummy, curieHandler, modelIdPrefix, journalFilePath, null, null, false);
- //in case of update rather than whole new journal
- Set stored = new HashSet(m3.getStoredModelIds());
- LOGGER.info("loading gocams from "+inputFolder);
- //for (File file : FileUtils.listFiles(new File(inputFolder), null, true)) {
- File i = new File(inputFolder);
- if(i.exists()) {
- if(i.isDirectory()) {
- total_files = i.listFiles().length;
- FileUtils.listFiles(i, null, true).parallelStream().parallel().forEach(file-> {
- if(file.getName().endsWith("ttl")){
- java.util.Optional irio;
- try {
- irio = m3.scanForOntologyIRI(file);
- IRI iri = null;
- if(irio.isPresent()) {
- iri = IRI.create(irio.get());
- }
- //is it in there already?
- if(stored.contains(iri)) {
- LOGGER.error("Attempted to load gocam ttl file into database but gocam with that iri already exists, skipping "+ file+" "+iri);
- }else {
- stored.add(iri);
- m3.importModelToDatabase(file, true);
- }
- } catch (RDFParseException | RDFHandlerException | IOException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- } catch (OWLOntologyCreationException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (RepositoryException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }else {
- LOGGER.info("Ignored for not ending with .ttl" + file);
- }
- });
- }}
- m3.dispose();
- LOGGER.info("done loading gocams, loaded: "+stored.size()+" out of: "+total_files+" files");
- }
-
- /**
- *
- * @param journalFilePath
- * @param inputFolder
- * @throws Exception
- */
- public static void buildMergedOwlOntology(String inputFolder, String outputfile, String base_iri, boolean addInferences) throws Exception {
- // minimal inputs
- if (outputfile == null) {
- System.err.println("No output file was configured.");
- System.exit(-1);
- return;
- }
- if (inputFolder == null) {
- System.err.println("No input folder was configured.");
- System.exit(-1);
- return;
- }
- if (base_iri == null) {
- System.err.println("No base iri was configured.");
- System.exit(-1);
- return;
- }
- OWLOntologyManager ontman = OWLManager.createOWLOntologyManager();
- OWLDataFactory df = ontman.getOWLDataFactory();
- OWLOntology merged = ontman.createOntology(IRI.create(base_iri));
- for (File file : FileUtils.listFiles(new File(inputFolder), null, true)) {
- LOGGER.info("Loading " + file);
- if(file.getName().endsWith("ttl")||file.getName().endsWith("owl")) {
- try {
- OWLOntology ont = ontman.loadOntologyFromOntologyDocument(file);
- ontman.addAxioms(merged, ont.getAxioms());
- }catch(OWLOntologyAlreadyExistsException e) {
- LOGGER.error("error loading already loaded ontology: "+file);
- }
- } else {
- LOGGER.info("Ignored for not ending with .ttl or .owl " + file);
- }
- }
- if(addInferences) {
- LOGGER.info("Running reasoner");
- //OWLReasonerFactory reasonerFactory = new WhelkOWLReasonerFactory();
- //WhelkOWLReasoner reasoner = (WhelkOWLReasoner)reasonerFactory.createReasoner(merged);
- OWLReasonerFactory reasonerFactory = new StructuralReasonerFactory();
- OWLReasoner reasoner = reasonerFactory.createReasoner(merged);
- InferredOntologyGenerator gen = new InferredOntologyGenerator(reasoner);
- gen.fillOntology(df, merged);
- }
- try {
- ontman.saveOntology(merged, new FileOutputStream(new File(outputfile)));
- } catch (OWLOntologyStorageException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (FileNotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
-
- /**
- * Load the go-cam files in the input folder into the journal
- * cli import-owl-models
- * @param journalFilePath
- * @param inputFolder
- * @throws Exception
- */
- public static void importOWLOntologyIntoJournal(String journalFilePath, String inputFile, boolean reset) throws Exception {
- // minimal inputs
- if (journalFilePath == null) {
- System.err.println("No journal file was configured.");
- System.exit(-1);
- return;
- }
- if (inputFile == null) {
- System.err.println("No input file was configured.");
- System.exit(-1);
- return;
- }
-
- BlazegraphOntologyManager man = new BlazegraphOntologyManager(journalFilePath, false);
- String iri_for_ontology_graph = "http://geneontology.org/go-lego-graph";
- man.loadRepositoryFromOWLFile(new File(inputFile), iri_for_ontology_graph, reset);
- }
-
- /**
- * Updates the journal with the provided update sparql statement.
- * cli parameter --sparql-update
- * @param journalFilePath
- * @param updateFile
- * @throws OWLOntologyCreationException
- * @throws IOException
- * @throws RepositoryException
- * @throws MalformedQueryException
- * @throws UpdateExecutionException
- */
- public static void sparqlUpdate(String journalFilePath, String updateFile) throws OWLOntologyCreationException, IOException, RepositoryException, MalformedQueryException, UpdateExecutionException {
- // minimal inputs
- if (journalFilePath == null) {
- System.err.println("No journal file was configured.");
- System.exit(-1);
- return;
- }
- if (updateFile == null) {
- System.err.println("No update file was configured.");
- System.exit(-1);
- return;
- }
-
- String update = FileUtils.readFileToString(new File(updateFile), StandardCharsets.UTF_8);
- Properties properties = new Properties();
- properties.load(CommandLineInterface.class.getResourceAsStream("/org/geneontology/minerva/blazegraph.properties"));
- properties.setProperty(com.bigdata.journal.Options.FILE, journalFilePath);
-
- BigdataSail sail = new BigdataSail(properties);
- BigdataSailRepository repository = new BigdataSailRepository(sail);
- repository.initialize();
- BigdataSailRepositoryConnection conn = repository.getUnisolatedConnection();
- BlazegraphMutationCounter counter = new BlazegraphMutationCounter();
- conn.addChangeLog(counter);
- conn.prepareUpdate(QueryLanguage.SPARQL, update).execute();
- int changes = counter.mutationCount();
- conn.removeChangeLog(counter);
- System.out.println("\nApplied " + changes + " changes");
- conn.close();
- }
-
- /**
- * 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()));
- InferenceProvider inferenceProvider = null; // TODO decide if we need reasoning
- String modelId = null;
- Optional 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);
- }
- }
-
- /**
- * Output GPAD files via inference+SPARQL
- * cli --lego-to-gpad-sparql
- * @param modelIdPrefix
- * @param modelIdcurie
- * @param inputDB
- * @param gpadOutputFolder
- * @param ontologyIRI
- * @throws Exception
- */
- public static void legoToAnnotationsSPARQL(String modelIdPrefix, String modelIdcurie, String inputDB, String gpadOutputFolder, String ontologyIRI, String catalog, String go_lego_journal_file) throws Exception {
- if(modelIdPrefix==null) {
- modelIdPrefix = "http://model.geneontology.org/";
- }
- if(modelIdcurie==null) {
- modelIdcurie = "gomodel";
- }
- if(inputDB==null) {
- inputDB = "blazegraph.jnl";
- }
- if(gpadOutputFolder==null) {
- gpadOutputFolder = null;
- }
- if(ontologyIRI==null) {
- ontologyIRI = "http://purl.obolibrary.org/obo/go/extensions/go-lego.owl";
- }
- OWLOntologyManager ontman = OWLManager.createOWLOntologyManager();
- if(catalog!=null) {
- LOGGER.info("using catalog: "+catalog);
- ontman.setIRIMappers(Sets.newHashSet(new owltools.io.CatalogXmlIRIMapper(catalog)));
- }else {
- LOGGER.info("no catalog, resolving all ontology uris directly");
- }
-
- OWLOntology ontology = ontman.loadOntology(IRI.create(ontologyIRI));
- CurieMappings localMappings = new CurieMappings.SimpleCurieMappings(Collections.singletonMap(modelIdcurie, modelIdPrefix));
- CurieHandler curieHandler = new MappedCurieHandler(DefaultCurieHandler.loadDefaultMappings(), localMappings);
- boolean loadTboxIntoOntJournal = (!(new File(go_lego_journal_file)).exists());
- BlazegraphMolecularModelManager m3 = new BlazegraphMolecularModelManager<>(ontology, curieHandler, modelIdPrefix, inputDB, null, go_lego_journal_file, false);
- if (loadTboxIntoOntJournal) {
- m3.getGolego_repo().loadRepositoryFromOntology(ontology, "http://example.org/", true);
- }
- final String immutableModelIdPrefix = modelIdPrefix;
- final String immutableGpadOutputFolder = gpadOutputFolder;
- m3.getAvailableModelIds().stream().parallel().forEach(modelIRI -> {
- try {
- //TODO investigate whether changing to a neo-lite model has an impact on this - may need to make use of ontology journal
- String gpad = new GPADSPARQLExport(curieHandler, m3.getLegacyRelationShorthandIndex(), m3.getTboxShorthandIndex(), m3.getGolego_repo().regulatorsToRegulated).exportGPAD(m3.createInferredModel(modelIRI), modelIRI);
- String fileName = StringUtils.replaceOnce(modelIRI.toString(), immutableModelIdPrefix, "") + ".gpad";
- Writer writer = new OutputStreamWriter(new FileOutputStream(Paths.get(immutableGpadOutputFolder, fileName).toFile()), StandardCharsets.UTF_8);
- writer.write(gpad);
- writer.close();
- } catch (InconsistentOntologyException e) {
- LOGGER.error("Inconsistent ontology: " + modelIRI);
- } catch (IOException e) {
- LOGGER.error("Couldn't export GPAD for: " + modelIRI, e);
- }
- });
- m3.dispose();
- }
-
-
- /**
- * --validate-go-cams
- * -i /GitHub/GO_Shapes/test_ttl/go_cams/should_pass/
- * -c ./catalog-no-import.xml
- * @param input
- * @param basicOutputFile
- * @param explanationOutputFile
- * @param ontologyIRI
- * @param catalog
- * @param modelIdPrefix
- * @param modelIdcurie
- * @param shexpath
- * @param shapemappath
- * @param travisMode
- * @param shouldPass
- * @throws IOException
- * @throws OWLOntologyCreationException
- */
- public static void validateGoCams(String input, String outputFolder,
- String ontologyIRI, String catalog, String modelIdPrefix, String modelIdcurie,
- String shexpath, String shapemappath, boolean travisMode, boolean shouldFail, boolean checkShex,
- String go_lego_journal_file, boolean run_reasoner_report) throws OWLOntologyCreationException, IOException {
- LOGGER.setLevel(Level.INFO);
- String inputDB = "blazegraph.jnl";
- String shexFileUrl = "https://raw.githubusercontent.com/geneontology/go-shapes/master/shapes/go-cam-shapes.shex";
- String goshapemapFileUrl = "https://raw.githubusercontent.com/geneontology/go-shapes/master/shapes/go-cam-shapes.shapeMap";
- CurieMappings localMappings = new CurieMappings.SimpleCurieMappings(Collections.singletonMap(modelIdcurie, modelIdPrefix));
- CurieHandler curieHandler = new MappedCurieHandler(DefaultCurieHandler.loadDefaultMappings(), localMappings);
- Map modelid_filename = new HashMap();
-
- if(outputFolder==null) {
- LOGGER.error("please specify an output folder with -r ");
- System.exit(-1);
- }else if(!outputFolder.endsWith("/")) {
- outputFolder+="/";
- }
-
- if(input==null) {
- LOGGER.error("please provide an input file - either a directory of ttl files or a blazegraph journal");
- System.exit(-1);
- }
-
- LOGGER.info("loading tbox ontology: "+ontologyIRI);
- OWLOntologyManager ontman = OWLManager.createOWLOntologyManager();
- if(catalog!=null) {
- LOGGER.info("using catalog: "+catalog);
- try {
- ontman.setIRIMappers(Sets.newHashSet(new CatalogXmlIRIMapper(catalog)));
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }else {
- LOGGER.info("no catalog, resolving all ontology uris directly");
- }
-
- OWLOntology tbox_ontology = null;
- try {
- tbox_ontology = ontman.loadOntology(IRI.create(ontologyIRI));
- LOGGER.info("tbox ontology axioms loaded: "+tbox_ontology.getAxiomCount());
- } catch (OWLOntologyCreationException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- }
- //either load directly from existing journal
- if(input.endsWith(".jnl")) {
- inputDB = input;
- }else {
- //or make sure that the journal file provided is cleared out and ready
- File i = new File(input);
- if(i.exists()) {
- //remove anything that existed earlier
- File bgdb = new File(inputDB);
- if(bgdb.exists()) {
- bgdb.delete();
- }
- }
- }
- //make the manager
- LOGGER.info("Setting up model manager and initializing rules for Arachne reasoner");
- UndoAwareMolecularModelManager m3 = new UndoAwareMolecularModelManager(tbox_ontology, curieHandler, modelIdPrefix, inputDB, null, go_lego_journal_file, true);
- //if provided a directory as input, load them ttl files into the manager
- File i = new File(input);
- if(i.exists()&&!input.endsWith(".jnl")) {
- if(i.isDirectory()) {
- LOGGER.info("Loading models from " + i.getAbsolutePath());
- Set model_iris = new HashSet();
- FileUtils.listFiles(i, null, true).parallelStream().parallel().forEach(file-> {
- if(file.getName().endsWith(".ttl")||file.getName().endsWith("owl")) {
- try {
- String modeluri = m3.importModelToDatabase(file, true);
- if(modeluri==null) {
- LOGGER.error("Null model IRI: "+modeluri+" file: "+file);
- }
- else if(!model_iris.add(modeluri)) {
- LOGGER.error("Multiple models with same IRI: "+modeluri+" file: "+file+" file: "+modelid_filename.get(modeluri));
- }else {
- modelid_filename.put(modeluri, file.getName());
- }
- } catch (OWLOntologyCreationException | RepositoryException | RDFParseException
- | RDFHandlerException | IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- });
- }else {//just load the one provided
- LOGGER.info("Loading " + i);
- try {
- m3.importModelToDatabase(i, true);
- } catch (OWLOntologyCreationException | RepositoryException | RDFParseException
- | RDFHandlerException | IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- LOGGER.info("loaded files into blazegraph journal: "+input);
- }
- //models ready
- //now set up shex validator
- if(shexpath==null) {
- //fall back on downloading from shapes repo
- URL shex_schema_url;
- try {
- shex_schema_url = new URL(shexFileUrl);
- shexpath = "./go-cam-schema.shex";
- File shex_schema_file = new File(shexpath);
- org.apache.commons.io.FileUtils.copyURLToFile(shex_schema_url, shex_schema_file);
- System.err.println("-s .No shex schema provided, using: "+shexFileUrl);
- } catch (MalformedURLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- if(shapemappath==null) {
- URL shex_map_url;
- try {
- shex_map_url = new URL(goshapemapFileUrl);
- shapemappath = "./go-cam-shapes.shapeMap";
- File shex_map_file = new File(shapemappath);
- org.apache.commons.io.FileUtils.copyURLToFile(shex_map_url, shex_map_file);
- System.err.println("-m .No shape map file provided, using: "+goshapemapFileUrl);
- } catch (MalformedURLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- LOGGER.info("making shex validator: "+shexpath+" "+shapemappath+" "+curieHandler+" ");
- MinervaShexValidator shex = null;
- try {
- shex = new MinervaShexValidator(shexpath, shapemappath, curieHandler, m3.getGolego_repo());
- } catch (Exception e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- }
-
- if(checkShex) {
- shex.setActive(true);
- }else {
- shex.setActive(false);
- }
-
- //shex validator is ready, now build the inference provider (which provides access to the shex validator and provides inferences useful for shex)
- String reasonerOpt = "arachne";
- LOGGER.info("Building OWL inference provider: "+reasonerOpt);
- InferenceProviderCreator ipc = StartUpTool.createInferenceProviderCreator(reasonerOpt, m3, shex);
- LOGGER.info("Validating models: "+reasonerOpt);
-
- //Set up all the report files.
- String basic_output_file = outputFolder+"main_report.txt";
- String explanations_file = outputFolder+"explanations.txt";
- String activity_output_file = outputFolder+"activity_report.txt";
- if(outputFolder!=null) {
- try {
- //valid or not
- FileWriter basic_shex_output = new FileWriter(basic_output_file, false);
- basic_shex_output.write("filename\tmodel_title\tmodel_url\tmodelstate\tcontributor\tprovider\tdate\tOWL_consistent\tshex_valid\tshex_meta_problem\tshex_data_problem\tvalidation_time_milliseconds\taxioms\tn_rows_gpad\t");
- basic_shex_output.write(GoCamModelStats.statsHeader()+"\n");
- basic_shex_output.close();
- //tab delimited explanations for failures
- FileWriter explanations = new FileWriter(explanations_file, false);
- explanations.write("filename\tmodel_title\tmodel_iri\tnode\tNode_types\tproperty\tIntended_range_shapes\tobject\tObject_types\tObject_shapes\n");
- explanations.close();
- //tab delimited summary of properties of activity units
- FileWriter activity_output = new FileWriter(activity_output_file, false);
- activity_output.write("filename\tmodel_title\tmodel_url\tmodelstate\tcontributor\tprovider\tdate\tactivity_iri\tactivity_xref\tactivity_label\tcomplete\tinputs\toutputs\tenablers\tlocations\tcausal upstream\tcausal downstream\tpart of n BP\tMF\tBP\n");
- activity_output.close();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- //this will generate the json file used for the go rules report for the pipeline
- BatchPipelineValidationReport pipe_report = null;
- Set owl_errors = new HashSet();
- Set shex_errors = new HashSet();
- pipe_report = new BatchPipelineValidationReport();
- try {
- pipe_report.setNumber_of_models(m3.getAvailableModelIds().size());
- } catch (IOException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- }
- int bad_models = 0; int good_models = 0;
- final boolean shex_output = checkShex;
-
- //only used if OWL reasoning report is requested
- ReasonerReport reasoner_report = null;
- if(run_reasoner_report) {
- reasoner_report = initReasonerReport(outputFolder);
- }
- //now process each gocam
- try {
- for(IRI modelIRI : m3.getAvailableModelIds()) {
- long start = System.currentTimeMillis();
- String filename = modelid_filename.get(modelIRI.toString());
- boolean isConsistent = true; //OWL
- boolean isConformant = true; //shex
- if(filename !=null) {
- LOGGER.info("processing "+filename+"\t"+modelIRI);
- }else {
- LOGGER.info("processing \t"+modelIRI);
- }
- //this is where everything actually happens
- ModelContainer mc = m3.getModel(modelIRI);
- OWLOntology gocam = mc.getAboxOntology();
- try {
- //if a model does not have an import statement that links in an ontology that defines all of its classes and object properties
- //or if the model does not define the classes and object properties itself, parsing problems will prevail
- //this step makes sure that does not happen
- gocam = CoreMolecularModelManager.fixBrokenObjectPropertiesAndAxioms(gocam);
- } catch (OWLOntologyCreationException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- LOGGER.info("preparing model stats...");
- //The GoCamModel code is used to capture model-level statistics such as 'how many causal relations are there?'
- //This might be an area for a speed improvement if needed
- GoCamModel gcm = new GoCamModel(gocam, m3);
- String title = "title";
- if(gcm.getTitle()!=null) {
- title = makeColSafe(gcm.getTitle());
- }else {
- LOGGER.error("no title for "+filename);
- }
- //this is to make clickable links in reports
- String link = modelIRI.toString().replace("http://model.geneontology.org/", "http://noctua.geneontology.org/editor/graph/gomodel:");
- if(modelIRI.toString().contains("R-HSA")) {
- link = link.replace("noctua.geneontology", "noctua-dev.berkeleybop");
- }
- String modelstate = makeColSafe(gcm.getModelstate());
- String contributor = makeColSafe(gcm.getContributors().toString());
- String date = makeColSafe(gcm.getDate());
- String provider = makeColSafe(gcm.getProvided_by().toString());
- pipe_report.setTaxa(gcm.getIn_taxon());
- LOGGER.info("model stats done for title: "+title);
- int axioms = gocam.getAxiomCount();
- //add activity level statistics as a default
- FileWriter activity_output = new FileWriter(activity_output_file, true);
- for(ActivityUnit unit : gcm.getActivities()){
- activity_output.write(filename+"\t"+title+"\t"+link+"\t"+modelstate+"\t"+contributor+"\t"+provider+"\t"+date+"\t"+unit.getIndividual().getIRI().toString()+"\t"+unit.getXref()+"\t"+unit.getLabel()+"\t");
- activity_output.write(unit.isComplete()+"\t"+unit.getInputs().size()+"\t"+unit.getOutputs().size()+"\t"+unit.getEnablers().size()+"\t"+unit.getLocations().size()+
- "\t"+unit.getCausal_in().size()+"\t"+unit.getCausal_out().size()+"\t"+unit.getContaining_processes().size()+"\t"+unit.stringForClasses(unit.getDirect_types())+"\t"+unit.getURIsForConnectedBPs()+"\n");
- }
- activity_output.close();
-
- InferenceProvider ip = ipc.create(mc);
- isConsistent = ip.isConsistent();
- //TODO re-use reasoner object from ip
- //TODO this is another area that could be touched/removed for speed improvement
- int n_rows_gpad = 0;
- if(isConsistent) {
- try {
- Set gpad = new GPADSPARQLExport(curieHandler, m3.getLegacyRelationShorthandIndex(), m3.getTboxShorthandIndex(), m3.getGolego_repo().regulatorsToRegulated).getGPAD(m3.createInferredModel(modelIRI), modelIRI);
- if(gpad!=null) {
- n_rows_gpad = gpad.size();
- }
- }catch(InconsistentOntologyException e) {
- LOGGER.error("inconsistent ontology, can't make gpad");
- }
- }
- long done = System.currentTimeMillis();
- long milliseconds = (done-start);
- //for rules report in pipeline
- if(!ip.isConsistent()) {
- String level = "ERROR";
- String model_id = curieHandler.getCuri(modelIRI);
- String message = BatchPipelineValidationReport.getOwlMessage();
- int rule = BatchPipelineValidationReport.getOwlRule();
- ErrorMessage owl = new ErrorMessage(level, model_id, gcm.getIn_taxon(), message, rule);
- owl_errors.add(owl);
- }
- if(!isConsistent) {
- FileWriter explanations = new FileWriter(explanations_file, true);
- explanations.write(filename+"\t"+title+"\t"+modelIRI+"\tOWL fail explanation: "+ip.getValidation_results().getOwlvalidation().getAsText()+"\n");
- explanations.close();
- }
- //travis mode causes the system to exit when an invalid model is detected (unless shouldFail is on)
- if(travisMode&&!isConsistent) {
- if(!shouldFail) {
- LOGGER.error(filename+"\t"+title+"\t"+modelIRI+"\tOWL:is inconsistent, quitting");
- System.exit(-1);
- }
- }
- //basic is just one row per model - did it validate or not
- FileWriter basic= new FileWriter(basic_output_file, true);
- if(!shex_output) {
- if(ip.isConsistent()) {
- good_models++;
- }else {
- bad_models++;
- }
- }else{
- ValidationResultSet validations = ip.getValidation_results();
- isConformant = validations.allConformant();
- if(isConformant) {
- good_models++;
- }else {
- bad_models++;
- }
- if(!validations.getShexvalidation().isConformant()) {
- String level = "WARNING";
- String model_id = curieHandler.getCuri(modelIRI);
- String message = BatchPipelineValidationReport.getShexMessage();
- int rule = BatchPipelineValidationReport.getShexRule();
- ErrorMessage shex_message = new ErrorMessage(level, model_id, gcm.getIn_taxon(), message, rule);
- boolean include_explanations_in_json = true; //TODO set as a parameter
- if(include_explanations_in_json) {
- shex_message.setExplanations(validations);
- }
- shex_errors.add(shex_message);
- FileWriter explanations = new FileWriter(explanations_file, true);
- explanations.write(ip.getValidation_results().getShexvalidation().getAsTab(filename+"\t"+title+"\t"+modelIRI));
- explanations.close();
- }
- if(travisMode) {
- if(!isConformant&&!shouldFail) {
- LOGGER.error(filename+"\t"+title+"\t"+modelIRI+"\tshex is nonconformant, quitting, explanation:\n"+ip.getValidation_results().getShexvalidation().getAsText());
- System.exit(-1);
- }else if(isConformant&&shouldFail) {
- LOGGER.error(filename+"\t"+title+"\t"+modelIRI+"\tshex validates, but it should not be, quitting");
- System.exit(-1);
- }
- }
- //is it a metadata violation or data ?
- boolean shex_meta_problem = false;
- boolean shex_data_problem = false;
- if(!validations.getShexvalidation().isConformant()) {
- String model_curie = curieHandler.getCuri(modelIRI);
- ValidationResultSet validationset = ip.getValidation_results();
- ShexValidationReport shex_report = validationset.getShexvalidation();
- Set violations = shex_report.getViolations();
- if(violations!=null) {
- for(Violation v : violations) {
- if(v.getNode().equals(model_curie)){
- shex_meta_problem = true;
- }else {
- shex_data_problem = true;
- }
- }
- }else {
- LOGGER.error("Invalid model but no violations reported");
- }
- }
- LOGGER.info(filename+"\t"+title+"\t"+modelIRI+"\tOWL:"+isConsistent+"\tshex:"+isConformant);
- basic.write(filename+"\t"+title+"\t"+link+"\t"+modelstate+"\t"+contributor+"\t"+provider+"\t"+date+"\t"+isConsistent+"\t"+isConformant+"\t"+shex_meta_problem+"\t"+shex_data_problem+"\t"+milliseconds+"\t"+axioms+"\t"+
- n_rows_gpad+"\t"+ gcm.getGoCamModelStats().stats2cols()+"\n");
- }
- basic.close();
- if(run_reasoner_report) {
- addReasonerReport(outputFolder, gocam, ip, title, reasoner_report);
- }
- }
- } catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- if(run_reasoner_report) {
- summarizeReasonerReport(outputFolder, reasoner_report);
- }
-
- pipe_report.setNumber_of_correct_models(good_models);
- pipe_report.setNumber_of_models_in_error(bad_models);
- pipe_report.getMessages().put(BatchPipelineValidationReport.getShexRuleString(), shex_errors);
- pipe_report.getMessages().put(BatchPipelineValidationReport.getOwlRuleString(), owl_errors);
- GsonBuilder builder = new GsonBuilder();
- Gson gson = builder.setPrettyPrinting().create();
- String json = gson.toJson(pipe_report);
- try {
- FileWriter pipe_json = new FileWriter(outputFolder+"gorules_report.json", false);
- pipe_json.write(json);
- pipe_json.close();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- m3.dispose();
- LOGGER.info("done with validation");
- }
-
- static class ReasonerReport {
- Map term_asserted_instances_mapped = new HashMap();
- Map term_deepened_instances_mapped = new HashMap();
- Map term_asserted_instances_created = new HashMap();
- Map term_deepened_instances_created = new HashMap();
- }
-
-
- private static ReasonerReport initReasonerReport(String outputFolder) {
- String reasoner_report_file = outputFolder+"reasoner_report_all.txt";
- FileWriter reasoner_report;
- try {
- reasoner_report = new FileWriter(reasoner_report_file, false);
- reasoner_report.write("title\tindividual\txref\tasserted\tinferred\n");
- reasoner_report.close();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- ReasonerReport report = new ReasonerReport();
- return report;
- }
-
- private static ReasonerReport addReasonerReport(String outputFolder, OWLOntology gocam, InferenceProvider ip, String title, ReasonerReport report) throws IOException {
- String reasoner_report_file = outputFolder+"reasoner_report_all.txt";
- FileWriter reasoner_report = new FileWriter(reasoner_report_file, true);
- Set individuals = gocam.getIndividualsInSignature();
- for (OWLNamedIndividual individual : individuals) {
- //what kind of individual - mapped or created. mapped have xrefs, created do not.
- String xref = "none";
- for(OWLAnnotation anno : EntitySearcher.getAnnotations(individual, gocam)){
- if(anno.getProperty().getIRI().toString().equals("http://www.geneontology.org/formats/oboInOwl#hasDbXref")) {
- xref = anno.getValue().asLiteral().get().getLiteral();
- }
- }
-
- Collection asserted_ce = EntitySearcher.getTypes(individual, gocam);
- Set asserted = new HashSet();
- for(OWLClassExpression ce : asserted_ce) {
- if(!ce.isAnonymous()) {
- OWLClass a = ce.asOWLClass();
- if(a.isBuiltIn() == false) {
- asserted.add(a);
- }
- }
- }
- Set inferred_direct = new HashSet<>();
- Set flattened = ip.getTypes(individual);
- for (OWLClass cls : flattened) {
- if (cls.isBuiltIn() == false) {
- inferred_direct.add(cls);
- }
- }
- inferred_direct.removeAll(asserted);
- reasoner_report.write(title+"\t"+individual.getIRI()+"\t"+xref+"\t"+asserted+"\t"+inferred_direct+"\n");
- if(asserted!=null) {
- for(OWLClass go : asserted) {
- if(xref.equals("none")) {
- Integer n = report.term_asserted_instances_created.get(go.toString());
- if(n==null) {
- n = 0;
- }
- n = n+1;
- report.term_asserted_instances_created.put(go.toString(), n);
-
- if(inferred_direct!=null&&inferred_direct.size()>0) {
- Integer deepened = report.term_deepened_instances_created.get(go.toString());
- if(deepened==null) {
- deepened = 0;
- }
- deepened = deepened+1;
- report.term_deepened_instances_created.put(go.toString(), deepened);
- }
- }else {
- Integer n = report.term_asserted_instances_mapped.get(go.toString());
- if(n==null) {
- n = 0;
- }
- n = n+1;
- report.term_asserted_instances_mapped.put(go.toString(), n);
-
- if(inferred_direct!=null&&inferred_direct.size()>0) {
- Integer deepened = report.term_deepened_instances_mapped.get(go.toString());
- if(deepened==null) {
- deepened = 0;
- }
- deepened = deepened+1;
- report.term_deepened_instances_mapped.put(go.toString(), deepened);
- }
- }
- }
- }
- }
- reasoner_report.close();
- return report;
- }
-
- private static void summarizeReasonerReport(String outputFolder, ReasonerReport report) {
- String reasoner_report_summary_file = outputFolder+"reasoner_report_summary.txt";
- FileWriter reasoner_report_summary;
- try {
- reasoner_report_summary = new FileWriter(reasoner_report_summary_file, false);
- reasoner_report_summary.write("asserted GO term\tmapped individual count\tmapped N deepened\tcreated individual count\tcreated N deepened\n");
- Set terms = new HashSet();
- terms.addAll(report.term_asserted_instances_mapped.keySet());
- terms.addAll(report.term_asserted_instances_created.keySet());
- for(String goterm : terms) {
- int n_deepened_mapped = 0; int n_mapped = 0;
- if(report.term_asserted_instances_mapped.containsKey(goterm)) {
- n_mapped = report.term_asserted_instances_mapped.get(goterm);
- }
-
- if(report.term_deepened_instances_mapped.get(goterm)!=null) {
- n_deepened_mapped = report.term_deepened_instances_mapped.get(goterm);
- }
- int n_deepened_created = 0; int n_created = 0;
- if(report.term_asserted_instances_created.containsKey(goterm)) {
- n_created = report.term_asserted_instances_created.get(goterm);
- }
- if(report.term_deepened_instances_created.get(goterm)!=null) {
- n_deepened_created = report.term_deepened_instances_created.get(goterm);
- }
- reasoner_report_summary.write(goterm+"\t"+n_mapped+"\t"+n_deepened_mapped+"\t"+n_created+"\t"+n_deepened_created+"\n");
- }
- reasoner_report_summary.close();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
-
-
- private static String makeColSafe(String text) {
- text = text.replaceAll("\n", " ");
- text = text.replaceAll("\r", " ");
- text = text.replaceAll("\t", " ");
- return text;
- }
-
- public static void addTaxonMetaData(String go_cam_journal, String go_lego_journal_file) throws OWLOntologyCreationException, IOException {
- String modelIdPrefix = "http://model.geneontology.org/";
- OWLOntology dummy = OWLManager.createOWLOntologyManager().createOntology(IRI.create("http://example.org/dummy"));
- CurieHandler curieHandler = new MappedCurieHandler();
- BlazegraphMolecularModelManager m3 = new BlazegraphMolecularModelManager<>(dummy, curieHandler, modelIdPrefix, go_cam_journal, null, go_lego_journal_file, true);
- m3.addTaxonMetadata();
- }
-
- public static void cleanGoCams(String input_dir, String output_dir) {
- OWLOntologyManager m = OWLManager.createOWLOntologyManager();
- File directory = new File(input_dir);
- boolean ignore_imports = true;
- if(directory.isDirectory()) {
- for(File file : directory.listFiles()) {
- if(file.getName().endsWith("ttl")) {
- System.out.println("fixing "+file.getAbsolutePath());
- final IRI modelFile = IRI.create(file.getAbsoluteFile());
- OWLOntology o;
- try {
- o = CoreMolecularModelManager.loadOntologyDocumentSource(new IRIDocumentSource(modelFile), ignore_imports, m);
- //in case the reader was confused by the missing import, fix declarations
- o = CoreMolecularModelManager.fixBrokenObjectPropertiesAndAxioms(o);
- //clean the model
- OWLOntology cleaned_ont = CoreMolecularModelManager.removeDeadAnnotationsAndImports(o);
- //saved the blessed ontology
- OWLDocumentFormat owlFormat = new TurtleDocumentFormat();
- m.setOntologyFormat(cleaned_ont, owlFormat);
- String cleaned_ont_file = output_dir+file.getName();
- try {
- m.saveOntology(cleaned_ont, new FileOutputStream(cleaned_ont_file));
- } catch (OWLOntologyStorageException | FileNotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- } catch (OWLOntologyCreationException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- }
- }
- }
- }
- }
-
-
- public static void printVersion() throws Exception {
- printManifestEntry("git-revision-sha1", "UNKNOWN");
- printManifestEntry("git-revision-url", "UNKNOWN");
- printManifestEntry("git-branch", "UNKNOWN");
- printManifestEntry("git-dirty", "UNKNOWN");
- }
-
- private static String printManifestEntry(String key, String defaultValue) {
- String value = owltools.version.VersionInfo.getManifestVersion(key);
- if (value == null || value.isEmpty()) {
- value = defaultValue;
- }
- System.out.println(key+"\t"+value);
- return value;
- }
-
- public static void reportSystemParams() {
- /* Total number of processors or cores available to the JVM */
- LOGGER.info("Available processors (cores): " +
- Runtime.getRuntime().availableProcessors());
-
- /* Total amount of free memory available to the JVM */
- LOGGER.info("Free memory (m bytes): " +
- Runtime.getRuntime().freeMemory()/1048576);
-
- /* This will return Long.MAX_VALUE if there is no preset limit */
- long maxMemory = Runtime.getRuntime().maxMemory()/1048576;
- /* Maximum amount of memory the JVM will attempt to use */
- LOGGER.info("Maximum memory (m bytes): " +
- (maxMemory == Long.MAX_VALUE ? "no limit" : maxMemory));
-
- /* Total memory currently in use by the JVM */
- LOGGER.info("Total memory (m bytes): " +
- Runtime.getRuntime().totalMemory()/1048576);
-
- /* Get a list of all filesystem roots on this system */
- File[] roots = File.listRoots();
-
- /* For each filesystem root, print some info */
- for (File root : roots) {
- LOGGER.info("File system root: " + root.getAbsolutePath());
- LOGGER.info("Total space (bytes): " + root.getTotalSpace());
- LOGGER.info("Free space (bytes): " + root.getFreeSpace());
- LOGGER.info("Usable space (bytes): " + root.getUsableSpace());
- }
- }
+ private static final Logger LOGGER = Logger.getLogger(CommandLineInterface.class);
+
+ public static void main(String[] args) {
+
+ reportSystemParams();
+ Options main_options = new Options();
+ OptionGroup methods = new OptionGroup();
+ methods.setRequired(true);
+ Option dump = Option.builder()
+ .longOpt("dump-owl-models")
+ .desc("export OWL GO-CAM models from journal")
+ .hasArg(false)
+ .build();
+ methods.addOption(dump);
+
+ Option merge_ontologies = Option.builder()
+ .longOpt("merge-ontologies")
+ .desc("Merge owl ontologies")
+ .hasArg(false)
+ .build();
+ methods.addOption(merge_ontologies);
+ Option import_owl = Option.builder()
+ .longOpt("import-owl-models")
+ .desc("import OWL GO-CAM models into journal")
+ .hasArg(false)
+ .build();
+ methods.addOption(import_owl);
+ Option import_tbox_ontologies = Option.builder()
+ .longOpt("import-tbox-ontologies")
+ .desc("import OWL tbox ontologies into journal")
+ .hasArg(false)
+ .build();
+ methods.addOption(import_tbox_ontologies);
+
+ Option add_taxon_metadata = Option.builder()
+ .longOpt("add-taxon-metadata")
+ .desc("add taxon associated with genes in each model as an annotation on the model")
+ .hasArg(false)
+ .build();
+ methods.addOption(add_taxon_metadata);
+
+ Option clean_gocams = Option.builder()
+ .longOpt("clean-gocams")
+ .desc("remove import statements, add property declarations, remove json-model annotation")
+ .hasArg(false)
+ .build();
+ methods.addOption(clean_gocams);
+
+ Option sparql = Option.builder()
+ .longOpt("sparql-update")
+ .desc("update the blazegraph journal with the given sparql statement")
+ .hasArg(false)
+ .build();
+ methods.addOption(sparql);
+ Option json = Option.builder()
+ .longOpt("owl-lego-to-json")
+ .desc("Given a GO-CAM OWL file, make its minerva json represention")
+ .hasArg(false)
+ .build();
+ methods.addOption(json);
+ Option gpad = Option.builder()
+ .longOpt("lego-to-gpad-sparql")
+ .desc("Given a GO-CAM journal, export GPAD representation for all the go-cams")
+ .hasArg(false)
+ .build();
+ methods.addOption(gpad);
+ Option version = Option.builder()
+ .longOpt("version")
+ .desc("Print the version of the minerva stack used here. Extracts this from JAR file.")
+ .hasArg(false)
+ .build();
+ methods.addOption(version);
+ Option validate = Option.builder()
+ .longOpt("validate-go-cams")
+ .desc("Check a collection of go-cam files or a journal for valid semantics (owl) and structure (shex)")
+ .hasArg(false)
+ .build();
+ methods.addOption(validate);
+
+ main_options.addOptionGroup(methods);
+
+ CommandLineParser parser = new DefaultParser();
+ try {
+ CommandLine cmd = parser.parse(main_options, args, true);
+
+ if (cmd.hasOption("add-taxon-metadata")) {
+ Options add_taxon_options = new Options();
+ add_taxon_options.addOption(add_taxon_metadata);
+ add_taxon_options.addOption("j", "journal", true, "This is the go-cam journal that will be updated with taxon annotations.");
+ add_taxon_options.addOption("ontojournal", "ontojournal", true, "Specify a blazegraph journal file containing the merged, pre-reasoned tbox aka go-lego.owl");
+ cmd = parser.parse(add_taxon_options, args, false);
+ String journalFilePath = cmd.getOptionValue("j"); //--journal
+ String ontojournal = cmd.getOptionValue("ontojournal"); //--folder
+ addTaxonMetaData(journalFilePath, ontojournal);
+ }
+
+ if (cmd.hasOption("clean-gocams")) {
+ Options clean_options = new Options();
+ clean_options.addOption(clean_gocams);
+ clean_options.addOption("i", "input", true, "This is the directory of gocam files to clean.");
+ clean_options.addOption("o", "output", true, "This is the directory of cleaned gocam files that are produced.");
+ cmd = parser.parse(clean_options, args, false);
+ cleanGoCams(cmd.getOptionValue("i"), cmd.getOptionValue("o"));
+ }
+
+ if (cmd.hasOption("import-tbox-ontologies")) {
+ Options import_tbox_options = new Options();
+ import_tbox_options.addOption(import_tbox_ontologies);
+ import_tbox_options.addOption("j", "journal", true, "Sets the Blazegraph journal file for the database");
+ import_tbox_options.addOption("f", "file", true, "Sets the input file containing the ontology to load");
+ import_tbox_options.addOption("r", "reset", false, "If present, will clear out the journal, otherwise adds to it");
+ cmd = parser.parse(import_tbox_options, args, false);
+ String journalFilePath = cmd.getOptionValue("j"); //--journal
+ String inputFile = cmd.getOptionValue("f"); //--folder
+ importOWLOntologyIntoJournal(journalFilePath, inputFile, cmd.hasOption("r"));
+ }
+ if (cmd.hasOption("merge-ontologies")) {
+ Options merge_options = new Options();
+ merge_options.addOption(merge_ontologies);
+ merge_options.addOption("i", "input", true, "The input folder containing ontologies to merge");
+ merge_options.addOption("o", "output", true, "The file to write the ontology to");
+ merge_options.addOption("u", "iri", true, "The base iri for the merged ontology");
+ merge_options.addOption("r", "reason", false, "Add inferences to the merged ontology");
+ cmd = parser.parse(merge_options, args, false);
+ buildMergedOwlOntology(cmd.getOptionValue("i"), cmd.getOptionValue("o"), cmd.getOptionValue("u"), cmd.hasOption("r"));
+ }
+
+ if (cmd.hasOption("dump-owl-models")) {
+ Options dump_options = new Options();
+ dump_options.addOption(dump);
+ dump_options.addOption("j", "journal", true, "Sets the Blazegraph journal file for the database");
+ dump_options.addOption("f", "folder", true, "Sets the output folder the GO-CAM model files");
+ dump_options.addOption("p", "model-id-prefix", true, "prefix for GO-CAM model ids");
+ cmd = parser.parse(dump_options, args, false);
+ String journalFilePath = cmd.getOptionValue("j"); //--journal
+ String outputFolder = cmd.getOptionValue("f"); //--folder
+ String modelIdPrefix = cmd.getOptionValue("p"); //--prefix
+ modelsToOWL(journalFilePath, outputFolder, modelIdPrefix);
+ } else if (cmd.hasOption("import-owl-models")) {
+ Options import_options = new Options();
+ import_options.addOption(import_owl);
+ import_options.addOption("j", "journal", true, "Sets the Blazegraph journal file for the database");
+ import_options.addOption("f", "folder", true, "Sets the input folder the GO-CAM model files");
+ cmd = parser.parse(import_options, args, false);
+ String journalFilePath = cmd.getOptionValue("j"); //--journal
+ String outputFolder = cmd.getOptionValue("f"); //--folder
+ importOWLModels(journalFilePath, outputFolder);
+ } else if (cmd.hasOption("sparql-update")) {
+ Options sparql_options = new Options();
+ sparql_options.addOption(sparql);
+ sparql_options.addOption("j", "journal", true, "Sets the Blazegraph journal file for the database");
+ sparql_options.addOption("f", "file", true, "Sets the file containing a SPARQL update");
+ cmd = parser.parse(sparql_options, args, false);
+ String journalFilePath = cmd.getOptionValue("j"); //--journal
+ String file = cmd.getOptionValue("f");
+ sparqlUpdate(journalFilePath, file);
+ } else if (cmd.hasOption("owl-lego-to-json")) {
+ Options json_options = new Options();
+ json_options.addOption(json);
+ json_options.addOption("i", "OWLFile", true, "Input GO-CAM OWL file");
+ json_options.addOption("o", "JSONFILE", true, "Output JSON file");
+ OptionGroup format = new OptionGroup();
+ Option pretty = Option.builder()
+ .longOpt("pretty-json")
+ .desc("pretty json format")
+ .hasArg(false)
+ .build();
+ format.addOption(pretty);
+ Option compact = Option.builder()
+ .longOpt("compact-json")
+ .desc("compact json format")
+ .hasArg(false)
+ .build();
+ format.addOption(compact);
+ json_options.addOptionGroup(format);
+ cmd = parser.parse(json_options, args, false);
+ String input = cmd.getOptionValue("i");
+ String output = cmd.getOptionValue("o");
+ boolean usePretty = true;
+ if (cmd.hasOption("compact-json")) {
+ usePretty = false;
+ }
+ owl2LegoJson(input, output, usePretty);
+ } else if (cmd.hasOption("lego-to-gpad-sparql")) {
+ Options gpad_options = new Options();
+ gpad_options.addOption(gpad);
+ gpad_options.addOption("i", "input", true, "Sets the Blazegraph journal file for the database");
+ gpad_options.addOption("o", "gpad-output", true, "Sets the output location for the GPAD");
+ gpad_options.addOption("p", "model-id-prefix", true, "prefix for GO-CAM model ids");
+ gpad_options.addOption("c", "model-id-curie", true, "prefix for GO-CAM curies");
+ gpad_options.addOption("ont", "ontology", true, "IRI of tbox ontology for classification - usually default go-lego.owl");
+ gpad_options.addOption("cat", "catalog", true, "Catalog file for tbox ontology. " +
+ "Use this to specify local copies of the ontology and or its imports to " +
+ "speed and control the process. If not used, will download the tbox and all its imports.");
+ gpad_options.addOption("ontojournal", "ontojournal", true, "Specify a blazegraph journal file containing the merged, pre-reasoned tbox aka go-lego.owl");
+ cmd = parser.parse(gpad_options, args, false);
+ String inputDB = cmd.getOptionValue("input");
+ String gpadOutputFolder = cmd.getOptionValue("gpad-output");
+ String modelIdPrefix = cmd.getOptionValue("model-id-prefix");
+ String modelIdcurie = cmd.getOptionValue("model-id-curie");
+ String ontologyIRI = cmd.getOptionValue("ontology");
+ String catalog = cmd.getOptionValue("catalog");
+ String go_lego_journal_file = null;
+ if (cmd.hasOption("ontojournal")) {
+ go_lego_journal_file = cmd.getOptionValue("ontojournal");
+ }
+ if (go_lego_journal_file == null) {
+ System.err.println("Missing -- ontojournal . Need to specify location for blazegraph journal file containing the merged go-lego tbox (neo, GO-plus, etc..). If a journal does not exist at that location, the tbox ontology will be used to initialize one.");
+ System.exit(-1);
+ }
+ legoToAnnotationsSPARQL(modelIdPrefix, modelIdcurie, inputDB, gpadOutputFolder, ontologyIRI, catalog, go_lego_journal_file);
+ } else if (cmd.hasOption("version")) {
+ printVersion();
+ } else if (cmd.hasOption("validate-go-cams")) {
+ Options validate_options = new Options();
+ validate_options.addOption(validate);
+ validate_options.addOption("i", "input", true, "Either a blazegraph journal or a folder with go-cams in it");
+ validate_options.addOption("shex", "shex", false, "If present, will execute shex validation");
+ validate_options.addOption("owl", "owl", false, "If present, will execute shex validation");
+ validate_options.addOption("r", "report-folder", true, "Folder where output files will appear");
+ validate_options.addOption("p", "model-id-prefix", true, "prefix for GO-CAM model ids");
+ validate_options.addOption("cu", "model-id-curie", true, "prefix for GO-CAM curies");
+ validate_options.addOption("ont", "ontology", true, "IRI of tbox ontology - usually default go-lego.owl");
+ validate_options.addOption("c", "catalog", true, "Catalog file for tbox ontology. "
+ + "Use this to specify local copies of the ontology and or its imports to "
+ + "speed and control the process. If not used, will download the tbox and all its imports.");
+ validate_options.addOption("shouldfail", "shouldfail", false, "When used in travis mode for tests, shouldfail "
+ + "parameter will allow a successful run on a folder that only contains incorrect models.");
+ validate_options.addOption("t", "travis", false, "If travis, then the program will stop upon a failed "
+ + "validation and report an error. Otherwise it will continue to test all the models.");
+ validate_options.addOption("m", "shapemap", true, "Specify a shapemap file. Otherwise will download from go_shapes repo.");
+ validate_options.addOption("s", "shexpath", true, "Specify a shex schema file. Otherwise will download from go_shapes repo.");
+ validate_options.addOption("ontojournal", "ontojournal", true, "Specify a blazegraph journal file containing the merged, pre-reasoned tbox aka go-lego.owl");
+ validate_options.addOption("reasoner_report", "reasoner_report", false, "Add a report with reasoning results to the output of the validation. ");
+
+
+ cmd = parser.parse(validate_options, args, false);
+ String input = cmd.getOptionValue("input");
+ String outputFolder = cmd.getOptionValue("report-folder");
+ String shexpath = cmd.getOptionValue("s");
+ String shapemappath = cmd.getOptionValue("shapemap");
+
+ String ontologyIRI = "http://purl.obolibrary.org/obo/go/extensions/go-lego.owl";
+ if (cmd.hasOption("ontology")) {
+ ontologyIRI = cmd.getOptionValue("ontology");
+ }
+ String catalog = cmd.getOptionValue("catalog");
+ String modelIdPrefix = "http://model.geneontology.org/";
+ if (cmd.hasOption("model-id-prefix")) {
+ modelIdPrefix = cmd.getOptionValue("model-id-prefix");
+ }
+ String modelIdcurie = "gomodel";
+ if (cmd.hasOption("model-id-curie")) {
+ modelIdcurie = cmd.getOptionValue("model-id-curie");
+ }
+ boolean travisMode = false;
+ if (cmd.hasOption("travis")) {
+ travisMode = true;
+ }
+ boolean shouldFail = false;
+ if (cmd.hasOption("shouldfail")) {
+ shouldFail = true;
+ }
+ boolean checkShex = false;
+ if (cmd.hasOption("shex")) {
+ checkShex = true;
+ }
+ String go_lego_journal_file = null;
+ if (cmd.hasOption("ontojournal")) {
+ go_lego_journal_file = cmd.getOptionValue("ontojournal");
+ }
+ if (go_lego_journal_file == null) {
+ System.err.println("Missing -- ontojournal . Need to specify blazegraph journal file containing the merged go-lego tbox (neo, GO-plus, etc..)");
+ System.exit(-1);
+ }
+ boolean run_reasoner_report = false;
+ if (cmd.hasOption("reasoner_report")) {
+ run_reasoner_report = true;
+ }
+ validateGoCams(input, outputFolder, ontologyIRI, catalog, modelIdPrefix, modelIdcurie, shexpath, shapemappath, travisMode, shouldFail, checkShex, go_lego_journal_file, run_reasoner_report);
+ }
+ } catch (ParseException exp) {
+ System.out.println("Parameter parse exception. Note that the first parameter must be one of: "
+ + "[--validate-go-cams, --dump-owl-models, --import-owl-models, --sparql-update, --owl-lego-to-json, --lego-to-gpad-sparql, --version, --update-gene-product-types]"
+ + "\nSubsequent parameters are specific to each top level command. "
+ + "\nError message: " + exp.getMessage());
+ System.exit(-1);
+ } catch (Exception e) {
+ e.printStackTrace();
+ //explicitly exiting to inform travis of failure.
+ System.exit(-1);
+ }
+ }
+
+ /**
+ * Given a blazegraph journal with go-cams in it, write them all out as OWL files.
+ * cli --dump-owl-models
+ *
+ * @param journalFilePath
+ * @param outputFolder
+ * @param modelIdPrefix
+ * @throws Exception
+ */
+ public static void modelsToOWL(String journalFilePath, String outputFolder, String modelIdPrefix) throws Exception {
+ if (modelIdPrefix == null) {
+ modelIdPrefix = "http://model.geneontology.org/";
+ }
+
+ // minimal inputs
+ if (journalFilePath == null) {
+ System.err.println("No journal file was configured.");
+ System.exit(-1);
+ return;
+ }
+ if (outputFolder == null) {
+ System.err.println("No output folder was configured.");
+ System.exit(-1);
+ return;
+ }
+
+ OWLOntology dummy = OWLManager.createOWLOntologyManager().createOntology(IRI.create("http://example.org/dummy"));
+ CurieHandler curieHandler = new MappedCurieHandler();
+ BlazegraphMolecularModelManager m3 = new BlazegraphMolecularModelManager<>(dummy, curieHandler, modelIdPrefix, journalFilePath, outputFolder, null, false);
+ m3.dumpAllStoredModels();
+ m3.dispose();
+ }
+
+ /**
+ * Load the go-cam files in the input folder into the journal
+ * cli import-owl-models
+ *
+ * @param journalFilePath
+ * @param inputFolder
+ * @throws Exception
+ */
+ public static void importOWLModels(String journalFilePath, String inputFolder) throws Exception {
+ // minimal inputs
+ if (journalFilePath == null) {
+ System.err.println("No journal file was configured.");
+ System.exit(-1);
+ return;
+ }
+ if (inputFolder == null) {
+ System.err.println("No input folder was configured.");
+ System.exit(-1);
+ return;
+ }
+ int total_files = 0;
+ OWLOntology dummy = OWLManager.createOWLOntologyManager().createOntology(IRI.create("http://example.org/dummy"));
+ String modelIdPrefix = "http://model.geneontology.org/"; // this will not be used for anything
+ CurieHandler curieHandler = new MappedCurieHandler();
+ BlazegraphMolecularModelManager m3 = new BlazegraphMolecularModelManager<>(dummy, curieHandler, modelIdPrefix, journalFilePath, null, null, false);
+ //in case of update rather than whole new journal
+ Set stored = new HashSet(m3.getStoredModelIds());
+ LOGGER.info("loading gocams from " + inputFolder);
+ //for (File file : FileUtils.listFiles(new File(inputFolder), null, true)) {
+ File i = new File(inputFolder);
+ if (i.exists()) {
+ if (i.isDirectory()) {
+ total_files = i.listFiles().length;
+ FileUtils.listFiles(i, null, true).parallelStream().parallel().forEach(file -> {
+ if (file.getName().endsWith("ttl")) {
+ java.util.Optional irio;
+ try {
+ irio = m3.scanForOntologyIRI(file);
+ IRI iri = null;
+ if (irio.isPresent()) {
+ iri = IRI.create(irio.get());
+ }
+ //is it in there already?
+ if (stored.contains(iri)) {
+ LOGGER.error("Attempted to load gocam ttl file into database but gocam with that iri already exists, skipping " + file + " " + iri);
+ } else {
+ stored.add(iri);
+ m3.importModelToDatabase(file, true);
+ }
+ } catch (RDFParseException | RDFHandlerException | IOException e1) {
+ // TODO Auto-generated catch block
+ e1.printStackTrace();
+ } catch (OWLOntologyCreationException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (RepositoryException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ } else {
+ LOGGER.info("Ignored for not ending with .ttl" + file);
+ }
+ });
+ }
+ }
+ m3.dispose();
+ LOGGER.info("done loading gocams, loaded: " + stored.size() + " out of: " + total_files + " files");
+ }
+
+ /**
+ * @param journalFilePath
+ * @param inputFolder
+ * @throws Exception
+ */
+ public static void buildMergedOwlOntology(String inputFolder, String outputfile, String base_iri, boolean addInferences) throws Exception {
+ // minimal inputs
+ if (outputfile == null) {
+ System.err.println("No output file was configured.");
+ System.exit(-1);
+ return;
+ }
+ if (inputFolder == null) {
+ System.err.println("No input folder was configured.");
+ System.exit(-1);
+ return;
+ }
+ if (base_iri == null) {
+ System.err.println("No base iri was configured.");
+ System.exit(-1);
+ return;
+ }
+ OWLOntologyManager ontman = OWLManager.createOWLOntologyManager();
+ OWLDataFactory df = ontman.getOWLDataFactory();
+ OWLOntology merged = ontman.createOntology(IRI.create(base_iri));
+ for (File file : FileUtils.listFiles(new File(inputFolder), null, true)) {
+ LOGGER.info("Loading " + file);
+ if (file.getName().endsWith("ttl") || file.getName().endsWith("owl")) {
+ try {
+ OWLOntology ont = ontman.loadOntologyFromOntologyDocument(file);
+ ontman.addAxioms(merged, ont.getAxioms());
+ } catch (OWLOntologyAlreadyExistsException e) {
+ LOGGER.error("error loading already loaded ontology: " + file);
+ }
+ } else {
+ LOGGER.info("Ignored for not ending with .ttl or .owl " + file);
+ }
+ }
+ if (addInferences) {
+ LOGGER.info("Running reasoner");
+ //OWLReasonerFactory reasonerFactory = new WhelkOWLReasonerFactory();
+ //WhelkOWLReasoner reasoner = (WhelkOWLReasoner)reasonerFactory.createReasoner(merged);
+ OWLReasonerFactory reasonerFactory = new StructuralReasonerFactory();
+ OWLReasoner reasoner = reasonerFactory.createReasoner(merged);
+ InferredOntologyGenerator gen = new InferredOntologyGenerator(reasoner);
+ gen.fillOntology(df, merged);
+ }
+ try {
+ ontman.saveOntology(merged, new FileOutputStream(new File(outputfile)));
+ } catch (OWLOntologyStorageException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (FileNotFoundException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * Load the go-cam files in the input folder into the journal
+ * cli import-owl-models
+ *
+ * @param journalFilePath
+ * @param inputFolder
+ * @throws Exception
+ */
+ public static void importOWLOntologyIntoJournal(String journalFilePath, String inputFile, boolean reset) throws Exception {
+ // minimal inputs
+ if (journalFilePath == null) {
+ System.err.println("No journal file was configured.");
+ System.exit(-1);
+ return;
+ }
+ if (inputFile == null) {
+ System.err.println("No input file was configured.");
+ System.exit(-1);
+ return;
+ }
+
+ BlazegraphOntologyManager man = new BlazegraphOntologyManager(journalFilePath, false);
+ String iri_for_ontology_graph = "http://geneontology.org/go-lego-graph";
+ man.loadRepositoryFromOWLFile(new File(inputFile), iri_for_ontology_graph, reset);
+ }
+
+ /**
+ * Updates the journal with the provided update sparql statement.
+ * cli parameter --sparql-update
+ *
+ * @param journalFilePath
+ * @param updateFile
+ * @throws OWLOntologyCreationException
+ * @throws IOException
+ * @throws RepositoryException
+ * @throws MalformedQueryException
+ * @throws UpdateExecutionException
+ */
+ public static void sparqlUpdate(String journalFilePath, String updateFile) throws OWLOntologyCreationException, IOException, RepositoryException, MalformedQueryException, UpdateExecutionException {
+ // minimal inputs
+ if (journalFilePath == null) {
+ System.err.println("No journal file was configured.");
+ System.exit(-1);
+ return;
+ }
+ if (updateFile == null) {
+ System.err.println("No update file was configured.");
+ System.exit(-1);
+ return;
+ }
+
+ String update = FileUtils.readFileToString(new File(updateFile), StandardCharsets.UTF_8);
+ Properties properties = new Properties();
+ properties.load(CommandLineInterface.class.getResourceAsStream("/org/geneontology/minerva/blazegraph.properties"));
+ properties.setProperty(com.bigdata.journal.Options.FILE, journalFilePath);
+
+ BigdataSail sail = new BigdataSail(properties);
+ BigdataSailRepository repository = new BigdataSailRepository(sail);
+ repository.initialize();
+ BigdataSailRepositoryConnection conn = repository.getUnisolatedConnection();
+ BlazegraphMutationCounter counter = new BlazegraphMutationCounter();
+ conn.addChangeLog(counter);
+ conn.prepareUpdate(QueryLanguage.SPARQL, update).execute();
+ int changes = counter.mutationCount();
+ conn.removeChangeLog(counter);
+ System.out.println("\nApplied " + changes + " changes");
+ conn.close();
+ }
+
+ /**
+ * 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()));
+ InferenceProvider inferenceProvider = null; // TODO decide if we need reasoning
+ String modelId = null;
+ Optional 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);
+ }
+ }
+
+ /**
+ * Output GPAD files via inference+SPARQL
+ * cli --lego-to-gpad-sparql
+ *
+ * @param modelIdPrefix
+ * @param modelIdcurie
+ * @param inputDB
+ * @param gpadOutputFolder
+ * @param ontologyIRI
+ * @throws Exception
+ */
+ public static void legoToAnnotationsSPARQL(String modelIdPrefix, String modelIdcurie, String inputDB, String gpadOutputFolder, String ontologyIRI, String catalog, String go_lego_journal_file) throws Exception {
+ if (modelIdPrefix == null) {
+ modelIdPrefix = "http://model.geneontology.org/";
+ }
+ if (modelIdcurie == null) {
+ modelIdcurie = "gomodel";
+ }
+ if (inputDB == null) {
+ inputDB = "blazegraph.jnl";
+ }
+ if (gpadOutputFolder == null) {
+ gpadOutputFolder = null;
+ }
+ if (ontologyIRI == null) {
+ ontologyIRI = "http://purl.obolibrary.org/obo/go/extensions/go-lego.owl";
+ }
+ OWLOntologyManager ontman = OWLManager.createOWLOntologyManager();
+ if (catalog != null) {
+ LOGGER.info("using catalog: " + catalog);
+ ontman.setIRIMappers(Sets.newHashSet(new owltools.io.CatalogXmlIRIMapper(catalog)));
+ } else {
+ LOGGER.info("no catalog, resolving all ontology uris directly");
+ }
+
+ OWLOntology ontology = ontman.loadOntology(IRI.create(ontologyIRI));
+ CurieMappings localMappings = new CurieMappings.SimpleCurieMappings(Collections.singletonMap(modelIdcurie, modelIdPrefix));
+ CurieHandler curieHandler = new MappedCurieHandler(DefaultCurieHandler.loadDefaultMappings(), localMappings);
+ boolean loadTboxIntoOntJournal = (!(new File(go_lego_journal_file)).exists());
+ BlazegraphMolecularModelManager m3 = new BlazegraphMolecularModelManager<>(ontology, curieHandler, modelIdPrefix, inputDB, null, go_lego_journal_file, false);
+ if (loadTboxIntoOntJournal) {
+ m3.getGolego_repo().loadRepositoryFromOntology(ontology, "http://example.org/", true);
+ }
+ final String immutableModelIdPrefix = modelIdPrefix;
+ final String immutableGpadOutputFolder = gpadOutputFolder;
+ m3.getAvailableModelIds().stream().parallel().forEach(modelIRI -> {
+ try {
+ //TODO investigate whether changing to a neo-lite model has an impact on this - may need to make use of ontology journal
+ String gpad = new GPADSPARQLExport(curieHandler, m3.getLegacyRelationShorthandIndex(), m3.getTboxShorthandIndex(), m3.getGolego_repo().regulatorsToRegulated).exportGPAD(m3.createInferredModel(modelIRI), modelIRI);
+ String fileName = StringUtils.replaceOnce(modelIRI.toString(), immutableModelIdPrefix, "") + ".gpad";
+ Writer writer = new OutputStreamWriter(new FileOutputStream(Paths.get(immutableGpadOutputFolder, fileName).toFile()), StandardCharsets.UTF_8);
+ writer.write(gpad);
+ writer.close();
+ } catch (InconsistentOntologyException e) {
+ LOGGER.error("Inconsistent ontology: " + modelIRI);
+ } catch (IOException e) {
+ LOGGER.error("Couldn't export GPAD for: " + modelIRI, e);
+ }
+ });
+ m3.dispose();
+ }
+
+
+ /**
+ * --validate-go-cams
+ * -i /GitHub/GO_Shapes/test_ttl/go_cams/should_pass/
+ * -c ./catalog-no-import.xml
+ *
+ * @param input
+ * @param basicOutputFile
+ * @param explanationOutputFile
+ * @param ontologyIRI
+ * @param catalog
+ * @param modelIdPrefix
+ * @param modelIdcurie
+ * @param shexpath
+ * @param shapemappath
+ * @param travisMode
+ * @param shouldPass
+ * @throws IOException
+ * @throws OWLOntologyCreationException
+ */
+ public static void validateGoCams(String input, String outputFolder,
+ String ontologyIRI, String catalog, String modelIdPrefix, String modelIdcurie,
+ String shexpath, String shapemappath, boolean travisMode, boolean shouldFail, boolean checkShex,
+ String go_lego_journal_file, boolean run_reasoner_report) throws OWLOntologyCreationException, IOException {
+ LOGGER.setLevel(Level.INFO);
+ String inputDB = "blazegraph.jnl";
+ String shexFileUrl = "https://raw.githubusercontent.com/geneontology/go-shapes/master/shapes/go-cam-shapes.shex";
+ String goshapemapFileUrl = "https://raw.githubusercontent.com/geneontology/go-shapes/master/shapes/go-cam-shapes.shapeMap";
+ CurieMappings localMappings = new CurieMappings.SimpleCurieMappings(Collections.singletonMap(modelIdcurie, modelIdPrefix));
+ CurieHandler curieHandler = new MappedCurieHandler(DefaultCurieHandler.loadDefaultMappings(), localMappings);
+ Map modelid_filename = new HashMap();
+
+ if (outputFolder == null) {
+ LOGGER.error("please specify an output folder with -r ");
+ System.exit(-1);
+ } else if (!outputFolder.endsWith("/")) {
+ outputFolder += "/";
+ }
+
+ if (input == null) {
+ LOGGER.error("please provide an input file - either a directory of ttl files or a blazegraph journal");
+ System.exit(-1);
+ }
+
+ LOGGER.info("loading tbox ontology: " + ontologyIRI);
+ OWLOntologyManager ontman = OWLManager.createOWLOntologyManager();
+ if (catalog != null) {
+ LOGGER.info("using catalog: " + catalog);
+ try {
+ ontman.setIRIMappers(Sets.newHashSet(new CatalogXmlIRIMapper(catalog)));
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ } else {
+ LOGGER.info("no catalog, resolving all ontology uris directly");
+ }
+
+ OWLOntology tbox_ontology = null;
+ try {
+ tbox_ontology = ontman.loadOntology(IRI.create(ontologyIRI));
+ LOGGER.info("tbox ontology axioms loaded: " + tbox_ontology.getAxiomCount());
+ } catch (OWLOntologyCreationException e1) {
+ // TODO Auto-generated catch block
+ e1.printStackTrace();
+ }
+ //either load directly from existing journal
+ if (input.endsWith(".jnl")) {
+ inputDB = input;
+ } else {
+ //or make sure that the journal file provided is cleared out and ready
+ File i = new File(input);
+ if (i.exists()) {
+ //remove anything that existed earlier
+ File bgdb = new File(inputDB);
+ if (bgdb.exists()) {
+ bgdb.delete();
+ }
+ }
+ }
+ //make the manager
+ LOGGER.info("Setting up model manager and initializing rules for Arachne reasoner");
+ UndoAwareMolecularModelManager m3 = new UndoAwareMolecularModelManager(tbox_ontology, curieHandler, modelIdPrefix, inputDB, null, go_lego_journal_file, true);
+ //if provided a directory as input, load them ttl files into the manager
+ File i = new File(input);
+ if (i.exists() && !input.endsWith(".jnl")) {
+ if (i.isDirectory()) {
+ LOGGER.info("Loading models from " + i.getAbsolutePath());
+ Set model_iris = new HashSet();
+ FileUtils.listFiles(i, null, true).parallelStream().parallel().forEach(file -> {
+ if (file.getName().endsWith(".ttl") || file.getName().endsWith("owl")) {
+ try {
+ String modeluri = m3.importModelToDatabase(file, true);
+ if (modeluri == null) {
+ LOGGER.error("Null model IRI: " + modeluri + " file: " + file);
+ } else if (!model_iris.add(modeluri)) {
+ LOGGER.error("Multiple models with same IRI: " + modeluri + " file: " + file + " file: " + modelid_filename.get(modeluri));
+ } else {
+ modelid_filename.put(modeluri, file.getName());
+ }
+ } catch (OWLOntologyCreationException | RepositoryException | RDFParseException
+ | RDFHandlerException | IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ });
+ } else {//just load the one provided
+ LOGGER.info("Loading " + i);
+ try {
+ m3.importModelToDatabase(i, true);
+ } catch (OWLOntologyCreationException | RepositoryException | RDFParseException
+ | RDFHandlerException | IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ LOGGER.info("loaded files into blazegraph journal: " + input);
+ }
+ //models ready
+ //now set up shex validator
+ if (shexpath == null) {
+ //fall back on downloading from shapes repo
+ URL shex_schema_url;
+ try {
+ shex_schema_url = new URL(shexFileUrl);
+ shexpath = "./go-cam-schema.shex";
+ File shex_schema_file = new File(shexpath);
+ org.apache.commons.io.FileUtils.copyURLToFile(shex_schema_url, shex_schema_file);
+ System.err.println("-s .No shex schema provided, using: " + shexFileUrl);
+ } catch (MalformedURLException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ if (shapemappath == null) {
+ URL shex_map_url;
+ try {
+ shex_map_url = new URL(goshapemapFileUrl);
+ shapemappath = "./go-cam-shapes.shapeMap";
+ File shex_map_file = new File(shapemappath);
+ org.apache.commons.io.FileUtils.copyURLToFile(shex_map_url, shex_map_file);
+ System.err.println("-m .No shape map file provided, using: " + goshapemapFileUrl);
+ } catch (MalformedURLException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ LOGGER.info("making shex validator: " + shexpath + " " + shapemappath + " " + curieHandler + " ");
+ MinervaShexValidator shex = null;
+ try {
+ shex = new MinervaShexValidator(shexpath, shapemappath, curieHandler, m3.getGolego_repo());
+ } catch (Exception e1) {
+ // TODO Auto-generated catch block
+ e1.printStackTrace();
+ }
+
+ if (checkShex) {
+ shex.setActive(true);
+ } else {
+ shex.setActive(false);
+ }
+
+ //shex validator is ready, now build the inference provider (which provides access to the shex validator and provides inferences useful for shex)
+ String reasonerOpt = "arachne";
+ LOGGER.info("Building OWL inference provider: " + reasonerOpt);
+ InferenceProviderCreator ipc = StartUpTool.createInferenceProviderCreator(reasonerOpt, m3, shex);
+ LOGGER.info("Validating models: " + reasonerOpt);
+
+ //Set up all the report files.
+ String basic_output_file = outputFolder + "main_report.txt";
+ String explanations_file = outputFolder + "explanations.txt";
+ String activity_output_file = outputFolder + "activity_report.txt";
+ if (outputFolder != null) {
+ try {
+ //valid or not
+ FileWriter basic_shex_output = new FileWriter(basic_output_file, false);
+ basic_shex_output.write("filename\tmodel_title\tmodel_url\tmodelstate\tcontributor\tprovider\tdate\tOWL_consistent\tshex_valid\tshex_meta_problem\tshex_data_problem\tvalidation_time_milliseconds\taxioms\tn_rows_gpad\t");
+ basic_shex_output.write(GoCamModelStats.statsHeader() + "\n");
+ basic_shex_output.close();
+ //tab delimited explanations for failures
+ FileWriter explanations = new FileWriter(explanations_file, false);
+ explanations.write("filename\tmodel_title\tmodel_iri\tnode\tNode_types\tproperty\tIntended_range_shapes\tobject\tObject_types\tObject_shapes\n");
+ explanations.close();
+ //tab delimited summary of properties of activity units
+ FileWriter activity_output = new FileWriter(activity_output_file, false);
+ activity_output.write("filename\tmodel_title\tmodel_url\tmodelstate\tcontributor\tprovider\tdate\tactivity_iri\tactivity_xref\tactivity_label\tcomplete\tinputs\toutputs\tenablers\tlocations\tcausal upstream\tcausal downstream\tpart of n BP\tMF\tBP\n");
+ activity_output.close();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ //this will generate the json file used for the go rules report for the pipeline
+ BatchPipelineValidationReport pipe_report = null;
+ Set owl_errors = new HashSet();
+ Set shex_errors = new HashSet();
+ pipe_report = new BatchPipelineValidationReport();
+ try {
+ pipe_report.setNumber_of_models(m3.getAvailableModelIds().size());
+ } catch (IOException e1) {
+ // TODO Auto-generated catch block
+ e1.printStackTrace();
+ }
+ int bad_models = 0;
+ int good_models = 0;
+ final boolean shex_output = checkShex;
+
+ //only used if OWL reasoning report is requested
+ ReasonerReport reasoner_report = null;
+ if (run_reasoner_report) {
+ reasoner_report = initReasonerReport(outputFolder);
+ }
+ //now process each gocam
+ try {
+ for (IRI modelIRI : m3.getAvailableModelIds()) {
+ long start = System.currentTimeMillis();
+ String filename = modelid_filename.get(modelIRI.toString());
+ boolean isConsistent = true; //OWL
+ boolean isConformant = true; //shex
+ if (filename != null) {
+ LOGGER.info("processing " + filename + "\t" + modelIRI);
+ } else {
+ LOGGER.info("processing \t" + modelIRI);
+ }
+ //this is where everything actually happens
+ ModelContainer mc = m3.getModel(modelIRI);
+ OWLOntology gocam = mc.getAboxOntology();
+ try {
+ //if a model does not have an import statement that links in an ontology that defines all of its classes and object properties
+ //or if the model does not define the classes and object properties itself, parsing problems will prevail
+ //this step makes sure that does not happen
+ gocam = CoreMolecularModelManager.fixBrokenObjectPropertiesAndAxioms(gocam);
+ } catch (OWLOntologyCreationException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ LOGGER.info("preparing model stats...");
+ //The GoCamModel code is used to capture model-level statistics such as 'how many causal relations are there?'
+ //This might be an area for a speed improvement if needed
+ GoCamModel gcm = new GoCamModel(gocam, m3);
+ String title = "title";
+ if (gcm.getTitle() != null) {
+ title = makeColSafe(gcm.getTitle());
+ } else {
+ LOGGER.error("no title for " + filename);
+ }
+ //this is to make clickable links in reports
+ String link = modelIRI.toString().replace("http://model.geneontology.org/", "http://noctua.geneontology.org/editor/graph/gomodel:");
+ if (modelIRI.toString().contains("R-HSA")) {
+ link = link.replace("noctua.geneontology", "noctua-dev.berkeleybop");
+ }
+ String modelstate = makeColSafe(gcm.getModelstate());
+ String contributor = makeColSafe(gcm.getContributors().toString());
+ String date = makeColSafe(gcm.getDate());
+ String provider = makeColSafe(gcm.getProvided_by().toString());
+ pipe_report.setTaxa(gcm.getIn_taxon());
+ LOGGER.info("model stats done for title: " + title);
+ int axioms = gocam.getAxiomCount();
+ //add activity level statistics as a default
+ FileWriter activity_output = new FileWriter(activity_output_file, true);
+ for (ActivityUnit unit : gcm.getActivities()) {
+ activity_output.write(filename + "\t" + title + "\t" + link + "\t" + modelstate + "\t" + contributor + "\t" + provider + "\t" + date + "\t" + unit.getIndividual().getIRI().toString() + "\t" + unit.getXref() + "\t" + unit.getLabel() + "\t");
+ activity_output.write(unit.isComplete() + "\t" + unit.getInputs().size() + "\t" + unit.getOutputs().size() + "\t" + unit.getEnablers().size() + "\t" + unit.getLocations().size() +
+ "\t" + unit.getCausal_in().size() + "\t" + unit.getCausal_out().size() + "\t" + unit.getContaining_processes().size() + "\t" + unit.stringForClasses(unit.getDirect_types()) + "\t" + unit.getURIsForConnectedBPs() + "\n");
+ }
+ activity_output.close();
+
+ InferenceProvider ip = ipc.create(mc);
+ isConsistent = ip.isConsistent();
+ //TODO re-use reasoner object from ip
+ //TODO this is another area that could be touched/removed for speed improvement
+ int n_rows_gpad = 0;
+ if (isConsistent) {
+ try {
+ Set gpad = new GPADSPARQLExport(curieHandler, m3.getLegacyRelationShorthandIndex(), m3.getTboxShorthandIndex(), m3.getGolego_repo().regulatorsToRegulated).getGPAD(m3.createInferredModel(modelIRI), modelIRI);
+ if (gpad != null) {
+ n_rows_gpad = gpad.size();
+ }
+ } catch (InconsistentOntologyException e) {
+ LOGGER.error("inconsistent ontology, can't make gpad");
+ }
+ }
+ long done = System.currentTimeMillis();
+ long milliseconds = (done - start);
+ //for rules report in pipeline
+ if (!ip.isConsistent()) {
+ String level = "ERROR";
+ String model_id = curieHandler.getCuri(modelIRI);
+ String message = BatchPipelineValidationReport.getOwlMessage();
+ int rule = BatchPipelineValidationReport.getOwlRule();
+ ErrorMessage owl = new ErrorMessage(level, model_id, gcm.getIn_taxon(), message, rule);
+ owl_errors.add(owl);
+ }
+ if (!isConsistent) {
+ FileWriter explanations = new FileWriter(explanations_file, true);
+ explanations.write(filename + "\t" + title + "\t" + modelIRI + "\tOWL fail explanation: " + ip.getValidation_results().getOwlvalidation().getAsText() + "\n");
+ explanations.close();
+ }
+ //travis mode causes the system to exit when an invalid model is detected (unless shouldFail is on)
+ if (travisMode && !isConsistent) {
+ if (!shouldFail) {
+ LOGGER.error(filename + "\t" + title + "\t" + modelIRI + "\tOWL:is inconsistent, quitting");
+ System.exit(-1);
+ }
+ }
+ //basic is just one row per model - did it validate or not
+ FileWriter basic = new FileWriter(basic_output_file, true);
+ if (!shex_output) {
+ if (ip.isConsistent()) {
+ good_models++;
+ } else {
+ bad_models++;
+ }
+ } else {
+ ValidationResultSet validations = ip.getValidation_results();
+ isConformant = validations.allConformant();
+ if (isConformant) {
+ good_models++;
+ } else {
+ bad_models++;
+ }
+ if (!validations.getShexvalidation().isConformant()) {
+ String level = "WARNING";
+ String model_id = curieHandler.getCuri(modelIRI);
+ String message = BatchPipelineValidationReport.getShexMessage();
+ int rule = BatchPipelineValidationReport.getShexRule();
+ ErrorMessage shex_message = new ErrorMessage(level, model_id, gcm.getIn_taxon(), message, rule);
+ boolean include_explanations_in_json = true; //TODO set as a parameter
+ if (include_explanations_in_json) {
+ shex_message.setExplanations(validations);
+ }
+ shex_errors.add(shex_message);
+ FileWriter explanations = new FileWriter(explanations_file, true);
+ explanations.write(ip.getValidation_results().getShexvalidation().getAsTab(filename + "\t" + title + "\t" + modelIRI));
+ explanations.close();
+ }
+ if (travisMode) {
+ if (!isConformant && !shouldFail) {
+ LOGGER.error(filename + "\t" + title + "\t" + modelIRI + "\tshex is nonconformant, quitting, explanation:\n" + ip.getValidation_results().getShexvalidation().getAsText());
+ System.exit(-1);
+ } else if (isConformant && shouldFail) {
+ LOGGER.error(filename + "\t" + title + "\t" + modelIRI + "\tshex validates, but it should not be, quitting");
+ System.exit(-1);
+ }
+ }
+ //is it a metadata violation or data ?
+ boolean shex_meta_problem = false;
+ boolean shex_data_problem = false;
+ if (!validations.getShexvalidation().isConformant()) {
+ String model_curie = curieHandler.getCuri(modelIRI);
+ ValidationResultSet validationset = ip.getValidation_results();
+ ShexValidationReport shex_report = validationset.getShexvalidation();
+ Set violations = shex_report.getViolations();
+ if (violations != null) {
+ for (Violation v : violations) {
+ if (v.getNode().equals(model_curie)) {
+ shex_meta_problem = true;
+ } else {
+ shex_data_problem = true;
+ }
+ }
+ } else {
+ LOGGER.error("Invalid model but no violations reported");
+ }
+ }
+ LOGGER.info(filename + "\t" + title + "\t" + modelIRI + "\tOWL:" + isConsistent + "\tshex:" + isConformant);
+ basic.write(filename + "\t" + title + "\t" + link + "\t" + modelstate + "\t" + contributor + "\t" + provider + "\t" + date + "\t" + isConsistent + "\t" + isConformant + "\t" + shex_meta_problem + "\t" + shex_data_problem + "\t" + milliseconds + "\t" + axioms + "\t" +
+ n_rows_gpad + "\t" + gcm.getGoCamModelStats().stats2cols() + "\n");
+ }
+ basic.close();
+ if (run_reasoner_report) {
+ addReasonerReport(outputFolder, gocam, ip, title, reasoner_report);
+ }
+ }
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ if (run_reasoner_report) {
+ summarizeReasonerReport(outputFolder, reasoner_report);
+ }
+
+ pipe_report.setNumber_of_correct_models(good_models);
+ pipe_report.setNumber_of_models_in_error(bad_models);
+ pipe_report.getMessages().put(BatchPipelineValidationReport.getShexRuleString(), shex_errors);
+ pipe_report.getMessages().put(BatchPipelineValidationReport.getOwlRuleString(), owl_errors);
+ GsonBuilder builder = new GsonBuilder();
+ Gson gson = builder.setPrettyPrinting().create();
+ String json = gson.toJson(pipe_report);
+ try {
+ FileWriter pipe_json = new FileWriter(outputFolder + "gorules_report.json", false);
+ pipe_json.write(json);
+ pipe_json.close();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ m3.dispose();
+ LOGGER.info("done with validation");
+ }
+
+ static class ReasonerReport {
+ Map term_asserted_instances_mapped = new HashMap();
+ Map term_deepened_instances_mapped = new HashMap();
+ Map term_asserted_instances_created = new HashMap();
+ Map term_deepened_instances_created = new HashMap();
+ }
+
+
+ private static ReasonerReport initReasonerReport(String outputFolder) {
+ String reasoner_report_file = outputFolder + "reasoner_report_all.txt";
+ FileWriter reasoner_report;
+ try {
+ reasoner_report = new FileWriter(reasoner_report_file, false);
+ reasoner_report.write("title\tindividual\txref\tasserted\tinferred\n");
+ reasoner_report.close();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ ReasonerReport report = new ReasonerReport();
+ return report;
+ }
+
+ private static ReasonerReport addReasonerReport(String outputFolder, OWLOntology gocam, InferenceProvider ip, String title, ReasonerReport report) throws IOException {
+ String reasoner_report_file = outputFolder + "reasoner_report_all.txt";
+ FileWriter reasoner_report = new FileWriter(reasoner_report_file, true);
+ Set individuals = gocam.getIndividualsInSignature();
+ for (OWLNamedIndividual individual : individuals) {
+ //what kind of individual - mapped or created. mapped have xrefs, created do not.
+ String xref = "none";
+ for (OWLAnnotation anno : EntitySearcher.getAnnotations(individual, gocam)) {
+ if (anno.getProperty().getIRI().toString().equals("http://www.geneontology.org/formats/oboInOwl#hasDbXref")) {
+ xref = anno.getValue().asLiteral().get().getLiteral();
+ }
+ }
+
+ Collection asserted_ce = EntitySearcher.getTypes(individual, gocam);
+ Set asserted = new HashSet();
+ for (OWLClassExpression ce : asserted_ce) {
+ if (!ce.isAnonymous()) {
+ OWLClass a = ce.asOWLClass();
+ if (a.isBuiltIn() == false) {
+ asserted.add(a);
+ }
+ }
+ }
+ Set inferred_direct = new HashSet<>();
+ Set flattened = ip.getTypes(individual);
+ for (OWLClass cls : flattened) {
+ if (cls.isBuiltIn() == false) {
+ inferred_direct.add(cls);
+ }
+ }
+ inferred_direct.removeAll(asserted);
+ reasoner_report.write(title + "\t" + individual.getIRI() + "\t" + xref + "\t" + asserted + "\t" + inferred_direct + "\n");
+ if (asserted != null) {
+ for (OWLClass go : asserted) {
+ if (xref.equals("none")) {
+ Integer n = report.term_asserted_instances_created.get(go.toString());
+ if (n == null) {
+ n = 0;
+ }
+ n = n + 1;
+ report.term_asserted_instances_created.put(go.toString(), n);
+
+ if (inferred_direct != null && inferred_direct.size() > 0) {
+ Integer deepened = report.term_deepened_instances_created.get(go.toString());
+ if (deepened == null) {
+ deepened = 0;
+ }
+ deepened = deepened + 1;
+ report.term_deepened_instances_created.put(go.toString(), deepened);
+ }
+ } else {
+ Integer n = report.term_asserted_instances_mapped.get(go.toString());
+ if (n == null) {
+ n = 0;
+ }
+ n = n + 1;
+ report.term_asserted_instances_mapped.put(go.toString(), n);
+
+ if (inferred_direct != null && inferred_direct.size() > 0) {
+ Integer deepened = report.term_deepened_instances_mapped.get(go.toString());
+ if (deepened == null) {
+ deepened = 0;
+ }
+ deepened = deepened + 1;
+ report.term_deepened_instances_mapped.put(go.toString(), deepened);
+ }
+ }
+ }
+ }
+ }
+ reasoner_report.close();
+ return report;
+ }
+
+ private static void summarizeReasonerReport(String outputFolder, ReasonerReport report) {
+ String reasoner_report_summary_file = outputFolder + "reasoner_report_summary.txt";
+ FileWriter reasoner_report_summary;
+ try {
+ reasoner_report_summary = new FileWriter(reasoner_report_summary_file, false);
+ reasoner_report_summary.write("asserted GO term\tmapped individual count\tmapped N deepened\tcreated individual count\tcreated N deepened\n");
+ Set terms = new HashSet();
+ terms.addAll(report.term_asserted_instances_mapped.keySet());
+ terms.addAll(report.term_asserted_instances_created.keySet());
+ for (String goterm : terms) {
+ int n_deepened_mapped = 0;
+ int n_mapped = 0;
+ if (report.term_asserted_instances_mapped.containsKey(goterm)) {
+ n_mapped = report.term_asserted_instances_mapped.get(goterm);
+ }
+
+ if (report.term_deepened_instances_mapped.get(goterm) != null) {
+ n_deepened_mapped = report.term_deepened_instances_mapped.get(goterm);
+ }
+ int n_deepened_created = 0;
+ int n_created = 0;
+ if (report.term_asserted_instances_created.containsKey(goterm)) {
+ n_created = report.term_asserted_instances_created.get(goterm);
+ }
+ if (report.term_deepened_instances_created.get(goterm) != null) {
+ n_deepened_created = report.term_deepened_instances_created.get(goterm);
+ }
+ reasoner_report_summary.write(goterm + "\t" + n_mapped + "\t" + n_deepened_mapped + "\t" + n_created + "\t" + n_deepened_created + "\n");
+ }
+ reasoner_report_summary.close();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+
+ private static String makeColSafe(String text) {
+ text = text.replaceAll("\n", " ");
+ text = text.replaceAll("\r", " ");
+ text = text.replaceAll("\t", " ");
+ return text;
+ }
+
+ public static void addTaxonMetaData(String go_cam_journal, String go_lego_journal_file) throws OWLOntologyCreationException, IOException {
+ String modelIdPrefix = "http://model.geneontology.org/";
+ OWLOntology dummy = OWLManager.createOWLOntologyManager().createOntology(IRI.create("http://example.org/dummy"));
+ CurieHandler curieHandler = new MappedCurieHandler();
+ BlazegraphMolecularModelManager m3 = new BlazegraphMolecularModelManager<>(dummy, curieHandler, modelIdPrefix, go_cam_journal, null, go_lego_journal_file, true);
+ m3.addTaxonMetadata();
+ }
+
+ public static void cleanGoCams(String input_dir, String output_dir) {
+ OWLOntologyManager m = OWLManager.createOWLOntologyManager();
+ File directory = new File(input_dir);
+ boolean ignore_imports = true;
+ if (directory.isDirectory()) {
+ for (File file : directory.listFiles()) {
+ if (file.getName().endsWith("ttl")) {
+ System.out.println("fixing " + file.getAbsolutePath());
+ final IRI modelFile = IRI.create(file.getAbsoluteFile());
+ OWLOntology o;
+ try {
+ o = CoreMolecularModelManager.loadOntologyDocumentSource(new IRIDocumentSource(modelFile), ignore_imports, m);
+ //in case the reader was confused by the missing import, fix declarations
+ o = CoreMolecularModelManager.fixBrokenObjectPropertiesAndAxioms(o);
+ //clean the model
+ OWLOntology cleaned_ont = CoreMolecularModelManager.removeDeadAnnotationsAndImports(o);
+ //saved the blessed ontology
+ OWLDocumentFormat owlFormat = new TurtleDocumentFormat();
+ m.setOntologyFormat(cleaned_ont, owlFormat);
+ String cleaned_ont_file = output_dir + file.getName();
+ try {
+ m.saveOntology(cleaned_ont, new FileOutputStream(cleaned_ont_file));
+ } catch (OWLOntologyStorageException | FileNotFoundException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ } catch (OWLOntologyCreationException e1) {
+ // TODO Auto-generated catch block
+ e1.printStackTrace();
+ }
+ }
+ }
+ }
+ }
+
+
+ public static void printVersion() throws Exception {
+ printManifestEntry("git-revision-sha1", "UNKNOWN");
+ printManifestEntry("git-revision-url", "UNKNOWN");
+ printManifestEntry("git-branch", "UNKNOWN");
+ printManifestEntry("git-dirty", "UNKNOWN");
+ }
+
+ private static String printManifestEntry(String key, String defaultValue) {
+ String value = owltools.version.VersionInfo.getManifestVersion(key);
+ if (value == null || value.isEmpty()) {
+ value = defaultValue;
+ }
+ System.out.println(key + "\t" + value);
+ return value;
+ }
+
+ public static void reportSystemParams() {
+ /* Total number of processors or cores available to the JVM */
+ LOGGER.info("Available processors (cores): " +
+ Runtime.getRuntime().availableProcessors());
+
+ /* Total amount of free memory available to the JVM */
+ LOGGER.info("Free memory (m bytes): " +
+ Runtime.getRuntime().freeMemory() / 1048576);
+
+ /* This will return Long.MAX_VALUE if there is no preset limit */
+ long maxMemory = Runtime.getRuntime().maxMemory() / 1048576;
+ /* Maximum amount of memory the JVM will attempt to use */
+ LOGGER.info("Maximum memory (m bytes): " +
+ (maxMemory == Long.MAX_VALUE ? "no limit" : maxMemory));
+
+ /* Total memory currently in use by the JVM */
+ LOGGER.info("Total memory (m bytes): " +
+ Runtime.getRuntime().totalMemory() / 1048576);
+
+ /* Get a list of all filesystem roots on this system */
+ File[] roots = File.listRoots();
+
+ /* For each filesystem root, print some info */
+ for (File root : roots) {
+ LOGGER.info("File system root: " + root.getAbsolutePath());
+ LOGGER.info("Total space (bytes): " + root.getTotalSpace());
+ LOGGER.info("Free space (bytes): " + root.getFreeSpace());
+ LOGGER.info("Usable space (bytes): " + root.getUsableSpace());
+ }
+ }
}
diff --git a/minerva-cli/src/main/resources/log4j.properties b/minerva-cli/src/main/resources/log4j.properties
index 59f57563..854f81f2 100644
--- a/minerva-cli/src/main/resources/log4j.properties
+++ b/minerva-cli/src/main/resources/log4j.properties
@@ -1,9 +1,7 @@
log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern=%d %-5p (%c:%L) %m\n
-
-log4j.logger.org.semanticweb.elk = ERROR
+log4j.logger.org.semanticweb.elk=ERROR
log4j.logger.org.obolibrary.obo2owl=OFF
log4j.logger.org.semanticweb.owlapi=error
-
log4j.rootLogger=INFO, console
diff --git a/minerva-converter/pom.xml b/minerva-converter/pom.xml
index 0d3e2d5e..1f1e25c3 100644
--- a/minerva-converter/pom.xml
+++ b/minerva-converter/pom.xml
@@ -1,48 +1,48 @@
- 4.0.0
-
- minerva
- org.geneontology
- 0.6.1
-
- minerva-converter
- Minerva-Converter
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ 4.0.0
+
+ minerva
+ org.geneontology
+ 0.6.1
+
+ minerva-converter
+ Minerva-Converter
-
-
-
- org.apache.maven.plugins
- maven-surefire-plugin
-
-
- **/FooTest.java
-
-
-
-
- org.jacoco
- jacoco-maven-plugin
-
-
-
+
+
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+
+
+ **/FooTest.java
+
+
+
+
+ org.jacoco
+ jacoco-maven-plugin
+
+
+
-
-
- org.geneontology
- minerva-lookup
- ${project.parent.version}
-
-
- org.geneontology
- minerva-json
- ${project.parent.version}
- test
-
-
- com.google.code.gson
- gson
-
-
+
+
+ org.geneontology
+ minerva-lookup
+ ${project.parent.version}
+
+
+ org.geneontology
+ minerva-json
+ ${project.parent.version}
+ test
+
+
+ com.google.code.gson
+ gson
+
+
diff --git a/minerva-converter/src/main/java/org/geneontology/minerva/evidence/FindGoCodes.java b/minerva-converter/src/main/java/org/geneontology/minerva/evidence/FindGoCodes.java
index 3a797732..6222e8e4 100644
--- a/minerva-converter/src/main/java/org/geneontology/minerva/evidence/FindGoCodes.java
+++ b/minerva-converter/src/main/java/org/geneontology/minerva/evidence/FindGoCodes.java
@@ -1,71 +1,70 @@
package org.geneontology.minerva.evidence;
-import java.io.IOException;
-import java.util.HashSet;
-import java.util.LinkedList;
-import java.util.Queue;
-import java.util.Set;
-
import org.apache.commons.lang3.tuple.Pair;
import org.geneontology.minerva.curie.CurieHandler;
import org.semanticweb.owlapi.model.OWLClass;
import org.semanticweb.owlapi.model.OWLOntology;
import org.semanticweb.owlapi.model.OWLSubClassOfAxiom;
import org.semanticweb.owlapi.util.OWLClassExpressionVisitorAdapter;
-
import owltools.gaf.eco.EcoMapperFactory;
import owltools.gaf.eco.SimpleEcoMapper;
+import java.io.IOException;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.Queue;
+import java.util.Set;
+
public class FindGoCodes {
- private final SimpleEcoMapper mapper;
- private final CurieHandler curieHandler;
+ private final SimpleEcoMapper mapper;
+ private final CurieHandler curieHandler;
- public FindGoCodes(CurieHandler curieHandler) throws IOException {
- this(EcoMapperFactory.createSimple(), curieHandler);
- }
+ public FindGoCodes(CurieHandler curieHandler) throws IOException {
+ this(EcoMapperFactory.createSimple(), curieHandler);
+ }
- public FindGoCodes(SimpleEcoMapper mapper, CurieHandler curieHandler) {
- this.mapper = mapper;
- this.curieHandler = curieHandler;
- }
+ public FindGoCodes(SimpleEcoMapper mapper, CurieHandler curieHandler) {
+ this.mapper = mapper;
+ this.curieHandler = curieHandler;
+ }
- public Pair findShortEvidence(OWLClass eco, String ecoId, OWLOntology model) {
- Pair pair = mapper.getGoCode(ecoId);
- if (pair == null) {
- // try to find a GO-Code mapping in the named super classes
- // mini walker code, with cycle detection
- final Set done = new HashSet<>();
- final Queue queue = new LinkedList<>();
- queue.addAll(getNamedDirectSuperClasses(eco, model));
- done.add(eco);
- while (queue.isEmpty() == false && pair == null) {
- OWLClass current = queue.poll();
- pair = mapper.getGoCode(curieHandler.getCuri(current));
- if (done.add(current) && pair == null) {
- queue.addAll(getNamedDirectSuperClasses(current, model)) ;
- }
- }
- }
- return pair;
- }
+ public Pair findShortEvidence(OWLClass eco, String ecoId, OWLOntology model) {
+ Pair pair = mapper.getGoCode(ecoId);
+ if (pair == null) {
+ // try to find a GO-Code mapping in the named super classes
+ // mini walker code, with cycle detection
+ final Set done = new HashSet<>();
+ final Queue queue = new LinkedList<>();
+ queue.addAll(getNamedDirectSuperClasses(eco, model));
+ done.add(eco);
+ while (queue.isEmpty() == false && pair == null) {
+ OWLClass current = queue.poll();
+ pair = mapper.getGoCode(curieHandler.getCuri(current));
+ if (done.add(current) && pair == null) {
+ queue.addAll(getNamedDirectSuperClasses(current, model));
+ }
+ }
+ }
+ return pair;
+ }
- private Set getNamedDirectSuperClasses(OWLClass current, OWLOntology model) {
- final Set dedup = new HashSet();
- Set closure = model.getImportsClosure();
- for (OWLOntology ont : closure) {
- for(OWLSubClassOfAxiom ax : ont.getSubClassAxiomsForSubClass(current)) {
- ax.getSuperClass().accept(new OWLClassExpressionVisitorAdapter(){
+ private Set getNamedDirectSuperClasses(OWLClass current, OWLOntology model) {
+ final Set dedup = new HashSet();
+ Set closure = model.getImportsClosure();
+ for (OWLOntology ont : closure) {
+ for (OWLSubClassOfAxiom ax : ont.getSubClassAxiomsForSubClass(current)) {
+ ax.getSuperClass().accept(new OWLClassExpressionVisitorAdapter() {
- @Override
- public void visit(OWLClass cls) {
- if (cls.isBuiltIn() == false) {
- dedup.add(cls);
- }
- }
- });
- }
- }
- return dedup;
- }
+ @Override
+ public void visit(OWLClass cls) {
+ if (cls.isBuiltIn() == false) {
+ dedup.add(cls);
+ }
+ }
+ });
+ }
+ }
+ return dedup;
+ }
}
diff --git a/minerva-converter/src/main/java/org/geneontology/minerva/explanation/Explanation.java b/minerva-converter/src/main/java/org/geneontology/minerva/explanation/Explanation.java
index 0717ba7c..90eee627 100644
--- a/minerva-converter/src/main/java/org/geneontology/minerva/explanation/Explanation.java
+++ b/minerva-converter/src/main/java/org/geneontology/minerva/explanation/Explanation.java
@@ -3,32 +3,33 @@
import java.util.Arrays;
public class Explanation {
-
- public String[] triples;
- public String[] rules;
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + Arrays.hashCode(rules);
- result = prime * result + Arrays.hashCode(triples);
- return result;
- }
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (getClass() != obj.getClass())
- return false;
- Explanation other = (Explanation) obj;
- if (!Arrays.equals(rules, other.rules))
- return false;
- if (!Arrays.equals(triples, other.triples))
- return false;
- return true;
- }
+
+ public String[] triples;
+ public String[] rules;
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + Arrays.hashCode(rules);
+ result = prime * result + Arrays.hashCode(triples);
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ Explanation other = (Explanation) obj;
+ if (!Arrays.equals(rules, other.rules))
+ return false;
+ if (!Arrays.equals(triples, other.triples))
+ return false;
+ return true;
+ }
}
diff --git a/minerva-converter/src/main/java/org/geneontology/minerva/explanation/ExplanationRule.java b/minerva-converter/src/main/java/org/geneontology/minerva/explanation/ExplanationRule.java
index e01c8805..01a86e53 100644
--- a/minerva-converter/src/main/java/org/geneontology/minerva/explanation/ExplanationRule.java
+++ b/minerva-converter/src/main/java/org/geneontology/minerva/explanation/ExplanationRule.java
@@ -1,44 +1,45 @@
package org.geneontology.minerva.explanation;
-import java.util.Arrays;
-
import com.google.gson.annotations.SerializedName;
+import java.util.Arrays;
+
public class ExplanationRule {
-
- @SerializedName("@id")
- public String id;
- public ExplanationTriple[] body;
- public ExplanationTriple[] head;
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + Arrays.hashCode(body);
- result = prime * result + Arrays.hashCode(head);
- result = prime * result + ((id == null) ? 0 : id.hashCode());
- return result;
- }
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (getClass() != obj.getClass())
- return false;
- ExplanationRule other = (ExplanationRule) obj;
- if (!Arrays.equals(body, other.body))
- return false;
- if (!Arrays.equals(head, other.head))
- return false;
- if (id == null) {
- if (other.id != null)
- return false;
- } else if (!id.equals(other.id))
- return false;
- return true;
- }
+
+ @SerializedName("@id")
+ public String id;
+ public ExplanationTriple[] body;
+ public ExplanationTriple[] head;
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + Arrays.hashCode(body);
+ result = prime * result + Arrays.hashCode(head);
+ result = prime * result + ((id == null) ? 0 : id.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ ExplanationRule other = (ExplanationRule) obj;
+ if (!Arrays.equals(body, other.body))
+ return false;
+ if (!Arrays.equals(head, other.head))
+ return false;
+ if (id == null) {
+ if (other.id != null)
+ return false;
+ } else if (!id.equals(other.id))
+ return false;
+ return true;
+ }
}
diff --git a/minerva-converter/src/main/java/org/geneontology/minerva/explanation/ExplanationTerm.java b/minerva-converter/src/main/java/org/geneontology/minerva/explanation/ExplanationTerm.java
index 0a3255f9..417758a6 100644
--- a/minerva-converter/src/main/java/org/geneontology/minerva/explanation/ExplanationTerm.java
+++ b/minerva-converter/src/main/java/org/geneontology/minerva/explanation/ExplanationTerm.java
@@ -3,41 +3,41 @@
import com.google.gson.annotations.SerializedName;
public class ExplanationTerm {
-
- @SerializedName("@id")
- public String id;
- public String label;
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((id == null) ? 0 : id.hashCode());
- result = prime * result + ((label == null) ? 0 : label.hashCode());
- return result;
- }
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (getClass() != obj.getClass())
- return false;
- ExplanationTerm other = (ExplanationTerm) obj;
- if (id == null) {
- if (other.id != null)
- return false;
- } else if (!id.equals(other.id))
- return false;
- if (label == null) {
- if (other.label != null)
- return false;
- } else if (!label.equals(other.label))
- return false;
- return true;
- }
-
-
+
+ @SerializedName("@id")
+ public String id;
+ public String label;
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((id == null) ? 0 : id.hashCode());
+ result = prime * result + ((label == null) ? 0 : label.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ ExplanationTerm other = (ExplanationTerm) obj;
+ if (id == null) {
+ if (other.id != null)
+ return false;
+ } else if (!id.equals(other.id))
+ return false;
+ if (label == null) {
+ if (other.label != null)
+ return false;
+ } else if (!label.equals(other.label))
+ return false;
+ return true;
+ }
+
}
diff --git a/minerva-converter/src/main/java/org/geneontology/minerva/explanation/ExplanationTriple.java b/minerva-converter/src/main/java/org/geneontology/minerva/explanation/ExplanationTriple.java
index 5284fa67..a7b725a7 100644
--- a/minerva-converter/src/main/java/org/geneontology/minerva/explanation/ExplanationTriple.java
+++ b/minerva-converter/src/main/java/org/geneontology/minerva/explanation/ExplanationTriple.java
@@ -3,60 +3,61 @@
import com.google.gson.annotations.SerializedName;
public class ExplanationTriple {
-
- @SerializedName("@id")
- public String id;
- public String subject;
- public String predicate;
- public String object;
- public Explanation explanation;
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((explanation == null) ? 0 : explanation.hashCode());
- result = prime * result + ((id == null) ? 0 : id.hashCode());
- result = prime * result + ((object == null) ? 0 : object.hashCode());
- result = prime * result + ((predicate == null) ? 0 : predicate.hashCode());
- result = prime * result + ((subject == null) ? 0 : subject.hashCode());
- return result;
- }
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (getClass() != obj.getClass())
- return false;
- ExplanationTriple other = (ExplanationTriple) obj;
- if (explanation == null) {
- if (other.explanation != null)
- return false;
- } else if (!explanation.equals(other.explanation))
- return false;
- if (id == null) {
- if (other.id != null)
- return false;
- } else if (!id.equals(other.id))
- return false;
- if (object == null) {
- if (other.object != null)
- return false;
- } else if (!object.equals(other.object))
- return false;
- if (predicate == null) {
- if (other.predicate != null)
- return false;
- } else if (!predicate.equals(other.predicate))
- return false;
- if (subject == null) {
- if (other.subject != null)
- return false;
- } else if (!subject.equals(other.subject))
- return false;
- return true;
- }
+
+ @SerializedName("@id")
+ public String id;
+ public String subject;
+ public String predicate;
+ public String object;
+ public Explanation explanation;
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((explanation == null) ? 0 : explanation.hashCode());
+ result = prime * result + ((id == null) ? 0 : id.hashCode());
+ result = prime * result + ((object == null) ? 0 : object.hashCode());
+ result = prime * result + ((predicate == null) ? 0 : predicate.hashCode());
+ result = prime * result + ((subject == null) ? 0 : subject.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ ExplanationTriple other = (ExplanationTriple) obj;
+ if (explanation == null) {
+ if (other.explanation != null)
+ return false;
+ } else if (!explanation.equals(other.explanation))
+ return false;
+ if (id == null) {
+ if (other.id != null)
+ return false;
+ } else if (!id.equals(other.id))
+ return false;
+ if (object == null) {
+ if (other.object != null)
+ return false;
+ } else if (!object.equals(other.object))
+ return false;
+ if (predicate == null) {
+ if (other.predicate != null)
+ return false;
+ } else if (!predicate.equals(other.predicate))
+ return false;
+ if (subject == null) {
+ if (other.subject != null)
+ return false;
+ } else if (!subject.equals(other.subject))
+ return false;
+ return true;
+ }
}
diff --git a/minerva-converter/src/main/java/org/geneontology/minerva/explanation/ModelExplanation.java b/minerva-converter/src/main/java/org/geneontology/minerva/explanation/ModelExplanation.java
index 530d458f..6b4d17cb 100644
--- a/minerva-converter/src/main/java/org/geneontology/minerva/explanation/ModelExplanation.java
+++ b/minerva-converter/src/main/java/org/geneontology/minerva/explanation/ModelExplanation.java
@@ -3,40 +3,41 @@
import java.util.Arrays;
public class ModelExplanation {
-
- public ExplanationTerm[] terms;
- public ExplanationTriple[] assertions;
- public ExplanationTriple[] inferences;
- public ExplanationRule[] rules;
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + Arrays.hashCode(assertions);
- result = prime * result + Arrays.hashCode(inferences);
- result = prime * result + Arrays.hashCode(rules);
- result = prime * result + Arrays.hashCode(terms);
- return result;
- }
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (getClass() != obj.getClass())
- return false;
- ModelExplanation other = (ModelExplanation) obj;
- if (!Arrays.equals(assertions, other.assertions))
- return false;
- if (!Arrays.equals(inferences, other.inferences))
- return false;
- if (!Arrays.equals(rules, other.rules))
- return false;
- if (!Arrays.equals(terms, other.terms))
- return false;
- return true;
- }
+
+ public ExplanationTerm[] terms;
+ public ExplanationTriple[] assertions;
+ public ExplanationTriple[] inferences;
+ public ExplanationRule[] rules;
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + Arrays.hashCode(assertions);
+ result = prime * result + Arrays.hashCode(inferences);
+ result = prime * result + Arrays.hashCode(rules);
+ result = prime * result + Arrays.hashCode(terms);
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ ModelExplanation other = (ModelExplanation) obj;
+ if (!Arrays.equals(assertions, other.assertions))
+ return false;
+ if (!Arrays.equals(inferences, other.inferences))
+ return false;
+ if (!Arrays.equals(rules, other.rules))
+ return false;
+ if (!Arrays.equals(terms, other.terms))
+ return false;
+ return true;
+ }
}
diff --git a/minerva-converter/src/main/java/org/geneontology/minerva/legacy/LegoModelWalker.java b/minerva-converter/src/main/java/org/geneontology/minerva/legacy/LegoModelWalker.java
index fcefd33e..d288084a 100644
--- a/minerva-converter/src/main/java/org/geneontology/minerva/legacy/LegoModelWalker.java
+++ b/minerva-converter/src/main/java/org/geneontology/minerva/legacy/LegoModelWalker.java
@@ -1,448 +1,417 @@
package org.geneontology.minerva.legacy;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
import org.geneontology.minerva.MinervaOWLGraphWrapper;
import org.geneontology.minerva.MolecularModelManager.UnknownIdentifierException;
import org.geneontology.minerva.lookup.ExternalLookupService;
import org.geneontology.minerva.util.AnnotationShorthand;
import org.obolibrary.obo2owl.Obo2OWLConstants;
-import org.semanticweb.owlapi.model.AxiomType;
-import org.semanticweb.owlapi.model.IRI;
-import org.semanticweb.owlapi.model.OWLAnnotation;
-import org.semanticweb.owlapi.model.OWLAnnotationAssertionAxiom;
-import org.semanticweb.owlapi.model.OWLAnnotationProperty;
-import org.semanticweb.owlapi.model.OWLAnnotationValue;
-import org.semanticweb.owlapi.model.OWLAnnotationValueVisitorEx;
-import org.semanticweb.owlapi.model.OWLAnonymousIndividual;
-import org.semanticweb.owlapi.model.OWLClass;
-import org.semanticweb.owlapi.model.OWLClassAssertionAxiom;
-import org.semanticweb.owlapi.model.OWLClassExpression;
-import org.semanticweb.owlapi.model.OWLDataFactory;
-import org.semanticweb.owlapi.model.OWLIndividual;
-import org.semanticweb.owlapi.model.OWLLiteral;
-import org.semanticweb.owlapi.model.OWLNamedIndividual;
-import org.semanticweb.owlapi.model.OWLObjectProperty;
-import org.semanticweb.owlapi.model.OWLObjectPropertyAssertionAxiom;
-import org.semanticweb.owlapi.model.OWLObjectPropertyExpression;
-import org.semanticweb.owlapi.model.OWLObjectSomeValuesFrom;
-import org.semanticweb.owlapi.model.OWLOntology;
+import org.semanticweb.owlapi.model.*;
import org.semanticweb.owlapi.util.OWLClassExpressionVisitorAdapter;
-
import owltools.vocab.OBOUpperVocabulary;
+import java.util.*;
+
abstract class LegoModelWalker {
- protected final OWLObjectProperty partOf;
- protected final OWLObjectProperty occursIn;
- protected final OWLObjectProperty enabledBy;
- protected final OWLObjectProperty hasSupportingRef;
- protected final OWLObjectProperty withSupportFrom;
-
- protected final OWLAnnotationProperty source_old;
- protected final OWLAnnotationProperty contributor;
- protected final OWLAnnotationProperty group;
- protected final OWLAnnotationProperty date;
- protected final OWLAnnotationProperty evidenceOld;
- protected final OWLAnnotationProperty axiomHasEvidence;
- protected final OWLAnnotationProperty with_old;
-
- private final OWLAnnotationProperty shortIdProp;
-
- protected final OWLDataFactory f;
-
- protected LegoModelWalker(OWLDataFactory df) {
- this.f = df;
-
- partOf = OBOUpperVocabulary.BFO_part_of.getObjectProperty(f);
- occursIn = OBOUpperVocabulary.BFO_occurs_in.getObjectProperty(f);
-
- enabledBy = OBOUpperVocabulary.GOREL_enabled_by.getObjectProperty(f);
-
- shortIdProp = df.getOWLAnnotationProperty(IRI.create(Obo2OWLConstants.OIOVOCAB_IRI_PREFIX+"id"));
-
- contributor = f.getOWLAnnotationProperty(AnnotationShorthand.contributor.getAnnotationProperty());
- date = f.getOWLAnnotationProperty(AnnotationShorthand.date.getAnnotationProperty());
- group = f.getOWLAnnotationProperty(IRI.create("http://geneontology.org/lego/group")); // TODO place holder
-
- axiomHasEvidence = f.getOWLAnnotationProperty(IRI.create("http://purl.obolibrary.org/obo/RO_0002612"));
- hasSupportingRef = f.getOWLObjectProperty(IRI.create("http://purl.obolibrary.org/obo/SEPIO_0000124"));
- withSupportFrom = f.getOWLObjectProperty(IRI.create("http://purl.obolibrary.org/obo/RO_0002614"));
-
- evidenceOld = f.getOWLAnnotationProperty(IRI.create("http://geneontology.org/lego/evidence"));
- source_old = f.getOWLAnnotationProperty(AnnotationShorthand.source.getAnnotationProperty());
- with_old = f.getOWLAnnotationProperty(IRI.create("http://geneontology.org/lego/evidence-with"));
- }
-
- protected static class Entry {
- T value;
- Metadata metadata;
- List evidences;
- Set expressions;
- // TODO multi-species interactions
- }
-
- protected static class Evidence {
- OWLClass evidenceCls = null;
- String source = null;
- String with = null;
-
- Evidence copy() {
- Evidence evidence = new Evidence();
- evidence.evidenceCls = this.evidenceCls;
- evidence.source = this.source;
- evidence.with = this.with;
- return evidence;
- }
- }
-
- protected static class Metadata {
-
- String modelId = null;
- Set individualIds = null;
- Set contributors = null;
- Set groups = null;
- String date = null;
- }
-
- public void walkModel(OWLOntology model, ExternalLookupService lookup, Collection allPayloads) throws UnknownIdentifierException {
- final MinervaOWLGraphWrapper modelGraph = new MinervaOWLGraphWrapper(model);
-
- String modelId = null;
- for(OWLAnnotation modelAnnotation : model.getAnnotations()) {
- if (shortIdProp.equals(modelAnnotation.getProperty())) {
- modelId = modelAnnotation.getValue().accept(new OWLAnnotationValueVisitorEx() {
-
- @Override
- public String visit(IRI iri) {
- return null;
- }
-
- @Override
- public String visit(OWLAnonymousIndividual individual) {
- return null;
- }
-
- @Override
- public String visit(OWLLiteral literal) {
- return literal.getLiteral();
- }
- });
- }
- }
-
- final Set annotationIndividuals = new HashSet();
- final Map evidenceIndividuals = new HashMap();
-
- for(OWLNamedIndividual individual : model.getIndividualsInSignature()) {
- Set individualTypes = getTypes(individual, model);
- OWLClass eco = getEco(individualTypes);
- if (eco != null) {
- // is eco
- Evidence evidence = assembleEvidence(individual, eco, model);
- evidenceIndividuals.put(individual.getIRI(), evidence);
- }
- else if (isAnnotationIndividual(individual, individualTypes)) {
- annotationIndividuals.add(individual);
- }
- }
-
- final Map allMetadata = new HashMap();
- for(OWLNamedIndividual individual : annotationIndividuals) {
- Metadata metadata = extractMetadata(individual, modelGraph, modelId);
- allMetadata.put(individual, metadata);
- }
-
- for (OWLObjectPropertyAssertionAxiom axiom : model.getAxioms(AxiomType.OBJECT_PROPERTY_ASSERTION)) {
- final OWLObjectPropertyExpression p = axiom.getProperty();
- if (enabledBy.equals(p)) {
- // gene/protein/complex
- final OWLNamedIndividual object = axiom.getObject().asOWLNamedIndividual();
- Set expressions = getSvfTypes(object, model);
- Set objectTypes = getTypes(object, model);
- for (OWLClass objectType : objectTypes) {
- final PAYLOAD payload = initPayload(object, objectType, model, modelGraph, lookup);
- allPayloads.add(payload);
-
- final OWLNamedIndividual subject = axiom.getSubject().asOWLNamedIndividual();
-
- // get associated meta data
- final Metadata linkMetadata = extractMetadata(axiom.getAnnotations(), modelGraph, modelId);
- final Set linkEvidences = getEvidences(axiom, evidenceIndividuals);
-
- // get all OWLObjectPropertyAssertionAxiom for subject
- Set subjectAxioms = model.getObjectPropertyAssertionAxioms(subject);
- for(OWLObjectPropertyAssertionAxiom current : subjectAxioms) {
- final Metadata currentMetadata = extractMetadata(current.getAnnotations(), modelGraph, modelId);
- final Set currentEvidences = getEvidences(current, evidenceIndividuals);
- final OWLObjectPropertyExpression currentP = current.getProperty();
- final OWLNamedIndividual currentObj = current.getObject().asOWLNamedIndividual();
-
- if (occursIn.equals(currentP)) {
- // check for cc for subject (occurs in)
- for(OWLClass cls : getTypes(currentObj, model)) {
- boolean added = handleCC(payload, cls, currentMetadata, currentEvidences, getExpressions(currentObj, model));
- if (!added) {
- expressions.add(createSvf(occursIn, cls));
- }
- }
- }
- else if (partOf.equals(currentP)) {
- // check for bp for subject (part_of)
- for(OWLClass cls : getTypes(currentObj, model)) {
- boolean added = handleBP(payload, cls, currentMetadata, currentEvidences, getExpressions(currentObj, model));;
- if (!added) {
- expressions.add(createSvf(partOf, cls));
- }
- }
-
- }else if (enabledBy.equals(currentP)) {
- // do nothing
- }
- else {
- Set types = getTypes(currentObj, model);
- for (OWLClass cls : types) {
- expressions.add(createSvf(currentP, cls));
- }
- }
- }
-
- // handle types
- for(OWLClass cls : getTypes(subject, model)) {
- handleMF(payload, cls, linkMetadata, linkEvidences, expressions);
- }
- }
- }
- }
- }
-
- private Evidence assembleEvidence(OWLNamedIndividual individual, OWLClass eco, OWLOntology model) {
- Evidence evidence = new Evidence();
- evidence.evidenceCls = eco;
- evidence.source = null;
- evidence.with = null;
- Set evidenceLinks = model.getObjectPropertyAssertionAxioms(individual);
- for(OWLObjectPropertyAssertionAxiom ax : evidenceLinks) {
- OWLObjectPropertyExpression p = ax.getProperty();
- if (hasSupportingRef.equals(p)) {
- OWLIndividual object = ax.getObject();
- if (object.isNamed()) {
- OWLNamedIndividual namedIndividual = object.asOWLNamedIndividual();
- evidence.source = getShortHand(namedIndividual.getIRI());
- }
- }
- else if (withSupportFrom.equals(p)) {
- OWLIndividual object = ax.getObject();
- if (object.isNamed()) {
- Set types = getTypes(object.asOWLNamedIndividual(), model);
- for (OWLClass cls : types) {
- evidence.with = getShortHand(cls.getIRI());
- }
- }
- }
- }
- if (evidence.source == null) {
- // check old type of modelling as annotations
- for (OWLAnnotationAssertionAxiom annotation : model.getAnnotationAssertionAxioms(individual.getIRI())) {
- OWLAnnotationProperty p = annotation.getProperty();
- if (source_old.equals(p)) {
- evidence.source = getStringValue(annotation);
- }
- else if (with_old.equals(p)) {
- evidence.with = getStringValue(annotation);
- }
- }
- }
-
- return evidence;
- }
-
- private String getStringValue(OWLAnnotationAssertionAxiom ax) {
- OWLAnnotationValue value = ax.getValue();
- String stringValue = value.accept(new OWLAnnotationValueVisitorEx() {
-
- @Override
- public String visit(IRI iri) {
- return iri.toString();
- }
-
- @Override
- public String visit(OWLAnonymousIndividual individual) {
- return null;
- }
-
- @Override
- public String visit(OWLLiteral literal) {
- return literal.getLiteral();
- }
- });
- return stringValue;
- }
-
- private Set getEvidences(OWLObjectPropertyAssertionAxiom axiom, Map evidenceIndividuals) {
- Set evidences = new HashSet<>();
- for (OWLAnnotation annotation : axiom.getAnnotations()) {
- OWLAnnotationProperty property = annotation.getProperty();
- if (evidenceOld.equals(property) || hasSupportingRef.equals(property)) {
- IRI iri = annotation.getValue().accept(new OWLAnnotationValueVisitorEx() {
-
- @Override
- public IRI visit(IRI iri) {
- return iri;
- }
-
- @Override
- public IRI visit(OWLAnonymousIndividual individual) {
- return null;
- }
-
- @Override
- public IRI visit(OWLLiteral literal) {
- return null;
- }
- });
- if (iri != null) {
- Evidence evidence = evidenceIndividuals.get(iri);
- if (evidence != null) {
- evidences.add(evidence);
- }
- }
- }
- }
- return evidences;
- }
-
- private Set getSvfTypes(OWLNamedIndividual i, OWLOntology model) {
- Set axioms = model.getClassAssertionAxioms(i);
- final Set svfs = new HashSet();
- for (OWLClassAssertionAxiom axiom : axioms) {
- axiom.getClassExpression().accept(new OWLClassExpressionVisitorAdapter(){
-
- @Override
- public void visit(OWLObjectSomeValuesFrom svf) {
- svfs.add(svf);
- }
- });
- }
- return svfs;
- }
-
- protected abstract boolean isEco(OWLClass cls);
-
- protected abstract boolean isAnnotationIndividual(OWLNamedIndividual i, Set types);
-
- private OWLClass getEco(Set set) {
- for (OWLClass cls : set) {
- if (isEco(cls)) {
- return cls;
- }
- }
- return null;
- }
-
- private Set getTypes(OWLNamedIndividual i, OWLOntology model) {
- Set axioms = model.getClassAssertionAxioms(i);
- Set types = new HashSet();
- for (OWLClassAssertionAxiom axiom : axioms) {
- OWLClassExpression ce = axiom.getClassExpression();
- if (ce instanceof OWLClass) {
- OWLClass cls = ce.asOWLClass();
- if (cls.isBuiltIn() == false) {
- types.add(cls);
- }
- }
- }
- return types;
- }
-
- private Set getExpressions(OWLNamedIndividual i, OWLOntology model) {
- Set result = new HashSet();
- Set axioms = model.getObjectPropertyAssertionAxioms(i);
- for (OWLObjectPropertyAssertionAxiom ax : axioms) {
- if (enabledBy.equals(ax.getProperty())) {
- continue;
- }
- OWLIndividual object = ax.getObject();
- if (object.isNamed()) {
- Set types = getTypes(object.asOWLNamedIndividual(), model);
- for (OWLClass cls : types) {
- result.add(createSvf(ax.getProperty(), cls));
- }
- }
- }
- return result;
- }
-
- protected abstract PAYLOAD initPayload(OWLNamedIndividual object, OWLClass objectType, OWLOntology model, MinervaOWLGraphWrapper modelGraph, ExternalLookupService lookup) throws UnknownIdentifierException;
-
- protected abstract boolean handleCC(PAYLOAD payload, OWLClass cls, Metadata metadata, Set evidences, Set expressions);
-
- protected abstract boolean handleMF(PAYLOAD payload, OWLClass cls, Metadata metadata, Set evidences, Set expressions);
-
- protected abstract boolean handleBP(PAYLOAD payload, OWLClass cls, Metadata metadata, Set evidences, Set expressions);
-
- protected abstract String getShortHand(IRI iri);
-
- private OWLObjectSomeValuesFrom createSvf(OWLObjectPropertyExpression p, OWLClass c) {
- return f.getOWLObjectSomeValuesFrom(p, c);
- }
-
- private Metadata extractMetadata(OWLNamedIndividual individual, MinervaOWLGraphWrapper modelGraph, String modelId) {
- Metadata metadata = new Metadata();
- metadata.modelId = modelId;
- metadata.individualIds = new HashSet();
- metadata.individualIds.add(individual.getIRI());
- Set assertionAxioms = modelGraph.getSourceOntology().getAnnotationAssertionAxioms(individual.getIRI());
- for (OWLAnnotationAssertionAxiom axiom : assertionAxioms) {
- OWLAnnotationProperty currentProperty = axiom.getProperty();
- OWLAnnotationValue value = axiom.getValue();
- extractMetadata(currentProperty, value, metadata);
- }
- return metadata;
- }
-
- private void extractMetadata(OWLAnnotationProperty p, OWLAnnotationValue v, final Metadata metadata) {
- if (this.contributor.equals(p)) {
- if (v instanceof OWLLiteral) {
- String contributor = ((OWLLiteral) v).getLiteral();
- if (metadata.contributors == null) {
- metadata.contributors = new HashSet<>();
- }
- metadata.contributors.add(contributor);
- }
- }
- else if (this.date.equals(p)) {
- if (v instanceof OWLLiteral) {
- metadata.date = ((OWLLiteral) v).getLiteral();
- }
- }
- else if (this.group.equals(p)) {
- if (v instanceof OWLLiteral) {
- String group = ((OWLLiteral) v).getLiteral();
- if(metadata.groups == null) {
- metadata.groups = new HashSet<>();
- }
- metadata.groups.add(group);
- }
- }
- }
-
- private Metadata extractMetadata(Collection annotations, MinervaOWLGraphWrapper modelGraph, String modelId) {
- Metadata metadata = new Metadata();
- metadata.modelId = modelId;
- if (annotations != null && !annotations.isEmpty()) {
- for (OWLAnnotation owlAnnotation : annotations) {
- OWLAnnotationProperty currentProperty = owlAnnotation.getProperty();
- OWLAnnotationValue value = owlAnnotation.getValue();
- extractMetadata(currentProperty, value, metadata);
- }
- }
- return metadata;
- }
+ protected final OWLObjectProperty partOf;
+ protected final OWLObjectProperty occursIn;
+ protected final OWLObjectProperty enabledBy;
+ protected final OWLObjectProperty hasSupportingRef;
+ protected final OWLObjectProperty withSupportFrom;
+
+ protected final OWLAnnotationProperty source_old;
+ protected final OWLAnnotationProperty contributor;
+ protected final OWLAnnotationProperty group;
+ protected final OWLAnnotationProperty date;
+ protected final OWLAnnotationProperty evidenceOld;
+ protected final OWLAnnotationProperty axiomHasEvidence;
+ protected final OWLAnnotationProperty with_old;
+
+ private final OWLAnnotationProperty shortIdProp;
+
+ protected final OWLDataFactory f;
+
+ protected LegoModelWalker(OWLDataFactory df) {
+ this.f = df;
+
+ partOf = OBOUpperVocabulary.BFO_part_of.getObjectProperty(f);
+ occursIn = OBOUpperVocabulary.BFO_occurs_in.getObjectProperty(f);
+
+ enabledBy = OBOUpperVocabulary.GOREL_enabled_by.getObjectProperty(f);
+
+ shortIdProp = df.getOWLAnnotationProperty(IRI.create(Obo2OWLConstants.OIOVOCAB_IRI_PREFIX + "id"));
+
+ contributor = f.getOWLAnnotationProperty(AnnotationShorthand.contributor.getAnnotationProperty());
+ date = f.getOWLAnnotationProperty(AnnotationShorthand.date.getAnnotationProperty());
+ group = f.getOWLAnnotationProperty(IRI.create("http://geneontology.org/lego/group")); // TODO place holder
+
+ axiomHasEvidence = f.getOWLAnnotationProperty(IRI.create("http://purl.obolibrary.org/obo/RO_0002612"));
+ hasSupportingRef = f.getOWLObjectProperty(IRI.create("http://purl.obolibrary.org/obo/SEPIO_0000124"));
+ withSupportFrom = f.getOWLObjectProperty(IRI.create("http://purl.obolibrary.org/obo/RO_0002614"));
+
+ evidenceOld = f.getOWLAnnotationProperty(IRI.create("http://geneontology.org/lego/evidence"));
+ source_old = f.getOWLAnnotationProperty(AnnotationShorthand.source.getAnnotationProperty());
+ with_old = f.getOWLAnnotationProperty(IRI.create("http://geneontology.org/lego/evidence-with"));
+ }
+
+ protected static class Entry {
+ T value;
+ Metadata metadata;
+ List evidences;
+ Set expressions;
+ // TODO multi-species interactions
+ }
+
+ protected static class Evidence {
+ OWLClass evidenceCls = null;
+ String source = null;
+ String with = null;
+
+ Evidence copy() {
+ Evidence evidence = new Evidence();
+ evidence.evidenceCls = this.evidenceCls;
+ evidence.source = this.source;
+ evidence.with = this.with;
+ return evidence;
+ }
+ }
+
+ protected static class Metadata {
+
+ String modelId = null;
+ Set individualIds = null;
+ Set contributors = null;
+ Set groups = null;
+ String date = null;
+ }
+
+ public void walkModel(OWLOntology model, ExternalLookupService lookup, Collection allPayloads) throws UnknownIdentifierException {
+ final MinervaOWLGraphWrapper modelGraph = new MinervaOWLGraphWrapper(model);
+
+ String modelId = null;
+ for (OWLAnnotation modelAnnotation : model.getAnnotations()) {
+ if (shortIdProp.equals(modelAnnotation.getProperty())) {
+ modelId = modelAnnotation.getValue().accept(new OWLAnnotationValueVisitorEx() {
+
+ @Override
+ public String visit(IRI iri) {
+ return null;
+ }
+
+ @Override
+ public String visit(OWLAnonymousIndividual individual) {
+ return null;
+ }
+
+ @Override
+ public String visit(OWLLiteral literal) {
+ return literal.getLiteral();
+ }
+ });
+ }
+ }
+
+ final Set annotationIndividuals = new HashSet();
+ final Map evidenceIndividuals = new HashMap();
+
+ for (OWLNamedIndividual individual : model.getIndividualsInSignature()) {
+ Set individualTypes = getTypes(individual, model);
+ OWLClass eco = getEco(individualTypes);
+ if (eco != null) {
+ // is eco
+ Evidence evidence = assembleEvidence(individual, eco, model);
+ evidenceIndividuals.put(individual.getIRI(), evidence);
+ } else if (isAnnotationIndividual(individual, individualTypes)) {
+ annotationIndividuals.add(individual);
+ }
+ }
+
+ final Map allMetadata = new HashMap();
+ for (OWLNamedIndividual individual : annotationIndividuals) {
+ Metadata metadata = extractMetadata(individual, modelGraph, modelId);
+ allMetadata.put(individual, metadata);
+ }
+
+ for (OWLObjectPropertyAssertionAxiom axiom : model.getAxioms(AxiomType.OBJECT_PROPERTY_ASSERTION)) {
+ final OWLObjectPropertyExpression p = axiom.getProperty();
+ if (enabledBy.equals(p)) {
+ // gene/protein/complex
+ final OWLNamedIndividual object = axiom.getObject().asOWLNamedIndividual();
+ Set expressions = getSvfTypes(object, model);
+ Set objectTypes = getTypes(object, model);
+ for (OWLClass objectType : objectTypes) {
+ final PAYLOAD payload = initPayload(object, objectType, model, modelGraph, lookup);
+ allPayloads.add(payload);
+
+ final OWLNamedIndividual subject = axiom.getSubject().asOWLNamedIndividual();
+
+ // get associated meta data
+ final Metadata linkMetadata = extractMetadata(axiom.getAnnotations(), modelGraph, modelId);
+ final Set linkEvidences = getEvidences(axiom, evidenceIndividuals);
+
+ // get all OWLObjectPropertyAssertionAxiom for subject
+ Set subjectAxioms = model.getObjectPropertyAssertionAxioms(subject);
+ for (OWLObjectPropertyAssertionAxiom current : subjectAxioms) {
+ final Metadata currentMetadata = extractMetadata(current.getAnnotations(), modelGraph, modelId);
+ final Set currentEvidences = getEvidences(current, evidenceIndividuals);
+ final OWLObjectPropertyExpression currentP = current.getProperty();
+ final OWLNamedIndividual currentObj = current.getObject().asOWLNamedIndividual();
+
+ if (occursIn.equals(currentP)) {
+ // check for cc for subject (occurs in)
+ for (OWLClass cls : getTypes(currentObj, model)) {
+ boolean added = handleCC(payload, cls, currentMetadata, currentEvidences, getExpressions(currentObj, model));
+ if (!added) {
+ expressions.add(createSvf(occursIn, cls));
+ }
+ }
+ } else if (partOf.equals(currentP)) {
+ // check for bp for subject (part_of)
+ for (OWLClass cls : getTypes(currentObj, model)) {
+ boolean added = handleBP(payload, cls, currentMetadata, currentEvidences, getExpressions(currentObj, model));
+ ;
+ if (!added) {
+ expressions.add(createSvf(partOf, cls));
+ }
+ }
+
+ } else if (enabledBy.equals(currentP)) {
+ // do nothing
+ } else {
+ Set types = getTypes(currentObj, model);
+ for (OWLClass cls : types) {
+ expressions.add(createSvf(currentP, cls));
+ }
+ }
+ }
+
+ // handle types
+ for (OWLClass cls : getTypes(subject, model)) {
+ handleMF(payload, cls, linkMetadata, linkEvidences, expressions);
+ }
+ }
+ }
+ }
+ }
+
+ private Evidence assembleEvidence(OWLNamedIndividual individual, OWLClass eco, OWLOntology model) {
+ Evidence evidence = new Evidence();
+ evidence.evidenceCls = eco;
+ evidence.source = null;
+ evidence.with = null;
+ Set evidenceLinks = model.getObjectPropertyAssertionAxioms(individual);
+ for (OWLObjectPropertyAssertionAxiom ax : evidenceLinks) {
+ OWLObjectPropertyExpression p = ax.getProperty();
+ if (hasSupportingRef.equals(p)) {
+ OWLIndividual object = ax.getObject();
+ if (object.isNamed()) {
+ OWLNamedIndividual namedIndividual = object.asOWLNamedIndividual();
+ evidence.source = getShortHand(namedIndividual.getIRI());
+ }
+ } else if (withSupportFrom.equals(p)) {
+ OWLIndividual object = ax.getObject();
+ if (object.isNamed()) {
+ Set types = getTypes(object.asOWLNamedIndividual(), model);
+ for (OWLClass cls : types) {
+ evidence.with = getShortHand(cls.getIRI());
+ }
+ }
+ }
+ }
+ if (evidence.source == null) {
+ // check old type of modelling as annotations
+ for (OWLAnnotationAssertionAxiom annotation : model.getAnnotationAssertionAxioms(individual.getIRI())) {
+ OWLAnnotationProperty p = annotation.getProperty();
+ if (source_old.equals(p)) {
+ evidence.source = getStringValue(annotation);
+ } else if (with_old.equals(p)) {
+ evidence.with = getStringValue(annotation);
+ }
+ }
+ }
+
+ return evidence;
+ }
+
+ private String getStringValue(OWLAnnotationAssertionAxiom ax) {
+ OWLAnnotationValue value = ax.getValue();
+ String stringValue = value.accept(new OWLAnnotationValueVisitorEx() {
+
+ @Override
+ public String visit(IRI iri) {
+ return iri.toString();
+ }
+
+ @Override
+ public String visit(OWLAnonymousIndividual individual) {
+ return null;
+ }
+
+ @Override
+ public String visit(OWLLiteral literal) {
+ return literal.getLiteral();
+ }
+ });
+ return stringValue;
+ }
+
+ private Set getEvidences(OWLObjectPropertyAssertionAxiom axiom, Map evidenceIndividuals) {
+ Set evidences = new HashSet<>();
+ for (OWLAnnotation annotation : axiom.getAnnotations()) {
+ OWLAnnotationProperty property = annotation.getProperty();
+ if (evidenceOld.equals(property) || hasSupportingRef.equals(property)) {
+ IRI iri = annotation.getValue().accept(new OWLAnnotationValueVisitorEx() {
+
+ @Override
+ public IRI visit(IRI iri) {
+ return iri;
+ }
+
+ @Override
+ public IRI visit(OWLAnonymousIndividual individual) {
+ return null;
+ }
+
+ @Override
+ public IRI visit(OWLLiteral literal) {
+ return null;
+ }
+ });
+ if (iri != null) {
+ Evidence evidence = evidenceIndividuals.get(iri);
+ if (evidence != null) {
+ evidences.add(evidence);
+ }
+ }
+ }
+ }
+ return evidences;
+ }
+
+ private Set getSvfTypes(OWLNamedIndividual i, OWLOntology model) {
+ Set axioms = model.getClassAssertionAxioms(i);
+ final Set svfs = new HashSet();
+ for (OWLClassAssertionAxiom axiom : axioms) {
+ axiom.getClassExpression().accept(new OWLClassExpressionVisitorAdapter() {
+
+ @Override
+ public void visit(OWLObjectSomeValuesFrom svf) {
+ svfs.add(svf);
+ }
+ });
+ }
+ return svfs;
+ }
+
+ protected abstract boolean isEco(OWLClass cls);
+
+ protected abstract boolean isAnnotationIndividual(OWLNamedIndividual i, Set types);
+
+ private OWLClass getEco(Set set) {
+ for (OWLClass cls : set) {
+ if (isEco(cls)) {
+ return cls;
+ }
+ }
+ return null;
+ }
+
+ private Set getTypes(OWLNamedIndividual i, OWLOntology model) {
+ Set axioms = model.getClassAssertionAxioms(i);
+ Set types = new HashSet();
+ for (OWLClassAssertionAxiom axiom : axioms) {
+ OWLClassExpression ce = axiom.getClassExpression();
+ if (ce instanceof OWLClass) {
+ OWLClass cls = ce.asOWLClass();
+ if (cls.isBuiltIn() == false) {
+ types.add(cls);
+ }
+ }
+ }
+ return types;
+ }
+
+ private Set getExpressions(OWLNamedIndividual i, OWLOntology model) {
+ Set result = new HashSet();
+ Set axioms = model.getObjectPropertyAssertionAxioms(i);
+ for (OWLObjectPropertyAssertionAxiom ax : axioms) {
+ if (enabledBy.equals(ax.getProperty())) {
+ continue;
+ }
+ OWLIndividual object = ax.getObject();
+ if (object.isNamed()) {
+ Set types = getTypes(object.asOWLNamedIndividual(), model);
+ for (OWLClass cls : types) {
+ result.add(createSvf(ax.getProperty(), cls));
+ }
+ }
+ }
+ return result;
+ }
+
+ protected abstract PAYLOAD initPayload(OWLNamedIndividual object, OWLClass objectType, OWLOntology model, MinervaOWLGraphWrapper modelGraph, ExternalLookupService lookup) throws UnknownIdentifierException;
+
+ protected abstract boolean handleCC(PAYLOAD payload, OWLClass cls, Metadata metadata, Set evidences, Set expressions);
+
+ protected abstract boolean handleMF(PAYLOAD payload, OWLClass cls, Metadata metadata, Set evidences, Set expressions);
+
+ protected abstract boolean handleBP(PAYLOAD payload, OWLClass cls, Metadata metadata, Set evidences, Set expressions);
+
+ protected abstract String getShortHand(IRI iri);
+
+ private OWLObjectSomeValuesFrom createSvf(OWLObjectPropertyExpression p, OWLClass c) {
+ return f.getOWLObjectSomeValuesFrom(p, c);
+ }
+
+ private Metadata extractMetadata(OWLNamedIndividual individual, MinervaOWLGraphWrapper modelGraph, String modelId) {
+ Metadata metadata = new Metadata();
+ metadata.modelId = modelId;
+ metadata.individualIds = new HashSet();
+ metadata.individualIds.add(individual.getIRI());
+ Set assertionAxioms = modelGraph.getSourceOntology().getAnnotationAssertionAxioms(individual.getIRI());
+ for (OWLAnnotationAssertionAxiom axiom : assertionAxioms) {
+ OWLAnnotationProperty currentProperty = axiom.getProperty();
+ OWLAnnotationValue value = axiom.getValue();
+ extractMetadata(currentProperty, value, metadata);
+ }
+ return metadata;
+ }
+
+ private void extractMetadata(OWLAnnotationProperty p, OWLAnnotationValue v, final Metadata metadata) {
+ if (this.contributor.equals(p)) {
+ if (v instanceof OWLLiteral) {
+ String contributor = ((OWLLiteral) v).getLiteral();
+ if (metadata.contributors == null) {
+ metadata.contributors = new HashSet<>();
+ }
+ metadata.contributors.add(contributor);
+ }
+ } else if (this.date.equals(p)) {
+ if (v instanceof OWLLiteral) {
+ metadata.date = ((OWLLiteral) v).getLiteral();
+ }
+ } else if (this.group.equals(p)) {
+ if (v instanceof OWLLiteral) {
+ String group = ((OWLLiteral) v).getLiteral();
+ if (metadata.groups == null) {
+ metadata.groups = new HashSet<>();
+ }
+ metadata.groups.add(group);
+ }
+ }
+ }
+
+ private Metadata extractMetadata(Collection annotations, MinervaOWLGraphWrapper modelGraph, String modelId) {
+ Metadata metadata = new Metadata();
+ metadata.modelId = modelId;
+ if (annotations != null && !annotations.isEmpty()) {
+ for (OWLAnnotation owlAnnotation : annotations) {
+ OWLAnnotationProperty currentProperty = owlAnnotation.getProperty();
+ OWLAnnotationValue value = owlAnnotation.getValue();
+ extractMetadata(currentProperty, value, metadata);
+ }
+ }
+ return metadata;
+ }
}
diff --git a/minerva-converter/src/main/java/org/geneontology/minerva/legacy/sparql/AnnotationExtension.java b/minerva-converter/src/main/java/org/geneontology/minerva/legacy/sparql/AnnotationExtension.java
index a559478b..5536cb2d 100644
--- a/minerva-converter/src/main/java/org/geneontology/minerva/legacy/sparql/AnnotationExtension.java
+++ b/minerva-converter/src/main/java/org/geneontology/minerva/legacy/sparql/AnnotationExtension.java
@@ -1,33 +1,33 @@
package org.geneontology.minerva.legacy.sparql;
-import javax.annotation.Nonnull;
-
import org.apache.jena.graph.Triple;
import org.semanticweb.owlapi.model.IRI;
+import javax.annotation.Nonnull;
+
public class AnnotationExtension {
-
- private final Triple triple;
- private final IRI valueType;
-
- public AnnotationExtension(Triple triple, IRI valueType) {
- this.triple = triple;
- this.valueType = valueType;
- }
-
- @Nonnull
- public Triple getTriple() {
- return triple;
- }
-
- @Nonnull
- public IRI getValueType() {
- return valueType;
- }
-
- @Override
- public String toString() {
- return this.getTriple() + " " + this.getValueType();
- }
+
+ private final Triple triple;
+ private final IRI valueType;
+
+ public AnnotationExtension(Triple triple, IRI valueType) {
+ this.triple = triple;
+ this.valueType = valueType;
+ }
+
+ @Nonnull
+ public Triple getTriple() {
+ return triple;
+ }
+
+ @Nonnull
+ public IRI getValueType() {
+ return valueType;
+ }
+
+ @Override
+ public String toString() {
+ return this.getTriple() + " " + this.getValueType();
+ }
}
diff --git a/minerva-converter/src/main/java/org/geneontology/minerva/legacy/sparql/BasicGPADData.java b/minerva-converter/src/main/java/org/geneontology/minerva/legacy/sparql/BasicGPADData.java
index cd17687c..a352ff82 100644
--- a/minerva-converter/src/main/java/org/geneontology/minerva/legacy/sparql/BasicGPADData.java
+++ b/minerva-converter/src/main/java/org/geneontology/minerva/legacy/sparql/BasicGPADData.java
@@ -4,79 +4,81 @@
import org.semanticweb.owlapi.model.IRI;
public class BasicGPADData {
- private final Node objectNode;
- private final IRI object;
- private GPADOperatorStatus operator;
- private final IRI qualifier;
- private final Node ontologyClassNode;
- private final IRI ontologyClass;
-
- public BasicGPADData(Node objectNode, IRI object, IRI qualifier, Node ontologyClassNode, IRI ontologyClass) {
- this.object = object;
- this.operator = GPADOperatorStatus.NONE;
- this.qualifier = qualifier;
- this.ontologyClass = ontologyClass;
- this.objectNode = objectNode;
- this.ontologyClassNode = ontologyClassNode;
- }
-
- public IRI getObject() {
- return this.object;
- }
+ private final Node objectNode;
+ private final IRI object;
+ private GPADOperatorStatus operator;
+ private final IRI qualifier;
+ private final Node ontologyClassNode;
+ private final IRI ontologyClass;
- public void setOperator(GPADOperatorStatus operator) {
- this.operator = operator;
- }
-
- public GPADOperatorStatus getOperator() {
- return operator;
- }
-
- public IRI getQualifier() {
- return this.qualifier;
- }
+ public BasicGPADData(Node objectNode, IRI object, IRI qualifier, Node ontologyClassNode, IRI ontologyClass) {
+ this.object = object;
+ this.operator = GPADOperatorStatus.NONE;
+ this.qualifier = qualifier;
+ this.ontologyClass = ontologyClass;
+ this.objectNode = objectNode;
+ this.ontologyClassNode = ontologyClassNode;
+ }
- public IRI getOntologyClass() {
- return this.ontologyClass;
- }
+ public IRI getObject() {
+ return this.object;
+ }
- public Node getObjectNode() {
- return this.objectNode;
- }
+ public void setOperator(GPADOperatorStatus operator) {
+ this.operator = operator;
+ }
- public Node getOntologyClassNode() {
- return this.ontologyClassNode;
- }
+ public GPADOperatorStatus getOperator() {
+ return operator;
+ }
- @Override
- public boolean equals(Object other) {
- if (this == other) { return true; }
- else if (!(other instanceof BasicGPADData)) { return false; }
- else {
- BasicGPADData otherData = (BasicGPADData)other;
- return this.getObject().equals(otherData.getObject())
- && this.getOperator().equals(otherData.getOperator())
- && this.getQualifier().equals(otherData.getQualifier())
- && this.getOntologyClass().equals(otherData.getOntologyClass())
- && this.getObjectNode().equals(otherData.getObjectNode())
- && this.getOntologyClassNode().equals(otherData.getOntologyClassNode());
- }
- }
+ public IRI getQualifier() {
+ return this.qualifier;
+ }
- @Override
- public int hashCode() {
- int result = 17;
- result = 37 * result + this.getObject().hashCode();
- result = 37 * result + this.getOperator().hashCode();
- result = 37 * result + this.getQualifier().hashCode();
- result = 37 * result + this.getOntologyClass().hashCode();
- result = 37 * result + this.getObjectNode().hashCode();
- result = 37 * result + this.getOntologyClassNode().hashCode();
- return result;
- }
-
- @Override
- public String toString() {
- return this.object.toString() + ", " + this.operator.toString() + "," + this.qualifier.toString() + ", " + this.ontologyClass.toString();
- }
+ public IRI getOntologyClass() {
+ return this.ontologyClass;
+ }
+
+ public Node getObjectNode() {
+ return this.objectNode;
+ }
+
+ public Node getOntologyClassNode() {
+ return this.ontologyClassNode;
+ }
+
+ @Override
+ public boolean equals(Object other) {
+ if (this == other) {
+ return true;
+ } else if (!(other instanceof BasicGPADData)) {
+ return false;
+ } else {
+ BasicGPADData otherData = (BasicGPADData) other;
+ return this.getObject().equals(otherData.getObject())
+ && this.getOperator().equals(otherData.getOperator())
+ && this.getQualifier().equals(otherData.getQualifier())
+ && this.getOntologyClass().equals(otherData.getOntologyClass())
+ && this.getObjectNode().equals(otherData.getObjectNode())
+ && this.getOntologyClassNode().equals(otherData.getOntologyClassNode());
+ }
+ }
+
+ @Override
+ public int hashCode() {
+ int result = 17;
+ result = 37 * result + this.getObject().hashCode();
+ result = 37 * result + this.getOperator().hashCode();
+ result = 37 * result + this.getQualifier().hashCode();
+ result = 37 * result + this.getOntologyClass().hashCode();
+ result = 37 * result + this.getObjectNode().hashCode();
+ result = 37 * result + this.getOntologyClassNode().hashCode();
+ return result;
+ }
+
+ @Override
+ public String toString() {
+ return this.object.toString() + ", " + this.operator.toString() + "," + this.qualifier.toString() + ", " + this.ontologyClass.toString();
+ }
}
\ No newline at end of file
diff --git a/minerva-converter/src/main/java/org/geneontology/minerva/legacy/sparql/DefaultGPADData.java b/minerva-converter/src/main/java/org/geneontology/minerva/legacy/sparql/DefaultGPADData.java
index 9e70cdd0..a27517c4 100644
--- a/minerva-converter/src/main/java/org/geneontology/minerva/legacy/sparql/DefaultGPADData.java
+++ b/minerva-converter/src/main/java/org/geneontology/minerva/legacy/sparql/DefaultGPADData.java
@@ -1,144 +1,146 @@
package org.geneontology.minerva.legacy.sparql;
-import java.util.Optional;
-import java.util.Set;
-
import org.apache.commons.lang3.tuple.Pair;
import org.semanticweb.owlapi.model.IRI;
+import java.util.Optional;
+import java.util.Set;
+
public class DefaultGPADData implements GPADData {
- private final IRI object;
- private GPADOperatorStatus operator;
- private final IRI qualifier;
- private final IRI ontologyClass;
- private final Set annotationExtensions;
- private final String reference;
- private final IRI evidence;
- private final Optional withOrFrom;
- private final Optional interactingTaxon;
- private final String modificationDate;
- private final String assignedBy;
- private final Set> annotations;
-
- public DefaultGPADData(IRI object, IRI qualifier, IRI ontologyClass, Set annotationExtensions,
- String reference, IRI evidence, Optional withOrFrom, Optional interactingTaxon,
- String modificationDate, String assignedBy, Set> annotations) {
- this.object = object;
- this.qualifier = qualifier;
- this.ontologyClass = ontologyClass;
- this.annotationExtensions = annotationExtensions;
- this.reference = reference;
- this.evidence = evidence;
- this.withOrFrom = withOrFrom;
- this.interactingTaxon = interactingTaxon;
- this.modificationDate = modificationDate;
- this.assignedBy = assignedBy;
- this.annotations = annotations;
- }
-
- @Override
- public IRI getObject() {
- return this.object;
- }
-
- public void setOperator(GPADOperatorStatus operator) {
- this.operator = operator;
- }
-
- @Override
- public GPADOperatorStatus getOperator() {
- return operator;
- }
-
- @Override
- public IRI getQualifier() {
- return this.qualifier;
- }
-
- @Override
- public IRI getOntologyClass() {
- return this.ontologyClass;
- }
-
- @Override
- public Set getAnnotationExtensions() {
- return this.annotationExtensions;
- }
-
-
- @Override
- public String getReference() {
- return this.reference;
- }
-
- @Override
- public IRI getEvidence() {
- return this.evidence;
- }
-
- @Override
- public Optional getWithOrFrom() {
- return this.withOrFrom;
- }
-
- @Override
- public Optional getInteractingTaxonID() {
- return this.interactingTaxon;
- }
-
- @Override
- public String getModificationDate() {
- return this.modificationDate;
- }
-
- @Override
- public String getAssignedBy() {
- return this.assignedBy;
- }
-
- @Override
- public Set> getAnnotations() {
- return this.annotations;
- }
-
- @Override
- public boolean equals(Object other) {
- if (this == other) { return true; }
- else if (!(other instanceof DefaultGPADData)) { return false; }
- else {
- DefaultGPADData otherData = (DefaultGPADData)other;
- return this.getObject().equals(otherData.getObject())
- && this.getOperator().equals(otherData.getOperator())
- && this.getQualifier().equals(otherData.getQualifier())
- && this.getOntologyClass().equals(otherData.getOntologyClass())
- && this.getAnnotationExtensions().equals(otherData.getAnnotationExtensions())
- && this.getReference().equals(otherData.getReference())
- && this.getEvidence().equals(otherData.getEvidence())
- && this.getWithOrFrom().equals(otherData.getWithOrFrom())
- && this.getInteractingTaxonID().equals(otherData.getInteractingTaxonID())
- && this.getModificationDate().equals(otherData.getModificationDate())
- && this.getAssignedBy().equals(otherData.getAssignedBy())
- && this.getAnnotations().equals(otherData.getAnnotations());
- }
- }
-
- @Override
- public int hashCode() {
- int result = 17;
- result = 37 * result + this.getObject().hashCode();
- result = 37 * result + this.getOperator().hashCode();
- result = 37 * result + this.getQualifier().hashCode();
- result = 37 * result + this.getOntologyClass().hashCode();
- result = 37 * result + this.getAnnotationExtensions().hashCode();
- result = 37 * result + this.getReference().hashCode();
- result = 37 * result + this.getEvidence().hashCode();
- result = 37 * result + this.getReference().hashCode();
- result = 37 * result + this.getWithOrFrom().hashCode();
- result = 37 * result + this.getInteractingTaxonID().hashCode();
- result = 37 * result + this.getModificationDate().hashCode();
- result = 37 * result + this.getAssignedBy().hashCode();
- result = 37 * result + this.getAnnotations().hashCode();
- return result;
- }
+ private final IRI object;
+ private GPADOperatorStatus operator;
+ private final IRI qualifier;
+ private final IRI ontologyClass;
+ private final Set annotationExtensions;
+ private final String reference;
+ private final IRI evidence;
+ private final Optional withOrFrom;
+ private final Optional interactingTaxon;
+ private final String modificationDate;
+ private final String assignedBy;
+ private final Set> annotations;
+
+ public DefaultGPADData(IRI object, IRI qualifier, IRI ontologyClass, Set annotationExtensions,
+ String reference, IRI evidence, Optional withOrFrom, Optional interactingTaxon,
+ String modificationDate, String assignedBy, Set> annotations) {
+ this.object = object;
+ this.qualifier = qualifier;
+ this.ontologyClass = ontologyClass;
+ this.annotationExtensions = annotationExtensions;
+ this.reference = reference;
+ this.evidence = evidence;
+ this.withOrFrom = withOrFrom;
+ this.interactingTaxon = interactingTaxon;
+ this.modificationDate = modificationDate;
+ this.assignedBy = assignedBy;
+ this.annotations = annotations;
+ }
+
+ @Override
+ public IRI getObject() {
+ return this.object;
+ }
+
+ public void setOperator(GPADOperatorStatus operator) {
+ this.operator = operator;
+ }
+
+ @Override
+ public GPADOperatorStatus getOperator() {
+ return operator;
+ }
+
+ @Override
+ public IRI getQualifier() {
+ return this.qualifier;
+ }
+
+ @Override
+ public IRI getOntologyClass() {
+ return this.ontologyClass;
+ }
+
+ @Override
+ public Set getAnnotationExtensions() {
+ return this.annotationExtensions;
+ }
+
+
+ @Override
+ public String getReference() {
+ return this.reference;
+ }
+
+ @Override
+ public IRI getEvidence() {
+ return this.evidence;
+ }
+
+ @Override
+ public Optional getWithOrFrom() {
+ return this.withOrFrom;
+ }
+
+ @Override
+ public Optional getInteractingTaxonID() {
+ return this.interactingTaxon;
+ }
+
+ @Override
+ public String getModificationDate() {
+ return this.modificationDate;
+ }
+
+ @Override
+ public String getAssignedBy() {
+ return this.assignedBy;
+ }
+
+ @Override
+ public Set> getAnnotations() {
+ return this.annotations;
+ }
+
+ @Override
+ public boolean equals(Object other) {
+ if (this == other) {
+ return true;
+ } else if (!(other instanceof DefaultGPADData)) {
+ return false;
+ } else {
+ DefaultGPADData otherData = (DefaultGPADData) other;
+ return this.getObject().equals(otherData.getObject())
+ && this.getOperator().equals(otherData.getOperator())
+ && this.getQualifier().equals(otherData.getQualifier())
+ && this.getOntologyClass().equals(otherData.getOntologyClass())
+ && this.getAnnotationExtensions().equals(otherData.getAnnotationExtensions())
+ && this.getReference().equals(otherData.getReference())
+ && this.getEvidence().equals(otherData.getEvidence())
+ && this.getWithOrFrom().equals(otherData.getWithOrFrom())
+ && this.getInteractingTaxonID().equals(otherData.getInteractingTaxonID())
+ && this.getModificationDate().equals(otherData.getModificationDate())
+ && this.getAssignedBy().equals(otherData.getAssignedBy())
+ && this.getAnnotations().equals(otherData.getAnnotations());
+ }
+ }
+
+ @Override
+ public int hashCode() {
+ int result = 17;
+ result = 37 * result + this.getObject().hashCode();
+ result = 37 * result + this.getOperator().hashCode();
+ result = 37 * result + this.getQualifier().hashCode();
+ result = 37 * result + this.getOntologyClass().hashCode();
+ result = 37 * result + this.getAnnotationExtensions().hashCode();
+ result = 37 * result + this.getReference().hashCode();
+ result = 37 * result + this.getEvidence().hashCode();
+ result = 37 * result + this.getReference().hashCode();
+ result = 37 * result + this.getWithOrFrom().hashCode();
+ result = 37 * result + this.getInteractingTaxonID().hashCode();
+ result = 37 * result + this.getModificationDate().hashCode();
+ result = 37 * result + this.getAssignedBy().hashCode();
+ result = 37 * result + this.getAnnotations().hashCode();
+ return result;
+ }
}
diff --git a/minerva-converter/src/main/java/org/geneontology/minerva/legacy/sparql/ExportExplanation.java b/minerva-converter/src/main/java/org/geneontology/minerva/legacy/sparql/ExportExplanation.java
index a4e57f1a..72acd27a 100644
--- a/minerva-converter/src/main/java/org/geneontology/minerva/legacy/sparql/ExportExplanation.java
+++ b/minerva-converter/src/main/java/org/geneontology/minerva/legacy/sparql/ExportExplanation.java
@@ -1,18 +1,7 @@
package org.geneontology.minerva.legacy.sparql;
-import java.io.IOException;
-import java.nio.charset.StandardCharsets;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Optional;
-import java.util.Set;
-import java.util.function.Function;
-import java.util.stream.Collectors;
-import java.util.stream.Stream;
-
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
import org.apache.commons.io.IOUtils;
import org.apache.jena.query.QueryExecution;
import org.apache.jena.query.QueryExecutionFactory;
@@ -26,204 +15,199 @@
import org.geneontology.minerva.explanation.ExplanationTerm;
import org.geneontology.minerva.explanation.ExplanationTriple;
import org.geneontology.minerva.explanation.ModelExplanation;
-import org.geneontology.minerva.lookup.ExternalLookupService;
-import org.geneontology.minerva.lookup.ExternalLookupService.LookupEntry;
-import org.geneontology.rules.engine.Explanation;
-import org.geneontology.rules.engine.Node;
-import org.geneontology.rules.engine.Rule;
-import org.geneontology.rules.engine.Triple;
-import org.geneontology.rules.engine.TriplePattern;
-import org.geneontology.rules.engine.URI;
-import org.geneontology.rules.engine.Variable;
-import org.geneontology.rules.engine.WorkingMemory;
+import org.geneontology.rules.engine.*;
import org.geneontology.rules.util.Bridge;
import org.semanticweb.owlapi.model.IRI;
-
-import com.google.gson.Gson;
-import com.google.gson.GsonBuilder;
-
import scala.collection.JavaConverters;
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.util.*;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
public class ExportExplanation {
- private static final Logger LOG = Logger.getLogger(ExportExplanation.class);
- private static String mainQuery;
- static {
- try {
- mainQuery = IOUtils.toString(ExportExplanation.class.getResourceAsStream("ExplanationTriples.rq"), StandardCharsets.UTF_8);
- } catch (IOException e) {
- LOG.error("Could not load SPARQL query from jar", e);
- }
- }
+ private static final Logger LOG = Logger.getLogger(ExportExplanation.class);
+ private static String mainQuery;
+
+ static {
+ try {
+ mainQuery = IOUtils.toString(ExportExplanation.class.getResourceAsStream("ExplanationTriples.rq"), StandardCharsets.UTF_8);
+ } catch (IOException e) {
+ LOG.error("Could not load SPARQL query from jar", e);
+ }
+ }
- public static String exportExplanation(WorkingMemory wm, BlazegraphOntologyManager go_lego, Map labelMap) {
- Set triples = new HashSet<>();
- Model model = ModelFactory.createDefaultModel();
- model.add(toJava(wm.facts()).stream().map(t -> model.asStatement(Bridge.jenaFromTriple(t))).collect(Collectors.toList()));
- QueryExecution qe = QueryExecutionFactory.create(mainQuery, model);
- ResultSet results = qe.execSelect();
- while (results.hasNext()) {
- QuerySolution qs = results.next();
- triples.add(new Triple(new URI(qs.getResource("s").getURI()), new URI(qs.getResource("p").getURI()), new URI(qs.getResource("o").getURI())));
- }
- qe.close();
- // Make sure all the asserted triples are included, in case they got filtered out as indirect by the first query
- Model assertedModel = ModelFactory.createDefaultModel();
- assertedModel.add(toJava(wm.asserted()).stream().map(t -> assertedModel.asStatement(Bridge.jenaFromTriple(t))).collect(Collectors.toList()));
- QueryExecution aqe = QueryExecutionFactory.create(mainQuery, assertedModel);
- ResultSet assertedResults = aqe.execSelect();
- while (assertedResults.hasNext()) {
- QuerySolution qs = assertedResults.next();
- triples.add(new Triple(new URI(qs.getResource("s").getURI()), new URI(qs.getResource("p").getURI()), new URI(qs.getResource("o").getURI())));
- }
- aqe.close();
- Set asserted = triples.stream().filter(t -> wm.asserted().contains(t)).collect(Collectors.toSet());
- Set inferred = triples.stream().filter(t -> !wm.asserted().contains(t)).collect(Collectors.toSet());
- Map> allExplanations = inferred.stream().collect(Collectors.toMap(Function.identity(), s -> toJava(wm.explain(s))));
- Set allRules = allExplanations.values().stream().flatMap(es -> es.stream().flatMap(e -> toJava(e.rules()).stream())).collect(Collectors.toSet());
- Stream subjects = triples.stream().map(t -> (URI)(t.s()));
- Stream predicates = triples.stream().map(t -> (URI)(t.p()));
- Stream objects = triples.stream().map(t -> (URI)(t.o()));
- Set allTerms = new HashSet<>();
- for (Rule rule : allRules) {
- for (TriplePattern tp : toJavaList(rule.body())) {
- if (tp.s() instanceof URI) allTerms.add((URI)tp.s());
- if (tp.p() instanceof URI) allTerms.add((URI)tp.p());
- if (tp.o() instanceof URI) allTerms.add((URI)tp.o());
- }
- for (TriplePattern tp : toJavaList(rule.head())) {
- if (tp.s() instanceof URI) allTerms.add((URI)tp.s());
- if (tp.p() instanceof URI) allTerms.add((URI)tp.p());
- if (tp.o() instanceof URI) allTerms.add((URI)tp.o());
- }
- }
- allTerms.addAll(subjects.collect(Collectors.toSet()));
- allTerms.addAll(predicates.collect(Collectors.toSet()));
- allTerms.addAll(objects.collect(Collectors.toSet()));
- Map labels = findLabels(allTerms, asserted, go_lego, labelMap);
- int currentBlankNode = 0;
- Map assertedForJSON = new HashMap<>();
- for (Triple t : asserted) {
- ExplanationTriple et = new ExplanationTriple();
- et.id = "_:" + currentBlankNode++;
- et.subject = ((URI)(t.s())).uri();
- et.predicate = ((URI)(t.p())).uri();
- et.object = ((URI)(t.o())).uri();
- assertedForJSON.put(t, et);
- }
- Map rulesForJSON = new HashMap<>();
- for (Rule r : allRules) {
- ExplanationRule er = new ExplanationRule();
- er.id = "_:" + currentBlankNode++;
- List body = new ArrayList<>();
- List head = new ArrayList<>();
- for (TriplePattern t : toJavaList(r.body())) {
- ExplanationTriple et = new ExplanationTriple();
- et.subject = patternNodeToString(t.s());
- et.predicate = patternNodeToString(t.p());
- et.object = patternNodeToString(t.o());
- body.add(et);
- }
- for (TriplePattern t : toJavaList(r.head())) {
- ExplanationTriple et = new ExplanationTriple();
- et.subject = patternNodeToString(t.s());
- et.predicate = patternNodeToString(t.p());
- et.object = patternNodeToString(t.o());
- head.add(et);
- }
- er.body = body.toArray(new ExplanationTriple[] {});
- er.head = head.toArray(new ExplanationTriple[] {});
- rulesForJSON.put(r, er);
- }
- Map inferredForJSON = new HashMap<>();
- for (Triple t : inferred) {
- ExplanationTriple et = new ExplanationTriple();
- et.subject = ((URI)(t.s())).uri();
- et.predicate = ((URI)(t.p())).uri();
- et.object = ((URI)(t.o())).uri();
- Explanation explanation = allExplanations.get(t).iterator().next();
- org.geneontology.minerva.explanation.Explanation ex = new org.geneontology.minerva.explanation.Explanation();
- ex.triples = toJava(explanation.facts()).stream().map(f -> assertedForJSON.get(f).id).toArray(String[]::new);
- ex.rules = toJava(explanation.rules()).stream().map(r -> rulesForJSON.get(r).id).toArray(String[]::new);
- et.explanation = ex;
- inferredForJSON.put(t, et);
- }
- ModelExplanation me = new ModelExplanation();
- me.terms = labels.keySet().stream().map(uri -> {
- ExplanationTerm et = new ExplanationTerm();
- et.id = uri.uri();
- et.label = labels.get(uri);
- return et;
- }).toArray(ExplanationTerm[]::new);
- me.assertions = assertedForJSON.values().toArray(new ExplanationTriple[] {});
- me.rules = rulesForJSON.values().toArray(new ExplanationRule[] {});
- me.inferences = inferredForJSON.values().toArray(new ExplanationTriple[] {});
- GsonBuilder builder = new GsonBuilder();
- builder = builder.setPrettyPrinting();
- Gson gson = builder.create();
- String json = gson.toJson(me);
- return json;
- }
+ public static String exportExplanation(WorkingMemory wm, BlazegraphOntologyManager go_lego, Map labelMap) {
+ Set triples = new HashSet<>();
+ Model model = ModelFactory.createDefaultModel();
+ model.add(toJava(wm.facts()).stream().map(t -> model.asStatement(Bridge.jenaFromTriple(t))).collect(Collectors.toList()));
+ QueryExecution qe = QueryExecutionFactory.create(mainQuery, model);
+ ResultSet results = qe.execSelect();
+ while (results.hasNext()) {
+ QuerySolution qs = results.next();
+ triples.add(new Triple(new URI(qs.getResource("s").getURI()), new URI(qs.getResource("p").getURI()), new URI(qs.getResource("o").getURI())));
+ }
+ qe.close();
+ // Make sure all the asserted triples are included, in case they got filtered out as indirect by the first query
+ Model assertedModel = ModelFactory.createDefaultModel();
+ assertedModel.add(toJava(wm.asserted()).stream().map(t -> assertedModel.asStatement(Bridge.jenaFromTriple(t))).collect(Collectors.toList()));
+ QueryExecution aqe = QueryExecutionFactory.create(mainQuery, assertedModel);
+ ResultSet assertedResults = aqe.execSelect();
+ while (assertedResults.hasNext()) {
+ QuerySolution qs = assertedResults.next();
+ triples.add(new Triple(new URI(qs.getResource("s").getURI()), new URI(qs.getResource("p").getURI()), new URI(qs.getResource("o").getURI())));
+ }
+ aqe.close();
+ Set asserted = triples.stream().filter(t -> wm.asserted().contains(t)).collect(Collectors.toSet());
+ Set inferred = triples.stream().filter(t -> !wm.asserted().contains(t)).collect(Collectors.toSet());
+ Map> allExplanations = inferred.stream().collect(Collectors.toMap(Function.identity(), s -> toJava(wm.explain(s))));
+ Set allRules = allExplanations.values().stream().flatMap(es -> es.stream().flatMap(e -> toJava(e.rules()).stream())).collect(Collectors.toSet());
+ Stream subjects = triples.stream().map(t -> (URI) (t.s()));
+ Stream predicates = triples.stream().map(t -> (URI) (t.p()));
+ Stream objects = triples.stream().map(t -> (URI) (t.o()));
+ Set allTerms = new HashSet<>();
+ for (Rule rule : allRules) {
+ for (TriplePattern tp : toJavaList(rule.body())) {
+ if (tp.s() instanceof URI) allTerms.add((URI) tp.s());
+ if (tp.p() instanceof URI) allTerms.add((URI) tp.p());
+ if (tp.o() instanceof URI) allTerms.add((URI) tp.o());
+ }
+ for (TriplePattern tp : toJavaList(rule.head())) {
+ if (tp.s() instanceof URI) allTerms.add((URI) tp.s());
+ if (tp.p() instanceof URI) allTerms.add((URI) tp.p());
+ if (tp.o() instanceof URI) allTerms.add((URI) tp.o());
+ }
+ }
+ allTerms.addAll(subjects.collect(Collectors.toSet()));
+ allTerms.addAll(predicates.collect(Collectors.toSet()));
+ allTerms.addAll(objects.collect(Collectors.toSet()));
+ Map labels = findLabels(allTerms, asserted, go_lego, labelMap);
+ int currentBlankNode = 0;
+ Map assertedForJSON = new HashMap<>();
+ for (Triple t : asserted) {
+ ExplanationTriple et = new ExplanationTriple();
+ et.id = "_:" + currentBlankNode++;
+ et.subject = ((URI) (t.s())).uri();
+ et.predicate = ((URI) (t.p())).uri();
+ et.object = ((URI) (t.o())).uri();
+ assertedForJSON.put(t, et);
+ }
+ Map rulesForJSON = new HashMap<>();
+ for (Rule r : allRules) {
+ ExplanationRule er = new ExplanationRule();
+ er.id = "_:" + currentBlankNode++;
+ List body = new ArrayList<>();
+ List head = new ArrayList<>();
+ for (TriplePattern t : toJavaList(r.body())) {
+ ExplanationTriple et = new ExplanationTriple();
+ et.subject = patternNodeToString(t.s());
+ et.predicate = patternNodeToString(t.p());
+ et.object = patternNodeToString(t.o());
+ body.add(et);
+ }
+ for (TriplePattern t : toJavaList(r.head())) {
+ ExplanationTriple et = new ExplanationTriple();
+ et.subject = patternNodeToString(t.s());
+ et.predicate = patternNodeToString(t.p());
+ et.object = patternNodeToString(t.o());
+ head.add(et);
+ }
+ er.body = body.toArray(new ExplanationTriple[]{});
+ er.head = head.toArray(new ExplanationTriple[]{});
+ rulesForJSON.put(r, er);
+ }
+ Map inferredForJSON = new HashMap<>();
+ for (Triple t : inferred) {
+ ExplanationTriple et = new ExplanationTriple();
+ et.subject = ((URI) (t.s())).uri();
+ et.predicate = ((URI) (t.p())).uri();
+ et.object = ((URI) (t.o())).uri();
+ Explanation explanation = allExplanations.get(t).iterator().next();
+ org.geneontology.minerva.explanation.Explanation ex = new org.geneontology.minerva.explanation.Explanation();
+ ex.triples = toJava(explanation.facts()).stream().map(f -> assertedForJSON.get(f).id).toArray(String[]::new);
+ ex.rules = toJava(explanation.rules()).stream().map(r -> rulesForJSON.get(r).id).toArray(String[]::new);
+ et.explanation = ex;
+ inferredForJSON.put(t, et);
+ }
+ ModelExplanation me = new ModelExplanation();
+ me.terms = labels.keySet().stream().map(uri -> {
+ ExplanationTerm et = new ExplanationTerm();
+ et.id = uri.uri();
+ et.label = labels.get(uri);
+ return et;
+ }).toArray(ExplanationTerm[]::new);
+ me.assertions = assertedForJSON.values().toArray(new ExplanationTriple[]{});
+ me.rules = rulesForJSON.values().toArray(new ExplanationRule[]{});
+ me.inferences = inferredForJSON.values().toArray(new ExplanationTriple[]{});
+ GsonBuilder builder = new GsonBuilder();
+ builder = builder.setPrettyPrinting();
+ Gson gson = builder.create();
+ String json = gson.toJson(me);
+ return json;
+ }
- private static String patternNodeToString(Node node) {
- if (node instanceof URI) {
- return ((URI)node).uri();
- } else {
- return ((Variable)node).name();
- }
- }
+ private static String patternNodeToString(Node node) {
+ if (node instanceof URI) {
+ return ((URI) node).uri();
+ } else {
+ return ((Variable) node).name();
+ }
+ }
- private static Map findLabels(Set uris, Set assertions, BlazegraphOntologyManager go_lego, Map labelMap) {
- final URI rdfType = new URI("http://www.w3.org/1999/02/22-rdf-syntax-ns#type");
- Map labels = new HashMap<>();
- labels.put(rdfType, "type");
- for (URI uri : uris) {
- Optional possibleLabel = lookup(uri, go_lego, labelMap, labels);
- if (possibleLabel.isPresent()) {
- labels.put(uri, possibleLabel.get());
- } else {
- Optional type = assertions.stream().filter(t -> t.s().equals(uri) && t.p().equals(rdfType)).map(t -> (URI)(t.o())).findAny();
- if (type.isPresent()) {
- Optional possibleTypeLabel = lookup(type.get(), go_lego, labelMap, labels);
- if (possibleTypeLabel.isPresent()) {
- labels.put(uri, possibleTypeLabel.get() + "#" + uri.uri().substring(uri.uri().lastIndexOf("/") + 1));
- } else {
- labels.put(uri, uri.uri());
- }
- }
- }
+ private static Map findLabels(Set