Skip to content

Instantly share code, notes, and snippets.

@grabear
Forked from federicomarini/iSEE_plug.R
Created August 20, 2020 17:18
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 grabear/a1c7d2aa413a2cfa96c3b231209c08ef to your computer and use it in GitHub Desktop.
Save grabear/a1c7d2aa413a2cfa96c3b231209c08ef to your computer and use it in GitHub Desktop.
A function to wrap up the DESeq2 inputs&outputs, and plug that as SingleCellExperiment into iSEE
library(DESeq2)
wrapup_for_iSEE <- function(dds, res) {
# dds to vst
vst <- vst(dds)
# initialize the container
se <- SummarizedExperiment(
assays = List(
counts = counts(dds),
normcounts = counts(dds,normalized = TRUE),
vst_counts = assay(vst)
)
)
# adding colData, taken directly from the DESeqDataSet object
colData(se) <- colData(dds)
# extract contrast info
this_contrast <- sub(".*p-value: (.*)","\\1",mcols(res, use.names=TRUE)["pvalue","description"])
# getting the rowData from the dds itself
rdd <- rowData(dds)
# modifying in advance the DESeqResults object
res$log10_baseMean <- log10(res$baseMean)
res$log10_pvalue <- -log10(res$pvalue)
# and for the rowData
rdd$log10_dispersion <- log10(rdd$dispersion)
# adding rowData to se
rowData(se)[[paste0("DESeq2_",gsub(" ","_",this_contrast))]] <- res
# merging in the existing rowData slot
rowData(se) <- cbind(rowData(se), rdd)
return(se)
}
# next, launch iSEE directly on the se object!
se <- wrapup_for_iSEE(dds,res)
library(iSEE)
iSEE(se)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment