/
GO.step82.replicate_variability.create_scatterplots.R
773 lines (606 loc) · 52.8 KB
/
GO.step82.replicate_variability.create_scatterplots.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
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
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
# ################################################################################################################################################################################################################
# GO.step82.replicate_variability.create_scatterplots.R
#
# CC-BY Lee Edsall
# email: le49@duke.edu
# Twitter: @LeeEdsall
#
# This script was used to analyze data for Edsall et al. 2019 which compared DNase-seq data from 5 primates (human, chimpanzee, gorilla, orangutan, macaque)
# Create scatterplots of the cut counts to assess replicate variability
# Plot each species separately; save species plots in a png file; one png file per species (saving all of them in one pdf makes the pdf file huge)
# The input scores are not normalized; so normalize them first
# ###################################################################################################################################################################################################################
# ===================================================================================================================================================================================================================
# load libraries
# ===================================================================================================================================================================================================================
library("ggplot2")
library("grid")
library("gridExtra")
library("gtable")
library("scales")
# ===================================================================================================================================================================================================================
# set options
# ===================================================================================================================================================================================================================
options(scipen=0)
# ===================================================================================================================================================================================================================
# open connection to log file
# ===================================================================================================================================================================================================================
# -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
# Open the log file; write date
# -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
sink(file="LOG.step82.replicate_variability.create_scatterplots.R", append=FALSE, type="output", split=TRUE)
cat("------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\n")
cat("BEGIN:", date(), "\n")
cat("------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\n\n")
# ===================================================================================================================================================================================================================
# Load the score table
# The replicates are in the columns and the locations are in the rows
# The scores have not been normalized
# ===================================================================================================================================================================================================================
cat("Reading score file (all_DHS_sites.passed_coverage_filter.with_non_normalized_scores.zero_filtered.txt.with_PLoS_overlap_information) ... ")
scores_with_locations <- as.data.frame(read.table("all_DHS_sites.passed_coverage_filter.with_non_normalized_scores.zero_filtered.txt.with_PLoS_overlap_information", sep="\t", header=FALSE))
colnames(scores_with_locations) <- c("chrom","start","end", "h1", "h2", "h3", "c1", "c2", "c3", "g1", "g2", "g3", "o1", "o2", "o3", "m1", "m2", "m3", "PLoS_overlap")
rownames(scores_with_locations) <- paste(scores_with_locations$chrom, scores_with_locations$start, scores_with_locations$end, sep=":")
cat("done\n\n")
# ===================================================================================================================================================================================================================
# Calculate library sizes
# ===================================================================================================================================================================================================================
cat("Calculating library sizes ... ")
h1_total <- sum(scores_with_locations$h1)
h2_total <- sum(scores_with_locations$h2)
h3_total <- sum(scores_with_locations$h3)
c1_total <- sum(scores_with_locations$c1)
c2_total <- sum(scores_with_locations$c2)
c3_total <- sum(scores_with_locations$c3)
g1_total <- sum(scores_with_locations$g1)
g2_total <- sum(scores_with_locations$g2)
g3_total <- sum(scores_with_locations$g3)
o1_total <- sum(scores_with_locations$o1)
o2_total <- sum(scores_with_locations$o2)
o3_total <- sum(scores_with_locations$o3)
m1_total <- sum(scores_with_locations$m1)
m2_total <- sum(scores_with_locations$m2)
m3_total <- sum(scores_with_locations$m3)
cat("done.\n\n")
# ===================================================================================================================================================================================================================
# Normalize scores by library size
# ===================================================================================================================================================================================================================
cat("Normalizing by library size ... ")
normalized_scores <- scores_with_locations[,4:18]
normalized_scores$h1 <- scores_with_locations$h1 / h1_total
normalized_scores$h2 <- scores_with_locations$h2 / h2_total
normalized_scores$h3 <- scores_with_locations$h3 / h3_total
normalized_scores$c1 <- scores_with_locations$c1 / c1_total
normalized_scores$c2 <- scores_with_locations$c2 / c2_total
normalized_scores$c3 <- scores_with_locations$c3 / c3_total
normalized_scores$g1 <- scores_with_locations$g1 / g1_total
normalized_scores$g2 <- scores_with_locations$g2 / g2_total
normalized_scores$g3 <- scores_with_locations$g3 / g3_total
normalized_scores$o1 <- scores_with_locations$o1 / o1_total
normalized_scores$o2 <- scores_with_locations$o2 / o2_total
normalized_scores$o3 <- scores_with_locations$o3 / o3_total
normalized_scores$m1 <- scores_with_locations$m1 / m1_total
normalized_scores$m2 <- scores_with_locations$m2 / m2_total
normalized_scores$m3 <- scores_with_locations$m3 / m3_total
cat("done.\n\n")
# ###################################################################################################################################################################################################################
# Generate scatterplots
# ###################################################################################################################################################################################################################
# ===================================================================================================================================================================================================================
# Human
# ===================================================================================================================================================================================================================
cat("Generating scatterplots for human replicates ... ")
png("replicate_scatterplots.human.png", height=2250, width=2100, res=300)
# -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
# Replicate 1 plots
# -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
h1_h1.plot <- ggplotGrob(ggplot(normalized_scores, aes(x=h1, y=h1)) + geom_point(size=.5) +
scale_x_continuous(labels = scientific, limits=c(0,3e-04)) + scale_y_continuous(labels = scientific, limits=c(0,3e-04)) +
theme_bw() + theme(axis.text.x=element_text(size=10, angle=90, hjust = 1)) + theme(axis.text.y=element_text(size=10)) + xlab("Replicate 1") + ylab("Replicate 1") +
geom_abline(intercept=0, slope=1, color="red"))
h1_h2.plot <- ggplotGrob(ggplot(normalized_scores, aes(x=h1, y=h2)) + geom_point(size=.5) +
scale_x_continuous(labels = scientific, limits=c(0,3e-04)) + scale_y_continuous(labels = scientific, limits=c(0,3e-04)) +
theme_bw() + theme(axis.text.x=element_text(size=10, angle=90, hjust = 1)) + theme(axis.text.y=element_text(size=10)) + xlab("Replicate 1") + ylab("Replicate 2") +
geom_abline(intercept=0, slope=1, color="red"))
h1_h3.plot <- ggplotGrob(ggplot(normalized_scores, aes(x=h1, y=h3)) + geom_point(size=.5) +
scale_x_continuous(labels = scientific, limits=c(0,3e-04)) + scale_y_continuous(labels = scientific, limits=c(0,3e-04)) +
theme_bw() + theme(axis.text.x=element_text(size=10, angle=90, hjust = 1)) + theme(axis.text.y=element_text(size=10)) + xlab("Replicate 1") + ylab("Replicate 3") +
geom_abline(intercept=0, slope=1, color="red"))
# -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
# Replicate 2 plots
# -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
h2_h1.plot <- ggplotGrob(ggplot(normalized_scores, aes(x=h2, y=h1)) + geom_point(size=.5) +
scale_x_continuous(labels = scientific, limits=c(0,3e-04)) + scale_y_continuous(labels = scientific, limits=c(0,3e-04)) +
theme_bw() + theme(axis.text.x=element_text(size=10, angle=90, hjust = 1)) + theme(axis.text.y=element_text(size=10)) + xlab("Replicate 2") + ylab("Replicate 1") +
geom_abline(intercept=0, slope=1, color="red"))
h2_h2.plot <- ggplotGrob(ggplot(normalized_scores, aes(x=h2, y=h2)) + geom_point(size=.5) +
scale_x_continuous(labels = scientific, limits=c(0,3e-04)) + scale_y_continuous(labels = scientific, limits=c(0,3e-04)) +
theme_bw() + theme(axis.text.x=element_text(size=10, angle=90, hjust = 1)) + theme(axis.text.y=element_text(size=10)) + xlab("Replicate 2") + ylab("Replicate 2") +
geom_abline(intercept=0, slope=1, color="red"))
h2_h3.plot <- ggplotGrob(ggplot(normalized_scores, aes(x=h2, y=h3)) + geom_point(size=.5) +
scale_x_continuous(labels = scientific, limits=c(0,3e-04)) + scale_y_continuous(labels = scientific, limits=c(0,3e-04)) +
theme_bw() + theme(axis.text.x=element_text(size=10, angle=90, hjust = 1)) + theme(axis.text.y=element_text(size=10)) + xlab("Replicate 2") + ylab("Replicate 3") +
geom_abline(intercept=0, slope=1, color="red"))
# -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
# Replicate 3 plots
# -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
h3_h1.plot <- ggplotGrob(ggplot(normalized_scores, aes(x=h3, y=h1)) + geom_point(size=.5) +
scale_x_continuous(labels = scientific, limits=c(0,3e-04)) + scale_y_continuous(labels = scientific, limits=c(0,3e-04)) +
theme_bw() + theme(axis.text.x=element_text(size=10, angle=90, hjust = 1)) + theme(axis.text.y=element_text(size=10)) + xlab("Replicate 3") + ylab("Replicate 1") +
geom_abline(intercept=0, slope=1, color="red"))
h3_h2.plot <- ggplotGrob(ggplot(normalized_scores, aes(x=h3, y=h2)) + geom_point(size=.5) +
scale_x_continuous(labels = scientific, limits=c(0,3e-04)) + scale_y_continuous(labels = scientific, limits=c(0,3e-04)) +
theme_bw() + theme(axis.text.x=element_text(size=10, angle=90, hjust = 1)) + theme(axis.text.y=element_text(size=10)) + xlab("Replicate 3") + ylab("Replicate 2") +
geom_abline(intercept=0, slope=1, color="red"))
h3_h3.plot <- ggplotGrob(ggplot(normalized_scores, aes(x=h3, y=h3)) + geom_point(size=.5) +
scale_x_continuous(labels = scientific, limits=c(0,3e-04)) + scale_y_continuous(labels = scientific, limits=c(0,3e-04)) +
theme_bw() + theme(axis.text.x=element_text(size=10, angle=90, hjust = 1)) + theme(axis.text.y=element_text(size=10)) + xlab("Replicate 3") + ylab("Replicate 3") +
geom_abline(intercept=0, slope=1, color="red"))
# -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
# Create final plot
# The layout for the gtable is 5 columns x 8 rows (7.25 inches high x 6.5 inches wide)
# The 5 columns are:
# 1. plot 1 for the replicate (2 inches)
# 2. spacer (.25 inches)
# 3. plot 2 for the replicate (2 inches)
# 4. spacer (.25 inches)
# 5. plot 3 for the replicate (2 inches)
# The 8 rows are:
# 1: replicate 1 title (.25 inches)
# 2: replicate 1 plots (2 inches)
# 3: spacer (.25 inches)
# 4: replicate 2 title (.25 inches)
# 5: replicate 2 plots (2 inches)
# 6: spacer (.25 inches)
# 7: replicate 3 title (.25 inches)
# 8: replicate 3 plots (2 inches)
# The parameters are:
# t --> top
# l --> left
# r --> right
# b- --> bottom
# -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
# Create the table
human_gtable <- gtable(widths=unit(c(2, .25, 2, .25, 2), "in"), heights=unit(c(.2, 2, .25, .2, 2, .25, .2, 2), "in"))
# Add a white background to all of the cells
human_gtable <- gtable_add_grob(human_gtable, rectGrob(gp = gpar(fill = "white", col="white")), t=1, l=1, b=8, r=5)
# Add the headings for each of the replicate rows
human_gtable <- gtable_add_grob(human_gtable, textGrob("Replicate 1", gp=gpar(col="blue", fontsize=12)), t=1, l=1, r=5)
human_gtable <- gtable_add_grob(human_gtable, textGrob("Replicate 2", gp=gpar(col="blue", fontsize=12)), t=4, l=1, r=5)
human_gtable <- gtable_add_grob(human_gtable, textGrob("Replicate 3", gp=gpar(col="blue", fontsize=12)), t=7, l=1, r=5)
# Add the replicate 1 plots
human_gtable <- gtable_add_grob(human_gtable, h1_h1.plot, t=2, l=1)
human_gtable <- gtable_add_grob(human_gtable, h1_h2.plot, t=2, l=3)
human_gtable <- gtable_add_grob(human_gtable, h1_h3.plot, t=2, l=5)
# Add the replicate 2 plots
human_gtable <- gtable_add_grob(human_gtable, h2_h1.plot, t=5, l=1)
human_gtable <- gtable_add_grob(human_gtable, h2_h2.plot, t=5, l=3)
human_gtable <- gtable_add_grob(human_gtable, h2_h3.plot, t=5, l=5)
# Add the replicate 3 plots
human_gtable <- gtable_add_grob(human_gtable, h3_h1.plot, t=8, l=1)
human_gtable <- gtable_add_grob(human_gtable, h3_h2.plot, t=8, l=3)
human_gtable <- gtable_add_grob(human_gtable, h3_h3.plot, t=8, l=5)
# Plot the elements
grid.arrange(human_gtable, top=textGrob("Human cut counts for the union set of DHS sites (89,744 sites)", gp=gpar(col="black", fontface="bold")), ncol=1, nrow=1)
dev.off()
# -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
# Finish up
# -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
cat("done\n\n")
# ===================================================================================================================================================================================================================
# Chimp
# ===================================================================================================================================================================================================================
cat("Generating scatterplots for chimp replicates ... ")
png("replicate_scatterplots.chimp.png", height=2250, width=2100, res=300)
# -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
# Replicate 1 plots
# -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
c1_c1.plot <- ggplotGrob(ggplot(normalized_scores, aes(x=c1, y=c1)) + geom_point(size=.5) +
scale_x_continuous(labels = scientific, limits=c(0,3e-04)) + scale_y_continuous(labels = scientific, limits=c(0,3e-04)) +
theme_bw() + theme(axis.text.x=element_text(size=10, angle=90, hjust = 1)) + theme(axis.text.y=element_text(size=10)) + xlab("Replicate 1") + ylab("Replicate 1") +
geom_abline(intercept=0, slope=1, color="red"))
c1_c2.plot <- ggplotGrob(ggplot(normalized_scores, aes(x=c1, y=c2)) + geom_point(size=.5) +
scale_x_continuous(labels = scientific, limits=c(0,3e-04)) + scale_y_continuous(labels = scientific, limits=c(0,3e-04)) +
theme_bw() + theme(axis.text.x=element_text(size=10, angle=90, hjust = 1)) + theme(axis.text.y=element_text(size=10)) + xlab("Replicate 1") + ylab("Replicate 2") +
geom_abline(intercept=0, slope=1, color="red"))
c1_c3.plot <- ggplotGrob(ggplot(normalized_scores, aes(x=c1, y=c3)) + geom_point(size=.5) +
scale_x_continuous(labels = scientific, limits=c(0,3e-04)) + scale_y_continuous(labels = scientific, limits=c(0,3e-04)) +
theme_bw() + theme(axis.text.x=element_text(size=10, angle=90, hjust = 1)) + theme(axis.text.y=element_text(size=10)) + xlab("Replicate 1") + ylab("Replicate 3") +
geom_abline(intercept=0, slope=1, color="red"))
# -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
# Replicate 2 plots
# -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
c2_c1.plot <- ggplotGrob(ggplot(normalized_scores, aes(x=c2, y=c1)) + geom_point(size=.5) +
scale_x_continuous(labels = scientific, limits=c(0,3e-04)) + scale_y_continuous(labels = scientific, limits=c(0,3e-04)) +
theme_bw() + theme(axis.text.x=element_text(size=10, angle=90, hjust = 1)) + theme(axis.text.y=element_text(size=10)) + xlab("Replicate 2") + ylab("Replicate 1") +
geom_abline(intercept=0, slope=1, color="red"))
c2_c2.plot <- ggplotGrob(ggplot(normalized_scores, aes(x=c2, y=c2)) + geom_point(size=.5) +
scale_x_continuous(labels = scientific, limits=c(0,3e-04)) + scale_y_continuous(labels = scientific, limits=c(0,3e-04)) +
theme_bw() + theme(axis.text.x=element_text(size=10, angle=90, hjust = 1)) + theme(axis.text.y=element_text(size=10)) + xlab("Replicate 2") + ylab("Replicate 2") +
geom_abline(intercept=0, slope=1, color="red"))
c2_c3.plot <- ggplotGrob(ggplot(normalized_scores, aes(x=c2, y=c3)) + geom_point(size=.5) +
scale_x_continuous(labels = scientific, limits=c(0,3e-04)) + scale_y_continuous(labels = scientific, limits=c(0,3e-04)) +
theme_bw() + theme(axis.text.x=element_text(size=10, angle=90, hjust = 1)) + theme(axis.text.y=element_text(size=10)) + xlab("Replicate 2") + ylab("Replicate 3") +
geom_abline(intercept=0, slope=1, color="red"))
# -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
# Replicate 3 plots
# -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
c3_c1.plot <- ggplotGrob(ggplot(normalized_scores, aes(x=c3, y=c1)) + geom_point(size=.5) +
scale_x_continuous(labels = scientific, limits=c(0,3e-04)) + scale_y_continuous(labels = scientific, limits=c(0,3e-04)) +
theme_bw() + theme(axis.text.x=element_text(size=10, angle=90, hjust = 1)) + theme(axis.text.y=element_text(size=10)) + xlab("Replicate 3") + ylab("Replicate 1") +
geom_abline(intercept=0, slope=1, color="red"))
c3_c2.plot <- ggplotGrob(ggplot(normalized_scores, aes(x=c3, y=c2)) + geom_point(size=.5) +
scale_x_continuous(labels = scientific, limits=c(0,3e-04)) + scale_y_continuous(labels = scientific, limits=c(0,3e-04)) +
theme_bw() + theme(axis.text.x=element_text(size=10, angle=90, hjust = 1)) + theme(axis.text.y=element_text(size=10)) + xlab("Replicate 3") + ylab("Replicate 2") +
geom_abline(intercept=0, slope=1, color="red"))
c3_c3.plot <- ggplotGrob(ggplot(normalized_scores, aes(x=c3, y=c3)) + geom_point(size=.5) +
scale_x_continuous(labels = scientific, limits=c(0,3e-04)) + scale_y_continuous(labels = scientific, limits=c(0,3e-04)) +
theme_bw() + theme(axis.text.x=element_text(size=10, angle=90, hjust = 1)) + theme(axis.text.y=element_text(size=10)) + xlab("Replicate 3") + ylab("Replicate 3") +
geom_abline(intercept=0, slope=1, color="red"))
# -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
# Create final plot
# The layout for the gtable is 5 columns x 8 rows (7.25 inches high x 6.5 inches wide)
# The 5 columns are:
# 1. plot 1 for the replicate (2 inches)
# 2. spacer (.25 inches)
# 3. plot 2 for the replicate (2 inches)
# 4. spacer (.25 inches)
# 5. plot 3 for the replicate (2 inches)
# The 8 rows are:
# 1: replicate 1 title (.25 inches)
# 2: replicate 1 plots (2 inches)
# 3: spacer (.25 inches)
# 4: replicate 2 title (.25 inches)
# 5: replicate 2 plots (2 inches)
# 6: spacer (.25 inches)
# 7: replicate 3 title (.25 inches)
# 8: replicate 3 plots (2 inches)
# The parameters are:
# t --> top
# l --> left
# r --> right
# b- --> bottom
# -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
# Create the table
chimp_gtable <- gtable(widths=unit(c(2, .25, 2, .25, 2), "in"), heights=unit(c(.2, 2, .25, .2, 2, .25, .2, 2), "in"))
# Add a white background to all of the cells
chimp_gtable <- gtable_add_grob(chimp_gtable, rectGrob(gp = gpar(fill = "white", col="white")), t=1, l=1, b=8, r=5)
# Add the headings for each of the replicate rows
chimp_gtable <- gtable_add_grob(chimp_gtable, textGrob("Replicate 1", gp=gpar(col="blue", fontsize=12)), t=1, l=1, r=5)
chimp_gtable <- gtable_add_grob(chimp_gtable, textGrob("Replicate 2", gp=gpar(col="blue", fontsize=12)), t=4, l=1, r=5)
chimp_gtable <- gtable_add_grob(chimp_gtable, textGrob("Replicate 3", gp=gpar(col="blue", fontsize=12)), t=7, l=1, r=5)
# Add the replicate 1 plots
chimp_gtable <- gtable_add_grob(chimp_gtable, c1_c1.plot, t=2, l=1)
chimp_gtable <- gtable_add_grob(chimp_gtable, c1_c2.plot, t=2, l=3)
chimp_gtable <- gtable_add_grob(chimp_gtable, c1_c3.plot, t=2, l=5)
# Add the replicate 2 plots
chimp_gtable <- gtable_add_grob(chimp_gtable, c2_c1.plot, t=5, l=1)
chimp_gtable <- gtable_add_grob(chimp_gtable, c2_c2.plot, t=5, l=3)
chimp_gtable <- gtable_add_grob(chimp_gtable, c2_c3.plot, t=5, l=5)
# Add the replicate 3 plots
chimp_gtable <- gtable_add_grob(chimp_gtable, c3_c1.plot, t=8, l=1)
chimp_gtable <- gtable_add_grob(chimp_gtable, c3_c2.plot, t=8, l=3)
chimp_gtable <- gtable_add_grob(chimp_gtable, c3_c3.plot, t=8, l=5)
# Plot the elements
grid.arrange(chimp_gtable, top=textGrob("Chimp cut counts for the union set of DHS sites (89,744 sites)", gp=gpar(col="black", fontface="bold")), ncol=1, nrow=1)
dev.off()
# -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
# Finish up
# -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
cat("done\n\n")
# ===================================================================================================================================================================================================================
# Gorilla
# ===================================================================================================================================================================================================================
cat("Generating scatterplots for gorilla replicates ... ")
png("replicate_scatterplots.gorilla.png", height=2250, width=2100, res=300)
# -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
# Replicate 1 plots
# -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
g1_g1.plot <- ggplotGrob(ggplot(normalized_scores, aes(x=g1, y=g1)) + geom_point(size=.5) +
scale_x_continuous(labels = scientific, limits=c(0,2e-04)) + scale_y_continuous(labels = scientific, limits=c(0,2e-04)) +
theme_bw() + theme(axis.text.x=element_text(size=10, angle=90, hjust = 1)) + theme(axis.text.y=element_text(size=10)) + xlab("Replicate 1") + ylab("Replicate 1") +
geom_abline(intercept=0, slope=1, color="red"))
g1_g2.plot <- ggplotGrob(ggplot(normalized_scores, aes(x=g1, y=g2)) + geom_point(size=.5) +
scale_x_continuous(labels = scientific, limits=c(0,2e-04)) + scale_y_continuous(labels = scientific, limits=c(0,2e-04)) +
theme_bw() + theme(axis.text.x=element_text(size=10, angle=90, hjust = 1)) + theme(axis.text.y=element_text(size=10)) + xlab("Replicate 1") + ylab("Replicate 2") +
geom_abline(intercept=0, slope=1, color="red"))
g1_g3.plot <- ggplotGrob(ggplot(normalized_scores, aes(x=g1, y=g3)) + geom_point(size=.5) +
scale_x_continuous(labels = scientific, limits=c(0,2e-04)) + scale_y_continuous(labels = scientific, limits=c(0,2e-04)) +
theme_bw() + theme(axis.text.x=element_text(size=10, angle=90, hjust = 1)) + theme(axis.text.y=element_text(size=10)) + xlab("Replicate 1") + ylab("Replicate 3") +
geom_abline(intercept=0, slope=1, color="red"))
# -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
# Replicate 2 plots
# -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
g2_g1.plot <- ggplotGrob(ggplot(normalized_scores, aes(x=g2, y=g1)) + geom_point(size=.5) +
scale_x_continuous(labels = scientific, limits=c(0,2e-04)) + scale_y_continuous(labels = scientific, limits=c(0,2e-04)) +
theme_bw() + theme(axis.text.x=element_text(size=10, angle=90, hjust = 1)) + theme(axis.text.y=element_text(size=10)) + xlab("Replicate 2") + ylab("Replicate 1") +
geom_abline(intercept=0, slope=1, color="red"))
g2_g2.plot <- ggplotGrob(ggplot(normalized_scores, aes(x=g2, y=g2)) + geom_point(size=.5) +
scale_x_continuous(labels = scientific, limits=c(0,2e-04)) + scale_y_continuous(labels = scientific, limits=c(0,2e-04)) +
theme_bw() + theme(axis.text.x=element_text(size=10, angle=90, hjust = 1)) + theme(axis.text.y=element_text(size=10)) + xlab("Replicate 2") + ylab("Replicate 2") +
geom_abline(intercept=0, slope=1, color="red"))
g2_g3.plot <- ggplotGrob(ggplot(normalized_scores, aes(x=g2, y=g3)) + geom_point(size=.5) +
scale_x_continuous(labels = scientific, limits=c(0,2e-04)) + scale_y_continuous(labels = scientific, limits=c(0,2e-04)) +
theme_bw() + theme(axis.text.x=element_text(size=10, angle=90, hjust = 1)) + theme(axis.text.y=element_text(size=10)) + xlab("Replicate 2") + ylab("Replicate 3") +
geom_abline(intercept=0, slope=1, color="red"))
# -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
# Replicate 3 plots
# -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
g3_g1.plot <- ggplotGrob(ggplot(normalized_scores, aes(x=g3, y=g1)) + geom_point(size=.5) +
scale_x_continuous(labels = scientific, limits=c(0,2e-04)) + scale_y_continuous(labels = scientific, limits=c(0,2e-04)) +
theme_bw() + theme(axis.text.x=element_text(size=10, angle=90, hjust = 1)) + theme(axis.text.y=element_text(size=10)) + xlab("Replicate 3") + ylab("Replicate 1") +
geom_abline(intercept=0, slope=1, color="red"))
g3_g2.plot <- ggplotGrob(ggplot(normalized_scores, aes(x=g3, y=g2)) + geom_point(size=.5) +
scale_x_continuous(labels = scientific, limits=c(0,2e-04)) + scale_y_continuous(labels = scientific, limits=c(0,2e-04)) +
theme_bw() + theme(axis.text.x=element_text(size=10, angle=90, hjust = 1)) + theme(axis.text.y=element_text(size=10)) + xlab("Replicate 3") + ylab("Replicate 2") +
geom_abline(intercept=0, slope=1, color="red"))
g3_g3.plot <- ggplotGrob(ggplot(normalized_scores, aes(x=g3, y=g3)) + geom_point(size=.5) +
scale_x_continuous(labels = scientific, limits=c(0,2e-04)) + scale_y_continuous(labels = scientific, limits=c(0,2e-04)) +
theme_bw() + theme(axis.text.x=element_text(size=10, angle=90, hjust = 1)) + theme(axis.text.y=element_text(size=10)) + xlab("Replicate 3") + ylab("Replicate 3") +
geom_abline(intercept=0, slope=1, color="red"))
# -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
# Create final plot
# The layout for the gtable is 5 columns x 8 rows (7.25 inches high x 6.5 inches wide)
# The 5 columns are:
# 1. plot 1 for the replicate (2 inches)
# 2. spacer (.25 inches)
# 3. plot 2 for the replicate (2 inches)
# 4. spacer (.25 inches)
# 5. plot 3 for the replicate (2 inches)
# The 8 rows are:
# 1: replicate 1 title (.25 inches)
# 2: replicate 1 plots (2 inches)
# 3: spacer (.25 inches)
# 4: replicate 2 title (.25 inches)
# 5: replicate 2 plots (2 inches)
# 6: spacer (.25 inches)
# 7: replicate 3 title (.25 inches)
# 8: replicate 3 plots (2 inches)
# The parameters are:
# t --> top
# l --> left
# r --> right
# b- --> bottom
# -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
# Create the table
gorilla_gtable <- gtable(widths=unit(c(2, .25, 2, .25, 2), "in"), heights=unit(c(.2, 2, .25, .2, 2, .25, .2, 2), "in"))
# Add a white background to all of the cells
gorilla_gtable <- gtable_add_grob(gorilla_gtable, rectGrob(gp = gpar(fill = "white", col="white")), t=1, l=1, b=8, r=5)
# Add the headings for each of the replicate rows
gorilla_gtable <- gtable_add_grob(gorilla_gtable, textGrob("Replicate 1", gp=gpar(col="blue", fontsize=12)), t=1, l=1, r=5)
gorilla_gtable <- gtable_add_grob(gorilla_gtable, textGrob("Replicate 2", gp=gpar(col="blue", fontsize=12)), t=4, l=1, r=5)
gorilla_gtable <- gtable_add_grob(gorilla_gtable, textGrob("Replicate 3", gp=gpar(col="blue", fontsize=12)), t=7, l=1, r=5)
# Add the replicate 1 plots
gorilla_gtable <- gtable_add_grob(gorilla_gtable, g1_g1.plot, t=2, l=1)
gorilla_gtable <- gtable_add_grob(gorilla_gtable, g1_g2.plot, t=2, l=3)
gorilla_gtable <- gtable_add_grob(gorilla_gtable, g1_g3.plot, t=2, l=5)
# Add the replicate 2 plots
gorilla_gtable <- gtable_add_grob(gorilla_gtable, g2_g1.plot, t=5, l=1)
gorilla_gtable <- gtable_add_grob(gorilla_gtable, g2_g2.plot, t=5, l=3)
gorilla_gtable <- gtable_add_grob(gorilla_gtable, g2_g3.plot, t=5, l=5)
# Add the replicate 3 plots
gorilla_gtable <- gtable_add_grob(gorilla_gtable, g3_g1.plot, t=8, l=1)
gorilla_gtable <- gtable_add_grob(gorilla_gtable, g3_g2.plot, t=8, l=3)
gorilla_gtable <- gtable_add_grob(gorilla_gtable, g3_g3.plot, t=8, l=5)
# Plot the elements
grid.arrange(gorilla_gtable, top=textGrob("Gorilla cut counts for the union set of DHS sites (89,744 sites)", gp=gpar(col="black", fontface="bold")), ncol=1, nrow=1)
dev.off()
# -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
# Finish up
# -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
cat("done\n\n")
# ===================================================================================================================================================================================================================
# Orangutan
# ===================================================================================================================================================================================================================
cat("Generating scatterplots for orangutan replicates ... ")
png("replicate_scatterplots.orangutan.png", height=2250, width=2100, res=300)
# -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
# Replicate 1 plots
# -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
o1_o1.plot <- ggplotGrob(ggplot(normalized_scores, aes(x=o1, y=o1)) + geom_point(size=.5) +
scale_x_continuous(labels = scientific, limits=c(0,2e-04)) + scale_y_continuous(labels = scientific, limits=c(0,2e-04)) +
theme_bw() + theme(axis.text.x=element_text(size=10, angle=90, hjust = 1)) + theme(axis.text.y=element_text(size=10)) + xlab("Replicate 1") + ylab("Replicate 1") +
geom_abline(intercept=0, slope=1, color="red"))
o1_o2.plot <- ggplotGrob(ggplot(normalized_scores, aes(x=o1, y=o2)) + geom_point(size=.5) +
scale_x_continuous(labels = scientific, limits=c(0,2e-04)) + scale_y_continuous(labels = scientific, limits=c(0,2e-04)) +
theme_bw() + theme(axis.text.x=element_text(size=10, angle=90, hjust = 1)) + theme(axis.text.y=element_text(size=10)) + xlab("Replicate 1") + ylab("Replicate 2") +
geom_abline(intercept=0, slope=1, color="red"))
o1_o3.plot <- ggplotGrob(ggplot(normalized_scores, aes(x=o1, y=o3)) + geom_point(size=.5) +
scale_x_continuous(labels = scientific, limits=c(0,2e-04)) + scale_y_continuous(labels = scientific, limits=c(0,2e-04)) +
theme_bw() + theme(axis.text.x=element_text(size=10, angle=90, hjust = 1)) + theme(axis.text.y=element_text(size=10)) + xlab("Replicate 1") + ylab("Replicate 3") +
geom_abline(intercept=0, slope=1, color="red"))
# -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
# Replicate 2 plots
# -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
o2_o1.plot <- ggplotGrob(ggplot(normalized_scores, aes(x=o2, y=o1)) + geom_point(size=.5) +
scale_x_continuous(labels = scientific, limits=c(0,2e-04)) + scale_y_continuous(labels = scientific, limits=c(0,2e-04)) +
theme_bw() + theme(axis.text.x=element_text(size=10, angle=90, hjust = 1)) + theme(axis.text.y=element_text(size=10)) + xlab("Replicate 2") + ylab("Replicate 1") +
geom_abline(intercept=0, slope=1, color="red"))
o2_o2.plot <- ggplotGrob(ggplot(normalized_scores, aes(x=o2, y=o2)) + geom_point(size=.5) +
scale_x_continuous(labels = scientific, limits=c(0,2e-04)) + scale_y_continuous(labels = scientific, limits=c(0,2e-04)) +
theme_bw() + theme(axis.text.x=element_text(size=10, angle=90, hjust = 1)) + theme(axis.text.y=element_text(size=10)) + xlab("Replicate 2") + ylab("Replicate 2") +
geom_abline(intercept=0, slope=1, color="red"))
o2_o3.plot <- ggplotGrob(ggplot(normalized_scores, aes(x=o2, y=o3)) + geom_point(size=.5) +
scale_x_continuous(labels = scientific, limits=c(0,2e-04)) + scale_y_continuous(labels = scientific, limits=c(0,2e-04)) +
theme_bw() + theme(axis.text.x=element_text(size=10, angle=90, hjust = 1)) + theme(axis.text.y=element_text(size=10)) + xlab("Replicate 2") + ylab("Replicate 3") +
geom_abline(intercept=0, slope=1, color="red"))
# -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
# Replicate 3 plots
# -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
o3_o1.plot <- ggplotGrob(ggplot(normalized_scores, aes(x=o3, y=o1)) + geom_point(size=.5) +
scale_x_continuous(labels = scientific, limits=c(0,2e-04)) + scale_y_continuous(labels = scientific, limits=c(0,2e-04)) +
theme_bw() + theme(axis.text.x=element_text(size=10, angle=90, hjust = 1)) + theme(axis.text.y=element_text(size=10)) + xlab("Replicate 3") + ylab("Replicate 1") +
geom_abline(intercept=0, slope=1, color="red"))
o3_o2.plot <- ggplotGrob(ggplot(normalized_scores, aes(x=o3, y=o2)) + geom_point(size=.5) +
scale_x_continuous(labels = scientific, limits=c(0,2e-04)) + scale_y_continuous(labels = scientific, limits=c(0,2e-04)) +
theme_bw() + theme(axis.text.x=element_text(size=10, angle=90, hjust = 1)) + theme(axis.text.y=element_text(size=10)) + xlab("Replicate 3") + ylab("Replicate 2") +
geom_abline(intercept=0, slope=1, color="red"))
o3_o3.plot <- ggplotGrob(ggplot(normalized_scores, aes(x=o3, y=o3)) + geom_point(size=.5) +
scale_x_continuous(labels = scientific, limits=c(0,2e-04)) + scale_y_continuous(labels = scientific, limits=c(0,2e-04)) +
theme_bw() + theme(axis.text.x=element_text(size=10, angle=90, hjust = 1)) + theme(axis.text.y=element_text(size=10)) + xlab("Replicate 3") + ylab("Replicate 3") +
geom_abline(intercept=0, slope=1, color="red"))
# -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
# Create final plot
# The layout for the gtable is 5 columns x 8 rows (7.25 inches high x 6.5 inches wide)
# The 5 columns are:
# 1. plot 1 for the replicate (2 inches)
# 2. spacer (.25 inches)
# 3. plot 2 for the replicate (2 inches)
# 4. spacer (.25 inches)
# 5. plot 3 for the replicate (2 inches)
# The 8 rows are:
# 1: replicate 1 title (.25 inches)
# 2: replicate 1 plots (2 inches)
# 3: spacer (.25 inches)
# 4: replicate 2 title (.25 inches)
# 5: replicate 2 plots (2 inches)
# 6: spacer (.25 inches)
# 7: replicate 3 title (.25 inches)
# 8: replicate 3 plots (2 inches)
# The parameters are:
# t --> top
# l --> left
# r --> right
# b- --> bottom
# -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
# Create the table
orangutan_gtable <- gtable(widths=unit(c(2, .25, 2, .25, 2), "in"), heights=unit(c(.2, 2, .25, .2, 2, .25, .2, 2), "in"))
# Add a white background to all of the cells
orangutan_gtable <- gtable_add_grob(orangutan_gtable, rectGrob(gp = gpar(fill = "white", col="white")), t=1, l=1, b=8, r=5)
# Add the headings for each of the replicate rows
orangutan_gtable <- gtable_add_grob(orangutan_gtable, textGrob("Replicate 1", gp=gpar(col="blue", fontsize=12)), t=1, l=1, r=5)
orangutan_gtable <- gtable_add_grob(orangutan_gtable, textGrob("Replicate 2", gp=gpar(col="blue", fontsize=12)), t=4, l=1, r=5)
orangutan_gtable <- gtable_add_grob(orangutan_gtable, textGrob("Replicate 3", gp=gpar(col="blue", fontsize=12)), t=7, l=1, r=5)
# Add the replicate 1 plots
orangutan_gtable <- gtable_add_grob(orangutan_gtable, o1_o1.plot, t=2, l=1)
orangutan_gtable <- gtable_add_grob(orangutan_gtable, o1_o2.plot, t=2, l=3)
orangutan_gtable <- gtable_add_grob(orangutan_gtable, o1_o3.plot, t=2, l=5)
# Add the replicate 2 plots
orangutan_gtable <- gtable_add_grob(orangutan_gtable, o2_o1.plot, t=5, l=1)
orangutan_gtable <- gtable_add_grob(orangutan_gtable, o2_o2.plot, t=5, l=3)
orangutan_gtable <- gtable_add_grob(orangutan_gtable, o2_o3.plot, t=5, l=5)
# Add the replicate 3 plots
orangutan_gtable <- gtable_add_grob(orangutan_gtable, o3_o1.plot, t=8, l=1)
orangutan_gtable <- gtable_add_grob(orangutan_gtable, o3_o2.plot, t=8, l=3)
orangutan_gtable <- gtable_add_grob(orangutan_gtable, o3_o3.plot, t=8, l=5)
# Plot the elements
grid.arrange(orangutan_gtable, top=textGrob("Orangutan cut counts for the union set of DHS sites (89,744 sites)", gp=gpar(col="black", fontface="bold")), ncol=1, nrow=1)
dev.off()
# -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
# Finish up
# -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
cat("done\n\n")
# ===================================================================================================================================================================================================================
# Macaque
# ===================================================================================================================================================================================================================
cat("Generating scatterplots for macaque replicates ... ")
png("replicate_scatterplots.macaque.png", height=2250, width=2100, res=300)
# -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
# Replicate 1 plots
# -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
m1_m1.plot <- ggplotGrob(ggplot(normalized_scores, aes(x=m1, y=m1)) + geom_point(size=.5) +
scale_x_continuous(labels = scientific, limits=c(0,5e-04)) + scale_y_continuous(labels = scientific, limits=c(0,5e-04)) +
theme_bw() + theme(axis.text.x=element_text(size=10, angle=90, hjust = 1)) + theme(axis.text.y=element_text(size=10)) + xlab("Replicate 1") + ylab("Replicate 1") +
geom_abline(intercept=0, slope=1, color="red"))
m1_m2.plot <- ggplotGrob(ggplot(normalized_scores, aes(x=m1, y=m2)) + geom_point(size=.5) +
scale_x_continuous(labels = scientific, limits=c(0,5e-04)) + scale_y_continuous(labels = scientific, limits=c(0,5e-04)) +
theme_bw() + theme(axis.text.x=element_text(size=10, angle=90, hjust = 1)) + theme(axis.text.y=element_text(size=10)) + xlab("Replicate 1") + ylab("Replicate 2") +
geom_abline(intercept=0, slope=1, color="red"))
m1_m3.plot <- ggplotGrob(ggplot(normalized_scores, aes(x=m1, y=m3)) + geom_point(size=.5) +
scale_x_continuous(labels = scientific, limits=c(0,5e-04)) + scale_y_continuous(labels = scientific, limits=c(0,5e-04)) +
theme_bw() + theme(axis.text.x=element_text(size=10, angle=90, hjust = 1)) + theme(axis.text.y=element_text(size=10)) + xlab("Replicate 1") + ylab("Replicate 3") +
geom_abline(intercept=0, slope=1, color="red"))
# -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
# Replicate 2 plots
# -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
m2_m1.plot <- ggplotGrob(ggplot(normalized_scores, aes(x=m2, y=m1)) + geom_point(size=.5) +
scale_x_continuous(labels = scientific, limits=c(0,5e-04)) + scale_y_continuous(labels = scientific, limits=c(0,5e-04)) +
theme_bw() + theme(axis.text.x=element_text(size=10, angle=90, hjust = 1)) + theme(axis.text.y=element_text(size=10)) + xlab("Replicate 2") + ylab("Replicate 1") +
geom_abline(intercept=0, slope=1, color="red"))
m2_m2.plot <- ggplotGrob(ggplot(normalized_scores, aes(x=m2, y=m2)) + geom_point(size=.5) +
scale_x_continuous(labels = scientific, limits=c(0,5e-04)) + scale_y_continuous(labels = scientific, limits=c(0,5e-04)) +
theme_bw() + theme(axis.text.x=element_text(size=10, angle=90, hjust = 1)) + theme(axis.text.y=element_text(size=10)) + xlab("Replicate 2") + ylab("Replicate 2") +
geom_abline(intercept=0, slope=1, color="red"))
m2_m3.plot <- ggplotGrob(ggplot(normalized_scores, aes(x=m2, y=m3)) + geom_point(size=.5) +
scale_x_continuous(labels = scientific, limits=c(0,5e-04)) + scale_y_continuous(labels = scientific, limits=c(0,5e-04)) +
theme_bw() + theme(axis.text.x=element_text(size=10, angle=90, hjust = 1)) + theme(axis.text.y=element_text(size=10)) + xlab("Replicate 2") + ylab("Replicate 3") +
geom_abline(intercept=0, slope=1, color="red"))
# -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
# Replicate 3 plots
# -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
m3_m1.plot <- ggplotGrob(ggplot(normalized_scores, aes(x=m3, y=m1)) + geom_point(size=.5) +
scale_x_continuous(labels = scientific, limits=c(0,5e-04)) + scale_y_continuous(labels = scientific, limits=c(0,5e-04)) +
theme_bw() + theme(axis.text.x=element_text(size=10, angle=90, hjust = 1)) + theme(axis.text.y=element_text(size=10)) + xlab("Replicate 3") + ylab("Replicate 1") +
geom_abline(intercept=0, slope=1, color="red"))
m3_m2.plot <- ggplotGrob(ggplot(normalized_scores, aes(x=m3, y=m2)) + geom_point(size=.5) +
scale_x_continuous(labels = scientific, limits=c(0,5e-04)) + scale_y_continuous(labels = scientific, limits=c(0,5e-04)) +
theme_bw() + theme(axis.text.x=element_text(size=10, angle=90, hjust = 1)) + theme(axis.text.y=element_text(size=10)) + xlab("Replicate 3") + ylab("Replicate 2") +
geom_abline(intercept=0, slope=1, color="red"))
m3_m3.plot <- ggplotGrob(ggplot(normalized_scores, aes(x=m3, y=m3)) + geom_point(size=.5) +
scale_x_continuous(labels = scientific, limits=c(0,5e-04)) + scale_y_continuous(labels = scientific, limits=c(0,5e-04)) +
theme_bw() + theme(axis.text.x=element_text(size=10, angle=90, hjust = 1)) + theme(axis.text.y=element_text(size=10)) + xlab("Replicate 3") + ylab("Replicate 3") +
geom_abline(intercept=0, slope=1, color="red"))
# -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
# Create final plot
# The layout for the gtable is 5 columns x 8 rows (7.25 inches high x 6.5 inches wide)
# The 5 columns are:
# 1. plot 1 for the replicate (2 inches)
# 2. spacer (.25 inches)
# 3. plot 2 for the replicate (2 inches)
# 4. spacer (.25 inches)
# 5. plot 3 for the replicate (2 inches)
# The 8 rows are:
# 1: replicate 1 title (.25 inches)
# 2: replicate 1 plots (2 inches)
# 3: spacer (.25 inches)
# 4: replicate 2 title (.25 inches)
# 5: replicate 2 plots (2 inches)
# 6: spacer (.25 inches)
# 7: replicate 3 title (.25 inches)
# 8: replicate 3 plots (2 inches)
# The parameters are:
# t --> top
# l --> left
# r --> right
# b- --> bottom
# -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
# Create the table
macaque_gtable <- gtable(widths=unit(c(2, .25, 2, .25, 2), "in"), heights=unit(c(.2, 2, .25, .2, 2, .25, .2, 2), "in"))
# Add a white background to all of the cells
macaque_gtable <- gtable_add_grob(macaque_gtable, rectGrob(gp = gpar(fill = "white", col="white")), t=1, l=1, b=8, r=5)
# Add the headings for each of the replicate rows
macaque_gtable <- gtable_add_grob(macaque_gtable, textGrob("Replicate 1", gp=gpar(col="blue", fontsize=12)), t=1, l=1, r=5)
macaque_gtable <- gtable_add_grob(macaque_gtable, textGrob("Replicate 2", gp=gpar(col="blue", fontsize=12)), t=4, l=1, r=5)
macaque_gtable <- gtable_add_grob(macaque_gtable, textGrob("Replicate 3", gp=gpar(col="blue", fontsize=12)), t=7, l=1, r=5)
# Add the replicate 1 plots
macaque_gtable <- gtable_add_grob(macaque_gtable, m1_m1.plot, t=2, l=1)
macaque_gtable <- gtable_add_grob(macaque_gtable, m1_m2.plot, t=2, l=3)
macaque_gtable <- gtable_add_grob(macaque_gtable, m1_m3.plot, t=2, l=5)
# Add the replicate 2 plots
macaque_gtable <- gtable_add_grob(macaque_gtable, m2_m1.plot, t=5, l=1)
macaque_gtable <- gtable_add_grob(macaque_gtable, m2_m2.plot, t=5, l=3)
macaque_gtable <- gtable_add_grob(macaque_gtable, m2_m3.plot, t=5, l=5)
# Add the replicate 3 plots
macaque_gtable <- gtable_add_grob(macaque_gtable, m3_m1.plot, t=8, l=1)
macaque_gtable <- gtable_add_grob(macaque_gtable, m3_m2.plot, t=8, l=3)
macaque_gtable <- gtable_add_grob(macaque_gtable, m3_m3.plot, t=8, l=5)
# Plot the elements
grid.arrange(macaque_gtable, top=textGrob("Macaque cut counts for the union set of DHS sites (89,744 sites)", gp=gpar(col="black", fontface="bold")), ncol=1, nrow=1)
dev.off()
# -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
# Finish up
# -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
cat("done\n\n")
# ###################################################################################################################################################################################################################
# Finish up
# ###################################################################################################################################################################################################################
cat("Plots are located in:\n")
cat(" replicate_scatterplots.chimp.png\n")
cat(" replicate_scatterplots.gorilla.png\n")
cat(" replicate_scatterplots.human.png\n")
cat(" replicate_scatterplots.macaque.png\n")
cat(" replicate_scatterplots.orangutan.png\n\n")
cat("------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\n")
cat("END:", date(), "\n")
cat("------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\n")
sink()