-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path4_RBP_motif.R
4602 lines (3606 loc) · 222 KB
/
4_RBP_motif.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
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
###############################################################################################################
#
# Filippos Klironomos, Department of Pediatric Hematology, Oncology and SCT Charité University Hospital Berlin
#
###############################################################################################################
##############################
#
#
# circRNAs RBP motif analysis
#
#
##############################
# [all RBPs] neuroblastoma-DE RBPs mRNA expression compared across tissues (human brain, various tumors)
#{{{
rm(list=ls())
library(Biostrings)
library(GenomicFeatures)
library(rtracklayer)
library(data.table)
library(RColorBrewer)
library(viridis)
library(pheatmap)
library(extrafont) # first time used need to run: font_import() , to load all for PDF device run: loadfonts(device='pdf')
loadfonts()
source('/fast/projects/peifer_wgs/work/work/2017-11-08_Fuchs_totalRNAseq/lib/load_gene_expression.R')
source('~/bio/lib/draw_highlights.R')
# load all RBPs
# inflate per motif the subgroups based on PWMs into one group of unique genes (motif-inflating needs to happen alone, different 1:many map than genes)
# keep 6mers or longer
# collect per RBP gene all its motifs
# define GENES data.frame
load('/fast/groups/ag_schulte/work/reference/annotation/ATtRACT/Homo_sapiens_ATtRACT_db.RData')
RBP<-db[, .(gene_name=unique(unlist(gene_name)), gene_id=unique(unlist(gene_id)), motif=motif), by=.(id)][, .(motif=unlist(motif)), by=.(gene_name, gene_id)][ sapply(motif, nchar)>=6, ][, .(motif=list(unique(motif))), by=.(gene_name, gene_id)]
GENES<-data.frame(RBP[, c('gene_name', 'gene_id')])
rm(db)
# get CPMs across tissues/tumors
# Mann-Whitney two-sided tests for neuroblastoma vs human brain and neuroblastoma vs various tumors for those genes found expressed in
# at least 50% of samples with at least 30% of them having a CPM>=1
# FDR-correct p-values
# define one p-value to be the sum of the FDR-corrected p-values if both are significant (<0.05)
# prepare for plotting
# save
#{{{
# get their CPMs across tissues/tumors
x<-load_gene_expression(GENES, nb.tumors.only=T, vt.tumors.only=T)
nb.genes<-x$nb$genes
nb.meta<-x$nb$meta
hb.genes<-x$hb$genes
hb.meta<-x$hb$meta
vt.genes<-x$vt$genes
vt.meta<-x$vt$meta
rm(x,load_gene_expression)
# [neuroblastoma] keep only tumors
# keep only CPMs and transpose
nb.genes<-t(nb.genes[ !is.na(nb.genes$risk_group), -tail(seq_len(ncol(nb.genes)),3)])
# [human brain] keep only CPMs and transpose
hb.genes<-t(hb.genes[, -tail(seq_len(ncol(hb.genes)),1) ])
# [various tumors] keep only CPMs and transpose
vt.genes<-t(vt.genes[, -tail(seq_len(ncol(vt.genes)),1) ])
# go over each gene and do Mann-Whitney tests for the CPMs in NB vs brain tissue and NB vs various tumors
GENES$pv.hb<-GENES$pv.vt<-NA
for (n in seq_along(GENES$gene_name)){
x<-nb.genes[ n, ]
y<-hb.genes[ n, ]
z<-vt.genes[ n, ]
# at least 50% of samples in the whole cohort should express it and at least 30% of those should have CPM>=1
if(quantile(x[x!=0], 0.7)<1 | sum(x!=0)/length(x)<0.5){ next }
# Mann-Whitney test that NB are higher expressed
GENES$pv.hb[n]<-wilcox.test(x=x, y=y, alternative='two.sided')$p.value
GENES$pv.vt[n]<-wilcox.test(x=x, y=z, alternative='two.sided')$p.value
}
rm(n,x,y,z)
# FDR-adjust p-values
GENES$pv.hb<-p.adjust(GENES$pv.hb, method='BH')
GENES$pv.vt<-p.adjust(GENES$pv.vt, method='BH')
# define a p-value which is the sum of p-values provided both FDR-corrected p-values are significant (<0.05)
GENES$pvalue<-GENES$pv.hb + GENES$pv.vt
GENES$pvalue[ ! ( GENES$pv.hb<0.05 & GENES$pv.vt<0.05) ]<-NA
# order by p-value
GENES<-GENES[ order(GENES$pvalue, decreasing=F), ]
rownames(GENES)<-NULL
nb.genes<-nb.genes[ GENES$gene_name, ]
hb.genes<-hb.genes[ GENES$gene_name, ]
vt.genes<-vt.genes[ GENES$gene_name, ]
stopifnot( all.equal( rownames(nb.genes), GENES$gene_name ) )
stopifnot( all.equal( rownames(hb.genes), GENES$gene_name ) )
stopifnot( all.equal( rownames(vt.genes), GENES$gene_name ) )
# save for easy use
save(RBP, GENES, nb.genes, nb.meta, hb.genes, hb.meta, vt.genes, vt.meta, file='/fast/projects/peifer_wgs/work/work/2017-11-08_Fuchs_totalRNAseq/raw/unified/RBPs_across_tissues.RData')
#}}}
# load above results
load('/fast/projects/peifer_wgs/work/work/2017-11-08_Fuchs_totalRNAseq/raw/unified/RBPs_across_tissues.RData')
# keep only significantly DE throughout
GENES<-subset(GENES, pvalue<0.05)
nb.genes<-nb.genes[ GENES$gene_name, ]
hb.genes<-hb.genes[ GENES$gene_name, ]
vt.genes<-vt.genes[ GENES$gene_name, ]
# order by NB expression
n<-order(rowMeans(nb.genes), decreasing=T)
GENES<-GENES[n, ]
nb.genes<-nb.genes[n, ]
hb.genes<-hb.genes[n, ]
vt.genes<-vt.genes[n, ]
stopifnot( all.equal( rownames(nb.genes), GENES$gene_name ) )
stopifnot( all.equal( rownames(nb.genes), rownames(hb.genes)) )
stopifnot( all.equal( rownames(nb.genes), rownames(vt.genes)) )
rm(n)
# identify those classified as groupI in Gerstberger et al. 2014 which are down-regulated upon brain development
load('/fast/projects/peifer_wgs/work/work/2017-11-08_Fuchs_totalRNAseq/validations/rbp/brainspan_census_of_human_RBPs_nrg3813/nrg3813-s7.RData')
GENES$groupI<-F
GENES$groupI[ GENES$gene_name %in% rbp[ groupI==T, gene_name] ]<-T
# recycle
x11(width=25, height=14, title='', bg='white', type='cairo', pointsize=20, antialias='subpixel', family='Arial')
# heatmap on the log2-transformed (best contrast, compared to z-scores of raw CPMs, or z-scores of log2-transformed CPMs)
# clustered by Euclidean distance in NB samples
X<-cbind(log2(1+nb.genes), log2(1+hb.genes), log2(1+vt.genes)) # combine in one matrix
ex<-data.frame(tissue=factor(rep(c('neuroblastoma', 'brain tissue', 'various tumors'), c(ncol(nb.genes), ncol(hb.genes), ncol(vt.genes))), exclude=F), row.names=colnames(X))
cl<-setNames(list(setNames( c('seagreen4', 'cornflowerblue', 'coral4'), c('neuroblastoma', 'brain tissue', 'various tumors') )), colnames(ex))
hc<-hclust(dist(log2(1+nb.genes), method='euclidean'), method='ward.D2') # cluster based on distance between rows for NB only samples
#hc<-hclust(dist(X, method='euclidean'), method='ward.D2')
ph<-pheatmap(X, color=viridis(10), border_color=NA, scale='none',
cluster_rows=hc,
cluster_cols=F,
annotation_legend=T, annotation_names_row=T, annotation_names_col=T,
annotation_col=ex, annotation_row=NA, annotation_colors=cl,
drop_levels=F, show_rownames=T, show_colnames=F,
fontsize = 12, fontsize_row=12, fontsize_col=12, fontsize_number=5.0)
dev.print(device=svg, file='/fast/projects/peifer_wgs/work/work/2017-11-08_Fuchs_totalRNAseq/raw/unified/figures/heatmap_RBPs_across_tissues.svg', width=18, height=14, bg='white', antialias='subpixel', pointsize=20, family='Arial')
rm(X,hc,ex,cl,ph)
# boxplots of log2-transformed CPMs
B<-c(split(log2(1+nb.genes), row(nb.genes)), split(log2(1+hb.genes), row(hb.genes)), split(log2(1+vt.genes), row(vt.genes)))
n<-c(rbind(rbind(1:nrow(nb.genes), nrow(nb.genes)+(1:nrow(nb.genes)), 2*nrow(nb.genes)+(1:nrow(nb.genes))))) # order them in triplets
B<-B[n]
B.cl<-rep(c('seagreen4', 'cornflowerblue', 'coral4'), nrow(nb.genes))
groupI.cl<-setNames(rep('black', nrow(nb.genes)), rownames(nb.genes))
#groupI.cl[ GENES$gene_name[ GENES$groupI ] ]<-'darkorange'
par(mar=c(6.0, 7.0, 0.1, 0.0), mgp=c(3,1,0), oma=c(0,0,0,0), las=1, xpd=NA, bty='n', cex.lab=2.4, cex.axis=2.4)
YTICK<-pretty(c(0, max(ceiling(sapply(B, max)))), 5)
plot(0:1, 0:1, xlim=c(0, length(B))+c(-2, 2), type='n', ylim=range(YTICK), axes=F, ann=F, xaxs='i')
bp<-boxplot(B, col=B.cl, ylab='', xlab='', show.names=F, frame.plot=F, medcol='lightgrey', boxwex=0.8, xpd=F, outline=F, boxcol=B.cl, range=0, add=T)
mtext(expression(log[2](1+'CPM')), side=2, line=3, padj=-0.2, las=0, cex=2.4)
mtext(text=rownames(nb.genes), side=1, line=0, at=seq(2, length(B), 3), las=2, adj=1, cex=1.2, col=groupI.cl)
draw_highlights(L=length(B), STEP=3, YMAX=max(YTICK))
legend('topleft', legend=c('neuroblastoma', 'brain tissue', 'various tumors'), col=unique(B.cl), bty='n', lty=1, lwd=15, pch=NA, cex=1.8, xpd=T, y.intersp=0.60, x.intersp=0.1, seg.len=0.5)
dev.print(device=svg, file='/fast/projects/peifer_wgs/work/work/2017-11-08_Fuchs_totalRNAseq/raw/unified/figures/boxplot_RBPs_across_tissues.svg', width=35, height=14, bg='white', antialias='subpixel', pointsize=20, family='Arial')
rm(YTICK,B,n,B.cl,bp)
#}}}
#
# => /fast/projects/peifer_wgs/work/work/2017-11-08_Fuchs_totalRNAseq/raw/unified/RBPs_across_tissues.RData
# [MNA vs HR_nMNA] intersection of DE splicing factors with neuroblastoma-DE RBPs
#{{{
rm(list=ls())
library(Biostrings)
library(GenomicFeatures)
library(rtracklayer)
library(data.table)
library(RColorBrewer)
library(viridis)
library(pheatmap)
library(extrafont) # first time used need to run: font_import() , to load all for PDF device run: loadfonts(device='pdf')
loadfonts()
# load the neuroblastoma-DE RBPs
load('/fast/projects/peifer_wgs/work/work/2017-11-08_Fuchs_totalRNAseq/raw/unified/RBPs_across_tissues.RData')
# load DE results for genes and split to up-/downregulated
load('/fast/projects/peifer_wgs/work/work/2017-11-08_Fuchs_totalRNAseq/raw/unified/DESeq2_genes_MNA_HR_nMNA.RData')
up.gns<-subset(RES, log2FoldChange>0 & padj<0.05)
down.gns<-subset(RES, log2FoldChange<0 & padj<0.05)
rm(RES, CND, DDS, PCA, VE, VSC)
# load union of splice-factors and identify the significantly up-/downregulated
load('/fast/groups/ag_schulte/work/reference/annotation/human_splicing/SpliceAid-F+GO.RData')
load('/fast/groups/ag_schulte/work/reference/annotation/human_splicing/MSigDB_c2_v7.0_splicing.RData')
db<-unique(rbind(data.frame(db[, c('gene_name', 'gene_id')]), msigdbSF[, c('gene_name', 'gene_id')]))
up.sf<-up.gns[ rownames(up.gns) %in% db$gene_id, , drop=F]
down.sf<-down.gns[ rownames(down.gns) %in% db$gene_id, , drop=F]
rm(db,msigdbSF)
# upregulated splicing factors (basically all of them)
RBP[ gene_id %in% rownames(up.sf) ]
# gene_name gene_id motif
# 1: SRSF3 ENSG00000112081.17 AACTTTAT,ACATTCAT,ATCATCAT,ATCTTCAC,ATCTTCAT,CACATCAT,...
# 2: YBX1 ENSG00000065978.19 AGCGAGC,CGAGCGG,GAGCGAG,GAGCGGA,GCGAGCG,CCCTGCG,...
# 3: DAZAP1 ENSG00000071626.16 AAAAAAA,AATTTA,AGATAT,AGTAGG,GGGGGGG,GTAACG,...
# 4: FUS ENSG00000089280.18 AAAAAAA,GGGGGGG,TTTTTTT,CGGTGA,CGGTGG,GGGTGA,...
# 5: HNRNPA1 ENSG00000135486.17 AAAAAAA,AATTTA,AGATAT,AGTAGG,TTTTTTT,CCCCCCC,...
# 6: HNRNPD ENSG00000138668.19 AAAAAAA,AATTTA,AGATAT,AGTAGG,ATTTATTTA,TTAGAG,...
# 7: HNRNPK ENSG00000165119.21 AAAAAAA,GGGGGGG,TTTTTTT,CCCCCCC,ACCCAA,ACCCAT,...
# 8: HNRNPU ENSG00000153187.20 AAAAAAA,GGGGGGG,TTTTTTT,CCCCCCC
# 9: PCBP1 ENSG00000169564.6 AAAAAAA,GGGGGGG,TTTTTTT,CCCCCCC,TTAGAG,TTAGGA,...
# 10: SYNCRIP ENSG00000135316.17 AAAAAAA,TTTTTTT
# 11: HNRNPA0 ENSG00000177733.6 AATTTA,AGATAT,AGTAGG
# 12: HNRNPC ENSG00000092199.17 GGGGGGG,TTTTTTT,GGATAC,ATTTTTG,TTTTTTG,CTTTTTG,...
# 13: HNRNPF ENSG00000169813.16 GGGGGGG,AGGGAT,AAGGTG,GGAGGA,AGGGAAGGGA,AGGGGAGGGG,...
# 14: HNRNPH1 ENSG00000169045.17 GGGGGGG,AAGGTG,GGAGGA,AGGGAAGGGA,AGGGGAGGGG,CGGGGGGGGC,...
# 15: HNRNPH3 ENSG00000096746.17 GGGGGGG,AAGGTG,GGAGGA,AGGGAAGGGA,AGGGGAGGGG,CGGGGGGGGC,...
# 16: HNRNPM ENSG00000099783.12 GGGGGGG,GAAGGAA
# 17: PCBP2 ENSG00000197111.15 GGGGGGG,TTTTTTT,CCCCCCC,TTAGAG,TTAGGA,TTAGGG,...
# 18: PTBP1 ENSG00000011304.20 GGGGGGG,TTTTTTT,CCCCCCC,ATCTTC,CTCTTA,CTCTTC,...
# 19: ELAVL1 ENSG00000066044.15 TTTTTTT,ATTTATTTATTT,CCCCCCC,TTATTTATT,TTATTTT,TTGTTTT,...
# 20: U2AF2 ENSG00000063244.12 TTTTTTT,TTTTTCC,TTTTTTC
# 21: TRA2B ENSG00000136527.18 GAAGGA,GAAGAA,AAGAAG,AAGAAGAA,AAGAAGAAGAA,AAGAAC,...
# 22: ESRP2 ENSG00000103067.13 TGGGAAA,TGGGGAA,TGGGAAT,TGGGGAT,TGGGAAG,TGGGGAG
# 23: SRSF1 ENSG00000136450.13 AAGGTG,GGATAC,GCATAC,GGATAT,GGATTC,GGGTAC,...
# 24: SRSF2 ENSG00000161547.16 CTAGACTAGA,GAGGAG,GGAGGA,GTAAGTACGC,AAAAGAGAAG,AGAGGAAGGCGA,...
# 25: HNRNPA3 ENSG00000170144.20 GCCAAGGAGCC
# 26: HNRNPA1L2 ENSG00000139675.12 ATAGGGA,TTAGGGA,GTAGGGA,ATAGGGT,TTAGGGT,GTAGGGT
# 27: HNRNPL ENSG00000104824.17 ACACAAA,ACACGAA,ACACAAC,ACACGAC,ACACAAG,ACACGAG,...
# 28: RBM25 ENSG00000119707.14 ATCGGGCA,CGGGCA
# 29: RBMX ENSG00000147274.14 ACCAAA,ATCAAA,ATCCCA,ATCCCC,TAAGAC,TCAAAA,...
# 30: SNRPA ENSG00000077312.9 AGGAGAT,ATTGCAC,ATTGCACC,GAGCAGTAGGC,GAGCAGTAGTC,GAGCAGTAGGG,...
# 31: SRSF7 ENSG00000115875.19 AGAGGAAGGCGA,GAAGAAGAA,CTCTTCAC,AAAGGACAAA,ACGAATGAT,ACGAGACTA,...
# 32: SRSF6 ENSG00000124193.15 GAAGAAGA,GAGGAAGAA,ACCGGG,ACCGTC,AGCGGA,ATCGTA,...
# gene_name gene_id motif
# downregulated SF (basically all of them)
RBP[ gene_id %in% rownames(down.sf) ]
# gene_name gene_id motif
# 1: TARDBP ENSG00000120948.17 TGTGTG,TGTGTGTG,TGTGTGTGTG,GTGAATGA,GTTGTGC,TGTGTGTGTGTG,...
# 2: CELF6 ENSG00000140488.16 TGTGAGG,TGTGTGG,TGTGGGG,TGTGATG,TGTGTTG,TGTGGTG
# 3: ELAVL4 ENSG00000162374.17 AAAAAAA,TTTTTTT,ATTTATTTATTT,TTTATTTATTT,TTTATTTATTTA,TTTTTTATTTT,...
# 4: PPIE ENSG00000084072.16 TTTTTT,AAAAAA,AATAAA,TAAAAA,ATAAAA,TTAAAA,...
# 5: RBFOX1 ENSG00000078328.20 TGCATG,AGCATG,TGCATGT,AGCATGA,TGCATGA,AGCATGC,...
# 6: SRSF4 ENSG00000116350.17 GAAGAAGA,GAGGAAGAA
# gene_name gene_id motif
#}}}
# [circRNAs] DREME : 6mer, 7mer, 8mer motif enrichment
# AME : ATtRACT human RBP motif enrichment for 6mers and above
# FIMO : count individual motif occurrences for 6mers and above
#{{{
rm(list=ls())
library(data.table)
library(GenomicAlignments)
library(rtracklayer)
library(XML)
# create the subdirectory and run in separate screen sessions the different analyses
#{{{
system2('mkdir', args='-p /fast/projects/peifer_wgs/work/work/2017-11-08_Fuchs_totalRNAseq/raw/unified/meme')
#
#
# run MEME (de novo 7mer-50mer motif enrichment):
# N.B. when full sequence lengths are used this becomes unbelievably slow, anyway there is no need to run it, AME is what we need
#
# cd /fast/projects/peifer_wgs/work/work/2017-11-08_Fuchs_totalRNAseq/raw/unified/meme/results_meme/
# fasta-get-markov -m 0 -rna -norc ../../circRNAs_sequences.fa background.model
# meme -rna -mod anr -oc results_meme -minw 7 -maxw 20 -markov_order 0 -bfile background.model -nmotifs 50 -allw -neg ../../circRNAs_controls_sequences.fa -objfun de -test mhg -searchsize 0 ../../circRNAs_sequences.fa
#
# run DREME (6mer, 7mer, 8mer motif enrichment):
# N.B. this is also unbelievably slow and anyway I never used these results, AME is what we need
#
# cd /fast/projects/peifer_wgs/work/work/2017-11-08_Fuchs_totalRNAseq/raw/unified/meme/results_dreme/
# dreme-py3 -p ../../circRNAs_sequences.fa -n ../../circRNAs_controls_sequences.fa -rna -norc -e 0.05 -mink 6 -maxk 8 -oc results_dreme -eps -png
#
# run AME (known motif enrichment using the ATtRACT Human motifs converted to the MEME motif format):
#
# cd /fast/projects/peifer_wgs/work/work/2017-11-08_Fuchs_totalRNAseq/raw/unified/meme/results_ame
# fasta-get-markov -m 0 -rna -norc ../../circRNAs_sequences.fa background.model
# ame --oc ./ --method fisher --scoring avg --evalue-report-threshold 0.05 --bfile background.model --control ../../circRNAs_controls_sequences.fa ../../circRNAs_sequences.fa /fast/groups/ag_schulte/work/reference/annotation/ATtRACT/Homo_sapiens_ATtRACT_db_strict.meme
#
# run FIMO (counting motif occurrences):
#
# cd /fast/projects/peifer_wgs/work/work/2017-11-08_Fuchs_totalRNAseq/raw/unified/meme/results_fimo
# fasta-get-markov -m 0 -rna -norc ../../circRNAs_controls_sequences.fa control_background.model
# fasta-get-markov -m 0 -rna -norc ../../circRNAs_sequences.fa signal_background.model
#
# fimo --oc ./ --norc --no-qvalue --thresh 1e-4 --bfile signal_background.model -max-stored-scores 1000000 /data/annotation/ATtRACT/Homo_sapiens_ATtRACT_db_strict.meme ../../circRNAs_sequences.fa
# fimo --oc ./control --norc --no-qvalue --thresh 1e-4 --bfile control_background.model -max-stored-scores 1000000 /data/annotation/ATtRACT/Homo_sapiens_ATtRACT_db_strict.meme ../../circRNAs_controls_sequences.fa
#}}}
# load reference to add gene_id to the results
hsa<-import('/fast/groups/ag_schulte/work/reference/annotation/GRCh38/GRCh38.gencode.v30.gtf')
hsa<-hsa[ hsa$type %in% 'gene' ]
mcols(hsa)<-mcols(hsa)[, c('gene_id', 'gene_type', 'gene_name')]
# AME results
# convert p-values to numerics
# add FDR = FP/(FP+TP) column
ame<-fread('/fast/projects/peifer_wgs/work/work/2017-11-08_Fuchs_totalRNAseq/raw/unified/meme/results_ame/ame.tsv', header=T, sep='\t', strip.white=T, blank.lines.skip=F, drop=c('motif_DB', 'FASTA_max', 'PWM_min'))[, fdr:=round(FP/(FP+TP), 3)] # comments at the bottom of the file produce warning
colnames(ame)<-c('rank', 'motif_id', 'motif_alt_id', 'consensus', 'pvalue', 'padj', 'evalue', 'tests', 'pos', 'neg', 'tp', '%tp', 'fp', '%fp', 'fdr')
ame<-ame[, c('pvalue', 'padj', 'evalue'):=list(as.numeric(pvalue), as.numeric(padj), as.numeric(evalue))]
# [do not run] DREME results
#{{{
# import the XML version of the results keeping the consensus and all equivalent motifs
# bind them to data.table converting to integer/numeric when appropriate and U->T
#
# N : ACGT
# V : ACG
# H : ACT
# D : AGT
# B : CGT
# M : AC
# R : AG
# W : AT
# S : CG
# Y : CT
# K : GT
#
dreme<-do.call(rbind, lapply(xmlToList(xmlParse('/fast/projects/peifer_wgs/work/work/2017-11-08_Fuchs_totalRNAseq/raw/unified/meme/results_dreme/dreme.xml'))[[2]], function(x){
a<-data.table(data.frame(t(x$.attrs), all_seq=unname(sapply(x[ grep('match', names(x)) ], '[', 1)), row.names=NULL))[, .(length=as.integer(length[1]),
nsites=as.integer(nsites[1]),
p=as.integer(p[1]),
n=as.integer(n[1]),
pvalue=as.numeric(pvalue[1]),
evalue=as.numeric(evalue[1]),
unerased_evalue=as.numeric(unerased_evalue[1]),
all_seq=list(all_seq)), by=.(id, alt, seq)];
return(a)}))
dreme[, c('seq', 'all_seq'):=list(gsub('U', 'T', seq), lapply(all_seq, function(s){ gsub('U', 'T', s) }))]
#}}}
# FIMO results
#{{{
# FIMO cuts off motif_ids at 100 characters. We need to fix that.
load('/fast/groups/ag_schulte/work/reference/annotation/ATtRACT/Homo_sapiens_ATtRACT_db.RData')
rm(pwm)
# load FIMO results (warning about last line skipping is normal, it contains comments about FIMO command run)
fimo<-fread('/fast/projects/peifer_wgs/work/work/2017-11-08_Fuchs_totalRNAseq/raw/unified/meme/results_fimo/fimo.tsv', header=T, strip.white=T, blank.lines.skip=T, select=c('motif_id', 'motif_alt_id', 'sequence_name', 'start', 'stop', 'score', 'p-value', 'q-value', 'matched_sequence'))
colnames(fimo)<-c('motif_id', 'motif_alt_id', 'circ_name', 'start', 'end', 'score', 'pvalue', 'qvalue', 'seq')
fimo.control<-fread('/fast/projects/peifer_wgs/work/work/2017-11-08_Fuchs_totalRNAseq/raw/unified/meme/results_fimo/control/fimo.tsv', header=T, strip.white=T, blank.lines.skip=T, select=c('motif_id', 'motif_alt_id', 'sequence_name', 'start', 'stop', 'score', 'p-value', 'q-value', 'matched_sequence'))
colnames(fimo.control)<-c('motif_id', 'motif_alt_id', 'circ_name', 'start', 'end', 'score', 'pvalue', 'qvalue', 'seq')
# fix cut motif_ids
#{{{
# identify the motif_ids 100 characters long, most likely they were cut, and the corresponding alternative motif_ids
# construct the full-length motif_ids
# check that each cut motif_id matches one full length motif_id
m<-fimo[nchar(motif_id)==100, unique(motif_id)]
a<-fimo[ motif_id %in% m, unique(motif_alt_id)]
d<-db[ motif %in% a, paste(sapply(gene_name, paste, sep='', collapse=','), id, sep='_') ]
for(i in m){
k<-grep(i, d, fixed=T)
if (length(k)==0){
stop(paste('cut motif:', i, 'does not have a home!'))
} else if (length(k)>1){
stop(paste('cut motif:', i, 'has many homes!'))
}
fimo[ motif_id %in% i, motif_id:=d[k] ]
}
# do the same for the controls
m<-fimo.control[nchar(motif_id)==100, unique(motif_id)]
a<-fimo.control[ motif_id %in% m, unique(motif_alt_id)]
d<-db[ motif %in% a, paste(sapply(gene_name, paste, sep='', collapse=','), id, sep='_') ]
for(i in m){
k<-grep(i, d, fixed=T)
if (length(k)==0){
stop(paste('cut motif:', i, 'does not have a home!'))
} else if (length(k)>1){
stop(paste('cut motif:', i, 'has many homes!'))
}
fimo.control[ motif_id %in% i, motif_id:=d[k] ]
}
#}}}
# identify the RBP groups for each motif
fimo<-fimo[, rbp_group:=lapply(strsplit(sub('_.*$', '', motif_id), ','), unique)]
fimo.control<-fimo.control[, rbp_group:=lapply(strsplit(sub('_.*$', '', motif_id), ','), unique)]
# identify the overlapping motifs per sequence
fimo[, o_group:={g<-seq_len(.N);
o<-mcols(reduce(IRanges(start=start, end=end), with.revmap=T))$revmap # God bless for reverse-map!!!!!
invisible(sapply(seq_along(o), function(n){ g[ o[[n]] ]<<-n })) # assign same group number to all overlapping motifs
g
}, by=.(circ_name)]
fimo.control[, o_group:={g<-seq_len(.N);
o<-mcols(reduce(IRanges(start=start, end=end), with.revmap=T))$revmap # God bless for reverse-map!!!!!
invisible(sapply(seq_along(o), function(n){ g[ o[[n]] ]<<-n })) # assign same group number to all overlapping motifs
g
}, by=.(circ_name)]
# group overlapping motifs per sequence
fimo<-fimo[, .(motif_id=list(unique(motif_id)), motif_alt_id=list(unique(motif_alt_id)), start=list(start), end=list(end), score=list(score), pvalue=list(pvalue), qvalue=list(qvalue), seq=list(seq), rbp_group=list(unique(unlist(rbp_group)))), by=.(circ_name, o_group)][, o_group:=NULL]
fimo.control<-fimo.control[, .(motif_id=list(unique(motif_id)), motif_alt_id=list(unique(motif_alt_id)), start=list(start), end=list(end), score=list(score), pvalue=list(pvalue), qvalue=list(qvalue), seq=list(seq), rbp_group=list(unique(unlist(rbp_group)))), by=.(circ_name, o_group)][, o_group:=NULL]
# keep on the side all motifs grouped by overlaps
fimo.all<-copy(fimo)
fimo.control.all<-copy(fimo.control)
# identify number of non-overlapping motifs per sequence collapsing motif_ids, motif_alt_ids, motif sequences and the RBPs involved
fimo<-fimo[, .(ncount=.N, motif_id=list(unique(unlist(motif_id))), motif_alt_id=list(unique(unlist(motif_alt_id))), seq=list(unique(unlist(seq))), rbp_group=list(unique(unlist(rbp_group)))), by=.(circ_name)]
fimo.control<-fimo.control[, .(ncount=.N, motif_id=list(unique(unlist(motif_id))), motif_alt_id=list(unique(unlist(motif_alt_id))), seq=list(unique(unlist(seq))), rbp_group=list(unique(unlist(rbp_group)))), by=.(circ_name)]
# add gene_ids to the RBPs involved per sequence
fimo[, gene_ids:=lapply(rbp_group, function(r){ hsa$gene_id[ match(r, hsa$gene_name) ] })]
fimo.control[, gene_ids:=lapply(rbp_group, function(r){ hsa$gene_id[ match(r, hsa$gene_name) ] })]
# include lengths of the putative circRNA sequences
# do the same for the controls
load('/fast/projects/peifer_wgs/work/work/2017-11-08_Fuchs_totalRNAseq/raw/unified/circRNAs_sequences.RData')
l<-setNames(width(CIRCS.exons.seqs), names(CIRCS.exons.seqs))
fimo[, length:=l[ circ_name ]]
fimo.all[, length:=l[ circ_name ]]
l<-setNames(width(CIRCS.controls.seqs.resized), names(CIRCS.controls.seqs.resized)) # N.B. THE RESIZED SEQUENCES ARE USED AS CONTROLS!!!
fimo.control[, length:=l[ circ_name ]]
fimo.control.all[, length:=l[ circ_name ]]
# compute count densities per 1K of sequence
fimo[, density:=ncount/length*1e3]
fimo.control[, density:=ncount/length*1e3]
#}}}
# save
save(ame, fimo, fimo.all, fimo.control, fimo.control.all, file='/fast/projects/peifer_wgs/work/work/2017-11-08_Fuchs_totalRNAseq/raw/unified/meme/results.RData')
#}}}
#
# => /fast/projects/peifer_wgs/work/work/2017-11-08_Fuchs_totalRNAseq/raw/unified/meme/results.RData
# [circRNA introns] DREME : 6mer, 7mer, 8mer motif enrichment
# AME : ATtRACT human RBP motif enrichment for 7mers and above
# FIMO : count individual motif occurrences for 7mers and above
#{{{
rm(list=ls())
library(data.table)
library(rtracklayer)
library(XML)
# create the subdirectory and run in separate screen sessions the different analyses
#{{{
system2('mkdir', args='-p /fast/projects/peifer_wgs/work/work/2017-11-08_Fuchs_totalRNAseq/raw/unified/meme/introns')
#
#
# combine upstream and downsteam intron sequences in one FASTA file BUT MAKE SURE TO ANNOTE WHICH IS WHICH:
#
# cd /fast/projects/peifer_wgs/work/work/2017-11-08_Fuchs_totalRNAseq/raw/unified/meme/introns
# cat <(sed '/^>/{s/$/_up/}' ../../circRNAs_introns_up.fa) <(sed '/^>/{s/$/_down/}' ../../circRNAs_introns_down.fa) > introns.fa
#
#
# run DREME (6mer, 7mer, 8mer motif enrichment):
#
# cd /fast/projects/peifer_wgs/work/work/2017-11-08_Fuchs_totalRNAseq/raw/unified/meme/introns/results_dreme/
# dreme-py3 -p ../introns.fa -n ../../../circRNAs_introns_controls.fa -rna -norc -e 0.05 -mink 6 -maxk 8 -oc results_dreme -eps
#
# run AME (known motif enrichment using the ATtRACT Human motifs converted to the MEME motif format):
#
# cd /fast/projects/peifer_wgs/work/work/2017-11-08_Fuchs_totalRNAseq/raw/unified/meme/introns/results_ame/
# fasta-get-markov -m 0 -rna -norc ../introns.fa background.model
# ame --oc ./ --method fisher --scoring avg --evalue-report-threshold 0.05 --bfile background.model --control ../../../circRNAs_introns_controls.fa ../introns.fa /fast/groups/ag_schulte/work/reference/annotation/ATtRACT/Homo_sapiens_ATtRACT_db_strict.meme
#
# run FIMO (counting motif occurrences):
#
# cd /fast/projects/peifer_wgs/work/work/2017-11-08_Fuchs_totalRNAseq/raw/unified/meme/introns/results_fimo
# fasta-get-markov -m 0 -rna -norc ../../../circRNAs_introns_controls.fa control_background.model
# fasta-get-markov -m 0 -rna -norc ../introns.fa signal_background.model
#
# fimo --oc ./ --norc --no-qvalue --thresh 1e-4 --bfile signal_background.model -max-stored-scores 1000000 /data/annotation/ATtRACT/Homo_sapiens_ATtRACT_db_strict.meme ../introns.fa
# fimo --oc ./control --norc --no-qvalue --thresh 1e-4 --bfile control_background.model -max-stored-scores 1000000 /data/annotation/ATtRACT/Homo_sapiens_ATtRACT_db_strict.meme ../../../circRNAs_introns_controls.fa
#}}}
# load reference to add gene_id to the results
hsa<-import('/fast/groups/ag_schulte/work/reference/annotation/GRCh38/GRCh38.gencode.v30.gtf')
hsa<-hsa[ hsa$type %in% 'gene' ]
mcols(hsa)<-mcols(hsa)[, c('gene_id', 'gene_type', 'gene_name')]
# AME results
# convert p-values to numerics
# add FDR = FP/(FP+TP) column
ame<-fread('/fast/projects/peifer_wgs/work/work/2017-11-08_Fuchs_totalRNAseq/raw/unified/meme/introns/results_ame/ame.tsv', header=T, sep='\t', strip.white=T, blank.lines.skip=F, drop=c('motif_DB', 'FASTA_max', 'PWM_min'))[, fdr:=round(FP/(FP+TP), 3)] # comments at the bottom of the file produce warning
colnames(ame)<-c('rank', 'motif_id', 'motif_alt_id', 'consensus', 'pvalue', 'padj', 'evalue', 'tests', 'pos', 'neg', 'tp', '%tp', 'fp', '%fp', 'fdr')
ame<-ame[, c('pvalue', 'padj', 'evalue'):=list(as.numeric(pvalue), as.numeric(padj), as.numeric(evalue))]
# [do not run] DREME results
#{{{
# import the XML version of the results keeping the consensus and all equivalent motifs
# bind them to data.table converting to integer/numeric when appropriate and U->T
#
# N : ACGT
# V : ACG
# H : ACT
# D : AGT
# B : CGT
# M : AC
# R : AG
# W : AT
# S : CG
# Y : CT
# K : GT
#
dreme<-do.call(rbind, lapply(xmlToList(xmlParse('/fast/projects/peifer_wgs/work/work/2017-11-08_Fuchs_totalRNAseq/raw/unified/meme/introns/results_dreme/dreme.xml'))[[2]], function(x){
a<-data.table(data.frame(t(x$.attrs), all_seq=unname(sapply(x[ grep('match', names(x)) ], '[', 1)), row.names=NULL))[, .(length=as.integer(length[1]),
nsites=as.integer(nsites[1]),
p=as.integer(p[1]),
n=as.integer(n[1]),
pvalue=as.numeric(pvalue[1]),
evalue=as.numeric(evalue[1]),
unerased_evalue=as.numeric(unerased_evalue[1]),
all_seq=list(all_seq)), by=.(id, alt, seq)];
return(a)}))
dreme[, c('seq', 'all_seq'):=list(gsub('U', 'T', seq), lapply(all_seq, function(s){ gsub('U', 'T', s) }))]
#}}}
# FIMO results
#{{{
# FIMO cuts off motif_ids at 100 characters. We need to fix that.
load('/fast/groups/ag_schulte/work/reference/annotation/ATtRACT/Homo_sapiens_ATtRACT_db.RData')
rm(pwm)
# load FIMO results (warning about last line skipping is normal, it contains comments about FIMO command run)
fimo<-fread('/fast/projects/peifer_wgs/work/work/2017-11-08_Fuchs_totalRNAseq/raw/unified/meme/introns/results_fimo/fimo.tsv', header=T, strip.white=T, blank.lines.skip=T, select=c('motif_id', 'motif_alt_id', 'sequence_name', 'start', 'stop', 'score', 'p-value', 'q-value', 'matched_sequence'))
colnames(fimo)<-c('motif_id', 'motif_alt_id', 'intron_name', 'start', 'end', 'score', 'pvalue', 'qvalue', 'seq')
fimo.control<-fread('/fast/projects/peifer_wgs/work/work/2017-11-08_Fuchs_totalRNAseq/raw/unified/meme/introns/results_fimo/control/fimo.tsv', header=T, strip.white=T, blank.lines.skip=T, select=c('motif_id', 'motif_alt_id', 'sequence_name', 'start', 'stop', 'score', 'p-value', 'q-value', 'matched_sequence'))
colnames(fimo.control)<-c('motif_id', 'motif_alt_id', 'intron_name', 'start', 'end', 'score', 'pvalue', 'qvalue', 'seq')
# fix cut motif_ids
#{{{
# identify the motif_ids 100 characters long, most likely they were cut, and the corresponding alternative motif_ids
# construct the full-length motif_ids
# check that each cut motif_id matches one full length motif_id
m<-fimo[nchar(motif_id)==100, unique(motif_id)]
a<-fimo[ motif_id %in% m, unique(motif_alt_id)]
d<-db[ motif %in% a, paste(sapply(gene_name, paste, sep='', collapse=','), id, sep='_') ]
for(i in m){
k<-grep(i, d, fixed=T)
if (length(k)==0){
stop(paste('cut motif:', i, 'does not have a home!'))
} else if (length(k)>1){
stop(paste('cut motif:', i, 'has many homes!'))
}
fimo[ motif_id %in% i, motif_id:=d[k] ]
}
# do the same for the controls
m<-fimo.control[nchar(motif_id)==100, unique(motif_id)]
a<-fimo.control[ motif_id %in% m, unique(motif_alt_id)]
d<-db[ motif %in% a, paste(sapply(gene_name, paste, sep='', collapse=','), id, sep='_') ]
for(i in m){
k<-grep(i, d, fixed=T)
if (length(k)==0){
stop(paste('cut motif:', i, 'does not have a home!'))
} else if (length(k)>1){
stop(paste('cut motif:', i, 'has many homes!'))
}
fimo.control[ motif_id %in% i, motif_id:=d[k] ]
}
#}}}
# identify the RBP groups for each motif
fimo<-fimo[, rbp_group:=lapply(strsplit(sub('_.*$', '', motif_id), ','), unique)]
fimo.control<-fimo.control[, rbp_group:=lapply(strsplit(sub('_.*$', '', motif_id), ','), unique)]
# identify the overlapping motifs per sequence
fimo[, o_group:={g<-seq_len(.N);
o<-mcols(reduce(IRanges(start=start, end=end), with.revmap=T))$revmap # God bless for reverse-map!!!!!
invisible(sapply(seq_along(o), function(n){ g[ o[[n]] ]<<-n })) # assign same group number to all overlapping motifs
g
}, by=.(intron_name)]
fimo.control[, o_group:={g<-seq_len(.N);
o<-mcols(reduce(IRanges(start=start, end=end), with.revmap=T))$revmap # God bless for reverse-map!!!!!
invisible(sapply(seq_along(o), function(n){ g[ o[[n]] ]<<-n })) # assign same group number to all overlapping motifs
g
}, by=.(intron_name)]
# group overlapping motifs per sequence
fimo<-fimo[, .(motif_id=list(unique(motif_id)), motif_alt_id=list(unique(motif_alt_id)), start=list(start), end=list(end), score=list(score), pvalue=list(pvalue), qvalue=list(qvalue), seq=list(seq), rbp_group=list(unique(unlist(rbp_group)))), by=.(intron_name, o_group)][, o_group:=NULL]
fimo.control<-fimo.control[, .(motif_id=list(unique(motif_id)), motif_alt_id=list(unique(motif_alt_id)), start=list(start), end=list(end), score=list(score), pvalue=list(pvalue), qvalue=list(qvalue), seq=list(seq), rbp_group=list(unique(unlist(rbp_group)))), by=.(intron_name, o_group)][, o_group:=NULL]
# keep on the side all motifs grouped by overlaps
fimo.all<-copy(fimo)
fimo.control.all<-copy(fimo.control)
# identify number of non-overlapping motifs per sequence collapsing motif_ids, motif sequences and the RBPs involved
fimo<-fimo[, .(ncount=.N, motif_id=list(unique(unlist(motif_id))), motif_alt_id=list(unique(unlist(motif_alt_id))), seq=list(unique(unlist(seq))), rbp_group=list(unique(unlist(rbp_group)))), by=.(intron_name)]
fimo.control<-fimo.control[, .(ncount=.N, motif_id=list(unique(unlist(motif_id))), motif_alt_id=list(unique(unlist(motif_alt_id))), seq=list(unique(unlist(seq))), rbp_group=list(unique(unlist(rbp_group)))), by=.(intron_name)]
# add gene_ids to the RBPs involved per circRNA
fimo[, gene_ids:=lapply(rbp_group, function(r){ hsa$gene_id[ match(r, hsa$gene_name) ] })]
fimo.control[, gene_ids:=lapply(rbp_group, function(r){ hsa$gene_id[ match(r, hsa$gene_name) ] })]
# define circ_name out of intron_name
fimo[, circ_name:=sub('_up$|_down$', '', intron_name)]
fimo.all[, circ_name:=sub('_up$|_down$', '', intron_name)]
fimo.control[, circ_name:=sub('_[0-9]*$', '', intron_name)]
fimo.control.all[, circ_name:=sub('_[0-9]*$', '', intron_name)]
# load introns
# resolve upstream and downstream intron sequences and add the corresponding length to the FIMO objects
# add corresponding lengths to the control introns as well
load('/fast/projects/peifer_wgs/work/work/2017-11-08_Fuchs_totalRNAseq/raw/unified/circRNAs_introns.RData')
fimo[ grepl('_up', intron_name), c('up', 'length'):=list(T , width(CIRCS.introns.up[ match(circ_name, CIRCS.introns.up$circ_name)]))]
fimo[ grepl('_down', intron_name), c('down', 'length'):=list(T , width(CIRCS.introns.down[ match(circ_name, CIRCS.introns.down$circ_name)]))]
fimo.control[, length:=width(CIRCS.controls.introns[ match(intron_name, CIRCS.controls.introns$intron_name) ])]
# compute count densities per 1K of sequence
# N.B. densities of the upstream/downstream introns of the circRNAs remain separated
fimo[, density:=ncount/length*1e3]
fimo.control[, density:=ncount/length*1e3]
#}}}
# save
save(ame, fimo, fimo.all, fimo.control, fimo.control.all, file='/fast/projects/peifer_wgs/work/work/2017-11-08_Fuchs_totalRNAseq/raw/unified/meme/introns/results.RData')
#}}}
#
# => /fast/projects/peifer_wgs/work/work/2017-11-08_Fuchs_totalRNAseq/raw/unified/meme/introns/results.RData
# [circRNAs] analysis of the AME ATtRACT RBP motif enrichment results
#{{{
rm(list=ls())
library(data.table)
library(pheatmap)
library(viridis)
library(RColorBrewer)
library(grid)
library(extrafont) # first time used need to run: font_import() , to load all for PDF device run: loadfonts(device='pdf')
loadfonts()
source('~/bio/lib/draw_highlights.R')
# load neuroblastoma-specific mRNA of RBPs results
load('/fast/projects/peifer_wgs/work/work/2017-11-08_Fuchs_totalRNAseq/raw/unified/RBPs_across_tissues.RData')
# load AME human RBP motif enrichment result
# identify gene_names from the motif_id
load('/fast/projects/peifer_wgs/work/work/2017-11-08_Fuchs_totalRNAseq/raw/unified/meme/results.RData')
ame[, gene_name:=list(strsplit(sub('_.*$', '', motif_id), ',', fixed=T))]
# RBPs in neuroblastoma with significant enrichment of their motifs in circRNAs
sig<-intersect(GENES$gene_name, unlist(ame$gene_name))
GENES<-GENES[ GENES$gene_name %in% sig, ]
rownames(GENES)<-NULL
nb.genes<-nb.genes[ GENES$gene_name, ]
hb.genes<-hb.genes[ GENES$gene_name, ]
vt.genes<-vt.genes[ GENES$gene_name, ]
ame<-ame[ sapply(gene_name, function(g){ any(g %in% sig) }), ]
# order by NB expression
n<-order(rowMeans(nb.genes), decreasing=T)
nb.genes<-nb.genes[n, ]
hb.genes<-hb.genes[n, ]
vt.genes<-vt.genes[n, ]
stopifnot( all.equal( rownames(nb.genes), rownames(hb.genes) ) )
stopifnot( all.equal( rownames(nb.genes), rownames(vt.genes) ) )
rm(n)
# identify those classified as groupI in Gerstberger et al. 2014 which are down-regulated upon brain development
load('/fast/projects/peifer_wgs/work/work/2017-11-08_Fuchs_totalRNAseq/validations/rbp/brainspan_census_of_human_RBPs_nrg3813/nrg3813-s7.RData')
GENES$groupI<-F
GENES$groupI[ GENES$gene_name %in% rbp[ groupI==T, gene_name] ]<-T
# save for easy access
save(GENES, nb.genes, hb.genes, vt.genes, ame, file='/fast/projects/peifer_wgs/work/work/2017-11-08_Fuchs_totalRNAseq/raw/unified/RBPs_across_tissues_with_motifs_significantly_enriched_in_circRNAs.RData')
# load back
load('/fast/projects/peifer_wgs/work/work/2017-11-08_Fuchs_totalRNAseq/raw/unified/RBPs_across_tissues_with_motifs_significantly_enriched_in_circRNAs.RData')
# recycle
x11(width=25, height=14, title='', bg='white', type='cairo', pointsize=20, antialias='subpixel', family='Arial')
# heatmap on the log2-transformed (best contrast, compared to z-scores of raw CPMs, or z-scores of log2-transformed CPMs)
# clustered by Euclidean distance in NB samples
X<-cbind(log2(1+nb.genes), log2(1+hb.genes), log2(1+vt.genes)) # combine in one matrix
ex<-data.frame(tissue=factor(rep(c('neuroblastoma', 'brain tissue', 'various tumors'), c(ncol(nb.genes), ncol(hb.genes), ncol(vt.genes))), exclude=F), row.names=colnames(X))
cl<-setNames(list(setNames( c('seagreen4', 'cornflowerblue', 'coral4'), c('neuroblastoma', 'brain tissue', 'various tumors') )), colnames(ex))
hc<-hclust(dist(log2(1+nb.genes), method='euclidean'), method='ward.D2') # cluster based on distance between rows for NB only samples
#hc<-hclust(dist(X, method='euclidean'), method='ward.D2')
grid.newpage()
ph<-pheatmap(X, color=viridis(10), border_color=NA, scale='none',
cluster_rows=hc,
cluster_cols=F,
annotation_legend=T, annotation_names_row=F, annotation_names_col=T,
annotation_col=ex, annotation_row=ex, annotation_colors=cl,
drop_levels=F, show_rownames=T, show_colnames=F,
fontsize = 12, fontsize_row=12, fontsize_col=12, fontsize_number=5.0)
grid.force()
dev.print(device=svg, file='/fast/projects/peifer_wgs/work/work/2017-11-08_Fuchs_totalRNAseq/raw/unified/figures/heatmap_RBPs_across_tissues_with_motifs_significantly_enriched_in_circRNAs.svg', width=18, height=14, bg='white', antialias='subpixel', pointsize=20, family='Arial')
rm(X,hc,ex,cl,ph)
# boxplots of log2-transformed CPMs
B<-c(split(log2(1+nb.genes), row(nb.genes)), split(log2(1+hb.genes), row(hb.genes)), split(log2(1+vt.genes), row(vt.genes)))
n<-c(rbind(rbind(1:nrow(nb.genes), nrow(nb.genes)+(1:nrow(nb.genes)), 2*nrow(nb.genes)+(1:nrow(nb.genes))))) # order them in triplets
B<-B[n]
B.cl<-rep(c('seagreen4', 'cornflowerblue', 'coral4'), nrow(nb.genes))
groupI.cl<-setNames(rep('black', nrow(nb.genes)), rownames(nb.genes))
#groupI.cl[ GENES$gene_name[ GENES$groupI ] ]<-'darkorange'
par(mar=c(8.5, 7.0, 0.1, 0.0), mgp=c(3,1,0), oma=c(0,0,0,0), las=1, xpd=NA, bty='n', cex.lab=2.4, cex.axis=2.4)
YTICK<-pretty(c(0, max(ceiling(sapply(B, max)))), 5)
plot(0:1, 0:1, xlim=c(0, length(B))+c(-2, 2), type='n', ylim=range(YTICK), axes=F, ann=F, xaxs='i')
bp<-boxplot(B, col=B.cl, ylab='', xlab='', show.names=F, frame.plot=F, medcol='lightgrey', boxwex=0.8, xpd=F, outline=F, boxcol=B.cl, range=0, add=T)
mtext(expression(log[2](1+'CPM')), side=2, line=3, padj=-0.2, las=0, cex=2.4)
mtext(text=rownames(nb.genes), side=1, line=0, at= seq(2, length(B), 3), las=3, adj=1, cex=1.6, col=groupI.cl)
draw_highlights(L=length(B), STEP=3, YMAX=max(YTICK))
legend('topright', legend=c('neuroblastoma', 'brain tissue', 'various tumors'), col=unique(B.cl), bty='n', lty=1, lwd=15, pch=NA, cex=1.8, xpd=T, y.intersp=0.60, x.intersp=0.2, seg.len=0.2)
dev.print(device=svg, file='/fast/projects/peifer_wgs/work/work/2017-11-08_Fuchs_totalRNAseq/raw/unified/figures/boxplot_RBPs_across_tissues_with_motifs_significantly_enriched_in_circRNAs.svg', width=30, height=14, bg='white', antialias='subpixel', pointsize=20, family='Arial')
rm(YTICK,B,n,B.cl,bp)
#}}}
#
# => /fast/projects/peifer_wgs/work/work/2017-11-08_Fuchs_totalRNAseq/raw/unified/RBPs_across_tissues_with_motifs_significantly_enriched_in_circRNAs.RData
# [circRNA introns] analysis of the AME ATtRACT RBP motif enrichment results
#{{{
rm(list=ls())
library(data.table)
library(pheatmap)
library(viridis)
library(RColorBrewer)
library(extrafont) # first time used need to run: font_import() , to load all for PDF device run: loadfonts(device='pdf')
loadfonts()
source('~/bio/lib/draw_highlights.R')
# load neuroblastoma-specific mRNA of RBPs results
load('/fast/projects/peifer_wgs/work/work/2017-11-08_Fuchs_totalRNAseq/raw/unified/RBPs_across_tissues.RData')
# load AME human RBP motif enrichment result
# identify gene_names from the motif_id
load('/fast/projects/peifer_wgs/work/work/2017-11-08_Fuchs_totalRNAseq/raw/unified/meme/introns/results.RData')
ame[, gene_name:=list(strsplit(sub('_.*$', '', motif_id), ',', fixed=T))]
# RBPs in neuroblastoma with also significant enrichment of their motifs in introns
sig<-intersect(GENES$gene_name, unlist(ame$gene_name))
GENES<-GENES[ GENES$gene_name %in% sig, ]
rownames(GENES)<-NULL
nb.genes<-nb.genes[ GENES$gene_name, ]
hb.genes<-hb.genes[ GENES$gene_name, ]
vt.genes<-vt.genes[ GENES$gene_name, ]
ame<-ame[ sapply(gene_name, function(g){ any(g %in% sig) }), ]
# order by NB expression
n<-order(rowMeans(nb.genes), decreasing=T)
nb.genes<-nb.genes[n, ]
hb.genes<-hb.genes[n, ]
vt.genes<-vt.genes[n, ]
stopifnot( all.equal( rownames(nb.genes), rownames(hb.genes) ) )
stopifnot( all.equal( rownames(nb.genes), rownames(vt.genes) ) )
rm(n)
# identify those classified as groupI in Gerstberger et al. 2014 which are down-regulated upon brain development
load('/fast/projects/peifer_wgs/work/work/2017-11-08_Fuchs_totalRNAseq/validations/rbp/brainspan_census_of_human_RBPs_nrg3813/nrg3813-s7.RData')
GENES$groupI<-F
GENES$groupI[ GENES$gene_name %in% rbp[ groupI==T, gene_name] ]<-T
# save for easy access
save(GENES, nb.genes, hb.genes, vt.genes, ame, file='/fast/projects/peifer_wgs/work/work/2017-11-08_Fuchs_totalRNAseq/raw/unified/RBPs_across_tissues_with_motifs_significantly_enriched_in_introns.RData')
# load back
load('/fast/projects/peifer_wgs/work/work/2017-11-08_Fuchs_totalRNAseq/raw/unified/RBPs_across_tissues_with_motifs_significantly_enriched_in_introns.RData')
# recycle
x11(width=25, height=14, title='', bg='white', type='cairo', pointsize=20, antialias='subpixel', family='Arial')
# heatmap on the log2-transformed (best contrast, compared to z-scores of raw CPMs, or z-scores of log2-transformed CPMs)
# clustered by Euclidean distance in NB samples
X<-cbind(log2(1+nb.genes), log2(1+hb.genes), log2(1+vt.genes)) # combine in one matrix
ex<-data.frame(tissue=factor(rep(c('neuroblastoma', 'brain tissue', 'various tumors'), c(ncol(nb.genes), ncol(hb.genes), ncol(vt.genes))), exclude=F), row.names=colnames(X))
cl<-setNames(list(setNames( c('seagreen4', 'cornflowerblue', 'coral4'), c('neuroblastoma', 'brain tissue', 'various tumors') )), colnames(ex))
hc<-hclust(dist(log2(1+nb.genes), method='euclidean'), method='ward.D2') # cluster based on distance between rows for NB only samples
#hc<-hclust(dist(X, method='euclidean'), method='ward.D2')
grid.newpage()
ph<-pheatmap(X, color=viridis(10), border_color=NA, scale='none',
cluster_rows=hc,
cluster_cols=F,
annotation_legend=T, annotation_names_row=F, annotation_names_col=T,
annotation_col=ex, annotation_row=ex, annotation_colors=cl,
drop_levels=F, show_rownames=T, show_colnames=F,
fontsize = 12, fontsize_row=12, fontsize_col=12, fontsize_number=5.0)
grid.force()
dev.print(device=svg, file='/fast/projects/peifer_wgs/work/work/2017-11-08_Fuchs_totalRNAseq/raw/unified/figures/heatmap_RBPs_across_tissues_with_motifs_significantly_enriched_in_introns.svg', width=18, height=14, bg='white', antialias='subpixel', pointsize=20, family='Arial')
rm(X,hc,ex,cl,ph)
# boxplots of log2-transformed CPMs
B<-c(split(log2(1+nb.genes), row(nb.genes)), split(log2(1+hb.genes), row(hb.genes)), split(log2(1+vt.genes), row(vt.genes)))
n<-c(rbind(rbind(1:nrow(nb.genes), nrow(nb.genes)+(1:nrow(nb.genes)), 2*nrow(nb.genes)+(1:nrow(nb.genes))))) # order them in triplets
B<-B[n]
B.cl<-rep(c('seagreen4', 'cornflowerblue', 'coral4'), nrow(nb.genes))
groupI.cl<-setNames(rep('black', nrow(nb.genes)), rownames(nb.genes))
#groupI.cl[ GENES$gene_name[ GENES$groupI ] ]<-'darkorange'
par(mar=c(8.5, 7.0, 0.1, 0.0), mgp=c(3,1,0), oma=c(0,0,0,0), las=1, xpd=NA, bty='n', cex.lab=2.4, cex.axis=2.4)
YTICK<-pretty(c(0, max(ceiling(sapply(B, max)))), 5)
plot(0:1, 0:1, xlim=c(0, length(B))+c(-2, 2), type='n', ylim=range(YTICK), axes=F, ann=F, xaxs='i')
bp<-boxplot(B, col=B.cl, ylab='', xlab='', show.names=F, frame.plot=F, medcol='lightgrey', boxwex=0.8, xpd=F, outline=F, boxcol=B.cl, range=0, add=T)
mtext(expression(log[2](1+'CPM')), side=2, line=3, padj=-0.2, las=0, cex=2.4)
mtext(text=rownames(nb.genes), side=1, line=0, at= seq(2, length(B), 3), las=3, adj=1, cex=1.6, col=groupI.cl)
draw_highlights(L=length(B), STEP=3, YMAX=max(YTICK))
legend('topright', legend=c('neuroblastoma', 'brain tissue', 'various tumors'), col=unique(B.cl), bty='n', lty=1, lwd=15, pch=NA, cex=1.8, xpd=T, y.intersp=0.60, x.intersp=0.2, seg.len=0.2)
dev.print(device=svg, file='/fast/projects/peifer_wgs/work/work/2017-11-08_Fuchs_totalRNAseq/raw/unified/figures/boxplot_RBPs_across_tissues_with_motifs_significantly_enriched_in_introns.svg', width=40, height=14, bg='white', antialias='subpixel', pointsize=20, family='Arial')
rm(YTICK,B,n,B.cl,bp)
#}}}
#
# => /fast/projects/peifer_wgs/work/work/2017-11-08_Fuchs_totalRNAseq/raw/unified/RBPs_across_tissues_with_motifs_significantly_enriched_in_introns.RData
# [circRNAs+introns, FIMO results] distributions of non-overlapping RBP motif counts and count densities per 1kb of cumulative sequence
# correlation of non-overlapping RBP motif counts and circRNA lengths
# distribution comparison of non-overlapping RBP motif count densities per 1kb of cumulative sequence
# enrichment of repeat elements in introns
#{{{
rm(list=ls())
library(GenomicAlignments)
library(rtracklayer)
library(data.table)
library(pheatmap)
library(viridis)
library(grid)
library(RColorBrewer)
library(topGO)
library(org.Hs.eg.db)
library(extrafont) # first time used need to run: font_import() , to load all for PDF device run: loadfonts(device='pdf')
loadfonts()
source('~/bio/lib/draw_highlights.R')
# load FIMO results
load('/fast/projects/peifer_wgs/work/work/2017-11-08_Fuchs_totalRNAseq/raw/unified/meme/results.RData')
circs.fimo<-fimo
circs.fimo.all<-fimo.all
circs.fimo.control<-fimo.control
circs.fimo.control.all<-fimo.control.all
rm(fimo, fimo.all, fimo.control, fimo.control.all)
# load FIMO human non-overlapping RBP motif counts
# recompute intron motif densities for cumulative intron sequences and counts (upstream + downstream for circRNAs, all control introns for controls)
load('/fast/projects/peifer_wgs/work/work/2017-11-08_Fuchs_totalRNAseq/raw/unified/meme/introns/results.RData')
introns.fimo<-fimo
introns.fimo.all<-fimo.all
introns.fimo.control<-fimo.control
introns.fimo.control.all<-fimo.control.all
introns.fimo<-introns.fimo[, .(rbp_group=list(unique(unlist(rbp_group))), ncount=sum(ncount, na.rm=T), length=sum(length, na.rm=T)), by=.(circ_name)][, density:=ncount/length*1e3]
introns.fimo.control<-introns.fimo.control[, .(rbp_group=list(unique(unlist(rbp_group))), ncount=sum(ncount, na.rm=T), length=sum(length, na.rm=T)), by=.(circ_name)][, density:=ncount/length*1e3]
rm(fimo, fimo.all, fimo.control, fimo.control.all)
gc()
# load circRNA exon and intron GRanges
l<-ls()
load('/fast/projects/peifer_wgs/work/work/2017-11-08_Fuchs_totalRNAseq/raw/unified/circRNAs_sequences.RData')
circs.exons<-CIRCS.exons
circs.exons.control<-CIRCS.controls
load('/fast/projects/peifer_wgs/work/work/2017-11-08_Fuchs_totalRNAseq/raw/unified/circRNAs_introns.RData')
circs.introns<-c(CIRCS.introns.up, CIRCS.introns.down)
circs.introns.controls<-CIRCS.controls.introns
rm(list=setdiff(ls(), c(l, 'circs.exons', 'circs.exons.control', 'circs.introns', 'circs.introns.controls')))
# import RepeatMasker annotations
#
# TRF : Tandem Repeat Finder
#
# N.B. annotations overlap but we are going to keep all hits since they are anyway valid even for identical types, e.g.
# if a TRF simple repeat overlaps with another within an intron range then this should count as two hits, not one.
#
# This is not the same as in the RBP motif analysis where the RBP footprint ought to be taken into consideration rendering
# overlapping motifs practically impossible to be simultaneously bound.
#
rpmk<-import('/fast/groups/ag_schulte/work/reference/annotation/GRCh38/rpmk+simple_repeats.gtf')
seqlevels(rpmk, pruning.mode='coarse')<-seqlevels(unlist(circs.exons))
# circRNAs basic analysis
#{{{
# correlation of number of non-overlapping RBP motifs and circRNA length
circs.fimo[, cor(ncount, length, method='pearson')] # 0.9817346438
circs.fimo.control[, cor(ncount, length, method='pearson')] # 0.9731943631
# explore the circRNAs-RBP pairs with no motifs found in the corresponding control sequences
#{{{