class_to_deseq2 {cellpypes} | R Documentation |
Create DESeq2 object for a given cell type
Description
Create a DESeq2 data set (‘dds’ in the DESeq2 vignette) for the specified class (cell type).
Usage
class_to_deseq2(obj, meta_df, class, design = ~condition)
Arguments
obj |
A cellpypes object, see section cellpypes Objects below. |
meta_df |
Data frame where each column helps to identify a pseudobulk. Typical columns of meta_df are for example patient, treatment and cell type – anything that uniquely identifies a replicate / batch / 10x run. Each row in meta_df corresponds to a single cell in your raw count matrix. |
class |
The name of cellpypes class for which you want to test for differential expression. |
design |
A formula based on columns in |
Value
A DESeq2 object (e.g. dds)
cellpypes Objects
A cellpypes object is a list with four slots:
raw
(sparse) matrix with genes in rows, cells in columns
totalUMI
the colSums of obj$raw
embed
two-dimensional embedding of the cells, provided as data.frame or tibble with two columns and one row per cell.
neighbors
index matrix with one row per cell and k columns, where k is the number of nearest neighbors (we recommend 15<k<100, e.g. k=50). Here are two ways to get the neighbors index matrix:
Use
find_knn(featureMatrix)$idx
, where featureMatrix could be principal components, latent variables or normalized genes (features in rows, cells in columns).use
as(seurat@graphs[["RNA_nn"]], "dgCMatrix")> .1
to extract the kNN graph computed on RNA. The> .1
ensures this also works with RNA_snn, wknn/wsnn or any other available graph – check withnames(seurat@graphs)
.
Examples
data("simulated_umis")
# Meta data
ncells <- ncol(simulated_umis$raw)
dummy_variable <- function(x) factor(sample(x, ncells, replace=TRUE))
meta_data <- data.frame(patient=dummy_variable(paste0("patient", 1:6)),
treatment=dummy_variable(c("control", "treated")))
obj <- rule(simulated_umis, "T", "CD3E",">", 1e-4)
# > 5 s in CRAN check
dds <- class_to_deseq2(obj, meta_data, "T", ~ treatment)