Skip to content
This repository was archived by the owner on Dec 30, 2023. It is now read-only.

Commit dd93000

Browse files
committed
add small drug cmap file
1 parent 91409e3 commit dd93000

File tree

5 files changed

+6178
-33
lines changed

5 files changed

+6178
-33
lines changed

R/compute2-extra.R

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -76,19 +76,25 @@ pgx.computeExtra <- function(ngs, extra, lib.dir=FILES, sigdb=NULL) {
7676
if("drugs" %in% extra) {
7777
ngs$drugs <- NULL ## reset??
7878
cmap.dir <- file.path(libx.dir,"cmap")
79-
79+
if(!dir.exists(cmap.dir)) {
80+
cmap.dir <- file.path(lib.dir,"cmap") ## look for default lib
81+
}
82+
if(!dir.exists(cmap.dir)) {
83+
message("Warning:: missing CMAP files. Skipping drug connectivity analysis!")
84+
}
85+
dbg("[pgx.computeExtra] cmap.dir = ",cmap.dir)
86+
8087
if(dir.exists(cmap.dir)) {
8188

8289
message(">>> Computing drug activity enrichment...")
8390
tt <- system.time({
84-
ngs <- compute.drugActivityEnrichment(ngs, lib.dir=cmap.dir)
91+
ngs <- compute.drugActivityEnrichment(ngs, cmap.dir)
8592
})
8693
timings <- rbind(timings, c("drugs", tt))
8794

8895
message(">>> Computing drug sensitivity enrichment...")
8996
tt <- system.time({
90-
ngs <- compute.drugSensitivityEnrichment(
91-
ngs, lib.dir=cmap.dir)
97+
ngs <- compute.drugSensitivityEnrichment(ngs, cmap.dir)
9298
})
9399
timings <- rbind(timings, c("drugs-sx", tt))
94100

@@ -97,7 +103,6 @@ pgx.computeExtra <- function(ngs, extra, lib.dir=FILES, sigdb=NULL) {
97103
## ngs <- compute.genePerturbationEnrichment(ngs, lib.dir=cmap.dir)
98104
## })
99105
##timings <- rbind(timings, c("drugs-gene", tt))
100-
101106
}
102107

103108
}
@@ -273,18 +278,19 @@ compute.cellcycle.gender <- function(ngs, rna.counts=ngs$counts)
273278
return(ngs)
274279
}
275280

276-
compute.drugActivityEnrichment <- function(ngs, lib.dir) {
281+
compute.drugActivityEnrichment <- function(ngs, cmap.dir) {
277282

278283
## -------------- drug enrichment
279-
L1000.FILE = "l1000_es_n20a1698.csv.gz"
280284
L1000.FILE = "l1000_es_n20d1011.csv.gz"
281285
L1000.FILE = "l1000_es.rds"
282-
lib.dir
283-
dir(lib.dir, pattern='.*rds$')
284-
dir(lib.dir, pattern='^L1000-activity.*rds$')
285-
ref.db <- dir(lib.dir, pattern='^L1000-activity.*rds$')
286-
ref.db <- dir(lib.dir, pattern='^L1000-.*rds$')
286+
cmap.dir
287+
dir(cmap.dir, pattern='.*rds$')
288+
ref.db <- dir(cmap.dir, pattern='^L1000-.*rds$')
287289
ref.db
290+
if(length(ref.db)==0) {
291+
message("[compute.drugActivityEnrichment] Warning:: missing drug activity database")
292+
return(ngs)
293+
}
288294
names(ref.db) <- sub("-","/",gsub("_.*","",ref.db))
289295
ref.db
290296
f <- ref.db[1]
@@ -293,8 +299,8 @@ compute.drugActivityEnrichment <- function(ngs, lib.dir) {
293299
for(i in 1:length(ref.db)) {
294300
f <- ref.db[i]
295301
message("[compute.drugActivityEnrichment] reading L1000 reference: ",f)
296-
X <- readRDS(file=file.path(lib.dir,f))
297-
##X <- fread.csv(file=file.path(lib.dir,L1000.FILE))
302+
X <- readRDS(file=file.path(cmap.dir,f))
303+
##X <- fread.csv(file=file.path(cmap.dir,L1000.FILE))
298304
xdrugs <- gsub("_.*$","",colnames(X))
299305
ndrugs <- length(table(xdrugs))
300306
ndrugs
@@ -318,7 +324,7 @@ compute.drugActivityEnrichment <- function(ngs, lib.dir) {
318324
## --------------- attach annotation
319325
annot0 <- NULL
320326
if(is.drug) {
321-
annot0 <- read.csv(file.path(lib.dir,"L1000_repurposing_drugs.txt"),
327+
annot0 <- read.csv(file.path(cmap.dir,"L1000_repurposing_drugs.txt"),
322328
sep="\t", comment.char="#")
323329
annot0$drug <- annot0$pert_iname
324330
rownames(annot0) <- annot0$pert_iname
@@ -338,9 +344,6 @@ compute.drugActivityEnrichment <- function(ngs, lib.dir) {
338344
Matrix::head(annot0)
339345
}
340346

341-
342-
343-
344347
## --------------- attach results to object
345348
db <- names(ref.db)[i]
346349
## ngs$drugs[["activity/L1000"]] <- res.mono[["GSEA"]]
@@ -356,20 +359,24 @@ compute.drugActivityEnrichment <- function(ngs, lib.dir) {
356359
return(ngs)
357360
}
358361

359-
##ref="CTRPv2";lib.dir="../lib";combo=FALSE
360-
compute.drugSensitivityEnrichment <- function(ngs, lib.dir)
362+
##ref="CTRPv2";cmap.dir="../lib";combo=FALSE
363+
compute.drugSensitivityEnrichment <- function(ngs, cmap.dir)
361364
{
362365

363-
ref.db <- dir(lib.dir, pattern='sensitivity.*rds$')
366+
ref.db <- dir(cmap.dir, pattern='sensitivity.*rds$')
364367
ref.db
368+
if(length(ref.db)==0) {
369+
message("[compute.drugSensitivityEnrichment] Warning:: missing drug sensitivity database")
370+
return(ngs)
371+
}
365372
names(ref.db) <- sub("-","/",gsub("_.*","",ref.db))
366373
ref.db
367374
ref <- ref.db[1]
368375
for(i in 1:length(ref.db)) {
369376
ref <- ref.db[i]
370-
##X <- readRDS(file=file.path(lib.dir,"drugSX-GDSC-t25-g1000.rds"))
371-
##X <- readRDS(file=file.path(lib.dir,"drugSX-CTRPv2-t25-g1000.rds"))
372-
X <- readRDS(file=file.path(lib.dir,ref))
377+
##X <- readRDS(file=file.path(cmap.dir,"drugSX-GDSC-t25-g1000.rds"))
378+
##X <- readRDS(file=file.path(cmap.dir,"drugSX-CTRPv2-t25-g1000.rds"))
379+
X <- readRDS(file=file.path(cmap.dir,ref))
373380
xdrugs <- gsub("[@_].*$","",colnames(X))
374381
length(table(xdrugs))
375382
dim(X)
@@ -383,7 +390,7 @@ compute.drugSensitivityEnrichment <- function(ngs, lib.dir)
383390
if(!is.null(out1)) {
384391
## attach annotation
385392
db <- sub("-.*","",ref)
386-
annot0 <- read.csv(file.path(lib.dir,paste0(db,"-drugs.csv")))
393+
annot0 <- read.csv(file.path(cmap.dir,paste0(db,"-drugs.csv")))
387394
Matrix::head(annot0)
388395
rownames(annot0) <- annot0$drug
389396
annot0 <- annot0[match(rownames(out1[["GSEA"]]$X),rownames(annot0)),]

R/pgx-modules.R

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,6 @@ plotModule <- function(input, output, session, ## ns=NULL,
349349
HTMLFILE = paste0(gsub("file","plot",tempfile()),".html") ## tempory for webshot
350350
HTMLFILE
351351
unlink(HTMLFILE)
352-
353352

354353
##============================================================
355354
##=============== Download Handlers ==========================
@@ -375,12 +374,14 @@ plotModule <- function(input, output, session, ## ns=NULL,
375374
iheatmapr::save_iheatmap(p, vwidth=pdf.width*80,vheight=pdf.height*80,PNGFILE)
376375
} else if(plotlib=="visnetwork") {
377376
p <- func()
377+
dbg("[plotModule] visnetwork download PNG : visSave : HTMLFILE=",HTMLFILE)
378378
visNetwork::visSave(p, HTMLFILE)
379-
webshot::webshot(HTMLFILE,vwidth=pdf.width*100,vheight=pdf.height*100,PNGFILE)
379+
dbg("[plotModule] visnetwork download PNG : webshot : PNGFILE = ",PNGFILE)
380+
webshot::webshot(url=HTMLFILE,file=PNGFILE,vwidth=pdf.width*100,vheight=pdf.height*100)
380381
} else if(plotlib %in% c("htmlwidget","pairsD3","scatterD3")) {
381382
p <- func()
382383
htmlwidgets::saveWidget(p, HTMLFILE)
383-
webshot::webshot(HTMLFILE, vwidth=pdf.width*100,vheight=pdf.height*100,PNGFILE)
384+
webshot::webshot(url=HTMLFILE,file=PNGFILE,vwidth=pdf.width*100,vheight=pdf.height*100)
384385
} else if(plotlib %in% c("ggplot","ggplot2")) {
385386
p <- func()
386387
png(PNGFILE, width=pdf.width*100, height=pdf.height*100,
@@ -444,12 +445,14 @@ plotModule <- function(input, output, session, ## ns=NULL,
444445
iheatmapr::save_iheatmap(p, vwidth=pdf.width*80,vheight=pdf.height*80,PDFFILE)
445446
} else if(plotlib=="visnetwork") {
446447
p <- func()
448+
dbg("[plotModule] visnetwork :: download PDF : visSave : HTMLFILE=",HTMLFILE)
447449
visNetwork::visSave(p, HTMLFILE)
448-
webshot::webshot(HTMLFILE,vwidth=pdf.width*100,vheight=pdf.height*100,PDFFILE)
450+
dbg("[plotModule] visnetwork :: download PDF : webshot ; PDFFILE=",PDFFILE)
451+
webshot::webshot(url=HTMLFILE,file=PDFFILE,vwidth=pdf.width*100,vheight=pdf.height*100)
449452
} else if(plotlib %in% c("htmlwidget","pairsD3","scatterD3")) {
450453
p <- func()
451454
htmlwidgets::saveWidget(p, HTMLFILE)
452-
webshot::webshot(HTMLFILE, vwidth=pdf.width*100,vheight=pdf.height*100,PDFFILE)
455+
webshot::webshot(url=HTMLFILE, file=PDFFILE, vwidth=pdf.width*100,vheight=pdf.height*100)
453456
} else if(plotlib %in% c("ggplot","ggplot2")) {
454457
p <- func()
455458
##p = addSignature(p)

lib/cmap/L1000-activityS_n20d1011.rds

47 MB
Binary file not shown.

0 commit comments

Comments
 (0)