-
Notifications
You must be signed in to change notification settings - Fork 1
/
stress_check_all_classes.R
87 lines (68 loc) · 3.46 KB
/
stress_check_all_classes.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
library(Seurat)
library(SeuratDisk)
lydia <- LoadH5Seurat('F://lydia.h5Seurat0.h5seurat')
head(lydia)
library(ggplot2)
library(ggpubr)
library(escape)
library(patchwork)
gene.sets1 <- getGeneSets(library = "C5", gene.sets = c('GOBP_NEURON_DEATH','GOBP_RESPONSE_TO_AXON_INJURY',
'GOBP_INFLAMMATORY_RESPONSE', 'GOBP_INFLAMMASOME_COMPLEX_ASSEMBLY',
'GOBP_ACUTE_INFLAMMATORY_RESPONSE', 'GOBP_CYTOKINE_PRODUCTION_INVOLVED_IN_INFLAMMATORY_RESPONSE',
'GOBP_NEUROINFLAMMATORY_RESPONSE'),
species = 'Mus musculus')
ES <- enrichIt(obj = lydia,
gene.sets = gene.sets1,
groups = 1000)
lydia <- AddMetaData(lydia, ES)
ES2 <- data.frame(lydia[[]], Idents(lydia))
colnames(ES2)[ncol(ES2)] <- "cluster"
lyd_RGC <- ES2
fun_range <- function(x) { # Create user-defined function
(x - min(x)) / (max(x) - min(x))}
neude <- aggregate(lyd_RGC$GOBP_NEURON_DEATH, list(lyd_RGC$anno2, lyd_RGC$background), FUN = mean)
neude$neude <- fun_range(x = neude$x)
resax <- aggregate(lyd_RGC$GOBP_RESPONSE_TO_AXON_INJURY, list(lyd_RGC$anno2, lyd_RGC$background), FUN = mean)
resax$resax <- fun_range(x = resax$x)
acinf <- aggregate(lyd_RGC$GOBP_ACUTE_INFLAMMATORY_RESPONSE, list(lyd_RGC$anno2, lyd_RGC$background), FUN = mean)
acinf$acinf <- fun_range(x = acinf$x)
cytpr <- aggregate(lyd_RGC$GOBP_CYTOKINE_PRODUCTION_INVOLVED_IN_INFLAMMATORY_RESPONSE, list(lyd_RGC$anno2, lyd_RGC$background), FUN = mean)
cytpr$cytpr <- fun_range(x = cytpr$x)
infco <- aggregate(lyd_RGC$GOBP_INFLAMMASOME_COMPLEX_ASSEMBLY, list(lyd_RGC$anno2, lyd_RGC$background), FUN = mean)
infco$infco <- fun_range(x = infco$x)
infre <- aggregate(lyd_RGC$GOBP_INFLAMMATORY_RESPONSE, list(lyd_RGC$anno2, lyd_RGC$background), FUN = mean)
infre$infre <- fun_range(x = infre$x)
neure <- aggregate(lyd_RGC$GOBP_NEUROINFLAMMATORY_RESPONSE, list(lyd_RGC$anno2, lyd_RGC$background), FUN = mean)
neure$neure <- fun_range(x = neure$x)
final <- neude
final$neude <- neude$neude
final$resax <- resax$resax
final$acinf <- acinf$acinf
final$cytpr <- cytpr$cytpr
final$infco <- infco$infco
final$infre <- infre$infre
final$neure <- neure$neure
head(final)
final$injury <- final$resax + final$neude
final$inflam <- final$acinf + final$cytpr + final$infco + final$infre + final$neure
final$injury_new <- fun_range(x = final$injury)
final$inflam_new <- fun_range(x = final$inflam)
testnew <- final %>% select(Group.1, injury_new, inflam_new, Group.2) %>%
pivot_longer(., cols = c(injury_new, inflam_new), names_to = "Var", values_to = "Val")
head(testnew)
ggplot(testnew, aes(x = reorder(Group.1, +Val), y = Val, fill = Group.2, color = Group.2, group = Group.2)) +
geom_point() + geom_line() + theme_bw() + coord_flip() + facet_wrap(~Var)
VlnPlot(lydia, features = "percent.mt", split.by = "background")
df <- FetchData(lydia, vars = c("percent.mt", "anno2", "background"))
head(df)
df$background <- factor(df$background, levels = c("WT", "DFcKO"))
ggplot(df, aes(x = anno2, y = percent.mt, fill = background)) +
geom_violin(scale = "width", trim = FALSE) +
theme_minimal() +
labs(
title = "Violin Plot of percent.mt",
x = "Annotation (anno2)",
y = "Percent Mitochondrial (percent.mt)"
) +
scale_fill_brewer(palette = "Set3") + # Optional: to change the color palette
scale_y_continuous(limits = c(0, 40))