Setting Up DUBStepR

Installing DUBStepR

DUBStepR requires your R version to be >= 3.5.0. Once you’ve ensured that, you can install DUBStepR from CRAN using the following command:

if (!require(DUBStepR))
  install.packages("DUBStepR")

The installation should take ~ 30 seconds, not including dependencies.

Loading DUBStepR into your environment

After installation, load DUBStepR using the following command:

library(DUBStepR)

Using DUBStepR

For users new to single-cell RNA sequencing data analysis, we recommend using DUBStepR with the Seurat (Satija, R. et al. Nature Biotechnol. 33.5(2015):495.) package to analyze single-cell RNA seq data. Below is a tutorial using the Seurat package.

Install and load Seurat

Seurat can be installed and loaded into your R environment using the following commands:

library(Seurat)
library(dplyr)

Prepare Seurat object

Here, we use a publicly available PBMC dataset generated by 10X Genomics. Here’s a link to the dataset. We use the Feature / cell matrix HDF5 (filtered) file.

Locate the file in your working directory and load the data in to your Seurat object using the hdf5r package in the following manner (For easy loading, we start directly from the Seurat object in this package) :

load("counts.rda")
seuratObj <- CreateSeuratObject(counts = counts, assay = "RNA", project = "10k_PBMC")
seuratObj
#> An object of class Seurat 
#> 5362 features across 996 samples within 1 assay 
#> Active assay: RNA (5362 features, 0 variable features)

For DUBStepR, we recommend log-normalizing your data. That can be performed in Seurat using the following command:

seuratObj <- NormalizeData(object = seuratObj, normalization.method = "LogNormalize")

Run DUBStepR to identify feature genes

DUBStepR can be inserted into the Seurat workflow at this stage, and we recommend that be done in the following manner:

dubstepR.out <- DUBStepR(input.data = seuratObj@assays$RNA@data, min.cells = 0.05*ncol(seuratObj), optimise.features = TRUE, k = 10, num.pcs = 20, error = 0)
#> 
#> Running DUBStepR...
#> Dimensions of input data: 5362 x 996
#> 
#> Expression Filtering Done.
#> Mitochondrial, Ribosomal and Pseudo Genes Filtering Done.
#> Dimensions of filtered data:  5256  x  996
#> 
#> Computing GGC...
#> Done.
#> 
#> Running Stepwise Regression...
#> 
#> Done.
#> 
#> Adding correlated features...
#> 
#> Done.
#> Determining optimal feature set...
#> 
#> Done.
seuratObj@assays$RNA@var.features <- dubstepR.out$optimal.feature.genes
seuratObj

This step could take upto 1 minute on a normal desktop computer.

Visualize and cluster cells

Following Seurat’s recommendations, we scale the gene expression data and run Principal Component Analysis (PCA). We then visualize the standard deviation of PCs using an elbow plot and select the number of PCs we think is sufficient to explain the variance in the dataset.

seuratObj <- ScaleData(seuratObj, features = rownames(seuratObj))
#> Centering and scaling data matrix
seuratObj <- RunPCA(seuratObj, features = VariableFeatures(object = seuratObj), npcs = 30)
#> PC_ 1 
#> Positive:  TRAC, MALAT1, HLA-C, EEF1A1, GZMA, CD79A, CD79B, CST7, IGHM, MS4A1 
#>     PRF1, NKG7, IGHD, TCL1A, GNLY, KLRD1, JCHAIN, FCGR3A, CD74, NRGN 
#>     HLA-DRB1 
#> Negative:  LYZ, S100A9, S100A8, FCN1, CST3, CSTA, S100A12, LGALS1, MNDA, AC020656.1 
#>     LST1, CTSS, VCAN, TYROBP, AIF1, MS4A6A, FCER1G, S100A4, HLA-DRA, ACTB 
#>     CES1 
#> PC_ 2 
#> Positive:  NKG7, GZMA, PRF1, CST7, GNLY, KLRD1, S100A4, HLA-C, TRAC, FCGR3A 
#>     ACTB, FCER1G, TYROBP, LGALS1, MALAT1, NRGN, AIF1, S100A12, VCAN, S100A8 
#>     LYZ 
#> Negative:  IGHM, CD79A, IGHD, CD79B, MS4A1, TCL1A, HLA-DRB1, HLA-DRA, CD74, JCHAIN 
#>     CTSS, EEF1A1, MS4A6A, MNDA, CSTA, FCN1, LST1, AC020656.1, CST3, CES1 
#>     S100A9 
#> PC_ 3 
#> Positive:  TRAC, EEF1A1, S100A12, VCAN, MALAT1, S100A8, MS4A6A, AC020656.1, S100A9, AIF1 
#>     LYZ, MNDA, CES1, CSTA, NRGN, FCN1, CST3, LST1, CTSS, S100A4 
#>     LGALS1 
#> Negative:  GNLY, KLRD1, NKG7, PRF1, CST7, GZMA, FCGR3A, CD74, FCER1G, CD79B 
#>     HLA-DRB1, ACTB, IGHM, CD79A, HLA-DRA, IGHD, TYROBP, MS4A1, TCL1A, HLA-C 
#>     JCHAIN 
#> PC_ 4 
#> Positive:  MALAT1, EEF1A1, VCAN, S100A12, AC020656.1, MS4A6A, S100A8, CST7, GZMA, NKG7 
#>     PRF1, CSTA, MNDA, CTSS, S100A9, GNLY, KLRD1, LYZ, S100A4, FCN1 
#>     CES1 
#> Negative:  NRGN, ACTB, HLA-C, CST3, FCGR3A, FCER1G, JCHAIN, HLA-DRB1, AIF1, LST1 
#>     HLA-DRA, CD79B, TCL1A, CD74, CD79A, MS4A1, IGHM, IGHD, LGALS1, TYROBP 
#>     TRAC 
#> PC_ 5 
#> Positive:  FCGR3A, EEF1A1, AIF1, LST1, HLA-C, S100A4, HLA-DRB1, CD74, HLA-DRA, FCER1G 
#>     MALAT1, CST3, CTSS, ACTB, LGALS1, TYROBP, TRAC, JCHAIN, CD79B, FCN1 
#>     CSTA 
#> Negative:  S100A12, VCAN, AC020656.1, S100A8, CES1, NRGN, IGHD, TCL1A, GZMA, PRF1 
#>     MS4A6A, IGHM, S100A9, GNLY, CST7, NKG7, KLRD1, MNDA, CD79A, MS4A1 
#>     LYZ
ElbowPlot(seuratObj, ndims = 30)

