Skip to content

Commit 7691f4c

Browse files
committed
fix: remove deprecated mapCompound2CTD function and related documentation
1 parent f6779a8 commit 7691f4c

File tree

5 files changed

+119
-164
lines changed

5 files changed

+119
-164
lines changed

NAMESPACE

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ export(getUnichemSources)
2222
export(mapCID2Properties)
2323
export(mapCell2Accession)
2424
export(mapCompound2CID)
25-
export(mapCompound2CTD)
2625
export(matchNested)
2726
export(queryChemblAPI)
2827
export(queryUnichemCompound)

R/CancerTargetDiscovery.R

Lines changed: 83 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,93 +1,96 @@
1-
# CancerTargetDiscoveryDevelopment Functions
1+
# NOTE: This file is deprecated until the Cancer Target Discovery and Development (CTD2) works again
2+
# as of today, the https://ctd2-dashboard.nci.nih.gov/ doesnt work at all
23

3-
#' Map Compound to CTD
4-
#'
5-
#' This function maps a drug compound to the Cancer Target Discovery (CTD) database.
6-
#' It retrieves information about the compound from the CTD database and returns the results as a data table.
7-
#'
8-
#' @param compounds A character vector of drug compounds to map to the CTD database.
9-
#' @param base_url The base URL of the CTD API. Default is "https://ctd2-dashboard.nci.nih.gov/dashboard/get".
10-
#' @param endpoint The API endpoint for the compound mapping. Default is "compound".
11-
#' @param nParallel The number of parallel processes to use. Default is one less than the number of available cores.
12-
#' @param raw Logical indicating whether to return the raw response from the API. Default is FALSE.
13-
#' @param query_only Logical indicating whether to only return the API request URL without making the actual request. Default is FALSE.
14-
#'
15-
#' @return A data table containing the mapped information for the drug compound.
16-
#' If the API request fails, a data table with the drug compound name will be returned.
17-
#' If \code{raw} is set to TRUE, the raw response from the API will be returned.
18-
#'
19-
#' @export
20-
mapCompound2CTD <- function(
21-
compounds,
22-
base_url = "https://ctd2-dashboard.nci.nih.gov/dashboard/get",
23-
endpoint = "compound",
24-
nParallel = parallel::detectCores() - 1,
25-
raw = FALSE,
26-
query_only = FALSE
27-
) {
28-
# March 06 2025:
29-
# this function is deprecated until
30-
# the Cancer Target Discovery and Development (CTD2) works again
31-
# as of today, the https://ctd2-dashboard.nci.nih.gov/ doesnt work at all
32-
# we will raise an error for now
33-
errmsg <- "The CTD2 API is currently not working. Please check the status of the API at https://ctd2-dashboard.nci.nih.gov/"
34-
stop(errmsg)
354

36-
funContext <- .funContext("mapCompound2CTD")
37-
38-
# Check input types
39-
checkmate::assert_character(compounds)
40-
checkmate::assert_character(base_url)
41-
checkmate::assert_character(endpoint)
42-
checkmate::assert_logical(raw)
43-
checkmate::assert_logical(query_only)
5+
# # CancerTargetDiscoveryDevelopment Functions
446

45-
.info(funContext,
46-
sprintf("Creating requests for %s compounds", length(compounds)))
7+
# #' Map Compound to CTD
8+
# #'
9+
# #' This function maps a drug compound to the Cancer Target Discovery (CTD) database.
10+
# #' It retrieves information about the compound from the CTD database and returns the results as a data table.
11+
# #'
12+
# #' @param compounds A character vector of drug compounds to map to the CTD database.
13+
# #' @param base_url The base URL of the CTD API. Default is "https://ctd2-dashboard.nci.nih.gov/dashboard/get".
14+
# #' @param endpoint The API endpoint for the compound mapping. Default is "compound".
15+
# #' @param nParallel The number of parallel processes to use. Default is one less than the number of available cores.
16+
# #' @param raw Logical indicating whether to return the raw response from the API. Default is FALSE.
17+
# #' @param query_only Logical indicating whether to only return the API request URL without making the actual request. Default is FALSE.
18+
# #'
19+
# #' @return A data table containing the mapped information for the drug compound.
20+
# #' If the API request fails, a data table with the drug compound name will be returned.
21+
# #' If \code{raw} is set to TRUE, the raw response from the API will be returned.
22+
# #'
23+
# #' @export
24+
# mapCompound2CTD <- function(
25+
# compounds,
26+
# base_url = "https://ctd2-dashboard.nci.nih.gov/dashboard/get",
27+
# endpoint = "compound",
28+
# nParallel = parallel::detectCores() - 1,
29+
# raw = FALSE,
30+
# query_only = FALSE
31+
# ) {
32+
# # March 06 2025:
33+
# # this function is deprecated until
34+
# # the Cancer Target Discovery and Development (CTD2) works again
35+
# # as of today, the https://ctd2-dashboard.nci.nih.gov/ doesnt work at all
36+
# # we will raise an error for now
37+
# errmsg <- "The CTD2 API is currently not working. Please check the status of the API at https://ctd2-dashboard.nci.nih.gov/"
38+
# stop(errmsg)
4739

48-
requests <- parallel::mclapply(compounds, function(compound){
49-
compound <- gsub(" ", "-", compound)
40+
# funContext <- .funContext("mapCompound2CTD")
5041

51-
.buildURL(base_url, endpoint, compound) |>
52-
.build_request()
53-
})
54-
if(query_only) return(requests)
42+
# # Check input types
43+
# checkmate::assert_character(compounds)
44+
# checkmate::assert_character(base_url)
45+
# checkmate::assert_character(endpoint)
46+
# checkmate::assert_logical(raw)
47+
# checkmate::assert_logical(query_only)
5548

56-
.info(funContext, "Performing requests w/", nParallel, "parallel processes..")
57-
resps <- .perform_request_parallel(requests)
58-
names(resps) <- compounds
49+
# .info(funContext,
50+
# sprintf("Creating requests for %s compounds", length(compounds)))
5951

60-
results <- parallel::mclapply(
61-
names(resps) ,
62-
function(compound){
63-
resp <- resps[[compound]]
52+
# requests <- parallel::mclapply(compounds, function(compound){
53+
# compound <- gsub(" ", "-", compound)
6454

65-
if(all(class(resp) != "httr2_response") || resp$status_code != 200){
66-
dt <- data.table::data.table(
67-
displayName = compound)
68-
return(dt)
69-
}
55+
# .buildURL(base_url, endpoint, compound) |>
56+
# .build_request()
57+
# })
58+
# if(query_only) return(requests)
7059

71-
resp <- .parse_resp_json(resp)
72-
if(raw) return(resp)
60+
# .info(funContext, "Performing requests w/", nParallel, "parallel processes..")
61+
# resps <- .perform_request_parallel(requests)
62+
# names(resps) <- compounds
7363

74-
original_dt <- .asDT(resp$xrefs)[, c("databaseId", "databaseName")]
75-
original_dt[, "displayName" := resp$displayName]
64+
# results <- parallel::mclapply(
65+
# names(resps) ,
66+
# function(compound){
67+
# resp <- resps[[compound]]
7668

77-
dt <- data.table::dcast(
78-
original_dt,
79-
formula = displayName ~ databaseName,
80-
value.var = "databaseId"
81-
)
82-
return(dt)
83-
},
84-
mc.cores = nParallel
85-
)
86-
if(raw) {
87-
names(results) <- compounds
88-
return(results)
89-
}
69+
# if(all(class(resp) != "httr2_response") || resp$status_code != 200){
70+
# dt <- data.table::data.table(
71+
# displayName = compound)
72+
# return(dt)
73+
# }
9074

91-
return(data.table::rbindlist(results, fill = TRUE))
92-
}
75+
# resp <- .parse_resp_json(resp)
76+
# if(raw) return(resp)
9377

