-
Notifications
You must be signed in to change notification settings - Fork 0
/
ScoreGenes_UCell.R
50 lines (39 loc) · 1.79 KB
/
ScoreGenes_UCell.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
source('HelperFUNs.R')
library(UCell)
fig_path <- "UCell_out"
object <- readRDS("seuratobj.RDS")
DefaultAssay(object) <- "RNA"
## find files with pathway genes and load as list
file_list <- list.files( pattern = "*.grp")
file_list
df_list <- lapply(file_list,
FUN = function(files) {
read.table(files, header=TRUE, quote="\"")
})
## extract gene set (pathway) names
names <- lapply(df_list, function(x) names(x))
names <- unlist(names)
## extract genes for each pathway and add to list
path <- lapply(df_list, unlist, use.names=FALSE)
names(path) <- names
## change gene names to upper case if needed
#path <- lapply(path, toupper)
## extract all gene names present in seurat object
all.genes <- rownames(object)
## remove pathway genes that are NOT in seurat dataset
path <- lapply(path, function(x) x[x %in% all.genes])
## or remove pathway genes that are present in seurat dataset
#path <- lapply(path, function(x) x[!x %in% all.genes])
## run UCell scoring
ucell <- AddModuleScore_UCell(object, features = path, maxRank = 2000, slot = "data")
signature.names <- paste0(names(path), "_UCell")
## create and save Feature plots and Violin plots
lapply(seq_along(signature.names), function(i) {
p1 <- VlnPlot(ucell, features = signature.names[i]) + theme(legend.position = 'none')
SaveFigure(p1, paste0('VlnPlot_',signature.names[i]), width = 8, height = 8)})
lapply(seq_along(signature.names), function(i) {
p1 <- VlnPlot(ucell, features = signature.names[i], split.by = "group")
SaveFigure(p1, paste0('VlnPlot2_',signature.names[i]), width = 10, height = 8)})
lapply(seq_along(signature.names), function(i) {
p1 <- FeaturePlot(ucell, features = signature.names[i])
SaveFigure(p1, paste0('FeaturePlot_',signature.names[i]), width = 8, height = 8)})