--- title: "Querying ChEMBL Database" author: - name: Jermiah Joseph, Shahzada Muhammad Shameel Farooq, and Christopher Eeles output: BiocStyle::html_document: toc: true vignette: > %\VignetteIndexEntry{Querying ChEMBL Database} %\VignetteEngine{knitr::rmarkdown} %\VignetteEncoding{UTF-8} --- ```{r setup-options, include = FALSE} knitr::opts_chunk$set( collapse = TRUE, comment = "#>", crop = NULL ## Related to https://stat.ethz.ch/pipermail/bioc-devel/2020-April/016656.html ) run_chembl_example <- function(expr) { tryCatch( expr, httr2_failure = function(error) { message("ChEMBL example could not complete: ", conditionMessage(error)) NULL }, annotationgx_chembl_unavailable = function(error) { message("ChEMBL example could not complete: ", conditionMessage(error)) NULL } ) } ``` # Introduction to ChEMBL API **WARNING: This vignette is a work in progress. If you have questions or would like to see more features, please open an issue at [bhklab/AnnotationGx](https://github.com/bhklab/AnnotationGx)** The ChEMBL database contains information on bioactive drug-like small molecules. The information includes 2-D structures, calculated properties; logP, Molecular Weight, Lipinski Parameters, and abstracted bioactivities; binding constants and ADMET data. The data is curated from primary scientific literature. The ChEMBL API allows for the data to be made available for retrieval in a programmatic fashion. We can use the API to query CHEMBL ID of a compound, retrieve all molecule mechanisms of action, query compound_record resource and molecule resource from the ChEMBL database. ## Licensing ChEMBL is licensed under [CC BY-SA 3.0](https://creativecommons.org/licenses/by-sa/3.0/). Source: https://www.ebi.ac.uk/chembl/ ## Setup ```{r setup-package} library(AnnotationGx) ``` ## Retrieve molecule mechanisms of action from ChEMBL {#chembl-mechanisms} Given a ChEMBL ID, we can retrieve the molecule mechanisms of action from the ChEMBL database using the `getChemblMechanism()` function. ** NOTE: This is a specialized function that queries the API for the *mechanism* resource only. To query other resources, please see the [Custom Queries](#custom-queries) section. ** ```{r single-query} mechs <- run_chembl_example(getChemblMechanism("CHEMBL1413")) mechs ``` When ChEMBL is available, this example returns mechanisms of action. Live examples report request failures and allow the vignette to continue if the service is unavailable. ## Custom Queries {#custom-queries} The ChEMBL API allows for a wide range of queries. We have specialized one function, but are open to incorporating more. Please open an issue at [bhklab/AnnotationGx](https://github.com/bhklab/AnnotationGx) with an idea of a specialized function that meets a use case. A query to the API follows the following format: ``` https://www.ebi.ac.uk/chembl/api/data/[resource]?[field]__[filter_type]=[value]&format=[format] ``` More information can be found at the [API Documentation](https://chembl.gitbook.io/chembl-interface-documentation/web-services/chembl-data-web-services) In summary, the requirements for a query are: 1. The `resource` to be queried 2. The resource `field` to be queried 3. The `filter_type` to be used 4. The `value` to be used for the filter 5. (optional) The `format` of the returned data (default is JSON) For example, the query for the example in [the above section](#chembl-mechanisms) would be: "https://www.ebi.ac.uk/chembl/api/data/mechanism?molecule_chembl_id__in=CHEMBL1413&format=json" where: - `resource` is "mechanism" - `field` is "molecule_chembl_id" - `filter_type` is "in" - `value` is "CHEMBL1413" - `format` is "json" These parameters can be used in the `queryChemblAPI(resource, field, filter_type, value, format = "json")` function to query the ChEMBL API. **NOTE: unlike the `getChemblMechanism()` function which returns a `data.table`, the `queryChemblAPI()` function returns the raw data unformatted** ```{r custom-query} run_chembl_example( queryChemblAPI("mechanism", "molecule_chembl_id", "in", "CHEMBL1413") ) ``` The `getChemblResources()` function returns a list of possible resources that can be queried: ```{r chembl-resources} getChemblResources() ``` The `getChemblResourceFields(resource)` function returns a list of possible fields that can be queried for a given resource: ```{r resource-fields} run_chembl_example(getChemblResourceFields("mechanism")) ``` The `getChemblFilterTypes()` function returns a list of possible filter types. ```{r filter-types} getChemblFilterTypes() ``` ```{r session-info} sessionInfo() ```