An R interface to the Ontology Lookup Service

## Warning in fun(libname, pkgname): Package 'rols' is deprecated and will be removed from Bioconductor
##   version 3.24

Introduction

Installation

rols is a Bioconductor package and should hence be installed using the dedicated functionality

## try http:// if https:// URLs are not supported
if (!requireNamespace("BiocManager", quietly=TRUE))
    install.packages("BiocManager")
BiocManager::install("rols")

Getting help

To get help, either post your question on the Bioconductor support site or open an issue on the r Biocpkg("rols") github page.

The resource

The Ontology Lookup Service (OLS) [1, 2] is originally spin-off of the PRoteomics IDEntifications database (PRIDE) service, located at the EBI, and is now developed and maintained by the Samples, Phenotypes and Ontologies team at EMBL-EBI.

The package

The OLS provides a REST interface to hundreds of ontologies from a single location with a unified output format. The rols package make this possible from within R. Do do so, it relies on the httr2 package to query the REST interface, and access and retrieve data.

There are 280 ontologies available in the OLS, listed in the table below. Their name is to be use to defined which ontology to query.

A Brief rols overview

The rols package is build around a few classes that enable to query the OLS and retrieve, store and manipulate data. Each of these classes are described in more details in their respective manual pages. We start by loading the package.

library("rols")

Ontologies

