7.12.2. Application ontology for metabolomics




Recipe Overview
Reading Time
30 minutes
Executable Code
Yes
Difficulty
MSIO build process
FAIRPlus logo
Recipe Type
Hands-on
Maturity Level & Indicator
hover me Tooltip text

7.12.2.1. Overview

MSIO an Application Ontology for Metabolomics. We detail how we use OBO Foundry ROBOT tool for generating the ontology from a set of seeds, which have been established by manual selection of the key classes to build a mild level ontology for experiments. MSIO specific classes are added the MSIO namespace but remain compatible with OBI for which MSIO can become a module.

7.12.2.2. Obtaining and installing robot

The robot tool is available from: http://robot.obolibrary.org/ with detailed instructions available from the official pages. One may obtain the latest official version or the latest successful build from the obofoundry project. This the latter option we go for in this notebook as we want to test a new function available from version 1.7, onwards.

import os
robot_dir="robot_jar"
if not os.path.exists(robot_dir):
    os.makedirs(robot_dir)
    
# Check if a newer versio exists a:

get_robot_curl="curl -L https://build.obolibrary.io/job/ontodev/job/robot/job/master/lastSuccessfulBuild/artifact/bin/robot.jar > ./robot_jar/robot.jar"
try:
    os.system(get_robot_curl)
except IOError as ioe_curl:
            print(ioe_curl)
resources=[
"curl -L http://purl.obolibrary.org/obo/duo.owl   > ./ontology-sources-test/duo.owl",
"curl -L http://purl.obolibrary.org/obo/stato.owl > ./ontology-sources-test/stato.owl",
"curl -L http://purl.obolibrary.org/obo/chmo.owl  > ./ontology-sources-test/chmo.owl",
"curl -L http://purl.obolibrary.org/obo/iao.owl   > ./ontology-sources-test/iao.owl",
"curl -L http://purl.obolibrary.org/obo/obi.owl   > ./ontology-sources-test/obi.owl",
"curl -L http://purl.obolibrary.org/obo/ms.owl    > ./ontology-sources-test/ms.owl",
"curl -L https://raw.githubusercontent.com/MSI-Metabolomics-Standards-Initiative/nmrcv/master/nmrCV-corrected-namespace.owl > ./ontology-sources-test/nmrcv.owl",
"curl -L http://purl.obolibrary.org/obo/chebi.owl > ./ontology-sources-test/chebi.owl",
"curl -L http://purl.obolibrary.org/obo/uo.owl    > ./ontology-sources-test/uo.owl",
"curl -L http://purl.obolibrary.org/obo/stato.owl > ./ontology-sources-test/stato.owl"          
]
cwd = os.getcwd()
print(cwd)
/Users/philippe/Documents/git/FAIRplus-org/the-fair-cookbook/docs/content/recipes/ontology-robot

7.12.2.3. 1. Downloading Reference Ontologies & Key Resources:

ontoresource_dir="ontology-sources-test"
if not os.path.exists(ontoresource_dir):
    os.makedirs(ontoresource_dir)
else:
    for resource in resources:
        try:
            print(resource)
            os.system(resource)
        except IOError as ioe_curl:
            print(ioe_curl)

7.12.2.4. 2. Module Extraction from seeds using the MIREOT approach:

Using a number of seed files, which contains the classes manually selected by the ontology developers, we use the MIREOT method

onto_outputdir="ontology-msio-build-modules"

extractors=[
"java -jar ./robot_jar/robot.jar extract --method MIREOT --input ./ontology-sources-test/chebi.owl --upper-terms ./ontology-select-classes/chebi-upper-terms.txt --lower-terms ./ontology-select-classes/chebi-lower-terms.txt --intermediates none --imports exclude --copy-ontology-annotations true --output ./ontology-msio-build-modules/chebi_mireot_module.owl",
"java -jar ./robot_jar/robot.jar extract --method MIREOT --input ./ontology-sources-test/chmo.owl  --lower-terms ./ontology-select-classes/chmo-lower-terms.txt  --intermediates all --copy-ontology-annotations true --output ./ontology-msio-build-modules/chmo_mireot_module.owl",
"java -jar ./robot_jar/robot.jar extract --method MIREOT --input ./ontology-sources-test/iao.owl   --lower-terms ./ontology-select-classes/iao-lower-terms.txt   --intermediates all --copy-ontology-annotations true --output ./ontology-msio-build-modules/iao_mireot_robot_module.owl",
"java -jar ./robot_jar/robot.jar extract --method MIREOT --input ./ontology-sources-test/obi.owl   --lower-terms ./ontology-select-classes/obi-lower-terms.txt   --intermediates all --copy-ontology-annotations true --output ./ontology-msio-build-modules/obi_mireot_robot_module.owl",
"java -jar ./robot_jar/robot.jar extract --method MIREOT --input ./ontology-sources-test/ms.owl --lower-terms ./ontology-select-classes/psims-lower-terms.txt --intermediates minimal --copy-ontology-annotations true --output ./ontology-msio-build-modules/psims_mireot_robot_module.owl",
"java -jar ./robot_jar/robot.jar extract --method MIREOT --input ./ontology-sources-test/uo.owl    --lower-terms ./ontology-select-classes/uo-lower-terms.txt    --intermediates minimal --copy-ontology-annotations true --output ./ontology-msio-build-modules/uo_mireot_robot_module.owl",
"java -jar ./robot_jar/robot.jar extract --method MIREOT --input ./ontology-sources-test/duo.owl   --lower-terms ./ontology-select-classes/duo-lower-terms.txt   --intermediates all --copy-ontology-annotations true --output ./ontology-msio-build-modules/duo_mireot_robot_module.owl"
] 

