Skip to content

Instantly share code, notes, and snippets.

@lwaldron
Last active December 4, 2017 14:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lwaldron/ab3e6ab3ddc8815a01e3c46969aad130 to your computer and use it in GitHub Desktop.
Save lwaldron/ab3e6ab3ddc8815a01e3c46969aad130 to your computer and use it in GitHub Desktop.
Some code to provide some dose-viability data to play with:
library(PharmacoGx)
fimm <- downloadPSet("FIMM")
slotNames(fimm)
names(fimm@sensitivity)
head(fimm@sensitivity$info)
head(fimm@sensitivity$profiles)
fimm@sensitivity$n[1:5, 1:5]
class(fimm@sensitivity$raw)
dim(fimm@sensitivity$raw)
str(fimm@sensitivity$raw)
library(SummarizedExperiment)
rawassay <- fimm@sensitivity$raw
dim(fimm@sensitivity$profiles)
rownames(fimm@sensitivity$profiles)
getSummaryAssays <- function(pset) {
library(reshape2)
longfmt <- pset@sensitivity$profiles
assaynames <- colnames(longfmt)[-1:-2]
assaylist <- lapply(assaynames, function(x) {
res <- dcast(longfmt, drugid ~ cellid, value.var = x)
rownames(res) <- res[, 1]
res <- res[,-1]
return(res)
})
names(assaylist) <- assaynames
return(assaylist)
}
getRawAssays <- function(pset){
tmp <- getSummaryAssays(pset)[[1]]
correctcolnames <- colnames(tmp)
correctrownames <- rownames(tmp)
raw <- pset@sensitivity$raw
res <- list()
for (i in seq_along(1:dim(raw)[2])){
for (j in seq_along(1:dim(raw)[3])){
tmp <- data.frame(value=raw[, i, j])
tmp$drugid <- sub("_.+", "", rownames(tmp))
tmp$cellid <- sub(".+_", "", rownames(tmp))
tmp <- reshape2::dcast(tmp, drugid ~ cellid, value.var = "value")
rownames(tmp) <- tmp[, 1]
tmp <- tmp[, -1]
tmp <- tmp[match(correctrownames, rownames(tmp)), match(correctcolnames, colnames(tmp))]
res[[paste(dimnames(raw)[[2]][i], dimnames(raw)[[3]][j], sep=":")]] <- tmp
}
}
return( res )
}
pset2se <- function(pset){
myassays=c(getSummaryAssays(pset), getRawAssays(pset))
mycoldat <- pset@cell
rownames(mycoldat) <- mycoldat$cellid
SummarizedExperiment(assays=myassays, colData=mycoldat)
}
pset2se(fimm)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment