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: 16 × 10
## name last_used lifetime package loader loader_param latest_param loaded
## <chr> <lgl> <dbl> <chr> <chr> <list> <lgl> <lgl>
## 1 Gene On… NA 300 Omnipa… go_onto… <named list… NA FALSE
## 2 Gene On… NA 300 Omnipa… go_onto… <named list… NA FALSE
## 3 Gene On… NA 300 Omnipa… go_onto… <named list… NA FALSE
## 4 Gene On… NA 300 Omnipa… go_onto… <named list… NA FALSE
## 5 Gene On… NA 300 Omnipa… go_onto… <named list… NA FALSE
## 6 Gene On… NA 300 Omnipa… go_onto… <named list… NA FALSE
## 7 Gene On… NA 300 Omnipa… go_onto… <named list… NA FALSE
## 8 Gene On… NA 300 Omnipa… go_onto… <named list… NA FALSE
## 9 Gene On… NA 300 Omnipa… go_onto… <named list… NA FALSE
## 10 Gene On… NA 300 Omnipa… go_onto… <named list… NA FALSE
## 11 Gene On… NA 300 Omnipa… go_onto… <named list… NA FALSE
## 12 Gene On… NA 300 Omnipa… go_onto… <named list… NA FALSE
## 13 Gene On… NA 300 Omnipa… go_onto… <named list… NA FALSE
## 14 Gene On… NA 300 Omnipa… go_onto… <named list… NA FALSE
## 15 GO anno… NA 300 Omnipa… go_anno… <named list… NA FALSE
## 16 UniProt… NA 300 Omnipa… uniprot… <named list… NA FALSE
## # … with 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_human
.
up_gs <- get_db('up_gs_human')
up_gs
## # A tibble: 20,344 × 2
## From To
## <chr> <chr>
## 1 Q96NG5 ZNF558
## 2 Q6ZN19 ZNF841
## 3 Q86XN6 ZNF761
## 4 A8MUZ8 ZNF705G
## 5 Q08ER8 ZNF543
## 6 Q9GZX5 ZNF350
## 7 Q9GZP7 VN1R1
## 8 Q3MJ13 WDR72
## 9 Q9NY84 VNN3
## 10 B1APH4 ZNF487
## # … with 20,334 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: 16 × 10
## name last_used lifetime package loader loader_param latest_param
## <chr> <dttm> <dbl> <chr> <chr> <list> <list>
## 1 Gene … NA 300 Omnipat… go_on… <named list… <lgl [1]>
## 2 Gene … NA 300 Omnipat… go_on… <named list… <lgl [1]>
## 3 Gene … NA 300 Omnipat… go_on… <named list… <lgl [1]>
## 4 Gene … NA 300 Omnipat… go_on… <named list… <lgl [1]>
## 5 Gene … NA 300 Omnipat… go_on… <named list… <lgl [1]>
## 6 Gene … NA 300 Omnipat… go_on… <named list… <lgl [1]>
## 7 Gene … NA 300 Omnipat… go_on… <named list… <lgl [1]>
## 8 Gene … NA 300 Omnipat… go_on… <named list… <lgl [1]>
## 9 Gene … NA 300 Omnipat… go_on… <named list… <lgl [1]>
## 10 Gene … NA 300 Omnipat… go_on… <named list… <lgl [1]>
## 11 Gene … NA 300 Omnipat… go_on… <named list… <lgl [1]>
## 12 Gene … NA 300 Omnipat… go_on… <named list… <lgl [1]>
## 13 Gene … NA 300 Omnipat… go_on… <named list… <lgl [1]>
## 14 Gene … NA 300 Omnipat… go_on… <named list… <lgl [1]>
## 15 GO an… NA 300 Omnipat… go_an… <named list… <lgl [1]>
## 16 UniPr… 2022-02-19 15:07:40 300 Omnipat… unipr… <named list… <named list…
## # … with 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,344 × 2
## From To
## <chr> <chr>
## 1 Q96NG5 ZNF558
## 2 Q6ZN19 ZNF841
## 3 Q86XN6 ZNF761
## 4 A8MUZ8 ZNF705G
## 5 Q08ER8 ZNF543
## 6 Q9GZX5 ZNF350
## 7 Q9GZP7 VN1R1
## 8 Q3MJ13 WDR72
## 9 Q9NY84 VNN3
## 10 B1APH4 ZNF487
## # … with 20,334 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_human')
omnipath_show_db()
## # A tibble: 16 × 10
## name last_used lifetime package loader loader_param latest_param
## <chr> <dttm> <dbl> <chr> <chr> <list> <list>
## 1 Gene … NA 300 Omnipat… go_on… <named list… <lgl [1]>
## 2 Gene … NA 300 Omnipat… go_on… <named list… <lgl [1]>
## 3 Gene … NA 300 Omnipat… go_on… <named list… <lgl [1]>
## 4 Gene … NA 300 Omnipat… go_on… <named list… <lgl [1]>
## 5 Gene … NA 300 Omnipat… go_on… <named list… <lgl [1]>
## 6 Gene … NA 300 Omnipat… go_on… <named list… <lgl [1]>
## 7 Gene … NA 300 Omnipat… go_on… <named list… <lgl [1]>
## 8 Gene … NA 300 Omnipat… go_on… <named list… <lgl [1]>
## 9 Gene … NA 300 Omnipat… go_on… <named list… <lgl [1]>
## 10 Gene … NA 300 Omnipat… go_on… <named list… <lgl [1]>
## 11 Gene … NA 300 Omnipat… go_on… <named list… <lgl [1]>
## 12 Gene … NA 300 Omnipat… go_on… <named list… <lgl [1]>
## 13 Gene … NA 300 Omnipat… go_on… <named list… <lgl [1]>
## 14 Gene … NA 300 Omnipat… go_on… <named list… <lgl [1]>
## 15 GO an… NA 300 Omnipat… go_an… <named list… <lgl [1]>
## 16 UniPr… 2022-02-19 15:07:50 300 Omnipat… unipr… <named list… <named list…
## # … with 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_human
## $name
## [1] "UniProt-GeneSymbol table (human)"
##
## $last_used
## [1] "2022-02-19 15:07:50 CET"
##
## $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,344 × 2
## From To
## <chr> <chr>
## 1 Q96NG5 ZNF558
## 2 Q6ZN19 ZNF841
## 3 Q86XN6 ZNF761
## 4 A8MUZ8 ZNF705G
## 5 Q08ER8 ZNF543
## 6 Q9GZX5 ZNF350
## 7 Q9GZP7 VN1R1
## 8 Q3MJ13 WDR72
## 9 Q9NY84 VNN3
## 10 B1APH4 ZNF487
## # … with 20,334 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.1.2 (2021-11-01)
## Platform: x86_64-pc-linux-gnu (64-bit)
## Running under: Arch Linux
##
## Matrix products: default
## BLAS: /usr/lib/libopenblasp-r0.3.19.so
## LAPACK: /usr/lib/liblapack.so.3.10.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
##
## attached base packages:
## [1] stats graphics grDevices utils datasets methods base
##
## other attached packages:
## [1] OmnipathR_3.3.14 BiocStyle_2.22.0
##
## loaded via a namespace (and not attached):
## [1] progress_1.2.2 tidyselect_1.1.1 xfun_0.29
## [4] bslib_0.3.1 purrr_0.3.4 vctrs_0.3.8
## [7] generics_0.1.1 htmltools_0.5.2 yaml_2.2.1
## [10] utf8_1.2.2 rlang_1.0.0 pkgdown_2.0.2
## [13] jquerylib_0.1.4 pillar_1.6.4 later_1.3.0
## [16] glue_1.6.1 DBI_1.1.2 rappdirs_0.3.3
## [19] bit64_4.0.5 readxl_1.3.1 lifecycle_1.0.1
## [22] stringr_1.4.0 cellranger_1.1.0 ragg_1.2.1
## [25] memoise_2.0.1 evaluate_0.14 knitr_1.37
## [28] tzdb_0.2.0 fastmap_1.1.0 curl_4.3.2
## [31] fansi_1.0.2 Rcpp_1.0.8 readr_2.1.1
## [34] backports_1.4.1 checkmate_2.0.0 BiocManager_1.30.16
## [37] cachem_1.0.6 desc_1.4.0 vroom_1.5.7
## [40] jsonlite_1.7.3 bit_4.0.4 systemfonts_1.0.3
## [43] fs_1.5.2 textshaping_0.3.6 hms_1.1.1
## [46] digest_0.6.29 stringi_1.7.6 bookdown_0.24
## [49] dplyr_1.0.7 rprojroot_2.0.2 cli_3.1.0
## [52] tools_4.1.2 magrittr_2.0.1 logger_0.2.2
## [55] sass_0.4.0 tibble_3.1.6 tidyr_1.1.4
## [58] crayon_1.4.2 pkgconfig_2.0.3 ellipsis_0.3.2
## [61] xml2_1.3.3 prettyunits_1.1.1 assertthat_0.2.1
## [64] rmarkdown_2.11 httr_1.4.2 R6_2.5.1
## [67] igraph_1.2.11 compiler_4.1.2