|
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 |
2 | 3 |
|
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) |
35 | 4 |
|
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 |
44 | 6 |
|
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) |
47 | 39 |
|
48 | | - requests <- parallel::mclapply(compounds, function(compound){ |
49 | | - compound <- gsub(" ", "-", compound) |
| 40 | +# funContext <- .funContext("mapCompound2CTD") |
50 | 41 |
|
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) |
55 | 48 |
|
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))) |
59 | 51 |
|
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) |
64 | 54 |
|
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) |
70 | 59 |
|
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 |
73 | 63 |
|
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]] |
76 | 68 |
|
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 | +# } |
90 | 74 |
|
91 | | - return(data.table::rbindlist(results, fill = TRUE)) |
92 | | -} |
| 75 | +# resp <- .parse_resp_json(resp) |
| 76 | +# if(raw) return(resp) |
93 | 77 |
|
| 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 | +# } |
0 commit comments