From 57b9f36e041b2cc3b08d602ccafd0093701dc6df Mon Sep 17 00:00:00 2001 From: Nico Matentzoglu Date: Mon, 8 Apr 2024 16:03:43 +0300 Subject: [PATCH 1/3] Make repair command more flexible This commit makes it possible to selectively invoke repair functions rather than a all or nothing approach. --- .../uberon_axiom_annotation_merged.owl | 297 +++++++++++++++++ .../uberon_axiom_annotation_merging.owl | 308 ++++++++++++++++++ docs/repair.md | 9 +- .../org/obolibrary/robot/RepairCommand.java | 27 +- 4 files changed, 639 insertions(+), 2 deletions(-) create mode 100644 docs/examples/uberon_axiom_annotation_merged.owl create mode 100644 docs/examples/uberon_axiom_annotation_merging.owl 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..c95d8d12f 100644 --- a/docs/repair.md +++ b/docs/repair.md @@ -17,7 +17,14 @@ To repair an ontology (with the name `need-of-repair.owl`) run the following com 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`: +To use ROBOT solely for merging axiom annotations, you can use: + + robot repair --input uberon_axiom_annotation_merging.owl \ + --merge-axiom-annotations true \ + --output results/uberon_axiom_annotation_merged.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`: robot repair \ --input xref-need-of-repair.obo \ 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); From 8ca3df408600e871b343421ece81a978ccab10e9 Mon Sep 17 00:00:00 2001 From: Nico Matentzoglu Date: Mon, 8 Apr 2024 16:16:31 +0300 Subject: [PATCH 2/3] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 40198a9ed..461f372a4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,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] ## [1.9.5] - 2023-09-20 From 5b59fc5bd365b26c1b3f8d1892d548faf2d14d60 Mon Sep 17 00:00:00 2001 From: Nico Matentzoglu Date: Thu, 2 May 2024 15:44:17 +0300 Subject: [PATCH 3/3] Update repair.md --- docs/repair.md | 40 ++++++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/docs/repair.md b/docs/repair.md index c95d8d12f..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,20 +26,13 @@ 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`). - -To use ROBOT solely for merging axiom annotations, you can use: - - robot repair --input uberon_axiom_annotation_merging.owl \ - --merge-axiom-annotations true \ - --output results/uberon_axiom_annotation_merged.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`: @@ -30,3 +40,13 @@ However, this can be enabled for a list of annotation properties passed either a --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