78+
# original_dt <- .asDT(resp$xrefs)[, c("databaseId", "databaseName")]
79+
# original_dt[, "displayName" := resp$displayName]
80+
81+
# dt <- data.table::dcast(
82+
# original_dt,
83+
# formula = displayName ~ databaseName,
84+
# value.var = "databaseId"
85+
# )
86+
# return(dt)
87+
# },
88+
# mc.cores = nParallel
89+
# )
90+
# if(raw) {
91+
# names(results) <- compounds
92+
# return(results)
93+
# }
94+
95+
# return(data.table::rbindlist(results, fill = TRUE))
96+
# }

man/mapCompound2CTD.Rd

Lines changed: 0 additions & 37 deletions
This file was deleted.
Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
1-
library(AnnotationGx)
2-
library(testthat)
3-
library(checkmate)
1+
# library(AnnotationGx)
2+
# library(testthat)
3+
# library(checkmate)
44

5-
test_that("mapCompound2CTD returns expected results", {
6-
expect_error(mapCompound2CTD("Invalid Compound", nParallel = 1))
7-
# deprecated for now:
8-
# # Test case 1: Single compound mapping
9-
# compounds <- c("Bax channel blocker")
10-
# result <- mapCompound2CTD(compounds, nParallel = 1)
11-
# expect_true("displayName" %in% names(result))
12-
# expect_true("PUBCHEM" %in% names(result))
5+
# test_that("mapCompound2CTD returns expected results", {
6+
# expect_error(mapCompound2CTD("Invalid Compound", nParallel = 1))
7+
# # deprecated for now:
8+
# # # Test case 1: Single compound mapping
9+
# # compounds <- c("Bax channel blocker")
10+
# # result <- mapCompound2CTD(compounds, nParallel = 1)
11+
# # expect_true("displayName" %in% names(result))
12+
# # expect_true("PUBCHEM" %in% names(result))
1313

14-
# result2 <- mapCompound2CTD(compounds, nParallel = 1, query_only = TRUE)
15-
# checkmate::assert_list(result2, min.len = 1)
16-
# checkmate::assert_class(result2[[1]], "httr2_request")
14+
# # result2 <- mapCompound2CTD(compounds, nParallel = 1, query_only = TRUE)
15+
# # checkmate::assert_list(result2, min.len = 1)
16+
# # checkmate::assert_class(result2[[1]], "httr2_request")
1717

18-
# result3 <- mapCompound2CTD(compounds, nParallel = 1, raw = TRUE)
19-
# checkmate::assert_list(result3, min.len = 1)
20-
# expect_equal(result3[[1]]$class, "Compound")
21-
# expect_equal(result3[[1]]$displayName, "Bax channel blocker")
18+
# # result3 <- mapCompound2CTD(compounds, nParallel = 1, raw = TRUE)
19+
# # checkmate::assert_list(result3, min.len = 1)
20+
# # expect_equal(result3[[1]]$class, "Compound")
21+
# # expect_equal(result3[[1]]$displayName, "Bax channel blocker")
2222

23-
# # Test case 3: Invalid compound mapping
24-
# compounds <- c("Invalid Compound")
25-
# result4 <- mapCompound2CTD(compounds, nParallel = 1)
26-
# expect_true("displayName" %in% names(result4))
27-
# checkmate::expect_data_table(result4, min.cols = 1, min.rows = 1)
28-
})
23+
# # # Test case 3: Invalid compound mapping
24+
# # compounds <- c("Invalid Compound")
25+
# # result4 <- mapCompound2CTD(compounds, nParallel = 1)
26+
# # expect_true("displayName" %in% names(result4))
27+
# # checkmate::expect_data_table(result4, min.cols = 1, min.rows = 1)
28+
# })

