@@ -191,6 +191,7 @@ chembl_files <- function(version = "latest") {
191191# ' @param query character; a vector of ChEMBL IDs.
192192# ' @param resource character; the ChEMBL resource to query. Use
193193# ' [chembl_resources()] to see all available resources.
194+ # ' @param tidy logical; attempt to convert output to a simpler structure.
194195# ' @param cache_file character; the name of the cache file without the file
195196# ' extension. If \code{NULL}, results are not cached.
196197# ' @param verbose logical; should a verbose output be printed on the console?
@@ -245,8 +246,8 @@ chembl_files <- function(version = "latest") {
245246# ' chembl_query("CHEMBL1", resource = "chembl_id_lookup")
246247# ' # Resource: compound_record - requires record ID
247248# ' chembl_query("1", resource = "compound_record")
248- # ' # Resource: compound_structural_alert - requires compound structural alert ID
249- # ' chembl_query("79048021 ", resource = "compound_structural_alert")
249+ # ' # Resource: compound_structural_alert - requires compound ChEMBL ID
250+ # ' chembl_query("CHEMBL266429 ", resource = "compound_structural_alert")
250251# ' # Resource: document - requires document ChEMBL ID
251252# ' chembl_query("CHEMBL1158643", resource = "document")
252253# ' # Resource: document_similarity - requires document 1 ChEMBL ID
@@ -294,6 +295,7 @@ chembl_files <- function(version = "latest") {
294295# ' @export
295296chembl_query <- function (query ,
296297 resource = " molecule" ,
298+ tidy = TRUE ,
297299 cache_file = NULL ,
298300 similarity = 70 ,
299301 verbose = getOption(" verbose" ),
@@ -317,17 +319,16 @@ chembl_query <- function(query,
317319 query <- chembl_validate_query(query , resource , verbose )
318320 if (is.na(query )) return (NA )
319321 if (verbose ) webchem_message(" query" , query , appendLF = FALSE )
320- if (resource == " similarity" ) {
321- url <- ifelse(
322- test_service_down , " " ,
323- paste0(stem , " /" , resource , " /" , query , " /" , similarity , " .json" )
324- )
322+ if (test_service_down ) {
323+ url <- " "
324+ } else if (resource == " similarity" ) {
325+ url <- paste0(stem , " /" , resource , " /" , query , " /" , similarity , " .json" )
326+ } else if (resource == " compound_structural_alert" ) {
327+ url <- paste0(stem , " /" , resource , " .json?molecule_chembl_id=" , query )
325328 } else {
326- url <- ifelse(
327- test_service_down , " " ,
328- paste0(stem , " /" , resource , " /" , query , " .json" )
329- )
329+ url <- paste0(stem , " /" , resource , " /" , query , " .json" )
330330 }
331+
331332 webchem_sleep(type = " API" )
332333 res <- try(httr :: RETRY(" GET" ,
333334 url ,
@@ -344,7 +345,9 @@ chembl_query <- function(query,
344345 }
345346 if (verbose ) message(httr :: message_for_status(res ))
346347 cont <- httr :: content(res , type = " application/json" )
347- cont <- format_chembl(cont )
348+ if (tidy ) {
349+ cont <- format_chembl(cont )
350+ }
348351 return (cont )
349352 }
350353 if (is.null(cache_file )) {
@@ -488,7 +491,6 @@ chembl_validate_query <- function(query, resource, verbose) {
488491 " activity" ,
489492 " binding_site" ,
490493 " compund_record" ,
491- " compound_structural_alert" ,
492494 " drug_indication" ,
493495 " drug_warning" ,
494496 " mechanism" ,
@@ -506,6 +508,7 @@ chembl_validate_query <- function(query, resource, verbose) {
506508 " assay" ,
507509 " biotherapeutic" ,
508510 " chembl_id_lookup" ,
511+ " compound_structural_alert" ,
509512 " document" ,
510513 " document_similarity" ,
511514 " drug" ,
@@ -621,6 +624,7 @@ format_chembl <- function(cont) {
621624 " biotherapeutic" ,
622625 " biocomponents" ,
623626 " chembl_release" ,
627+ " compound_structural_alerts" ,
624628 " cross_references" ,
625629 " go_slims" ,
626630 " indication_refs" ,
@@ -844,7 +848,7 @@ chembl_example_query <- function(resource) {
844848 cell_line = c(" CHEMBL3307241" , " CHEMBL3307242" ),
845849 chembl_id_lookup = " CHEMBL1" ,
846850 compound_record = " 1" ,
847- compound_structural_alert = " 79048021 " ,
851+ compound_structural_alert = " CHEMBL266429 " ,
848852 document = c(" CHEMBL1158643" , " CHEMBL1132398" , " CHEMBL5303573" , " CHEMBL3639173" ),
849853 document_similarity = " CHEMBL1148466" ,
850854 drug = " CHEMBL2" ,
0 commit comments