-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathall_chr_plotaroundCens.R
More file actions
535 lines (389 loc) · 18.8 KB
/
all_chr_plotaroundCens.R
File metadata and controls
535 lines (389 loc) · 18.8 KB
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
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
library(hwglabr2)
library(GenomicRanges)
library(IRanges)
library(regioneR)
library(hwglabr2)
library(EnrichedHeatmap)
library(ggplot2)
library(rtracklayer)
library(BSgenome)
library(data.table)
library(stringr)
library(readr)
library(patchwork)
library('Repitools')
library(magick)
library(EnrichedHeatmap)
library(circlize)
library(GenomicRanges)
#----------------------------------------------------------------#
# Figure 1A (for all chromosomes) #
#----------------------------------------------------------------#
# ggplot theme
ggplot2_blanktheme <- theme_classic() +
theme(axis.line=element_blank(),axis.text.x=element_blank(),
axis.text.y=element_blank(),axis.ticks=element_blank(),
axis.title.x=element_blank(),
axis.title.y=element_text(angle = 0),
panel.background=element_blank(),panel.border=element_blank(),panel.grid.major=element_blank(),
panel.grid.minor=element_blank(),plot.background=element_blank())
theme_set(ggplot2_blanktheme)
WtFile <- paste0('/Users/darmokandjalad/Documents/Hop1PHD-Loop2/RAnalysis/Hop1-wildtype-334-340-32-177-Reps-SK1Yue-PM_B3W3_MACS2_FE.bdg.gz')
Wtsig <- import_bedGraph(WtFile)
Wtsig <- sort(Wtsig)
genAvg <- hwglabr2::average_chr_signal(Wtsig)$genome_avrg
Wtsig$score <- Wtsig$score/genAvg
loopFile <- paste0('/Users/darmokandjalad/Documents/Hop1PHD-Loop2/RAnalysis/11644-NHantiHop1-20220331-20220125-20221004-Reps-SK1Yue-PM-PE_B4_W3_MACS2_FE.bdg.gz')
loopSig <- import_bedGraph(loopFile)
loopSig <- sort(loopSig)
genAvg <- hwglabr2::average_chr_signal(loopSig)$genome_avrg
loopSig$score <- loopSig$score/genAvg
loopPchFile <- paste0('/Users/darmokandjalad/Documents/Hop1PHD-Loop2/RAnalysis/11757-hop1NH-20220125-20220721-20221004-Reps-SK1Yue-PM-PE_B4_W3_MACS2_FE.bdg.gz')
lpPchSig <- import_bedGraph(loopPchFile)
lpPchSig <- sort(lpPchSig)
genAvg <- hwglabr2::average_chr_signal(lpPchSig)$genome_avrg
lpPchSig$score <- lpPchSig$score/genAvg
pchFile <- paste0('/Users/darmokandjalad/Documents/Hop1PHD-Loop2/RAnalysis/11758-hop1NH-20220125-20220721-20221004-Reps-SK1Yue-PM-PE_B4_W3_MACS2_FE.bdg.gz')
pchSig <- import_bedGraph(pchFile)
pchSig <- sort(pchSig)
genAvg <- hwglabr2::average_chr_signal(pchSig)$genome_avrg
pchSig$score <- pchSig$score/genAvg
rec8File <- paste0('/Users/darmokandjalad/Documents/Hop1PHD-Loop2/RAnalysis/Hop1-rec8D-61-91-Reps-SK1Yue-PM_B3W3_MACS2_FE.bdg.gz')
rec8Sig <- import_bedGraph(rec8File)
rec8Sig <- sort(rec8Sig)
genAvg <- hwglabr2::average_chr_signal(rec8Sig)$genome_avrg
rec8Sig$score <- rec8Sig$score/genAvg
#Wtsig$group <- "WT"
#loopSig$group <- "loop2"
#all <- c(Wtsig, loopSig)
all <-lpPchSig
Flank = 20000
genome_info <- hwglabr2::get_chr_coordinates(genome = 'SK1Yue')
genome_infodf <- toDataframe(genome_info)
cen_mid <- genome_info
cen_mid <- round((start(cen_mid) + end(cen_mid))/2)
cen_plus20 <- cen_mid + Flank
cen_min20 <- cen_mid - Flank
chr <- genome_infodf$chr
flank_cen <- data.frame(first_column = genome_infodf$chr, second_column = cen_min20, third_column = cen_plus20)
colnames(flank_cen) <- c("seqnames","start","end")
flank_cen <- toGRanges(flank_cen)
cen_mid <- data.frame(cen_midpt = cen_mid, y = 0)
hits = findOverlaps(flank_cen,all)
all_cens <- all[subjectHits(hits)]
rm(hits)
sample <- all_cens
tile = 10
positions_ex <- seq(from = 1 , to = 40001 , by = 10)
# function for plotting signal across chromosomes
plot_signal <- function(sample,chrnum,tile) {
genome_info <- hwglabr2::get_chr_coordinates(genome = 'SK1Yue')
sample_ex <- sort(GenomeInfoDb::sortSeqlevels(sample))
GenomeInfoDb::seqlengths(sample_ex) <- GenomeInfoDb::seqlengths(genome_info)
bins_ex <- GenomicRanges::tileGenome(GenomeInfoDb::seqlengths(sample_ex),
tilewidth=tile,
cut.last.tile.in.chrom=TRUE)
score_ex <- GenomicRanges::coverage(sample_ex, weight="score")
bins_ex <- GenomicRanges::binnedAverage(bins_ex, score_ex, "binned_score")
#bins_ex <- GenomeInfoDb::keepSeqlevels(bins_ex, "chrII", pruning.mode="coarse")
bins_ex <- GenomeInfoDb::keepSeqlevels(bins_ex, paste0("chr",chrnum),pruning.mode="coarse")
hits = findOverlaps(flank_cen,bins_ex)
bins_ex <- bins_ex[subjectHits(hits)]
rm(hits)
positions_ex <- seq(from = 1 , to = 40001 , by = 10)
df_ex <- data.frame(seqnames=paste0('chr',chrnum),position=positions_ex, signal=bins_ex$binned_score)
#df_ex <- data.frame(seqnames="chrII",position=positions_ex, signal=bins_ex$binned_score)
#df_exS <- df_ex$position - (df_ex$position/2)
#df_exE <- df_ex$position + (df_ex$position/2)
#df_ex$start <- df_exS
#df_ex$end <- df_exE
#df_ex$width <- tile
#df_ex <- makeGRangesFromDataFrame(df_ex,
#start.field="start",
#end.field=c("end"))
#en_ex <- GenomeInfoDb::keepSeqlevels(genome_info, "chrII", pruning.mode="coarse")
#cen_mid_ex <- cen_ex
#cen_mid_ex <- round((start(cen_mid_ex) + end(cen_mid_ex))/2)
#cen_ex <- toDataframe(cen_ex)
#cen_ex$start <- cen_ex$start - 20000
#cen_ex$end <- cenr_ex$end + 20000
#cen_ex <- makeGRangesFromDataFrame(cen_ex)
#hits = findOverlaps(cen_ex,df_ex)
#df_ex <- df_ex[subjectHits(hits)]
#rm(hits)
}
max_score=max(sample$signal)
#genome_info <- hwglabr2::get_chr_coordinates(genome = 'SK1Yue')
#chrs <- list('I','VI','III','IX','VIII','V','XI','X','XIV','II','XIII','XVI','XII','VII','XV','IV')
chrs <- list('I','II','III','IV','V','VI','VII','VIII','IX','X','XI','XII','XIII','XIV','XV','XVI')
#chrs <- list('I','VI', 'III')
p=list()
for(i in chrs) {
print(i)
p[[i]] = plot_signal(sample,i,tile)
}
#clusters <- rtracklayer::import.bed('/Users/darmokandjalad/Documents/Hop1PHD-Loop2/RAnalysis/clusters_joined.bed')
plist=list()
for(i in chrs){
a = data.frame()
temp=data.frame()
temp = p[[i]]
cen_mid = 10001
a <- ggplot(temp,aes(position,signal)) +
geom_line() +
ylab(i) + ylim(-0.65,11) + xlim(0,40001)
#ylim is 10 for all except pch2, where ylim is 12
a <- a + geom_vline(xintercept = 20000, alpha = 0.2)
#a <- a + geom_point(cen_mid, mapping=aes(cen_midpt,-0.15),
# size = 1.6, colour = 'green',shape=20)
#clusterregion = data.frame(clusters[seqnames(clusters)==paste0("chr",i)])
#a <- a + geom_segment(clusterregion, size = 6,alpha = 0.6,
#mapping=aes(x = start, y = max_score/2, xend = end, yend = max_score/2, colour = "segment"))
plist[[i]] <- a
}
#wrap_plots(plist,nrow = 16)
p <- wrap_plots(plist,nrow = 16)
p
#export pdf, portrait 4X8inches
####################################
#Put signal over genome average
#pick signal to analyzie
ggplot2_blanktheme <- theme_classic() +
theme(axis.line=element_blank(),axis.text.x=element_blank(),
axis.text.y=element_blank(),axis.ticks=element_blank(),
axis.title.x=element_blank(),
axis.title.y=element_blank(),
panel.background=element_blank(),panel.border=element_blank(),panel.grid.major=element_blank(),
panel.grid.minor=element_blank(),plot.background=element_blank(),
title = NULL)
theme_set(ggplot2_blanktheme)
#For Wildtype
signal = Wtsig
Cen_flank = 10000
genAvg <- hwglabr2::average_chr_signal(signal)$genome_avrg
signal$score <- signal$score/genAvg
#get genome
genome_info <- hwglabr2::get_chr_coordinates(genome = 'SK1Yue')
# Sort sequences and levels to make sure they match
signal <- sort(GenomeInfoDb::sortSeqlevels(signal))
genome_info <- GenomeInfoDb::sortSeqlevels(genome_info)
# isolate centromere regions
#how far out from cen
axis = hwglabr2::get_Red1_summits("SK1Yue")
hits = findOverlaps(Cens_bpFlank,axis)
axis_cens <- axis[subjectHits(hits)]
rm(hits)
axis_offcen <- axis[axis %outside% axis_cens]
mat1 <- normalizeToMatrix(signal, axis_cens, value_column = "score",
extend = 1000, mean_mode = "weighted", w = 5,empty_value=NA)
mat1_avrg <- hwglabr2::signal_mean_and_ci(mat1,
ci=0.95, rep_bootstrap=1000,
na_rm=TRUE)
mat2 <- normalizeToMatrix(signal, axis_offcen, value_column = "score",
extend = 1000, mean_mode = "weighted", w = 5,empty_value=NA)
mat2_avrg <- hwglabr2::signal_mean_and_ci(mat2,
ci=0.95, rep_bootstrap=1000,
na_rm=TRUE)
mat1_avrg_df <- data.frame(mat1_avrg)
row = c(-199:200)
mat1_avrg_df['Position'] = row
mat1_avrg_df['sample'] = 'On_cen'
mat2_avrg_df <- data.frame(mat2_avrg)
mat2_avrg_df['Position'] = row
mat2_avrg_df['sample'] = 'Off_cen'
alldata = rbind(mat1_avrg_df,mat2_avrg_df)
p <- ggplot(alldata, aes(Position, Mean, group = sample, colour=sample, fill=sample)) +
geom_vline(xintercept = 0, lty = 3) +
scale_x_continuous(breaks = c(-199, 0, 200),
labels = c("-10 kb", "summit", "10 kb"))+
scale_color_manual(values = c("#662D91", "#00A14B"))+
theme(legend.position="none")
# Add confidence interval as a ribbon
p <- p + geom_ribbon(aes(ymin = Lower, ymax = Upper), alpha=0.3,colour=NA)
p <- p + geom_line()
p
#for loop2
signal = loopSig
Cen_flank = 10000
genAvg <- hwglabr2::average_chr_signal(signal)$genome_avrg
signal$score <- signal$score/genAvg
#get genome
genome_info <- hwglabr2::get_chr_coordinates(genome = 'SK1Yue')
# Sort sequences and levels to make sure they match
signal <- sort(GenomeInfoDb::sortSeqlevels(signal))
genome_info <- GenomeInfoDb::sortSeqlevels(genome_info)
# isolate centromere regions
#how far out from cen
axis = hwglabr2::get_Red1_summits("SK1Yue")
hits = findOverlaps(Cens_bpFlank,axis)
axis_cens <- axis[subjectHits(hits)]
rm(hits)
axis_offcen <- axis[axis %outside% axis_cens]
mat1 <- normalizeToMatrix(signal, axis_cens, value_column = "score",
extend = 1000, mean_mode = "weighted", w = 5,empty_value=NA)
mat1_avrg <- hwglabr2::signal_mean_and_ci(mat1,
ci=0.95, rep_bootstrap=1000,
na_rm=TRUE)
mat2 <- normalizeToMatrix(signal, axis_offcen, value_column = "score",
extend = 1000, mean_mode = "weighted", w = 5,empty_value=NA)
mat2_avrg <- hwglabr2::signal_mean_and_ci(mat2,
ci=0.95, rep_bootstrap=1000,
na_rm=TRUE)
mat1_avrg_df <- data.frame(mat1_avrg)
row = c(-199:200)
mat1_avrg_df['Position'] = row
mat1_avrg_df['sample'] = 'On_cen'
mat2_avrg_df <- data.frame(mat2_avrg)
mat2_avrg_df['Position'] = row
mat2_avrg_df['sample'] = 'Off_cen'
alldata = rbind(mat1_avrg_df,mat2_avrg_df)
p <- ggplot(alldata, aes(Position, Mean, group = sample, colour=sample, fill=sample)) +
labs(x = "Distance to axis site (bp)", y = "Average\nChIP-seq signal") +
geom_vline(xintercept = 0, lty = 3) +
scale_x_continuous(breaks = c(-199, 0, 200),
labels = c("-10 kb", "summit", "10 kb"))+
scale_color_manual(values = c("#662D91", "#00A14B"))+
theme(legend.position="none")
# Add confidence interval as a ribbon
p <- p + geom_ribbon(aes(ymin = Lower, ymax = Upper), alpha=0.3,colour=NA)
p <- p + geom_line()
p
#for loop2Pch2
signal = lpPchSig
Cen_flank = 10000
genAvg <- hwglabr2::average_chr_signal(signal)$genome_avrg
signal$score <- signal$score/genAvg
#get genome
genome_info <- hwglabr2::get_chr_coordinates(genome = 'SK1Yue')
# Sort sequences and levels to make sure they match
signal <- sort(GenomeInfoDb::sortSeqlevels(signal))
genome_info <- GenomeInfoDb::sortSeqlevels(genome_info)
# isolate centromere regions
#how far out from cen
axis = hwglabr2::get_Red1_summits("SK1Yue")
hits = findOverlaps(Cens_bpFlank,axis)
axis_cens <- axis[subjectHits(hits)]
rm(hits)
axis_offcen <- axis[axis %outside% axis_cens]
mat1 <- normalizeToMatrix(signal, axis_cens, value_column = "score",
extend = 1000, mean_mode = "weighted", w = 5,empty_value=NA)
mat1_avrg <- hwglabr2::signal_mean_and_ci(mat1,
ci=0.95, rep_bootstrap=1000,
na_rm=TRUE)
mat2 <- normalizeToMatrix(signal, axis_offcen, value_column = "score",
extend = 1000, mean_mode = "weighted", w = 5,empty_value=NA)
mat2_avrg <- hwglabr2::signal_mean_and_ci(mat2,
ci=0.95, rep_bootstrap=1000,
na_rm=TRUE)
mat1_avrg_df <- data.frame(mat1_avrg)
row = c(-199:200)
mat1_avrg_df['Position'] = row
mat1_avrg_df['sample'] = 'On_cen'
mat2_avrg_df <- data.frame(mat2_avrg)
mat2_avrg_df['Position'] = row
mat2_avrg_df['sample'] = 'Off_cen'
alldata = rbind(mat1_avrg_df,mat2_avrg_df)
p <- ggplot(alldata, aes(Position, Mean, group = sample, colour=sample, fill=sample)) +
labs(x = "Distance to axis site (bp)", y = "Average\nChIP-seq signal") +
geom_vline(xintercept = 0, lty = 3) +
scale_x_continuous(breaks = c(-199, 0, 200),
labels = c("-10 kb", "summit", "10 kb"))+
scale_color_manual(values = c("#662D91", "#00A14B"))+
theme(legend.position="none")
# Add confidence interval as a ribbon
p <- p + geom_ribbon(aes(ymin = Lower, ymax = Upper), alpha=0.3,colour=NA)
p <- p + geom_line()
p
###For Pch2
signal = pchSig
Cen_flank = 10000
genAvg <- hwglabr2::average_chr_signal(signal)$genome_avrg
signal$score <- signal$score/genAvg
#get genome
genome_info <- hwglabr2::get_chr_coordinates(genome = 'SK1Yue')
# Sort sequences and levels to make sure they match
signal <- sort(GenomeInfoDb::sortSeqlevels(signal))
genome_info <- GenomeInfoDb::sortSeqlevels(genome_info)
# isolate centromere regions
#how far out from cen
axis = hwglabr2::get_Red1_summits("SK1Yue")
hits = findOverlaps(Cens_bpFlank,axis)
axis_cens <- axis[subjectHits(hits)]
rm(hits)
axis_offcen <- axis[axis %outside% axis_cens]
mat1 <- normalizeToMatrix(signal, axis_cens, value_column = "score",
extend = 1000, mean_mode = "weighted", w = 5,empty_value=NA)
mat1_avrg <- hwglabr2::signal_mean_and_ci(mat1,
ci=0.95, rep_bootstrap=1000,
na_rm=TRUE)
mat2 <- normalizeToMatrix(signal, axis_offcen, value_column = "score",
extend = 1000, mean_mode = "weighted", w = 5,empty_value=NA)
mat2_avrg <- hwglabr2::signal_mean_and_ci(mat2,
ci=0.95, rep_bootstrap=1000,
na_rm=TRUE)
mat1_avrg_df <- data.frame(mat1_avrg)
row = c(-199:200)
mat1_avrg_df['Position'] = row
mat1_avrg_df['sample'] = 'On_cen'
mat2_avrg_df <- data.frame(mat2_avrg)
mat2_avrg_df['Position'] = row
mat2_avrg_df['sample'] = 'Off_cen'
alldata = rbind(mat1_avrg_df,mat2_avrg_df)
p <- ggplot(alldata, aes(Position, Mean, group = sample, colour=sample, fill=sample)) +
labs(x = "Distance to axis site (bp)", y = "Average\nChIP-seq signal") +
geom_vline(xintercept = 0, lty = 3) +
scale_x_continuous(breaks = c(-199, 0, 200),
labels = c("-10 kb", "summit", "10 kb"))+
scale_color_manual(values = c("#662D91", "#00A14B"))+
theme(legend.position="none")
# Add confidence interval as a ribbon
p <- p + geom_ribbon(aes(ymin = Lower, ymax = Upper), alpha=0.3,colour=NA)
p <- p + geom_line()
p
###for rec8
signal = rec8Sig
Cen_flank = 10000
genAvg <- hwglabr2::average_chr_signal(signal)$genome_avrg
signal$score <- signal$score/genAvg
#get genome
genome_info <- hwglabr2::get_chr_coordinates(genome = 'SK1Yue')
# Sort sequences and levels to make sure they match
signal <- sort(GenomeInfoDb::sortSeqlevels(signal))
genome_info <- GenomeInfoDb::sortSeqlevels(genome_info)
# isolate centromere regions
#how far out from cen
axis = hwglabr2::get_Red1_summits("SK1Yue")
hits = findOverlaps(Cens_bpFlank,axis)
axis_cens <- axis[subjectHits(hits)]
rm(hits)
axis_offcen <- axis[axis %outside% axis_cens]
mat1 <- normalizeToMatrix(signal, axis_cens, value_column = "score",
extend = 1000, mean_mode = "weighted", w = 5,empty_value=NA)
mat1_avrg <- hwglabr2::signal_mean_and_ci(mat1,
ci=0.95, rep_bootstrap=1000,
na_rm=TRUE)
mat2 <- normalizeToMatrix(signal, axis_offcen, value_column = "score",
extend = 1000, mean_mode = "weighted", w = 5,empty_value=NA)
mat2_avrg <- hwglabr2::signal_mean_and_ci(mat2,
ci=0.95, rep_bootstrap=1000,
na_rm=TRUE)
mat1_avrg_df <- data.frame(mat1_avrg)
row = c(-199:200)
mat1_avrg_df['Position'] = row
mat1_avrg_df['sample'] = 'On_cen'
mat2_avrg_df <- data.frame(mat2_avrg)
mat2_avrg_df['Position'] = row
mat2_avrg_df['sample'] = 'Off_cen'
alldata = rbind(mat1_avrg_df,mat2_avrg_df)
p <- ggplot(alldata, aes(Position, Mean, group = sample, colour=sample, fill=sample)) +
labs(x = "Distance to axis site (bp)", y = "Average\nChIP-seq signal") +
geom_vline(xintercept = 0, lty = 3) +
scale_x_continuous(breaks = c(-199, 0, 200),
labels = c("-10 kb", "summit", "10 kb"))+
scale_color_manual(values = c("#662D91", "#00A14B"))+
theme(legend.position="none")
# Add confidence interval as a ribbon
p <- p + geom_ribbon(aes(ymin = Lower, ymax = Upper), alpha=0.3,colour=NA)
p <- p + geom_line()
p
###################################################