We select the first few feature genes selected by DUBStepR to show cell type specific expression, using 10 PCs to compute UMAP coordinates.

seuratObj <- RunUMAP(seuratObj, dims = 1:10, n.components = 2, seed.use = 2019)
#> Warning: The default method for RunUMAP has changed from calling Python UMAP via reticulate to the R-native UWOT using the cosine metric
#> To use Python UMAP via reticulate, set umap.method to 'umap-learn' and metric to 'correlation'
#> This message will be shown once per session
#> 11:14:16 UMAP embedding parameters a = 0.9922 b = 1.112
#> 11:14:16 Read 996 rows and found 10 numeric columns
#> 11:14:16 Using Annoy for neighbor search, n_neighbors = 30
#> 11:14:16 Building Annoy index with metric = cosine, n_trees = 50
#> 0%   10   20   30   40   50   60   70   80   90   100%
#> [----|----|----|----|----|----|----|----|----|----|
#> **************************************************|
#> 11:14:16 Writing NN index file to temp file /var/folders/t7/0txgn1656t9dfyp_z35999dm0000gn/T//RtmpEvv3o7/file1373e19492b35
#> 11:14:16 Searching Annoy index using 1 thread, search_k = 3000
#> 11:14:16 Annoy recall = 100%
#> 11:14:16 Commencing smooth kNN distance calibration using 1 thread
#> 11:14:17 Initializing from normalized Laplacian + noise
#> 11:14:17 Commencing optimization for 500 epochs, with 38916 positive edges
#> 11:14:18 Optimization finished
FeaturePlot(seuratObj, features = VariableFeatures(object = seuratObj)[1:9], cols = c("lightgrey", "magenta"))

Using known marker genes, we show cell type specific regions of the UMAP

FeaturePlot(seuratObj, features = c("MS4A1", "NKG7", "CD3E", "IL7R", "CD8A", "CD14", "CST3", "FCGR3A", "PPBP"))
#> Warning in FetchData(object = object, vars = c(dims, "ident", features), : The
#> following requested variables were not found: PPBP

We select 10 PCs for clustering, and visualize the cells in a 2D UMAP.

seuratObj <- FindNeighbors(seuratObj, reduction = "pca", dims = 1:10)
#> Computing nearest neighbor graph
#> Computing SNN
seuratObj <- FindClusters(seuratObj)
#> Modularity Optimizer version 1.3.0 by Ludo Waltman and Nees Jan van Eck
#> 
#> Number of nodes: 996
#> Number of edges: 30332
#> 
#> Running Louvain algorithm...
#> Maximum modularity in 10 random starts: 0.8444
#> Number of communities: 11
#> Elapsed time: 0 seconds
DimPlot(seuratObj, reduction = "umap", label = TRUE, pt.size = 0.5, repel = T, label.size = 5)

Identifying top 10 marker genes of each cluster

top.10.markers <- FindAllMarkers(object = seuratObj, assay = "RNA", logfc.threshold = 0.5, min.pct = 0.5, only.pos = TRUE) %>% filter(p_val_adj < 0.1) %>% group_by(cluster) %>% top_n(n = 10, wt = avg_log2FC)
#> Calculating cluster 0
#> Calculating cluster 1
#> Calculating cluster 2
#> Calculating cluster 3
#> Calculating cluster 4
#> Calculating cluster 5
#> Calculating cluster 6
#> Calculating cluster 7
#> Calculating cluster 8
#> Calculating cluster 9
#> Calculating cluster 10
DoHeatmap(object = seuratObj, features = unique(top.10.markers$gene), size = 5)

Annotating clusters using gene expression

cell.types <- c("0" = "CD14+ Monocytes", "5" = "Inflammatory CD14+ Monocytes", "1" = "Naive CD4+ T cells", "3" = "Memory CD4+ T cells", "4" = "Naive CD8+ T cells", "2" = "B cells", "6" = "NK cells", "7" = "CD16+ Monocytes", "8" = "Platelets")
seuratObj <- RenameIdents(seuratObj, cell.types)
DimPlot(seuratObj, reduction = "umap", label = TRUE, pt.size = 1, repel = TRUE, label.size = 5) + NoLegend()