Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow interpolation of placeholders in annotation values. #1242

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added
- Add `--clean-obo` option to [`convert`] [#995]
- Allow interpolation of ontology IRI and version IRI within annotation values [#1241]

### Fixed
- Update owl-diff dependency for stable ordering and to avoid large string creation [#1227]
Expand Down
13 changes: 13 additions & 0 deletions docs/annotate.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,19 @@ Including at least the following annotations is recommended:
* Description (<a href="http://purl.org/dc/terms/description" target="_blank">`dcterms:description`</a>)
* License (<a href="http://purl.org/dc/terms/license" target="_blank">`dcterms:license`</a>)

If the `--interpolate` option is used, then some placeholders, of the form `%{NAME}`, can be used within the annotation values and will be automatically replaced by computed values. Currently supported placeholers are:

* `%{ontology_iri}`, replaced by the ontology's IRI;
* `%{version_iri}`, replaced by the ontology's version IRI.

Example:

robot annotate --input fbcv-module.owl \
--interpolate true \
--link-annotation dc:source %{version_iri} \
--annotation rdfs:comment "Derived from %{ontology_iri}" \
--output results/fbcv-annotated.owl

This command can also remove all ontology annotations from your file with `--remove-annotations`. You can combine this with options to add new annotations:

robot annotate --input annotated.owl \
Expand Down
176 changes: 176 additions & 0 deletions docs/examples/fbcv-annotated.owl
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
<?xml version="1.0"?>
<rdf:RDF xmlns="http://purl.obolibrary.org/obo/dpo/simple#"
xml:base="http://purl.obolibrary.org/obo/dpo/simple"
xmlns:obo="http://purl.obolibrary.org/obo/"
xmlns:owl="http://www.w3.org/2002/07/owl#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:xml="http://www.w3.org/XML/1998/namespace"
xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
xmlns:terms="http://purl.org/dc/terms/"
xmlns:oboInOwl="http://www.geneontology.org/formats/oboInOwl#">
<owl:Ontology rdf:about="http://purl.obolibrary.org/obo/dpo/simple">
<owl:versionIRI rdf:resource="http://purl.obolibrary.org/obo/dpo/releases/2019-07-08/simple"/>
<terms:source rdf:resource="http://purl.obolibrary.org/obo/dpo/releases/2019-07-08/simple"/>
<rdfs:comment>Derived from http://purl.obolibrary.org/obo/dpo/simple</rdfs:comment>
</owl:Ontology>



<!--
///////////////////////////////////////////////////////////////////////////////////////
//
// Annotation properties
//
///////////////////////////////////////////////////////////////////////////////////////
-->




<!-- http://purl.obolibrary.org/obo/IAO_0000115 -->

<owl:AnnotationProperty rdf:about="http://purl.obolibrary.org/obo/IAO_0000115"/>



<!-- http://purl.org/dc/terms/source -->

<owl:AnnotationProperty rdf:about="http://purl.org/dc/terms/source"/>



<!-- http://www.geneontology.org/formats/oboInOwl#created_by -->

<owl:AnnotationProperty rdf:about="http://www.geneontology.org/formats/oboInOwl#created_by"/>



<!-- http://www.geneontology.org/formats/oboInOwl#creation_date -->

<owl:AnnotationProperty rdf:about="http://www.geneontology.org/formats/oboInOwl#creation_date"/>



<!-- http://www.geneontology.org/formats/oboInOwl#hasDbXref -->

<owl:AnnotationProperty rdf:about="http://www.geneontology.org/formats/oboInOwl#hasDbXref"/>



<!-- http://www.geneontology.org/formats/oboInOwl#hasExactSynonym -->

<owl:AnnotationProperty rdf:about="http://www.geneontology.org/formats/oboInOwl#hasExactSynonym"/>



<!-- http://www.geneontology.org/formats/oboInOwl#hasOBONamespace -->

<owl:AnnotationProperty rdf:about="http://www.geneontology.org/formats/oboInOwl#hasOBONamespace"/>



<!-- http://www.geneontology.org/formats/oboInOwl#id -->

<owl:AnnotationProperty rdf:about="http://www.geneontology.org/formats/oboInOwl#id"/>



<!-- http://www.geneontology.org/formats/oboInOwl#inSubset -->

<owl:AnnotationProperty rdf:about="http://www.geneontology.org/formats/oboInOwl#inSubset"/>



<!-- http://www.w3.org/2000/01/rdf-schema#comment -->

<owl:AnnotationProperty rdf:about="http://www.w3.org/2000/01/rdf-schema#comment"/>



<!-- http://www.w3.org/2000/01/rdf-schema#label -->

<owl:AnnotationProperty rdf:about="http://www.w3.org/2000/01/rdf-schema#label"/>



<!--
///////////////////////////////////////////////////////////////////////////////////////
//
// Classes
//
///////////////////////////////////////////////////////////////////////////////////////
-->




<!-- http://purl.obolibrary.org/obo/FBcv_0000002 -->

<owl:Class rdf:about="http://purl.obolibrary.org/obo/FBcv_0000002">
<rdfs:subClassOf rdf:resource="http://purl.obolibrary.org/obo/FBcv_0000683"/>
<obo:IAO_0000115>Phenotype that is a defect in thermotaxis (GO:0043052). &apos;thermotaxis&apos; is defined as: &apos;$sub_GO:0043052&apos;</obo:IAO_0000115>
<oboInOwl:hasExactSynonym>thermotaxis behaviour defective</oboInOwl:hasExactSynonym>
<oboInOwl:hasOBONamespace>phenotypic_class</oboInOwl:hasOBONamespace>
<oboInOwl:id>FBcv:0000002</oboInOwl:id>
<rdfs:label>thermotaxis behavior defective</rdfs:label>
</owl:Class>
<owl:Axiom>
<owl:annotatedSource rdf:resource="http://purl.obolibrary.org/obo/FBcv_0000002"/>
<owl:annotatedProperty rdf:resource="http://purl.obolibrary.org/obo/IAO_0000115"/>
<owl:annotatedTarget>Phenotype that is a defect in thermotaxis (GO:0043052). &apos;thermotaxis&apos; is defined as: &apos;$sub_GO:0043052&apos;</owl:annotatedTarget>
<oboInOwl:hasDbXref>FBC:DOS</oboInOwl:hasDbXref>
</owl:Axiom>



<!-- http://purl.obolibrary.org/obo/FBcv_0000347 -->

<owl:Class rdf:about="http://purl.obolibrary.org/obo/FBcv_0000347">
<rdfs:subClassOf rdf:resource="http://www.w3.org/2002/07/owl#Thing"/>
<oboInOwl:hasOBONamespace>phenotypic_class</oboInOwl:hasOBONamespace>
<oboInOwl:id>FBcv:0000347</oboInOwl:id>
<rdfs:label>phenotypic class</rdfs:label>
</owl:Class>



<!-- http://purl.obolibrary.org/obo/FBcv_0000683 -->

<owl:Class rdf:about="http://purl.obolibrary.org/obo/FBcv_0000683">
<rdfs:subClassOf rdf:resource="http://purl.obolibrary.org/obo/FBcv_0001347"/>
<obo:IAO_0000115>Phenotype that is a defect in response to temperature stimulus (GO:0009266). &apos;response to temperature stimulus&apos; is defined as: &apos;$sub_GO:0009266&apos;</obo:IAO_0000115>
<oboInOwl:created_by>djs93</oboInOwl:created_by>
<oboInOwl:creation_date>2010-02-23T12:51:02Z</oboInOwl:creation_date>
<oboInOwl:hasOBONamespace>phenotypic_class</oboInOwl:hasOBONamespace>
<oboInOwl:id>FBcv:0000683</oboInOwl:id>
<oboInOwl:inSubset>fbcvsubset_mgiribbons</oboInOwl:inSubset>
<rdfs:label>temperature response defective</rdfs:label>
</owl:Class>



<!-- http://purl.obolibrary.org/obo/FBcv_0001347 -->

<owl:Class rdf:about="http://purl.obolibrary.org/obo/FBcv_0001347">
<rdfs:subClassOf rdf:resource="http://purl.obolibrary.org/obo/FBcv_0000347"/>
<obo:IAO_0000115>A defect in or loss of some anatomical structure or biological process compared to wild-type.</obo:IAO_0000115>
<oboInOwl:hasExactSynonym>phenotypic class</oboInOwl:hasExactSynonym>
<oboInOwl:hasOBONamespace>phenotypic_class</oboInOwl:hasOBONamespace>
<oboInOwl:id>FBcv:0001347</oboInOwl:id>
<oboInOwl:inSubset>do_not_annotate</oboInOwl:inSubset>
<rdfs:comment>The subclasses of this term classify Drosophila phenotypes into different common categories. They have been chosen by FlyBase to reflect phenotype terms most often reported by Drosophila researchers in the published literature.</rdfs:comment>
<rdfs:label>phenotype</rdfs:label>
</owl:Class>
<owl:Axiom>
<owl:annotatedSource rdf:resource="http://purl.obolibrary.org/obo/FBcv_0001347"/>
<owl:annotatedProperty rdf:resource="http://purl.obolibrary.org/obo/IAO_0000115"/>
<owl:annotatedTarget>A defect in or loss of some anatomical structure or biological process compared to wild-type.</owl:annotatedTarget>
<oboInOwl:hasDbXref>FBC:DOS</oboInOwl:hasDbXref>
</owl:Axiom>
</rdf:RDF>



<!-- Generated by the OWL API (version 4.5.29) https://github.com/owlcs/owlapi -->

Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ public AnnotateCommand() {
"annotate-defined-by",
true,
"if true, annotate all entities in the ontology with the ontology IRI");
o.addOption(
"e", "interpolate", true, "if true, interpolate placeholders within annotation values");

options = o;

Expand Down Expand Up @@ -187,6 +189,7 @@ public CommandState execute(CommandState state, String[] args) throws Exception

String property;
String value;
boolean interpolate = CommandLineHelper.getBooleanValue(line, "interpolate", false);

// Add annotations with PROP VALUE
List<String> annotationItems = CommandLineHelper.getOptionValues(line, "annotation");
Expand All @@ -199,6 +202,9 @@ public CommandState execute(CommandState state, String[] args) throws Exception
} catch (IndexOutOfBoundsException e) {
throw new IllegalArgumentException(annotationFormatError, e);
}
if (interpolate) {
value = expandValue(value, ontology);
}
IRI iri = CommandLineHelper.maybeCreateIRI(ioHelper, property, "property");
OntologyHelper.addOntologyAnnotation(ontology, iri, IOHelper.createLiteral(value));
}
Expand All @@ -214,6 +220,9 @@ public CommandState execute(CommandState state, String[] args) throws Exception
} catch (IndexOutOfBoundsException e) {
throw new IllegalArgumentException(linkAnnotationFormatError, e);
}
if (interpolate) {
value = expandValue(value, ontology);
}
IRI propIRI = CommandLineHelper.maybeCreateIRI(ioHelper, property, "property");
IRI valueIRI = CommandLineHelper.maybeCreateIRI(ioHelper, value, "value");
OntologyHelper.addOntologyAnnotation(ontology, propIRI, valueIRI);
Expand All @@ -232,6 +241,9 @@ public CommandState execute(CommandState state, String[] args) throws Exception
} catch (IndexOutOfBoundsException e) {
throw new IllegalArgumentException(langAnnotationFormatError, e);
}
if (interpolate) {
value = expandValue(value, ontology);
}
IRI iri = CommandLineHelper.maybeCreateIRI(ioHelper, property, "property");
OntologyHelper.addOntologyAnnotation(
ontology, iri, IOHelper.createTaggedLiteral(value, lang));
Expand All @@ -250,6 +262,9 @@ public CommandState execute(CommandState state, String[] args) throws Exception
} catch (IndexOutOfBoundsException e) {
throw new IllegalArgumentException(typedAnnotationFormatError, e);
}
if (interpolate) {
value = expandValue(value, ontology);
}
IRI iri = CommandLineHelper.maybeCreateIRI(ioHelper, property, "property");
OntologyHelper.addOntologyAnnotation(ontology, iri, ioHelper.createTypedLiteral(value, type));
}
Expand All @@ -265,6 +280,9 @@ public CommandState execute(CommandState state, String[] args) throws Exception
} catch (IndexOutOfBoundsException e) {
throw new IllegalArgumentException(axiomAnnotationFormatError, e);
}
if (interpolate) {
value = expandValue(value, ontology);
}
IRI iri = CommandLineHelper.maybeCreateIRI(ioHelper, property, "property");
OntologyHelper.addAxiomAnnotations(ontology, iri, IOHelper.createLiteral(value));
}
Expand Down Expand Up @@ -334,4 +352,31 @@ public CommandState execute(CommandState state, String[] args) throws Exception

return state;
}

/**
* Expands placeholders within the given string with values derived from the ontology.
*
* <p>Placeholders are keywords enclosed within <code>%{...}</code>. Currently supported
* placeholders are:
*
* <ul>
* <li><code>ontology_iri</code>: replaced by the ontology's IRI;
* <li><code>version_iri</code>: replaced by the ontology's version IRI.
* </ul>
*
* @param value the string in which to replace placeholders
* @param ontology the ontology from which placeholder values should be derived
* @return the updated string
*/
private String expandValue(String value, OWLOntology ontology) {
IRI ontologyIRI = ontology.getOntologyID().getOntologyIRI().orNull();
IRI versionIRI = ontology.getOntologyID().getVersionIRI().orNull();
if (ontologyIRI != null) {
value = value.replace("%{ontology_iri}", ontologyIRI.toString());
}
if (versionIRI != null) {
value = value.replace("%{version_iri}", versionIRI.toString());
}
return value;
}
}