From e1daecda64e1b89702c2dd3acb25aa03afff1e89 Mon Sep 17 00:00:00 2001 From: Michael Tran Date: Tue, 21 Oct 2025 10:08:50 -0400 Subject: [PATCH 1/3] fix: properly skip tsv comments instead of hardcoding skips --- R/utils-httr2.R | 7 ++++++- tests/testthat/test_cellosaurus_helpers.R | 8 ++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/R/utils-httr2.R b/R/utils-httr2.R index 171e0d7..cbcbce3 100644 --- a/R/utils-httr2.R +++ b/R/utils-httr2.R @@ -61,5 +61,10 @@ #' @noRd #' @keywords internal .parse_resp_tsv <- function(resp, show_col_types = FALSE, skip = 0) { - readr::read_tsv(resp$body, skip = skip, show_col_types = show_col_types) + readr::read_tsv( + resp$body, + skip = skip, + show_col_types = show_col_types, + comment = "#" + ) } diff --git a/tests/testthat/test_cellosaurus_helpers.R b/tests/testthat/test_cellosaurus_helpers.R index 10aa3eb..87937c6 100644 --- a/tests/testthat/test_cellosaurus_helpers.R +++ b/tests/testthat/test_cellosaurus_helpers.R @@ -39,9 +39,9 @@ test_that(".build_cellosaurus_request is acting as expected", { expect_equal(request$url, expected) response <- AnnotationGx:::.perform_request(request) |> - AnnotationGx:::.parse_resp_tsv(show_col_types = FALSE, skip = 14) + AnnotationGx:::.parse_resp_tsv(show_col_types = FALSE) expect_class(response, "spec_tbl_df") - expect_gte(nrow(response), 1) + expect_equal(nrow(response), 1) request2 <- AnnotationGx:::.build_cellosaurus_request( query = "id:HeLa", @@ -74,8 +74,8 @@ test_that(".build_cellosaurus_request is acting as expected", { "https://api.cellosaurus.org/search/cell-line?q=id%3AHeLa&sort=ac%20asc&fields=id%2Cac%2Csy%2Cacas%2Csx%2Cag%2Cdi%2Cdio%2Cdin%2Cdr%2Ccell-type%2Cderived-from-site%2Cmisspelling%2Cdt%2Cdtc%2Cdtu%2Cdtv%2Cgenome-ancestry&format=tsv&rows=2" ) response <- AnnotationGx:::.perform_request(request2) |> - AnnotationGx:::.parse_resp_tsv(show_col_types = FALSE, skip = 14) - expect_gte(nrow(response), 1) + AnnotationGx:::.parse_resp_tsv(show_col_types = FALSE) + expect_equal(nrow(response), 2) }) test_that(".build_cellosaurus_request accepts documented sort fields", { From 10fe41496ed3c566e350a9269814531dc9878d41 Mon Sep 17 00:00:00 2001 From: Michael Tran Date: Tue, 21 Oct 2025 11:51:09 -0400 Subject: [PATCH 2/3] refactor: streamline cellosaurus column ordering --- R/cellosaurus.R | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/R/cellosaurus.R b/R/cellosaurus.R index 05dbb97..53b550e 100644 --- a/R/cellosaurus.R +++ b/R/cellosaurus.R @@ -206,16 +206,13 @@ mapCell2Accession <- function( core_cols <- c("cellLineName", "accession") existing_core <- core_cols[core_cols %in% names(responses_dt)] if (length(existing_core) > 0L) { - query_cols <- if (include_query) { - grep("^query", names(responses_dt), value = TRUE) - } else { - character(0) + other_cols <- setdiff(names(responses_dt), existing_core) + if (include_query) { + query_cols <- grep("^query", other_cols, value = TRUE) + non_query_cols <- setdiff(other_cols, query_cols) + other_cols <- c(non_query_cols, query_cols) } - extra_cols <- setdiff(names(responses_dt), c(existing_core, query_cols)) - data.table::setcolorder( - responses_dt, - c(existing_core, extra_cols, query_cols) - ) + data.table::setcolorder(responses_dt, c(existing_core, other_cols)) } return(responses_dt) From 6b1e9af074f6da9ed9a968ec3b89599451524152 Mon Sep 17 00:00:00 2001 From: Michael Tran Date: Tue, 21 Oct 2025 17:09:46 -0400 Subject: [PATCH 3/3] chore: restore cellosaurus column ordering --- R/cellosaurus.R | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/R/cellosaurus.R b/R/cellosaurus.R index 53b550e..05dbb97 100644 --- a/R/cellosaurus.R +++ b/R/cellosaurus.R @@ -206,13 +206,16 @@ mapCell2Accession <- function( core_cols <- c("cellLineName", "accession") existing_core <- core_cols[core_cols %in% names(responses_dt)] if (length(existing_core) > 0L) { - other_cols <- setdiff(names(responses_dt), existing_core) - if (include_query) { - query_cols <- grep("^query", other_cols, value = TRUE) - non_query_cols <- setdiff(other_cols, query_cols) - other_cols <- c(non_query_cols, query_cols) + query_cols <- if (include_query) { + grep("^query", names(responses_dt), value = TRUE) + } else { + character(0) } - data.table::setcolorder(responses_dt, c(existing_core, other_cols)) + extra_cols <- setdiff(names(responses_dt), c(existing_core, query_cols)) + data.table::setcolorder( + responses_dt, + c(existing_core, extra_cols, query_cols) + ) } return(responses_dt)