Features
As already explained, the sparsity of the count
matrix is high, very high.
To the point that there probably are some features that have
so low expression level that they were only counted in
very few cells. As such, they have absolutely
no chance to characterize any cell type, nor harbor
some variation between different cell types.
As such, we should discard these
features
What are the actual dimensions of our expression data ?
## Dimensions of our Seurat object
dim(sobj)
Show output
[1] 31053 4587
We want to remove the features that are expressed in less than
5 cells.
First, we quantify, for each feature, the number of cells with 0
count.
## Compute the amount of 0s per feature
nFeat_zero <- sparseMatrixStats::rowCounts(
x = SeuratObject::GetAssayData(
object = sobj,
assay = "RNA",
layer = "counts"),
value = 0)
## Inversion : computing the number of cells with at least one count, per feature
nFeat_nonzero <- ncol(sobj) - nFeat_zero
## Identify those with at least 5 cells with expression
nFeat_keep <- nFeat_nonzero >= min_cells
## Quantify the selected ones
table(nFeat_keep)
Show output
nFeat_keep
FALSE TRUE
18545 12508
And now we can discard features expressed in less
than 5 cells :
filtc5_pre <- SC.helper::QnD_viz(sobj = sobj,
return_plot = TRUE)
Show plot

## Restrict the Seurat object
sobj <- sobj[nFeat_keep,]
What are the Seurat object dimensions, now ?
Show output
[1] 12508 4587
We can visualize the cell space after this features
filtering
filtc5_post <- SC.helper::QnD_viz(sobj = sobj,
return_plot = TRUE)
Show plot

Merging plots for ease of visualization :
## Using the patchwork package to merge plots (and ggplot2 to add titles)
patchwork::wrap_plots(
list(
filtc5_pre & ggplot2::ggtitle(label = "BEFORE"),
filtc5_post & ggplot2::ggtitle(label = "AFTER")),
nrow = 1)
Show plot

Question :
Do you see any difference when comparing before vs after features filtering ?
## . Not much changed, maybe cell groups seem a bit more condensed
##
## . This is expected, as we removed features with almost no expression
Cells
We are now able to apply all the filtering
strategies we established for each QC metric.
## Identify the cells to keep
bc_keep <- sobj$nFeature_RNA_in_range &
sobj$nCount_RNA_in_range &
sobj$percent_mt_in_range &
sobj$percent_rb_in_range &
sobj$percent_st_in_range
## Contengency
table(bc_keep)
Show output
bc_keep
FALSE TRUE
309 4278
Apply the filter
## Seurat object BEFORE cell filtering
dim(sobj)
Show output
[1] 12508 4587
## Apply cell filtering
sobj <- subset(x = sobj, cells = colnames(sobj)[bc_keep])
## Seurat object AFTER cell filtering
dim(sobj)
Show output
[1] 12508 4278
We can visualize the cell space since this cell
filtering
SC.helper::QnD_viz(sobj = sobj)
Show plot

Question
Do you see any difference when comparing before vs after features filtering ?
## . Not much changed as well (we did not discard many cells)
##
## . The biggest cluster structure seems more defined