Skip to content

Commit

Permalink
feat: precompute user.sigdb connectivity score at pgxcompute
Browse files Browse the repository at this point in the history
  • Loading branch information
ivokwee committed Oct 18, 2023
1 parent d4f6474 commit f30e6eb
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 14 deletions.
5 changes: 3 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ export(makeContrastsFromLabelMatrix)
export(makeDirectContrasts)
export(makeDirectContrasts000)
export(makeFullContrasts)
export(mat2gmt)
export(matGroupMeans)
export(merge_sparse_matrix)
export(mixHivePlot)
Expand Down Expand Up @@ -171,7 +172,6 @@ export(pgx.contrastScatter)
export(pgx.correlateSignatureH5)
export(pgx.countNormalization)
export(pgx.createComboDrugAnnot)
export(pgx.createCreedsSigDB)
export(pgx.createFromFiles)
export(pgx.createOmicsGraph)
export(pgx.createPGX)
Expand Down Expand Up @@ -252,10 +252,11 @@ export(pgx.superBatchCorrect)
export(pgx.survivalVariableImportance)
export(pgx.testPhenoCorrelation)
export(pgx.testTCGAsurvival)
export(pgx.updateInfoPGX)
export(pgx.variableImportance)
export(pgx.violinPlot)
export(pgx.wgcna)
export(pgxinfo.add)
export(pgxinfo.delete)
export(pgxinfo.needUpdate)
export(pgxinfo.read)
export(pgxinfo.updateDatasetFolder)
Expand Down
27 changes: 18 additions & 9 deletions R/compute2-extra.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
compute_extra <- function(pgx, extra = c(
"meta.go", "infer", "deconv", "drugs", ## "graph",
"connectivity", "wordcloud", "wgcna"
), sigdb = NULL, libx.dir = NULL) {
), sigdb = NULL, libx.dir = NULL, pgx.dir = NULL) {
timings <- c()

if (length(extra) == 0) {
Expand Down Expand Up @@ -119,25 +119,34 @@ compute_extra <- function(pgx, extra = c(
message("<<< done!")
}

# THIS REQUIRES libx.dir TO BE SET TO FIND sigdb-.h5 FILES
# This requires libx.dir to be set (or sigdb passed) to find sigdb-.h5 files
if ("connectivity" %in% extra) {
# try to find sigdb in libx dir if not specified
if (!is.null(libx.dir) || !is.null(sigdb)) {
if (!is.null(libx.dir) || !is.null(pgx.dir) || !is.null(sigdb)) {
message(">>> Computing connectivity scores...")
if (is.null(sigdb)) {
sigdb <- dir(file.path(libx.dir, "sigdb"), pattern = "h5$", full.names = TRUE)
sigdb <- NULL
if (!is.null(pgx.dir) ) {
## make sure h5 file is up-to-date
pgxinfo.updateDatasetFolder(pgx.dir, force=FALSE, update.sigdb=TRUE)
user.sigdb <- file.path(pgx.dir, "datasets-sigdb.h5")
sigdb <- c(sigdb, user.sigdb)
}
if (!is.null(libx.dir) ) {
libx.sigdb <- dir(file.path(libx.dir, "sigdb"), pattern = "h5$", full.names = TRUE)
sigdb <- c(sigdb, libx.sigdb)
}
}

db <- sigdb[1]
for (db in sigdb) {
if (file.exists(db)) {
message("computing connectivity scores for ", db)
## in memory for many comparisons
meta <- pgx.getMetaFoldChangeMatrix(pgx, what = "meta")
tt <- system.time({
scores <- pgx.computeConnectivityScores(
pgx, db,
ntop = 1000,
pgx,
db,
ntop = 200,
contrasts = NULL,
remove.le = TRUE
)
Expand Down
9 changes: 6 additions & 3 deletions R/pgx-compute.R
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,8 @@ pgx.computePGX <- function(pgx,
"meta.go", "infer", "deconv", "drugs",
"connectivity", "wordcloud", "wgcna"
)[c(1, 2)],
libx.dir = NULL,
pgx.dir = NULL,
libx.dir = NULL,
progress = NULL) {
## ======================================================================
## ======================================================================
Expand Down Expand Up @@ -643,14 +644,16 @@ pgx.computePGX <- function(pgx,

if (do.cluster) {
message("[pgx.computePGX] clustering genes...")
pgx <- pgx.clusterGenes(pgx, methods = "umap", dims = c(2, 3), level = "geneset") ## gsetX not ready!!
## gsetX was not ready before!!
pgx <- pgx.clusterGenes(pgx, methods = "umap", dims = c(2, 3), level = "geneset")
}


## ------------------ extra analyses ---------------------
if (!is.null(progress)) progress$inc(0.3, detail = "extra modules")
message("[pgx.computePGX] computing extra modules...")
pgx <- compute_extra(pgx, extra = extra.methods, libx.dir = libx.dir)
pgx <- compute_extra(pgx, extra = extra.methods,
pgx.dir = pgx.dir, libx.dir = libx.dir)

message("[pgx.computePGX] done!")

Expand Down

0 comments on commit f30e6eb

Please sign in to comment.