-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wrappers for bioentity endpoints and tests
- Loading branch information
Showing
2 changed files
with
197 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
|
||
#' Call API to get UniProt IDs from UniProt mnemonic IDs | ||
#' @param uniprotMnemonicIds list of UniProt mnemonic ids | ||
#' @return list of UniProt IDs | ||
#' @importFrom jsonlite toJSON | ||
#' @importFrom httr POST add_headers content | ||
#' @keywords internal | ||
#' @noRd | ||
.callGetUniprotIdsFromUniprotMnemonicIdsApi <- function(uniprotMnemonicIds) { | ||
apiUrl <- "http://localhost:5000/api/get_uniprot_ids_from_uniprot_mnemonic_ids" | ||
|
||
requestBody <- list(uniprot_mnemonic_ids = uniprotMnemonicIds) | ||
requestBody <- jsonlite::toJSON(requestBody, auto_unbox = TRUE) | ||
|
||
res <- POST( | ||
apiUrl, | ||
body = requestBody, | ||
add_headers("Content-Type" = "application/json"), | ||
encode = "raw" | ||
) | ||
res <- content(res) | ||
return(res) | ||
} | ||
|
||
#' Call API to get HGNC IDs from UniProt IDs | ||
#' @param uniprotIds list of UniProt IDs | ||
#' @return list of HGNC IDs | ||
#' @importFrom jsonlite toJSON | ||
#' @importFrom httr POST add_headers content | ||
#' @keywords internal | ||
#' @noRd | ||
.callGetHgncIdsFromUniprotIdsApi <- function(uniprotIds) { | ||
apiUrl <- "http://localhost:5000/api/get_hgnc_ids_from_uniprot_ids" | ||
|
||
requestBody <- list(uniprot_ids = uniprotIds) | ||
requestBody <- jsonlite::toJSON(requestBody, auto_unbox = TRUE) | ||
|
||
res <- POST( | ||
apiUrl, | ||
body = requestBody, | ||
add_headers("Content-Type" = "application/json"), | ||
encode = "raw" | ||
) | ||
res <- content(res) | ||
return(res) | ||
} | ||
|
||
#' Call API to get HGNC names from HGNC IDs | ||
#' @param hgncIds list of HGNC IDs | ||
#' @return list of HGNC names | ||
#' @importFrom jsonlite toJSON | ||
#' @importFrom httr POST add_headers content | ||
#' @keywords internal | ||
#' @noRd | ||
.callGetHgncNamesFromHgncIdsApi <- function(hgncIds) { | ||
apiUrl <- "http://localhost:5000/api/get_hgnc_names_from_hgnc_ids" | ||
|
||
requestBody <- list(hgnc_ids = hgncIds) | ||
requestBody <- jsonlite::toJSON(requestBody, auto_unbox = TRUE) | ||
|
||
res <- POST( | ||
apiUrl, | ||
body = requestBody, | ||
add_headers("Content-Type" = "application/json"), | ||
encode = "raw" | ||
) | ||
res <- content(res) | ||
return(res) | ||
} | ||
|
||
#' Call API to check if genes are kinases | ||
#' @param genes list of gene names | ||
#' @return list indicating if genes are kinases | ||
#' @importFrom jsonlite toJSON | ||
#' @importFrom httr POST add_headers content | ||
#' @keywords internal | ||
#' @noRd | ||
.callIsKinaseApi <- function(genes) { | ||
apiUrl <- "http://localhost:5000/api/is_kinase" | ||
|
||
requestBody <- list(genes = genes) | ||
requestBody <- jsonlite::toJSON(requestBody, auto_unbox = TRUE) | ||
|
||
res <- POST( | ||
apiUrl, | ||
body = requestBody, | ||
add_headers("Content-Type" = "application/json"), | ||
encode = "raw" | ||
) | ||
res <- content(res) | ||
return(res) | ||
} | ||
|
||
#' Call API to check if genes are phosphatases | ||
#' @param genes list of gene names | ||
#' @return list indicating if genes are phosphatases | ||
#' @importFrom jsonlite toJSON | ||
#' @importFrom httr POST add_headers content | ||
#' @keywords internal | ||
#' @noRd | ||
.callIsPhosphataseApi <- function(genes) { | ||
apiUrl <- "http://localhost:5000/api/is_phosphatase" | ||
|
||
requestBody <- list(genes = genes) | ||
requestBody <- jsonlite::toJSON(requestBody, auto_unbox = TRUE) | ||
|
||
res <- POST( | ||
apiUrl, | ||
body = requestBody, | ||
add_headers("Content-Type" = "application/json"), | ||
encode = "raw" | ||
) | ||
res <- content(res) | ||
return(res) | ||
} | ||
|
||
#' Call API to check if genes are transcription factors | ||
#' @param genes list of gene names | ||
#' @return list indicating if genes are transcription factors | ||
#' @importFrom jsonlite toJSON | ||
#' @importFrom httr POST add_headers content | ||
#' @keywords internal | ||
#' @noRd | ||
.callIsTranscriptionFactorApi <- function(genes) { | ||
apiUrl <- "http://localhost:5000/api/is_transcription_factor" | ||
|
||
requestBody <- list(genes = genes) | ||
requestBody <- jsonlite::toJSON(requestBody, auto_unbox = TRUE) | ||
|
||
res <- POST( | ||
apiUrl, | ||
body = requestBody, | ||
add_headers("Content-Type" = "application/json"), | ||
encode = "raw" | ||
) | ||
res <- content(res) | ||
return(res) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# Test .callGetUniprotIdsFromUniprotMnemonicIdsApi | ||
test_that(".callGetUniprotIdsFromUniprotMnemonicIdsApi works correctly", { | ||
uniprotMnemonicIds <- list("CLH1_HUMAN") | ||
result <- .callGetUniprotIdsFromUniprotMnemonicIdsApi(uniprotMnemonicIds) | ||
expect_type(result, "list") | ||
expect_true(length(result) == 1) | ||
expected_value <- list(CLH1_HUMAN = "Q00610") | ||
expect_equal(result, expected_value) | ||
}) | ||
|
||
# Test .callGetHgncIdsFromUniprotIdsApi | ||
test_that(".callGetHgncIdsFromUniprotIdsApi works correctly", { | ||
uniprotIds <- list("Q00610") | ||
result <- .callGetHgncIdsFromUniprotIdsApi(uniprotIds) | ||
expect_type(result, "list") | ||
expect_true(length(result) == 1) | ||
expected_value <- list("Q00610" = "2092") | ||
expect_equal(result, expected_value) | ||
}) | ||
|
||
# Test .callGetHgncNamesFromHgncIdsApi | ||
test_that(".callGetHgncNamesFromHgncIdsApi works correctly", { | ||
hgncIds <- list("2092") | ||
result <- .callGetHgncNamesFromHgncIdsApi(hgncIds) | ||
expect_type(result, "list") | ||
expect_true(length(result) == 1) | ||
expected_value <- list("2092" = "CLTC") | ||
expect_equal(result, expected_value) | ||
}) | ||
|
||
# Test .callIsKinaseApi | ||
test_that(".callIsKinaseApi works correctly", { | ||
kinaseGenes <- list("CHEK1") | ||
result <- .callIsKinaseApi(kinaseGenes) | ||
expect_type(result, "list") | ||
expect_true(length(result) == 1) | ||
expected_value <- list("CHEK1" = TRUE) | ||
expect_equal(result, expected_value) | ||
}) | ||
|
||
# Test .callIsPhosphataseApi | ||
test_that(".callIsPhosphataseApi works correctly", { | ||
phosphataseGenes <- list("MTM1") | ||
result <- .callIsPhosphataseApi(phosphataseGenes) | ||
expect_type(result, "list") | ||
expect_true(length(result) == 1) | ||
expected_value <- list("MTM1" = TRUE) | ||
expect_equal(result, expected_value) | ||
}) | ||
|
||
# Test .callIsTranscriptionFactorApi | ||
test_that(".callIsTranscriptionFactorApi works correctly", { | ||
transcriptionFactorGenes <- list("STAT1") | ||
result <- .callIsTranscriptionFactorApi(transcriptionFactorGenes) | ||
expect_type(result, "list") | ||
expect_true(length(result) == 1) | ||
expected_value <- list("STAT1" = TRUE) | ||
expect_equal(result, expected_value) | ||
}) |