Skip to content

Commit

Permalink
works
Browse files Browse the repository at this point in the history
  • Loading branch information
alexvpickering committed May 22, 2024
1 parent b7d8208 commit 77e971b
Show file tree
Hide file tree
Showing 16 changed files with 1,053 additions and 805 deletions.
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM rocker/r-ver:4.3.3 AS build
FROM rocker/r-ver:4.4.0 AS build
WORKDIR /src/dseqr

# install required debian packages to install R packages
Expand All @@ -12,7 +12,7 @@ RUN echo ".libPaths(c('$RENV_LIB', .libPaths()))" >> $(R RHOME)/etc/Rprofile.sit

# install dseqr dependencies from renv.lock file
RUN R -e "install.packages('remotes', repos = c(CRAN = 'https://cloud.r-project.org'))" && \
R -e "remotes::install_github('rstudio/[email protected].5')" && \
R -e "remotes::install_github('rstudio/[email protected].7')" && \
R -e "renv::init(bare = TRUE, settings = list(use.cache = FALSE))"

# initial lockfile: sync periodically
Expand Down Expand Up @@ -54,7 +54,7 @@ RUN Rscript get_sysdeps_run.R
# ----------
# COMMON
#-----------
FROM rocker/r-ver:4.3.3 AS common
FROM rocker/r-ver:4.4.0 AS common
WORKDIR /src/dseqr