vignettes/articles/CTRP-Treatment-Annotation.Rmd

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,21 @@ title: "Annotating CTRP Treatments"
66

77
This vignette compares annotating CTRP-provided treatment ids to PubChem CIDs and CTD information.
88

9-
Whereas the PubChem CID is a unique identifier for a compound, the PubChem API does not easily map
10-
treatment names to CIDs, atleast not in a way that easy for commonly misnamed treatments.
11-
Specifically, for the **CTRP** treatment names (n=545), the PubChem API does not correctly map
9+
Whereas the PubChem CID is a unique identifier for a compound, the PubChem API does not easily map
10+
treatment names to CIDs, atleast not in a way that easy for commonly misnamed treatments.
11+
Specifically, for the **CTRP** treatment names (n=545), the PubChem API does not correctly map
1212
all of them to PubChem CIDs.
13-
14-
The [CTD2](https://ctd2-dashboard.nci.nih.gov/dashboard) database is the central database where **CTRP**
15-
data is hosted. They happen to expose (an API)[https://ctd2-dashboard.nci.nih.gov/dashboard/#api-documentation]
16-
for their database.
13+
<!--
14+
NOTE: As of March 27, 2025, the CTD2 database is not available. The API is not available.
15+
The [CTD2](https://ctd2-dashboard.nci.nih.gov/dashboard) database is the central database where **CTRP**
16+
data is hosted. They happen to expose [an API](https://ctd2-dashboard.nci.nih.gov/dashboard/#api-documentation)
17+
for their database.
1718
1819
Developer Note: The API calls they describe on their API documentation is useful, but they have an endpoint:
1920
`GET /compound/{compoundId}` that is not documented. This endpoint is useful for mapping compound names in the way
2021
their data (i.e CTRP) names them to PubChem CIDs.
2122
22-
The functionality for this is implemented in the `mapCompound2CTD` function.
23+
The functionality for this is implemented in the `mapCompound2CTD` function. -->
2324

2425
It is an investigation to see which of the methods might map more compounds
2526

@@ -30,46 +31,37 @@ knitr::opts_chunk$set(
3031
)
3132
```
3233

33-
3434
```{r setup}
3535
library(AnnotationGx)
3636
3737
data(CTRP_treatmentMetadata)
3838
```
3939

40-
41-
4240
``` {r test_both}
4341
4442
# get a random row from the CTRP_treatmentMetadata
4543
4644
treatment <- CTRP_treatmentMetadata[1, CTRP.treatmentid]
4745
sprintf("CTRP treatment id : %s", treatment)
4846
49-
# map the treatment to a CID using the CTD database
50-
mapCompound2CTD(treatment)[, .(displayName, PUBCHEM)]
51-
52-
5347
# map the treatment to a CID using PubChem
5448
mapCompound2CID(treatment)
5549
5650
```
57-
58-
51+
<!--
5952
# Annotating using the CTD database
6053
61-
6254
```{r run_CTD}
6355
result <- CTRP_treatmentMetadata[, mapCompound2CTD(CTRP.treatmentid, query_only = F, raw = F)]
6456
6557
show(result)
6658
message("Failed results: ", result[is.na(result$PUBCHEM), .N])
6759
6860
failed_names <- result[is.na(result$PUBCHEM),displayName]
69-
```
70-
61+
``` -->
7162

7263
# Annotating using PubChem
64+
7365
``` {r run_CTRP_Pubchem, eval = FALSE}
7466
(compounds_to_cids <-
7567
CTRP_treatmentMetadata[,
@@ -84,8 +76,6 @@ failed <-
8476
names()
8577
```
8678

87-
88-
8979
``` {r Pubchem Failed, eval = FALSE}
9080
failed <- unique(CTRP_treatmentMetadata[CTRP.treatmentid %in% failed, ])
9181

0 commit comments

Comments
 (0)