Skip to content

Commit

Permalink
wrappers for bioentity endpoints and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pnavada committed Oct 27, 2024
1 parent b5ea6b1 commit 98ba20b
Show file tree
Hide file tree
Showing 2 changed files with 197 additions and 0 deletions.
138 changes: 138 additions & 0 deletions R/getBioEntityInfoFromIndra.R
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)
}
59 changes: 59 additions & 0 deletions tests/testthat/test-getBioEntityInfoFromIndra.R
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)
})

0 comments on commit 98ba20b

Please sign in to comment.