#' Calculate the gene detection rate in each condition
#' @name get_pct_expr
#' @param seuratobj A Seurat object
#' @param conditions A vector of conditions of interest
#' @return
#' A matrix of the detection rate of each gene in each condition with genes in rows and conditions in columns
#' @import tidyverse Seurat
#' @export
get_pct_expr <- function(seuratobj, conditions) {
data = seuratobj@assays$RNA@data
pct_expr = matrix(0, nrow = nrow(data), ncol = length(conditions))
Idents(object = seuratobj) = 'Condition'
for (i in 1:length(conditions)) {
subdata = data[,WhichCells(seuratobj, idents = conditions[i])]
pct_expr[,i] = rowSums(subdata >0)/ncol(subdata)
}
rownames(pct_expr) = rownames(data)
colnames(pct_expr) = conditions
return(pct_expr)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.