-
Notifications
You must be signed in to change notification settings - Fork 0
/
H3K4me3_CHIPseeker_analysis.Rmd
230 lines (144 loc) · 5.75 KB
/
H3K4me3_CHIPseeker_analysis.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
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
---
title: "CHIPseeker"
author: "chenli"
date: "2022/8/19"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r}
library(ChIPseeker)
library(GenomicFeatures)
library(ggplot2)
library(dplyr)
```
## K4me3
```{r}
files <- list(`10+MET-1` = "../09.CHIPseeker/10+MET-1_macs2_peaks_CHIPseeker.bed",
`10+MET-2` = "../09.CHIPseeker/10+MET-2_macs2_peaks_CHIPseeker.bed",
`10mm-1` = "../09.CHIPseeker/10mm-1_macs2_peaks_CHIPseeker.bed",
`10mm-2` = "../09.CHIPseeker/10mm-2_macs2_peaks_CHIPseeker.bed",
`Ctrl-1` = "../09.CHIPseeker/Ctrl-1_macs2_peaks_CHIPseeker.bed",
`Ctrl-2` = "../09.CHIPseeker/Ctrl-2_macs2_peaks_CHIPseeker.bed" )
myPeaks <- GenomicRanges::GRangesList(`10+MET-1` = readPeakFile(files[[1]]),
`10+MET-2` = readPeakFile(files[[2]]),
`10mm-1` = readPeakFile(files[[3]]),
`10mm-2` = readPeakFile(files[[4]]),
`Ctrl-1` = readPeakFile(files[[5]]),
`Ctrl-2` = readPeakFile(files[[6]]) )
```
```{r fig.height=16, fig.width=10}
covplot(myPeaks[[1]])
covplot(myPeaks) + facet_grid(chr ~ .id)
```
```{r fig.height=5, fig.width=3}
##getPromoters函数准备启动子窗口
library(TxDb.Hsapiens.UCSC.hg38.knownGene)
txdb <- TxDb.Hsapiens.UCSC.hg38.knownGene
promoter <- getPromoters(TxDb=txdb, upstream=3000, downstream=3000)
lapply(1:6, function(x){
tagMatrix <- getTagMatrix(myPeaks[[x]], windows=promoter)
}) -> tagMatrixList
tagHeatmap(tagMatrixList[[1]], xlim =c(-3000, 3000), color="red")
tagHeatmap(tagMatrixList[[2]], xlim =c(-3000, 3000), color="red")
```
```{r fig.height=6, fig.width=12}
peakHeatmap(files, TxDb=txdb, upstream=3000, downstream=3000, color=c("#6495ED","#6495ED","#FFA500","#FFA500","#228B22","#228B22"))
```
```{r fig.height=3, fig.width=3.5}
plotAvgProf(tagMatrixList[[1]], xlim=c(-3000, 3000),xlab="Genomic Region (5'->3')", ylab = "Read Count Frequency")
plotAvgProf(tagMatrixList[[2]], xlim=c(-3000, 3000),xlab="Genomic Region (5'->3')", ylab = "Read Count Frequency")
plotAvgProf(tagMatrixList[[3]], xlim=c(-3000, 3000),xlab="Genomic Region (5'->3')", ylab = "Read Count Frequency")
plotAvgProf(tagMatrixList[[4]], xlim=c(-3000, 3000),xlab="Genomic Region (5'->3')", ylab = "Read Count Frequency")
plotAvgProf(tagMatrixList[[5]], xlim=c(-3000, 3000),xlab="Genomic Region (5'->3')", ylab = "Read Count Frequency")
plotAvgProf(tagMatrixList[[6]], xlim=c(-3000, 3000),xlab="Genomic Region (5'->3')", ylab = "Read Count Frequency")
```
```{r fig.height=3, fig.width=13}
##lapply函数进行批量处理
# tagMatrixList <- lapply(files, getTagMatrix, windows=promoter)
##conf定义置信区间,facet决定从上到下还是从左往右
plotAvgProf(tagMatrixList, xlim =c(-3000, 3000), conf=0.95, resample=500, facet="column")
```
```{r}
##addFlankGeneInfo看peak附近基因,flankDistance看peak左3kb距离
##指定tssRegion(启动子区域),一般TSS上下游区域作为启动子区域
## annoDb参数进行转换gene ID
# peakAnno = annotatePeak(files[[1]], tssRegion=c(-1000, 1000), TxDb=txdb, addFlankGeneInfo=TRUE, flankDistance=3000, annoDb = 'org.Hs.eg.db')
options(ChIPseeker.ignore_1st_exon = T)
options(ChIPseeker.ignore_1st_intron = T)
options(ChIPseeker.ignore_downstream = T)
options(ChIPseeker.ignore_promoter_subcategory = T)
peakAnnoList <- lapply(
files,
annotatePeak,
tssRegion = c(-1000, 1000),
TxDb = txdb,
addFlankGeneInfo = TRUE,
flankDistance = 3000,
annoDb = 'org.Hs.eg.db'
)
as.GRanges(peakAnnoList[[1]]) %>% head(3)
```
```{r}
plotAnnoPie(peakAnnoList[[1]])
```
```{r}
plotAnnoBar(peakAnnoList)
```
```{r}
df_peak <- lapply(names(peakAnnoList), function(x){
tmp <- peakAnnoList[[x]]@annoStat
tmp$Treat <- x
return(tmp)
}) %>% do.call(rbind,.) %>%
mutate(Treat = factor(Treat, levels = c("10+MET-2","10+MET-1","10mm-2",
"10mm-1","Ctrl-2","Ctrl-1")),
Class = rep(c("10+MET","10MM","CON"), each = 12))
df_peak <- df_peak %>% dplyr::group_by(Class, Feature) %>% summarize(meanFreq = mean(Frequency)) %>% data.frame()
Ctrl_freq <- subset(df_peak, Class == "CON")$meanFreq
freq_10MM <- subset(df_peak, Class == "10MM")$meanFreq
freq_10MET <- subset(df_peak, Class == "10+MET")$meanFreq
All_freq <- Ctrl_freq + freq_10MM+ freq_10MET
prop.test ( Ctrl_freq , All_freq)
prop.test ( freq_10MM , All_freq)
prop.test ( freq_10MET , All_freq)
matrix_freq <- cbind(Ctrl_freq,freq_10MM,freq_10MET )
rownames(matrix_freq) <- unique(df_peak$Feature)
chisq.test(matrix_freq, correct = F)
```
```{r fig.height=3, fig.width=5}
ggplot(df_peak,
aes(x = Treat,
y = Frequency,
fill = Feature)) +
geom_bar(stat = 'identity', width = 0.4, position = "fill") +
coord_flip() +
theme_minimal(base_size = 15) +
scale_fill_manual(values = RColorBrewer::brewer.pal(6, "Set2")) +
labs(x = "", y = "Percentage (%)") +
theme(legend.title = element_blank(),
panel.grid.minor=element_blank(),
panel.grid.major.y = element_blank()
) -> p_barplot
pdf("../09.CHIPseeker/K4me3_anno_barplot.pdf", width = 5, height = 3)
p_barplot
dev.off()
```
```{r fig.height=6, fig.width=6}
genes <- lapply(peakAnnoList, function(i) as.data.frame(i)$geneId)
genes_uniq <- list(`10+MET` = unique(c(genes[[1]],genes[[2]])),
`10mm` = unique(c(genes[[3]],genes[[4]])),
`Ctrl` = unique(c(genes[[5]],genes[[6]])))
vennplot(genes_uniq)
```
```{r}
peakAnnoList_df <- lapply(peakAnnoList, function(x){
as.data.frame(x)
})
```
```{r}
library(openxlsx)
write.xlsx(peakAnnoList_df,file='./09.CHIPseeker/K4me3_anno_peak.xlsx',
colNames = TRUE,colWidths = c("auto", "auto", "auto","auto", "auto", "auto"))
```