Chapter 3 Seurat Pre-process Filtering Confounding Genes

library(Seurat)
library(tidyverse)
library(magrittr)

3.1 Normalize, scale, find variable genes and dimension reduciton

  • Remove confounding genes
res <- seq(0.5, 3, 0.5)
ndims <- 30
vars.reg <- c('nCount_RNA')


combined <- NormalizeData(combined)
combined <- FindVariableFeatures(combined, selection.method = 'vst', nfeatures = 2000)
hvg <- VariableFeatures(combined)
var_regex = '^HLA-|^IG[HJKL]|^RNA|^MT|^RP' # remove HLA, immunoglobulin, RNA, MT, and RP genes based on HUGO gene names
hvg = grep(var_regex, hvg, invert=T, value=T)


combined %<>%
  ScaleData(vars.to.regress = vars.reg) %>%
  RunPCA(features = hvg) %>%
  FindNeighbors(dims = 1:ndims) %>%
  FindClusters(resolution = res) %>%
  RunUMAP(dims = 1:ndims) %>%
  RunTSNE(dims = 1:ndims)