Skip to content

Commit

Permalink
Added obsoletion menu.
Browse files Browse the repository at this point in the history
  • Loading branch information
balhoff committed Aug 19, 2017
1 parent 9e2216b commit 6d59041
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# OBO annotations editor #

A plug-in for Protege that provides entry fields for standard OBO annotation properties.
A plug-in for Protege that provides entry fields for standard OBO annotation properties, as well as menu actions such as term obsoletion.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>org.geneontology</groupId>
<artifactId>obo-annotations-plugin</artifactId>
<version>0.3.0</version>
<version>0.4.0</version>
<packaging>bundle</packaging>

<name>OBO Annotations Editor</name>
Expand Down Expand Up @@ -33,7 +33,7 @@
<developer>
<id>balhoff</id>
<name>Jim Balhoff</name>
<email>jim@balhoff.org</email>
<email>balhoff@renci.org</email>
</developer>
</developers>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package org.protege.oboeditor.menu;

import java.util.Set;

import org.protege.editor.owl.ui.action.SelectedOWLEntityAction;
import org.semanticweb.owlapi.model.OWLAnnotation;
import org.semanticweb.owlapi.model.OWLAnnotationAssertionAxiom;
import org.semanticweb.owlapi.model.OWLAnnotationProperty;
import org.semanticweb.owlapi.model.OWLClass;
import org.semanticweb.owlapi.model.OWLClassExpression;
import org.semanticweb.owlapi.model.OWLDataFactory;
import org.semanticweb.owlapi.model.OWLDisjointClassesAxiom;
import org.semanticweb.owlapi.model.OWLEntity;
import org.semanticweb.owlapi.model.OWLEquivalentClassesAxiom;
import org.semanticweb.owlapi.model.OWLHasKeyAxiom;
import org.semanticweb.owlapi.model.OWLLiteral;
import org.semanticweb.owlapi.model.OWLOntology;
import org.semanticweb.owlapi.model.OWLOntologyManager;
import org.semanticweb.owlapi.model.OWLSubClassOfAxiom;
import org.semanticweb.owlapi.vocab.OWLRDFVocabulary;

public class ObsoleteEntityMenuAction extends SelectedOWLEntityAction {

private static final long serialVersionUID = -1431847694761565949L;

@Override
protected void actionPerformed(OWLEntity entity) {
final OWLOntologyManager manager = this.getOWLModelManager().getOWLOntologyManager();
final OWLDataFactory factory = this.getOWLDataFactory();
final OWLOntology ontology = this.getOWLModelManager().getActiveOntology();
this.relabel(entity);
manager.addAxiom(ontology, factory.getDeprecatedOWLAnnotationAssertionAxiom(entity.getIRI()));
if (entity.isOWLClass()) {
final OWLClass ontClass = entity.asOWLClass();
for (OWLEquivalentClassesAxiom axiom : ontology.getEquivalentClassesAxioms(ontClass)) {
manager.removeAxiom(ontology, axiom);
final Set<OWLClassExpression> otherClasses = axiom.getClassExpressionsMinus(ontClass);
final Set<OWLAnnotation> annotations = axiom.getAnnotations();
if (otherClasses.size() > 1) {
final OWLEquivalentClassesAxiom newAxiom = factory.getOWLEquivalentClassesAxiom(otherClasses, annotations);
manager.addAxiom(ontology, newAxiom);
}
}
for (OWLSubClassOfAxiom axiom : ontology.getSubClassAxiomsForSubClass(ontClass)) {
manager.removeAxiom(ontology, axiom);
}
for (OWLSubClassOfAxiom axiom : ontology.getSubClassAxiomsForSuperClass(ontClass)) {
manager.removeAxiom(ontology, axiom);
}
for (OWLHasKeyAxiom axiom : ontology.getHasKeyAxioms(ontClass)) {
manager.removeAxiom(ontology, axiom);
}
for (OWLDisjointClassesAxiom axiom : ontology.getDisjointClassesAxioms(ontClass)) {
manager.removeAxiom(ontology, axiom);
final Set<OWLClassExpression> otherClasses = axiom.getClassExpressionsMinus(ontClass);
final Set<OWLAnnotation> annotations = axiom.getAnnotations();
if (otherClasses.size() > 1) {
final OWLDisjointClassesAxiom newAxiom = factory.getOWLDisjointClassesAxiom(otherClasses, annotations);
manager.addAxiom(ontology, newAxiom);
}
}
}
if (entity.isOWLNamedIndividual()) {
//TODO
}
if (entity.isOWLObjectProperty()) {
//TODO
}
}

@Override
protected void disposeAction() throws Exception {}

private void relabel(OWLEntity entity) {
final OWLOntologyManager manager = this.getOWLModelManager().getOWLOntologyManager();
final OWLDataFactory factory = this.getOWLDataFactory();
final OWLAnnotationProperty rdfsLabel = factory.getOWLAnnotationProperty(OWLRDFVocabulary.RDFS_LABEL.getIRI());
final OWLOntology ontology = this.getOWLModelManager().getActiveOntology();
for (OWLAnnotationAssertionAxiom annotation : ontology.getAnnotationAssertionAxioms(entity.getIRI())) {
if (annotation.getProperty().equals(rdfsLabel)) {
if (annotation.getValue() instanceof OWLLiteral) {
final Set<OWLAnnotation> annotationAnnotations = annotation.getAnnotations();
final OWLLiteral literal = (OWLLiteral)(annotation.getValue());
final String newLabel = "obsolete " + literal.getLiteral();
final OWLLiteral newLiteral = factory.getOWLLiteral(newLabel);
final OWLAnnotationAssertionAxiom newAxiom = factory.getOWLAnnotationAssertionAxiom(rdfsLabel, entity.getIRI(), newLiteral, annotationAnnotations);
manager.removeAxiom(ontology, annotation);
manager.addAxiom(ontology, newAxiom);
}
}
}
}

}
8 changes: 8 additions & 0 deletions src/main/resources/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,13 @@
<headerColor value="B1CAF6"/>
<category value="OBO"/>
</extension>

<extension id="menu.ObsoleteEntity" name="Make entity obsolete" point="org.protege.editor.core.application.EditorKitMenuAction">
<class value="org.protege.oboeditor.menu.ObsoleteEntityMenuAction"/>
<name value="Make entity obsolete"/>
<toolTip value="Deprecates the selected entity and removes its defining axioms."/>
<path value="org.protege.editor.core.application.menu.EditMenu/SlotOBO-Z"/>
<editorKitId value="OWLEditorKit"/>
</extension>

</plugin>
4 changes: 2 additions & 2 deletions update.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
id=org.protege.oboeditor
version=0.3.0
download=https://github.com/owlcollab/protege-obo-plugin/releases/download/v0.3.0/obo-annotations-plugin-0.3.0.jar
version=0.4.0
download=https://github.com/owlcollab/protege-obo-plugin/releases/download/v0.4.0/obo-annotations-plugin-0.4.0.jar
name=OBO Annotations Editor
readme=https://raw.githubusercontent.com/owlcollab/protege-obo-plugin/master/README.md
license=https://opensource.org/licenses/BSD-3-Clause
Expand Down

0 comments on commit 6d59041

Please sign in to comment.