-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfobrosis
150 lines (118 loc) · 3.9 KB
/
fobrosis
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
Symbol<-strsplit(GPL96$Gene.Symbol, "///")
sb=list()
for(i in 1:22215) {
sb[i]=Symbol[[i]][1]
}
Symbol=unlist(sb)
GPL96$Gene.Symbol=Symbol
rt1=rt['218963_s_at',]
for(i in 1:ncol(rt1)){
group[i]=case_when(rt1[,i]<=quantile(rt1,0.5)~ 'low',
rt1[,i]>=quantile(rt1[,i],0.5)~'high')
}
group <- factor(group,levels = c("low","high"))
table(group)
library(easyTCGA)
diff_res <- diff_analysis(exprset = rt
, group = group
, is_count = F
)
## log2 transform not needed
## => Running limma
## => Running wilcoxon test
## => Analysis done.
diff_limma1 <- diff_res$deg_limma
library(clusterProfiler)
gene_entrezid <- bitr(geneID = diff_limma$Gene.Symbol
, fromType = "SYMBOL" # 从symbol
, toType = "ENTREZID" # 转成ENTREZID
, OrgDb = "org.Hs.eg.db"
)
head(gene_entrezid)
gene_entrezid <- merge(gene_entrezid,diff_limma,by.x = "SYMBOL", by.y = "Gene.Symbol")
genelist <- gene_entrezid$logFC
names(genelist) <- gene_entrezid$ENTREZID
genelist <- sort(genelist,decreasing = T)
head(genelist)
library(msigdbr)
m_t2g <- msigdbr(species = "Homo sapiens", category = "C5") %>%
dplyr::select(gs_name, entrez_gene)
gsea_res <- GSEA(genelist,
TERM2GENE = m_t2g,
minGSSize = 10,
maxGSSize = 500,
pvalueCutoff = 0.05,
pAdjustMethod = "BH",
seed = 456
)
library(enrichplot)
library(ggplot2)
ridgeplot(gsea_res,
showCategory = 20,
fill = "p.adjust", #填充色 "pvalue", "p.adjust", "qvalue"
core_enrichment = TRUE,#是否只使用 core_enriched gene
label_format = 30,
orderBy = "NES",
decreasing = FALSE
)+
theme(axis.text.y = element_text(size=8))
ids <- gsea_res@result$ID[10:15]
gseadist(gsea_res,
IDs = ids,
type="density" # boxplot
)+
theme(legend.direction = "vertical")
gsea_res_symbol <- setReadable(gsea_res,"org.Hs.eg.db","ENTREZID")
tmp <- as.data.frame(gsea_res_symbol)
head(tmp,2)
p=gseaplot2(gsea_res,geneSetID = 1:6)
p[[1]] <- p[[1]]+theme(legend.position = "top",legend.direction = "vertical")
p
if (pvalue_table) {
pd <- x[geneSetID, c("Description","pvalue", "p.adjust")]
# pd <- pd[order(pd[,1], decreasing=FALSE),]
rownames(pd) <- pd$Description
pd <- pd[,-1]
# pd <- round(pd, 4)
for (i in seq_len(ncol(pd))) {
pd[, i] <- format(pd[, i], digits = 4)
}
tp <- tableGrob2(pd, p.res)
p.res <- p.res + theme(legend.position = "none") +
annotation_custom(tp,
xmin = quantile(p.res$data$x, .5),
xmax = quantile(p.res$data$x, .95),
ymin = quantile(p.res$data$runningScore, .75),
ymax = quantile(p.res$data$runningScore, .9))
}
library(gridExtra)
x <- gsea_res_symbol
geneSetID <- 1:6
# 提取NES,P值等信息
pd <- x[geneSetID, c( "NES","pvalue", "p.adjust")]
pd <- pd[order(rownames(pd), decreasing=FALSE),]
for (i in seq_len(ncol(pd))) {pd[, i] <- format(pd[, i], digits = 6)}
# 通过修改table的主题来修改表格细节
tt <- ttheme_minimal(base_size = 10,
core=list(#bg_params = list(fill = NA, col=NA),
#fg_params=list(col=c("#F8766D","#00BA38","#619CFF","#73a0d8","#d0d873","#737ad8"))
)
)
tp <- tableGrob(pd,rows = NULL,theme = tt)
# 修改表格每个格子的宽度和高度
#tp$widths <- unit(rep(1.2,ncol(tp)), "cm")
tp$heights <- unit(rep(0.4,nrow(tp)),"cm") # cell height
plot(tp)
p <- gseaplot2(gsea_res, geneSetID = 1:6)
p[[1]] <- p[[1]]+
annotation_custom(tp,
xmin = 10000,
xmax = 14000,
ymin = 0.4,
ymax = 0.8
)+
theme(plot.title = element_text(size = 5),
legend.position = "top",
legend.direction = "vertical"
)
p