Reuse

Importing FoodOn terms into your ontology

We recognize that FoodOn itself is a very large ontology, especially if one includes all food product type facets. For reuse it becomes important to just select the terms and axioms one needs for a smaller import file.

Using Ontofox

Lets say you want to import selected FoodOn terms into an ontology. The Ontofox ontology import file service is a convenient tool to enter term ids into, and retrieve the OWL file equivalent that includes annotation (label, description) and other axioms you are interested in. The Ontofox specification file it generates can then be reused in the future to import updated versions of those terms. Here is an example specification file (these parameters can also be entered into the Ontofox web form itself):

[URI of the OWL(RDF/XML) output file]
http://purl.obolibrary.org/obo/generic/foodon_import.owl

[Source ontology]
FOODON

[Low level source term URIs]
http://purl.obolibrary.org/obo/FOODON_03411564 #food source
includeAllChildren

[Top level source term URIs and target direct superclass URIs]


[Source term retrieval setting]
includeNoIntermediates

[Source annotation URIs]
http://www.w3.org/2000/01/rdf-schema#label
http://purl.obolibrary.org/obo/IAO_0000115 #iao:definition
http://www.geneontology.org/formats/oboInOwl#hasSynonym

[Source annotation URIs to be excluded]

This will create an import file containing the entire tree of “food source” (FOODON_03411564) terms from FoodOn.

Using Protégé

To some extent one can do the same thing when editing FoodOn with the Stanford Protégé OWL ontology editor. It has a way of enabling one to select classes and make a new ontology out of selected classes. However, each item has to be selected manually in their interface, which is painful when there are thousands of items descended from a root item that one wants to import.

The “Texas Chainsaw Massacre” approach can also work in a pinch: load up FoodOn in Protégé, delete all the items one doesn’t want by using the [X] option at top of Class tab above hierarchy display. Use the “(o) delete _______ and asserted descended classes” option. But this is not a convenient way to use FoodOn over time since this culling would have to be redone.

Using SPARQL + Ontofox

One can use a combination of Ontofox and the following SPARQL query in Protégé 5 to achieve term selections in a way Ontofox doesn’t support out of the box. (One may need to load the “SPARQL Query” plugin; the builtin protégé “SPARQL” tab doesn’t work on my mac). Note however that clicking on the “SPARQL Query” tab can take a long time to respond with a display of a default query and cursor because it is running some check on the ontology first. This could be alleviated by not importing the “foodon food product” branch (foodon_product_import.owl). (In the future we will offer a smaller core food product import file that will be faster to query.)

This query retrieves all underlying terms for the given top classes. Add more top-level FoodOn ids and/or make them more specific if desired.

PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX obo: <http://purl.obolibrary.org/obo/>
SELECT DISTINCT ?id ?parent ?label ?definition
	WHERE {
		{?parent rdfs:subClassOf* obo:FOODON_03411297} #animal food source
		UNION {?parent rdfs:subClassOf* obo:FOODON_03411347} # plant food source
		UNION {?parent rdfs:subClassOf* obo:FOODON_03470107} #preservation type    

		?id rdfs:subClassOf ?parent.
		OPTIONAL {?id rdfs:label ?label}.
		OPTIONAL {?id obo:IAO_0000115 ?definition.}
	}
ORDER BY ?parent ?label ?uiLabel

Below is a more precise query that gets only the “leaf” term ids, and so skips label and definition etc. We insert these results in the Ontofox form/specification file “[Low level source term URIs]” section, and we tell Ontofox to retrieve all parent terms with the “includeAllIntermediates” parameter.

PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX obo: <http://purl.obolibrary.org/obo/>
SELECT DISTINCT ?id
	WHERE {
		{?parent rdfs:subClassOf* obo:FOODON_03411297} #animal food source
		UNION {?parent rdfs:subClassOf* obo:FOODON_03411347} # plant food source
		UNION {?parent rdfs:subClassOf* obo:FOODON_03470107} #preservation type
		?id rdfs:subClassOf ?parent.
	}
ORDER BY ?label

A trick with the Protégé SPARQL Query is that one can copy the results in the result pane by clicking the cursor there, and then CTRL-a CTRL-c directly. This provides a list of ontology term ids with their full URL which can be pasted directly into the Ontofox specification file.