Querying ChEMBL Database

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

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. Source: https://www.ebi.ac.uk/chembl/

Setup

library(AnnotationGx)

Retrieve molecule mechanisms of action from ChEMBL

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 section.

mechs <- run_chembl_example(getChemblMechanism("CHEMBL1413"))
#> [01:17:04][INFO][AnnotationGx::getChemblMechanism] Retrieving ChEMBL Mechanism information for  1  ChEMBL IDs.
#> ChEMBL example could not complete: ChEMBL service unavailable: HTTP 500.
mechs
#> NULL

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

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 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

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 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

run_chembl_example(
  queryChemblAPI("mechanism", "molecule_chembl_id", "in", "CHEMBL1413")
)
#> ChEMBL example could not complete: ChEMBL service unavailable: HTTP 500.
#> NULL

The getChemblResources() function returns a list of possible resources that can be queried:

getChemblResources()
#>  [1] "activity"                  "assay"                    
#>  [3] "atc_class"                 "binding_site"             
#>  [5] "biotherapeutic"            "cell_line"                
#>  [7] "chembl_id_lookup"          "compound_record"          
#>  [9] "compound_structural_alert" "document"                 
#> [11] "document_similarity"       "document_term"            
#> [13] "drug"                      "drug_indication"          
#> [15] "drug_warning"              "go_slim"                  
#> [17] "image"                     "mechanism"                
#> [19] "metabolism"                "molecule"                 
#> [21] "molecule_form"             "organism"                 
#> [23] "protein_classification"    "similarity"               
#> [25] "source"                    "status"                   
#> [27] "substructure"              "target"                   
#> [29] "target_component"          "target_relation"          
#> [31] "tissue"                    "xref_source"

The getChemblResourceFields(resource) function returns a list of possible fields that can be queried for a given resource:

run_chembl_example(getChemblResourceFields("mechanism"))
#>  [1] "action_type"               "binding_site_comment"     
#>  [3] "direct_interaction"        "disease_efficacy"         
#>  [5] "max_phase"                 "mec_id"                   
#>  [7] "mechanism_comment"         "mechanism_of_action"      
#>  [9] "mechanism_refs"            "molecular_mechanism"      
#> [11] "molecule_chembl_id"        "parent_molecule_chembl_id"
#> [13] "record_id"                 "selectivity_comment"      
#> [15] "site_id"                   "target_chembl_id"         
#> [17] "variant_sequence"

The getChemblFilterTypes() function returns a list of possible filter types.

getChemblFilterTypes()
#>  [1] "exact"       "iexact"      "contains"    "icontains"   "startswith" 
#>  [6] "istartswith" "endswith"    "iendswith"   "regex"       "iregex"     
#> [11] "gt"          "gte"         "lt"          "lte"         "range"      
#> [16] "in"          "isnull"      "search"      "only"
sessionInfo()
#> R version 4.6.2 (2026-10-29)
#> Platform: x86_64-pc-linux-gnu
#> Running under: Ubuntu 26.04.1 LTS
#> 
#> Matrix products: default
#> BLAS:   /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3 
#> LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.32.so;  LAPACK version 3.12.0
#> 
#> locale:
#>  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
#>  [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
#>  [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
#>  [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
#>  [9] LC_ADDRESS=C               LC_TELEPHONE=C            
#> [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       
#> 
#> time zone: Etc/UTC
#> tzcode source: system (glibc)
#> 
#> attached base packages:
#> [1] stats     graphics  grDevices utils     datasets  methods   base     
#> 
#> other attached packages:
#> [1] data.table_1.18.6.1  AnnotationGx_0.99.15 BiocStyle_2.41.0    
#> 
#> loaded via a namespace (and not attached):
#>  [1] bit_4.6.0           jsonlite_2.0.0      crayon_1.5.3       
#>  [4] dplyr_1.2.1         compiler_4.6.2      BiocManager_1.30.27
#>  [7] filelock_1.0.3      tidyselect_1.2.1    blob_1.3.0         
#> [10] parallel_4.6.2      jquerylib_0.1.4     yaml_2.3.12        
#> [13] fastmap_1.2.0       R6_2.6.1            generics_0.1.4     
#> [16] curl_8.1.0          httr2_1.3.0         knitr_1.52         
#> [19] backports_1.5.1     checkmate_2.3.4     tibble_3.3.1       
#> [22] maketools_1.3.2     DBI_1.3.0           bslib_0.12.0       
#> [25] pillar_1.11.1       rlang_1.3.0         cachem_1.1.0       
#> [28] xfun_0.62           sass_0.5.0          sys_3.4.3          
#> [31] bit64_4.8.6         otel_0.3.0          RSQLite_3.53.3     
#> [34] memoise_2.0.1       cli_3.6.6           withr_3.0.3        
#> [37] magrittr_2.0.5      digest_0.6.39       dbplyr_2.6.0       
#> [40] lifecycle_1.0.5     BiocFileCache_3.3.3 vctrs_0.7.3        
#> [43] evaluate_1.0.5      glue_1.8.1          buildtools_1.0.0   
#> [46] purrr_1.2.2         rmarkdown_2.32      tools_4.6.2        
#> [49] pkgconfig_2.0.3     htmltools_0.5.9