├── .Rbuildignore ├── .covrignore ├── .github ├── .gitignore ├── ISSUE_TEMPLATE.md ├── SUPPORT.md └── workflows │ ├── check-standard.yaml │ └── pkgdown.yaml ├── .gitignore ├── .lintr ├── CRAN-SUBMISSION ├── DESCRIPTION ├── Dockerfile ├── LICENSE.md ├── Makefile ├── NAMESPACE ├── NEWS.md ├── R ├── confounder.R ├── cypher.R ├── drugs.R ├── epigraphdb-package.R ├── genetic_cor.R ├── literature.R ├── mappings.R ├── meta.R ├── mr.R ├── obs_cor.R ├── ontology.R ├── pathway.R ├── pqtl.R ├── protein.R ├── request_and_response.R ├── utils-pipe.R ├── xqtl.R └── zzz.R ├── README.md ├── _pkgdown.yml ├── codecov.yml ├── cran-comments.md ├── docker-compose.yml ├── epigraphdb.Rproj ├── inst └── WORDLIST ├── man ├── api_get_request.Rd ├── api_post_request.Rd ├── api_request.Rd ├── confounder.Rd ├── cypher.Rd ├── drugs_risk_factors.Rd ├── epigraphdb-package.Rd ├── figures │ ├── epigraphdb-logo.svg │ ├── mrc-ieu-logo.png │ └── uob.svg ├── flatten_response.Rd ├── genetic_cor.Rd ├── http_condition.Rd ├── literature_gwas.Rd ├── mappings_gene_to_protein.Rd ├── meta_nodes_list.Rd ├── meta_nodes_list_node.Rd ├── meta_nodes_search_node.Rd ├── meta_rels_list.Rd ├── meta_rels_list_rel.Rd ├── mr.Rd ├── obs_cor.Rd ├── ontology_gwas_efo.Rd ├── pathway.Rd ├── pipe.Rd ├── pqtl.Rd ├── pqtl_list.Rd ├── pqtl_pleio.Rd ├── protein_in_pathway.Rd ├── query_epigraphdb.Rd ├── stop_for_status.Rd ├── xqtl_multi_snp_mr.Rd └── xqtl_single_snp_mr.Rd ├── pkg-build └── .gitkeep ├── pkgdown ├── extra.css └── favicon │ ├── apple-touch-icon-120x120.png │ ├── apple-touch-icon-152x152.png │ ├── apple-touch-icon-180x180.png │ ├── apple-touch-icon-60x60.png │ ├── apple-touch-icon-76x76.png │ ├── apple-touch-icon.png │ ├── favicon-16x16.png │ ├── favicon-32x32.png │ └── favicon.ico ├── scripts └── precompute.R ├── tests ├── spelling.R ├── testthat.R └── testthat │ ├── test-confounder.R │ ├── test-cypher.R │ ├── test-drugs.R │ ├── test-error-grace.R │ ├── test-genetic_cor.R │ ├── test-literature.R │ ├── test-mappings.R │ ├── test-meta.R │ ├── test-mr.R │ ├── test-obs_cor.R │ ├── test-ontology.R │ ├── test-pathway.R │ ├── test-pqtl.R │ ├── test-protein.R │ ├── test-request_and_response.R │ └── test-xqtl.R ├── vignettes ├── .gitignore ├── about.Rmd ├── figures │ ├── epigraphdb-api-swagger.png │ ├── epigraphdb-docs.png │ ├── epigraphdb-home-view.png │ ├── epigraphdb-r.png │ └── epigraphdb-xqtl-view.png ├── getting-started-with-epigraphdb-r.Rmd ├── meta-functionalities.Rmd ├── options.Rmd ├── using-epigraphdb-api.Rmd └── using-epigraphdb-r-package.Rmd └── vignettes_src ├── .gitignore ├── about.Rmd ├── getting-started-with-epigraphdb-r.Rmd ├── meta-functionalities.Rmd ├── options.Rmd ├── using-epigraphdb-api.Rmd └── using-epigraphdb-r-package.Rmd /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^epigraphdb\.Rproj$ 2 | ^\.Rproj\.user$ 3 | ^LICENSE\.md$ 4 | ^README\.Rmd$ 5 | ^cran-comments\.md$ 6 | ^\.github$ 7 | ^\.git$ 8 | ^_pkgdown\.yml$ 9 | ^docs$ 10 | ^pkgdown$ 11 | ^\.gitlab-ci\.yml$ 12 | ^TODO.org$ 13 | ^TODO.md$ 14 | ^TAGS$ 15 | ^Makefile$ 16 | ^ci$ 17 | ^\.lintr$ 18 | ^\.travis\.yml$ 19 | ^codecov\.yml$ 20 | ^\.Rprofile$ 21 | ^\.covrignore$ 22 | ^CRAN-RELEASE$ 23 | ^\.Rcheck$ 24 | ^Dockerfile$ 25 | ^docker-compose.yml$ 26 | ^\.ipynb_checkpoints$ 27 | ^\.env$ 28 | ^pkg-build$ 29 | ^scripts$ 30 | ^vignettes_src$ 31 | ^CRAN-SUBMISSION$ 32 | -------------------------------------------------------------------------------- /.covrignore: -------------------------------------------------------------------------------- 1 | R/zzz.R 2 | -------------------------------------------------------------------------------- /.github/.gitignore: -------------------------------------------------------------------------------- 1 | *.html 2 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | Please briefly describe your problem and what output you expect. If you have a question, please don't use this form. Instead, ask on or . 2 | 3 | Please include a minimal reproducible example (AKA a reprex). If you've never heard of a [reprex](https://reprex.tidyverse.org/) before, start by reading . 4 | 5 | --- 6 | 7 | Brief description of the problem 8 | 9 | ```r 10 | # insert reprex here 11 | ``` 12 | -------------------------------------------------------------------------------- /.github/SUPPORT.md: -------------------------------------------------------------------------------- 1 | # Getting help with epigraphdb 2 | 3 | Thanks for using epigraphdb. Before filing an issue, there are a few places 4 | to explore and pieces to put together to make the process as smooth as possible. 5 | 6 | Start by making a minimal **repr**oducible **ex**ample using the 7 | [reprex](https://reprex.tidyverse.org/) package. If you haven't heard of or used 8 | reprex before, you're in for a treat! Seriously, reprex will make all of your 9 | R-question-asking endeavors easier (which is a pretty insane ROI for the five to 10 | ten minutes it'll take you to learn what it's all about). For additional reprex 11 | pointers, check out the [Get help!](https://www.tidyverse.org/help/) section of 12 | the tidyverse site. 13 | 14 | Armed with your reprex, the next step is to figure out [where to ask](https://www.tidyverse.org/help/#where-to-ask). 15 | 16 | * If it's a question: start with [community.rstudio.com](https://community.rstudio.com/), 17 | and/or StackOverflow. There are more people there to answer questions. 18 | * If it's a bug: you're in the right place, file an issue. 19 | * If you're not sure: let the community help you figure it out! If your 20 | problem _is_ a bug or a feature request, you can easily return here and 21 | report it. 22 | 23 | Before opening a new issue, be sure to [search issues and pull requests](https://github.com/tidyverse/epigraphdb/issues) to make sure the 24 | bug hasn't been reported and/or already fixed in the development version. By 25 | default, the search will be pre-populated with `is:issue is:open`. You can 26 | [edit the qualifiers](https://help.github.com/articles/searching-issues-and-pull-requests/) 27 | (e.g. `is:pr`, `is:closed`) as needed. For example, you'd simply 28 | remove `is:open` to search _all_ issues in the repo, open or closed. 29 | 30 | 31 | If you _are_ in the right place, and need to file an issue, please review the 32 | ["File issues"](https://www.tidyverse.org/contribute/#issues) paragraph from 33 | the tidyverse contributing guidelines. 34 | 35 | Thanks for your help! 36 | -------------------------------------------------------------------------------- /.github/workflows/check-standard.yaml: -------------------------------------------------------------------------------- 1 | # For help debugging build failures open an issue on the RStudio community with the 'github-actions' tag. 2 | # https://community.rstudio.com/new-topic?category=Package%20development&tags=github-actions 3 | on: 4 | push: 5 | branches: 6 | - main 7 | - master 8 | pull_request: 9 | branches: 10 | - main 11 | - master 12 | schedule: 13 | - cron: '21 4 * * 0' 14 | workflow_dispatch 15 | 16 | name: R-CMD-check 17 | 18 | jobs: 19 | R-CMD-check: 20 | runs-on: ${{ matrix.config.os }} 21 | 22 | name: ${{ matrix.config.os }} (${{ matrix.config.r }}) 23 | 24 | strategy: 25 | fail-fast: false 26 | matrix: 27 | config: 28 | - {os: windows-latest, r: 'release'} 29 | - {os: macOS-latest, r: 'release'} 30 | - {os: ubuntu-20.04, r: 'release', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"} 31 | - {os: ubuntu-20.04, r: 'devel', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"} 32 | 33 | env: 34 | R_REMOTES_NO_ERRORS_FROM_WARNINGS: true 35 | RSPM: ${{ matrix.config.rspm }} 36 | GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} 37 | 38 | steps: 39 | - uses: actions/checkout@v2 40 | 41 | - uses: r-lib/actions/setup-r@v1 42 | with: 43 | r-version: ${{ matrix.config.r }} 44 | 45 | - uses: r-lib/actions/setup-pandoc@v1 46 | 47 | - name: Query dependencies 48 | run: | 49 | install.packages('remotes') 50 | saveRDS(remotes::dev_package_deps(dependencies = TRUE), ".github/depends.Rds", version = 2) 51 | writeLines(sprintf("R-%i.%i", getRversion()$major, getRversion()$minor), ".github/R-version") 52 | shell: Rscript {0} 53 | 54 | - name: Cache R packages 55 | if: runner.os != 'Windows' 56 | uses: actions/cache@v2 57 | with: 58 | path: ${{ env.R_LIBS_USER }} 59 | key: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('.github/depends.Rds') }} 60 | restore-keys: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1- 61 | 62 | - name: Install system dependencies 63 | if: runner.os == 'Linux' 64 | run: | 65 | while read -r cmd 66 | do 67 | eval sudo $cmd 68 | done < <(Rscript -e 'writeLines(remotes::system_requirements("ubuntu", "20.04"))') 69 | 70 | - name: Install dependencies 71 | run: | 72 | remotes::install_deps(dependencies = TRUE) 73 | remotes::install_cran("rcmdcheck") 74 | shell: Rscript {0} 75 | 76 | - name: R CMD CHECK 77 | env: 78 | _R_CHECK_CRAN_INCOMING_REMOTE_: false 79 | CI: true 80 | run: | 81 | options(crayon.enabled = TRUE) 82 | rcmdcheck::rcmdcheck(args = c("--no-manual", "--as-cran"), error_on = "warning", check_dir = "check") 83 | shell: Rscript {0} 84 | 85 | - name: Upload check results 86 | if: failure() 87 | uses: actions/upload-artifact@main 88 | with: 89 | name: ${{ runner.os }}-r${{ matrix.config.r }}-results 90 | path: check 91 | 92 | - name: devtools::run_examples 93 | env: 94 | CI: true 95 | run: | 96 | devtools::run_examples(run_dontrun = TRUE) 97 | shell: Rscript {0} 98 | 99 | - name: devtools::test 100 | env: 101 | CI: true 102 | run: | 103 | devtools::test() 104 | shell: Rscript {0} 105 | -------------------------------------------------------------------------------- /.github/workflows/pkgdown.yaml: -------------------------------------------------------------------------------- 1 | on: 2 | push: 3 | branches: 4 | - main 5 | - master 6 | 7 | name: pkgdown 8 | 9 | jobs: 10 | pkgdown: 11 | runs-on: macOS-latest 12 | env: 13 | GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} 14 | steps: 15 | - uses: actions/checkout@v2 16 | 17 | - uses: r-lib/actions/setup-r@v1 18 | 19 | - uses: r-lib/actions/setup-pandoc@v1 20 | 21 | - name: Query dependencies 22 | run: | 23 | install.packages('remotes') 24 | saveRDS(remotes::dev_package_deps(dependencies = TRUE), ".github/depends.Rds", version = 2) 25 | writeLines(sprintf("R-%i.%i", getRversion()$major, getRversion()$minor), ".github/R-version") 26 | shell: Rscript {0} 27 | 28 | - name: Cache R packages 29 | uses: actions/cache@v2 30 | with: 31 | path: ${{ env.R_LIBS_USER }} 32 | key: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('.github/depends.Rds') }} 33 | restore-keys: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1- 34 | 35 | - name: Install dependencies 36 | run: | 37 | remotes::install_deps(dependencies = TRUE) 38 | install.packages("pkgdown", type = "binary") 39 | shell: Rscript {0} 40 | 41 | - name: Install package 42 | run: R CMD INSTALL . 43 | 44 | - name: Deploy package 45 | run: | 46 | git config --local user.email "actions@github.com" 47 | git config --local user.name "GitHub Actions" 48 | Rscript -e 'pkgdown::deploy_to_branch(new_process = FALSE, run_dont_run = TRUE)' 49 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .Rproj.user 2 | inst/doc 3 | .Rhistory 4 | .Rprofile 5 | .RData 6 | docs/ 7 | CRAN-RELEASE 8 | *.Rcheck 9 | -------------------------------------------------------------------------------- /.lintr: -------------------------------------------------------------------------------- 1 | linters: with_defaults(object_usage_linter = NULL, line_length_linter(120)) 2 | -------------------------------------------------------------------------------- /CRAN-SUBMISSION: -------------------------------------------------------------------------------- 1 | Version: 0.2.3 2 | Date: 2022-01-14 19:42:16 UTC 3 | SHA: 41fba32c8083240934546a91eba652d73a08674f 4 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: epigraphdb 2 | Title: Interface Package for the 'EpiGraphDB' Platform 3 | Version: 0.2.3 4 | Authors@R: c( 5 | person("Yi", "Liu", email = "yi6240.liu@bristol.ac.uk", 6 | role = c("cre", "aut") 7 | ), 8 | person("Valeriia", "Haberland", email = "valeriia.haberland@bristol.ac.uk", 9 | role = c("aut") 10 | ), 11 | person("Marina", "Vabistsevits", email = "ny19205@bristol.ac.uk", 12 | role = c("aut") 13 | ), 14 | person("Tom", "Gaunt", email = "Tom.Gaunt@bristol.ac.uk", 15 | role = c("aut") 16 | ), 17 | person(given = "MRC IEU", role = c("cph")) 18 | ) 19 | Description: The interface package to access data from the 20 | 'EpiGraphDB' platform. 21 | It provides easy access to the 'EpiGraphDB' platform with functions that 22 | query the corresponding REST endpoints on the API 23 | and return the response data in the 'tibble' data frame format. 24 | URL: https://mrcieu.github.io/epigraphdb-r/ 25 | BugReports: https://github.com/MRCIEU/epigraphdb-r/issues 26 | License: GPL-3 27 | Suggests: 28 | testthat, 29 | roxygen2, 30 | knitr, 31 | rmarkdown, 32 | spelling, 33 | devtools, 34 | usethis, 35 | pkgdown, 36 | styler, 37 | lintr, 38 | covr, 39 | igraph, 40 | gtools, 41 | stringr, 42 | dplyr, 43 | ggplot2 44 | Encoding: UTF-8 45 | Roxygen: list(markdown = TRUE) 46 | RoxygenNote: 7.1.2 47 | Imports: 48 | magrittr, 49 | tibble, 50 | httr, 51 | glue, 52 | purrr, 53 | jsonlite 54 | VignetteBuilder: knitr 55 | Language: en-GB 56 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM rocker/verse:4.1.2 2 | MAINTAINER Yi Liu 3 | 4 | RUN apt --allow-releaseinfo-change update && \ 5 | apt install -y \ 6 | build-essential libglpk40 \ 7 | texlive-fonts-recommended 8 | WORKDIR /data 9 | # install the dependencies of devtools which has not been fully installed 10 | RUN Rscript -e "install.packages('devtools', dependencies = TRUE)" 11 | COPY ./DESCRIPTION ./ 12 | RUN Rscript -e "devtools::install(dependencies = TRUE)" 13 | CMD bash 14 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: lint docs build test tests fmt init 2 | 3 | ################################################################################# 4 | # Rules 5 | ################################################################################# 6 | 7 | ## ==== codebase devel ==== 8 | 9 | ## Lint codebase 10 | lint: 11 | Rscript -e "lintr::lint_package()" 12 | 13 | ## Format codebase 14 | fmt: 15 | Rscript -e "styler::style_pkg(filetype=c('R', 'Rmd'))" 16 | 17 | ## testthat 18 | test: 19 | CI=true Rscript -e "devtools::test()" 20 | 21 | tests: test 22 | 23 | ## ==== package build ==== 24 | 25 | ## Update rd docs 26 | roxygen: 27 | CI=true Rscript -e "devtools::document()" 28 | 29 | ## devtools::check (superset of unit tests) 30 | check: 31 | CI=true Rscript -e "devtools::check()" 32 | 33 | ## devtools::run_examples, including don't run 34 | run_examples: 35 | CI=true Rscript -e "devtools::run_examples(run_dontrun = TRUE)" 36 | 37 | ## Precompute vignetts 38 | precompute_docs: 39 | CI=true Rscript scripts/precompute.R 40 | 41 | ## Build pkgdown documentation 42 | docs: 43 | CI=true Rscript -e "pkgdown::build_site(run_dont_run = TRUE)" 44 | 45 | ## Build package 46 | build: 47 | CI=true Rscript -e "devtools::build(path = '/pkg-build', vignettes = TRUE, manual = TRUE)" 48 | 49 | ## ==== CRAN submission ==== 50 | 51 | ## Check for CRAN submission 52 | ## (note: assuming path to package is /build/epigraphdb_0.2.3.tar.gz) 53 | r-cmd-check: 54 | CI=true R CMD check --as-cran /pkg-build/epigraphdb_0.2.3.tar.gz 55 | 56 | ## Check for CRAN submission (via rhub's remote specs) 57 | ## (note: you should have manually done rhub::validate_email, 58 | ## as https://r-hub.github.io/rhub/articles/rhub.html) 59 | rhub-check-cran: 60 | # NOTE: the env_var tries to deal with utf8 issues 61 | # https://github.com/r-hub/rhub/issues/374 62 | # Rscript -e "rhub::check_for_cran(env_vars=c(R_COMPILE_AND_INSTALL_PACKAGES = 'always'))" 63 | Rscript -e "devtools::check_rhub(interactive = FALSE, env_vars=c(R_COMPILE_AND_INSTALL_PACKAGES = 'always'))" 64 | 65 | ## Check for MS windows compatibility (via devtools::check_win_devel) 66 | rhub-check-windows: 67 | Rscript -e "devtools::check_win_devel()" 68 | Rscript -e "devtools::check_win_release()" 69 | 70 | ## ==== less frequently used utils ==== 71 | 72 | ## Init (install a local copy and its development dependencies) 73 | init: 74 | Rscript -e "devtools::install(dependencies = TRUE)" 75 | 76 | ## Build package and install locally 77 | install: 78 | Rscript -e "devtools::install()" 79 | 80 | ## Uninstall 81 | uninstall: 82 | Rscript -e "devtools::uninstall()" 83 | 84 | ## Check for CRAN submission (via rhub's local docker container); requirement: sysreqs, and github version of rhub 85 | check-cran-local: 86 | # NOTE: the env_var tries to deal with utf8 issues 87 | # https://github.com/r-hub/rhub/issues/374 88 | Rscript -e "rhub::local_check_linux(env_vars=c(R_COMPILE_AND_INSTALL_PACKAGES = 'always'))" 89 | 90 | ################################################################################# 91 | # Self Documenting Commands # 92 | ################################################################################# 93 | 94 | .DEFAULT_GOAL := help 95 | 96 | .PHONY: help 97 | help: 98 | @echo "$$(tput bold)Available rules:$$(tput sgr0)" 99 | @echo 100 | @sed -n -e "/^## / { \ 101 | h; \ 102 | s/.*//; \ 103 | :doc" \ 104 | -e "H; \ 105 | n; \ 106 | s/^## //; \ 107 | t doc" \ 108 | -e "s/:.*//; \ 109 | G; \ 110 | s/\\n## /---/; \ 111 | s/\\n/ /g; \ 112 | p; \ 113 | }" ${MAKEFILE_LIST} \ 114 | | awk -F '---' \ 115 | -v ncol=$$(tput cols) \ 116 | -v indent=19 \ 117 | -v col_on="$$(tput setaf 6)" \ 118 | -v col_off="$$(tput sgr0)" \ 119 | '{ \ 120 | printf "%s%*s%s ", col_on, -indent, $$1, col_off; \ 121 | n = split($$2, words, " "); \ 122 | line_length = ncol - indent; \ 123 | for (i = 1; i <= n; i++) { \ 124 | line_length -= length(words[i]) + 1; \ 125 | if (line_length <= 0) { \ 126 | line_length = ncol - indent - length(words[i]) - 1; \ 127 | printf "\n%*s ", -indent, " "; \ 128 | } \ 129 | printf "%s ", words[i]; \ 130 | } \ 131 | printf "\n"; \ 132 | }' 133 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: do not edit by hand 2 | 3 | export("%>%") 4 | export(confounder) 5 | export(cypher) 6 | export(drugs_risk_factors) 7 | export(genetic_cor) 8 | export(literature_gwas) 9 | export(mappings_gene_to_protein) 10 | export(meta_nodes_list) 11 | export(meta_nodes_list_node) 12 | export(meta_nodes_search_node) 13 | export(meta_rels_list) 14 | export(meta_rels_list_rel) 15 | export(mr) 16 | export(obs_cor) 17 | export(ontology_gwas_efo) 18 | export(pathway) 19 | export(pqtl) 20 | export(pqtl_list) 21 | export(pqtl_pleio) 22 | export(protein_in_pathway) 23 | export(query_epigraphdb) 24 | export(xqtl_multi_snp_mr) 25 | export(xqtl_single_snp_mr) 26 | importFrom(magrittr,"%>%") 27 | -------------------------------------------------------------------------------- /NEWS.md: -------------------------------------------------------------------------------- 1 | # epigraphdb 0.2.3 (2022-01-14) 2 | 3 | - Error handling logics have been overhauled. 4 | - Now it is easier to see the context when a request function fails 5 | - Vignettes on case studies of using EpiGraphDB functionalities have been moved to [EpiGraphDB's platform documentation](https://docs.epigraphdb.org). This is to make the package building process faster and less error prone. Specifically, it involves these vignette articles: 6 | - [Case 1 pleiotropy](https://docs.epigraphdb.org/r-package/case-1-pleiotropy/) 7 | - [Case 2 alternative drug target](https://docs.epigraphdb.org/r-package/case-2-alt-drug-target/) 8 | - [Case 3 literature triangulation](https://docs.epigraphdb.org/r-package/case-3-literature-triangulation/) 9 | - (For developers) Added docker for package development in a portable and consistent development environment. 10 | 11 | # epigraphdb 0.2.2 (2021-03-21) 12 | 13 | - Switch to github actions for building the package documentation site. 14 | - Switch to EpiGraphDB v1.0.0 API. 15 | 16 | # epigraphdb 0.2.1 (2020-08-06) 17 | 18 | - use `httr::RETRY` to mitigate problems due to network errors. 19 | - Shortened the startup message. 20 | - Added functions `protein_in_pathway`, `mappings_gene_to_protein` 21 | - Added RMarkdown vignettes to the equivalent Jupyter notebooks in the 22 | [EpiGraphDB GitHub repo](https://github.com/MRCIEU/epigraphdb). 23 | - Added functions `meta_nodes_list`, `meta_rels_list`, `meta_nodes_list_node`, `meta_rels_list_rel`, 24 | `meta_nodes_search_node`, `cypher` 25 | 26 | # epigraphdb 0.2 (2020-04-21) 27 | 28 | - Migrated to EpiGraphDB v0.3.0 API. 29 | 30 | # epigraphdb 0.1.0.9 31 | 32 | Current ongoing development 33 | 34 | - (2020-03) Move upstream API url to https://api.epigraphdb.org/v0.2.0 35 | - (2019-11) Migrated to github and travis CI. 36 | Current documentation site is now `https://mrcieu.github.io/epigraphdb-r`. 37 | 38 | # epigraphdb 0.1 (2019-07-04) 39 | 40 | Initial release on github 41 | 42 | # epigraphdb 0.0.0.9000 (2019-04-11) 43 | 44 | Initial pre-development 45 | -------------------------------------------------------------------------------- /R/confounder.R: -------------------------------------------------------------------------------- 1 | #' MR evidence on confounding traits between exposure and outcome 2 | #' 3 | #' [`GET /confounder`](https://docs.epigraphdb.org/api/api-endpoints/#get-confounder) 4 | #' 5 | #' @param type One in `["confounder", "intermediate", 6 | #' "reverse_intermediate", "collider"]` 7 | #' Refer to [ 8 | #' the confounder view in web application 9 | #' ](https://epigraphdb.org/confounder) 10 | #' for details 11 | #' @inheritParams mr 12 | #' 13 | #' @return Data from `GET /confounder` 14 | #' 15 | #' @examples 16 | #' \dontrun{ 17 | #' confounder(exposure_trait = "Body mass index", outcome_trait = "Coronary heart disease") 18 | #' } 19 | #' @export 20 | confounder <- function(exposure_trait = NULL, outcome_trait = NULL, 21 | type = c( 22 | "confounder", "intermediate", 23 | "reverse_intermediate", "collider" 24 | ), 25 | pval_threshold = 0.00001, 26 | mode = c("table", "raw")) { 27 | mode <- match.arg(mode) 28 | type <- match.arg(type) 29 | response <- query_epigraphdb( 30 | route = "/confounder", 31 | params = list( 32 | exposure_trait = exposure_trait, outcome_trait = outcome_trait, 33 | type = type, 34 | pval_threshold = pval_threshold 35 | ), 36 | mode = mode 37 | ) 38 | response 39 | } 40 | -------------------------------------------------------------------------------- /R/cypher.R: -------------------------------------------------------------------------------- 1 | #' Send a query in Cypher to EpiGraphDB 2 | #' 3 | #' NOTE: this function is intended for advanced uses. 4 | #' Regular users are recommended to use standard query functions 5 | #' 6 | #' @inheritParams mr 7 | #' @param query 8 | #' A Cypher query. 9 | #' 10 | #' @examples 11 | #' \dontrun{ 12 | #' cypher("MATCH (n:Gwas) RETURN n LIMIT 2") 13 | #' } 14 | #' @export 15 | cypher <- function(query, mode = c("table", "raw")) { 16 | mode <- match.arg(mode) 17 | response <- query_epigraphdb( 18 | route = "/cypher", 19 | params = list(query = query), 20 | mode = mode, 21 | method = "POST" 22 | ) 23 | response 24 | } 25 | -------------------------------------------------------------------------------- /R/drugs.R: -------------------------------------------------------------------------------- 1 | #' Drugs for risk factors 2 | #' 3 | #' [`GET /drugs/risk-factors`](https://docs.epigraphdb.org/api/api-endpoints/#get-drugsrisk-factors) 4 | #' 5 | #' @param trait A trait name 6 | #' @inheritParams mr 7 | #' @return Data from `GET /drugs/risk-factors` 8 | #' 9 | #' @examples 10 | #' \dontrun{ 11 | #' drugs_risk_factors(trait = "Body mass index") 12 | #' } 13 | #' @export 14 | drugs_risk_factors <- function(trait, pval_threshold = 1e-8, 15 | mode = c("table", "raw")) { 16 | mode <- match.arg(mode) 17 | response <- query_epigraphdb( 18 | route = "/drugs/risk-factors", 19 | params = list( 20 | trait = trait, 21 | pval_threshold = pval_threshold 22 | ), 23 | mode = mode 24 | ) 25 | response 26 | } 27 | -------------------------------------------------------------------------------- /R/epigraphdb-package.R: -------------------------------------------------------------------------------- 1 | #' @keywords internal 2 | "_PACKAGE" 3 | 4 | # The following block is used by usethis to automatically manage 5 | # roxygen namespace tags. Modify with care! 6 | ## usethis namespace: start 7 | ## usethis namespace: end 8 | NULL 9 | -------------------------------------------------------------------------------- /R/genetic_cor.R: -------------------------------------------------------------------------------- 1 | #' Genetic correlations between traits 2 | #' 3 | #' [`GET /genetic-cor`](https://docs.epigraphdb.org/api/api-endpoints/#get-genetic-cor) 4 | #' 5 | #' @inheritParams obs_cor 6 | #' 7 | #' @return Data from `GET /genetic_cor` 8 | #' 9 | #' @examples 10 | #' \dontrun{ 11 | #' genetic_cor(trait = "Body mass index") %>% 12 | #' dplyr::glimpse() 13 | #' } 14 | #' 15 | #' # Use a different threshold 16 | #' \dontrun{ 17 | #' genetic_cor(trait = "Body mass index", cor_coef_threshold = 0.4) %>% 18 | #' dplyr::glimpse() 19 | #' } 20 | #' @export 21 | genetic_cor <- function(trait, cor_coef_threshold = 0.8, 22 | mode = c("table", "raw")) { 23 | mode <- match.arg(mode) 24 | response <- query_epigraphdb( 25 | route = "/genetic-cor", 26 | params = list( 27 | trait = trait, cor_coef_threshold = cor_coef_threshold 28 | ), 29 | mode = mode 30 | ) 31 | response 32 | } 33 | -------------------------------------------------------------------------------- /R/literature.R: -------------------------------------------------------------------------------- 1 | #' Literature evidence regarding a GWAS trait 2 | #' 3 | #' [`GET /literature/gwas`](https://docs.epigraphdb.org/api/api-endpoints/#get-literaturegwas) 4 | #' 5 | #' @param trait A trait name 6 | #' @param semmed_predicate Either NULL which returns entries from 7 | #' all predicates, or a SemMed predicate e.g. "DIAGNOSES" or "ASSOCIATED_WITH" 8 | #' @inheritParams mr 9 | #' @return Data from `GET /literature/gwas` 10 | #' 11 | #' @examples 12 | #' \dontrun{ 13 | #' literature_gwas(trait = "Body mass index") 14 | #' } 15 | #' @export 16 | literature_gwas <- function(trait, semmed_predicate = NULL, 17 | mode = c("table", "raw")) { 18 | mode <- match.arg(mode) 19 | response <- query_epigraphdb( 20 | route = "/literature/gwas", 21 | params = list( 22 | trait = trait, 23 | semmed_predicate = semmed_predicate 24 | ), 25 | mode = mode 26 | ) 27 | response 28 | } 29 | -------------------------------------------------------------------------------- /R/mappings.R: -------------------------------------------------------------------------------- 1 | #' Return protein uniprot_id from associated genes 2 | #' 3 | #' [`POST /mappings/gene-to-protein`](https://docs.epigraphdb.org/api/api-endpoints/#post-mappingsgene-to-protein) 4 | #' 5 | #' @param gene_name_list 6 | #' List of HGNC symbols of the genes (default) 7 | #' @param gene_id_list 8 | #' List of Ensembl gene IDs (when `by_gene_id == TRUE`) 9 | #' @param by_gene_id 10 | #' Search for gene ids (Ensembl gene IDs) instead of gene names (HGNC symbols) 11 | #' @inheritParams mr 12 | #' 13 | #' @return Data from `POST /mappings/gene-to-protein` 14 | #' @export 15 | #' 16 | #' @examples 17 | #' # By HGNC symbols 18 | #' \dontrun{ 19 | #' mappings_gene_to_protein(gene_name_list = c("GCH1", "MYOF")) 20 | #' } 21 | #' 22 | #' # By Enselbl Ids 23 | #' \dontrun{ 24 | #' mappings_gene_to_protein(gene_id_list = c("ENSG00000162594", "ENSG00000113302"), by_gene_id = TRUE) 25 | #' } 26 | mappings_gene_to_protein <- function(gene_name_list = NULL, gene_id_list = NULL, 27 | by_gene_id = FALSE, 28 | mode = c("table", "raw")) { 29 | mode <- match.arg(mode) 30 | # Resolve singletons 31 | if (!is.null(gene_name_list)) { 32 | gene_name_list <- I(gene_name_list) 33 | } else { 34 | gene_name_list <- list() 35 | } 36 | if (!is.null(gene_id_list)) { 37 | gene_id_list <- I(gene_id_list) 38 | } else { 39 | gene_id_list <- list() 40 | } 41 | response <- query_epigraphdb( 42 | route = "/mappings/gene-to-protein", 43 | params = list( 44 | gene_name_list = gene_name_list, 45 | gene_id_list = gene_id_list, 46 | by_gene_id = by_gene_id 47 | ), 48 | mode = mode, 49 | method = "POST" 50 | ) 51 | response 52 | } 53 | -------------------------------------------------------------------------------- /R/meta.R: -------------------------------------------------------------------------------- 1 | #' List meta nodes (e.g. Gwas, Gene, etc.) 2 | #' 3 | #' [`GET /meta/nodes/list`](https://docs.epigraphdb.org/api/api-endpoints/#get-metanodeslist) 4 | #' 5 | #' @inheritParams mr 6 | #' 7 | #' @return Data from `GET /meta/nodes/list` 8 | #' 9 | #' @examples 10 | #' \dontrun{ 11 | #' meta_nodes_list() 12 | #' } 13 | #' @export 14 | meta_nodes_list <- function(mode = c("raw")) { 15 | # NOTE: currently response from the API does 16 | # not conform with the standard response model 17 | mode <- match.arg(mode) 18 | response <- query_epigraphdb( 19 | route = "/meta/nodes/list", 20 | mode = mode 21 | ) 22 | response 23 | } 24 | 25 | #' List meta rels (e.g. MR, etc.) 26 | #' 27 | #' [`GET /meta/rels/list`](https://docs.epigraphdb.org/api/api-endpoints/#get-metarelslist) 28 | #' 29 | #' @inheritParams mr 30 | #' 31 | #' @return Data from `GET /meta/rels/list` 32 | #' 33 | #' @examples 34 | #' \dontrun{ 35 | #' meta_rels_list() 36 | #' } 37 | #' @export 38 | meta_rels_list <- function(mode = c("raw")) { 39 | # NOTE: currently response from the API does 40 | # not conform with the standard response model 41 | mode <- match.arg(mode) 42 | response <- query_epigraphdb( 43 | route = "/meta/rels/list", 44 | mode = mode 45 | ) 46 | response 47 | } 48 | 49 | #' List nodes under a meta node 50 | #' 51 | #' [`GET /meta/nodes/{meta_node}/list`](https://docs.epigraphdb.org/api/api-endpoints/#get-metanodesmeta_nodelist) 52 | #' 53 | #' @inheritParams mr 54 | #' @param meta_node 55 | #' Name of a meta node (e.g. Gwas). Use `meta_nodes_list` to get the full list of meta nodes. 56 | #' @param full_data 57 | #' When False, only return the id and name fields (their specific names differ in specific nodes) for a node. 58 | #' This is useful if you want your queries to return results faster with smaller amount of data requested. 59 | #' @param limit 60 | #' Max number of items to retrieve. 61 | #' @param offset 62 | #' Number of items to skip. Use `limit` and `offset` in combination to do pagination. 63 | #' 64 | #' @return Data from `GET /meta/nodes/{meta_node}/list` 65 | #' 66 | #' @examples 67 | #' # List the first 5 Gwas nodes, with only id and name fields 68 | #' \dontrun{ 69 | #' meta_nodes_list_node(meta_node = "Gwas", full_data = FALSE, limit = 5) 70 | #' } 71 | #' 72 | #' # List the 6th - 10th Disease nodes, with full properties 73 | #' \dontrun{ 74 | #' meta_nodes_list_node(meta_node = "Disease", full_data = TRUE, limit = 5, offset = 0) 75 | #' } 76 | #' @export 77 | meta_nodes_list_node <- function(meta_node, full_data = TRUE, limit = 10, offset = 0, 78 | mode = c("table", "raw")) { 79 | mode <- match.arg(mode) 80 | response <- query_epigraphdb( 81 | route = glue::glue("/meta/nodes/{meta_node}/list"), 82 | params = list( 83 | full_data = full_data, limit = limit, offset = offset 84 | ), 85 | mode = mode 86 | ) 87 | response 88 | } 89 | 90 | #' List relationships under a meta relationship 91 | #' 92 | #' [`GET /meta/rels/{meta_rel}/list`](https://docs.epigraphdb.org/api/api-endpoints/#get-metarelsmeta_rellist) 93 | #' 94 | #' @inheritParams mr 95 | #' @param meta_rel 96 | #' Name of a meta relationship (e.g. MR). Use `meta_rels_list` to get the full list of meta relationships. 97 | #' @param limit 98 | #' Max number of items to retrieve. 99 | #' @param offset 100 | #' Number of items to skip. Use `limit` and `offset` in combination to do pagination. 101 | #' 102 | #' @return Data from `GET /meta/rels/{meta_rel}/list` 103 | #' 104 | #' @examples 105 | #' # List the first 5 MR relationships 106 | #' \dontrun{ 107 | #' meta_rels_list_rel(meta_rel = "MR_EVE_MR", limit = 5) 108 | #' } 109 | #' @export 110 | meta_rels_list_rel <- function(meta_rel, limit = 10, offset = 0, 111 | mode = c("table", "raw")) { 112 | mode <- match.arg(mode) 113 | response <- query_epigraphdb( 114 | route = glue::glue("/meta/rels/{meta_rel}/list"), 115 | params = list( 116 | limit = limit, offset = offset 117 | ), 118 | mode = mode 119 | ) 120 | response 121 | } 122 | 123 | #' Search a node by its id field, or its name field 124 | #' 125 | #' [`GET /meta/nodes/{meta_node}/search`](https://docs.epigraphdb.org/api/api-endpoints/#get-metanodesmeta_nodesearch) 126 | #' 127 | #' @inheritParams mr 128 | #' @param meta_node 129 | #' Name of a meta node (e.g. Gwas). Use `meta_nodes_list` to get the full list of meta nodes. 130 | #' @param id 131 | #' The id field of a node (e.g. "ieu-a-2" for a Gwas). 132 | #' Use EpiGraphDB web UI to get a sense of what those ids are for entities. 133 | #' @param name 134 | #' The name field of a node (e.g. "body mass index" for a Gwas). 135 | #' Use EpiGraphDB web UI to get a sense of what those names are for entities. 136 | #' @param full_data 137 | #' When False, only return the id and name fields (their specific names differ in specific nodes) for a node. 138 | #' This is useful if you want your queries to return results faster with smaller amount of data requested. 139 | #' @param limit 140 | #' Max number of items to retrieve. 141 | #' 142 | #' @return Data from `GET /meta/nodes/{meta_node}/search` 143 | #' 144 | #' @examples 145 | #' # Search Gwas nodes 146 | #' \dontrun{ 147 | #' meta_nodes_search_node(meta_node = "Gwas", name = "body mass index") 148 | #' } 149 | #' @export 150 | meta_nodes_search_node <- function(meta_node, 151 | id = NULL, name = NULL, 152 | limit = 10, full_data = TRUE, 153 | mode = c("table", "raw")) { 154 | mode <- match.arg(mode) 155 | response <- query_epigraphdb( 156 | route = glue::glue("/meta/nodes/{meta_node}/search"), 157 | params = list( 158 | full_data = full_data, 159 | id = id, name = name, 160 | limit = limit 161 | ), 162 | mode = mode 163 | ) 164 | response 165 | } 166 | -------------------------------------------------------------------------------- /R/mr.R: -------------------------------------------------------------------------------- 1 | #' Return information related to Mendelian Randomisation 2 | #' 3 | #' [`GET /mr`](https://docs.epigraphdb.org/api/api-endpoints/#get-mr) 4 | #' 5 | #' @param exposure_trait 6 | #' A trait name, e.g. "Body mass index", 7 | #' leaving `exposure_trait` as `NULL` will return MR information 8 | #' related to a specific `outcome`. 9 | #' **NOTE**: `exposure_trait` and `outcome_trait` cannot be both `NULL`. 10 | #' @param outcome_trait 11 | #' A trait name, e.g. "Coronary heart disease", 12 | #' leaving `outcome_trait` as `NULL` will return MR information 13 | #' related to a specific `exposure_trait`. 14 | #' **NOTE**: `exposure_trait` and `outcome_trait` cannot be both `NULL`. 15 | #' @param pval_threshold 16 | #' P-value threshold 17 | #' @param mode 18 | #' If `mode = "table"`, returns a data frame 19 | #' (a [`tibble`](https://tibble.tidyverse.org/) as per 20 | #' [`tidyverse`](https://style.tidyverse.org/) convention). 21 | #' If `mode = "raw"`, returns a raw response from EpiGraphDB API 22 | #' with minimal parsing done by [`httr`](https://httr.r-lib.org/). 23 | #' 24 | #' @return Data from `GET /mr` 25 | #' 26 | #' @examples 27 | #' # Returns a data frame 28 | #' \dontrun{ 29 | #' mr(exposure_trait = "Body mass index", outcome_trait = "Coronary heart disease") 30 | #' } 31 | #' 32 | #' # Returns raw response 33 | #' \dontrun{ 34 | #' mr( 35 | #' exposure_trait = "Body mass index", outcome_trait = "Coronary heart disease", 36 | #' mode = "raw" 37 | #' ) %>% str() 38 | #' } 39 | #' 40 | #' # Use a different threshold 41 | #' \dontrun{ 42 | #' mr(exposure_trait = "Body mass index", pval_threshold = 1e-8) 43 | #' } 44 | #' @export 45 | mr <- function(exposure_trait = NULL, outcome_trait = NULL, 46 | pval_threshold = 1e-5, 47 | mode = c("table", "raw")) { 48 | mode <- match.arg(mode) 49 | response <- query_epigraphdb( 50 | route = "/mr", 51 | params = list( 52 | exposure_trait = exposure_trait, outcome_trait = outcome_trait, 53 | pval_threshold = pval_threshold 54 | ), 55 | mode = mode 56 | ) 57 | response 58 | } 59 | -------------------------------------------------------------------------------- /R/obs_cor.R: -------------------------------------------------------------------------------- 1 | #' Observational correlations between traits 2 | #' 3 | #' [`GET /obs-cor`](https://docs.epigraphdb.org/api/api-endpoints/#get-obs-cor) 4 | #' 5 | #' @param trait name of the trait, e.g. "body mass index" 6 | #' @param cor_coef_threshold correlation coefficient threshold 7 | #' @inheritParams mr 8 | #' 9 | #' @return Data from `GET /obs-cor` 10 | #' 11 | #' @examples 12 | #' \dontrun{ 13 | #' obs_cor(trait = "Body mass index (BMI)") %>% 14 | #' dplyr::glimpse() 15 | #' } 16 | #' 17 | #' # Use a different threshold 18 | #' \dontrun{ 19 | #' obs_cor(trait = "Body mass index (BMI)", cor_coef_threshold = 0.8) %>% 20 | #' dplyr::glimpse() 21 | #' } 22 | #' @export 23 | obs_cor <- function(trait, cor_coef_threshold = 0.8, mode = c("table", "raw")) { 24 | mode <- match.arg(mode) 25 | response <- query_epigraphdb( 26 | route = "/obs-cor", 27 | params = list( 28 | trait = trait, cor_coef_threshold = cor_coef_threshold 29 | ), 30 | mode = mode 31 | ) 32 | response 33 | } 34 | -------------------------------------------------------------------------------- /R/ontology.R: -------------------------------------------------------------------------------- 1 | #' Ontology association between EFO term and Gwas 2 | #' 3 | #' [`GET /ontology/gwas-efo`](https://docs.epigraphdb.org/api/api-endpoints/#get-ontologygwas-efo) 4 | #' 5 | #' @param trait trait name, e.g. "body mass" 6 | #' @param efo_term EFO term, e.g. "systolic blood pressure" 7 | #' @param fuzzy whether query with exact matching (FALSE) or fuzzy matching (default, TRUE) 8 | #' @inheritParams mr 9 | #' 10 | #' @return Data from `GET /ontology/gwas-efo` 11 | #' 12 | #' @examples 13 | #' \dontrun{ 14 | #' ontology_gwas_efo(trait = "blood", fuzzy = FALSE) 15 | #' } 16 | #' 17 | #' \dontrun{ 18 | #' ontology_gwas_efo(efo_term = "blood pressure", fuzzy = FALSE) 19 | #' } 20 | #' @export 21 | ontology_gwas_efo <- function(trait = NULL, efo_term = NULL, fuzzy = TRUE, mode = c("table", "raw")) { 22 | mode <- match.arg(mode) 23 | response <- query_epigraphdb( 24 | route = "/ontology/gwas-efo", 25 | params = list(trait = trait, efo_term = efo_term, fuzzy = fuzzy), 26 | mode = mode 27 | ) 28 | response 29 | } 30 | -------------------------------------------------------------------------------- /R/pathway.R: -------------------------------------------------------------------------------- 1 | #' Pathway evidence 2 | #' 3 | #' [`GET /pathway`](https://docs.epigraphdb.org/api/api-endpoints/#get-pathway) 4 | #' 5 | #' @param trait A trait name 6 | #' @inheritParams mr 7 | #' @return Data from `GET /pathway` 8 | #' 9 | #' @examples 10 | #' \dontrun{ 11 | #' pathway(trait = "Body mass index") 12 | #' } 13 | #' @export 14 | pathway <- function(trait, 15 | pval_threshold = 0.00001, 16 | mode = c("table", "raw")) { 17 | mode <- match.arg(mode) 18 | response <- query_epigraphdb( 19 | route = "/pathway", 20 | params = list( 21 | trait = trait, 22 | pval_threshold = pval_threshold 23 | ), 24 | mode = mode 25 | ) 26 | response 27 | } 28 | -------------------------------------------------------------------------------- /R/pqtl.R: -------------------------------------------------------------------------------- 1 | #' Return information related to the pQTL analysis 2 | #' 3 | #' [`GET /pqtl/`](https://docs.epigraphdb.org/api/api-endpoints/#get-pqtl) 4 | #' 5 | #' @param query 6 | #' (Required) A protein coding gene name or a trait name, 7 | #' e.g. "ADAM19" or "Inflammatory bowel disease" 8 | #' which cannot be `NULL`. 9 | #' @param rtype 10 | #' (Optional) A type of data to be extracted, which can be one of these options: 11 | #' 1. `simple`: Basic summary 12 | #' 2. `mrres`: MR results (DEFAULT) 13 | #' 3. `sglmr`: Single SNP MR results 14 | #' 4. `inst`: SNP information 15 | #' 5. `sense`: Sensitivity analysis 16 | #' **NOTE**: `mrres` is a DEFAULT option. 17 | #' @param pvalue 18 | #' (Optional) A pvalue threshold for MR results with the DEFAULT set to 0.05. 19 | #' **NOTE**: this threshold applies to any `rtype` chosen. 20 | #' @param searchflag 21 | #' (Required) A flag to indicate whether you are searching for proteins or 22 | #' traits which cannot be `NULL`. 23 | #' If `query` is a protein name, then this flag should be "proteins"; 24 | #' if `query` is a trait, this flag should be "traits". 25 | #' **NOTE**: if the wrong flag is chosen for `query`, there will be no result 26 | #' returned. 27 | #' @inheritParams mr 28 | #' 29 | #' @return Data from `GET /pqtl/` 30 | #' 31 | #' @examples 32 | #' # Returns a data frame of MR results, while searching for proteins 33 | #' \dontrun{ 34 | #' pqtl(query = "ADAM19", searchflag = "proteins") 35 | #' } 36 | #' 37 | #' # Returns a data frame with SNP information, while searching for traits 38 | #' \dontrun{ 39 | #' pqtl( 40 | #' query = "Inflammatory bowel disease", 41 | #' rtype = "inst", 42 | #' searchflag = "traits" 43 | #' ) 44 | #' } 45 | #' 46 | #' # Change a pvalue threshold (the default is 0.05) 47 | #' \dontrun{ 48 | #' pqtl( 49 | #' query = "Inflammatory bowel disease", 50 | #' rtype = "inst", 51 | #' pvalue = 1.0, 52 | #' searchflag = "traits" 53 | #' ) 54 | #' } 55 | #' 56 | #' # Returns raw response if mode="raw" 57 | #' \dontrun{ 58 | #' pqtl( 59 | #' query = "ADAM19", searchflag = "proteins", 60 | #' mode = "raw" 61 | #' ) %>% str() 62 | #' } 63 | #' @export 64 | pqtl <- function(query, 65 | rtype = c("mrres", "simple", "sglmr", "inst", "sense"), 66 | pvalue = 0.05, 67 | searchflag = c("traits", "proteins"), 68 | mode = c("table", "raw")) { 69 | mode <- match.arg(mode) 70 | rtype <- match.arg(rtype) 71 | searchflag <- match.arg(searchflag) 72 | response <- query_epigraphdb( 73 | route = "/pqtl/", 74 | params = list( 75 | query = query, 76 | rtype = rtype, 77 | pvalue = pvalue, 78 | searchflag = searchflag 79 | ), 80 | mode = mode 81 | ) 82 | response 83 | } 84 | 85 | 86 | #' Return information related to the pleiotropy of SNPs 87 | #' 88 | #' [`GET /pqtl/pleio/`](https://docs.epigraphdb.org/api/api-endpoints/#get-pqtlpleio) 89 | #' 90 | #' @param rsid 91 | #' (Required) A SNP identified by rsID which cannot be `NULL`. 92 | #' @param prflag 93 | #' (Optional) A flag which determines whether the number (if "count") 94 | #' or names (if "proteins") of the associated proteins should be returned. 95 | #' The DEFAULT value is "proteins". 96 | #' @param mode 97 | #' (Optional) If `mode = "table"`, returns a data frame 98 | #' (a [`tibble`](https://tibble.tidyverse.org/) as per 99 | #' [`tidyverse`](https://style.tidyverse.org/) convention). 100 | #' If `mode = "raw"`, returns a raw response from EpiGraphDB API 101 | #' with minimal parsing done by [`httr`](https://httr.r-lib.org/). 102 | #' 103 | #' @return Data from `GET /pqtl/pleio/` 104 | #' 105 | #' @export 106 | #' 107 | #' @examples 108 | #' 109 | #' # Returns a data frame of associated proteins 110 | #' \dontrun{ 111 | #' pqtl_pleio(rsid = "rs1260326") 112 | #' } 113 | #' 114 | #' # Returns a number of associated proteins 115 | #' \dontrun{ 116 | #' pqtl_pleio(rsid = "rs1260326", prflag = "count") 117 | #' } 118 | pqtl_pleio <- function(rsid = NULL, 119 | prflag = c("proteins", "count"), 120 | mode = c("table", "raw")) { 121 | mode <- match.arg(mode) 122 | prflag <- match.arg(prflag) 123 | response <- query_epigraphdb( 124 | route = "/pqtl/pleio/", 125 | params = list( 126 | rsid = rsid, 127 | prflag = prflag 128 | ), 129 | mode = mode 130 | ) 131 | # special cases 132 | if (prflag == "count") { 133 | response <- as.integer(response) 134 | } 135 | response 136 | } 137 | 138 | 139 | #' Return a list of all proteins/exposures or traits/outcomes 140 | #' available in the database 141 | #' 142 | #' [`GET /pqtl/list/`](https://docs.epigraphdb.org/api/api-endpoints/#get-pqtllist) 143 | #' 144 | #' @param flag 145 | #' (Optional) A flag which indicates whether the list of 146 | #' exposures (if "exposures") or outcomes (if "outcomes") 147 | #' should be returned. The DEFAULT is "exposures". 148 | #' @inheritParams mr 149 | #' 150 | #' @return Data from `GET /pqtl/list/` 151 | #' 152 | #' @export 153 | #' 154 | #' @examples 155 | #' 156 | #' # Returns a list of available proteins (exposures) 157 | #' \dontrun{ 158 | #' pqtl_list() 159 | #' } 160 | #' 161 | #' # Returns a list of available traits (outcomes) 162 | #' \dontrun{ 163 | #' pqtl_list(flag = "outcomes") 164 | #' } 165 | pqtl_list <- function(flag = c("exposures", "outcomes"), 166 | mode = c("table", "raw")) { 167 | mode <- match.arg(mode) 168 | flag <- match.arg(flag) 169 | response <- query_epigraphdb( 170 | route = "/pqtl/list/", 171 | params = list(flag = flag), 172 | mode = mode 173 | ) 174 | response 175 | } 176 | -------------------------------------------------------------------------------- /R/protein.R: -------------------------------------------------------------------------------- 1 | #' For the list of proteins, returns their associated pathway data 2 | #' 3 | #' [`POST /protein/in-pathway`](https://docs.epigraphdb.org/api/api-endpoints/#post-proteinin-pathway) 4 | #' 5 | #' @param uniprot_id_list 6 | #' A list of protein UniProt IDs 7 | #' @inheritParams mr 8 | #' 9 | #' @return Data from `POST /protein/in-pathway` 10 | #' @export 11 | #' 12 | #' @examples 13 | #' \dontrun{ 14 | #' protein_in_pathway(uniprot_id_list = c("014933", "060674", "P32455")) 15 | #' } 16 | protein_in_pathway <- function(uniprot_id_list, mode = c("table", "raw")) { 17 | mode <- match.arg(mode) 18 | response <- query_epigraphdb( 19 | route = "/protein/in-pathway", 20 | params = list( 21 | # guard against auto unpacking of singletons 22 | uniprot_id_list = I(uniprot_id_list) 23 | ), 24 | mode = mode, 25 | method = "POST" 26 | ) 27 | response 28 | } 29 | -------------------------------------------------------------------------------- /R/request_and_response.R: -------------------------------------------------------------------------------- 1 | #' Send data request to an EpiGraphDB API endpoint 2 | #' 3 | #' This is a general purpose function to send data request 4 | #' which can be used when there has not been an R equivalent package function 5 | #' to an API endpoint. 6 | #' Underneath this is a wrapper around `httr` functions with better handling of 7 | #' returned status. 8 | #' 9 | #' @param route An EpiGraphDB API endpoint route, e.g. `"/mr"` or `"/confounder"`. 10 | #' Consult the [EpiGraphDB API documentation](https://api.epigraphdb.org). 11 | #' @param params A list of parameters associated with the query endpoint. 12 | #' @param mode `c("raw", "table")`, if `"table"` then the query handler will try 13 | #' to convert the returned data to a tibble dataframe. 14 | #' NOTE: The default mode is "raw" which will NOT convert the returned response to 15 | #' a dataframe. 16 | #' This is different to functions that query topic endpoints which 17 | #' default to return a dataframe. 18 | #' Explicitly specify `mode = "table"` when needed. 19 | #' @param method Type of HTTP (GET, POST, PUT, etc.) method. 20 | #' 21 | #' NOTE: When sending a POST request where a specific parameter is specified as a list on the API, 22 | #' and if the equivalent in R is a vector of length 1, you should wrap this parameter 23 | #' in `I()`, e.g. I(c("APOE")) to avoid auto unboxing. 24 | #' For details, please refer to [`httr::POST`](https://httr.r-lib.org/reference/POST.html) 25 | #' 26 | #' @param retry_times Number of times the function will retry the request to the API. 27 | #' @param retry_pause_min Minimum number of seconds to wait for the next retry. 28 | #' 29 | #' @return Data from an EpiGraphDB API endpoint. 30 | #' 31 | #' @examples 32 | #' # GET /mr 33 | #' # equivalent to `mr(exposure_trait = "Body mass index", outcome_trait = "Coronary heart disease")` 34 | #' \dontrun{ 35 | #' query_epigraphdb( 36 | #' route = "/mr", 37 | #' params = list( 38 | #' exposure_trait = "Body mass index", 39 | #' outcome_trait = "Coronary heart disease" 40 | #' ), 41 | #' mode = "table" 42 | #' ) 43 | #' } 44 | #' 45 | #' # GET /meta/nodes/Gwas/list 46 | #' \dontrun{ 47 | #' query_epigraphdb( 48 | #' route = "/meta/nodes/Gwas/list", 49 | #' params = list( 50 | #' limit = 5, 51 | #' offset = 0 52 | #' ) 53 | #' ) %>% str(1) 54 | #' } 55 | #' 56 | #' # POST /protein/ppi 57 | #' \dontrun{ 58 | #' query_epigraphdb( 59 | #' route = "/protein/ppi", 60 | #' params = list( 61 | #' uniprot_id_list = c("P30793", "Q9NZM1", "O95236") 62 | #' ), 63 | #' method = "POST" 64 | #' ) 65 | #' } 66 | #' 67 | #' # error handling 68 | #' \dontrun{ 69 | #' tryCatch( 70 | #' query_epigraphdb( 71 | #' route = "/mr", 72 | #' params = list( 73 | #' exposure_trait = NULL, 74 | #' outcome_trait = NULL 75 | #' ), 76 | #' retry_times = 0 77 | #' ), 78 | #' error = function(e) { 79 | #' message(e) 80 | #' } 81 | #' ) 82 | #' } 83 | #' @export 84 | query_epigraphdb <- function(route, params = NULL, 85 | mode = c("raw", "table"), 86 | method = c("GET", "POST"), 87 | retry_times = 3, 88 | retry_pause_min = 1) { 89 | mode <- match.arg(mode) 90 | method <- match.arg(method) 91 | if (method == "GET") { 92 | method_func <- api_get_request 93 | } else if (method == "POST") { 94 | method_func <- api_post_request 95 | } 96 | res <- api_request( 97 | route = route, params = params, mode = mode, method = method_func, 98 | retry_times = retry_times, retry_pause_min = retry_pause_min 99 | ) 100 | res 101 | } 102 | 103 | #' Wrapper of httr::GET that handles status errors and custom headers 104 | #' 105 | #' @param route An EpiGraphDB API endpoint route, e.g. "/mr" 106 | #' @param params GET request params 107 | #' 108 | #' @keywords internal 109 | api_get_request <- function(route, params, 110 | retry_times, retry_pause_min) { 111 | api_url <- getOption("epigraphdb.api.url") # nolint 112 | url <- glue::glue("{api_url}{route}") 113 | is_ci <- getOption("epigraphdb.ci") %>% 114 | as.character() %>% 115 | tolower() 116 | config <- httr::add_headers(.headers = c("client-type" = "R", "ci" = is_ci)) 117 | response <- httr::RETRY( 118 | "GET", 119 | url = url, query = params, config = config, 120 | times = retry_times, pause_min = retry_pause_min 121 | ) 122 | stop_for_status(response = response, context = list(params = params, url = url)) 123 | response 124 | } 125 | 126 | #' Wrapper of httr::POST that handles status errors and custom headers 127 | #' 128 | #' @param route An EpiGraphDB API endpoint route, e.g. "/mr" 129 | #' @param params POST request payload 130 | #' 131 | #' @keywords internal 132 | api_post_request <- function(route, params, 133 | retry_times, retry_pause_min) { 134 | api_url <- getOption("epigraphdb.api.url") # nolint 135 | url <- glue::glue("{api_url}{route}") 136 | is_ci <- getOption("epigraphdb.ci") %>% 137 | as.character() %>% 138 | tolower() 139 | config <- httr::add_headers(.headers = c("client-type" = "R", "ci" = is_ci)) 140 | body <- jsonlite::toJSON(params, auto_unbox = TRUE) 141 | response <- httr::RETRY( 142 | "POST", 143 | url = url, body = body, config = config, 144 | times = retry_times, pause_min = retry_pause_min 145 | ) 146 | stop_for_status(response, context = list(params = params, url = url)) 147 | response 148 | } 149 | 150 | #' The very general wrapper from EpiGraphDB endpoint request 151 | #' 152 | #' @param route An EpiGraphDB API endpoint route, e.g. "/mr" 153 | #' @param params A list of parameters to send 154 | #' @param mode Either `"table"` (returns tibble) or 155 | #' `"raw"` (returns raw response parsed from json to R list). 156 | #' @param method A specific request handler, e.g. `epi_get_request` 157 | #' 158 | #' @keywords internal 159 | api_request <- function(route, params, 160 | mode = c("table", "raw"), 161 | method = api_get_request, 162 | retry_times, retry_pause_min) { 163 | mode <- match.arg(mode) 164 | response <- do.call(method, args = list( 165 | route = route, params = params, 166 | retry_times = retry_times, retry_pause_min = retry_pause_min 167 | )) 168 | if (mode == "table") { 169 | return(flatten_response(response)) 170 | } 171 | response %>% httr::content(as = "parsed", encoding = "utf-8") 172 | } 173 | 174 | #' Flatten the "results" field from an API response to a tibble df 175 | #' 176 | #' The general tibble flattener for EpiGraphDB endpoints 177 | #' 178 | #' @param response An httr response 179 | #' 180 | #' @param field Default to the "results" field 181 | #' 182 | #' @return A tibble df 183 | #' 184 | #' @keywords internal 185 | flatten_response <- function(response, field = "results") { 186 | response %>% 187 | httr::content(as = "text", encoding = "utf-8") %>% 188 | jsonlite::fromJSON(flatten = TRUE) %>% 189 | purrr::pluck(field) %>% 190 | tibble::as_tibble() 191 | } 192 | 193 | #' Catch error for an HTTP response 194 | #' 195 | #' Modifies from httr::stop_for_status 196 | #' 197 | #' @param response An httr response 198 | #' @param context A list on the url and params for the request 199 | #' 200 | #' @keywords internal 201 | stop_for_status <- function(response, context) { 202 | if (httr::status_code(response) < 300) { 203 | return(invisible(response)) 204 | } 205 | 206 | stop(http_condition(response, context)) 207 | } 208 | 209 | #' Modified httr::http_condition 210 | #' 211 | #' @param response An httr response 212 | #' @param context A list on the url and params for the request 213 | #' 214 | #' @keywords internal 215 | http_condition <- function(response, context) { 216 | status <- httr::status_code(response) 217 | reason <- httr::http_status(status)$reason 218 | detail <- paste( 219 | utils::capture.output(httr::content(response)), 220 | collapse = "\n" 221 | ) 222 | context_str <- paste( 223 | utils::capture.output(context), 224 | collapse = "\n" 225 | ) 226 | 227 | message <- sprintf( 228 | "HTTP error: %s (status code %d).\nDetail:\n%s\nContext:\n%s", 229 | reason, status, detail, context_str 230 | ) 231 | 232 | structure( 233 | list(message = message) 234 | ) 235 | } 236 | -------------------------------------------------------------------------------- /R/utils-pipe.R: -------------------------------------------------------------------------------- 1 | #' Pipe operator 2 | #' 3 | #' See \code{magrittr::\link[magrittr:pipe]{\%>\%}} for details. 4 | #' 5 | #' @name %>% 6 | #' @rdname pipe 7 | #' @keywords internal 8 | #' @export 9 | #' @importFrom magrittr %>% 10 | #' @usage lhs \%>\% rhs 11 | NULL 12 | -------------------------------------------------------------------------------- /R/xqtl.R: -------------------------------------------------------------------------------- 1 | #' Multi SNP QTL MR evidence 2 | #' 3 | #' [`GET /xqtl/multi-snp-mr`](https://docs.epigraphdb.org/api/api-endpoints/#get-xqtlmulti-snp-mr) 4 | #' 5 | #' @param exposure_gene Name of the exposure gene 6 | #' @param outcome_trait Name of the outcome trait 7 | #' @param mr_method "IVW" or "Egger" 8 | #' @param qtl_type "eQTL" or "pQTL" 9 | #' @inheritParams mr 10 | #' @return Data from `GET /xqtl/multi-snp-mr` 11 | #' 12 | #' @examples 13 | #' \dontrun{ 14 | #' xqtl_multi_snp_mr(outcome_trait = "Coronary heart disease") 15 | #' } 16 | #' @export 17 | xqtl_multi_snp_mr <- function(exposure_gene = NULL, outcome_trait = NULL, 18 | mr_method = c("IVW", "Egger"), 19 | qtl_type = c("eQTL", "pQTL"), 20 | pval_threshold = 1e-5, 21 | mode = c("table", "raw")) { 22 | mode <- match.arg(mode) 23 | mr_method <- match.arg(mr_method) 24 | qtl_type <- match.arg(qtl_type) 25 | response <- query_epigraphdb( 26 | route = "/xqtl/multi-snp-mr", 27 | params = list( 28 | exposure_gene = exposure_gene, 29 | outcome_trait = outcome_trait, 30 | mr_method = mr_method, 31 | qtl_type = qtl_type, 32 | pval_threshold = pval_threshold 33 | ), 34 | mode = mode 35 | ) 36 | response 37 | } 38 | 39 | #' Single SNP QTL MR evidence 40 | #' 41 | #' [`GET /xqtl/single-snp-mr`](https://docs.epigraphdb.org/api/api-endpoints/#get-xqtlsingle-snp-mr) 42 | #' 43 | #' @param snp SNP rsid 44 | #' @inheritParams xqtl_multi_snp_mr 45 | #' @return Data from `GEET /xqtl/single-snp-mr` 46 | #' 47 | #' @examples 48 | #' \dontrun{ 49 | #' xqtl_single_snp_mr(outcome_trait = "Coronary heart disease") 50 | #' } 51 | #' @export 52 | xqtl_single_snp_mr <- function(exposure_gene = NULL, outcome_trait = NULL, 53 | snp = NULL, 54 | qtl_type = c("eQTL", "pQTL"), 55 | pval_threshold = 1e-5, 56 | mode = c("table", "raw")) { 57 | mode <- match.arg(mode) 58 | qtl_type <- match.arg(qtl_type) 59 | response <- query_epigraphdb( 60 | route = "/xqtl/single-snp-mr", 61 | params = list( 62 | exposure_gene = exposure_gene, 63 | outcome_trait = outcome_trait, 64 | snp = snp, 65 | qtl_type = qtl_type, 66 | pval_threshold = pval_threshold 67 | ), 68 | mode = mode 69 | ) 70 | response 71 | } 72 | -------------------------------------------------------------------------------- /R/zzz.R: -------------------------------------------------------------------------------- 1 | .onAttach <- function(libname, pkgname) { # nolint 2 | packageStartupMessage(" 3 | EpiGraphDB v1.0 (API: https://api.epigraphdb.org) 4 | ") 5 | } 6 | 7 | .onLoad <- function(libname, pkgname) { # nolint 8 | current_options <- options() 9 | package_options <- list( 10 | # URL to EpiGraphDB API 11 | epigraphdb.api.url = "https://api.epigraphdb.org", 12 | # Are the requests for CI usage 13 | epigraphdb.ci = Sys.getenv(x = "CI", unset = c(CI = "false")) %>% 14 | as.logical() 15 | ) 16 | to_set <- !(names(package_options) %in% names(current_options)) 17 | if (any(to_set)) options(package_options[to_set]) 18 | 19 | invisible() 20 | } 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # EpiGraphDB R package `epigraphdb` 2 | 3 |
4 | 5 | 9 | 10 | 11 | 12 | 16 | 17 | 18 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | [![CRAN status](https://www.r-pkg.org/badges/version/epigraphdb)](https://cran.r-project.org/package=epigraphdb) 29 | [![Codecov test coverage](https://codecov.io/gh/MRCIEU/epigraphdb-r/branch/master/graph/badge.svg)](https://app.codecov.io/gh/MRCIEU/epigraphdb-r?branch=master) 30 | 31 | 32 | 33 | [EpiGraphDB](https://epigraphdb.org) is an analytical platform and database to support data mining in epidemiology. 34 | The platform incorporates a graph of causal estimates generated by systematically applying Mendelian randomization to a wide array of phenotypes, and augments this with a wealth of additional data from other bioinformatic sources. 35 | EpiGraphDB aims to support appropriate application and interpretation of causal inference in systematic automated analyses of many phenotypes. 36 | 37 | [`epigraphdb`](https://github.com/MRCIEU/epigraphdb-r) is an R package to provide ease of access to EpiGraphDB services. We will refer to `epigraphdb` as the name of the R package whereas `"EpiGraphDB"` as the overall platform. 38 | 39 | ## Installation 40 | 41 | To install the latest development version from github ( 42 | [`devtools`](https://devtools.r-lib.org/) is required 43 | ): 44 | ```r 45 | # install.packages("devtools") 46 | devtools::install_github("MRCIEU/epigraphdb-r") 47 | ``` 48 | 49 | To install a stable version from CRAN: 50 | ```r 51 | install.packages("epigraphdb") 52 | ``` 53 | 54 | **NOTE**: while the package repository is "epigraphdb-r", 55 | the R package name is "epigraphdb". 56 | 57 | ## Using `epigraphdb` 58 | 59 | `epigraphdb` provides a simple and intuitive way to query the API, as: 60 | 61 | ```r 62 | library("epigraphdb") 63 | #> 64 | #> EpiGraphDB v1.0 (API: https://api.epigraphdb.org) 65 | #> 66 | mr(outcome_trait = "Body mass index") 67 | #> # A tibble: 370 x 12 68 | #> exposure_id exposure_name outcome_id outcome_name estimate se 69 | #> 70 | #> 1 627 Epiandroster… 785 Body mass i… 0.0950 2.28e-3 71 | #> 2 541 X-11787 835 Body mass i… -0.0578 1.77e-4 72 | #> 3 971 Ulcerative c… 835 Body mass i… -0.0111 1.76e-4 73 | #> 4 60 Waist circum… 835 Body mass i… 0.861 2.07e-2 74 | #> 5 UKB-a:426 Eye problems… 94 Body mass i… -1.12 1.90e-2 75 | #> 6 UKB-a:373 Ever depress… 95 Body mass i… -0.616 4.80e-4 76 | #> 7 29 Birth length 95 Body mass i… -0.141 5.67e-4 77 | #> 8 350 Laurate (12:… 974 Body mass i… 0.418 7.10e-3 78 | #> 9 UKB-a:124 Treatment/me… 974 Body mass i… -5.14 1.08e-1 79 | #> 10 95 Body mass in… 974 Body mass i… 0.981 2.79e-2 80 | #> # … with 360 more rows, and 6 more variables: p , ci_upp , 81 | #> # ci_low , selection , method , moescore ) 82 | ``` 83 | 84 | For more information on how to use the `epigraphdb` R package and 85 | how to use the API in R please check out the following articles: 86 | 87 | | Article | 88 | |---| 89 | | [Getting started with EpiGraphDB in R](https://mrcieu.github.io/epigraphdb-r/articles/getting-started-with-epigraphdb-r.html) | 90 | | [Using EpiGraphDB R package](https://mrcieu.github.io/epigraphdb-r/articles/using-epigraphdb-r-package.html) | 91 | | [Using EpiGraphDB API (from R and command line) ](https://mrcieu.github.io/epigraphdb-r/articles/using-epigraphdb-api.html) | 92 | | [Package options](https://mrcieu.github.io/epigraphdb-r/articles/options.html)| 93 | | [Meta functionalities of the EpiGraphDB platform](https://mrcieu.github.io/epigraphdb-r/articles/meta-functionalities.html)| 94 | | [Case study 1: Distinguishing vertical and horizontal pleiotropy for SNP-protein associations](https://docs.epigraphdb.org/r-package/case-1-pleiotropy/)| 95 | | [Case study 2: Identification of potential drug targets](https://docs.epigraphdb.org/r-package/case-2-alt-drug-target/)| 96 | | [Case study 3: Triangulating causal estimates with literature evidence](https://docs.epigraphdb.org/r-package/case-3-literature-triangulation/)| 97 | 98 | ## Package functionalities 99 | 100 | Users can use the general query function 101 | [query_epigraphdb](https://mrcieu.github.io/epigraphdb-r/reference/query_epigraphdb.html) 102 | to get data from an API endpoint on EpiGraphDB without having to deal with HTTP requests by themselves. 103 | We also provide a list of functions (see the table below) that are equivalent to the upstream endpoints for the ease of use. 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 120 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 132 | 135 | 136 | 137 | 140 | 143 | 144 | 145 | 148 | 151 | 152 | 153 | 156 | 159 | 160 | 161 | 164 | 167 | 168 | 169 | 172 | 176 | 177 | 178 | 181 | 184 | 185 | 186 | 189 | 192 | 193 | 194 | 197 | 200 | 201 | 202 | 205 | 208 | 209 | 210 | 213 | 216 | 217 | 218 | 221 | 224 | 225 | 226 | 229 | 232 | 233 | 234 | 237 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 249 | 252 | 253 | 254 | 257 | 260 | 261 | 262 | 265 | 268 | 269 | 270 | 273 | 276 | 277 | 278 | 281 | 284 | 285 | 286 | 289 | 292 | 293 | 294 | 297 | 300 | 301 | 302 |
APIr package
General query
119 | 121 | query_epigraphdb 122 |
Topic queries
130 | GET /mr 131 | 133 | mr 134 |
138 | GET /ontology/gwas-efo 139 | 141 | ontology_gwas_efo 142 |
146 | GET /obs-cor 147 | 149 | obs_cor 150 |
154 | GET /genetic-cor 155 | 157 | genetic_cor 158 |
162 | GET /pqtl/ 163 | 165 | pqtl 166 |
170 | GET /pqtl/pleio/ 171 | 173 | pqtl_pleio 175 |
179 | GET /pqtl/list 180 | 182 | pqtl_list 183 |
187 | GET /confounder 188 | 190 | confounder 191 |
195 | GET /pathway 196 | 198 | pathway 199 |
203 | GET /drugs/risk-factors 204 | 206 | drugs_risk_factors 207 |
211 | GET /xqtl/multi-snp-mr 212 | 214 | xqtl_multi_snp_mr 215 |
219 | GET /xqtl/single-snp-mr 220 | 222 | xqtl_single_snp_mr 223 |
227 | GET /literature/gwas 228 | 230 | literature_gwas 231 |
235 | POST /protein/in-pathway 236 | 238 | protein_in_pathway 239 |
Utilities
247 | POST /mappings/gene-to-protein 248 | 250 | mappings_gene_to_protein 251 |
255 | GET /meta/nodes/list 256 | 258 | meta_nodes_list 259 |
263 | GET /meta/rels/list 264 | 266 | meta_rels_list 267 |
271 | GET /meta/nodes/{meta_node}/list 272 | 274 | meta_nodes_list_node 275 |
279 | GET /meta/rels/{meta_rel}/list 280 | 282 | meta_rels_list_rel 283 |
287 | GET /meta/nodes/{meta_node}/search 288 | 290 | meta_nodes_search_node 291 |
295 | POST /cypher 296 | 298 | cypher 299 |
303 | 304 | ## Contributing 305 | 306 | If you would like to contribute to this package, please check out [documentation](https://github.com/MRCIEU/epigraphdb-r/wiki/Development) on setting up development and currently planned updates. 307 | 308 | ## EpiGraphDB resources 309 | 310 | | link | screenshot | 311 | |-----------------------------------------------------|-------------------------------------------------------| 312 | | [docs](https://docs.epigraphdb.org) | ![docs](vignettes/figures/epigraphdb-docs.png) | 313 | | [API](https://api.epigraphdb.org) | ![api](vignettes/figures/epigraphdb-api-swagger.png) | 314 | | [web application](https://epigraphdb.org) | ![webapp](vignettes/figures/epigraphdb-xqtl-view.png) | 315 | | [r package](https://github.com/MRCIEU/epigraphdb-r) | ![epigraphdb-r](vignettes/figures/epigraphdb-r.png) | 316 | 317 | ## Citation 318 | 319 | Please cite EpiGraphDB as 320 | 321 | > Yi Liu, Benjamin Elsworth, Pau Erola, Valeriia Haberland, Gibran Hemani, Matt Lyon, Jie Zheng, Oliver Lloyd, Marina Vabistsevits, Tom R Gaunt, EpiGraphDB: a database and data mining platform for health data science, Bioinformatics, btaa961, https://doi.org/10.1093/bioinformatics/btaa961 322 | 323 | ``` 324 | @article{epigraphdb2020bioinformatics, 325 | author = {Liu, Yi and Elsworth, Benjamin and Erola, Pau and Haberland, Valeriia and Hemani, Gibran and Lyon, Matt and Zheng, Jie and Lloyd, Oliver and Vabistsevits, Marina and Gaunt, Tom R}, 326 | title = {{EpiGraphDB}: a database and data mining platform for health data science}, 327 | journal = {Bioinformatics}, 328 | year = {2020}, 329 | month = {11}, 330 | issn = {1367-4803}, 331 | doi = {10.1093/bioinformatics/btaa961}, 332 | url = {https://doi.org/10.1093/bioinformatics/btaa961}, 333 | note = {btaa961}, 334 | eprint = {https://academic.oup.com/bioinformatics/advance-article-pdf/doi/10.1093/bioinformatics/btaa961/34178613/btaa961.pdf} 335 | } 336 | ``` 337 | 338 | ## Contact 339 | 340 | Please get in touch with us for issues, comments, suggestions, etc. via the following methods: 341 | 342 | - [The issue tracker on the `epigraphdb` repo](https://github.com/MRCIEU/epigraphdb/issues) 343 | - [The support email](mailto:feedback@epigraphdb.org) 344 | - [The EpiGraphDB twitter](https://twitter.com/epigraphdb) 345 | -------------------------------------------------------------------------------- /_pkgdown.yml: -------------------------------------------------------------------------------- 1 | destination: docs 2 | 3 | authors: 4 | Yi Liu: 5 | href: https://yiliu6240.github.io 6 | Marina Vabistsevits: 7 | href: https://marinalearning.netlify.com 8 | Tom Gaunt: 9 | href: http://www.biocompute.org.uk/ 10 | MRC IEU: 11 | href: https://mrcieu.github.io/ 12 | 13 | navbar: 14 | title: "epigraphdb" 15 | type: inverse 16 | left: 17 | - text: "Home" 18 | href: index.html 19 | - text: "Reference" 20 | href: "reference/index.html" 21 | - text: "Articles" 22 | menu: 23 | - text: "Articles" 24 | href: articles/index.html 25 | - text: "About EpiGraphDB" 26 | href: "articles/about.html" 27 | - text: "Getting started with EpiGraphDB in R" 28 | href: "articles/getting-started-with-epigraphdb-r.html" 29 | - text: "Using R package" 30 | href: articles/using-epigraphdb-r-package.html 31 | - text: "Meta functionalities of the EpiGraphDB platform" 32 | href: "articles/meta-functionalities.html" 33 | - text: "Using API" 34 | href: articles/using-epigraphdb-api.html 35 | - text: "Options" 36 | href: "articles/options.html" 37 | - text: "(on EpiGraphDB docs) Case study 1: Distinguishing vertical and horizontal pleiotropy for SNP-protein associations" 38 | href: "https://docs.epigraphdb.org/r-package/case-1-pleiotropy/" 39 | - text: "(on EpiGraphDB docs) Case study 2: Identification of potential drug targets" 40 | href: "https://docs.epigraphdb.org/r-package/case-2-alt-drug-target/" 41 | - text: "(on EpiGraphDB docs) Case study 3: Triangulating causal estimates with literature evidence" 42 | href: "https://docs.epigraphdb.org/r-package/case-3-literature-triangulation/" 43 | - text: "CHANGELOG" 44 | href: "news/index.html" 45 | right: 46 | - icon: fa-github 47 | href: https://github.com/MRCIEU/epigraphdb-r 48 | 49 | reference: 50 | - title: General query 51 | contents: 52 | - query_epigraphdb 53 | - title: Topic queries 54 | contents: 55 | - confounder 56 | - drugs_risk_factors 57 | - genetic_cor 58 | - literature_gwas 59 | - mr 60 | - obs_cor 61 | - ontology_gwas_efo 62 | - pathway 63 | - pqtl 64 | - pqtl_list 65 | - pqtl_pleio 66 | - xqtl_multi_snp_mr 67 | - xqtl_single_snp_mr 68 | - protein_in_pathway 69 | - title: Utilities 70 | contents: 71 | - mappings_gene_to_protein 72 | - meta_nodes_list 73 | - meta_rels_list 74 | - meta_nodes_list_node 75 | - meta_rels_list_rel 76 | - meta_nodes_search_node 77 | - cypher 78 | -------------------------------------------------------------------------------- /codecov.yml: -------------------------------------------------------------------------------- 1 | comment: false 2 | 3 | coverage: 4 | status: 5 | project: 6 | default: 7 | target: auto 8 | threshold: 1% 9 | patch: 10 | default: 11 | target: auto 12 | threshold: 1% 13 | -------------------------------------------------------------------------------- /cran-comments.md: -------------------------------------------------------------------------------- 1 | # epigraphdb 0.2.3 2 | 3 | (2022-01-14 second submissioin) 4 | Fixed the issue of the package size too large. 5 | 6 | (2022-01-14 first submissioin) 7 | This is a minor update making the package building and checks more resilient to issues of internet resources. 8 | 9 | - When a function call to web service resources fails, either because of the user or the service, it is now easier to trace the issue with more context provided. 10 | - Vignettes are now pre-computed. Some vignettes involving lengthy analysis steps are moved to EpiGraphDB's documentation. 11 | - When running package checks on cran, code examples of functions that rely on internet resources are put in `\dontrun{}`, and the same applies for unit tests (`skip_on_cran` in `testthat`). 12 | - Function code examples get run and checked when the pkgdown static site are built by GitHub Actions. 13 | - Tests (including ones relying on internet resources) get regularly run by GitHub Actions. 14 | 15 | ## Test environments 16 | - Local Linux in Docker, R 4.1.2 17 | - Via GitHub Actions 18 | - windows-latest, R release 19 | - macOS-latest, R release 20 | - ubuntu-20.04, R release and R devel 21 | - Via rhub 22 | - windows, R release and devel 23 | - Ubuntu Linux 20.04.1 LTS, R-release, GCC 24 | - Fedora Linux, R-devel, clang, gfortran 25 | - Fedora Linux, R-devel, clang, gfortran 26 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: "3.4" 2 | services: 3 | epigraphdb-r: 4 | build: 5 | context: . 6 | volumes: 7 | - ./:/data 8 | - ./pkg-build/:/pkg-build 9 | -------------------------------------------------------------------------------- /epigraphdb.Rproj: -------------------------------------------------------------------------------- 1 | Version: 1.0 2 | 3 | RestoreWorkspace: No 4 | SaveWorkspace: No 5 | AlwaysSaveHistory: Default 6 | 7 | EnableCodeIndexing: Yes 8 | UseSpacesForTab: Yes 9 | NumSpacesForTab: 2 10 | Encoding: UTF-8 11 | 12 | RnwWeave: Sweave 13 | LaTeX: pdfLaTeX 14 | 15 | AutoAppendNewline: Yes 16 | StripTrailingWhitespace: Yes 17 | 18 | BuildType: Package 19 | PackageUseDevtools: Yes 20 | PackageInstallArgs: --no-multiarch --with-keep.source 21 | PackageRoxygenize: rd,collate,namespace 22 | -------------------------------------------------------------------------------- /inst/WORDLIST: -------------------------------------------------------------------------------- 1 | APOE 2 | CHD 3 | Codecov 4 | Duerr 5 | EFO 6 | Ensembl 7 | EpiGraphDB 8 | Finan 9 | GWAS 10 | GWASes 11 | Gibran 12 | Gwas 13 | HGNC 14 | Hemani 15 | IBD 16 | IEU 17 | IL 18 | IVW 19 | Jie 20 | Jupyter 21 | Lifecycle 22 | MELODI 23 | MMTx 24 | Momozawa 25 | Neo 26 | OpenAPI 27 | PubMed 28 | RESTful 29 | RMarkdown 30 | SemMed 31 | SemMedDB 32 | SemRep 33 | UniProt 34 | api 35 | confounder 36 | df 37 | druggability 38 | druggable 39 | eQTL 40 | epigraphdb 41 | etc 42 | github 43 | gov 44 | httpie 45 | httr 46 | ieu 47 | json 48 | mmtx 49 | mr 50 | neo 51 | neo4j 52 | nih 53 | nlm 54 | pQTL 55 | params 56 | ppi 57 | pqtl 58 | pvalue 59 | rs 60 | rsID 61 | rsid 62 | semanticTypes 63 | shtml 64 | snp 65 | tibble 66 | tidyverse 67 | travis 68 | uniprot 69 | webapp 70 | xqtl 71 | bioRxiv 72 | doi 73 | rels 74 | rel 75 | MRC 76 | Pau 77 | Erola 78 | org 79 | Reactome 80 | TNF 81 | TP 82 | UniProtID 83 | btaa 84 | BRCA 85 | EpiGraphDB's 86 | WIP 87 | -------------------------------------------------------------------------------- /man/api_get_request.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/request_and_response.R 3 | \name{api_get_request} 4 | \alias{api_get_request} 5 | \title{Wrapper of httr::GET that handles status errors and custom headers} 6 | \usage{ 7 | api_get_request(route, params, retry_times, retry_pause_min) 8 | } 9 | \arguments{ 10 | \item{route}{An EpiGraphDB API endpoint route, e.g. "/mr"} 11 | 12 | \item{params}{GET request params} 13 | } 14 | \description{ 15 | Wrapper of httr::GET that handles status errors and custom headers 16 | } 17 | \keyword{internal} 18 | -------------------------------------------------------------------------------- /man/api_post_request.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/request_and_response.R 3 | \name{api_post_request} 4 | \alias{api_post_request} 5 | \title{Wrapper of httr::POST that handles status errors and custom headers} 6 | \usage{ 7 | api_post_request(route, params, retry_times, retry_pause_min) 8 | } 9 | \arguments{ 10 | \item{route}{An EpiGraphDB API endpoint route, e.g. "/mr"} 11 | 12 | \item{params}{POST request payload} 13 | } 14 | \description{ 15 | Wrapper of httr::POST that handles status errors and custom headers 16 | } 17 | \keyword{internal} 18 | -------------------------------------------------------------------------------- /man/api_request.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/request_and_response.R 3 | \name{api_request} 4 | \alias{api_request} 5 | \title{The very general wrapper from EpiGraphDB endpoint request} 6 | \usage{ 7 | api_request( 8 | route, 9 | params, 10 | mode = c("table", "raw"), 11 | method = api_get_request, 12 | retry_times, 13 | retry_pause_min 14 | ) 15 | } 16 | \arguments{ 17 | \item{route}{An EpiGraphDB API endpoint route, e.g. "/mr"} 18 | 19 | \item{params}{A list of parameters to send} 20 | 21 | \item{mode}{Either \code{"table"} (returns tibble) or 22 | \code{"raw"} (returns raw response parsed from json to R list).} 23 | 24 | \item{method}{A specific request handler, e.g. \code{epi_get_request}} 25 | } 26 | \description{ 27 | The very general wrapper from EpiGraphDB endpoint request 28 | } 29 | \keyword{internal} 30 | -------------------------------------------------------------------------------- /man/confounder.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/confounder.R 3 | \name{confounder} 4 | \alias{confounder} 5 | \title{MR evidence on confounding traits between exposure and outcome} 6 | \usage{ 7 | confounder( 8 | exposure_trait = NULL, 9 | outcome_trait = NULL, 10 | type = c("confounder", "intermediate", "reverse_intermediate", "collider"), 11 | pval_threshold = 1e-05, 12 | mode = c("table", "raw") 13 | ) 14 | } 15 | \arguments{ 16 | \item{exposure_trait}{A trait name, e.g. "Body mass index", 17 | leaving \code{exposure_trait} as \code{NULL} will return MR information 18 | related to a specific \code{outcome}. 19 | \strong{NOTE}: \code{exposure_trait} and \code{outcome_trait} cannot be both \code{NULL}.} 20 | 21 | \item{outcome_trait}{A trait name, e.g. "Coronary heart disease", 22 | leaving \code{outcome_trait} as \code{NULL} will return MR information 23 | related to a specific \code{exposure_trait}. 24 | \strong{NOTE}: \code{exposure_trait} and \code{outcome_trait} cannot be both \code{NULL}.} 25 | 26 | \item{type}{One in \verb{["confounder", "intermediate", "reverse_intermediate", "collider"]} 27 | Refer to \href{https://epigraphdb.org/confounder}{ the confounder view in web application } 28 | for details} 29 | 30 | \item{pval_threshold}{P-value threshold} 31 | 32 | \item{mode}{If \code{mode = "table"}, returns a data frame 33 | (a \href{https://tibble.tidyverse.org/}{\code{tibble}} as per 34 | \href{https://style.tidyverse.org/}{\code{tidyverse}} convention). 35 | If \code{mode = "raw"}, returns a raw response from EpiGraphDB API 36 | with minimal parsing done by \href{https://httr.r-lib.org/}{\code{httr}}.} 37 | } 38 | \value{ 39 | Data from \code{GET /confounder} 40 | } 41 | \description{ 42 | \href{https://docs.epigraphdb.org/api/api-endpoints/#get-confounder}{\code{GET /confounder}} 43 | } 44 | \examples{ 45 | \dontrun{ 46 | confounder(exposure_trait = "Body mass index", outcome_trait = "Coronary heart disease") 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /man/cypher.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/cypher.R 3 | \name{cypher} 4 | \alias{cypher} 5 | \title{Send a query in Cypher to EpiGraphDB} 6 | \usage{ 7 | cypher(query, mode = c("table", "raw")) 8 | } 9 | \arguments{ 10 | \item{query}{A Cypher query.} 11 | 12 | \item{mode}{If \code{mode = "table"}, returns a data frame 13 | (a \href{https://tibble.tidyverse.org/}{\code{tibble}} as per 14 | \href{https://style.tidyverse.org/}{\code{tidyverse}} convention). 15 | If \code{mode = "raw"}, returns a raw response from EpiGraphDB API 16 | with minimal parsing done by \href{https://httr.r-lib.org/}{\code{httr}}.} 17 | } 18 | \description{ 19 | NOTE: this function is intended for advanced uses. 20 | Regular users are recommended to use standard query functions 21 | } 22 | \examples{ 23 | \dontrun{ 24 | cypher("MATCH (n:Gwas) RETURN n LIMIT 2") 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /man/drugs_risk_factors.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/drugs.R 3 | \name{drugs_risk_factors} 4 | \alias{drugs_risk_factors} 5 | \title{Drugs for risk factors} 6 | \usage{ 7 | drugs_risk_factors(trait, pval_threshold = 1e-08, mode = c("table", "raw")) 8 | } 9 | \arguments{ 10 | \item{trait}{A trait name} 11 | 12 | \item{pval_threshold}{P-value threshold} 13 | 14 | \item{mode}{If \code{mode = "table"}, returns a data frame 15 | (a \href{https://tibble.tidyverse.org/}{\code{tibble}} as per 16 | \href{https://style.tidyverse.org/}{\code{tidyverse}} convention). 17 | If \code{mode = "raw"}, returns a raw response from EpiGraphDB API 18 | with minimal parsing done by \href{https://httr.r-lib.org/}{\code{httr}}.} 19 | } 20 | \value{ 21 | Data from \code{GET /drugs/risk-factors} 22 | } 23 | \description{ 24 | \href{https://docs.epigraphdb.org/api/api-endpoints/#get-drugsrisk-factors}{\code{GET /drugs/risk-factors}} 25 | } 26 | \examples{ 27 | \dontrun{ 28 | drugs_risk_factors(trait = "Body mass index") 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /man/epigraphdb-package.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/epigraphdb-package.R 3 | \docType{package} 4 | \name{epigraphdb-package} 5 | \alias{epigraphdb} 6 | \alias{epigraphdb-package} 7 | \title{epigraphdb: Interface Package for the 'EpiGraphDB' Platform} 8 | \description{ 9 | The interface package to access data from the 'EpiGraphDB' platform. It provides easy access to the 'EpiGraphDB' platform with functions that query the corresponding REST endpoints on the API and return the response data in the 'tibble' data frame format. 10 | } 11 | \seealso{ 12 | Useful links: 13 | \itemize{ 14 | \item \url{https://mrcieu.github.io/epigraphdb-r/} 15 | \item Report bugs at \url{https://github.com/MRCIEU/epigraphdb-r/issues} 16 | } 17 | 18 | } 19 | \author{ 20 | \strong{Maintainer}: Yi Liu \email{yi6240.liu@bristol.ac.uk} 21 | 22 | Authors: 23 | \itemize{ 24 | \item Valeriia Haberland \email{valeriia.haberland@bristol.ac.uk} 25 | \item Marina Vabistsevits \email{ny19205@bristol.ac.uk} 26 | \item Tom Gaunt \email{Tom.Gaunt@bristol.ac.uk} 27 | } 28 | 29 | Other contributors: 30 | \itemize{ 31 | \item MRC IEU [copyright holder] 32 | } 33 | 34 | } 35 | \keyword{internal} 36 | -------------------------------------------------------------------------------- /man/figures/mrc-ieu-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MRCIEU/epigraphdb-r/1cd05d8426a8e9f65160374ab3f631793ac3f742/man/figures/mrc-ieu-logo.png -------------------------------------------------------------------------------- /man/flatten_response.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/request_and_response.R 3 | \name{flatten_response} 4 | \alias{flatten_response} 5 | \title{Flatten the "results" field from an API response to a tibble df} 6 | \usage{ 7 | flatten_response(response, field = "results") 8 | } 9 | \arguments{ 10 | \item{response}{An httr response} 11 | 12 | \item{field}{Default to the "results" field} 13 | } 14 | \value{ 15 | A tibble df 16 | } 17 | \description{ 18 | The general tibble flattener for EpiGraphDB endpoints 19 | } 20 | \keyword{internal} 21 | -------------------------------------------------------------------------------- /man/genetic_cor.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/genetic_cor.R 3 | \name{genetic_cor} 4 | \alias{genetic_cor} 5 | \title{Genetic correlations between traits} 6 | \usage{ 7 | genetic_cor(trait, cor_coef_threshold = 0.8, mode = c("table", "raw")) 8 | } 9 | \arguments{ 10 | \item{trait}{name of the trait, e.g. "body mass index"} 11 | 12 | \item{cor_coef_threshold}{correlation coefficient threshold} 13 | 14 | \item{mode}{If \code{mode = "table"}, returns a data frame 15 | (a \href{https://tibble.tidyverse.org/}{\code{tibble}} as per 16 | \href{https://style.tidyverse.org/}{\code{tidyverse}} convention). 17 | If \code{mode = "raw"}, returns a raw response from EpiGraphDB API 18 | with minimal parsing done by \href{https://httr.r-lib.org/}{\code{httr}}.} 19 | } 20 | \value{ 21 | Data from \code{GET /genetic_cor} 22 | } 23 | \description{ 24 | \href{https://docs.epigraphdb.org/api/api-endpoints/#get-genetic-cor}{\code{GET /genetic-cor}} 25 | } 26 | \examples{ 27 | \dontrun{ 28 | genetic_cor(trait = "Body mass index") \%>\% 29 | dplyr::glimpse() 30 | } 31 | 32 | # Use a different threshold 33 | \dontrun{ 34 | genetic_cor(trait = "Body mass index", cor_coef_threshold = 0.4) \%>\% 35 | dplyr::glimpse() 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /man/http_condition.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/request_and_response.R 3 | \name{http_condition} 4 | \alias{http_condition} 5 | \title{Modified httr::http_condition} 6 | \usage{ 7 | http_condition(response, context) 8 | } 9 | \arguments{ 10 | \item{response}{An httr response} 11 | 12 | \item{context}{A list on the url and params for the request} 13 | } 14 | \description{ 15 | Modified httr::http_condition 16 | } 17 | \keyword{internal} 18 | -------------------------------------------------------------------------------- /man/literature_gwas.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/literature.R 3 | \name{literature_gwas} 4 | \alias{literature_gwas} 5 | \title{Literature evidence regarding a GWAS trait} 6 | \usage{ 7 | literature_gwas(trait, semmed_predicate = NULL, mode = c("table", "raw")) 8 | } 9 | \arguments{ 10 | \item{trait}{A trait name} 11 | 12 | \item{semmed_predicate}{Either NULL which returns entries from 13 | all predicates, or a SemMed predicate e.g. "DIAGNOSES" or "ASSOCIATED_WITH"} 14 | 15 | \item{mode}{If \code{mode = "table"}, returns a data frame 16 | (a \href{https://tibble.tidyverse.org/}{\code{tibble}} as per 17 | \href{https://style.tidyverse.org/}{\code{tidyverse}} convention). 18 | If \code{mode = "raw"}, returns a raw response from EpiGraphDB API 19 | with minimal parsing done by \href{https://httr.r-lib.org/}{\code{httr}}.} 20 | } 21 | \value{ 22 | Data from \code{GET /literature/gwas} 23 | } 24 | \description{ 25 | \href{https://docs.epigraphdb.org/api/api-endpoints/#get-literaturegwas}{\code{GET /literature/gwas}} 26 | } 27 | \examples{ 28 | \dontrun{ 29 | literature_gwas(trait = "Body mass index") 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /man/mappings_gene_to_protein.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/mappings.R 3 | \name{mappings_gene_to_protein} 4 | \alias{mappings_gene_to_protein} 5 | \title{Return protein uniprot_id from associated genes} 6 | \usage{ 7 | mappings_gene_to_protein( 8 | gene_name_list = NULL, 9 | gene_id_list = NULL, 10 | by_gene_id = FALSE, 11 | mode = c("table", "raw") 12 | ) 13 | } 14 | \arguments{ 15 | \item{gene_name_list}{List of HGNC symbols of the genes (default)} 16 | 17 | \item{gene_id_list}{List of Ensembl gene IDs (when \code{by_gene_id == TRUE})} 18 | 19 | \item{by_gene_id}{Search for gene ids (Ensembl gene IDs) instead of gene names (HGNC symbols)} 20 | 21 | \item{mode}{If \code{mode = "table"}, returns a data frame 22 | (a \href{https://tibble.tidyverse.org/}{\code{tibble}} as per 23 | \href{https://style.tidyverse.org/}{\code{tidyverse}} convention). 24 | If \code{mode = "raw"}, returns a raw response from EpiGraphDB API 25 | with minimal parsing done by \href{https://httr.r-lib.org/}{\code{httr}}.} 26 | } 27 | \value{ 28 | Data from \code{POST /mappings/gene-to-protein} 29 | } 30 | \description{ 31 | \href{https://docs.epigraphdb.org/api/api-endpoints/#post-mappingsgene-to-protein}{\code{POST /mappings/gene-to-protein}} 32 | } 33 | \examples{ 34 | # By HGNC symbols 35 | \dontrun{ 36 | mappings_gene_to_protein(gene_name_list = c("GCH1", "MYOF")) 37 | } 38 | 39 | # By Enselbl Ids 40 | \dontrun{ 41 | mappings_gene_to_protein(gene_id_list = c("ENSG00000162594", "ENSG00000113302"), by_gene_id = TRUE) 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /man/meta_nodes_list.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/meta.R 3 | \name{meta_nodes_list} 4 | \alias{meta_nodes_list} 5 | \title{List meta nodes (e.g. Gwas, Gene, etc.)} 6 | \usage{ 7 | meta_nodes_list(mode = c("raw")) 8 | } 9 | \arguments{ 10 | \item{mode}{If \code{mode = "table"}, returns a data frame 11 | (a \href{https://tibble.tidyverse.org/}{\code{tibble}} as per 12 | \href{https://style.tidyverse.org/}{\code{tidyverse}} convention). 13 | If \code{mode = "raw"}, returns a raw response from EpiGraphDB API 14 | with minimal parsing done by \href{https://httr.r-lib.org/}{\code{httr}}.} 15 | } 16 | \value{ 17 | Data from \code{GET /meta/nodes/list} 18 | } 19 | \description{ 20 | \href{https://docs.epigraphdb.org/api/api-endpoints/#get-metanodeslist}{\code{GET /meta/nodes/list}} 21 | } 22 | \examples{ 23 | \dontrun{ 24 | meta_nodes_list() 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /man/meta_nodes_list_node.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/meta.R 3 | \name{meta_nodes_list_node} 4 | \alias{meta_nodes_list_node} 5 | \title{List nodes under a meta node} 6 | \usage{ 7 | meta_nodes_list_node( 8 | meta_node, 9 | full_data = TRUE, 10 | limit = 10, 11 | offset = 0, 12 | mode = c("table", "raw") 13 | ) 14 | } 15 | \arguments{ 16 | \item{meta_node}{Name of a meta node (e.g. Gwas). Use \code{meta_nodes_list} to get the full list of meta nodes.} 17 | 18 | \item{full_data}{When False, only return the id and name fields (their specific names differ in specific nodes) for a node. 19 | This is useful if you want your queries to return results faster with smaller amount of data requested.} 20 | 21 | \item{limit}{Max number of items to retrieve.} 22 | 23 | \item{offset}{Number of items to skip. Use \code{limit} and \code{offset} in combination to do pagination.} 24 | 25 | \item{mode}{If \code{mode = "table"}, returns a data frame 26 | (a \href{https://tibble.tidyverse.org/}{\code{tibble}} as per 27 | \href{https://style.tidyverse.org/}{\code{tidyverse}} convention). 28 | If \code{mode = "raw"}, returns a raw response from EpiGraphDB API 29 | with minimal parsing done by \href{https://httr.r-lib.org/}{\code{httr}}.} 30 | } 31 | \value{ 32 | Data from \code{GET /meta/nodes/{meta_node}/list} 33 | } 34 | \description{ 35 | \href{https://docs.epigraphdb.org/api/api-endpoints/#get-metanodesmeta_nodelist}{\code{GET /meta/nodes/{meta_node}/list}} 36 | } 37 | \examples{ 38 | # List the first 5 Gwas nodes, with only id and name fields 39 | \dontrun{ 40 | meta_nodes_list_node(meta_node = "Gwas", full_data = FALSE, limit = 5) 41 | } 42 | 43 | # List the 6th - 10th Disease nodes, with full properties 44 | \dontrun{ 45 | meta_nodes_list_node(meta_node = "Disease", full_data = TRUE, limit = 5, offset = 0) 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /man/meta_nodes_search_node.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/meta.R 3 | \name{meta_nodes_search_node} 4 | \alias{meta_nodes_search_node} 5 | \title{Search a node by its id field, or its name field} 6 | \usage{ 7 | meta_nodes_search_node( 8 | meta_node, 9 | id = NULL, 10 | name = NULL, 11 | limit = 10, 12 | full_data = TRUE, 13 | mode = c("table", "raw") 14 | ) 15 | } 16 | \arguments{ 17 | \item{meta_node}{Name of a meta node (e.g. Gwas). Use \code{meta_nodes_list} to get the full list of meta nodes.} 18 | 19 | \item{id}{The id field of a node (e.g. "ieu-a-2" for a Gwas). 20 | Use EpiGraphDB web UI to get a sense of what those ids are for entities.} 21 | 22 | \item{name}{The name field of a node (e.g. "body mass index" for a Gwas). 23 | Use EpiGraphDB web UI to get a sense of what those names are for entities.} 24 | 25 | \item{limit}{Max number of items to retrieve.} 26 | 27 | \item{full_data}{When False, only return the id and name fields (their specific names differ in specific nodes) for a node. 28 | This is useful if you want your queries to return results faster with smaller amount of data requested.} 29 | 30 | \item{mode}{If \code{mode = "table"}, returns a data frame 31 | (a \href{https://tibble.tidyverse.org/}{\code{tibble}} as per 32 | \href{https://style.tidyverse.org/}{\code{tidyverse}} convention). 33 | If \code{mode = "raw"}, returns a raw response from EpiGraphDB API 34 | with minimal parsing done by \href{https://httr.r-lib.org/}{\code{httr}}.} 35 | } 36 | \value{ 37 | Data from \code{GET /meta/nodes/{meta_node}/search} 38 | } 39 | \description{ 40 | \href{https://docs.epigraphdb.org/api/api-endpoints/#get-metanodesmeta_nodesearch}{\code{GET /meta/nodes/{meta_node}/search}} 41 | } 42 | \examples{ 43 | # Search Gwas nodes 44 | \dontrun{ 45 | meta_nodes_search_node(meta_node = "Gwas", name = "body mass index") 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /man/meta_rels_list.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/meta.R 3 | \name{meta_rels_list} 4 | \alias{meta_rels_list} 5 | \title{List meta rels (e.g. MR, etc.)} 6 | \usage{ 7 | meta_rels_list(mode = c("raw")) 8 | } 9 | \arguments{ 10 | \item{mode}{If \code{mode = "table"}, returns a data frame 11 | (a \href{https://tibble.tidyverse.org/}{\code{tibble}} as per 12 | \href{https://style.tidyverse.org/}{\code{tidyverse}} convention). 13 | If \code{mode = "raw"}, returns a raw response from EpiGraphDB API 14 | with minimal parsing done by \href{https://httr.r-lib.org/}{\code{httr}}.} 15 | } 16 | \value{ 17 | Data from \code{GET /meta/rels/list} 18 | } 19 | \description{ 20 | \href{https://docs.epigraphdb.org/api/api-endpoints/#get-metarelslist}{\code{GET /meta/rels/list}} 21 | } 22 | \examples{ 23 | \dontrun{ 24 | meta_rels_list() 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /man/meta_rels_list_rel.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/meta.R 3 | \name{meta_rels_list_rel} 4 | \alias{meta_rels_list_rel} 5 | \title{List relationships under a meta relationship} 6 | \usage{ 7 | meta_rels_list_rel(meta_rel, limit = 10, offset = 0, mode = c("table", "raw")) 8 | } 9 | \arguments{ 10 | \item{meta_rel}{Name of a meta relationship (e.g. MR). Use \code{meta_rels_list} to get the full list of meta relationships.} 11 | 12 | \item{limit}{Max number of items to retrieve.} 13 | 14 | \item{offset}{Number of items to skip. Use \code{limit} and \code{offset} in combination to do pagination.} 15 | 16 | \item{mode}{If \code{mode = "table"}, returns a data frame 17 | (a \href{https://tibble.tidyverse.org/}{\code{tibble}} as per 18 | \href{https://style.tidyverse.org/}{\code{tidyverse}} convention). 19 | If \code{mode = "raw"}, returns a raw response from EpiGraphDB API 20 | with minimal parsing done by \href{https://httr.r-lib.org/}{\code{httr}}.} 21 | } 22 | \value{ 23 | Data from \code{GET /meta/rels/{meta_rel}/list} 24 | } 25 | \description{ 26 | \href{https://docs.epigraphdb.org/api/api-endpoints/#get-metarelsmeta_rellist}{\code{GET /meta/rels/{meta_rel}/list}} 27 | } 28 | \examples{ 29 | # List the first 5 MR relationships 30 | \dontrun{ 31 | meta_rels_list_rel(meta_rel = "MR_EVE_MR", limit = 5) 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /man/mr.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/mr.R 3 | \name{mr} 4 | \alias{mr} 5 | \title{Return information related to Mendelian Randomisation} 6 | \usage{ 7 | mr( 8 | exposure_trait = NULL, 9 | outcome_trait = NULL, 10 | pval_threshold = 1e-05, 11 | mode = c("table", "raw") 12 | ) 13 | } 14 | \arguments{ 15 | \item{exposure_trait}{A trait name, e.g. "Body mass index", 16 | leaving \code{exposure_trait} as \code{NULL} will return MR information 17 | related to a specific \code{outcome}. 18 | \strong{NOTE}: \code{exposure_trait} and \code{outcome_trait} cannot be both \code{NULL}.} 19 | 20 | \item{outcome_trait}{A trait name, e.g. "Coronary heart disease", 21 | leaving \code{outcome_trait} as \code{NULL} will return MR information 22 | related to a specific \code{exposure_trait}. 23 | \strong{NOTE}: \code{exposure_trait} and \code{outcome_trait} cannot be both \code{NULL}.} 24 | 25 | \item{pval_threshold}{P-value threshold} 26 | 27 | \item{mode}{If \code{mode = "table"}, returns a data frame 28 | (a \href{https://tibble.tidyverse.org/}{\code{tibble}} as per 29 | \href{https://style.tidyverse.org/}{\code{tidyverse}} convention). 30 | If \code{mode = "raw"}, returns a raw response from EpiGraphDB API 31 | with minimal parsing done by \href{https://httr.r-lib.org/}{\code{httr}}.} 32 | } 33 | \value{ 34 | Data from \code{GET /mr} 35 | } 36 | \description{ 37 | \href{https://docs.epigraphdb.org/api/api-endpoints/#get-mr}{\code{GET /mr}} 38 | } 39 | \examples{ 40 | # Returns a data frame 41 | \dontrun{ 42 | mr(exposure_trait = "Body mass index", outcome_trait = "Coronary heart disease") 43 | } 44 | 45 | # Returns raw response 46 | \dontrun{ 47 | mr( 48 | exposure_trait = "Body mass index", outcome_trait = "Coronary heart disease", 49 | mode = "raw" 50 | ) \%>\% str() 51 | } 52 | 53 | # Use a different threshold 54 | \dontrun{ 55 | mr(exposure_trait = "Body mass index", pval_threshold = 1e-8) 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /man/obs_cor.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/obs_cor.R 3 | \name{obs_cor} 4 | \alias{obs_cor} 5 | \title{Observational correlations between traits} 6 | \usage{ 7 | obs_cor(trait, cor_coef_threshold = 0.8, mode = c("table", "raw")) 8 | } 9 | \arguments{ 10 | \item{trait}{name of the trait, e.g. "body mass index"} 11 | 12 | \item{cor_coef_threshold}{correlation coefficient threshold} 13 | 14 | \item{mode}{If \code{mode = "table"}, returns a data frame 15 | (a \href{https://tibble.tidyverse.org/}{\code{tibble}} as per 16 | \href{https://style.tidyverse.org/}{\code{tidyverse}} convention). 17 | If \code{mode = "raw"}, returns a raw response from EpiGraphDB API 18 | with minimal parsing done by \href{https://httr.r-lib.org/}{\code{httr}}.} 19 | } 20 | \value{ 21 | Data from \code{GET /obs-cor} 22 | } 23 | \description{ 24 | \href{https://docs.epigraphdb.org/api/api-endpoints/#get-obs-cor}{\code{GET /obs-cor}} 25 | } 26 | \examples{ 27 | \dontrun{ 28 | obs_cor(trait = "Body mass index (BMI)") \%>\% 29 | dplyr::glimpse() 30 | } 31 | 32 | # Use a different threshold 33 | \dontrun{ 34 | obs_cor(trait = "Body mass index (BMI)", cor_coef_threshold = 0.8) \%>\% 35 | dplyr::glimpse() 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /man/ontology_gwas_efo.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ontology.R 3 | \name{ontology_gwas_efo} 4 | \alias{ontology_gwas_efo} 5 | \title{Ontology association between EFO term and Gwas} 6 | \usage{ 7 | ontology_gwas_efo( 8 | trait = NULL, 9 | efo_term = NULL, 10 | fuzzy = TRUE, 11 | mode = c("table", "raw") 12 | ) 13 | } 14 | \arguments{ 15 | \item{trait}{trait name, e.g. "body mass"} 16 | 17 | \item{efo_term}{EFO term, e.g. "systolic blood pressure"} 18 | 19 | \item{fuzzy}{whether query with exact matching (FALSE) or fuzzy matching (default, TRUE)} 20 | 21 | \item{mode}{If \code{mode = "table"}, returns a data frame 22 | (a \href{https://tibble.tidyverse.org/}{\code{tibble}} as per 23 | \href{https://style.tidyverse.org/}{\code{tidyverse}} convention). 24 | If \code{mode = "raw"}, returns a raw response from EpiGraphDB API 25 | with minimal parsing done by \href{https://httr.r-lib.org/}{\code{httr}}.} 26 | } 27 | \value{ 28 | Data from \code{GET /ontology/gwas-efo} 29 | } 30 | \description{ 31 | \href{https://docs.epigraphdb.org/api/api-endpoints/#get-ontologygwas-efo}{\code{GET /ontology/gwas-efo}} 32 | } 33 | \examples{ 34 | \dontrun{ 35 | ontology_gwas_efo(trait = "blood", fuzzy = FALSE) 36 | } 37 | 38 | \dontrun{ 39 | ontology_gwas_efo(efo_term = "blood pressure", fuzzy = FALSE) 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /man/pathway.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/pathway.R 3 | \name{pathway} 4 | \alias{pathway} 5 | \title{Pathway evidence} 6 | \usage{ 7 | pathway(trait, pval_threshold = 1e-05, mode = c("table", "raw")) 8 | } 9 | \arguments{ 10 | \item{trait}{A trait name} 11 | 12 | \item{pval_threshold}{P-value threshold} 13 | 14 | \item{mode}{If \code{mode = "table"}, returns a data frame 15 | (a \href{https://tibble.tidyverse.org/}{\code{tibble}} as per 16 | \href{https://style.tidyverse.org/}{\code{tidyverse}} convention). 17 | If \code{mode = "raw"}, returns a raw response from EpiGraphDB API 18 | with minimal parsing done by \href{https://httr.r-lib.org/}{\code{httr}}.} 19 | } 20 | \value{ 21 | Data from \code{GET /pathway} 22 | } 23 | \description{ 24 | \href{https://docs.epigraphdb.org/api/api-endpoints/#get-pathway}{\code{GET /pathway}} 25 | } 26 | \examples{ 27 | \dontrun{ 28 | pathway(trait = "Body mass index") 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /man/pipe.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utils-pipe.R 3 | \name{\%>\%} 4 | \alias{\%>\%} 5 | \title{Pipe operator} 6 | \usage{ 7 | lhs \%>\% rhs 8 | } 9 | \description{ 10 | See \code{magrittr::\link[magrittr:pipe]{\%>\%}} for details. 11 | } 12 | \keyword{internal} 13 | -------------------------------------------------------------------------------- /man/pqtl.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/pqtl.R 3 | \name{pqtl} 4 | \alias{pqtl} 5 | \title{Return information related to the pQTL analysis} 6 | \usage{ 7 | pqtl( 8 | query, 9 | rtype = c("mrres", "simple", "sglmr", "inst", "sense"), 10 | pvalue = 0.05, 11 | searchflag = c("traits", "proteins"), 12 | mode = c("table", "raw") 13 | ) 14 | } 15 | \arguments{ 16 | \item{query}{(Required) A protein coding gene name or a trait name, 17 | e.g. "ADAM19" or "Inflammatory bowel disease" 18 | which cannot be \code{NULL}.} 19 | 20 | \item{rtype}{(Optional) A type of data to be extracted, which can be one of these options: 21 | \enumerate{ 22 | \item \code{simple}: Basic summary 23 | \item \code{mrres}: MR results (DEFAULT) 24 | \item \code{sglmr}: Single SNP MR results 25 | \item \code{inst}: SNP information 26 | \item \code{sense}: Sensitivity analysis 27 | \strong{NOTE}: \code{mrres} is a DEFAULT option. 28 | }} 29 | 30 | \item{pvalue}{(Optional) A pvalue threshold for MR results with the DEFAULT set to 0.05. 31 | \strong{NOTE}: this threshold applies to any \code{rtype} chosen.} 32 | 33 | \item{searchflag}{(Required) A flag to indicate whether you are searching for proteins or 34 | traits which cannot be \code{NULL}. 35 | If \code{query} is a protein name, then this flag should be "proteins"; 36 | if \code{query} is a trait, this flag should be "traits". 37 | \strong{NOTE}: if the wrong flag is chosen for \code{query}, there will be no result 38 | returned.} 39 | 40 | \item{mode}{If \code{mode = "table"}, returns a data frame 41 | (a \href{https://tibble.tidyverse.org/}{\code{tibble}} as per 42 | \href{https://style.tidyverse.org/}{\code{tidyverse}} convention). 43 | If \code{mode = "raw"}, returns a raw response from EpiGraphDB API 44 | with minimal parsing done by \href{https://httr.r-lib.org/}{\code{httr}}.} 45 | } 46 | \value{ 47 | Data from \verb{GET /pqtl/} 48 | } 49 | \description{ 50 | \href{https://docs.epigraphdb.org/api/api-endpoints/#get-pqtl}{\verb{GET /pqtl/}} 51 | } 52 | \examples{ 53 | # Returns a data frame of MR results, while searching for proteins 54 | \dontrun{ 55 | pqtl(query = "ADAM19", searchflag = "proteins") 56 | } 57 | 58 | # Returns a data frame with SNP information, while searching for traits 59 | \dontrun{ 60 | pqtl( 61 | query = "Inflammatory bowel disease", 62 | rtype = "inst", 63 | searchflag = "traits" 64 | ) 65 | } 66 | 67 | # Change a pvalue threshold (the default is 0.05) 68 | \dontrun{ 69 | pqtl( 70 | query = "Inflammatory bowel disease", 71 | rtype = "inst", 72 | pvalue = 1.0, 73 | searchflag = "traits" 74 | ) 75 | } 76 | 77 | # Returns raw response if mode="raw" 78 | \dontrun{ 79 | pqtl( 80 | query = "ADAM19", searchflag = "proteins", 81 | mode = "raw" 82 | ) \%>\% str() 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /man/pqtl_list.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/pqtl.R 3 | \name{pqtl_list} 4 | \alias{pqtl_list} 5 | \title{Return a list of all proteins/exposures or traits/outcomes 6 | available in the database} 7 | \usage{ 8 | pqtl_list(flag = c("exposures", "outcomes"), mode = c("table", "raw")) 9 | } 10 | \arguments{ 11 | \item{flag}{(Optional) A flag which indicates whether the list of 12 | exposures (if "exposures") or outcomes (if "outcomes") 13 | should be returned. The DEFAULT is "exposures".} 14 | 15 | \item{mode}{If \code{mode = "table"}, returns a data frame 16 | (a \href{https://tibble.tidyverse.org/}{\code{tibble}} as per 17 | \href{https://style.tidyverse.org/}{\code{tidyverse}} convention). 18 | If \code{mode = "raw"}, returns a raw response from EpiGraphDB API 19 | with minimal parsing done by \href{https://httr.r-lib.org/}{\code{httr}}.} 20 | } 21 | \value{ 22 | Data from \verb{GET /pqtl/list/} 23 | } 24 | \description{ 25 | \href{https://docs.epigraphdb.org/api/api-endpoints/#get-pqtllist}{\verb{GET /pqtl/list/}} 26 | } 27 | \examples{ 28 | 29 | # Returns a list of available proteins (exposures) 30 | \dontrun{ 31 | pqtl_list() 32 | } 33 | 34 | # Returns a list of available traits (outcomes) 35 | \dontrun{ 36 | pqtl_list(flag = "outcomes") 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /man/pqtl_pleio.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/pqtl.R 3 | \name{pqtl_pleio} 4 | \alias{pqtl_pleio} 5 | \title{Return information related to the pleiotropy of SNPs} 6 | \usage{ 7 | pqtl_pleio( 8 | rsid = NULL, 9 | prflag = c("proteins", "count"), 10 | mode = c("table", "raw") 11 | ) 12 | } 13 | \arguments{ 14 | \item{rsid}{(Required) A SNP identified by rsID which cannot be \code{NULL}.} 15 | 16 | \item{prflag}{(Optional) A flag which determines whether the number (if "count") 17 | or names (if "proteins") of the associated proteins should be returned. 18 | The DEFAULT value is "proteins".} 19 | 20 | \item{mode}{(Optional) If \code{mode = "table"}, returns a data frame 21 | (a \href{https://tibble.tidyverse.org/}{\code{tibble}} as per 22 | \href{https://style.tidyverse.org/}{\code{tidyverse}} convention). 23 | If \code{mode = "raw"}, returns a raw response from EpiGraphDB API 24 | with minimal parsing done by \href{https://httr.r-lib.org/}{\code{httr}}.} 25 | } 26 | \value{ 27 | Data from \verb{GET /pqtl/pleio/} 28 | } 29 | \description{ 30 | \href{https://docs.epigraphdb.org/api/api-endpoints/#get-pqtlpleio}{\verb{GET /pqtl/pleio/}} 31 | } 32 | \examples{ 33 | 34 | # Returns a data frame of associated proteins 35 | \dontrun{ 36 | pqtl_pleio(rsid = "rs1260326") 37 | } 38 | 39 | # Returns a number of associated proteins 40 | \dontrun{ 41 | pqtl_pleio(rsid = "rs1260326", prflag = "count") 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /man/protein_in_pathway.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/protein.R 3 | \name{protein_in_pathway} 4 | \alias{protein_in_pathway} 5 | \title{For the list of proteins, returns their associated pathway data} 6 | \usage{ 7 | protein_in_pathway(uniprot_id_list, mode = c("table", "raw")) 8 | } 9 | \arguments{ 10 | \item{uniprot_id_list}{A list of protein UniProt IDs} 11 | 12 | \item{mode}{If \code{mode = "table"}, returns a data frame 13 | (a \href{https://tibble.tidyverse.org/}{\code{tibble}} as per 14 | \href{https://style.tidyverse.org/}{\code{tidyverse}} convention). 15 | If \code{mode = "raw"}, returns a raw response from EpiGraphDB API 16 | with minimal parsing done by \href{https://httr.r-lib.org/}{\code{httr}}.} 17 | } 18 | \value{ 19 | Data from \verb{POST /protein/in-pathway} 20 | } 21 | \description{ 22 | \href{https://docs.epigraphdb.org/api/api-endpoints/#post-proteinin-pathway}{\verb{POST /protein/in-pathway}} 23 | } 24 | \examples{ 25 | \dontrun{ 26 | protein_in_pathway(uniprot_id_list = c("014933", "060674", "P32455")) 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /man/query_epigraphdb.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/request_and_response.R 3 | \name{query_epigraphdb} 4 | \alias{query_epigraphdb} 5 | \title{Send data request to an EpiGraphDB API endpoint} 6 | \usage{ 7 | query_epigraphdb( 8 | route, 9 | params = NULL, 10 | mode = c("raw", "table"), 11 | method = c("GET", "POST"), 12 | retry_times = 3, 13 | retry_pause_min = 1 14 | ) 15 | } 16 | \arguments{ 17 | \item{route}{An EpiGraphDB API endpoint route, e.g. \code{"/mr"} or \code{"/confounder"}. 18 | Consult the \href{https://api.epigraphdb.org}{EpiGraphDB API documentation}.} 19 | 20 | \item{params}{A list of parameters associated with the query endpoint.} 21 | 22 | \item{mode}{\code{c("raw", "table")}, if \code{"table"} then the query handler will try 23 | to convert the returned data to a tibble dataframe. 24 | NOTE: The default mode is "raw" which will NOT convert the returned response to 25 | a dataframe. 26 | This is different to functions that query topic endpoints which 27 | default to return a dataframe. 28 | Explicitly specify \code{mode = "table"} when needed.} 29 | 30 | \item{method}{Type of HTTP (GET, POST, PUT, etc.) method. 31 | 32 | NOTE: When sending a POST request where a specific parameter is specified as a list on the API, 33 | and if the equivalent in R is a vector of length 1, you should wrap this parameter 34 | in \code{I()}, e.g. I(c("APOE")) to avoid auto unboxing. 35 | For details, please refer to \href{https://httr.r-lib.org/reference/POST.html}{\code{httr::POST}}} 36 | 37 | \item{retry_times}{Number of times the function will retry the request to the API.} 38 | 39 | \item{retry_pause_min}{Minimum number of seconds to wait for the next retry.} 40 | } 41 | \value{ 42 | Data from an EpiGraphDB API endpoint. 43 | } 44 | \description{ 45 | This is a general purpose function to send data request 46 | which can be used when there has not been an R equivalent package function 47 | to an API endpoint. 48 | Underneath this is a wrapper around \code{httr} functions with better handling of 49 | returned status. 50 | } 51 | \examples{ 52 | # GET /mr 53 | # equivalent to `mr(exposure_trait = "Body mass index", outcome_trait = "Coronary heart disease")` 54 | \dontrun{ 55 | query_epigraphdb( 56 | route = "/mr", 57 | params = list( 58 | exposure_trait = "Body mass index", 59 | outcome_trait = "Coronary heart disease" 60 | ), 61 | mode = "table" 62 | ) 63 | } 64 | 65 | # GET /meta/nodes/Gwas/list 66 | \dontrun{ 67 | query_epigraphdb( 68 | route = "/meta/nodes/Gwas/list", 69 | params = list( 70 | limit = 5, 71 | offset = 0 72 | ) 73 | ) \%>\% str(1) 74 | } 75 | 76 | # POST /protein/ppi 77 | \dontrun{ 78 | query_epigraphdb( 79 | route = "/protein/ppi", 80 | params = list( 81 | uniprot_id_list = c("P30793", "Q9NZM1", "O95236") 82 | ), 83 | method = "POST" 84 | ) 85 | } 86 | 87 | # error handling 88 | \dontrun{ 89 | tryCatch( 90 | query_epigraphdb( 91 | route = "/mr", 92 | params = list( 93 | exposure_trait = NULL, 94 | outcome_trait = NULL 95 | ), 96 | retry_times = 0 97 | ), 98 | error = function(e) { 99 | message(e) 100 | } 101 | ) 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /man/stop_for_status.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/request_and_response.R 3 | \name{stop_for_status} 4 | \alias{stop_for_status} 5 | \title{Catch error for an HTTP response} 6 | \usage{ 7 | stop_for_status(response, context) 8 | } 9 | \arguments{ 10 | \item{response}{An httr response} 11 | 12 | \item{context}{A list on the url and params for the request} 13 | } 14 | \description{ 15 | Modifies from httr::stop_for_status 16 | } 17 | \keyword{internal} 18 | -------------------------------------------------------------------------------- /man/xqtl_multi_snp_mr.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/xqtl.R 3 | \name{xqtl_multi_snp_mr} 4 | \alias{xqtl_multi_snp_mr} 5 | \title{Multi SNP QTL MR evidence} 6 | \usage{ 7 | xqtl_multi_snp_mr( 8 | exposure_gene = NULL, 9 | outcome_trait = NULL, 10 | mr_method = c("IVW", "Egger"), 11 | qtl_type = c("eQTL", "pQTL"), 12 | pval_threshold = 1e-05, 13 | mode = c("table", "raw") 14 | ) 15 | } 16 | \arguments{ 17 | \item{exposure_gene}{Name of the exposure gene} 18 | 19 | \item{outcome_trait}{Name of the outcome trait} 20 | 21 | \item{mr_method}{"IVW" or "Egger"} 22 | 23 | \item{qtl_type}{"eQTL" or "pQTL"} 24 | 25 | \item{pval_threshold}{P-value threshold} 26 | 27 | \item{mode}{If \code{mode = "table"}, returns a data frame 28 | (a \href{https://tibble.tidyverse.org/}{\code{tibble}} as per 29 | \href{https://style.tidyverse.org/}{\code{tidyverse}} convention). 30 | If \code{mode = "raw"}, returns a raw response from EpiGraphDB API 31 | with minimal parsing done by \href{https://httr.r-lib.org/}{\code{httr}}.} 32 | } 33 | \value{ 34 | Data from \code{GET /xqtl/multi-snp-mr} 35 | } 36 | \description{ 37 | \href{https://docs.epigraphdb.org/api/api-endpoints/#get-xqtlmulti-snp-mr}{\code{GET /xqtl/multi-snp-mr}} 38 | } 39 | \examples{ 40 | \dontrun{ 41 | xqtl_multi_snp_mr(outcome_trait = "Coronary heart disease") 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /man/xqtl_single_snp_mr.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/xqtl.R 3 | \name{xqtl_single_snp_mr} 4 | \alias{xqtl_single_snp_mr} 5 | \title{Single SNP QTL MR evidence} 6 | \usage{ 7 | xqtl_single_snp_mr( 8 | exposure_gene = NULL, 9 | outcome_trait = NULL, 10 | snp = NULL, 11 | qtl_type = c("eQTL", "pQTL"), 12 | pval_threshold = 1e-05, 13 | mode = c("table", "raw") 14 | ) 15 | } 16 | \arguments{ 17 | \item{exposure_gene}{Name of the exposure gene} 18 | 19 | \item{outcome_trait}{Name of the outcome trait} 20 | 21 | \item{snp}{SNP rsid} 22 | 23 | \item{qtl_type}{"eQTL" or "pQTL"} 24 | 25 | \item{pval_threshold}{P-value threshold} 26 | 27 | \item{mode}{If \code{mode = "table"}, returns a data frame 28 | (a \href{https://tibble.tidyverse.org/}{\code{tibble}} as per 29 | \href{https://style.tidyverse.org/}{\code{tidyverse}} convention). 30 | If \code{mode = "raw"}, returns a raw response from EpiGraphDB API 31 | with minimal parsing done by \href{https://httr.r-lib.org/}{\code{httr}}.} 32 | } 33 | \value{ 34 | Data from \code{GEET /xqtl/single-snp-mr} 35 | } 36 | \description{ 37 | \href{https://docs.epigraphdb.org/api/api-endpoints/#get-xqtlsingle-snp-mr}{\code{GET /xqtl/single-snp-mr}} 38 | } 39 | \examples{ 40 | \dontrun{ 41 | xqtl_single_snp_mr(outcome_trait = "Coronary heart disease") 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /pkg-build/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MRCIEU/epigraphdb-r/1cd05d8426a8e9f65160374ab3f631793ac3f742/pkg-build/.gitkeep -------------------------------------------------------------------------------- /pkgdown/extra.css: -------------------------------------------------------------------------------- 1 | pre, 2 | code { 3 | height: auto; 4 | max-height: 600px; 5 | } 6 | -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon-120x120.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MRCIEU/epigraphdb-r/1cd05d8426a8e9f65160374ab3f631793ac3f742/pkgdown/favicon/apple-touch-icon-120x120.png -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon-152x152.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MRCIEU/epigraphdb-r/1cd05d8426a8e9f65160374ab3f631793ac3f742/pkgdown/favicon/apple-touch-icon-152x152.png -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon-180x180.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MRCIEU/epigraphdb-r/1cd05d8426a8e9f65160374ab3f631793ac3f742/pkgdown/favicon/apple-touch-icon-180x180.png -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon-60x60.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MRCIEU/epigraphdb-r/1cd05d8426a8e9f65160374ab3f631793ac3f742/pkgdown/favicon/apple-touch-icon-60x60.png -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon-76x76.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MRCIEU/epigraphdb-r/1cd05d8426a8e9f65160374ab3f631793ac3f742/pkgdown/favicon/apple-touch-icon-76x76.png -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MRCIEU/epigraphdb-r/1cd05d8426a8e9f65160374ab3f631793ac3f742/pkgdown/favicon/apple-touch-icon.png -------------------------------------------------------------------------------- /pkgdown/favicon/favicon-16x16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MRCIEU/epigraphdb-r/1cd05d8426a8e9f65160374ab3f631793ac3f742/pkgdown/favicon/favicon-16x16.png -------------------------------------------------------------------------------- /pkgdown/favicon/favicon-32x32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MRCIEU/epigraphdb-r/1cd05d8426a8e9f65160374ab3f631793ac3f742/pkgdown/favicon/favicon-32x32.png -------------------------------------------------------------------------------- /pkgdown/favicon/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MRCIEU/epigraphdb-r/1cd05d8426a8e9f65160374ab3f631793ac3f742/pkgdown/favicon/favicon.ico -------------------------------------------------------------------------------- /scripts/precompute.R: -------------------------------------------------------------------------------- 1 | pwd <- getwd() 2 | 3 | setwd("vignettes") 4 | 5 | vignette_files <- c( 6 | "about.Rmd", 7 | "getting-started-with-epigraphdb-r.Rmd", 8 | "meta-functionalities.Rmd", 9 | "options.Rmd", 10 | "using-epigraphdb-api.Rmd", 11 | "using-epigraphdb-r-package.Rmd" 12 | ) 13 | 14 | for (file in vignette_files) { 15 | cat(glue::glue("Building {file}\n")) 16 | knitr::knit(glue::glue("../vignettes_src/{file}"), glue::glue("{file}")) 17 | } 18 | 19 | setwd(pwd) 20 | -------------------------------------------------------------------------------- /tests/spelling.R: -------------------------------------------------------------------------------- 1 | if (requireNamespace("spelling", quietly = TRUE)) { 2 | spelling::spell_check_test( 3 | vignettes = TRUE, error = FALSE, 4 | skip_on_cran = TRUE 5 | ) 6 | } 7 | -------------------------------------------------------------------------------- /tests/testthat.R: -------------------------------------------------------------------------------- 1 | library(testthat) 2 | 3 | options(epigraphdb.ci = TRUE) 4 | test_check("epigraphdb") 5 | -------------------------------------------------------------------------------- /tests/testthat/test-confounder.R: -------------------------------------------------------------------------------- 1 | context("confounder") 2 | 3 | test_that("/confounder", { 4 | skip_on_cran() 5 | url <- getOption("epigraphdb.api.url") 6 | exposure <- "Body mass index" 7 | outcome <- "Coronary heart disease" 8 | r <- httr::RETRY("GET", glue::glue("{url}/confounder"), 9 | query = list( 10 | exposure_trait = exposure, 11 | outcome_trait = outcome 12 | ), 13 | config = httr::add_headers(.headers = c("client-type" = "R", "ci" = "true")) 14 | ) 15 | expect_equal(httr::status_code(r), 200) 16 | expect_true(length(httr::content(r)) > 0) 17 | }) 18 | 19 | test_that("confounder", { 20 | skip_on_cran() 21 | exposure <- "Body mass index" 22 | outcome <- "Coronary heart disease" 23 | expect_error( 24 | confounder( 25 | exposure_trait = exposure, 26 | outcome_trait = outcome 27 | ), 28 | NA 29 | ) 30 | }) 31 | -------------------------------------------------------------------------------- /tests/testthat/test-cypher.R: -------------------------------------------------------------------------------- 1 | context("cypher") 2 | 3 | test_that("POST /cypher", { 4 | skip_on_cran() 5 | url <- getOption("epigraphdb.api.url") 6 | route <- "/cypher" 7 | query <- "MATCH (n:Gwas) RETURN n LIMIT 2" 8 | body <- jsonlite::toJSON(list(query = query), auto_unbox = TRUE) 9 | r <- httr::RETRY( 10 | "POST", 11 | glue::glue("{url}{route}"), 12 | body = body, 13 | encode = "json", 14 | config = httr::add_headers(.headers = c("client-type" = "R", "ci" = "true")) 15 | ) 16 | expect_equal(httr::status_code(r), 200) 17 | expect_true(length(httr::content(r)) > 0) 18 | }) 19 | 20 | test_that("cypher", { 21 | skip_on_cran() 22 | query <- "MATCH (n:Gwas) RETURN n LIMIT 2" 23 | expect_error( 24 | cypher(query = query), 25 | NA 26 | ) 27 | }) 28 | -------------------------------------------------------------------------------- /tests/testthat/test-drugs.R: -------------------------------------------------------------------------------- 1 | context("drugs") 2 | 3 | test_that("/drugs/risk-factors", { 4 | skip_on_cran() 5 | url <- getOption("epigraphdb.api.url") 6 | trait <- "Body mass index" 7 | r <- httr::RETRY("GET", glue::glue("{url}/drugs/risk-factors"), 8 | query = list( 9 | trait = trait 10 | ), 11 | config = httr::add_headers(.headers = c("client-type" = "R", "ci" = "true")) 12 | ) 13 | expect_equal(httr::status_code(r), 200) 14 | expect_true(length(httr::content(r)) > 0) 15 | }) 16 | 17 | test_that("drugs_risk_factors", { 18 | skip_on_cran() 19 | trait <- "Body mass index" 20 | expect_error( 21 | drugs_risk_factors( 22 | trait = trait 23 | ), 24 | NA 25 | ) 26 | }) 27 | -------------------------------------------------------------------------------- /tests/testthat/test-error-grace.R: -------------------------------------------------------------------------------- 1 | context("request_and_response") 2 | 3 | test_that("Give informative error message when server error", { 4 | skip_on_cran() 5 | inform_status <- function(url) { 6 | params <- list(param_a = "a", param_b = "b") 7 | response <- httr::RETRY( 8 | "GET", 9 | url = url, query = params, 10 | times = 2, pause_min = 0.5 11 | ) 12 | stop_for_status(response, context = list(url = url, params = params)) 13 | response 14 | } 15 | url <- "http://httpbin.org/status/500" 16 | expect_error( 17 | inform_status(url), 18 | "500" 19 | ) 20 | }) 21 | -------------------------------------------------------------------------------- /tests/testthat/test-genetic_cor.R: -------------------------------------------------------------------------------- 1 | context("genetic_cor") 2 | 3 | test_that("genetic_cor endpoint", { 4 | skip_on_cran() 5 | url <- getOption("epigraphdb.api.url") 6 | trait <- "body mass index" 7 | r <- httr::RETRY("GET", glue::glue("{url}/genetic-cor"), 8 | query = list( 9 | trait = trait 10 | ), 11 | config = httr::add_headers(.headers = c("client-type" = "R", "ci" = "true")) 12 | ) 13 | expect_equal(httr::status_code(r), 200) 14 | expect_true(length(httr::content(r)) > 0) 15 | }) 16 | 17 | test_that("genetic_cor mode = \"table\"", { 18 | skip_on_cran() 19 | trait <- "body mass index" 20 | expect_error( 21 | df <- genetic_cor( 22 | trait = trait 23 | ), 24 | NA 25 | ) 26 | expect_is(df, "tbl_df") 27 | }) 28 | 29 | test_that("genetic_cor mode = \"raw\"", { 30 | skip_on_cran() 31 | trait <- "body mass index" 32 | expect_error( 33 | response <- genetic_cor( 34 | trait = trait, 35 | mode = "raw" 36 | ), 37 | NA 38 | ) 39 | expect_equal(length(response), 2L) 40 | }) 41 | 42 | test_that("genetic_cor cor_coef_threshold", { 43 | skip_on_cran() 44 | trait <- "Body mass index" 45 | expect_error( 46 | response <- genetic_cor( 47 | trait = trait, 48 | cor_coef_threshold = 0.8 49 | ), 50 | NA 51 | ) 52 | expect_error( 53 | response <- genetic_cor( 54 | trait = trait, 55 | cor_coef_threshold = 0.6 56 | ), 57 | NA 58 | ) 59 | expect_error( 60 | response <- genetic_cor( 61 | trait = trait, 62 | cor_coef_threshold = 0.4 63 | ), 64 | NA 65 | ) 66 | }) 67 | -------------------------------------------------------------------------------- /tests/testthat/test-literature.R: -------------------------------------------------------------------------------- 1 | context("literature") 2 | 3 | test_that("/literature/gwas", { 4 | skip_on_cran() 5 | url <- getOption("epigraphdb.api.url") 6 | trait <- "Body mass index" 7 | semmed_predicate <- NULL 8 | r <- httr::RETRY("GET", glue::glue("{url}/literature/gwas"), 9 | query = list( 10 | trait = trait, 11 | semmed_predicate = semmed_predicate 12 | ), 13 | config = httr::add_headers(.headers = c("client-type" = "R", "ci" = "true")) 14 | ) 15 | expect_equal(httr::status_code(r), 200) 16 | expect_true(length(httr::content(r)) > 0) 17 | }) 18 | 19 | test_that("literature_gwas", { 20 | skip_on_cran() 21 | trait <- "Body mass index" 22 | expect_error( 23 | literature_gwas( 24 | trait = trait 25 | ), 26 | NA 27 | ) 28 | }) 29 | -------------------------------------------------------------------------------- /tests/testthat/test-mappings.R: -------------------------------------------------------------------------------- 1 | context("protein") 2 | 3 | test_that("POST /mappings/gene-to-protein", { 4 | skip_on_cran() 5 | url <- getOption("epigraphdb.api.url") 6 | gene_name_list <- c("GCH1", "MYOF") 7 | params <- list( 8 | gene_name_list = I(gene_name_list) 9 | ) 10 | r <- httr::RETRY( 11 | "POST", 12 | glue::glue("{url}/mappings/gene-to-protein"), 13 | body = jsonlite::toJSON(params, auto_unbox = TRUE), 14 | encode = "json", 15 | config = httr::add_headers(.headers = c("client-type" = "R", "ci" = "true")) 16 | ) 17 | expect_equal(httr::status_code(r), 200) 18 | expect_true(length(httr::content(r)) > 0) 19 | }) 20 | 21 | test_that("mappings_gene_to_protein, by gene name", { 22 | skip_on_cran() 23 | gene_name_list <- c("GCH1", "MYOF") 24 | expect_error( 25 | df <- mappings_gene_to_protein( 26 | gene_name_list = gene_name_list 27 | ), 28 | NA 29 | ) 30 | expect_is(df, "tbl_df") 31 | }) 32 | 33 | test_that("mappings_gene_to_protein, by gene name, singleton", { 34 | skip_on_cran() 35 | gene_name_list <- c("GCH1") 36 | expect_error( 37 | df <- mappings_gene_to_protein( 38 | gene_name_list = gene_name_list 39 | ), 40 | NA 41 | ) 42 | expect_is(df, "tbl_df") 43 | }) 44 | 45 | test_that("mappings_gene_to_protein, by gene id", { 46 | skip_on_cran() 47 | gene_id_list <- c("ENSG00000162594", "ENSG00000113302") 48 | expect_error( 49 | df <- mappings_gene_to_protein( 50 | gene_id_list = gene_id_list, 51 | by_gene_id = TRUE 52 | ), 53 | NA 54 | ) 55 | expect_is(df, "tbl_df") 56 | }) 57 | 58 | test_that("mappings_gene_to_protein, by gene id, singleton", { 59 | skip_on_cran() 60 | gene_id_list <- c("ENSG00000162594") 61 | expect_error( 62 | df <- mappings_gene_to_protein( 63 | gene_id_list = gene_id_list, 64 | by_gene_id = TRUE 65 | ), 66 | NA 67 | ) 68 | expect_is(df, "tbl_df") 69 | }) 70 | 71 | test_that("mappings_gene_to_protein, error handling", { 72 | skip_on_cran() 73 | gene_id_list <- c("ENSG00000162594") 74 | expect_error( 75 | df <- mappings_gene_to_protein( 76 | gene_id_list = gene_id_list, 77 | by_gene_id = FALSE 78 | ) 79 | ) 80 | }) 81 | -------------------------------------------------------------------------------- /tests/testthat/test-meta.R: -------------------------------------------------------------------------------- 1 | context("meta") 2 | 3 | test_that("GET /meta/nodes/list", { 4 | skip_on_cran() 5 | url <- getOption("epigraphdb.api.url") 6 | route <- "/meta/nodes/list" 7 | r <- httr::RETRY("GET", 8 | url = glue::glue("{url}{route}"), 9 | config = httr::add_headers(.headers = c("client-type" = "R", "ci" = "true")) 10 | ) 11 | expect_equal(httr::status_code(r), 200) 12 | expect_true(length(httr::content(r)) > 0) 13 | }) 14 | 15 | test_that("GET /meta/rels/list", { 16 | skip_on_cran() 17 | url <- getOption("epigraphdb.api.url") 18 | route <- "/meta/rels/list" 19 | r <- httr::RETRY("GET", 20 | url = glue::glue("{url}{route}"), 21 | config = httr::add_headers(.headers = c("client-type" = "R", "ci" = "true")) 22 | ) 23 | expect_equal(httr::status_code(r), 200) 24 | expect_true(length(httr::content(r)) > 0) 25 | }) 26 | 27 | test_that("meta_nodes_list", { 28 | skip_on_cran() 29 | expect_error( 30 | meta_nodes_list(), 31 | NA 32 | ) 33 | }) 34 | 35 | test_that("meta_rels_list", { 36 | skip_on_cran() 37 | expect_error( 38 | meta_rels_list(), 39 | NA 40 | ) 41 | }) 42 | 43 | test_that("meta_nodes_list_node", { 44 | skip_on_cran() 45 | meta_node <- "Gwas" 46 | expect_error( 47 | meta_nodes_list_node( 48 | meta_node = meta_node 49 | ), 50 | NA 51 | ) 52 | }) 53 | 54 | test_that("meta_rels_list_rel", { 55 | skip_on_cran() 56 | meta_rel <- "MR_EVE_MR" 57 | expect_error( 58 | meta_rels_list_rel( 59 | meta_rel = meta_rel 60 | ), 61 | NA 62 | ) 63 | }) 64 | 65 | test_that("meta_nodes_search_node, by id", { 66 | skip_on_cran() 67 | meta_node <- "Gwas" 68 | id <- "ieu-a-2" 69 | expect_error( 70 | meta_nodes_search_node( 71 | meta_node = meta_node, 72 | id = id 73 | ), 74 | NA 75 | ) 76 | }) 77 | 78 | test_that("meta_nodes_search_node, by name", { 79 | skip_on_cran() 80 | meta_node <- "Gwas" 81 | name <- "Body mass index" 82 | expect_error( 83 | meta_nodes_search_node( 84 | meta_node = meta_node, 85 | name = name 86 | ), 87 | NA 88 | ) 89 | }) 90 | -------------------------------------------------------------------------------- /tests/testthat/test-mr.R: -------------------------------------------------------------------------------- 1 | context("mr") 2 | 3 | test_that("mr endpoint", { 4 | skip_on_cran() 5 | url <- getOption("epigraphdb.api.url") 6 | exposure <- "Body mass index" 7 | outcome <- "Coronary heart disease" 8 | r <- httr::RETRY("GET", glue::glue("{url}/mr"), 9 | query = list( 10 | exposure_trait = exposure, 11 | outcome_trait = outcome 12 | ), 13 | config = httr::add_headers(.headers = c("client-type" = "R", "ci" = "true")) 14 | ) 15 | expect_equal(httr::status_code(r), 200) 16 | expect_true(length(httr::content(r)) > 0) 17 | }) 18 | 19 | test_that("mr mode = \"table\"", { 20 | skip_on_cran() 21 | exposure <- "Body mass index" 22 | outcome <- "Coronary heart disease" 23 | expect_error( 24 | df <- mr( 25 | exposure_trait = exposure, 26 | outcome_trait = outcome 27 | ), 28 | NA 29 | ) 30 | expect_is(df, "tbl_df") 31 | }) 32 | 33 | test_that("mr mode = \"raw\"", { 34 | skip_on_cran() 35 | exposure <- "Body mass index" 36 | outcome <- "Coronary heart disease" 37 | expect_error( 38 | response <- mr( 39 | exposure_trait = exposure, 40 | outcome_trait = outcome, 41 | mode = "raw" 42 | ), 43 | NA 44 | ) 45 | expect_equal(length(response), 2L) 46 | }) 47 | 48 | test_that("mr parameters", { 49 | skip_on_cran() 50 | exposure <- "Body mass index" 51 | outcome <- "Coronary heart disease" 52 | expect_error( 53 | mr( 54 | exposure_trait = exposure, 55 | outcome_trait = NULL 56 | ), 57 | NA 58 | ) 59 | expect_error( 60 | mr( 61 | exposure_trait = NULL, 62 | outcome_trait = outcome 63 | ), 64 | NA 65 | ) 66 | expect_error( 67 | mr( 68 | exposure_trait = NULL, 69 | outcome_trait = NULL 70 | ) 71 | ) 72 | }) 73 | 74 | test_that("mr pval_threshold", { 75 | skip_on_cran() 76 | exposure <- "Body mass index" 77 | expect_error( 78 | response <- mr( 79 | exposure_trait = exposure, 80 | pval_threshold = 1e-5 81 | ), 82 | NA 83 | ) 84 | expect_error( 85 | response <- mr( 86 | exposure_trait = exposure, 87 | pval_threshold = 1e-8 88 | ), 89 | NA 90 | ) 91 | expect_error( 92 | response <- mr( 93 | exposure_trait = exposure, 94 | pval_threshold = 1e-2 95 | ), 96 | NA 97 | ) 98 | }) 99 | -------------------------------------------------------------------------------- /tests/testthat/test-obs_cor.R: -------------------------------------------------------------------------------- 1 | context("obs_cor") 2 | 3 | test_that("obs_cor endpoint", { 4 | skip_on_cran() 5 | url <- getOption("epigraphdb.api.url") 6 | trait <- "body mass index" 7 | r <- httr::RETRY("GET", glue::glue("{url}/obs-cor"), 8 | query = list( 9 | trait = trait 10 | ), 11 | config = httr::add_headers(.headers = c("client-type" = "R", "ci" = "true")) 12 | ) 13 | expect_equal(httr::status_code(r), 200) 14 | expect_true(length(httr::content(r)) > 0) 15 | }) 16 | 17 | test_that("obs_cor mode = \"table\"", { 18 | skip_on_cran() 19 | trait <- "body mass index" 20 | expect_error( 21 | df <- obs_cor( 22 | trait = trait 23 | ), 24 | NA 25 | ) 26 | expect_is(df, "tbl_df") 27 | }) 28 | 29 | test_that("obs_cor mode = \"raw\"", { 30 | skip_on_cran() 31 | trait <- "body mass index" 32 | expect_error( 33 | response <- obs_cor( 34 | trait = trait, 35 | mode = "raw" 36 | ), 37 | NA 38 | ) 39 | expect_equal(length(response), 2L) 40 | }) 41 | 42 | test_that("obs_cor cor_coef_threshold", { 43 | skip_on_cran() 44 | trait <- "Body mass index" 45 | expect_error( 46 | response <- obs_cor( 47 | trait = trait, 48 | cor_coef_threshold = 0.8 49 | ), 50 | NA 51 | ) 52 | expect_error( 53 | response <- obs_cor( 54 | trait = trait, 55 | cor_coef_threshold = 0.6 56 | ), 57 | NA 58 | ) 59 | expect_error( 60 | response <- obs_cor( 61 | trait = trait, 62 | cor_coef_threshold = 0.4 63 | ), 64 | NA 65 | ) 66 | }) 67 | -------------------------------------------------------------------------------- /tests/testthat/test-ontology.R: -------------------------------------------------------------------------------- 1 | context("ontology") 2 | 3 | test_that("ontology endpoint", { 4 | skip_on_cran() 5 | url <- getOption("epigraphdb.api.url") 6 | efo_term <- "blood pressure" 7 | r <- httr::RETRY("GET", glue::glue("{url}/ontology/gwas-efo"), 8 | query = list( 9 | efo_term = efo_term 10 | ), 11 | config = httr::add_headers(.headers = c("client-type" = "R", "ci" = "true")) 12 | ) 13 | expect_equal(httr::status_code(r), 200) 14 | expect_true(length(httr::content(r)) > 0) 15 | }) 16 | 17 | test_that("ontology mode = \"table\"", { 18 | skip_on_cran() 19 | efo_term <- "blood pressure" 20 | expect_error( 21 | df <- ontology_gwas_efo( 22 | efo_term = efo_term 23 | ), 24 | NA 25 | ) 26 | expect_is(df, "tbl_df") 27 | }) 28 | 29 | test_that("mr mode = \"raw\"", { 30 | skip_on_cran() 31 | efo_term <- "blood pressure" 32 | expect_error( 33 | response <- ontology_gwas_efo( 34 | efo_term = efo_term, 35 | mode = "raw" 36 | ), 37 | NA 38 | ) 39 | expect_equal(length(response), 2L) 40 | }) 41 | -------------------------------------------------------------------------------- /tests/testthat/test-pathway.R: -------------------------------------------------------------------------------- 1 | context("pathway") 2 | 3 | test_that("/pathway", { 4 | skip_on_cran() 5 | url <- getOption("epigraphdb.api.url") 6 | trait <- "Body mass index" 7 | r <- httr::RETRY("GET", glue::glue("{url}/pathway"), 8 | query = list( 9 | trait = trait 10 | ), 11 | config = httr::add_headers(.headers = c("client-type" = "R", "ci" = "true")) 12 | ) 13 | expect_equal(httr::status_code(r), 200) 14 | expect_true(length(httr::content(r)) > 0) 15 | }) 16 | 17 | test_that("pathway", { 18 | skip_on_cran() 19 | trait <- "Body mass index" 20 | expect_error( 21 | pathway( 22 | trait = trait 23 | ), 24 | NA 25 | ) 26 | }) 27 | -------------------------------------------------------------------------------- /tests/testthat/test-pqtl.R: -------------------------------------------------------------------------------- 1 | context("pqtl") 2 | 3 | test_that("pqtl protein endpoint", { 4 | skip_on_cran() 5 | url <- getOption("epigraphdb.api.url") 6 | query <- "ADAM19" 7 | rtype <- "mrres" 8 | pvalue <- 0.05 9 | searchflag <- "proteins" 10 | r <- httr::RETRY("GET", glue::glue("{url}/pqtl/"), 11 | query = list( 12 | query = query, 13 | rtype = rtype, 14 | pvalue = pvalue, 15 | searchflag = searchflag 16 | ), 17 | config = httr::add_headers(.headers = c("client-type" = "R", "ci" = "true")) 18 | ) 19 | expect_equal(httr::status_code(r), 200) 20 | expect_true(length(httr::content(r)) > 0) 21 | }) 22 | 23 | test_that("pqtl trait endpoint", { 24 | skip_on_cran() 25 | url <- getOption("epigraphdb.api.url") 26 | query <- "Inflammatory bowel disease" 27 | rtype <- "mrres" 28 | pvalue <- 0.05 29 | searchflag <- "traits" 30 | r <- httr::RETRY("GET", glue::glue("{url}/pqtl/"), 31 | query = list( 32 | query = query, 33 | rtype = rtype, 34 | pvalue = pvalue, 35 | searchflag = searchflag 36 | ), 37 | config = httr::add_headers(.headers = c("client-type" = "R", "ci" = "true")) 38 | ) 39 | expect_equal(httr::status_code(r), 200) 40 | }) 41 | 42 | test_that("pqtl_pleio endpoint", { 43 | skip_on_cran() 44 | url <- getOption("epigraphdb.api.url") 45 | rsid <- "rs1260326" 46 | prflag <- "proteins" 47 | r <- httr::RETRY("GET", glue::glue("{url}/pqtl/pleio/"), 48 | query = list( 49 | rsid = rsid, 50 | prflag = prflag 51 | ), 52 | config = httr::add_headers(.headers = c("client-type" = "R", "ci" = "true")) 53 | ) 54 | expect_equal(httr::status_code(r), 200) 55 | }) 56 | 57 | test_that("pqtl_list endpoint", { 58 | skip_on_cran() 59 | url <- getOption("epigraphdb.api.url") 60 | flag <- "exposures" 61 | r <- httr::RETRY("GET", glue::glue("{url}/pqtl/list/"), 62 | query = list( 63 | flag = flag 64 | ), 65 | config = httr::add_headers(.headers = c("client-type" = "R", "ci" = "true")) 66 | ) 67 | expect_equal(httr::status_code(r), 200) 68 | }) 69 | 70 | test_that("pqtl correct input", { 71 | skip_on_cran() 72 | query <- "Inflammatory bowel disease" 73 | rtype <- "mrres" 74 | pvalue <- 0.05 75 | searchflag <- "traits" 76 | r <- pqtl( 77 | query = query, 78 | rtype = rtype, 79 | pvalue = pvalue, 80 | searchflag = searchflag, 81 | mode = "table" 82 | ) 83 | expect_is(r, "tbl_df") 84 | expect_true(dim(r)[1] > 0) 85 | }) 86 | 87 | test_that("pqtl incorrect input", { 88 | skip_on_cran() 89 | query <- "Inflammatory bowel disease" 90 | rtype <- "mrress" 91 | pvalue <- 0.05 92 | searchflag <- "traits" 93 | expect_error( 94 | r <- pqtl( 95 | query = query, 96 | rtype = rtype, 97 | pvalue = pvalue, 98 | searchflag = searchflag 99 | ) 100 | ) 101 | }) 102 | 103 | test_that("pqtl not found input", { 104 | skip_on_cran() 105 | query <- "ADAM199999" 106 | rtype <- "mrres" 107 | pvalue <- 0.05 108 | searchflag <- "proteins" 109 | r <- pqtl( 110 | query = query, 111 | rtype = rtype, 112 | pvalue = pvalue, 113 | searchflag = searchflag 114 | ) 115 | expect_equal(dim(r), c(0, 0)) 116 | }) 117 | 118 | test_that("pqtl_pleio correct input for a list of proteins", { 119 | skip_on_cran() 120 | rsid <- "rs1260326" 121 | prflag <- "proteins" 122 | r <- pqtl_pleio( 123 | rsid = rsid, 124 | prflag = prflag 125 | ) 126 | expect_true(dim(r)[1] > 0) 127 | }) 128 | 129 | test_that("pqtl_pleio correct input for a count", { 130 | skip_on_cran() 131 | rsid <- "rs1260326" 132 | prflag <- "count" 133 | r <- pqtl_pleio( 134 | rsid = rsid, 135 | prflag = prflag 136 | ) 137 | expect_equal(r, 3) 138 | }) 139 | 140 | test_that("pqtl_pleio incorrect input", { 141 | skip_on_cran() 142 | rsid <- "rs1260326" 143 | prflag <- "countt" 144 | expect_error( 145 | r <- pqtl_pleio( 146 | rsid = rsid, 147 | prflag = prflag 148 | ) 149 | ) 150 | }) 151 | 152 | test_that("pqtl_pleio not found input", { 153 | skip_on_cran() 154 | rsid <- "rs1260326gggg" 155 | prflag <- "proteins" 156 | r <- pqtl_pleio( 157 | rsid = rsid, 158 | prflag = prflag 159 | ) 160 | expect_equal(dim(r), c(0, 0)) 161 | }) 162 | 163 | test_that("pqtl_list raw", { 164 | skip_on_cran() 165 | flag <- "exposures" 166 | r <- pqtl_list( 167 | flag = flag, 168 | mode = "raw" 169 | ) 170 | expect_true(length(r) > 1) 171 | }) 172 | 173 | test_that("pqtl_list correct exposures input", { 174 | skip_on_cran() 175 | flag <- "exposures" 176 | r <- pqtl_list( 177 | flag = flag 178 | ) 179 | expect_is(r, "tbl_df") 180 | expect_true(dim(r)[1] > 0) 181 | }) 182 | 183 | test_that("pqtl_list correct outcomes input", { 184 | skip_on_cran() 185 | flag <- "outcomes" 186 | r <- pqtl_list( 187 | flag = flag 188 | ) 189 | expect_is(r, "tbl_df") 190 | expect_true(dim(r)[1] > 0) 191 | }) 192 | 193 | test_that("pqtl_list incorrect input", { 194 | skip_on_cran() 195 | flag <- "foobar" 196 | expect_error( 197 | r <- pqtl_list( 198 | flag = flag 199 | ) 200 | ) 201 | }) 202 | -------------------------------------------------------------------------------- /tests/testthat/test-protein.R: -------------------------------------------------------------------------------- 1 | context("protein") 2 | 3 | test_that("POST /protein/in-pathway", { 4 | skip_on_cran() 5 | url <- getOption("epigraphdb.api.url") 6 | uniprot_id_list <- c("014933", "060674", "P32455") 7 | params <- list( 8 | uniprot_id_list = uniprot_id_list 9 | ) 10 | r <- httr::RETRY( 11 | "POST", 12 | glue::glue("{url}/protein/in-pathway"), 13 | body = jsonlite::toJSON(params, auto_unbox = TRUE), 14 | encode = "json", 15 | config = httr::add_headers(.headers = c("client-type" = "R", "ci" = "true")) 16 | ) 17 | expect_equal(httr::status_code(r), 200) 18 | expect_true(length(httr::content(r)) > 0) 19 | }) 20 | 21 | test_that("protein_in_pathway", { 22 | skip_on_cran() 23 | uniprot_id_list <- c("014933", "060674", "P32455") 24 | expect_error( 25 | df <- protein_in_pathway( 26 | uniprot_id_list = uniprot_id_list 27 | ), 28 | NA 29 | ) 30 | expect_is(df, "tbl_df") 31 | }) 32 | 33 | test_that("protein_in_pathway, singleton", { 34 | skip_on_cran() 35 | uniprot_id_list <- c("014933") 36 | expect_error( 37 | df <- protein_in_pathway( 38 | uniprot_id_list = uniprot_id_list 39 | ), 40 | NA 41 | ) 42 | expect_is(df, "tbl_df") 43 | }) 44 | -------------------------------------------------------------------------------- /tests/testthat/test-request_and_response.R: -------------------------------------------------------------------------------- 1 | context("request_and_response") 2 | 3 | test_that("query_epigraphdb raw", { 4 | skip_on_cran() 5 | expect_error( 6 | results <- query_epigraphdb( 7 | route = "/meta/nodes/Gwas/list", 8 | params = list( 9 | limit = 5, 10 | offset = 0 11 | ) 12 | ), 13 | NA 14 | ) 15 | expect_equal(names(results), c("metadata", "results")) 16 | }) 17 | 18 | test_that("query_epigraphdb table", { 19 | skip_on_cran() 20 | expect_error( 21 | results <- query_epigraphdb( 22 | route = "/mr", 23 | params = list( 24 | exposure_trait = "Body mass index", 25 | outcome_trait = "Coronary heart disease" 26 | ), 27 | mode = "table" 28 | ), 29 | NA 30 | ) 31 | expect_is(results, "tbl_df") 32 | }) 33 | 34 | test_that("query_epigraphdb error handling", { 35 | skip_on_cran() 36 | expect_error( 37 | results <- query_epigraphdb( 38 | route = "/mr", 39 | params = list( 40 | exposure_trait = NULL, 41 | outcome_trait = NULL 42 | ) 43 | ) 44 | ) 45 | }) 46 | 47 | test_that("query_epigraphdb POST 1", { 48 | skip_on_cran() 49 | expect_error( 50 | results <- query_epigraphdb( 51 | route = "/protein/ppi", 52 | params = list( 53 | uniprot_id_list = c("P30793", "Q9NZM1", "O95236") 54 | ), 55 | method = "POST" 56 | ), 57 | NA 58 | ) 59 | expect_equal(names(results), c("metadata", "results")) 60 | }) 61 | 62 | test_that("query_epigraphdb POST 2", { 63 | skip_on_cran() 64 | expect_error( 65 | results <- query_epigraphdb( 66 | route = "/xqtl/single-snp-mr/gene-by-variant", 67 | params = list( 68 | qtl_type = "eQTL", 69 | variant_list = c( 70 | "rs7028268", "rs140244541", "rs4970834", 71 | "rs2904220", "rs34032254", "rs2184061", "rs7412", 72 | "rs11065979", "rs10774625", "rs4766578", "rs7568458", 73 | "rs10176176", "rs653178", "rs3184504", "rs3731827", 74 | "rs7310615", "rs10187424", "rs10774624", "rs17696736", 75 | "rs597808" 76 | ) 77 | ), 78 | method = "POST", 79 | mode = "table" 80 | ), 81 | NA 82 | ) 83 | expect_is(results, "tbl_df") 84 | }) 85 | -------------------------------------------------------------------------------- /tests/testthat/test-xqtl.R: -------------------------------------------------------------------------------- 1 | context("xqtl") 2 | 3 | test_that("/xqtl/multi-snp-mr", { 4 | skip_on_cran() 5 | url <- getOption("epigraphdb.api.url") 6 | outcome_trait <- "Coronary heart disease" 7 | r <- httr::RETRY("GET", glue::glue("{url}/xqtl/multi-snp-mr"), 8 | query = list( 9 | outcome_trait = outcome_trait 10 | ), 11 | config = httr::add_headers(.headers = c("client-type" = "R", "ci" = "true")) 12 | ) 13 | expect_equal(httr::status_code(r), 200) 14 | expect_true(length(httr::content(r)) > 0) 15 | }) 16 | 17 | test_that("/xqtl/single-snp-mr", { 18 | skip_on_cran() 19 | url <- getOption("epigraphdb.api.url") 20 | outcome_trait <- "Coronary heart disease" 21 | r <- httr::RETRY("GET", glue::glue("{url}/xqtl/single-snp-mr"), 22 | query = list( 23 | outcome_trait = outcome_trait 24 | ), 25 | config = httr::add_headers(.headers = c("client-type" = "R", "ci" = "true")) 26 | ) 27 | expect_equal(httr::status_code(r), 200) 28 | expect_true(length(httr::content(r)) > 0) 29 | }) 30 | 31 | test_that("xqtl_multi_snp_mr", { 32 | skip_on_cran() 33 | outcome_trait <- "Coronary heart disease" 34 | expect_error( 35 | xqtl_multi_snp_mr( 36 | outcome_trait = outcome_trait 37 | ), 38 | NA 39 | ) 40 | }) 41 | 42 | test_that("xqtl_single_snp_mr", { 43 | skip_on_cran() 44 | outcome_trait <- "Coronary heart disease" 45 | expect_error( 46 | xqtl_single_snp_mr( 47 | outcome_trait = outcome_trait 48 | ), 49 | NA 50 | ) 51 | }) 52 | -------------------------------------------------------------------------------- /vignettes/.gitignore: -------------------------------------------------------------------------------- 1 | *.html 2 | *.R 3 | -------------------------------------------------------------------------------- /vignettes/about.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "About" 3 | output: rmarkdown::html_vignette 4 | vignette: > 5 | %\VignetteIndexEntry{About} 6 | %\VignetteEngine{knitr::rmarkdown} 7 | %\VignetteEncoding{UTF-8} 8 | --- 9 | 10 | 11 | 12 | [EpiGraphDB](https://epigraphdb.org) is an analytical platform and database to support data mining in epidemiology. The platform incorporates a graph of causal estimates generated by systematically applying Mendelian randomization to a wide array of phenotypes, and augments this with a wealth of additional data from other bioinformatic sources. 13 | EpiGraphDB aims to support appropriate application and interpretation of causal inference in systematic automated analyses of many phenotypes. 14 | 15 | [`epigraphdb`](https://github.com/MRCIEU/epigraphdb-r) is an R package to provide ease of access to EpiGraphDB services. 16 | 17 | ## EpiGraphDB resources 18 | 19 | | link | screenshot | 20 | |-----------------------------------------------------|---------------------------------------------| 21 | | [docs](https://docs.epigraphdb.org) | ![docs](figures/epigraphdb-docs.png) | 22 | | [API](https://api.epigraphdb.org) | ![api](figures/epigraphdb-api-swagger.png) | 23 | | [web application](https://epigraphdb.org) | ![webapp](figures/epigraphdb-xqtl-view.png) | 24 | | [r package](https://github.com/MRCIEU/epigraphdb-r) | ![epigraphdb-r](figures/epigraphdb-r.png) | 25 | -------------------------------------------------------------------------------- /vignettes/figures/epigraphdb-api-swagger.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MRCIEU/epigraphdb-r/1cd05d8426a8e9f65160374ab3f631793ac3f742/vignettes/figures/epigraphdb-api-swagger.png -------------------------------------------------------------------------------- /vignettes/figures/epigraphdb-docs.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MRCIEU/epigraphdb-r/1cd05d8426a8e9f65160374ab3f631793ac3f742/vignettes/figures/epigraphdb-docs.png -------------------------------------------------------------------------------- /vignettes/figures/epigraphdb-home-view.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MRCIEU/epigraphdb-r/1cd05d8426a8e9f65160374ab3f631793ac3f742/vignettes/figures/epigraphdb-home-view.png -------------------------------------------------------------------------------- /vignettes/figures/epigraphdb-r.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MRCIEU/epigraphdb-r/1cd05d8426a8e9f65160374ab3f631793ac3f742/vignettes/figures/epigraphdb-r.png -------------------------------------------------------------------------------- /vignettes/figures/epigraphdb-xqtl-view.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MRCIEU/epigraphdb-r/1cd05d8426a8e9f65160374ab3f631793ac3f742/vignettes/figures/epigraphdb-xqtl-view.png -------------------------------------------------------------------------------- /vignettes/meta-functionalities.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Meta functionalities of the EpiGraphDB platform" 3 | output: rmarkdown::html_vignette 4 | vignette: > 5 | %\VignetteIndexEntry{Meta functionalities of the EpiGraphDB platform} 6 | %\VignetteEngine{knitr::rmarkdown} 7 | %\VignetteEncoding{UTF-8} 8 | --- 9 | 10 | 11 | 12 | This RMarkdown document demonstrates how key elements from the 13 | [github notebook for the meta functionalities]( 14 | https://github.com/MRCIEU/epigraphdb/blob/master/general-examples/platform-meta-functionalities.ipynb 15 | ) can be achieved using the R package. 16 | For detailed explanations of the case study please refer to the 17 | [notebook on github]( 18 | https://github.com/MRCIEU/epigraphdb/blob/master/general-examples/platform-meta-functionalities.ipynb 19 | ). 20 | 21 | Here we show the following aspects of the EpiGraphDB platform, and how to use the API to get the information: 22 | 23 | - Metadata: meta nodes and meta edges, and the overall schema. 24 | - Search for a specific node under the meta node. 25 | - Cypher: how to query the database directly using Neo4j Cypher 26 | 27 | For detailed documentation on the API endpoints please visit: 28 | 29 | - The Swagger interface: https://api.epigraphdb.org 30 | - The sections regarding API endpoints on the documentation site: 31 | https://docs.epigraphdb.org/api/api-endpoints/ 32 | 33 | 34 | ```r 35 | library("magrittr") 36 | library("dplyr") 37 | library("purrr") 38 | #> 39 | #> Attaching package: 'purrr' 40 | #> The following object is masked from 'package:magrittr': 41 | #> 42 | #> set_names 43 | library("igraph") 44 | #> 45 | #> Attaching package: 'igraph' 46 | #> The following objects are masked from 'package:purrr': 47 | #> 48 | #> compose, simplify 49 | #> The following objects are masked from 'package:dplyr': 50 | #> 51 | #> as_data_frame, groups, union 52 | #> The following objects are masked from 'package:stats': 53 | #> 54 | #> decompose, spectrum 55 | #> The following object is masked from 'package:base': 56 | #> 57 | #> union 58 | library("epigraphdb") 59 | ``` 60 | 61 | ## Metadata 62 | 63 | Here we query for the metadata information using the endpoint `GET /meta/schema`, which will be used for downstream processing. 64 | 65 | 66 | ```r 67 | endpoint <- "/meta/schema" 68 | params <- list( 69 | graphviz = FALSE, 70 | plot = FALSE 71 | ) 72 | metadata <- query_epigraphdb( 73 | route = endpoint, params = params, mode = "raw" 74 | ) 75 | 76 | metadata %>% str(2) 77 | #> List of 3 78 | #> $ nodes :List of 12 79 | #> ..$ Disease :List of 2 80 | #> ..$ Pathway :List of 2 81 | #> ..$ LiteratureTerm :List of 2 82 | #> ..$ Gene :List of 2 83 | #> ..$ LiteratureTriple:List of 2 84 | #> ..$ Literature :List of 2 85 | #> ..$ Protein :List of 2 86 | #> ..$ Variant :List of 2 87 | #> ..$ Efo :List of 2 88 | #> ..$ Tissue :List of 2 89 | #> ..$ Drug :List of 2 90 | #> ..$ Gwas :List of 2 91 | #> $ edges :List of 41 92 | #> ..$ OPENTARGETS_DRUG_TO_DISEASE :List of 2 93 | #> ..$ MEDRXIV_SUB :List of 2 94 | #> ..$ GENE_TO_DISEASE :List of 2 95 | #> ..$ GWAS_NLP_EFO :List of 2 96 | #> ..$ SEMMEDDB_PREDICATE :List of 2 97 | #> ..$ STRING_INTERACT_WITH :List of 2 98 | #> ..$ GWAS_TO_LITERATURE_TRIPLE :List of 2 99 | #> ..$ PRS :List of 2 100 | #> ..$ BIORXIV_PREDICATE :List of 2 101 | #> ..$ MONDO_MAP_UMLS :List of 2 102 | #> ..$ SEMMEDDB_SUB :List of 2 103 | #> ..$ MR_EVE_MR :List of 2 104 | #> ..$ OPENGWAS_TOPHITS :List of 2 105 | #> ..$ VARIANT_TO_GENE :List of 2 106 | #> ..$ MEDRXIV_PREDICATE :List of 2 107 | #> ..$ MEDRXIV_OBJ :List of 2 108 | #> ..$ EXPRESSED_IN :List of 2 109 | #> ..$ BIORXIV_OBJ :List of 2 110 | #> ..$ EFO_CHILD_OF :List of 2 111 | #> ..$ BIORXIV_TO_LIT :List of 2 112 | #> ..$ GEN_COR :List of 2 113 | #> ..$ METAMAP_LITE :List of 2 114 | #> ..$ SEMMEDDB_TO_LIT :List of 2 115 | #> ..$ PROTEIN_IN_PATHWAY :List of 2 116 | #> ..$ MONDO_MAP_EFO :List of 2 117 | #> ..$ PATHWAY_CHILD_OF :List of 2 118 | #> ..$ TERM_TO_GENE :List of 2 119 | #> ..$ GWAS_EFO_EBI :List of 2 120 | #> ..$ CPIC :List of 2 121 | #> ..$ XQTL_MULTI_SNP_MR :List of 2 122 | #> ..$ XQTL_SINGLE_SNP_MR_SNP_GENE :List of 2 123 | #> ..$ OBS_COR :List of 2 124 | #> ..$ GWAS_NLP :List of 2 125 | #> ..$ XQTL_SINGLE_SNP_MR_GENE_GWAS:List of 2 126 | #> ..$ MEDRXIV_TO_LIT :List of 2 127 | #> ..$ BIORXIV_SUB :List of 2 128 | #> ..$ OPENTARGETS_DRUG_TO_TARGET :List of 2 129 | #> ..$ GWAS_TO_VARIANT :List of 2 130 | #> ..$ GWAS_TO_LITERATURE :List of 2 131 | #> ..$ GENE_TO_PROTEIN :List of 2 132 | #> ..$ SEMMEDDB_OBJ :List of 2 133 | #> $ connections:List of 41 134 | #> ..$ :List of 4 135 | #> ..$ :List of 4 136 | #> ..$ :List of 4 137 | #> ..$ :List of 4 138 | #> ..$ :List of 4 139 | #> ..$ :List of 4 140 | #> ..$ :List of 4 141 | #> ..$ :List of 4 142 | #> ..$ :List of 4 143 | #> ..$ :List of 4 144 | #> ..$ :List of 4 145 | #> ..$ :List of 4 146 | #> ..$ :List of 4 147 | #> ..$ :List of 4 148 | #> ..$ :List of 4 149 | #> ..$ :List of 4 150 | #> ..$ :List of 4 151 | #> ..$ :List of 4 152 | #> ..$ :List of 4 153 | #> ..$ :List of 4 154 | #> ..$ :List of 4 155 | #> ..$ :List of 4 156 | #> ..$ :List of 4 157 | #> ..$ :List of 4 158 | #> ..$ :List of 4 159 | #> ..$ :List of 4 160 | #> ..$ :List of 4 161 | #> ..$ :List of 4 162 | #> ..$ :List of 4 163 | #> ..$ :List of 4 164 | #> ..$ :List of 4 165 | #> ..$ :List of 4 166 | #> ..$ :List of 4 167 | #> ..$ :List of 4 168 | #> ..$ :List of 4 169 | #> ..$ :List of 4 170 | #> ..$ :List of 4 171 | #> ..$ :List of 4 172 | #> ..$ :List of 4 173 | #> ..$ :List of 4 174 | #> ..$ :List of 4 175 | ``` 176 | 177 | ### Meta nodes 178 | 179 | We can extract the specific meta node information as a dataframe from the metadata. 180 | 181 | 182 | ```r 183 | meta_node_df <- metadata %>% 184 | pluck("nodes") %>% 185 | { 186 | names <- names(.) 187 | transpose(.) %>% 188 | as_tibble() %>% 189 | mutate(meta_node = names) %>% 190 | # Hide properties column which does not display well 191 | select(meta_node, count) %>% 192 | # We also need to flatten count 193 | mutate(count = flatten_int(count)) 194 | } 195 | 196 | meta_node_df %>% 197 | arrange(meta_node) %>% 198 | mutate(count = format(count, big.mark = ",")) 199 | #> # A tibble: 12 × 2 200 | #> meta_node count 201 | #> 202 | #> 1 Disease " 38,960" 203 | #> 2 Drug " 2,697" 204 | #> 3 Efo " 25,390" 205 | #> 4 Gene " 57,737" 206 | #> 5 Gwas " 34,494" 207 | #> 6 Literature "3,995,672" 208 | #> 7 LiteratureTerm " 108,905" 209 | #> 8 LiteratureTriple "5,609,945" 210 | #> 9 Pathway " 2,441" 211 | #> 10 Protein " 20,280" 212 | #> 11 Tissue " 54" 213 | #> 12 Variant " 99,005" 214 | ``` 215 | 216 | ### Meta relationships and connections 217 | 218 | We can also extract the meta relationship (edge) information, and the connections. 219 | 220 | 221 | ```r 222 | meta_rel_df <- metadata %>% 223 | pluck("edges") %>% 224 | { 225 | names <- names(.) 226 | transpose(.) %>% 227 | as_tibble() %>% 228 | mutate(meta_rel = names) %>% 229 | mutate(count = flatten_int(count)) %>% 230 | select(meta_rel, count) 231 | } %>% 232 | inner_join( 233 | metadata %>% pluck("connections") %>% 234 | { 235 | transpose(.) %>% 236 | as_tibble() %>% 237 | mutate(meta_rel = flatten_chr(rel)) %>% 238 | mutate_at(vars(from_node, to_node), flatten_chr) %>% 239 | select(meta_rel, from_node, to_node) 240 | } 241 | ) 242 | #> Joining, by = "meta_rel" 243 | 244 | meta_rel_df %>% 245 | arrange(from_node, to_node) %>% 246 | mutate(count = format(count, big.mark = ",")) 247 | #> # A tibble: 41 × 4 248 | #> meta_rel count from_node to_node 249 | #> 250 | #> 1 MONDO_MAP_EFO " 2,819" Disease Efo 251 | #> 2 MONDO_MAP_UMLS " 8,247" Disease LiteratureTerm 252 | #> 3 OPENTARGETS_DRUG_TO_DISEASE " 2,461" Drug Disease 253 | #> 4 CPIC " 375" Drug Gene 254 | #> 5 OPENTARGETS_DRUG_TO_TARGET " 6,534" Drug Gene 255 | #> 6 EFO_CHILD_OF " 43,132" Efo Efo 256 | #> 7 GENE_TO_DISEASE " 5,763" Gene Disease 257 | #> 8 XQTL_MULTI_SNP_MR " 3,015,233" Gene Gwas 258 | #> 9 XQTL_SINGLE_SNP_MR_GENE_GWAS " 8,449,779" Gene Gwas 259 | #> 10 GENE_TO_PROTEIN " 19,142" Gene Protein 260 | #> # … with 31 more rows 261 | ``` 262 | 263 | ## Search for specific node 264 | 265 | Users can use [the explorer on the Web UI](https://dev.epigraphdb.org/explore) to search for a specific node by: 266 | 267 | - fuzzy matching by "name" field. 268 | - exact matching by "ID" field if you know the its ID (e.g. the ID to a GWAS from IEU GWAS Database). 269 | 270 | Here we show how these are done at the API level using `Gwas` nodes as an example. 271 | 272 | First we need to know what the "ID" and "name" fields are for the meta nodes using `GET /meta/nodes/id-name-schema`: 273 | 274 | 275 | ```r 276 | endpoint <- "/meta/nodes/id-name-schema" 277 | meta_node_fields <- query_epigraphdb( 278 | route = endpoint, params = NULL, mode = "raw" 279 | ) 280 | meta_node_fields 281 | #> $Disease 282 | #> $Disease$id 283 | #> [1] "id" 284 | #> 285 | #> $Disease$name 286 | #> [1] "label" 287 | #> 288 | #> 289 | #> $Drug 290 | #> $Drug$id 291 | #> [1] "label" 292 | #> 293 | #> $Drug$name 294 | #> [1] "label" 295 | #> 296 | #> 297 | #> $Efo 298 | #> $Efo$id 299 | #> [1] "id" 300 | #> 301 | #> $Efo$name 302 | #> [1] "value" 303 | #> 304 | #> 305 | #> $Gene 306 | #> $Gene$id 307 | #> [1] "ensembl_id" 308 | #> 309 | #> $Gene$name 310 | #> [1] "name" 311 | #> 312 | #> 313 | #> $Gwas 314 | #> $Gwas$id 315 | #> [1] "id" 316 | #> 317 | #> $Gwas$name 318 | #> [1] "trait" 319 | #> 320 | #> 321 | #> $Literature 322 | #> $Literature$id 323 | #> [1] "id" 324 | #> 325 | #> $Literature$name 326 | #> [1] "id" 327 | #> 328 | #> 329 | #> $LiteratureTerm 330 | #> $LiteratureTerm$id 331 | #> [1] "id" 332 | #> 333 | #> $LiteratureTerm$name 334 | #> [1] "name" 335 | #> 336 | #> 337 | #> $LiteratureTriple 338 | #> $LiteratureTriple$id 339 | #> [1] "id" 340 | #> 341 | #> $LiteratureTriple$name 342 | #> [1] "name" 343 | #> 344 | #> 345 | #> $Pathway 346 | #> $Pathway$id 347 | #> [1] "id" 348 | #> 349 | #> $Pathway$name 350 | #> [1] "name" 351 | #> 352 | #> 353 | #> $Protein 354 | #> $Protein$id 355 | #> [1] "uniprot_id" 356 | #> 357 | #> $Protein$name 358 | #> [1] "uniprot_id" 359 | #> 360 | #> 361 | #> $Tissue 362 | #> $Tissue$id 363 | #> [1] "id" 364 | #> 365 | #> $Tissue$name 366 | #> [1] "name" 367 | #> 368 | #> 369 | #> $Variant 370 | #> $Variant$id 371 | #> [1] "name" 372 | #> 373 | #> $Variant$name 374 | #> [1] "name" 375 | ``` 376 | 377 | ## Fuzzy matching 378 | 379 | Here we search for nodes can contain "body mass index" in their traits. 380 | 381 | 382 | ```r 383 | name <- "body mass index" 384 | 385 | endpoint <- "/meta/nodes/Gwas/search" 386 | params <- list(name = name) 387 | 388 | results <- query_epigraphdb( 389 | route = endpoint, params = params, mode = "table" 390 | ) 391 | results 392 | #> # A tibble: 10 × 18 393 | #> node.note node._name node.year node.mr node.author node.sex node.pmid 394 | #> 395 | #> 1 Dominance model… Body mass … 2016.0 0 Wood Males a… 26961502… 396 | #> 2 Body mass … 2015.0 1 Locke AE Females 25673413… 397 | #> 3 Body mass … 2013.0 1 Randall JC Females 23754948… 398 | #> 4 Body mass … 2017.0 1 Akiyama M 28892062… 399 | #> 5 Body mass … 2018.0 1 Hoffmann TJ 30108127… 400 | #> 6 Body mass … 2019.0 1 Ishigaki K Males 28892062… 401 | #> 7 Body mass … 2015.0 1 Locke AE Males a… 25673413… 402 | #> 8 Body mass … 2015.0 1 Locke AE Males a… 25673413… 403 | #> 9 Body mass … 2015.0 1 Locke AE Males 25673413… 404 | #> 10 Body mass … 2019.0 1 Ishigaki K Males a… 28892062… 405 | #> # … with 11 more variables: node.population , node.sample_size , 406 | #> # node.nsnp , node.build , node.trait , node._source , 407 | #> # node.id , node._id , node.subcategory , node.category , 408 | #> # node.sd 409 | ``` 410 | 411 | ## Exact matching 412 | 413 | Similarly, we can exact match a specific node by its ID. 414 | 415 | 416 | ```r 417 | id <- "ieu-a-2" 418 | 419 | endpoint <- "/meta/nodes/Gwas/search" 420 | params <- list(id = id) 421 | 422 | results <- query_epigraphdb( 423 | route = endpoint, params = params, mode = "table" 424 | ) 425 | results 426 | #> # A tibble: 1 × 17 427 | #> node._name node.year node.mr node.author node.sex node.pmid node.population 428 | #> 429 | #> 1 Body mass … 2015.0 1 Locke AE Males and… 25673413… Mixed 430 | #> # … with 10 more variables: node.sd , node.sample_size , 431 | #> # node.nsnp , node.build , node.trait , node._source , 432 | #> # node.id , node._id , node.subcategory , node.category 433 | ``` 434 | 435 | ## Cypher (advanced) 436 | 437 | Advanced users that are familiar with Neo4j Cypher can query the database using Cypher directly. 438 | 439 | 440 | ```r 441 | query <- " 442 | MATCH (exposure:Gwas)-[mr:MR]->(outcome:Gwas) 443 | WHERE exposure.trait = 'Body mass index' 444 | RETURN exposure, outcome, mr LIMIT 2 445 | " 446 | 447 | endpoint <- "/cypher" 448 | params <- list(query = query) 449 | 450 | # NOTE this is a POST request 451 | results <- query_epigraphdb( 452 | route = endpoint, params = params, method = "POST", 453 | mode = "table" 454 | ) 455 | results 456 | #> # A tibble: 0 × 0 457 | ``` 458 | 459 | 460 | ## `sessionInfo` 461 | 462 | 463 | ```r 464 | sessionInfo() 465 | #> R version 4.1.2 (2021-11-01) 466 | #> Platform: x86_64-pc-linux-gnu (64-bit) 467 | #> Running under: Ubuntu 20.04.3 LTS 468 | #> 469 | #> Matrix products: default 470 | #> BLAS/LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.8.so 471 | #> 472 | #> locale: 473 | #> [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C 474 | #> [3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8 475 | #> [5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 476 | #> [7] LC_PAPER=en_US.UTF-8 LC_NAME=C 477 | #> [9] LC_ADDRESS=C LC_TELEPHONE=C 478 | #> [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C 479 | #> 480 | #> attached base packages: 481 | #> [1] stats graphics grDevices utils datasets methods base 482 | #> 483 | #> other attached packages: 484 | #> [1] igraph_1.2.11 purrr_0.3.4 magrittr_2.0.1 epigraphdb_0.2.3 485 | #> [5] dplyr_1.0.7 486 | #> 487 | #> loaded via a namespace (and not attached): 488 | #> [1] knitr_1.37 tidyselect_1.1.1 R6_2.5.1 rlang_0.4.12 489 | #> [5] fansi_1.0.0 stringr_1.4.0 httr_1.4.2 tools_4.1.2 490 | #> [9] xfun_0.29 utf8_1.2.2 cli_3.1.0 DBI_1.1.2 491 | #> [13] ellipsis_0.3.2 assertthat_0.2.1 tibble_3.1.6 lifecycle_1.0.1 492 | #> [17] crayon_1.4.2 vctrs_0.3.8 curl_4.3.2 glue_1.6.0 493 | #> [21] evaluate_0.14 stringi_1.7.6 compiler_4.1.2 pillar_1.6.4 494 | #> [25] generics_0.1.1 jsonlite_1.7.2 pkgconfig_2.0.3 495 | ``` 496 | -------------------------------------------------------------------------------- /vignettes/options.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Options" 3 | output: rmarkdown::html_vignette 4 | vignette: > 5 | %\VignetteIndexEntry{Options} 6 | %\VignetteEngine{knitr::rmarkdown} 7 | %\VignetteEncoding{UTF-8} 8 | --- 9 | 10 | 11 | 12 | ## Change the API URL 13 | 14 | EpiGraphDB currently offers two API URLs 15 | 16 | - production (default): https://api.epigraphdb.org 17 | - development: http://dev-api.epigraphdb.org 18 | 19 | To switch to the development API, do 20 | 21 | ```r 22 | # Get default option 23 | default_api_url <- getOptions("epigraphdb.api.url") 24 | # Change to the development API 25 | options(epigraphdb.api.url = "http://dev-api.epigraphdb.org") 26 | # Verify current URL 27 | getOption("epigraphdb.api.url") 28 | # Switch back 29 | options(epigraphdb.api.url = default_api_url) 30 | ``` 31 | 32 | NOTE: you can make this change persistent by placing the changes in 33 | [`.Rprofile`](https://www.statmethods.net/interface/customizing.html). 34 | 35 | ## Suppress start up message 36 | 37 | If you would like to turn off the start up message that displays the current version of EpiGraphDB service, use the following code to load the package: 38 | 39 | ```r 40 | suppressPackageStartupMessages({library("epigraphdb")}) 41 | ``` 42 | -------------------------------------------------------------------------------- /vignettes/using-epigraphdb-api.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Using EpiGraphDB API" 3 | output: rmarkdown::html_vignette 4 | vignette: > 5 | %\VignetteIndexEntry{Using EpiGraphDB API} 6 | %\VignetteEngine{knitr::rmarkdown} 7 | %\VignetteEncoding{UTF-8} 8 | --- 9 | 10 | 11 | 12 | ## Introduction 13 | 14 | EpiGraphDB as a collated resource offers rich integrative epidemiological 15 | evidence for researchers to use, which can be queried from our 16 | [RESTful API service](https://api.epigraphdb.org). 17 | 18 | EpiGraphDB [web application](https://epigraphdb.org): 19 | 20 | ![web application](figures/epigraphdb-xqtl-view.png) 21 | 22 | EpiGraphDB [web API (OpenAPI / swagger interface)](https://api.epigraphdb.org): 23 | 24 | ![web API](figures/epigraphdb-api-swagger.png) 25 | 26 | The R package is designed to give users quick access to some of the 27 | key resources, but not as a comprehensive replacement of the web API. 28 | At the moment EpiGraphDB is still under fast and active development with 29 | frequent addition of new API endpoints that might not have corresponding 30 | functions available in the R package. 31 | 32 | In this tutorial we will discuss two alternative methods to get data from 33 | the EpiGraphDB web API -- using `httr` in R and 34 | using `curl` in the command line. 35 | 36 | ## Using `httr` 37 | 38 | Here are some examples of querying EpiGraphDB web API using 39 | [httr](https://httr.r-lib.org/reference/index.html): 40 | 41 | 42 | ```r 43 | library("epigraphdb") 44 | url <- getOption("epigraphdb.api.url") 45 | payload <- list( 46 | exposure_trait = "Body mass index", 47 | outcome_trait = "Coronary heart disease" 48 | ) 49 | r <- httr::RETRY("GET", glue::glue("{url}/mr"), query = payload) 50 | r %>% 51 | httr::content(as = "parsed") %>% 52 | str(2) 53 | #> List of 2 54 | #> $ metadata:List of 3 55 | #> ..$ query : chr "MATCH (exposure:Gwas)-[mr:MR_EVE_MR]->(outcome:Gwas) WHERE exposure.trait = \"Body mass index\" AND outcome.tra"| __truncated__ 56 | #> ..$ total_seconds: num 0.0306 57 | #> ..$ empty_results: logi FALSE 58 | #> $ results :List of 18 59 | #> ..$ :List of 3 60 | #> ..$ :List of 3 61 | #> ..$ :List of 3 62 | #> ..$ :List of 3 63 | #> ..$ :List of 3 64 | #> ..$ :List of 3 65 | #> ..$ :List of 3 66 | #> ..$ :List of 3 67 | #> ..$ :List of 3 68 | #> ..$ :List of 3 69 | #> ..$ :List of 3 70 | #> ..$ :List of 3 71 | #> ..$ :List of 3 72 | #> ..$ :List of 3 73 | #> ..$ :List of 3 74 | #> ..$ :List of 3 75 | #> ..$ :List of 3 76 | #> ..$ :List of 3 77 | ``` 78 | 79 | And this is the data structure as returned from the 80 | `epigraphdb::mr` call with `mode = "raw"`: 81 | 82 | 83 | ```r 84 | epigraphdb::mr( 85 | exposure_trait = "Body mass index", 86 | outcome_trait = "Coronary heart disease", 87 | mode = "raw" 88 | ) %>% 89 | str(2) 90 | #> List of 2 91 | #> $ metadata:List of 3 92 | #> ..$ query : chr "MATCH (exposure:Gwas)-[mr:MR_EVE_MR]->(outcome:Gwas) WHERE exposure.trait = \"Body mass index\" AND outcome.tra"| __truncated__ 93 | #> ..$ total_seconds: num 0.0234 94 | #> ..$ empty_results: logi FALSE 95 | #> $ results :List of 18 96 | #> ..$ :List of 3 97 | #> ..$ :List of 3 98 | #> ..$ :List of 3 99 | #> ..$ :List of 3 100 | #> ..$ :List of 3 101 | #> ..$ :List of 3 102 | #> ..$ :List of 3 103 | #> ..$ :List of 3 104 | #> ..$ :List of 3 105 | #> ..$ :List of 3 106 | #> ..$ :List of 3 107 | #> ..$ :List of 3 108 | #> ..$ :List of 3 109 | #> ..$ :List of 3 110 | #> ..$ :List of 3 111 | #> ..$ :List of 3 112 | #> ..$ :List of 3 113 | #> ..$ :List of 3 114 | ``` 115 | 116 | In fact, currently the `epigraphdb::mr` function is a 117 | [wrapper](https://github.com/MRCIEU/epigraphdb-r/blob/master/R/mr.R) 118 | of `httr::get`. 119 | Please consult with 120 | [`httr` documentation](https://httr.r-lib.org/index.html) 121 | for details of usage. 122 | 123 | ## Using `curl` 124 | 125 | Here is an example in using `curl` to get data and using 126 | [`jq`](https://stedolan.github.io/jq/) for 127 | post processing the returned json data: 128 | 129 | ```shell 130 | curl -X 'GET' 'https://api.epigraphdb.org/mr?exposure=Body+mass+index&outcome=Coronary+heart+disease' | jq 131 | ``` 132 | 133 | The returned data will look like this: 134 | 135 | ```json 136 | { 137 | "query": "MATCH (t1:Gwas)-[r:MR]->(t2:Gwas) WHERE t1.trait = \"Body mass index\" AND t2.trait = \"Coronary heart disease\" AND r.p < 1e-05 RETURN t1.id AS exposure_id, t1.trait AS exposure_name, t2.id AS outcome_id, t2.trait AS outcome_name, r.estimate AS estimate, r.se AS se, r.p AS p, r.ci_upp as ci_upp, r.ci_low AS ci_low, r.selection AS selection, r.method AS method, r.moescore AS moescore ORDER BY r.p ;", 138 | "results": [ 139 | { 140 | "exposure_id": "974", 141 | "exposure_name": "Body mass index", 142 | "outcome_id": "7", 143 | "outcome_name": "Coronary heart disease", 144 | "estimate": 0.388519597717655, 145 | "se": 0.0493380883899318, 146 | "p": 3.41730166606158e-15, 147 | "ci_upp": 0.498022055339364, 148 | "ci_low": 0.279017140095947, 149 | "selection": "DF", 150 | "method": "FE IVW", 151 | "moescore": 0.89 152 | }, 153 | { 154 | "exposure_id": "2", 155 | "exposure_name": "Body mass index", 156 | "outcome_id": "7", 157 | "outcome_name": "Coronary heart disease", 158 | "estimate": 0.397101449275362, 159 | "se": 0.0727452867916401, 160 | "p": 4.79382740959139e-08, 161 | "ci_upp": 0.539679591432014, 162 | "ci_low": 0.25452330711871, 163 | "selection": "HF", 164 | "method": "Simple median", 165 | "moescore": 0.92 166 | }, 167 | { 168 | "exposure_id": "95", 169 | "exposure_name": "Body mass index", 170 | "outcome_id": "7", 171 | "outcome_name": "Coronary heart disease", 172 | "estimate": 0.454936804438897, 173 | "se": 0.0930665978652417, 174 | "p": 1.01714040121612e-06, 175 | "ci_upp": 0.637343984418443, 176 | "ci_low": 0.272529624459351, 177 | "selection": "DF", 178 | "method": "Penalised median", 179 | "moescore": 0.78 180 | }, 181 | { 182 | "exposure_id": "2", 183 | "exposure_name": "Body mass index", 184 | "outcome_id": "8", 185 | "outcome_name": "Coronary heart disease", 186 | "estimate": 0.330889761641503, 187 | "se": 0.0683874628196063, 188 | "p": 1.30851348920923e-06, 189 | "ci_upp": 0.47183747438535, 190 | "ci_low": 0.189942048897655, 191 | "selection": "DF", 192 | "method": "FE IVW", 193 | "moescore": 0.75 194 | }, 195 | { 196 | "exposure_id": "835", 197 | "exposure_name": "Body mass index", 198 | "outcome_id": "7", 199 | "outcome_name": "Coronary heart disease", 200 | "estimate": 0.359685792349727, 201 | "se": 0.0755689310372249, 202 | "p": 1.93876456579184e-06, 203 | "ci_upp": 0.507798175532879, 204 | "ci_low": 0.211573409166575, 205 | "selection": "Tophits", 206 | "method": "Simple median", 207 | "moescore": 0.91 208 | }, 209 | { 210 | "exposure_id": "974", 211 | "exposure_name": "Body mass index", 212 | "outcome_id": "8", 213 | "outcome_name": "Coronary heart disease", 214 | "estimate": 0.32847610101648, 215 | "se": 0.0730805223133059, 216 | "p": 6.96632705468264e-06, 217 | "ci_upp": 0.49537017731629, 218 | "ci_low": 0.16158202471667, 219 | "selection": "DF", 220 | "method": "FE IVW", 221 | "moescore": 0.85 222 | } 223 | ] 224 | } 225 | ``` 226 | 227 | ## Other methods 228 | 229 | Alternatively, you can use other commonly used tools to query the web API: 230 | 231 | - [command line: httpie](https://github.com/httpie/httpie) 232 | - [python: requests](https://realpython.com/python-requests/) 233 | - [GUI client: postman](https://www.guru99.com/postman-tutorial.html) 234 | 235 | For details of the EpiGraphDB RESTful API and related services, 236 | please visit our [documentation site](https://docs.epigraphdb.org). 237 | -------------------------------------------------------------------------------- /vignettes/using-epigraphdb-r-package.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Using EpiGraphDB R package" 3 | output: rmarkdown::html_vignette 4 | vignette: > 5 | %\VignetteIndexEntry{Using EpiGraphDB R package} 6 | %\VignetteEngine{knitr::rmarkdown} 7 | %\VignetteEncoding{UTF-8} 8 | --- 9 | 10 | 11 | 12 | 13 | ```r 14 | library("epigraphdb") 15 | ``` 16 | 17 | ## Methods to query EpiGraphDB 18 | 19 | We provide a 20 | [list of functions](https://mrcieu.github.io/epigraphdb-r/index.html#functionalities) 21 | that are equivalent to the 22 | [upstream API endpoints](https://api.epigraphdb.org) 23 | for users to use. 24 | For endpoints that don't have equivalent functions, users can use the 25 | [`query_epigraphdb`](https://mrcieu.github.io/epigraphdb-r/reference/query_epigraphdb.html) 26 | function. 27 | 28 | Here we show the two approaches to query MR data from EpiGraphDB, using the 29 | [`mr`](https://mrcieu.github.io/epigraphdb-r/reference/mr.html) function and 30 | using 31 | [`query_epigraphdb`](https://mrcieu.github.io/epigraphdb-r/reference/query_epigraphdb.html) 32 | to query the 33 | [`GET /mr`](https://docs.epigraphdb.org/api/api-endpoints/#get-mr) 34 | endpoint. 35 | 36 | ### `mr` 37 | 38 | 39 | ```r 40 | df <- mr( 41 | exposure_trait = "Body mass index", 42 | outcome_trait = "Coronary heart disease", 43 | mode = "table" 44 | ) 45 | df 46 | #> # A tibble: 18 × 10 47 | #> exposure.id exposure.trait outcome.id outcome.trait mr.b mr.se mr.pval 48 | #> 49 | #> 1 ieu-a-2 Body mass index ieu-a-7 Coronary hear… 0.464 0.0415 5.46e-29 50 | #> 2 ebi-a-GCST0… Body mass index ieu-a-7 Coronary hear… 0.457 0.0410 3.33e-20 51 | #> 3 ieu-a-974 Body mass index ieu-a-7 Coronary hear… 0.389 0.0493 3.42e-15 52 | #> 4 ieu-a-835 Body mass index ieu-a-7 Coronary hear… 0.417 0.0492 1.00e-11 53 | #> 5 ieu-a-974 Body mass index ieu-a-9 Coronary hear… 0.320 0.0536 2.32e- 9 54 | #> 6 ieu-a-2 Body mass index ieu-a-9 Coronary hear… 0.358 0.0535 5.91e- 9 55 | #> 7 ieu-a-835 Body mass index ieu-a-9 Coronary hear… 0.397 0.0604 1.79e- 8 56 | #> 8 ebi-a-GCST0… Body mass index ieu-a-9 Coronary hear… 0.341 0.0590 1.24e- 7 57 | #> 9 ieu-a-95 Body mass index ieu-a-9 Coronary hear… 0.371 0.0708 1.62e- 7 58 | #> 10 ebi-a-GCST0… Body mass index ieu-a-6 Coronary hear… 0.493 0.0986 5.88e- 7 59 | #> 11 ieu-a-785 Body mass index ieu-a-9 Coronary hear… 0.395 0.0609 1.07e- 6 60 | #> 12 ebi-a-GCST0… Body mass index ebi-a-GCST… Coronary hear… 0.309 0.0648 1.81e- 6 61 | #> 13 ebi-a-GCST0… Body mass index ieu-a-8 Coronary hear… 0.309 0.0648 1.81e- 6 62 | #> 14 ebi-a-GCST0… Body mass index ieu-a-7 Coronary hear… 0.275 0.0514 2.76e- 6 63 | #> 15 ieu-a-95 Body mass index ieu-a-7 Coronary hear… 0.455 0.0971 2.82e- 6 64 | #> 16 ieu-a-2 Body mass index ieu-a-8 Coronary hear… 0.317 0.0686 3.93e- 6 65 | #> 17 ieu-a-2 Body mass index ebi-a-GCST… Coronary hear… 0.312 0.0688 5.86e- 6 66 | #> 18 ieu-a-974 Body mass index ieu-a-8 Coronary hear… 0.328 0.0731 6.97e- 6 67 | #> # … with 3 more variables: mr.method , mr.selection , 68 | #> # mr.moescore 69 | ``` 70 | 71 | ### `GET /mr` 72 | 73 | 74 | ```r 75 | df <- query_epigraphdb( 76 | route = "/mr", 77 | params = list( 78 | exposure_trait = "Body mass index", 79 | outcome_trait = "Coronary heart disease" 80 | ), 81 | mode = "table" 82 | ) 83 | 84 | df 85 | #> # A tibble: 18 × 10 86 | #> exposure.id exposure.trait outcome.id outcome.trait mr.b mr.se mr.pval 87 | #> 88 | #> 1 ieu-a-2 Body mass index ieu-a-7 Coronary hear… 0.464 0.0415 5.46e-29 89 | #> 2 ebi-a-GCST0… Body mass index ieu-a-7 Coronary hear… 0.457 0.0410 3.33e-20 90 | #> 3 ieu-a-974 Body mass index ieu-a-7 Coronary hear… 0.389 0.0493 3.42e-15 91 | #> 4 ieu-a-835 Body mass index ieu-a-7 Coronary hear… 0.417 0.0492 1.00e-11 92 | #> 5 ieu-a-974 Body mass index ieu-a-9 Coronary hear… 0.320 0.0536 2.32e- 9 93 | #> 6 ieu-a-2 Body mass index ieu-a-9 Coronary hear… 0.358 0.0535 5.91e- 9 94 | #> 7 ieu-a-835 Body mass index ieu-a-9 Coronary hear… 0.397 0.0604 1.79e- 8 95 | #> 8 ebi-a-GCST0… Body mass index ieu-a-9 Coronary hear… 0.341 0.0590 1.24e- 7 96 | #> 9 ieu-a-95 Body mass index ieu-a-9 Coronary hear… 0.371 0.0708 1.62e- 7 97 | #> 10 ebi-a-GCST0… Body mass index ieu-a-6 Coronary hear… 0.493 0.0986 5.88e- 7 98 | #> 11 ieu-a-785 Body mass index ieu-a-9 Coronary hear… 0.395 0.0609 1.07e- 6 99 | #> 12 ebi-a-GCST0… Body mass index ebi-a-GCST… Coronary hear… 0.309 0.0648 1.81e- 6 100 | #> 13 ebi-a-GCST0… Body mass index ieu-a-8 Coronary hear… 0.309 0.0648 1.81e- 6 101 | #> 14 ebi-a-GCST0… Body mass index ieu-a-7 Coronary hear… 0.275 0.0514 2.76e- 6 102 | #> 15 ieu-a-95 Body mass index ieu-a-7 Coronary hear… 0.455 0.0971 2.82e- 6 103 | #> 16 ieu-a-2 Body mass index ieu-a-8 Coronary hear… 0.317 0.0686 3.93e- 6 104 | #> 17 ieu-a-2 Body mass index ebi-a-GCST… Coronary hear… 0.312 0.0688 5.86e- 6 105 | #> 18 ieu-a-974 Body mass index ieu-a-8 Coronary hear… 0.328 0.0731 6.97e- 6 106 | #> # … with 3 more variables: mr.method , mr.selection , 107 | #> # mr.moescore 108 | ``` 109 | 110 | For more information on the API endpoints, please visit: 111 | 112 | - The API Swagger interface https://api.epigraphdb.org 113 | - The documentation on API endpoints https://docs.epigraphdb.org/api/api-endpoints/ 114 | 115 | ## Returned data format 116 | 117 | As a general principle, we offer two modes of the returned data: 118 | a `table` mode (default) that returns a data frame, 119 | and a `raw` mode that preserves the hierarchical structure of the upstream 120 | json data and contains other information that might benefit users. 121 | 122 | ### `mode = "table"` 123 | 124 | By default, for ease of use, the query returns a data frame which is a 125 | tidyverse [`tibble`](https://tibble.tidyverse.org/): 126 | 127 | 128 | ```r 129 | df <- mr( 130 | exposure_trait = "Body mass index", 131 | outcome_trait = "Coronary heart disease" 132 | ) 133 | df 134 | #> # A tibble: 18 × 10 135 | #> exposure.id exposure.trait outcome.id outcome.trait mr.b mr.se mr.pval 136 | #> 137 | #> 1 ieu-a-2 Body mass index ieu-a-7 Coronary hear… 0.464 0.0415 5.46e-29 138 | #> 2 ebi-a-GCST0… Body mass index ieu-a-7 Coronary hear… 0.457 0.0410 3.33e-20 139 | #> 3 ieu-a-974 Body mass index ieu-a-7 Coronary hear… 0.389 0.0493 3.42e-15 140 | #> 4 ieu-a-835 Body mass index ieu-a-7 Coronary hear… 0.417 0.0492 1.00e-11 141 | #> 5 ieu-a-974 Body mass index ieu-a-9 Coronary hear… 0.320 0.0536 2.32e- 9 142 | #> 6 ieu-a-2 Body mass index ieu-a-9 Coronary hear… 0.358 0.0535 5.91e- 9 143 | #> 7 ieu-a-835 Body mass index ieu-a-9 Coronary hear… 0.397 0.0604 1.79e- 8 144 | #> 8 ebi-a-GCST0… Body mass index ieu-a-9 Coronary hear… 0.341 0.0590 1.24e- 7 145 | #> 9 ieu-a-95 Body mass index ieu-a-9 Coronary hear… 0.371 0.0708 1.62e- 7 146 | #> 10 ebi-a-GCST0… Body mass index ieu-a-6 Coronary hear… 0.493 0.0986 5.88e- 7 147 | #> 11 ieu-a-785 Body mass index ieu-a-9 Coronary hear… 0.395 0.0609 1.07e- 6 148 | #> 12 ebi-a-GCST0… Body mass index ebi-a-GCST… Coronary hear… 0.309 0.0648 1.81e- 6 149 | #> 13 ebi-a-GCST0… Body mass index ieu-a-8 Coronary hear… 0.309 0.0648 1.81e- 6 150 | #> 14 ebi-a-GCST0… Body mass index ieu-a-7 Coronary hear… 0.275 0.0514 2.76e- 6 151 | #> 15 ieu-a-95 Body mass index ieu-a-7 Coronary hear… 0.455 0.0971 2.82e- 6 152 | #> 16 ieu-a-2 Body mass index ieu-a-8 Coronary hear… 0.317 0.0686 3.93e- 6 153 | #> 17 ieu-a-2 Body mass index ebi-a-GCST… Coronary hear… 0.312 0.0688 5.86e- 6 154 | #> 18 ieu-a-974 Body mass index ieu-a-8 Coronary hear… 0.328 0.0731 6.97e- 6 155 | #> # … with 3 more variables: mr.method , mr.selection , 156 | #> # mr.moescore 157 | ``` 158 | 159 | ### `mode = "raw"` 160 | 161 | Alternatively, you can use `results_type = "raw"` to get the unformatted 162 | response from EpiGraphDB API. 163 | 164 | 165 | ```r 166 | response <- mr( 167 | exposure_trait = "Body mass index", 168 | outcome_trait = "Coronary heart disease", 169 | mode = "raw" 170 | ) 171 | response %>% str(2) 172 | #> List of 2 173 | #> $ metadata:List of 3 174 | #> ..$ query : chr "MATCH (exposure:Gwas)-[mr:MR_EVE_MR]->(outcome:Gwas) WHERE exposure.trait = \"Body mass index\" AND outcome.tra"| __truncated__ 175 | #> ..$ total_seconds: num 0.0207 176 | #> ..$ empty_results: logi FALSE 177 | #> $ results :List of 18 178 | #> ..$ :List of 3 179 | #> ..$ :List of 3 180 | #> ..$ :List of 3 181 | #> ..$ :List of 3 182 | #> ..$ :List of 3 183 | #> ..$ :List of 3 184 | #> ..$ :List of 3 185 | #> ..$ :List of 3 186 | #> ..$ :List of 3 187 | #> ..$ :List of 3 188 | #> ..$ :List of 3 189 | #> ..$ :List of 3 190 | #> ..$ :List of 3 191 | #> ..$ :List of 3 192 | #> ..$ :List of 3 193 | #> ..$ :List of 3 194 | #> ..$ :List of 3 195 | #> ..$ :List of 3 196 | ``` 197 | 198 | There are several reasons that a `raw` mode might benefit you: 199 | 200 | 1. The `results` component preserves the upstream hierarchical json structure 201 | that might be useful for users aiming for specific tasks 202 | such as rendering network plots or batch post-processing the returned data 203 | in a large scale. 204 | 205 | 2. The `query` component returns 206 | the [cypher](https://neo4j.com/developer/cypher/) 207 | query that fetches data from the EpiGraphDB neo4j databases. 208 | EpiGraphDB will offer functionality (forthcoming) for users to 209 | send cypher queries to the web API that can return more complex query 210 | structure (visit our [web app](https://epigraphdb.org) for examples). 211 | Once you are sufficiently well-versed in cypher you can construct 212 | your own refined queries to better suit your needs. 213 | -------------------------------------------------------------------------------- /vignettes_src/.gitignore: -------------------------------------------------------------------------------- 1 | *.html 2 | *.R 3 | -------------------------------------------------------------------------------- /vignettes_src/about.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "About" 3 | output: rmarkdown::html_vignette 4 | vignette: > 5 | %\VignetteIndexEntry{About} 6 | %\VignetteEngine{knitr::rmarkdown} 7 | %\VignetteEncoding{UTF-8} 8 | --- 9 | 10 | ```{r, include = FALSE} 11 | knitr::opts_chunk$set( 12 | collapse = TRUE, 13 | comment = "#>" 14 | ) 15 | ``` 16 | 17 | [EpiGraphDB](https://epigraphdb.org) is an analytical platform and database to support data mining in epidemiology. The platform incorporates a graph of causal estimates generated by systematically applying Mendelian randomization to a wide array of phenotypes, and augments this with a wealth of additional data from other bioinformatic sources. 18 | EpiGraphDB aims to support appropriate application and interpretation of causal inference in systematic automated analyses of many phenotypes. 19 | 20 | [`epigraphdb`](https://github.com/MRCIEU/epigraphdb-r) is an R package to provide ease of access to EpiGraphDB services. 21 | 22 | ## EpiGraphDB resources 23 | 24 | | link | screenshot | 25 | |-----------------------------------------------------|---------------------------------------------| 26 | | [docs](https://docs.epigraphdb.org) | ![docs](figures/epigraphdb-docs.png) | 27 | | [API](https://api.epigraphdb.org) | ![api](figures/epigraphdb-api-swagger.png) | 28 | | [web application](https://epigraphdb.org) | ![webapp](figures/epigraphdb-xqtl-view.png) | 29 | | [r package](https://github.com/MRCIEU/epigraphdb-r) | ![epigraphdb-r](figures/epigraphdb-r.png) | 30 | -------------------------------------------------------------------------------- /vignettes_src/getting-started-with-epigraphdb-r.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Getting started with EpiGraphDB in R" 3 | output: rmarkdown::html_vignette 4 | vignette: > 5 | %\VignetteIndexEntry{Getting started with EpiGraphDB in R} 6 | %\VignetteEngine{knitr::rmarkdown} 7 | %\VignetteEncoding{UTF-8} 8 | --- 9 | 10 | This article is provided as a brief introductory guide to working with the EpiGraphDB platform through `epigraphdb` R package. Here we will demonstrate a few basic operations that can be carried out using the platform, but for more advanced methods please refer to the [API endpoint documentation][2]. 11 | 12 | ```{r, include = FALSE} 13 | knitr::opts_chunk$set( 14 | collapse = TRUE, 15 | comment = "#>" 16 | ) 17 | ``` 18 | 19 | ```{r} 20 | library("dplyr") 21 | library("epigraphdb") 22 | ``` 23 | 24 | ## Part 1: Using EpiGraphDB to obtain biological mappings 25 | 26 | With EpiGraphDB you can map genetic variants to genes, genes to proteins, proteins to pathways, pathways to diseases and so on, as shown in the network diagram [here][1]. 27 | 28 | In this part, we want to demonstrate how to do basic mappings between biological entities. We are going to map genes to proteins (i.e. their UniProtID), proteins to pathways that they are found in (using Reactome data), and then extract information on the specific pathways identified. 29 | 30 | But first, let's talk about the basic querying syntax. `query_epigraphdb` is the main querying function in the package; it is used to communicate with EpiGraphDB by specifying API endpoints. 31 | 32 | ```r 33 | query_epigraphdb( 34 | route = endpoint, # supply the route / endpoint 35 | params = list(... = ...), # supply the query parameters 36 | mode = "table", # How the results are shown in R 37 | method = "GET" # HTTP method, "GET", "POST", etc. 38 | ) 39 | ``` 40 | 41 | - `endpoint` and `method` constitute the 'method' provided by the EpiGraphDB API web service of where you want to query the data from, and there is a dedicated one for each case. e.g. [`POST /mappings/gene-to-protein`](https://docs.epigraphdb.org/api/api-endpoints/#post-mappingsgene-to-protein) is used to query gene-to-proteins mappings. See the full list of currently available endpoints [here][2] in the documentation or the [Swagger interface of the API](https://api.epigraphdb.org). 42 | 43 | - `params` is where you supply the list of things you want to query about (can be a list of genes, GWAS trait, MR outcome of interest), subject to what each endpoint accepts and requires. 44 | 45 | - `mode` is the format in which the results are returned. Use "table" for basic cases, for more advanced stuff you may need to use "raw" - more on this later. 46 | 47 |
48 | In this guide, we are going to use the all-purpose `query_epigraphdb` function in all basic examples. However, many of the most common queries have been wrapped in [specific functions][12] within `epigraphdb` R package for the ease of use. Those are very helpful, but to help the understanding of the core principles behind using EpiGraphDB, here we present the ways to run queries in a less abstracted way. 49 | 50 | ### Mapping genes to proteins 51 | 52 | In this first section, we will take an arbitrary list of genes and query the EpiGraphDB API to find the proteins that they map to. 53 | 54 | ```{r} 55 | # Let's test this on a few genes 56 | genes <- c("TP53", "BRCA1", "TNF") 57 | 58 | # Select the endpoint "POST /mappings/gene-to-protein" 59 | endpoint <- "/mappings/gene-to-protein" 60 | method <- "POST" 61 | 62 | # Build a query 63 | proteins <- query_epigraphdb( 64 | route = endpoint, 65 | params = list(gene_name_list = genes), 66 | mode = "table", 67 | method = method 68 | ) 69 | 70 | # Check the output 71 | print(proteins) 72 | ``` 73 | 74 | In the above data frame, we see the output from querying EpiGraphDB for the proteins that have been mapped to the genes TP53, BRCA1, and TNF. Our query returned the UniProt and Ensembl IDs for those genes. 75 | 76 | ### Mapping proteins to pathways 77 | 78 | Next, to demonstrate the mapping of proteins to pathways, we are going to take one protein from the previous example, P04637, and query EpiGraphDB for all pathways it is known to be involved in. 79 | 80 | ```{r} 81 | # Let's see what pathways the protein product of TP53 gene is involved in 82 | 83 | # NOTE: Argument `uniprot_id_list` requires a list of UniProt IDs in 84 | # POST /mappings/gene-to-protein. 85 | # In this case for the R package, we need to wrap `proteins_uniprot_ids` 86 | # with an `I()` function (AsIs) to prevent auto-unpacking by `httr` 87 | proteins_uniprot_ids <- c("P04637") %>% I() 88 | 89 | endpoint <- "/protein/in-pathway" 90 | 91 | pathway_df <- query_epigraphdb( 92 | route = endpoint, 93 | params = list(uniprot_id_list = proteins_uniprot_ids), 94 | mode = "table", 95 | method = "POST" 96 | ) 97 | 98 | # Check out how many pathways this protein is found in 99 | print(pathway_df) 100 | 101 | # Get pathways names (Reactome IDs) 102 | print(pathway_df$pathway_reactome_id[[1]]) 103 | ``` 104 | 105 | P04637 is involved in five pathways. Next, let's get pathway info for one of them. 106 | 107 | ### Get pathway info 108 | 109 | ```{r} 110 | # Let's see what exactly this pathway is 111 | reactome_id <- "R-HSA-6804754" 112 | 113 | endpoint <- "/meta/nodes/Pathway/search" 114 | 115 | pathway_info <- query_epigraphdb( 116 | route = endpoint, 117 | params = list(id = reactome_id), 118 | mode = "table" 119 | ) 120 | 121 | # Pathway description 122 | print(pathway_info) 123 | ``` 124 | 125 | If you are interested in this type of analysis, check out case studies [1][3] and [2][4] for further details on pathways analysis, PPI, mapping drugs to targets etc. 126 | 127 |
128 | _Running the above queries using the [dedicated wrapped functions][12]:_ 129 | ```{r} 130 | mappings_gene_to_protein(genes) 131 | protein_in_pathway(proteins_uniprot_ids) 132 | ``` 133 | 134 | ## Part 2: Epidemiological relationships analysis 135 | 136 | In this part we will demonstrate queries that may be relevant in epidemiology research. 137 | 138 | ### Look up GWAS studies 139 | 140 | First, we want to check what GWAS are available within EpiGraphDB for our trait of interest, e.g. Body mass index. Doing this query is equivalent doing a look-up using [EpiGraphDB Web UI](https://dev.epigraphdb.org/explore). The search functionality is fuzzy search and case insensitive, i.e. 'body mass index' or 'Body Mass Index' will give you the same set of results. 141 | 142 | ```{r} 143 | # Let's see what Body mass index GWAS are available in EpiGraphDB 144 | trait <- "body mass index" 145 | 146 | endpoint <- "/meta/nodes/Gwas/search" 147 | 148 | results <- query_epigraphdb( 149 | route = endpoint, 150 | params = list(name = trait), 151 | mode = "table" 152 | ) 153 | 154 | # show selected columns in the results 155 | results %>% 156 | select( 157 | node.trait, node.id, node.sample_size, 158 | node.year, node.author 159 | ) 160 | ``` 161 | 162 | ### Explore Mendelian randomization studies 163 | 164 | In these examples, we show how to extract [pre-computed MR results][6] for the specified exposure, outcome, or both, traits of interest. 165 | 166 | #### Specify exposure trait 167 | 168 | ```{r} 169 | # Look up all MR analyses where a trait was used as exposure 170 | # and find all outcome traits with causal evidence from it. 171 | 172 | trait1 <- "Body mass index" 173 | # NB: here, trait name has to specific (not fuzzy): 174 | # use the exact trait name wording as in GWAS `node.trait` (previous example) 175 | 176 | endpoint <- "/mr" 177 | 178 | mr_df <- query_epigraphdb( 179 | route = endpoint, 180 | params = list( 181 | exposure_trait = trait1, 182 | pval_threshold = 5e-08 183 | ), 184 | mode = "table" 185 | ) 186 | print(mr_df) 187 | ``` 188 | 189 | The returned data frame includes all MR analysis with `exposure.trait` being "Body mass index". However, there are several GWAS with this names. If you are interested in a specific GWAS, you will need to filter by `exposure.id`. 190 | 191 | ```{r} 192 | # Show how many MR analyses were done for each Body mass index GWAS 193 | mr_df %>% count(exposure.id) 194 | ``` 195 | 196 | #### Specify outcome trait 197 | 198 | Next, we can check all available MR analyses for an outcome trait of interest. 199 | 200 | ```{r} 201 | # Look up all MR for a specified outcome trait 202 | # and find all exposure traits with causal evidence on it. 203 | 204 | trait2 <- "Waist circumference" 205 | 206 | endpoint <- "/mr" 207 | 208 | mr_df <- query_epigraphdb( 209 | route = endpoint, 210 | params = list( 211 | outcome_trait = trait2, 212 | pval_threshold = 5e-08 213 | ), 214 | mode = "table" 215 | ) 216 | print(mr_df) 217 | ``` 218 | 219 | #### Specify both exposure and outcome traits 220 | 221 | Finally, we can look up MR causal inference results for a pair of exposure and outcome. 222 | 223 | ```{r} 224 | # Look up a specific pair of exposure+outcome 225 | trait1 <- "Body mass index" 226 | trait2 <- "Coronary heart disease" 227 | 228 | endpoint <- "/mr" 229 | 230 | mr_df <- query_epigraphdb( 231 | route = endpoint, 232 | params = list( 233 | exposure_trait = trait1, 234 | outcome_trait = trait2 235 | ), 236 | mode = "table" 237 | ) 238 | 239 | print(mr_df) 240 | ``` 241 | 242 | To query EpiGraphDB directly by GWAS ID, you will need to use the advanced functionality. See the end of this article. 243 | 244 |
245 | _Running the above MR query using a [dedicated wrapped function][12]:_ 246 | ```{r} 247 | mr( 248 | exposure_trait = trait1, 249 | outcome_trait = trait2 250 | ) 251 | ``` 252 | 253 | ## Part 3. Looking for literature evidence 254 | 255 | Accessing information in the literature is a ubiquitous task in research, be it for novel hypothesis generation or as part of evidence triangulation. EpiGraphDB facilitates fast processing of this information by allowing access to a host of literature-mined relationships that have been structured into semantic triples. These take the general form (subject, predicate, object) and have been generated using contemporary natural language processing techniques applied to a massive amount of published biomedical research papers. 256 | 257 | In the following section, we will query the API for the relationship between a given gene and a disease outcome. 258 | 259 | ```{r} 260 | # Identity all publications where a gene is mentioned with relation to a disease 261 | 262 | gene <- "IL23R" 263 | trait <- "Inflammatory bowel disease" 264 | 265 | endpoint <- "/gene/literature" 266 | 267 | lit_df <- query_epigraphdb( 268 | route = endpoint, 269 | params = list( 270 | gene_name = gene, 271 | object_name = trait 272 | ), 273 | mode = "table" 274 | ) 275 | 276 | # Review the found evidence in the literature 277 | print(lit_df) 278 | ``` 279 | 280 | The data frame above shows that IL23R has been mentioned in 25 publications (`pubmed_id` column) in relation to Inflammatory bowel disease, in four predicates. 281 | 282 | ```{r} 283 | # Get a list of all PubMed IDs 284 | lit_df %>% 285 | pull(pubmed_id) %>% 286 | unlist() %>% 287 | unique() 288 | ``` 289 | 290 | If you are interested in literature mining analysis, and also matching MR results to literature evidence, please refer to more specific examples in case studies [3][5] and [2][4]. 291 | 292 | ## EpiGraphDB node search 293 | 294 | EpiGraphDB stores data as nodes (data types) and edges (relationships between nodes). The available nodes can be viewed through the `meta/nodes` endpoint. Let's list the available nodes: 295 | 296 | ```{r} 297 | endpoint <- "/meta/nodes/list" 298 | meta_node_fields <- query_epigraphdb( 299 | route = endpoint, params = NULL, mode = "raw" 300 | ) 301 | meta_node_fields %>% unlist() 302 | ``` 303 | 304 | The list of nodes is also available in the [documentation][11], along with the node properties, which are useful for running native Cypher queries. In this section, we want to show how to perform node search for a term of interest. Any node can be searched by specifying it in this query: `GET /meta/nodes/{meta_node}/search`. 305 | 306 | To demonstrate this, we are going to search for 'breast cancer' in various nodes: 307 | 308 | ```{r} 309 | name <- "breast cancer" 310 | 311 | endpoint <- "/meta/nodes/Gwas/search" 312 | results <- query_epigraphdb( 313 | route = endpoint, 314 | params = list(name = name), 315 | mode = "table" 316 | ) 317 | results %>% 318 | select( 319 | node.trait, node.id, node.sample_size, 320 | node.year, node.author 321 | ) 322 | 323 | endpoint <- "/meta/nodes/Disease/search" 324 | results <- query_epigraphdb( 325 | route = endpoint, 326 | params = list(name = name), 327 | mode = "table" 328 | ) 329 | results %>% 330 | select(node.label, node.id, node.definition) 331 | 332 | endpoint <- "/meta/nodes/Efo/search" 333 | results <- query_epigraphdb( 334 | route = endpoint, 335 | params = list(name = name), 336 | mode = "table" 337 | ) 338 | results 339 | ``` 340 | 341 | The queries above can be further expanded using Cypher as will be shown in the next section. To get more information about `meta` endpoint please see the guidelines on [meta functionalities][10]. 342 | 343 | ## Advanced examples 344 | 345 | The functionalities of `epigraphdb` R package and the REST API of EpiGraphDB are currently limited to a certain number of API endpoints available via the `query_epigraphdb` function, which are simply a small and limited subset of what a graph database offers. 346 | If you would like to further customise your query, EpiGraphDB API supports using Neo4j Cypher to directly query the graph database. 347 | 348 | To get you started, we want to show that the majority of API endpoint queries are simple wrappers around Cypher queries which directly request data from the graph database. 349 | For example, the simple GWAS query we've done in Part 2 using "table" mode, can be executed using "raw" mode to expose the exact Cypher query that was run against the database: 350 | 351 | ```{r} 352 | # Running a GWAS query from Part 2 353 | # Ask for "raw" format (as a list) 354 | trait <- "body mass index" 355 | endpoint <- "/meta/nodes/Gwas/search" 356 | response <- query_epigraphdb( 357 | route = endpoint, 358 | params = list(name = trait), 359 | mode = "raw" 360 | ) 361 | 362 | # display the Cypher query 363 | response$metadata$query 364 | ``` 365 | 366 | This is what a native Cypher query looks like: 367 | 368 | ```{r} 369 | query <- " 370 | MATCH (node: Gwas) 371 | WHERE node.trait =~ \"(?i).*body mass index.*\" 372 | RETURN node LIMIT 10; 373 | " 374 | ``` 375 | 376 | This is how you supply a Cypher query to `query_epigraphdb` function: 377 | 378 | ```{r} 379 | # use POST /cypher 380 | 381 | endpoint <- "/cypher" 382 | method <- "POST" 383 | params <- list(query = query) 384 | 385 | results <- query_epigraphdb( 386 | route = endpoint, 387 | params = params, 388 | method = method, 389 | mode = "table" 390 | ) 391 | 392 | # The result should be identical to the example in Part 2 393 | results %>% 394 | select( 395 | node.trait, node.id, node.sample_size, 396 | node.year, node.author 397 | ) 398 | ``` 399 | 400 | Next step: let's modify Cypher query 401 | 402 | ```{r} 403 | # Let's return Body mass index GWAS that were done by Locke AE 404 | 405 | query <- " 406 | MATCH (node: Gwas) 407 | WHERE node.trait =~ \"(?i).*body mass index.*\" 408 | AND node.author = \"Locke AE\" 409 | RETURN node; 410 | " 411 | 412 | endpoint <- "/cypher" 413 | method <- "POST" 414 | params <- list(query = query) 415 | 416 | results_subset <- query_epigraphdb( 417 | route = endpoint, 418 | params = params, 419 | method = method, 420 | mode = "table" 421 | ) 422 | 423 | results_subset %>% 424 | select( 425 | node.trait, node.id, node.sample_size, 426 | node.year, node.author 427 | ) 428 | ``` 429 | 430 | NOTE: Be mindful of the data type of each node property. Please refer to [data dictionary][7] to explore data types before writing native Cypher queries. 431 | 432 |
433 | Now, let's try making queries by specifying a GWAS ID. 434 | 435 | ```{r} 436 | # Extract info only for GWAS 'ieu-a-2' 437 | query <- " 438 | MATCH (node: Gwas) 439 | WHERE node.id = \"ieu-a-2\" 440 | RETURN node; 441 | " 442 | endpoint <- "/cypher" 443 | params <- list(query = query) 444 | results_subset <- query_epigraphdb( 445 | route = endpoint, 446 | params = params, 447 | method = "POST", 448 | mode = "table" 449 | ) 450 | 451 | results_subset %>% 452 | select( 453 | node.trait, node.id, node.sample_size, 454 | node.year, node.author 455 | ) 456 | ``` 457 | 458 | ```{r} 459 | # Return MR results only for exposure trait 'ieu-a-2' (body mass index) 460 | 461 | # first let's check the MR Cypher query that we run in "table" mode in Part 2 462 | trait1 <- "Body mass index" 463 | endpoint <- "/mr" 464 | mr_df <- query_epigraphdb( 465 | route = endpoint, 466 | params = list( 467 | exposure_trait = trait1, 468 | pval_threshold = 5e-08 469 | ), 470 | mode = "raw" 471 | ) 472 | mr_df$metadata$query 473 | 474 | # modify the query to only return 'ieu-a-2' GWAS results 475 | query <- " 476 | MATCH (exposure:Gwas)-[mr:MR_EVE_MR]->(outcome:Gwas) 477 | WHERE exposure.id = \"ieu-a-2\" 478 | AND mr.pval < 5e-08 479 | RETURN exposure {.id, .trait}, outcome {.id, .trait}, mr {.b, .se, .pval, .method, .selection, .moescore} 480 | ORDER BY mr.pval ; 481 | " 482 | 483 | endpoint <- "/cypher" 484 | params <- list(query = query) 485 | results_subset <- query_epigraphdb( 486 | route = endpoint, 487 | params = params, 488 | method = "POST", 489 | mode = "table" 490 | ) 491 | results_subset 492 | 493 | # check exposures in the results 494 | results_subset %>% count(exposure.id) 495 | ``` 496 | 497 |
498 | Great! You can now use the basic functionality of the R package and make simple Cypher queries to the API. Next, we recommend to work through the [case studies][3] and check out the [Web UI examples][8] and the [EpiGraphDB Gallery][9]. 499 | 500 | [1]: https://epigraphdb.org/about 501 | [2]: https://docs.epigraphdb.org/api/api-endpoints/ 502 | [3]: https://docs.epigraphdb.org/r-package/case-1-pleiotropy/ 503 | [4]: https://docs.epigraphdb.org/r-package/case-2-alt-drug-target/ 504 | [5]: https://docs.epigraphdb.org/r-package/case-3-literature-triangulation/ 505 | [6]: https://epigraphdb.org/mr 506 | [7]: https://docs.epigraphdb.org/graph-database/meta-nodes/#gwas 507 | [8]: https://epigraphdb.org/explore 508 | [9]: https://epigraphdb.org/gallery 509 | [10]: https://mrcieu.github.io/epigraphdb-r/articles/meta-functionalities.html 510 | [11]: https://docs.epigraphdb.org/graph-database/meta-nodes/ 511 | [12]: https://mrcieu.github.io/epigraphdb-r/index.html#package-functionalities 512 | -------------------------------------------------------------------------------- /vignettes_src/meta-functionalities.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Meta functionalities of the EpiGraphDB platform" 3 | output: rmarkdown::html_vignette 4 | vignette: > 5 | %\VignetteIndexEntry{Meta functionalities of the EpiGraphDB platform} 6 | %\VignetteEngine{knitr::rmarkdown} 7 | %\VignetteEncoding{UTF-8} 8 | --- 9 | 10 | ```{r, include = FALSE} 11 | knitr::opts_chunk$set( 12 | collapse = TRUE, 13 | comment = "#>" 14 | ) 15 | ``` 16 | 17 | This RMarkdown document demonstrates how key elements from the 18 | [github notebook for the meta functionalities]( 19 | https://github.com/MRCIEU/epigraphdb/blob/master/general-examples/platform-meta-functionalities.ipynb 20 | ) can be achieved using the R package. 21 | For detailed explanations of the case study please refer to the 22 | [notebook on github]( 23 | https://github.com/MRCIEU/epigraphdb/blob/master/general-examples/platform-meta-functionalities.ipynb 24 | ). 25 | 26 | Here we show the following aspects of the EpiGraphDB platform, and how to use the API to get the information: 27 | 28 | - Metadata: meta nodes and meta edges, and the overall schema. 29 | - Search for a specific node under the meta node. 30 | - Cypher: how to query the database directly using Neo4j Cypher 31 | 32 | For detailed documentation on the API endpoints please visit: 33 | 34 | - The Swagger interface: https://api.epigraphdb.org 35 | - The sections regarding API endpoints on the documentation site: 36 | https://docs.epigraphdb.org/api/api-endpoints/ 37 | 38 | ```{r} 39 | library("magrittr") 40 | library("dplyr") 41 | library("purrr") 42 | library("igraph") 43 | library("epigraphdb") 44 | ``` 45 | 46 | ## Metadata 47 | 48 | Here we query for the metadata information using the endpoint `GET /meta/schema`, which will be used for downstream processing. 49 | 50 | ```{r} 51 | endpoint <- "/meta/schema" 52 | params <- list( 53 | graphviz = FALSE, 54 | plot = FALSE 55 | ) 56 | metadata <- query_epigraphdb( 57 | route = endpoint, params = params, mode = "raw" 58 | ) 59 | 60 | metadata %>% str(2) 61 | ``` 62 | 63 | ### Meta nodes 64 | 65 | We can extract the specific meta node information as a dataframe from the metadata. 66 | 67 | ```{r} 68 | meta_node_df <- metadata %>% 69 | pluck("nodes") %>% 70 | { 71 | names <- names(.) 72 | transpose(.) %>% 73 | as_tibble() %>% 74 | mutate(meta_node = names) %>% 75 | # Hide properties column which does not display well 76 | select(meta_node, count) %>% 77 | # We also need to flatten count 78 | mutate(count = flatten_int(count)) 79 | } 80 | 81 | meta_node_df %>% 82 | arrange(meta_node) %>% 83 | mutate(count = format(count, big.mark = ",")) 84 | ``` 85 | 86 | ### Meta relationships and connections 87 | 88 | We can also extract the meta relationship (edge) information, and the connections. 89 | 90 | ```{r} 91 | meta_rel_df <- metadata %>% 92 | pluck("edges") %>% 93 | { 94 | names <- names(.) 95 | transpose(.) %>% 96 | as_tibble() %>% 97 | mutate(meta_rel = names) %>% 98 | mutate(count = flatten_int(count)) %>% 99 | select(meta_rel, count) 100 | } %>% 101 | inner_join( 102 | metadata %>% pluck("connections") %>% 103 | { 104 | transpose(.) %>% 105 | as_tibble() %>% 106 | mutate(meta_rel = flatten_chr(rel)) %>% 107 | mutate_at(vars(from_node, to_node), flatten_chr) %>% 108 | select(meta_rel, from_node, to_node) 109 | } 110 | ) 111 | 112 | meta_rel_df %>% 113 | arrange(from_node, to_node) %>% 114 | mutate(count = format(count, big.mark = ",")) 115 | ``` 116 | 117 | ## Search for specific node 118 | 119 | Users can use [the explorer on the Web UI](https://dev.epigraphdb.org/explore) to search for a specific node by: 120 | 121 | - fuzzy matching by "name" field. 122 | - exact matching by "ID" field if you know the its ID (e.g. the ID to a GWAS from IEU GWAS Database). 123 | 124 | Here we show how these are done at the API level using `Gwas` nodes as an example. 125 | 126 | First we need to know what the "ID" and "name" fields are for the meta nodes using `GET /meta/nodes/id-name-schema`: 127 | 128 | ```{r} 129 | endpoint <- "/meta/nodes/id-name-schema" 130 | meta_node_fields <- query_epigraphdb( 131 | route = endpoint, params = NULL, mode = "raw" 132 | ) 133 | meta_node_fields 134 | ``` 135 | 136 | ## Fuzzy matching 137 | 138 | Here we search for nodes can contain "body mass index" in their traits. 139 | 140 | ```{r} 141 | name <- "body mass index" 142 | 143 | endpoint <- "/meta/nodes/Gwas/search" 144 | params <- list(name = name) 145 | 146 | results <- query_epigraphdb( 147 | route = endpoint, params = params, mode = "table" 148 | ) 149 | results 150 | ``` 151 | 152 | ## Exact matching 153 | 154 | Similarly, we can exact match a specific node by its ID. 155 | 156 | ```{r} 157 | id <- "ieu-a-2" 158 | 159 | endpoint <- "/meta/nodes/Gwas/search" 160 | params <- list(id = id) 161 | 162 | results <- query_epigraphdb( 163 | route = endpoint, params = params, mode = "table" 164 | ) 165 | results 166 | ``` 167 | 168 | ## Cypher (advanced) 169 | 170 | Advanced users that are familiar with Neo4j Cypher can query the database using Cypher directly. 171 | 172 | ```{r} 173 | query <- " 174 | MATCH (exposure:Gwas)-[mr:MR]->(outcome:Gwas) 175 | WHERE exposure.trait = 'Body mass index' 176 | RETURN exposure, outcome, mr LIMIT 2 177 | " 178 | 179 | endpoint <- "/cypher" 180 | params <- list(query = query) 181 | 182 | # NOTE this is a POST request 183 | results <- query_epigraphdb( 184 | route = endpoint, params = params, method = "POST", 185 | mode = "table" 186 | ) 187 | results 188 | ``` 189 | 190 | 191 | ## `sessionInfo` 192 | 193 | ```{r} 194 | sessionInfo() 195 | ``` 196 | -------------------------------------------------------------------------------- /vignettes_src/options.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Options" 3 | output: rmarkdown::html_vignette 4 | vignette: > 5 | %\VignetteIndexEntry{Options} 6 | %\VignetteEngine{knitr::rmarkdown} 7 | %\VignetteEncoding{UTF-8} 8 | --- 9 | 10 | ```{r, include = FALSE} 11 | knitr::opts_chunk$set( 12 | collapse = TRUE, 13 | comment = "#>" 14 | ) 15 | ``` 16 | 17 | ## Change the API URL 18 | 19 | EpiGraphDB currently offers two API URLs 20 | 21 | - production (default): https://api.epigraphdb.org 22 | - development: http://dev-api.epigraphdb.org 23 | 24 | To switch to the development API, do 25 | 26 | ```r 27 | # Get default option 28 | default_api_url <- getOptions("epigraphdb.api.url") 29 | # Change to the development API 30 | options(epigraphdb.api.url = "http://dev-api.epigraphdb.org") 31 | # Verify current URL 32 | getOption("epigraphdb.api.url") 33 | # Switch back 34 | options(epigraphdb.api.url = default_api_url) 35 | ``` 36 | 37 | NOTE: you can make this change persistent by placing the changes in 38 | [`.Rprofile`](https://www.statmethods.net/interface/customizing.html). 39 | 40 | ## Suppress start up message 41 | 42 | If you would like to turn off the start up message that displays the current version of EpiGraphDB service, use the following code to load the package: 43 | 44 | ```r 45 | suppressPackageStartupMessages({library("epigraphdb")}) 46 | ``` 47 | -------------------------------------------------------------------------------- /vignettes_src/using-epigraphdb-api.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Using EpiGraphDB API" 3 | output: rmarkdown::html_vignette 4 | vignette: > 5 | %\VignetteIndexEntry{Using EpiGraphDB API} 6 | %\VignetteEngine{knitr::rmarkdown} 7 | %\VignetteEncoding{UTF-8} 8 | --- 9 | 10 | ```{r, include = FALSE} 11 | knitr::opts_chunk$set( 12 | collapse = TRUE, 13 | comment = "#>" 14 | ) 15 | ``` 16 | 17 | ## Introduction 18 | 19 | EpiGraphDB as a collated resource offers rich integrative epidemiological 20 | evidence for researchers to use, which can be queried from our 21 | [RESTful API service](https://api.epigraphdb.org). 22 | 23 | EpiGraphDB [web application](https://epigraphdb.org): 24 | 25 | ![web application](figures/epigraphdb-xqtl-view.png) 26 | 27 | EpiGraphDB [web API (OpenAPI / swagger interface)](https://api.epigraphdb.org): 28 | 29 | ![web API](figures/epigraphdb-api-swagger.png) 30 | 31 | The R package is designed to give users quick access to some of the 32 | key resources, but not as a comprehensive replacement of the web API. 33 | At the moment EpiGraphDB is still under fast and active development with 34 | frequent addition of new API endpoints that might not have corresponding 35 | functions available in the R package. 36 | 37 | In this tutorial we will discuss two alternative methods to get data from 38 | the EpiGraphDB web API -- using `httr` in R and 39 | using `curl` in the command line. 40 | 41 | ## Using `httr` 42 | 43 | Here are some examples of querying EpiGraphDB web API using 44 | [httr](https://httr.r-lib.org/reference/index.html): 45 | 46 | ```{r} 47 | library("epigraphdb") 48 | url <- getOption("epigraphdb.api.url") 49 | payload <- list( 50 | exposure_trait = "Body mass index", 51 | outcome_trait = "Coronary heart disease" 52 | ) 53 | r <- httr::RETRY("GET", glue::glue("{url}/mr"), query = payload) 54 | r %>% 55 | httr::content(as = "parsed") %>% 56 | str(2) 57 | ``` 58 | 59 | And this is the data structure as returned from the 60 | `epigraphdb::mr` call with `mode = "raw"`: 61 | 62 | ```{r epigraphdb-mr} 63 | epigraphdb::mr( 64 | exposure_trait = "Body mass index", 65 | outcome_trait = "Coronary heart disease", 66 | mode = "raw" 67 | ) %>% 68 | str(2) 69 | ``` 70 | 71 | In fact, currently the `epigraphdb::mr` function is a 72 | [wrapper](https://github.com/MRCIEU/epigraphdb-r/blob/master/R/mr.R) 73 | of `httr::get`. 74 | Please consult with 75 | [`httr` documentation](https://httr.r-lib.org/index.html) 76 | for details of usage. 77 | 78 | ## Using `curl` 79 | 80 | Here is an example in using `curl` to get data and using 81 | [`jq`](https://stedolan.github.io/jq/) for 82 | post processing the returned json data: 83 | 84 | ```shell 85 | curl -X 'GET' 'https://api.epigraphdb.org/mr?exposure=Body+mass+index&outcome=Coronary+heart+disease' | jq 86 | ``` 87 | 88 | The returned data will look like this: 89 | 90 | ```json 91 | { 92 | "query": "MATCH (t1:Gwas)-[r:MR]->(t2:Gwas) WHERE t1.trait = \"Body mass index\" AND t2.trait = \"Coronary heart disease\" AND r.p < 1e-05 RETURN t1.id AS exposure_id, t1.trait AS exposure_name, t2.id AS outcome_id, t2.trait AS outcome_name, r.estimate AS estimate, r.se AS se, r.p AS p, r.ci_upp as ci_upp, r.ci_low AS ci_low, r.selection AS selection, r.method AS method, r.moescore AS moescore ORDER BY r.p ;", 93 | "results": [ 94 | { 95 | "exposure_id": "974", 96 | "exposure_name": "Body mass index", 97 | "outcome_id": "7", 98 | "outcome_name": "Coronary heart disease", 99 | "estimate": 0.388519597717655, 100 | "se": 0.0493380883899318, 101 | "p": 3.41730166606158e-15, 102 | "ci_upp": 0.498022055339364, 103 | "ci_low": 0.279017140095947, 104 | "selection": "DF", 105 | "method": "FE IVW", 106 | "moescore": 0.89 107 | }, 108 | { 109 | "exposure_id": "2", 110 | "exposure_name": "Body mass index", 111 | "outcome_id": "7", 112 | "outcome_name": "Coronary heart disease", 113 | "estimate": 0.397101449275362, 114 | "se": 0.0727452867916401, 115 | "p": 4.79382740959139e-08, 116 | "ci_upp": 0.539679591432014, 117 | "ci_low": 0.25452330711871, 118 | "selection": "HF", 119 | "method": "Simple median", 120 | "moescore": 0.92 121 | }, 122 | { 123 | "exposure_id": "95", 124 | "exposure_name": "Body mass index", 125 | "outcome_id": "7", 126 | "outcome_name": "Coronary heart disease", 127 | "estimate": 0.454936804438897, 128 | "se": 0.0930665978652417, 129 | "p": 1.01714040121612e-06, 130 | "ci_upp": 0.637343984418443, 131 | "ci_low": 0.272529624459351, 132 | "selection": "DF", 133 | "method": "Penalised median", 134 | "moescore": 0.78 135 | }, 136 | { 137 | "exposure_id": "2", 138 | "exposure_name": "Body mass index", 139 | "outcome_id": "8", 140 | "outcome_name": "Coronary heart disease", 141 | "estimate": 0.330889761641503, 142 | "se": 0.0683874628196063, 143 | "p": 1.30851348920923e-06, 144 | "ci_upp": 0.47183747438535, 145 | "ci_low": 0.189942048897655, 146 | "selection": "DF", 147 | "method": "FE IVW", 148 | "moescore": 0.75 149 | }, 150 | { 151 | "exposure_id": "835", 152 | "exposure_name": "Body mass index", 153 | "outcome_id": "7", 154 | "outcome_name": "Coronary heart disease", 155 | "estimate": 0.359685792349727, 156 | "se": 0.0755689310372249, 157 | "p": 1.93876456579184e-06, 158 | "ci_upp": 0.507798175532879, 159 | "ci_low": 0.211573409166575, 160 | "selection": "Tophits", 161 | "method": "Simple median", 162 | "moescore": 0.91 163 | }, 164 | { 165 | "exposure_id": "974", 166 | "exposure_name": "Body mass index", 167 | "outcome_id": "8", 168 | "outcome_name": "Coronary heart disease", 169 | "estimate": 0.32847610101648, 170 | "se": 0.0730805223133059, 171 | "p": 6.96632705468264e-06, 172 | "ci_upp": 0.49537017731629, 173 | "ci_low": 0.16158202471667, 174 | "selection": "DF", 175 | "method": "FE IVW", 176 | "moescore": 0.85 177 | } 178 | ] 179 | } 180 | ``` 181 | 182 | ## Other methods 183 | 184 | Alternatively, you can use other commonly used tools to query the web API: 185 | 186 | - [command line: httpie](https://github.com/httpie/httpie) 187 | - [python: requests](https://realpython.com/python-requests/) 188 | - [GUI client: postman](https://www.guru99.com/postman-tutorial.html) 189 | 190 | For details of the EpiGraphDB RESTful API and related services, 191 | please visit our [documentation site](https://docs.epigraphdb.org). 192 | -------------------------------------------------------------------------------- /vignettes_src/using-epigraphdb-r-package.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Using EpiGraphDB R package" 3 | output: rmarkdown::html_vignette 4 | vignette: > 5 | %\VignetteIndexEntry{Using EpiGraphDB R package} 6 | %\VignetteEngine{knitr::rmarkdown} 7 | %\VignetteEncoding{UTF-8} 8 | --- 9 | 10 | ```{r, include = FALSE} 11 | knitr::opts_chunk$set( 12 | collapse = TRUE, 13 | comment = "#>" 14 | ) 15 | ``` 16 | 17 | ```{r setup} 18 | library("epigraphdb") 19 | ``` 20 | 21 | ## Methods to query EpiGraphDB 22 | 23 | We provide a 24 | [list of functions](https://mrcieu.github.io/epigraphdb-r/index.html#functionalities) 25 | that are equivalent to the 26 | [upstream API endpoints](https://api.epigraphdb.org) 27 | for users to use. 28 | For endpoints that don't have equivalent functions, users can use the 29 | [`query_epigraphdb`](https://mrcieu.github.io/epigraphdb-r/reference/query_epigraphdb.html) 30 | function. 31 | 32 | Here we show the two approaches to query MR data from EpiGraphDB, using the 33 | [`mr`](https://mrcieu.github.io/epigraphdb-r/reference/mr.html) function and 34 | using 35 | [`query_epigraphdb`](https://mrcieu.github.io/epigraphdb-r/reference/query_epigraphdb.html) 36 | to query the 37 | [`GET /mr`](https://docs.epigraphdb.org/api/api-endpoints/#get-mr) 38 | endpoint. 39 | 40 | ### `mr` 41 | 42 | ```{r} 43 | df <- mr( 44 | exposure_trait = "Body mass index", 45 | outcome_trait = "Coronary heart disease", 46 | mode = "table" 47 | ) 48 | df 49 | ``` 50 | 51 | ### `GET /mr` 52 | 53 | ```{r} 54 | df <- query_epigraphdb( 55 | route = "/mr", 56 | params = list( 57 | exposure_trait = "Body mass index", 58 | outcome_trait = "Coronary heart disease" 59 | ), 60 | mode = "table" 61 | ) 62 | 63 | df 64 | ``` 65 | 66 | For more information on the API endpoints, please visit: 67 | 68 | - The API Swagger interface https://api.epigraphdb.org 69 | - The documentation on API endpoints https://docs.epigraphdb.org/api/api-endpoints/ 70 | 71 | ## Returned data format 72 | 73 | As a general principle, we offer two modes of the returned data: 74 | a `table` mode (default) that returns a data frame, 75 | and a `raw` mode that preserves the hierarchical structure of the upstream 76 | json data and contains other information that might benefit users. 77 | 78 | ### `mode = "table"` 79 | 80 | By default, for ease of use, the query returns a data frame which is a 81 | tidyverse [`tibble`](https://tibble.tidyverse.org/): 82 | 83 | ```{r} 84 | df <- mr( 85 | exposure_trait = "Body mass index", 86 | outcome_trait = "Coronary heart disease" 87 | ) 88 | df 89 | ``` 90 | 91 | ### `mode = "raw"` 92 | 93 | Alternatively, you can use `results_type = "raw"` to get the unformatted 94 | response from EpiGraphDB API. 95 | 96 | ```{r} 97 | response <- mr( 98 | exposure_trait = "Body mass index", 99 | outcome_trait = "Coronary heart disease", 100 | mode = "raw" 101 | ) 102 | response %>% str(2) 103 | ``` 104 | 105 | There are several reasons that a `raw` mode might benefit you: 106 | 107 | 1. The `results` component preserves the upstream hierarchical json structure 108 | that might be useful for users aiming for specific tasks 109 | such as rendering network plots or batch post-processing the returned data 110 | in a large scale. 111 | 112 | 2. The `query` component returns 113 | the [cypher](https://neo4j.com/developer/cypher/) 114 | query that fetches data from the EpiGraphDB neo4j databases. 115 | EpiGraphDB will offer functionality (forthcoming) for users to 116 | send cypher queries to the web API that can return more complex query 117 | structure (visit our [web app](https://epigraphdb.org) for examples). 118 | Once you are sufficiently well-versed in cypher you can construct 119 | your own refined queries to better suit your needs. 120 | --------------------------------------------------------------------------------