diff --git a/CHANGELOG.md b/CHANGELOG.md index d4be978a3..5c8ad6b32 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - [`merge`] and 'annotate' operations '--annotate-defined-by' excludes reserved OWL 2 vocabularies [#1171] - Handle IRIs that are not entities in export [#1168] - Fix integration tests [#1181] +- `robot repair` is fixed to be more flexible, to enable partial repairs [#1194] - Invalid Xrefs test has been fixed to recognise invalid CURIEs correctly [#1127] - Fix issue with correctly determining base entities [#1108] diff --git a/docs/examples/uberon_axiom_annotation_merged.owl b/docs/examples/uberon_axiom_annotation_merged.owl new file mode 100644 index 000000000..9c663e17d --- /dev/null +++ b/docs/examples/uberon_axiom_annotation_merged.owl @@ -0,0 +1,297 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + BFO:0000050 + uberon + part_of + part_of + part_of + + + + + + + + + BFO:0000051 + uberon + has_part + has_part + has_part + + + + + + + + + + + + + + + + + + + Anatomical structure that performs a specific function or group of functions [WP]. + + + + + WBbt:0003760 + anatomical unit + body organ + element + UBERON:0000062 + organ + + + + + Anatomical structure that performs a specific function or group of functions [WP]. + + + + + + + body organ + + + + + + + + + + + + + + + + diff --git a/docs/examples/uberon_axiom_annotation_merging.owl b/docs/examples/uberon_axiom_annotation_merging.owl new file mode 100644 index 000000000..57dfd7f26 --- /dev/null +++ b/docs/examples/uberon_axiom_annotation_merging.owl @@ -0,0 +1,308 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + BFO:0000050 + uberon + part_of + part_of + part_of + + + + + + + + + BFO:0000051 + uberon + has_part + has_part + has_part + + + + + + + + + + + + + + + + + + + Anatomical structure that performs a specific function or group of functions [WP]. + + + + + WBbt:0003760 + anatomical unit + body organ + element + UBERON:0000062 + organ + + + + + body organ + + + + + + body organ + + + + + + body organ + + + + + + Anatomical structure that performs a specific function or group of functions [WP]. + + + + + + Anatomical structure that performs a specific function or group of functions [WP]. + + + + + + + + + + diff --git a/docs/repair.md b/docs/repair.md index 373470f46..4c53f2ff5 100644 --- a/docs/repair.md +++ b/docs/repair.md @@ -1,6 +1,23 @@ # Repair -ROBOT can repair certain problems encountered in ontologies. So far, this is limited to updating axioms pointing to deprecated classes with their replacement class (indicated using [term replaced by](http://purl.obolibrary.org/obo/IAO_0100001)). +ROBOT can repair certain problems encountered in ontologies. So far, this is limited to + +- [updating axioms pointing to deprecated classes](#deprecated) with their replacement class (indicated using [term replaced by](http://purl.obolibrary.org/obo/IAO_0100001)) and +- [merging axiom annotations](#mergingax) about the same axiom into a single statement. + +To repair an ontology (i.e. execute all repair operations implemented by `robot`) run the following command: + + robot repair \ + --input need-of-repair.owl \ + --output results/repaired.owl + +This will generate a new file `results/repaired.owl`. You can compare this with the original file (either using unix `diff` or [robot diff](diff)). If the changes that were made look good then you can simply replace the source file with the repaired file (`mv results/repaired.owl need-of-repair.owl`). + +In the following, we will discuss how to run the different implemented repairs individually. + + + +## Updating axioms pointing to deprecated classes with their replacement class This situation can arise in a number of different ways: @@ -9,17 +26,27 @@ This situation can arise in a number of different ways: For more on obsoletion workflows, see the [obsoletion guide](https://ontology-development-kit.readthedocs.io/en/latest/ObsoleteTerm.html) in the Ontology Development Kit documentation. -To repair an ontology (with the name `need-of-repair.owl`) run the following command: +To update axioms pointing to deprecated classes with their replacement class an ontology run the following command: robot repair \ --input need-of-repair.owl \ + --invalid-references true \ --output results/repaired.owl -This will generate a new file `results/repaired.owl`. You can compare this with the original file (either using unix `diff` or [robot diff](diff)). If the changes that were made look good then you can simply replace the source file with the repaired file (`mv results/repaired.owl need-of-repair.owl`). - -By default, annotation axioms are not migrated to replacement classes. However, this can be enabled for a list of annotation properties passed either as arguments to `--annotation-property` or in a term file `--annotation-properties-file`: +By default, annotation axioms are not migrated to replacement classes. +However, this can be enabled for a list of annotation properties passed either as arguments to `--annotation-property` or in a term file `--annotation-properties-file`: robot repair \ --input xref-need-of-repair.obo \ --annotation-property oboInOwl:hasDbXref \ --output results/xref-repaired.obo + + + +## Merging axiom annotations + +Sometimes we end up with the same exact statement (synonym assertion, subclass of axiom) having different sets of axiom annotations (for example, different sources of provenance). If we want to merge these, so that all axiom annotations are combined on the same statement, we can use use: + + robot repair --input uberon_axiom_annotation_merging.owl \ + --merge-axiom-annotations true \ + --output results/uberon_axiom_annotation_merged.owl diff --git a/robot-command/src/main/java/org/obolibrary/robot/RepairCommand.java b/robot-command/src/main/java/org/obolibrary/robot/RepairCommand.java index 8c0dd4b00..6499be6e3 100644 --- a/robot-command/src/main/java/org/obolibrary/robot/RepairCommand.java +++ b/robot-command/src/main/java/org/obolibrary/robot/RepairCommand.java @@ -4,6 +4,8 @@ import java.util.stream.Collectors; import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.Options; +import org.obolibrary.robot.checks.InvalidReferenceChecker; +import org.obolibrary.robot.checks.InvalidReferenceViolation; import org.semanticweb.owlapi.model.IRI; import org.semanticweb.owlapi.model.OWLAnnotationProperty; import org.semanticweb.owlapi.model.OWLDataFactory; @@ -35,6 +37,8 @@ public RepairCommand() { "merge-axiom-annotations", true, "if true, merge axiom annotations on duplicate axioms"); + o.addOption( + "r", "invalid-references", true, "if true, repairs invalid references in the ontology"); options = o; o.addOption("a", "annotation-property", true, "an annotation property to migrate"); o.addOption( @@ -119,6 +123,9 @@ public CommandState execute(CommandState state, String[] args) throws Exception outputIRI = inputOntology.getOntologyID().getOntologyIRI().orNull(); } + boolean repairInvalidReferences = + CommandLineHelper.getBooleanValue(line, "invalid-references", false); + boolean mergeAxiomAnnotations = CommandLineHelper.getBooleanValue(line, "merge-axiom-annotations", false); @@ -130,7 +137,25 @@ public CommandState execute(CommandState state, String[] args) throws Exception .map(factory::getOWLAnnotationProperty) .collect(Collectors.toSet()); - RepairOperation.repair(inputOntology, ioHelper, mergeAxiomAnnotations, properties); + boolean repaired = false; + + if (mergeAxiomAnnotations) { + repaired = true; + RepairOperation.mergeAxiomAnnotations(inputOntology); + } + + if (repairInvalidReferences) { + repaired = true; + Set violations = + InvalidReferenceChecker.getInvalidReferenceViolations(inputOntology, true); + RepairOperation.repairInvalidReferences(ioHelper, inputOntology, violations, properties); + } + + if (!repaired) { + logger.info("No specific repair options were given, running the default repair pipeline"); + RepairOperation.repair(inputOntology, ioHelper, mergeAxiomAnnotations, properties); + } + outputOntology = inputOntology; if (outputIRI != null) { outputOntology.getOWLOntologyManager().setOntologyDocumentIRI(outputOntology, outputIRI);