# add conda to path
Expand Down
6 changes: 3 additions & 3 deletions R/import_scseq.R
Original file line number Diff line number Diff line change
Expand Up @@ -850,7 +850,7 @@ load_tx2gene <- function(species, tx2gene_dir) {
fname <- paste0(ensdb_species, '_tx2gene.qs')
fpath <- file.path(tx2gene_dir, fname)

if (file.exists(fpath)) {
if (file_exists(fpath)) {
tx2gene <- qs::qread(fpath)
} else {
tx2gene <- dseqr.data::load_tx2gene(species, release = NULL, with_hgnc = TRUE)
Expand Down Expand Up @@ -947,7 +947,7 @@ load_cellranger_counts <- function(data_dir) {
ensids <- gsub('^[^_]+[_]+(ENS.+?)$', '\\1', row.names(counts))

enids <- gsub('[.]\\d+', '', ensids)
row.names(counts) <- make.unique(enids)
row.names(counts) <- make_unique(enids)

return(counts)
}
Expand Down Expand Up @@ -1542,7 +1542,7 @@ run_symphony <- function(counts, logcounts, ref_name, batch, species, tx2gene_di
uwot_name <- paste0(ref_name, '_uwot_model')
dl_dir <- Sys.getenv('DSEQR_DATA_PATH')
uwot_path <- file.path(dl_dir, uwot_name)
if (!file.exists(uwot_path)) dseqr.data::dl_data(uwot_name)
if (!file_exists(uwot_path)) dseqr.data::dl_data(uwot_name)

# indicate model path for mapQuery
reference$save_uwot_path <- uwot_path
Expand Down
2 changes: 1 addition & 1 deletion R/merge_utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ merge_clusters <- function(data_dir, merge_list, resoln_dir = NULL) {
annot <- pretty.unique(annot)

orig_path <- file.path(data_dir, paste0(resoln_dir, '_orig'))
if (!dir.exists(orig_path)) {
if (!dir_exists(orig_path)) {
# store original resolution
file.rename(resoln_path, orig_path)
dir.create(resoln_path)
Expand Down
26 changes: 13 additions & 13 deletions R/modules-bulk-server.R
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ bulkMDS <- function(input, output, session, explore_eset, dataset_name, numsv, b
req(eset)

mds_path <- isolate(mds_path())
if (file.exists(mds_path)) {
if (file_exists(mds_path)) {
mds <- qs::qread(mds_path)

} else {
Expand Down Expand Up @@ -567,7 +567,7 @@ bulkDataset <- function(input, output, session, sc_dir, bulk_dir, tx2gene_dir, p
observeEvent(input$up_raw, {
prev <- uploads_table()
new <- input$up_raw
new <- new[file.exists(new$datapath), ]
new <- new[file_exists(new$datapath), ]

is.eset <- grep('[.]qs$|[.]rds$', new$name)

Expand Down Expand Up @@ -651,7 +651,7 @@ bulkDataset <- function(input, output, session, sc_dir, bulk_dir, tx2gene_dir, p
if (is_eset()) return(FALSE)

fastqs <- up_df$datapath
fastqs <- fastqs[file.exists(fastqs)]
fastqs <- fastqs[file_exists(fastqs)]

# auto-detect if paired
fastq_id1s <- rkal::get_fastq_id1s(fastqs)
Expand Down Expand Up @@ -977,7 +977,7 @@ bulkDataset <- function(input, output, session, sc_dir, bulk_dir, tx2gene_dir, p
svobj <- NULL
svobj_path <- svobj_path()

if (file.exists(svobj_path)) {
if (file_exists(svobj_path)) {
svobj <- qs::qread(svobj_path)
}

Expand All @@ -996,7 +996,7 @@ bulkDataset <- function(input, output, session, sc_dir, bulk_dir, tx2gene_dir, p
if (!is.null(svobj$n.sv)) maxsv <- svobj$n.sv

numsv_path <- numsv_path()
if (file.exists(numsv_path)) numsv <- qs::qread(numsv_path)
if (file_exists(numsv_path)) numsv <- qs::qread(numsv_path)
else qs::qsave(0, numsv_path)

maxsv_r(maxsv)
Expand Down Expand Up @@ -1066,7 +1066,7 @@ bulkFormAnal <- function(input, output, session, project_dir, dataset_name, data
prev_path <- file.path(dataset_dir(), 'pdata_explore_prev.qs')
pdata_path <- file.path(dataset_dir(), 'pdata_explore.qs')

if (file.exists(prev_path)) {
if (file_exists(prev_path)) {
prev <- qs::qread(prev_path)
saved <- qs::qread(pdata_path)
changed <- check_bulk_changed(prev, saved)
Expand Down Expand Up @@ -1349,7 +1349,7 @@ deconvForm <- function(input, output, session, show_deconv, new_dataset, sc_dir,
# check if already have
deconv_path <- deconv_path()

if (file.exists(deconv_path)) {
if (file_exists(deconv_path)) {
new_deconv(deconv_path)

} else {
Expand Down Expand Up @@ -1433,7 +1433,7 @@ deconv_bulk_dwls <- function(bulk_dataset_dir, scseq_dataset_dir, exclude_cluste
# load markers
resoln_dir <- load_resoln(scseq_dataset_dir)
markers_path <- file.path(scseq_dataset_dir, resoln_dir, 'markers.qs')
have.markers <- file.exists(markers_path)
have.markers <- file_exists(markers_path)

# need logs to get markers, counts for deconvolution
scseq <- load_scseq_qs(scseq_dataset_dir, with_logs = !have.markers, with_counts = TRUE)
Expand Down Expand Up @@ -1634,7 +1634,7 @@ bulkExploreTable <- function(input, output, session, eset, up_annot, project_dir
req(up)


if (file.exists(pdata_path)) {
if (file_exists(pdata_path)) {
prev <- qs::qread(pdata_path)
changed <- check_bulk_changed(prev, up)

Expand All @@ -1657,7 +1657,7 @@ bulkExploreTable <- function(input, output, session, eset, up_annot, project_dir
req(pdata, pdata_path)

# load pdata from previous if available
if (file.exists(pdata_path)) {
if (file_exists(pdata_path)) {
pdata <- qs::qread(pdata_path)

# TODO remove
Expand Down Expand Up @@ -1897,12 +1897,12 @@ bulkAnal <- function(input, output, session, pdata, dataset_name, eset, numsv, s
})

# do we have drug query results?
saved_drugs <- reactive(file.exists(drug_paths()$cmap))
saved_drugs <- reactive(file_exists(drug_paths()$cmap))

# load lm_fit if saved or run limma
lm_fit <- reactive({

if (file.exists(lmfit_path())) {
if (file_exists(lmfit_path())) {
lm_fit <- qs::qread(lmfit_path())

} else {
Expand Down Expand Up @@ -1986,7 +1986,7 @@ bulkAnal <- function(input, output, session, pdata, dataset_name, eset, numsv, s
req(valid_contrast())
goana_path <- goana_path()

if (file.exists(goana_path)) {
if (file_exists(goana_path)) {
res <- qs::qread(goana_path)

} else {
Expand Down
12 changes: 6 additions & 6 deletions R/modules-bulk-utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -339,12 +339,12 @@ load_bulk_datasets <-function(data_dir, with.explore = FALSE) {

dataset_names <- list.dirs(file.path(data_dir, 'bulk'), full.names = FALSE, recursive = FALSE)

has.eset <- file.exists(file.path(data_dir, 'bulk', dataset_names, 'eset.qs'))
has.eset <- file_exists(file.path(data_dir, 'bulk', dataset_names, 'eset.qs'))
dataset_names <- dataset_names[has.eset]

# for excluding datasets without a contrast
if (with.explore) {
has.explore <- file.exists(file.path(data_dir, 'bulk', dataset_names, 'pdata_explore.qs'))
has.explore <- file_exists(file.path(data_dir, 'bulk', dataset_names, 'pdata_explore.qs'))
dataset_names <- dataset_names[has.explore]
}

Expand Down Expand Up @@ -798,7 +798,7 @@ add_vsd <- function(eset, vsd_path = NULL, rna_seq = TRUE) {
# for microarray use exprs
vsd <- Biobase::assayDataElement(eset, 'exprs')

} else if (!is.null(vsd_path) && file.exists(vsd_path)) {
} else if (!is.null(vsd_path) && file_exists(vsd_path)) {
vsd <- qs::qread(vsd_path)

} else {
Expand All @@ -812,7 +812,7 @@ add_vsd <- function(eset, vsd_path = NULL, rna_seq = TRUE) {

add_adjusted <- function(eset, adj_path, svobj = list(sv = NULL), numsv = 0) {

if (file.exists(adj_path)) {
if (file_exists(adj_path)) {
Biobase::assayDataElement(eset, 'adjusted') <- qs::qread(adj_path)

} else {
Expand All @@ -826,7 +826,7 @@ add_adjusted <- function(eset, adj_path, svobj = list(sv = NULL), numsv = 0) {

iqr_replicates <- function(eset, keep_path, annot = "SYMBOL", rm.dup = FALSE) {

if (file.exists(keep_path)) {
if (file_exists(keep_path)) {
keep <- qs::qread(keep_path)
eset <- eset[keep, ]
Biobase::featureNames(eset) <- Biobase::fData(eset)[, annot]
Expand Down Expand Up @@ -1153,7 +1153,7 @@ handle_bulk_progress <- function(bgs, progs, new_dataset) {
}

file.move <- function(from, to) {
if (any(file.exists(to))) unlink(to)
if (any(file_exists(to))) unlink(to)
tryCatch(
file.rename(from, to),
warning = function(w) {
Expand Down
6 changes: 3 additions & 3 deletions R/modules-drugs-server.R
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ customQueryForm <- function(input, output, session, show_custom, is_custom, anal
res_paths <- reactive({
custom_name <- input$custom_name
custom_dir <- file.path(project_dir(), 'custom_queries')
if (!dir.exists(custom_dir)) dir.create(custom_dir)
if (!dir_exists(custom_dir)) dir.create(custom_dir)

res_paths <- get_drug_paths(custom_dir, custom_name)
res_paths$query_genes <- file.path(custom_dir, 'drugs', paste0('query_genes_', custom_name, '.qs'))
Expand Down Expand Up @@ -691,7 +691,7 @@ selectedAnal <- function(input, output, session, project_dir, choices, new_custo
numsv_path <- reactive(file.path(dataset_dir(), 'numsv.qs'))
numsv <- reactive({
numsv_path <- numsv_path()
if (!file.exists(numsv_path)) qs::qsave(0, numsv_path)
if (!file_exists(numsv_path)) qs::qsave(0, numsv_path)
qs::qread(numsv_path)
})

Expand Down Expand Up @@ -765,7 +765,7 @@ selectedAnal <- function(input, output, session, project_dir, choices, new_custo
} else if (is_custom()) {
custom_dir <- file.path(project_dir(), 'custom_queries')
drug_paths <- get_drug_paths(custom_dir, sel_name)
drug_queries <- lapply(drug_paths, function(x) if (file.exists(x)) qs::qread(x))
drug_queries <- lapply(drug_paths, function(x) if (file_exists(x)) qs::qread(x))

} else if (is_pert()) {
drug_paths <- get_drug_paths(pert_query_dir, fs::path_sanitize(sel_name), ftype = '.rds')
Expand Down
8 changes: 4 additions & 4 deletions R/modules-drugs-utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,10 @@ load_custom_results <- function(res_paths, is_pert) {
res_name <- names(res_paths)[i]

# download requested pert result
if (!file.exists(res_path) && is_pert && !grepl('diff_expr_symbol_.+?.rds$', res_path))
if (!file_exists(res_path) && is_pert && !grepl('diff_expr_symbol_.+?.rds$', res_path))
dl_pert_result(res_path)

if (file.exists(res_path))
if (file_exists(res_path))
res[[res_name]] <- readRDS(res_path)
}
return(res)
Expand All @@ -211,7 +211,7 @@ load_custom_results <- function(res_paths, is_pert) {
#'
dl_pert_result <- function(res_path) {
# name of the file being requested
if (file.exists(res_path)) return(NULL)
if (file_exists(res_path)) return(NULL)
dl_url <- paste0('https://s3.us-east-2.amazonaws.com/dseqr/pert_query_dir/', basename(res_path))
dl_url <- utils::URLencode(dl_url)
dl_url <- gsub('+', '%2B', dl_url, fixed = TRUE)
Expand All @@ -229,7 +229,7 @@ load_custom_anals <- function(data_dir) {
custom_dir <- file.path(data_dir, 'custom_queries', 'drugs')

anals <- NULL
if (dir.exists(custom_dir)) {
if (dir_exists(custom_dir)) {
custom_names <- list.files(custom_dir, pattern = '^cmap_res_.+?.qs')
custom_names <- gsub('^cmap_res_(.+?).qs$', '\\1', custom_names)

Expand Down
16 changes: 8 additions & 8 deletions R/modules-path-utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
load_pert_signature <- function(pert, pert_type, pert_signature_dir, pvals = FALSE) {
sig <- NULL
type_dir <- file.path(pert_signature_dir, pert_type)
if (!file.exists(type_dir)) dir.create(type_dir)
if (!file_exists(type_dir)) dir.create(type_dir)


fname <- paste0(pert, '.rds')
sig_path <- file.path(type_dir, fs::path_sanitize(fname))
if (!file.exists(sig_path)) dl_pert_signature(sig_path, pert_type)
if (file.exists(sig_path)) sig <- readRDS(sig_path)
if (!file_exists(sig_path)) dl_pert_signature(sig_path, pert_type)
if (file_exists(sig_path)) sig <- readRDS(sig_path)
return(sig)
}

Expand Down Expand Up @@ -209,7 +209,7 @@ get_cluster_markers <- function(selected_clusters, dataset_dir) {
fname <- paste0("markers_", clusters_name, '.qs')
fpath <- file.path(dataset_dir, fname)

if (file.exists(fpath)) {
if (file_exists(fpath)) {
cluster_markers <- qs::qread(fpath)

}
Expand Down Expand Up @@ -293,12 +293,12 @@ get_genego <- function(species = 'Hs', gs_dir = NULL) {
PathwayID <- GeneID <- SYMBOL <- NULL

persist <- !is.null(gs_dir)
if (persist && !dir.exists(gs_dir)) dir.create(gs_dir)
if (persist && !dir_exists(gs_dir)) dir.create(gs_dir)

fname <- paste('genego', species, 'qs', sep = '.')
genego_path <- file.path(gs_dir, fname)

if (file.exists(genego_path)) {
if (file_exists(genego_path)) {
genego <- qs::qread(genego_path)

} else {
Expand Down Expand Up @@ -350,12 +350,12 @@ get_genego <- function(species = 'Hs', gs_dir = NULL) {
#'
get_gonames <- function(genego, gs_dir = NULL) {
persist <- !is.null(gs_dir)
if (persist && !dir.exists(gs_dir)) dir.create(gs_dir)
if (persist && !dir_exists(gs_dir)) dir.create(gs_dir)

fname <- paste('genego.names', 'qs', sep = '.')
gonames_path <- file.path(gs_dir, fname)

if (file.exists(gonames_path)) {
if (file_exists(gonames_path)) {
gonames <- qs::qread(gonames_path)

} else {
Expand Down
Loading

0 comments on commit 77e971b

Please sign in to comment.