if not os.path.exists(onto_outputdir):
    os.makedirs(onto_outputdir)
else:
    for extractor in extractors:
        try:
            print(extractor)
            os.system(extractor)
        except IOError as ioe:
            print(ioe)    

7.12.2.5. 3. Merging Extracted Modules into Application Ontology:

This step simply fuses all the input OWL files into one single output, avoiding use of import statements.
:octocat: A merge can be undone with unmerge command also available from robot tool.

if not os.path.exists("ontology-msio-build-results"):
    os.makedirs("ontology-msio-build-results")
    try:
        print(os.getcwd())
        os.system("java -jar ./robot_jar/robot.jar merge --input ./ontology-msio-build-modules/iao_mireot_robot_module.owl --input ./ontology-msio-build-modules/obi_mireot_robot_module.owl --input ./ontology-msio-build-modules/duo_mireot_robot_module.owl --input ./ontology-msio-build-modules/chmo_mireot_module.owl --input ./ontology-msio-build-modules/uo_mireot_robot_module.owl --input ./ontology-msio-build-modules/psims_mireot_robot_module.owl  --input ./ontology-msio-build-modules/chebi_mireot_module.owl --output ./ontology-msio-build-results/msio-test-merge.owl")
    except IOError as ioe_merge:
        print(ioe_merge)
else:
    try:
        print(os.getcwd())
        os.system("java -jar ./robot_jar/robot.jar merge --input ./ontology-msio-build-modules/iao_mireot_robot_module.owl --input ./ontology-msio-build-modules/obi_mireot_robot_module.owl --input ./ontology-msio-build-modules/duo_mireot_robot_module.owl --input ./ontology-msio-build-modules/chmo_mireot_module.owl --input ./ontology-msio-build-modules/uo_mireot_robot_module.owl --input ./ontology-msio-build-modules/psims_mireot_robot_module.owl  --input ./ontology-msio-build-modules/chebi_mireot_module.owl --output ./ontology-msio-build-results/msio-test-merge.owl")
    except IOError as ioe_merge:
        print(ioe_merge)    
/Users/philippe/Documents/git/FAIRplus-org/the-fair-cookbook/docs/content/recipes/ontology-robot

7.12.2.6. 4. Working with ELK reasoner with Robot Materialize:

With this step, the goal is to ensure that the ontology is logically consistent. This can only be checked by running a reasoner, which will formally assess the various axioms used in the ontology and classify the classes bases on these constraints. Robot allows this step to be performed and provides various options as to which reasoner to offer. Here, the ELK reasoner is used.

if not os.path.exists("ontology-msio-materialize"):
    os.makedirs("ontology-msio-materialize")
else:    
    try:
        os.system("java -jar ./robot_jar/robot.jar materialize --reasoner ELK  --input ./ontology-msio-build-results/msio-test-merge.owl  reduce --output ./ontology-msio-materialize/msio-test-materialize.owl")
    except IOError as ioe_reason:
        print(ioe_reason)    

7.12.2.7. 5. Convert to OBO Format:

The module extraction, merging and reasoning function produce Ontology Web Language (OWL) documents. For reaching a wider audience and to allow use by some data entry tools, it is interesting to release the ontology in the OBO format. The following section details how to invoke the command.

if not os.path.exists("ontology-msio-convert"):
    os.makedirs("ontology-msio-convert")
    try:
        os.system("java -jar ./robot_jar/robot.jar convert --input ./ontology-msio-materialize/msio-test-materialize.owl --format obo --output ./ontology-msio-convert/msio-test-conversion.obo")
    except IOError as ioe_reason:
        print(ioe_reason) 
else:    
    try:
        os.system("java -jar ./robot_jar/robot.jar convert --input ./ontology-msio-materialize/msio-test-materialize.owl --format obo --output ./ontology-msio-convert/msio-test-conversion.obo")
    except IOError as ioe_reason:
        print(ioe_reason)         

7.12.2.8. 6. Importing stato and nmrCV ontology

# if not os.path.exists("ontology-msio-merge"):
#     os.makedirs("ontology-msio-merge")
# else: 
#     try:
#         os.system("java -jar robot.jar merge --input ./ontology-msio-materialize/msio-test-materialize.owl --input ./ontology-sources-modules/stato.owl --input ./ontology-sources-modules/nmrcv.owl --output ./ontology-msio-merge/msio-test-merge-round2.owl")
#     except IOError as ioe_convert:
#         print(ioe_convert)     

7.12.2.9. 7. Export as Tabular Representation in Excel format

A new function in Robot tool (starting with version 1.7) provides the option of exporting the classes and properties of an ontology in a tabular representation, which can be useful to engage with users and curators for review and extension. The following section details how to invoke the command.

if not os.path.exists("ontology-msio-export"):
    os.makedirs("ontology-msio-export")
    try:
        os.system("java -jar ./robot_jar/robot.jar export --input ./ontology-msio-materialize/msio-test-materialize.owl --header 'IRI|ID|LABEL|SubClass Of|definition' --format xlsx --export ./ontology-msio-export/msio-test-export.xlsx")
    except IOError as ioe_convert:
        print(ioe_convert)
else: 
    try:
        os.system("java -jar ./robot_jar/robot.jar export --input ./ontology-msio-materialize/msio-test-materialize.owl --header 'IRI|ID|LABEL|SubClass Of|definition' --format xlsx --export ./ontology-msio-export/msio-test-export.xlsx")
    except IOError as ioe_convert:
        print(ioe_convert)

7.12.2.10. References

7.12.2.11. Authors

7.12.2.12. License