Skip to content

Commit 197a777

Browse files
committed
export and document getCatalog function
1 parent 3de4eb0 commit 197a777

File tree

3 files changed

+74
-7
lines changed

3 files changed

+74
-7
lines changed

NAMESPACE

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export(HoverNet)
44
export(ProvGiga)
55
export(ProvGigaList)
66
export(embedding)
7+
export(getCatalog)
78
export(getEmbeddings)
89
export(listHoverNet)
910
export(listProvGiga)
@@ -47,8 +48,10 @@ importFrom(ggplot2,guides)
4748
importFrom(ggplot2,scale_color_manual)
4849
importFrom(ggplot2,theme)
4950
importFrom(ggplot2,theme_void)
51+
importFrom(httr2,req_headers)
5052
importFrom(httr2,req_perform)
5153
importFrom(httr2,request)
54+
importFrom(httr2,resp_body_json)
5255
importFrom(httr2,resp_body_string)
5356
importFrom(methods,callNextMethod)
5457
importFrom(methods,is)

R/listFiles.R

Lines changed: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
#' @param level `character(1L)` One of "slide_level" or "tile_level" specifying
1818
#' the desired ProvGiga data level. Default is "slide_level".
1919
#'
20+
#' @returns `listHoverNet`,`listProvGiga`: A `tibble` listing available HoverNet
21+
#' or ProvGigaPath files with `Filename`, `Modified`, and `Size` columns.
22+
#'
2023
#' @examplesIf interactive()
2124
#' ## List available HoverNet data for TCGA-OV
2225
#' listHoverNet(format = "h5ad")
@@ -52,11 +55,47 @@ listProvGiga <- function(
5255
table[!grepl("^\\.\\.", table[["Filename"]]), ]
5356
}
5457

55-
getCatalog <- function(pipeline = c("hovernet", "provgigapath")) {
56-
pipeline <- match.arg(pipeline)
57-
catalog_url <- paste(
58-
.BASE_URL, pipeline, paste0(pipeline, "_catalog.tsv"),
59-
sep = "/"
60-
) |>
61-
readr::read_tsv(show_col_types = FALSE)
58+
.CATALOG_COL_TYPES <- "ccccccccccccccccccccccddc"
59+
60+
#' @rdname listFiles
61+
#'
62+
#' @description The `getCatalog` function retrieves a catalog of all available
63+
#' HoVerNet and ProvGigaPath files, including filenames, sizes, pipelines
64+
#' used, tumor types, and data levels.
65+
#'
66+
#' @param pipeline `character()` One or both "hovernet" and/or "provgigapath"
67+
#' specifying which pipeline(s) to include in the catalog. Default includes
68+
#' both.
69+
#'
70+
#' @param redownload `logical(1L)` Whether to redownload the catalog file even
71+
#' if it is already cached locally. Default is `FALSE`.
72+
#'
73+
#' @returns `getCatalog`: A `tibble` containing the full catalog of available
74+
#' files for the specified pipeline(s).
75+
#'
76+
#' @examplesIf interactive()
77+
#' ## Get the full catalog of available files
78+
#' getCatalog(pipeline = c("hovernet", "provgigapath"))
79+
#' @export
80+
getCatalog <-
81+
function(pipeline = c("hovernet", "provgigapath"), redownload = FALSE)
82+
{
83+
pipeline <- match.arg(pipeline, several.ok = TRUE)
84+
catalog <- .download_catalog(redownload = redownload)
85+
readr::read_tsv(catalog, col_types = .CATALOG_COL_TYPES) |>
86+
subset(pipeline %in% pipeline)
87+
}
88+
89+
#' @importFrom httr2 request req_headers req_perform resp_body_json
90+
.download_catalog <- function(redownload) {
91+
resp <- request("https://zenodo.org/api/records/17981132") |>
92+
req_headers(
93+
Accept = "application/json"
94+
) |>
95+
req_perform() |>
96+
resp_body_json()
97+
98+
.cache_url_file(
99+
resp$files[[1L]]$links$self, redownload = redownload
100+
)
62101
}

man/listFiles.Rd

Lines changed: 25 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)