This repository has been archived by the owner on Sep 4, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy path901_compareGRN_chipseq.R
361 lines (270 loc) · 11.4 KB
/
901_compareGRN_chipseq.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
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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
# This script is to 1) compare the edges in top 1 million GRNs
# with interactions found in ChIP-Seq data (KN1, FEA4 and O2).
# 2) compare the top 100,000 edges in each tissue GRNs
# with interactions found in ChIP-Seq data (KN1, FEA4 and O2).
# 3) compare the top 4000 targets in each tissue GRNs
# with interactions found in ChIP-Seq data (KN1, FEA4 and O2).
# The result can be used in chi-square test.
# 4) Do the same thing for Briggs RNA and protein GRNs, top 1 million edges
# and top 100,000 edges.
# 5) All comparisons can be tested by one-tail Fisher's exact test and/or
# chi-square test.
# File in: 1) top 1 million edges for each tissue GRN:
# ll_leaf, ll_root, ll_sam and ll_seed
# 2) top 100,000 edges for each tissue GRN, same name.
# 3) ChIP target genes for KN1, FEA4 and O2
# File out: 1) Number of the overlap (record while running script)
# 2) Top 1 million edges from four tissues were combined into one
# long table (link_list_allFour_1million.RData)
###############################################################################
setwd("~/projects/NTWK/tissue_ntwk/")
load("data/right_seed/link_list_four_tissue_1million.RData")
load("data/right_seed/link_list_four_tissue_100thousand.RData")
library(tidyverse)
# Read chip-seq target list. ChIP only,
kn1 <- read_tsv("./data/KN1_chip_binding_10k.txt", col_names = "geneid")
kn1 <- as.vector(kn1$geneid)
fea4 <- read_tsv("data/FEA4_binding_10k.txt", col_names = "geneid")
fea4 <- as.vector(fea4$geneid)
o2 <- read_tsv("./data/o2_bind_gene.txt", col_names = "geneid")
o2 <- as.vector(o2$geneid)
# all geneids are in `length(kn1 %in% gene_name_all)`
# Try list with expression changes (true binding).
# O2 is from
kn1 <- read_tsv("./data/kn1_true.txt", col_names = "geneid")
kn1 <- as.vector(kn1$geneid)
kn1 <- read_tsv("data/kn1_true_withleaf.txt", col_names = "geneid")
kn1 <- as.vector(kn1$geneid)
fea4 <- read_tsv("data/FEA4_true_binding.txt", col_names = "geneid")
fea4 <- as.vector(fea4$geneid)
o2 <- read_tsv("data/o2_true_binding.txt", col_names = "geneid")
o2 <- as.vector(o2$geneid)
# combine four link_list into one.
ll_leaf <- mutate(ll_leaf, tissue = "leaf")
ll_root <- mutate(ll_root, tissue = "root")
ll_sam <- mutate(ll_sam, tissue = "sam")
ll_seed <- mutate(ll_seed, tissue = "seed")
ll_four <- bind_rows(ll_leaf, ll_root, ll_sam, ll_seed)
saveRDS(object = ll_four,
file = "data/right_seed/link_list_allFour_10million.RData")
# make sure the number is correct
ll_four %>%
group_by(tissue) %>%
summarise(n = n())
# Query gene (KN1, P1, O2 or FEA4)
# KN1: GRMZM2G017087; O2: GRMZM2G015534; P1: GRMZM2G084799; FEA4: GRMZM2G133331
# write a function to calcule edges numbers
edges_in_chip <- function(gene, chip){
edg <- ll_four %>%
filter(regulatory.gene == gene) %>%
group_by(tissue) %>%
summarise(n = n())
edg_chip <- ll_four %>%
filter(regulatory.gene == gene) %>%
filter(target.gene %in% chip) %>%
group_by(tissue) %>%
summarise(n = n())
left_join(edg, edg_chip, by = "tissue")
}
# the first number is how many edges in our top 1 million GRN.
# the second number is how many are overlap with ChIP-Seq targets.
edges_in_chip("GRMZM2G017087", kn1) # KN1: GRMZM2G017087
edges_in_chip("GRMZM2G084799", p1) # P1: GRMZM2G084799
edges_in_chip("GRMZM2G015534", o2) # O2: GRMZM2G015534
# FEA4: GRMZM2G133331 number is similar using KN1
edges_in_chip("GRMZM2G133331", fea4)
# I can use chi-square test to test enrichment.
# columns are "Regulated", "not-Regulated"; rows are "binding", "not binding"
####### Regulated not-Regulated
# Bind 5 4060
# Not Bind 67 35347
test <- matrix(c(51,743,2357,36328), nrow = 2)
test
set.seed(123)
fisher.test(test, simulate.p.value = T, alternative = "greater")
chisq.test(test,simulate.p.value = T)
#phyper(191,758,38721,4274, lower.tail = T)
plantReg <- read_tsv("regulation_merged_Zma.txt",
col_names = c("regulator", "direction",
"target", "species", "type"))
head(plantReg)
edg_chip <- ll_four %>%
filter(regulatory.gene == gene) %>%
filter(target.gene %in% chip) %>%
group_by(tissue) %>%
summarise(n = n())
plantReg %>%
filter(regulator == "GRMZM2G017087") %>%
filter(target %in% kn1) %>%
summarise(n = n())
################################################################################
## GET TOP ~4000 GENES AND FIND OVERLAP WITH CHIP TARGET
################################################################################
load("data/right_seed/wm_tissue_4tf.RData")
# KN1 top 4274
kn1_sam_4274 <- names(sort(wm_sam_4tf["GRMZM2G017087",],
decreasing = T)[1:4274])
kn1_seed_4274 <- names(sort(wm_seed_4tf["GRMZM2G017087",],
decreasing = T)[1:4274])
print(paste("Top 4274 predicted KN1 target from SAM GRN has",
length(intersect(kn1_sam_4274, kn1)),
"overlap with ChIP binding targets") )
print(paste("Top 4274 predicted KN1 target from seed GRN has",
length(intersect(kn1_seed_4274, kn1)),
"overlap with ChIP binding targets") )
# FEA4 top 4065
fea4_leaf_4065 <- names(sort(wm_leaf_4tf["GRMZM2G133331",],
decreasing = T)[1:4065])
fea4_root_4065 <- names(sort(wm_root_4tf["GRMZM2G133331",],
decreasing = T)[1:4065])
fea4_sam_4065 <- names(sort(wm_sam_4tf["GRMZM2G133331",],
decreasing = T)[1:4065])
fea4_seed_4065 <- names(sort(wm_seed_4tf["GRMZM2G133331",],
decreasing = T)[1:4065])
print(paste("Top 4065 predicted FEA4 target from leaf GRN has",
length(intersect(fea4_leaf_4065, fea4)),
"overlap with ChIP binding targets") )
print(paste("Top 4065 predicted FEA4 target from root GRN has",
length(intersect(fea4_root_4065, fea4)),
"overlap with ChIP binding targets") )
print(paste("Top 4065 predicted FEA4 target from SAM GRN has",
length(intersect(fea4_sam_4065, fea4)),
"overlap with ChIP binding targets") )
print(paste("Top 4065 predicted FEA4 target from seed GRN has",
length(intersect(fea4_seed_4065, fea4)),
"overlap with ChIP binding targets") )
# O2 top 2408
o2_seed_2408 <- names(sort(wm_seed_4tf["GRMZM2G015534",],
decreasing = T)[1:2408])
print(paste("Top 2408 predicted O2 target from seed GRN has",
length(intersect(o2_seed_2408, o2)),
"overlap with ChIP binding targets") )
################################################################################
# random overlap
################################################################################
# KN1
kn1_random_4274 <- c()
for (i in c(1:10000)) {
set.seed(i)
rd_sample <- sample(x = names(wm_seed_4tf[1,]), replace = F, size = 4274)
rd_number <- length(intersect(rd_sample, kn1))
kn1_random_4274 <- append(kn1_random_4274, rd_number)
}
print(mean(kn1_random_4274))
hist(kn1_random_4274)
# FEA4
fea4_random_4065 <- c()
for (i in c(1:10000)) {
set.seed(i)
rd_sample <- sample(x = names(wm_seed_4tf[1,]), replace = F, size = 4065)
rd_number <- length(intersect(rd_sample, fea4))
fea4_random_4065 <- append(fea4_random_4065, rd_number)
}
print(mean(fea4_random_4065))
hist(fea4_random_4065)
################################################################################
# BRIGGS NETWORK OVERLAP CHIPSEQ
################################################################################
# Briggs networks were downloaded from https://goo.gl/9YYgBX.
# 1. Read briggs networks. 1 million networks
brig_protein <- read_tsv(file = "data/briggs/briggs_protein_only.txt")
brig_rna <- read_tsv(file = "data/briggs/briggs_rna_only.txt")
brig_three <- read_tsv(file = "data/briggs/briggs_protein+rna+phospho.txt")
# 2. Calculate overlap of Briggs network with ChIP bindings.
# 2.1 KN1
gene <- "GRMZM2G017087" #KN1
# How many edges in each network?
tf_brig_protein <- brig_protein %>%
filter(regulator == gene)
tf_brig_rna <- brig_rna %>%
filter(regulator == gene)
tf_brig_three <- brig_three %>%
filter(regulator == gene)
# How many genes have ChIP binding?
tf_brig_protein_true <- brig_protein %>%
filter(regulator == gene) %>%
filter(target %in% kn1)
tf_brig_rna_true <- brig_rna %>%
filter(regulator == gene) %>%
filter(target %in% kn1)
tf_brig_three_true <- brig_three %>%
filter(regulator == gene) %>%
filter(target %in% kn1)
# Print the result.
print("Below is the result for KN1.")
print(paste("In Briggs protein only network,",
dim(tf_brig_protein_true)[1], "out of",
dim(tf_brig_protein)[1], "confirmed by ChIP"))
print(paste("In Briggs RNA only network,",
dim(tf_brig_rna_true)[1], "out of",
dim(tf_brig_rna)[1], "confirmed by ChIP"))
print(paste("In Briggs three network,",
dim(tf_brig_three_true)[1], "out of",
dim(tf_brig_three)[1], "confirmed by ChIP"))
# 2.2 FEA4
gene <- "GRMZM2G133331" #FEA4
# How many edges in each network?
tf_brig_protein <- brig_protein %>%
filter(regulator == gene)
tf_brig_rna <- brig_rna %>%
filter(regulator == gene)
tf_brig_three <- brig_three %>%
filter(regulator == gene)
# How many genes have ChIP binding?
tf_brig_protein_true <- brig_protein %>%
filter(regulator == gene) %>%
filter(target %in% fea4)
tf_brig_rna_true <- brig_rna %>%
filter(regulator == gene) %>%
filter(target %in% fea4)
tf_brig_three_true <- brig_three %>%
filter(regulator == gene) %>%
filter(target %in% fea4)
# Print the result.
print("Below is the result for FEA4.")
print(paste("In Briggs protein only network,",
dim(tf_brig_protein_true)[1], "out of",
dim(tf_brig_protein)[1], "confirmed by ChIP"))
print(paste("In Briggs RNA only network,",
dim(tf_brig_rna_true)[1], "out of",
dim(tf_brig_rna)[1], "confirmed by ChIP"))
print(paste("In Briggs three network,",
dim(tf_brig_three_true)[1], "out of",
dim(tf_brig_three)[1], "confirmed by ChIP"))
# 2.3 O2
gene <- "GRMZM2G015534" # O2
# How many edges in each network?
tf_brig_protein <- brig_protein %>%
filter(regulator == gene)
tf_brig_rna <- brig_rna %>%
filter(regulator == gene)
tf_brig_three <- brig_three %>%
filter(regulator == gene)
# How many genes have ChIP binding?
tf_brig_protein_true <- brig_protein %>%
filter(regulator == gene) %>%
filter(target %in% o2)
tf_brig_rna_true <- brig_rna %>%
filter(regulator == gene) %>%
filter(target %in% o2)
tf_brig_three_true <- brig_three %>%
filter(regulator == gene) %>%
filter(target %in% o2)
# Print the result.
print("Below is the result for O2.")
print(paste("In Briggs protein only network,",
dim(tf_brig_protein_true)[1], "out of",
dim(tf_brig_protein)[1], "confirmed by ChIP"))
print(paste("In Briggs RNA only network,",
dim(tf_brig_rna_true)[1], "out of",
dim(tf_brig_rna)[1], "confirmed by ChIP"))
print(paste("In Briggs three network,",
dim(tf_brig_three_true)[1], "out of",
dim(tf_brig_three)[1], "confirmed by ChIP"))
################################################################################
# Also, choose the top 100,000 from Briggs networks (already sorted).
# Do and compare it again.
brig_protein <- brig_protein[1:100000,]
brig_rna <- brig_rna[1:100000,]
brig_three <- brig_three[1:100000,]
# Then re-run the previous code