Skip to content

Commit

Permalink
update conversion of OBO alternate identifiers
Browse files Browse the repository at this point in the history
as discussed in
#317 (comment)
  • Loading branch information
hdietze authored and ignazio1977 committed Dec 24, 2014
1 parent a93a858 commit e1ec5d6
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 0 deletions.
57 changes: 57 additions & 0 deletions oboformat/src/main/java/org/obolibrary/obo2owl/OWLAPIObo2Owl.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import org.semanticweb.owlapi.model.OWLClassExpression;
import org.semanticweb.owlapi.model.OWLDataFactory;
import org.semanticweb.owlapi.model.OWLDocumentFormat;
import org.semanticweb.owlapi.model.OWLEntity;
import org.semanticweb.owlapi.model.OWLEquivalentClassesAxiom;
import org.semanticweb.owlapi.model.OWLIndividual;
import org.semanticweb.owlapi.model.OWLLiteral;
Expand Down Expand Up @@ -719,6 +720,13 @@ public OWLClassExpression trTermFrame(@Nonnull Frame termFrame) {
for (String t : termFrame.getTags()) {
// System.out.println("tag:"+tag);
Collection<Clause> clauses = termFrame.getClauses(t);
if (OboFormatTag.TAG_ALT_ID.getTag().equals(t)) {
// Generate deprecated and replaced_by details for alternate identifier
Set<OWLAxiom> axioms = translateAltIds(clauses, termFrame.getId(), true);
if (!axioms.isEmpty()) {
add(axioms);
}
}
Set<OWLAxiom> axioms = trTermFrameClauses(cls, clauses, t);
if (!axioms.isEmpty()) {
add(axioms);
Expand All @@ -728,6 +736,55 @@ public OWLClassExpression trTermFrame(@Nonnull Frame termFrame) {
}

/**
* Generate axioms for the alternate identifiers of an {@link OWLClass} or {@link OWLObjectProperty}.
*
* @param clauses collection of alt_id clauses
* @param replacedBy OBO style ID
* @param isClass set to true if the alt_id is represents a class, false in case of an property
* @return set of axioms generated for the alt_id clauses
*/
@Nonnull
protected Set<OWLAxiom> translateAltIds(
@Nonnull Collection<Clause> clauses, @Nonnull String replacedBy,
boolean isClass) {
Set<OWLAxiom> axioms = new HashSet<>();
for(Clause clause : clauses) {
final String altId = clause.getValue(String.class);
if (altId != null) {
final OWLEntity altIdEntity;
if (isClass) {
altIdEntity = trClass(altId);
}
else {
IRI altIdIRI = oboIdToIRI(altId);
altIdEntity = fac.getOWLObjectProperty(altIdIRI);
}
// entity declaration axiom
axioms.add(fac.getOWLDeclarationAxiom(altIdEntity));
// annotate as deprecated
axioms.add(fac.getOWLAnnotationAssertionAxiom(
altIdEntity.getIRI(), fac.getOWLAnnotation(
fac.getOWLDeprecated(),
fac.getOWLLiteral(true))));
// annotate with replaced_by (IAO_0100001)
axioms.add(fac.getOWLAnnotationAssertionAxiom(
altIdEntity.getIRI(),
fac.getOWLAnnotation( fac.getOWLAnnotationProperty(
Obo2OWLVocabulary.IRI_IAO_0100001.iri),
fac.getOWLLiteral(replacedBy))));
// annotate with obo:IAO_0000231=obo:IAO_0000227
// 'has obsolescence reason' 'terms merged'
axioms.add(fac.getOWLAnnotationAssertionAxiom(
altIdEntity.getIRI(), fac.getOWLAnnotation(
fac.getOWLAnnotationProperty(
Obo2OWLConstants.IRI_IAO_0000231),
Obo2OWLConstants.IRI_IAO_0000227)));
}
}
return axioms;
}

/**
* Tr term frame clauses.
*
* @param cls
Expand Down
52 changes: 52 additions & 0 deletions oboformat/src/main/java/org/obolibrary/obo2owl/OWLAPIOwl2Obo.java
Original file line number Diff line number Diff line change
Expand Up @@ -1605,6 +1605,14 @@ protected void tr(@Nonnull OWLDeclarationAxiom axiom) {
if (set.isEmpty()) {
return;
}
// check whether the entity is an alt_id
Optional<String> altIdOptional = isAltId(set, entity);
if (altIdOptional.isPresent()) {
// TODO make sure that the alt_id is declared in the appropriate frame
return;
}

// translate
Frame f = null;
if (entity instanceof OWLClass) {
f = getTermFrame(entity.asOWLClass());
Expand All @@ -1630,6 +1638,50 @@ protected void tr(@Nonnull OWLDeclarationAxiom axiom) {
}
}

/**
* Check the annotations of entity for axioms declaring it to be an
* obsolete entity, with 'obsolescence reason' being 'term merge', and a
* non-empty 'replaced by' literal.
*
* @param annotations set of annotations for the entity
* @param entity
* @return replaced_by if it is an alt_id
*/
@Nonnull
private Optional<String> isAltId(Set<OWLAnnotationAssertionAxiom> annotations, OWLEntity entity) {
String altId = null;
boolean isMerged = false;
boolean isDeprecated = false;
for (OWLAnnotationAssertionAxiom axiom : annotations) {
OWLAnnotationProperty prop = axiom.getProperty();
if (prop.isDeprecated()) {
isDeprecated = true;
}
else if (Obo2OWLConstants.IRI_IAO_0000231.equals(prop.getIRI())) {
OWLAnnotationValue value = axiom.getValue();
Optional<IRI> asIRI = value.asIRI();
if (asIRI.isPresent()) {
isMerged = Obo2OWLConstants.IRI_IAO_0000227.equals(asIRI.get());
}
}
else if (Obo2OWLVocabulary.IRI_IAO_0100001.iri.equals(prop.getIRI())) {
OWLAnnotationValue value = axiom.getValue();
Optional<OWLLiteral> asLiteral = value.asLiteral();
if (asLiteral.isPresent()) {
altId = asLiteral.get().getLiteral();
}
}
}
Optional<String> result;
if (altId != null && isMerged && isDeprecated) {
result = Optional.of(altId);
}
else {
result = Optional.absent();
}
return result;
}

/**
* Gets the identifier.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ public class Obo2OWLConstants {
@Nonnull
public static final String OIOVOCAB_IRI_PREFIX = "http://www.geneontology.org/formats/oboInOwl#";

/** IRI for the 'has obsolescence reason' annotation property */
@Nonnull
public static final IRI IRI_IAO_0000231 = IRI.create(DEFAULT_IRI_PREFIX+"IAO_0000231");

/** IRI for the 'terms merged' individual */
@Nonnull
public static final IRI IRI_IAO_0000227 = IRI.create(DEFAULT_IRI_PREFIX+"IAO_0000227");

/**
* @param d
* date to format
Expand Down

0 comments on commit e1ec5d6

Please sign in to comment.