The database manager in OmnipathR
Denes Turei
Institute for Computational Biomedicine, Heidelberg Universityturei.denes@gmail.com Source:
vignettes/db_manager.Rmd
db_manager.Rmd
Abstract
The database manager is an API within OmnipathR which is able to load various datasets, keep track of their usage and remove them after an expiry period. Currently it supports a few Gene Ontology and UniProt datasets, but easily can be extended to cover all datasets in the package.
Available datasets
To see a full list of datasets call the omnipath_show_db
function:
## # A tibble: 23 × 10
## name last_used lifetime package loader loader_param latest_param loaded
## <chr> <lgl> <dbl> <chr> <chr> <list> <lgl> <lgl>
## 1 Gene Onto… NA 300 Omnipa… go_on… <named list> NA FALSE
## 2 Gene Onto… NA 300 Omnipa… go_on… <named list> NA FALSE
## 3 Gene Onto… NA 300 Omnipa… go_on… <named list> NA FALSE
## 4 Gene Onto… NA 300 Omnipa… go_on… <named list> NA FALSE
## 5 Gene Onto… NA 300 Omnipa… go_on… <named list> NA FALSE
## 6 Gene Onto… NA 300 Omnipa… go_on… <named list> NA FALSE
## 7 Gene Onto… NA 300 Omnipa… go_on… <named list> NA FALSE
## 8 Gene Onto… NA 300 Omnipa… go_on… <named list> NA FALSE
## 9 Gene Onto… NA 300 Omnipa… go_on… <named list> NA FALSE
## 10 Gene Onto… NA 300 Omnipa… go_on… <named list> NA FALSE
## # ℹ 13 more rows
## # ℹ 2 more variables: db <lgl>, key <chr>
It returns a tibble where each dataset has a human readable name and a key which can be used to refer to it. We can also check here if the dataset is currently loaded, the time it’s been last used, the loader function and its arguments.
Access a dataset
Datasets can be accessed by the get_db
function. Ideally
you should call this function every time you use the dataset. The first
time it will be loaded, the subsequent times the already loaded dataset
will be returned. This way each access is registered and extends the
expiry time. Let’s load the human UniProt-GeneSymbol table. Above we see
its key is up_gs
.
up_gs <- get_db('up_gs')
up_gs
## # A tibble: 20,476 × 2
## From To
## <chr> <chr>
## 1 A0A087X1C5 CYP2D7
## 2 A0A0B4J2F0 PIGBOS1
## 3 A0A0B4J2F2 SIK1B
## 4 A0A0C5B5G6 MT-RNR1
## 5 A0A0K2S4Q6 CD300H
## 6 A0A0U1RRE5 NBDY
## 7 A0A1B0GTW7 CIROP
## 8 A0AV02 SLC12A8
## 9 A0AV96 RBM47
## 10 A0AVF1 IFT56
## # ℹ 20,466 more rows
This dataset is a two columns data frame of SwissProt IDs and Gene
Symbols. Looking again at the datasets, we find that this dataset is
loaded now and the last_used
timestamp is set to the time
we called get_db
:
## # A tibble: 23 × 10
## name last_used lifetime package loader loader_param latest_param
## <chr> <dttm> <dbl> <chr> <chr> <list> <list>
## 1 Gene O… NA 300 OmnipathR go_ontology_d… <named list> <lgl [1]>
## 2 Gene O… NA 300 OmnipathR go_ontology_d… <named list> <lgl [1]>
## 3 Gene O… NA 300 OmnipathR go_ontology_d… <named list> <lgl [1]>
## 4 Gene O… NA 300 OmnipathR go_ontology_d… <named list> <lgl [1]>
## 5 Gene O… NA 300 OmnipathR go_ontology_d… <named list> <lgl [1]>
## 6 Gene O… NA 300 OmnipathR go_ontology_d… <named list> <lgl [1]>
## 7 Gene O… NA 300 OmnipathR go_ontology_d… <named list> <lgl [1]>
## 8 Gene O… NA 300 OmnipathR go_ontology_d… <named list> <lgl [1]>
## 9 Gene O… NA 300 OmnipathR go_ontology_d… <named list> <lgl [1]>
## 10 Gene O… NA 300 OmnipathR go_ontology_d… <named list> <lgl [1]>
## # ℹ 13 more rows
## # ℹ 3 more variables: loaded <lgl>, db <list>, key <chr>
The above table contains also a reference to the dataset, and the arguments passed to the loader function:
d <- omnipath_show_db()
d %>% dplyr::pull(db) %>% magrittr::extract2(16)
## # A tibble: 20,476 × 2
## From To
## <chr> <chr>
## 1 A0A087X1C5 CYP2D7
## 2 A0A0B4J2F0 PIGBOS1
## 3 A0A0B4J2F2 SIK1B
## 4 A0A0C5B5G6 MT-RNR1
## 5 A0A0K2S4Q6 CD300H
## 6 A0A0U1RRE5 NBDY
## 7 A0A1B0GTW7 CIROP
## 8 A0AV02 SLC12A8
## 9 A0AV96 RBM47
## 10 A0AVF1 IFT56
## # ℹ 20,466 more rows
## $to
## [1] "genesymbol"
##
## $organism
## [1] 9606
If we call get_db
again, the timestamp is updated,
resetting the expiry counter:
up_gs <- get_db('up_gs')
omnipath_show_db()
## # A tibble: 23 × 10
## name last_used lifetime package loader loader_param latest_param
## <chr> <dttm> <dbl> <chr> <chr> <list> <list>
## 1 Gene O… NA 300 OmnipathR go_ontology_d… <named list> <lgl [1]>
## 2 Gene O… NA 300 OmnipathR go_ontology_d… <named list> <lgl [1]>
## 3 Gene O… NA 300 OmnipathR go_ontology_d… <named list> <lgl [1]>
## 4 Gene O… NA 300 OmnipathR go_ontology_d… <named list> <lgl [1]>
## 5 Gene O… NA 300 OmnipathR go_ontology_d… <named list> <lgl [1]>
## 6 Gene O… NA 300 OmnipathR go_ontology_d… <named list> <lgl [1]>
## 7 Gene O… NA 300 OmnipathR go_ontology_d… <named list> <lgl [1]>
## 8 Gene O… NA 300 OmnipathR go_ontology_d… <named list> <lgl [1]>
## 9 Gene O… NA 300 OmnipathR go_ontology_d… <named list> <lgl [1]>
## 10 Gene O… NA 300 OmnipathR go_ontology_d… <named list> <lgl [1]>
## # ℹ 13 more rows
## # ℹ 3 more variables: loaded <lgl>, db <list>, key <chr>
Where are the loaded datasets?
The loaded datasets live in an environment which belong to the
OmnipathR package. Normally users don’t need to access this environment.
As we see below, omnipath_show_db
presents us all
information availble by directly looking at the environment:
OmnipathR:::omnipath.env$db$up_gs
## $name
## [1] "UniProt-GeneSymbol table"
##
## $last_used
## [1] "2024-04-07 17:46:30 CEST"
##
## $lifetime
## [1] 300
##
## $package
## [1] "OmnipathR"
##
## $loader
## [1] "uniprot_full_id_mapping_table"
##
## $loader_param
## $loader_param$to
## [1] "genesymbol"
##
## $loader_param$organism
## [1] 9606
##
##
## $latest_param
## $latest_param$to
## [1] "genesymbol"
##
## $latest_param$organism
## [1] 9606
##
##
## $loaded
## [1] TRUE
##
## $db
## # A tibble: 20,476 × 2
## From To
## <chr> <chr>
## 1 A0A087X1C5 CYP2D7
## 2 A0A0B4J2F0 PIGBOS1
## 3 A0A0B4J2F2 SIK1B
## 4 A0A0C5B5G6 MT-RNR1
## 5 A0A0K2S4Q6 CD300H
## 6 A0A0U1RRE5 NBDY
## 7 A0A1B0GTW7 CIROP
## 8 A0AV02 SLC12A8
## 9 A0AV96 RBM47
## 10 A0AVF1 IFT56
## # ℹ 20,466 more rows
How to extend the expiry period?
The default expiry of datasets is given by the option
omnipath.db_lifetime
. By calling
omnipath_save_config
this option is saved to the default
config file and will be valid in all subsequent sessions. Otherwise it’s
valid only in the current session.
options(omnipath.db_lifetime = 600)
omnipath_save_config()
Where are the datasets defined?
The built-in dataset definitions are in a JSON file shipped with the package. Easiest way to see it is by the git web interface.
How to add custom datasets?
Currently no API available for this, but it would be super easy to implement. It would be matter of providing a JSON similar to the above, or calling a function. Please open an issue if you are interested in this feature.
Session information
## R version 4.3.2 (2023-10-31)
## Platform: x86_64-pc-linux-gnu (64-bit)
## Running under: Arch Linux
##
## Matrix products: default
## BLAS: /usr/lib/libblas.so.3.12.0
## LAPACK: /usr/lib/liblapack.so.3.12.0
##
## locale:
## [1] LC_CTYPE=en_GB.UTF-8 LC_NUMERIC=C
## [3] LC_TIME=en_GB.UTF-8 LC_COLLATE=en_GB.UTF-8
## [5] LC_MONETARY=en_GB.UTF-8 LC_MESSAGES=en_GB.UTF-8
## [7] LC_PAPER=en_GB.UTF-8 LC_NAME=C
## [9] LC_ADDRESS=C LC_TELEPHONE=C
## [11] LC_MEASUREMENT=en_GB.UTF-8 LC_IDENTIFICATION=C
##
## time zone: Europe/Madrid
## tzcode source: system (glibc)
##
## attached base packages:
## [1] stats graphics grDevices utils datasets methods base
##
## other attached packages:
## [1] OmnipathR_3.11.10 BiocStyle_2.30.0
##
## loaded via a namespace (and not attached):
## [1] tidyr_1.3.1 rappdirs_0.3.3 sass_0.4.9
## [4] utf8_1.2.4 generics_0.1.3 xml2_1.3.6
## [7] stringi_1.8.3 hms_1.1.3 digest_0.6.35
## [10] magrittr_2.0.3 evaluate_0.23 timechange_0.3.0
## [13] bookdown_0.38 fastmap_1.1.1 cellranger_1.1.0
## [16] jsonlite_1.8.8 progress_1.2.3 backports_1.4.1
## [19] BiocManager_1.30.22 rvest_1.0.4 httr_1.4.7
## [22] selectr_0.4-2 purrr_1.0.2 fansi_1.0.6
## [25] textshaping_0.3.7 jquerylib_0.1.4 cli_3.6.2
## [28] rlang_1.1.3 crayon_1.5.2 bit64_4.0.5
## [31] withr_3.0.0 cachem_1.0.8 yaml_2.3.8
## [34] tools_4.3.2 tzdb_0.4.0 memoise_2.0.1
## [37] checkmate_2.3.1 dplyr_1.1.4 curl_5.2.1
## [40] vctrs_0.6.5 logger_0.3.0 R6_2.5.1
## [43] lifecycle_1.0.4 lubridate_1.9.3 stringr_1.5.1
## [46] bit_4.0.5 fs_1.6.3 vroom_1.6.5
## [49] ragg_1.2.7 pkgconfig_2.0.3 desc_1.4.3
## [52] pkgdown_2.0.7 pillar_1.9.0 bslib_0.6.1
## [55] later_1.3.2 glue_1.7.0 Rcpp_1.0.12
## [58] systemfonts_1.0.6 xfun_0.42 tibble_3.2.1
## [61] tidyselect_1.2.1 knitr_1.45 htmltools_0.5.7
## [64] igraph_2.0.3 rmarkdown_2.26 readr_2.1.5
## [67] compiler_4.3.2 prettyunits_1.2.0 readxl_1.4.3