-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathAssignGeneSignature.Rmd
55 lines (38 loc) · 1.25 KB
/
AssignGeneSignature.Rmd
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
50
51
# Assign Gene Signature
## Description
Given a gene list, calculate gene signature by averaging gene expresion
## Load seurat object
```{r, cache=TRUE}
combined <- get(load('data/Demo_CombinedSeurat_SCT_Preprocess.RData'))
Idents(combined) <- "cluster"
```
## Load gene lists, here using the layer-enriched genes as examples
```{r loadgene, cache=TRUE}
f.ls <- list.files(
"data/GeneList/",
pattern = "FDR001.upDEG.csv$",
full.names = T,
recursive = T
)
names(f.ls) <-
f.ls %>% map(basename) %>% map( ~ str_remove(.x, "vs.*"))
layer.ls <- f.ls %>% map( ~ {
df <- fread(.x)
gn <- df$id[!is.na(df$id)]
gn <- gn[which(gn %in% rownames(combined))]
return(gn)
})
```
## Calcuate gene signature per gene list
```{r genesignature, cache=TRUE}
mean.ls <- layer.ls %>% map_dfc(~ colMeans(x = as.matrix(combined@assays$SCT[.x, ]), na.rm = TRUE))
rownames(mean.ls) <- rownames([email protected])
combined <- AddMetaData(combined, mean.ls, col.name = colnames(mean.ls))
```
## Explore the gene signature by `FeaturePlot` and `VlnPlot`
```{r plot, cache=TRUE}
names(layer.ls) %>% map(~ FeaturePlot(object = combined, features = .x, pt.size = 0.001))
names(layer.ls) %>% map(~ {
VlnPlot(object = combined, features = .x, pt.size = 0) + NoLegend()
})
```