-
Hi, I want to find all "never in" and "only in" relations between GOs and NCBITaxon or NCBITaxon_Union. This code using owlapi 5.5 helped me finding all "only in" relations, but I am still missing "never in". IRI iri = IRI.create("http://current.geneontology.org/ontology/extensions/go-plus.owl");
OWLOntology ontology = manager.loadOntologyFromOntologyDocument(iri);
for (OWLAxiom axiom : ontology.getAxioms()) {
if (axiom.isOfType(AxiomType.SUBCLASS_OF)) {
String ax = axiom.toString();
Set<OWLEntity> signature = axiom.getSignature();
if ((ax.contains("RO_0002160") || ax.contains("RO_0002161")) && ax.contains("GO_") && ax.contains("NCBITaxon_")) {
StringBuilder sb = new StringBuilder();
for (OWLEntity owlEntity : signature) {
if (sb.length() > 0) {
sb.append(" -> ");
}
sb.append(owlEntity.getIRI()
.getRemainder()
.get());
}
System.out.println(sb.toString());
}
}
} Can anyone help to extract this information in a reliable way? |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 2 replies
-
Tagging @balhoff |
Beta Was this translation helpful? Give feedback.
-
@davidbio I finally completed this ticket (geneontology/go-ontology#19759), which makes it much easier to see "complete" taxon constraints (e.g., including those that are logically inferred from use of particular anatomical terms or cell types). So that may affect your code for querying them. After the precomputation, all relevant taxon constraints for a term should be findable by looking at its own axioms or else traversing up the "is_a" class hierarchy. No need to to traverse any other relations. The precomputed taxon constraints are merged into go-plus, and have an annotation Here is one way to get them, loosely based on your code above. I included the SNAPSHOT URL, since these precomputed results aren't in a release yet. But they should be included in the November official release. public static void main(String[] args) throws OWLOntologyCreationException {
IRI iri = IRI.create("http://purl.obolibrary.org/obo/go/snapshot/extensions/go-plus.owl");
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
OWLDataFactory factory = manager.getOWLDataFactory();
OWLObjectProperty inTaxon = factory.getOWLObjectProperty(IRI.create("http://purl.obolibrary.org/obo/RO_0002162"));
OWLAnnotationProperty source = factory.getOWLAnnotationProperty(IRI.create("http://www.geneontology.org/formats/oboInOwl#source"));
OWLLiteral computed = factory.getOWLLiteral("computed");
OWLAnnotation isComputed = factory.getOWLAnnotation(source, computed);
OWLOntology ontology = manager.loadOntologyFromOntologyDocument(iri);
for (OWLSubClassOfAxiom axiom : ontology.getAxioms(AxiomType.SUBCLASS_OF)) {
if (axiom.getAnnotations().contains(isComputed) && axiom.getSubClass().isNamed()
&& axiom.getSubClass().asOWLClass().getIRI().toString().startsWith("http://purl.obolibrary.org/obo/GO_")) {
OWLClass subclass = axiom.getSubClass().asOWLClass();
OWLClassExpression superclass = axiom.getSuperClass();
if ((superclass instanceof OWLObjectSomeValuesFrom)
&& ((OWLObjectSomeValuesFrom) superclass).getProperty().equals(inTaxon)
&& ((OWLObjectSomeValuesFrom) superclass).getFiller().isNamed()) {
System.out.println(
subclass.getIRI() +
" always_in_taxon " +
((OWLObjectSomeValuesFrom) superclass).getFiller().asOWLClass().getIRI());
} else if ((superclass instanceof OWLObjectComplementOf)
&& (((OWLObjectComplementOf) superclass).getOperand() instanceof OWLObjectSomeValuesFrom)) {
OWLObjectSomeValuesFrom svf = (OWLObjectSomeValuesFrom) ((OWLObjectComplementOf) superclass).getOperand();
if (svf.getProperty().equals(inTaxon)
&& svf.getFiller().isNamed()) {
System.out.println(
subclass.getIRI() +
" never_in_taxon " +
svf.getFiller().asOWLClass().getIRI());
}
}
}
}
} |
Beta Was this translation helpful? Give feedback.
-
Another approach that may be simpler would be to use this file: http://snapshot.geneontology.org/ontology/imports/go-computed-taxon-constraints.obo (but preferably from an official release rather than snapshot; it should be out in the November release). |
Beta Was this translation helpful? Give feedback.
-
@balhoff |
Beta Was this translation helpful? Give feedback.
-
@balhoff Honestly, I feel like this data structure is "over-engineered" and people are/will not be able to use it. They will always depend on intermediate mapping files or partial extractions like go-computed-taxon-constraints.obo. My point is that this feels too complicated for the people who want to make use of this resource. |
Beta Was this translation helpful? Give feedback.
@davidbio I finally completed this ticket (geneontology/go-ontology#19759), which makes it much easier to see "complete" taxon constraints (e.g., including those that are logically inferred from use of particular anatomical terms or cell types). So that may affect your code for querying them. After the precomputation, all relevant taxon constraints for a term should be findable by looking at its own axioms or else traversing up the "is_a" class hierarchy. No need to to traverse any other relations. The precomputed taxon constraints are merged into go-plus, and have an annotation
source "computed"
.Here is one way to get them, loosely based on your code above. I included the SNAPSHOT URL, …