The Ontology and Ontologies classes can store information about single of multiple ontologies. The latter can be easily subset using [ and [[, as one would for lists.

ol <- olsOntologies()
ol
## Object of class 'olsOntologies' with 280 entries
##    ADDICTO, ADO ... ZFS, ZP
head(olsNamespace(ol))
## [1] "addicto" "ado"     "aeo"     "afo"     "afpo"    "agro"
ol[["bspo"]]
## olsOntology: Biological Spatial Ontology (bspo)  
##   An ontology for respresenting spatial concepts, anatomical axes,
##   gradients, regions, planes, sides and surfaces. These concepts can be
##   used at multiple biological scales and in a diversity of taxa,
##   including plants, animals and fungi. The BSPO is used to provide a
##   source of anatomical location descriptors for logically defining
##   anatomical entity classes in anatomy ontologies.
##    Loaded: 2026-06-26 Updated: 2026-06-26 Version: 2023-05-27 
##    169 terms  236 properties  18 individuals

It is also possible to initialise a single ontology

bspo <- olsOntology("bspo")
bspo
## olsOntology: Biological Spatial Ontology (bspo)  
##   An ontology for respresenting spatial concepts, anatomical axes,
##   gradients, regions, planes, sides and surfaces. These concepts can be
##   used at multiple biological scales and in a diversity of taxa,
##   including plants, animals and fungi. The BSPO is used to provide a
##   source of anatomical location descriptors for logically defining
##   anatomical entity classes in anatomy ontologies.
##    Loaded: 2026-06-26 Updated: 2026-06-26 Version: 2023-05-27 
##    169 terms  236 properties  18 individuals

Terms

Single ontology terms are stored in olsTerm objects. When more terms need to be manipulated, they are stored as olsTerms objects. It is easy to obtain all terms of an ontology of interest, and the resulting olsTerms object can be subset using [ and [[, as one would for lists.

bspotrms <- olsTerms(bspo) ## or olsTerms("bspo")
bspotrms
## Object of class 'olsTerms' with 169 entries
##  From the BSPO ontology
##   BFO:0000002, BFO:0000003 ... IAO:0000409, PATO:0000001
bspotrms[1:10]
## Object of class 'olsTerms' with 10 entries
##  From the BSPO ontology
##   BFO:0000002, BFO:0000003 ... BFO:0000023, BFO:0000031
bspotrms[["BSPO:0000092"]]
## A olsTerm from the BSPO ontology: BSPO:0000092 
##  Label: anatomical compartment boundary
##   to be merged into CARO

It is also possible to initialise a single term

trm <- olsTerm(bspo, "BSPO:0000092")
termId(trm)
## [1] "BSPO:0000092"
termLabel(trm)
## [1] "anatomical compartment boundary"

It is then possible to extract the ancestors, descendants, parents and children terms. Each of these functions return a olsTerms object

parents(trm)
## Object of class 'olsTerms' with 1 entries
##  From the BSPO ontology
## CARO:0000010
children(trm)
## Object of class 'olsTerms' with 6 entries
##  From the BSPO ontology
##   BSPO:0000040, BSPO:0000041 ... BSPO:0000093, BSPO:0000094

Finally, a single term or terms object can be coerced to a data.frame using as(x, "data.frame").

Properties

Properties (relationships) of single or multiple terms or complete ontologies can be queries with the properties method, as briefly illustrated below.

trm <- olsTerm("uberon", "UBERON:0002107")
trm
## A olsTerm from the UBERON ontology: UBERON:0002107 
##  Label: liver
##   An exocrine gland which secretes bile and functions in metabolism of
##   protein and carbohydrate and fat, synthesizes substances involved in
##   the clotting of the blood, synthesizes vitamin A, detoxifies poisonous
##   substances, stores glycogen, and breaks down worn-out erythrocytes[GO].
p <- olsProperties(trm)
p
## Object of class 'olsProperties' with 269 entries
##  From the UBERON ontology
##   abdomen, endocrine system ... liver lobule, liver bud
p[[1]]
## A olsProperty from the UBERON ontology: UBERON:0000916 
##  Label: abdomen
termLabel(p[[1]])
## [1] "abdomen"

Use case

A researcher might be interested in the trans-Golgi network. Searching the OLS is assured by the OlsSearch and olsSearch classes/functions. The first step is to defined the search query with OlsSearch, as shown below. This creates an search object of class OlsSearch that stores the query and its parameters. In records the number of requested results (default is 20) and the total number of possible results (there are 305 results across all ontologies, in this case). At this stage, the results have not yet been downloaded, as shown by the 0 responses.

OlsSearch(q = "trans-golgi network")
## Object of class 'OlsSearch':
##   query: trans-golgi network 
##   requested: 20 (out of 305)
##   response(s): 0

305 results are probably too many to be relevant. Below we show how to perform an exact search by setting exact = TRUE, and limiting the search the the GO ontology by specifying ontology = "GO", or doing both.

OlsSearch(q = "trans-golgi network", exact = TRUE)
## Object of class 'OlsSearch':
##   query: trans-golgi network 
##   requested: 20 (out of 287)
##   response(s): 0
OlsSearch(q = "trans-golgi network", ontology = "GO")
## Object of class 'OlsSearch':
##   ontolgy: GO 
##   query: trans-golgi network 
##   requested: 20 (out of 34)
##   response(s): 0
OlsSearch(q = "trans-golgi network", ontology = "GO", exact = TRUE)
## Object of class 'OlsSearch':
##   ontolgy: GO 
##   query: trans-golgi network 
##   requested: 20 (out of 32)
##   response(s): 0

One case set the rows argument to set the number of desired results.

OlsSearch(q = "trans-golgi network", ontology = "GO", rows = 200)
## Object of class 'OlsSearch':
##   ontolgy: GO 
##   query: trans-golgi network 
##   requested: 200 (out of 34)
##   response(s): 0

See ?OlsSearch for details about retrieving many results.

Let’s proceed with the exact search and retrieve the results. Even if we request the default 20 results, only the 287 relevant result will be retrieved. The olsSearch function updates the previously created object (called qry below) by adding the results to it.

qry <- OlsSearch(q = "trans-golgi network", exact = TRUE)
(qry <- olsSearch(qry))
## Object of class 'OlsSearch':
##   query: trans-golgi network 
##   requested: 20 (out of 287)
##   response(s): 20

We can now transform this search result object into a fully fledged olsTerms object or a data.frame.

(qtrms <- as(qry, "olsTerms"))
## Warning in asMethod(object): 1 term failed to be instantiated.
## Object of class 'olsTerms' with 19 entries
##  From the PR, GO, OBA, NCIT, FYPO ontologies
##   PR:O43493, GO:0160281 ... PR:000049435, PR:000050748
str(qdrf <- as(qry, "data.frame"))
## 'data.frame':    20 obs. of  12 variables:
##  $ iri             : chr  "http://purl.obolibrary.org/obo/PR_O43493" "http://purl.obolibrary.org/obo/GO_0160281" "http://purl.obolibrary.org/obo/GO_0160282" "http://purl.obolibrary.org/obo/GO_0012510" ...
##  $ ontology_name   : chr  "pr" "go" "go" "go" ...
##  $ related_synonyms:List of 20
##   ..$ : chr  "TGN46" "TGN51" "TGOLN2"
##   ..$ : NULL
##   ..$ : NULL
##   ..$ : NULL
##   ..$ : NULL
##   ..$ : chr "internal side of trans-Golgi network transport vesicle membrane"
##   ..$ : NULL
##   ..$ : NULL
##   ..$ : chr "trans-Golgi network accessory protein p56, human"
##   ..$ : NULL
##   ..$ : chr  "Ttgn2" "TGN46" "TGN51"
##   ..$ : NULL
##   ..$ : chr  "Golgi trans face" "Golgi trans-face" "maturing face" "late Golgi"
##   ..$ : NULL
##   ..$ : chr "Golgi trans face membrane"
##   ..$ : NULL
##   ..$ : NULL
##   ..$ : NULL
##   ..$ : NULL
##   ..$ : NULL
##  $ ontology_prefix : chr  "PR" "GO" "GO" "GO" ...
##  $ short_form      : chr  "PR_O43493" "GO_0160281" "GO_0160282" "GO_0012510" ...
##  $ description     :List of 20
##   ..$ : chr  "Category=organism-gene." "A trans-Golgi network integral membrane protein 2 that is encoded in the genome of human."
##   ..$ : chr "The leaflet of the trans-Golgi network membrane that faces the cytoplasm, including any protein embedded in, at"| __truncated__
##   ..$ : chr "The leaflet of the trans-Golgi network membrane that faces the Golgi lumen, including any protein embedded in, "| __truncated__
##   ..$ : chr "The lipid bilayer surrounding a vesicle transporting substances between the trans-Golgi network and other parts of the cell."
##   ..$ : chr "A vesicle that mediates transport between the trans-Golgi network and other parts of the cell."
##   ..$ : chr "The leaflet of a trans-Golgi network transport vesicle membrane that faces the lumen, including any protein emb"| __truncated__
##   ..$ : chr "The leaflet of the trans-Golgi network transport vesicle membrane that faces the cytoplasm, including any prote"| __truncated__
##   ..$ : chr "The amount of a trans-Golgi network integral membrane protein 2 when measured in blood."
##   ..$ : chr 
##   ..$ : chr "A network of membrane components where vesicles bud off the Golgi apparatus to bring proteins, membranes and ot"| __truncated__
##   ..$ : chr  "Category=gene." "A protein that is a translation product of the human TGOLN2 gene or a 1:1 ortholog thereof."
##   ..$ : chr "A cell phenotype observed in the vegetative growth phase of the life cycle in which the localization of a prote"| __truncated__
##   ..$ : chr  "There are different opinions about whether the TGN should be considered part of the Golgi apparatus or not. We "| __truncated__ "The network of interconnected tubular and cisternal structures located within the Golgi apparatus on the side d"| __truncated__
##   ..$ : chr "A clathrin coat found on a vesicle of the trans-Golgi network."
##   ..$ : chr "The lipid bilayer surrounding any of the compartments that make up the trans-Golgi network."
##   ..$ : chr "The directed movement of substances, in membrane-bounded vesicles, from the trans-Golgi network to the recycling endosomes."
##   ..$ : chr "The volume enclosed within the membrane of a trans-Golgi network transport vesicle."
##   ..$ : chr "A process which results in the assembly, arrangement of constituent parts, or disassembly of a trans-Golgi network membrane."
##   ..$ : chr  "Category=organism-modification." "A trans-Golgi network integral membrane protein 2 (human) that has had the signal peptide removed. UniProtKB:O43493, 22-437."
##   ..$ : chr  "Category=organism-modification. Requested by=GlyGen." "A trans-Golgi network integral membrane protein 2 (human) that has been O-glycosylated at the residue equivalen"| __truncated__
##  $ label           : chr  "trans-Golgi network integral membrane protein 2 (human)" "cytoplasmic side of trans-Golgi network membrane" "lumenal side of trans-Golgi network membrane" "trans-Golgi network transport vesicle membrane" ...
##  $ obo_id          : chr  "PR:O43493" "GO:0160281" "GO:0160282" "GO:0012510" ...
##  $ type            : chr  "class" "class" "class" "class" ...
##  $ exact_synonyms  :List of 20
##   ..$ : chr  "TGN38 homolog (human)" "hTGN46" "hTGN48" "hTGN51" ...
##   ..$ : chr  "cytoplasmic face of trans-Golgi network membrane" "cytoplasmic leaflet of trans-Golgi network membrane" "cytoplasmic side of trans-Golgi network"
##   ..$ : chr  "lumenal face of trans-Golgi network membrane" "lumenal leaflet of trans-Golgi network membrane" "lumenal side of trans-Golgi network"
##   ..$ : chr  "TGN transport vesicle membrane" "trans-Golgi network constitutive secretory pathway transport vesicle membrane"
##   ..$ : chr  "TGN transport vesicle" "trans-Golgi network constitutive secretory pathway transport vesicle"
##   ..$ : NULL
##   ..$ : chr "external side of trans-Golgi network transport vesicle membrane"
##   ..$ : chr "blood trans-Golgi network integral membrane protein 2 amount"
##   ..$ : NULL
##   ..$ : chr  "TGN" "Trans-Golgi Network"
##   ..$ : chr  "TGN38 homolog" "TGN38B" "TGN48" "trans-Golgi network protein TGN51" ...
##   ..$ : NULL
##   ..$ : chr  "TGN" "trans Golgi network"
##   ..$ : chr "clathrin coat of TGN vesicle"
##   ..$ : chr "trans Golgi network membrane"
##   ..$ : NULL
##   ..$ : NULL
##   ..$ : NULL
##   ..$ : chr  "PRO_0000022486" "UniProtKB:O43493, 22-437" "hTGOLN2/SigPep-"
##   ..$ : chr  "UniProtKB:O43493, Ser-236, MOD:00002~GNO:G43417UB" "hTGOLN2/OGlyco:1"
##  $ broad_synonyms  :List of 20
##   ..$ : NULL
##   ..$ : NULL
##   ..$ : NULL
##   ..$ : NULL
##   ..$ : NULL
##   ..$ : NULL
##   ..$ : NULL
##   ..$ : NULL
##   ..$ : NULL
##   ..$ : NULL
##   ..$ : NULL
##   ..$ : NULL
##   ..$ : chr "trans face"
##   ..$ : NULL
##   ..$ : NULL
##   ..$ : NULL
##   ..$ : NULL
##   ..$ : NULL
##   ..$ : NULL
##   ..$ : NULL
##  $ narrow_synonyms :List of 20
##   ..$ : NULL
##   ..$ : NULL
##   ..$ : NULL
##   ..$ : NULL
##   ..$ : NULL
##   ..$ : NULL
##   ..$ : NULL
##   ..$ : NULL
##   ..$ : NULL
##   ..$ : NULL
##   ..$ : NULL
##   ..$ : NULL
##   ..$ : NULL
##   ..$ : NULL
##   ..$ : NULL
##   ..$ : NULL
##   ..$ : NULL
##   ..$ : NULL
##   ..$ : NULL
##   ..$ : chr "UniProtKB:O43493-2, Ser-236, MOD:00002~GNO:G43417UB"

In this case, we can see that we actually retrieve the same term used across different ontologies. In such cases, it might be useful to keep only non-redundant term instances. Here, this would have been equivalent to searching the pr, go, go, go, go, go, go, oba, ncit, pr, fypo, go, go, go, go, go, go, pr, pr ontology

qtrms <- unique(qtrms)
termOntology(qtrms)
##    PR:O43493   GO:0160281   GO:0160282   GO:0012510   GO:0030140   GO:0098540 
##         "pr"         "go"         "go"         "go"         "go"         "go" 
##   GO:0098541  OBA:2051789  NCIT:C33802 PR:000016299 FYPO:0008347   GO:0005802 
##         "go"        "oba"       "ncit"         "pr"       "fypo"         "go" 
##   GO:0030130   GO:0032588   GO:0044795   GO:0098564   GO:0098629 PR:000049435 
##         "go"         "go"         "go"         "go"         "go"         "pr" 
## PR:000050748 
##         "pr"
termNamespace(qtrms)
## $`PR:O43493`
## [1] "protein"
## 
## $`GO:0160281`
## [1] "cellular_component"
## 
## $`GO:0160282`
## [1] "cellular_component"
## 
## $`GO:0012510`
## [1] "cellular_component"
## 
## $`GO:0030140`
## [1] "cellular_component"
## 
## $`GO:0098540`
## [1] "cellular_component"
## 
## $`GO:0098541`
## [1] "cellular_component"
## 
## $`OBA:2051789`
## NULL
## 
## $`NCIT:C33802`
## NULL
## 
## $`PR:000016299`
## [1] "protein"
## 
## $`FYPO:0008347`
## NULL
## 
## $`GO:0005802`
## [1] "cellular_component"
## 
## $`GO:0030130`
## [1] "cellular_component"
## 
## $`GO:0032588`
## [1] "cellular_component"
## 
## $`GO:0044795`
## [1] "biological_process"
## 
## $`GO:0098564`
## [1] "cellular_component"
## 
## $`GO:0098629`
## [1] "biological_process"
## 
## $`PR:000049435`
## [1] "protein"
## 
## $`PR:000050748`
## [1] "protein"

Below, we execute the same query using the GO.db package.

library("GO.db")
GOTERM[["GO:0005802"]]
## GOID: GO:0005802
## Term: trans-Golgi network
## Ontology: CC
## Definition: The network of interconnected tubular and cisternal
##     structures located within the Golgi apparatus on the side distal to
##     the endoplasmic reticulum, from which secretory vesicles emerge.
##     The trans-Golgi network is important in the later stages of protein
##     secretion where it is thought to play a key role in the sorting and
##     targeting of secreted proteins to the correct destination.
## Synonym: TGN
## Synonym: trans Golgi network
## Synonym: Golgi trans face
## Synonym: Golgi trans-face
## Synonym: late Golgi
## Synonym: maturing face
## Synonym: trans face

On-line vs. off-line data

It is possible to observe different results with rols and GO.db, as a result of the different ways they access the data. rols or biomaRt perform direct online queries, while GO.db and other annotation packages use database snapshot that are updated every release.

Both approaches have advantages. While online queries allow to obtain the latest up-to-date information, such approaches rely on network availability and quality. If reproducibility is a major issue, the version of the database to be queried can easily be controlled with off-line approaches. In the case of rols, although the load date of a specific ontology can be queried with olsVersion, it is not possible to query a specific version of an ontology.

Changes

Version 2.0

rols 2.0 has substantially changed. While the table below shows some correspondence between the old and new interface, this is not always the case. The new interface relies on the Ontology/Ontologies, olsTerm/olsTerms and OlsSearch classes, that need to be instantiated and can then be queried, as described above.

version < 1.99 version >= 1.99
ontologyLoadDate olsLoaded and olsUpdated
ontologyNames Ontologies
olsVersion olsVersion
allIds terms
isIdObsolete isObsolete
rootId olsRoot
olsQuery OlsSearch and olsSearch

Not all functionality is currently available. If there is anything that you need but not available in the new version, please contact the maintained by opening an issue on the package development site.

Version 2.99

  • rols version >= 2.99 has been refactored to use the OLS4 REST API.
  • REST queries now use httr2 instead of superseded httr.
  • The term(s) constructors are capitalised as olsTerm() and olsTerms().
  • The properties constructor is capitalised as Properties().
  • Some class definitions have been updated to accomodate changes in the data received by OLS. Some function have been dropped.
  • The Ontology and Ontologies classes and constructors have been renames olsOntology and olsOntologies to avoid clashes with AnnontationDbi::Ontology().
  • The Term and Terms classes and constructors have been renames olsTerm and olsTerms to avoid clashes with AnnontationDbi::Term().

CVParams

The CVParam class is used to handle controlled vocabulary. It can be used for user-defined parameters

CVParam(name = "A user param", value = "the value")
## [, , A user param, the value]

or official controlled vocabulary (which triggers a query to the OLS service)

CVParam(label = "GO", accession = "GO:0035145")
## [GO, GO:0035145, exon-exon junction complex, ]

See ?CVParam for more details and examples.

Session information

## R version 4.6.1 (2026-06-24)
## Platform: x86_64-pc-linux-gnu
## Running under: Ubuntu 26.04 LTS
## 
## Matrix products: default
## BLAS:   /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3 
## LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.32.so;  LAPACK version 3.12.0
## 
## attached base packages:
## [1] stats4    stats     graphics  grDevices utils     datasets  methods  
## [8] base     
## 
## other attached packages:
##  [1] DT_0.34.0            rols_3.8.0           GO.db_3.23.1        
##  [4] AnnotationDbi_1.74.0 IRanges_2.46.0       S4Vectors_0.50.1    
##  [7] Biobase_2.72.0       BiocGenerics_0.58.1  generics_0.1.4      
## [10] BiocStyle_2.40.0    
## 
## loaded via a namespace (and not attached):
##  [1] rappdirs_0.3.4      sass_0.4.10         RSQLite_3.53.3     
##  [4] digest_0.6.39       magrittr_2.0.5      evaluate_1.0.5     
##  [7] fastmap_1.2.0       blob_1.3.0          jsonlite_2.0.0     
## [10] DBI_1.3.0           BiocManager_1.30.27 httr_1.4.8         
## [13] crosstalk_1.2.2     Biostrings_2.80.1   httr2_1.2.3        
## [16] jquerylib_0.1.4     cli_3.6.6           rlang_1.2.0        
## [19] crayon_1.5.3        XVector_0.52.0      bit64_4.8.2        
## [22] withr_3.0.3         cachem_1.1.0        yaml_2.3.12        
## [25] otel_0.2.0          tools_4.6.1         memoise_2.0.1      
## [28] curl_7.1.0          buildtools_1.0.0    vctrs_0.7.3        
## [31] R6_2.6.1            png_0.1-9           lifecycle_1.0.5    
## [34] KEGGREST_1.52.2     Seqinfo_1.2.0       htmlwidgets_1.6.4  
## [37] bit_4.6.0           pkgconfig_2.0.3     bslib_0.11.0       
## [40] glue_1.8.1          xfun_0.59           sys_3.4.3          
## [43] knitr_1.51          htmltools_0.5.9     rmarkdown_2.31     
## [46] maketools_1.3.2     compiler_4.6.1