Skip to content

Commit

Permalink
use glims_portal_read
Browse files Browse the repository at this point in the history
  • Loading branch information
pdiakumis committed Mar 14, 2024
1 parent 2a01533 commit ac49e7f
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 24 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ Imports:
readr,
RJSONIO,
rlang,
rmarkdown,
scales,
sessioninfo,
tibble,
Expand All @@ -52,6 +51,7 @@ Suggests:
SparkR,
DBI,
RAthena,
rmarkdown,
testthat (>= 3.0.0)
Roxygen: list(markdown = TRUE,
roclets = c("namespace", "rd", "roxytest::testthat_roclet"))
Expand Down
3 changes: 2 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ export(gds_file_presignedurl)
export(gds_files_list)
export(gds_files_list_filter_relevant)
export(gds_volumes_list)
export(glims_read)
export(glims_excel_read)
export(glims_portal_read)
export(ica_token_validate)
export(match_regex)
export(meta_bcl_convert)
Expand Down
42 changes: 42 additions & 0 deletions R/portal_meta.R
Original file line number Diff line number Diff line change
Expand Up @@ -886,3 +886,45 @@ portal_meta_read_athena_tmp <- function(x = NULL) {
RAthena::dbGetQuery(con, q1) |>
tibble::as_tibble()
}

#' Read Portal Limsrow Table
#'
#' Reads rows from the data portal's limsrow table, given a set of `LibraryID`s
#' to query.
#'
#' @param libids Character vector of LibraryID values to query for.
#'
#' @return Tibble with all rows from the data portal limsrow table where
#' there are hits with the `library_id` column.
#' @export
glims_portal_read <- function(libids) {
assertthat::assert_that(!is.null(libids), all(grepl("^L", libids)))
libids <- unique(libids)
RAthena::RAthena_options(clear_s3_resource = FALSE)
con <- DBI::dbConnect(
RAthena::athena(),
work_group = "data_portal",
rstudio_conn_tab = FALSE
)
q_quote <- shQuote(paste(libids, collapse = "|"))
q1 <- glue(
'SELECT * FROM "data_portal"."data_portal"."data_portal_limsrow" where REGEXP_LIKE("library_id", {q_quote});'
)
d <- RAthena::dbGetQuery(con, q1) |>
tibble::as_tibble()
DBI::dbDisconnect(con)
d
}

#' Read Google LIMS
#'
#' Reads UMCCR's Google LIMS spreadsheet.
#'
#' @return Tibble with all columns and rows from the Google LIMS spreadsheet.
#' @export
glims_excel_read <- function() {
lims_key <- googledrive::drive_find("^Google LIMS$", shared_drive = "LIMS")$id
lims <- lims_key |>
googlesheets4::read_sheet("Sheet1", na = c(".", "", "-"), col_types = "c")
lims |> readr::type_convert(col_types = readr::cols(.default = "c", Timestamp = "T"))
}
12 changes: 0 additions & 12 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -165,18 +165,6 @@ read_jsongz_rjsonio <- function(x, ...) {
RJSONIO::fromJSON(x, ...)
}

#' Read Google LIMS
#'
#' Reads UMCCR's Google LIMS spreadsheet.
#'
#' @return Tibble with all columns and rows from the Google LIMS spreadsheet.
#' @export
glims_read <- function() {
lims_key <- googledrive::drive_find("^Google LIMS$", shared_drive = "LIMS")$id
lims <- lims_key |>
googlesheets4::read_sheet("Sheet1", na = c(".", "", "-"), col_types = "c")
lims |> readr::type_convert(col_types = readr::cols(.default = "c", Timestamp = "T"))
}


#' @noRd
Expand Down
12 changes: 7 additions & 5 deletions inst/rmd/umccr_portal/portal_summary.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,10 @@ add_totals <- function(x) {
# Get metadata for workflows run within the date range
# options(width = 150)
fmt1 <- "%Y-%m-%dT%H:%M:%S"
date_start <- as.POSIXct("2024-02-21T00:00:01", format = fmt1)
date_end <- as.POSIXct("2024-02-23T23:59:59", format = fmt1)
dstart <- "2024-03-08"
dend <- "2024-03-10"
date_start <- as.POSIXct(glue("{dstart}T00:00:01"), format = fmt1)
date_end <- as.POSIXct(glue("{dend}T23:59:59"), format = fmt1)
wf_order <- c(
"bcl_convert",
"tso_ctdna_tumor_only",
Expand All @@ -146,11 +148,11 @@ wf_order <- c(
invisible(capture.output(dracarys:::awsvault_profile("upro")))
lims_rds <- here(glue("nogit/data_portal/lims/{as.Date(date_end)}.rds"))
# lims_raw <- dracarys::glims_read()
# lims_raw <- dracarys::glims_read() # TODO: use glims_portal_read
# saveRDS(lims_raw, file = lims_rds)
lims_raw <- readr::read_rds(lims_rds)
pmeta_rds <- here(glue("nogit/data_portal/workflows/{as.Date(date_end)}.rds"))
wf_query <- 'WHERE "start" >= date(\'2024-02-21\') AND "start" <= date(\'2024-02-24\') ORDER BY "start" DESC;'
wf_query <- glue('WHERE "start" >= date(\'{dstart}\') AND "start" <= date(\'{dend}\') ORDER BY "start" DESC;')
# pmeta_raw <- dracarys:::portal_meta_read_athena_tmp(wf_query)
# saveRDS(pmeta_raw, file = pmeta_rds)
Expand Down Expand Up @@ -241,7 +243,7 @@ blank_lines()

## RuntimeVis

```{r vistime, fig.width=20, fig.height = 13}
```{r vistime, fig.width=20, fig.height = 16}
p1 <- pmeta_sumy |>
dplyr::arrange(sbj_lib, type_name) |>
dplyr::group_by(sbj_lib, type_name) |>
Expand Down
3 changes: 2 additions & 1 deletion inst/rmd/umccr_workflows/alignment_qc/test.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ dp_workflow_read <- function(start_date) {
d
}

# TODO: use dracarys::glims_portal_read
dp_lims_read <- function(libids) {
assertthat::assert_that(!is.null(libids), all(grepl("^L", libids)))
libids <- unique(libids)
Expand All @@ -52,7 +53,7 @@ dp_lims_read <- function(libids) {
}

# first read in the workflows table, extract metadata, then join with lims
start_date <- "2024-02-20"
start_date <- "2024-03-08"
p_raw <- dp_workflow_read(start_date)

wgs <- p_raw |>
Expand Down
8 changes: 4 additions & 4 deletions man/glims_read.Rd → man/glims_excel_read.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions man/glims_portal_read.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ac49e7f

Please sign in to comment.