-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path3_DEanalysis.R
5096 lines (3887 loc) · 248 KB
/
3_DEanalysis.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
#
###############################################################################################################
##################################################
#
#
# clustering
# differential expression analysis
# GSEA
#
#
##################################################
# Vermeulen et al. The Lancet Oncology (2009) list of prognostic gene set
#{{{
rm(list=ls())
library(GenomicFeatures)
library(rtracklayer)
library(data.table)
library(DESeq2)
library(pheatmap)
library(ggplot2)
library(ggrepel)
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')
# [run once] create list of prognostic genes by manually copying and pasting the Table from the SI
# get the corresponding circRNA/mRNA expression in the neuroblastoma tumors
#{{{
source('/fast/projects/peifer_wgs/work/work/2017-11-08_Fuchs_totalRNAseq/lib/load_circ_gene_expression.R')
# load reference to resolve gene_ids
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_name', 'gene_type')]
verm<-data.frame(gene_name=c('AHCY', 'AKR1C1', 'ARHGEF7', 'BIRC5', 'CADM1', 'CAMTA1', 'CAMTA2', 'CD44', 'CDCA5', 'CDKN3', 'CHD5', 'CLSTN1', 'CPSG3', 'DDC', 'DPYSL3', 'ECEL1', 'ELAVL4', 'EPB41L3', 'EPHA5', 'EPN2', 'FYN', 'GNB1', 'HIVEP2', 'INPP1', 'MAP2K4', 'MAP7', 'MAPT', 'MCM2', 'MRPL3', 'MTSS1', 'MYCN', 'NHLH2', 'NME1', 'NRCAM', 'NTRK1', 'ODC1', 'PAICS', 'PDE4DIP', 'PIK3R1', 'PLAGL1', 'PLAT', 'PMP22', 'PRAME', 'PRDM2', 'PRKACB', 'PRKCZ', 'PTN', 'PTPRF', 'PTPRH', 'PTPRN2', 'QPCT', 'SCG2', 'SLC25A5', 'SLC6A8', 'SNAPC1', 'TNFRSF25', 'TYMS', 'ULK2', 'WSB1'), risk_group_up=c('HR', 'LR', 'LR', 'HR', 'LR', 'LR', 'LR', 'LR', 'HR', 'HR', 'LR', 'LR', 'HR', 'LR', 'LR', 'LR', 'LR', 'LR', 'LR', 'LR', 'LR', 'LR', 'LR', 'LR', 'LR', 'LR', 'LR', 'HR', 'HR', 'LR', 'HR', 'HR', 'HR', 'LR', 'LR', 'HR', 'HR', 'LR', 'LR', 'LR', 'LR', 'LR', 'HR', 'LR', 'LR', 'LR', 'LR', 'LR', 'LR', 'LR', 'LR', 'LR', 'HR', 'HR', 'HR', 'LR', 'HR', 'LR', 'LR'))
# CPSG3 (NM_004386) is actually NCAN
setdiff(verm$gene_name, hsa$gene_name)
verm$gene_name[ verm$gene_name %in% 'CPSG3' ]<-'NCAN'
# add gene_ids
verm$gene_id<-hsa$gene_id[ match(verm$gene_name, hsa$gene_name) ]
verm<-verm[, c('gene_id', 'gene_name', 'risk_group_up')]
# load unified set of circRNAs
# limit genes to those of the Vermeulen geneset, the gene list is defined irrespective of whether a circRNA exists in the unified group of circRNAs
# load mRNA expression in TPMs and compute circRNA CPMs
load('/fast/projects/peifer_wgs/work/work/2017-11-08_Fuchs_totalRNAseq/raw/unified/circRNAs_across_tissues.RData')
GENES<-DataFrame( verm[, c('gene_id', 'gene_name')] )
CIRCS<-CIRCS[ CIRCS$gene_id %in% verm$gene_id ]
length(CIRCS) # 45 circRNAs
length(unique(CIRCS$gene_id)) # 18 genes
l<-load_circ_gene_expression(CIRCS, GENES, META=nb.meta, nb.tumors.only=T, nb.only=T, gene.tpm=T)
nb.meta<-l$meta
nb.meta<-nb.meta[, risk_group:=factor(risk_group, levels=c('ST4S', 'LR', 'IMR', 'HR_nMNA', 'MNA'))][ order(risk_group), ][, risk_group:=as.character(risk_group)]
nb.circs<-l$circs
nb.genes<-l$genes
stopifnot( length(setdiff( GENES$gene_id, rownames(l$counts) ))==0 )
nb.counts<-l$counts[ GENES$gene_id, ] # (genes x samples) matrix order (do not convert gene_id to gene_name because there are duplicates!)
rm(list=c('l','CIRCS.all','GENES',ls(pattern='vt.|hb.')))
# save
save(verm, nb.meta, nb.circs, nb.genes, nb.counts, CIRCS, file='/fast/projects/peifer_wgs/work/work/2017-11-08_Fuchs_totalRNAseq/raw/Vermeulen et al_prognostic_geneset.RData')
#}}}
# load the gene set and the circRNA/mRNA expression
load('/fast/projects/peifer_wgs/work/work/2017-11-08_Fuchs_totalRNAseq/raw/Vermeulen et al_prognostic_geneset.RData')
# [genes, log10-transformed TPMs, all risk groups] boxplot of LR-up and HR-up genes
#{{{
# split by risk group
nb.<-split(nb.genes[, ! colnames(nb.genes) %in% c('risk_group', 'cell_model', 'tissue')], nb.genes$risk_group)
l.LR<-lapply(nb., function(x){ log10(1+unname(unlist(c(x[, colnames(x) %in% verm$gene_name[ verm$risk_group_up %in% 'LR' ]])))) })
l.HR<-lapply(nb., function(x){ log10(1+unname(unlist(c(x[, colnames(x) %in% verm$gene_name[ verm$risk_group_up %in% 'HR' ]])))) })
l.LR<-l.LR[ unique(nb.meta$risk_group) ]
l.HR<-l.HR[ unique(nb.meta$risk_group) ]
L<-append(l.LR, l.HR)
# boxplot
x11(width=18, height=14, title='', bg='white', type='cairo', pointsize=20, antialias='subpixel', family='Arial')
par(mar=c(5.0, 7.0, 0.5, 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)
options(scipen=0)
YTICK<-pretty(c(0, max(ceiling(sapply(L, max, na.rm=T)))), 4)
plot(0:1, 0:1, xlim=c(0, length(L))+c(0.5, 0.5), type='n', ylim=range(YTICK), axes=F, ann=F, xaxs='i')
bp<-boxplot(L, col=unique(nb.meta$col), ylab='', xlab='', show.names=F, frame.plot=F, medcol='lightgrey', boxwex=0.8, xpd=F, outline=F, boxcol=unique(nb.meta$col), range=0, add=T)
mtext(expression(log[10](1+TPM)), side=2, line=2, padj=-0.5, las=0, cex=2.4)
mtext(text=c('LR-up', 'HR-up'), side=1, line=1, at=seq(median(seq_along(l.LR)), length(L), length(l.LR)), las=1, adj=0.5, cex=2.4, col='black')
mtext(text=c(paste0('(', table(verm$risk_group_up)['LR'], ')'), paste0('(', table(verm$risk_group_up)['HR'], ')')), side=1, line=3, at=seq(median(seq_along(l.LR)), length(L), length(l.LR)), las=1, adj=0.5, cex=2.4, col='black')
draw_highlights(L=length(L), STEP=length(l.LR), YMAX=max(YTICK))
legend('topleft', legend=names(l.LR), col=unique(nb.meta$col), bty='n', lty=1, lwd=15, pch=NA, cex=1.8, xpd=T, y.intersp=0.60, x.intersp=0.2, seg.len=0.5)
dev.print(device=svg, file='/fast/projects/peifer_wgs/work/work/2017-11-08_Fuchs_totalRNAseq/raw/unified/figures/boxplot_Vermeulen et al_prognostic_geneset_gene_TPMs.svg', width=18, height=14, bg='white', antialias='subpixel', pointsize=20, family='Arial')
# clean up
dev.off()
#}}}
# [genes] hierarchical clustering and PCA
#{{{
# round up gene counts of all genes to integers and variance-stabilize them
stopifnot( length(setdiff(colnames(nb.counts), nb.meta$bid))==0 )
dds<-DESeqDataSetFromMatrix(countData=as.matrix(ceiling(nb.counts[, nb.meta$bid])), colData=data.frame(Risk=factor(nb.meta$risk_group), row.names=nb.meta$bid), design=~Risk)
nb.sf<-sizeFactors(estimateSizeFactors(dds, type='poscounts'))
nb.vs<-assay(varianceStabilizingTransformation(dds, fitType='local', blind=T))
rm(dds,nb.sf)
# select the genes of interest and convert gene_id to gene_name
stopifnot( length(setdiff(verm$gene_id, rownames(nb.vs)))==0 )
nb.vs<-nb.vs[ verm$gene_id, ]
rownames(nb.vs)<-verm$gene_name[ match(rownames(nb.vs), verm$gene_id) ]
# recycle
x11(width=14, height=12, title='', bg='white', type='cairo', pointsize=20, antialias='subpixel', family='Arial')
ex<-data.frame(Risk=factor(nb.meta[ match(colnames(nb.vs), bid), risk_group], exclude=F), row.names=colnames(nb.vs))
cl<-setNames(list(setNames( nb.meta[, unique(col)], nb.meta[, unique(risk_group)] )), colnames(ex))
# [log10-transformed TPMs] clustering based on Spearman correlations of complete pairs
x<-log10(1+t(nb.genes[, ! colnames(nb.genes) %in% c('risk_group', 'cell_model', 'tissue')]))
stopifnot( length(setdiff(colnames(x), colnames(nb.vs)))==0 )
x<-x[, colnames(nb.vs)]
d<-cor(x, method='spearman', use='pairwise.complete.obs')
hc<-hclust(as.dist(1-d), method='ward.D2')
ph<-pheatmap(as.matrix(d), color=rev(colorRampPalette(brewer.pal(9,'RdBu'))(20)), border_color=NA, scale='none',
breaks=seq(0, 1, length.out=21), # reduced range
cluster_rows=hc,
cluster_cols=hc,
#cutree_row=4, cutree_col=4,
annotation_legend=T, annotation_names_row=T, annotation_names_col=T,
annotation_col=ex, annotation_row=ex, annotation_colors=cl,
drop_levels=F, show_rownames=F, show_colnames=F,
#display_numbers=T, number_format='%.1f', number_color='grey39',
fontsize=18, fontsize_row=18, fontsize_col=18, fontsize_number=10)
dev.print(device=svg, file='/fast/projects/peifer_wgs/work/work/2017-11-08_Fuchs_totalRNAseq/raw/unified/figures/heatmap_Vermeulen et al_prognostic_geneset_genes_tpm_cor.svg', width=20, height=16, bg='white', antialias='subpixel', pointsize=20, family='Arial')
rm(x)
# [variance-stabilized counts] clustering based on Euclidean distance
d<-dist(t(nb.vs), method='euclidean')
hc<-hclust(d, method='ward.D2')
ph<-pheatmap(as.matrix(d), color=colorRampPalette(brewer.pal(9,'GnBu'))(20), border_color=NA, scale='none',
cluster_rows=hc,
cluster_cols=hc,
#cutree_row=4, cutree_col=4,
annotation_legend=T, annotation_names_row=T, annotation_names_col=T,
annotation_col=ex, annotation_row=ex, annotation_colors=cl,
drop_levels=F, show_rownames=F, show_colnames=F,
#display_numbers=T, number_format='%.1f', number_color='grey39',
fontsize=18, fontsize_row=18, fontsize_col=18, fontsize_number=10)
dev.print(device=svg, file='/fast/projects/peifer_wgs/work/work/2017-11-08_Fuchs_totalRNAseq/raw/unified/figures/heatmap_Vermeulen et al_prognostic_geneset_genes_vsc.svg', width=20, height=16, bg='white', antialias='subpixel', pointsize=20, family='Arial')
# [variance-stabilized counts] PCA centered but not scaled
p<-prcomp(t(nb.vs), center=T, scale.=F) # PCA on the samples is done when the samples are the rows
ve<-round(100*p$sdev^2/sum(p$sdev^2), 1)
pca<-as.data.frame(p$x)
pca$'risk group'<-nb.meta[ match( rownames(pca), bid ), risk_group ]
XLIM<-pretty(range(p$x[, 'PC1']), 5)
XLIM<-c(XLIM[1], XLIM[length(XLIM)])
YLIM<-pretty(range(p$x[, 'PC2']), 5)
YLIM<-c(YLIM[1], YLIM[length(YLIM)])
ggplot(pca[, c('PC1', 'PC2', 'risk group')], aes(PC1, PC2, color=`risk group`)) +
geom_point(size=10) +
#geom_text_repel(aes(label=rownames(pca)), size=10, box.padding=0.5, segment.size=1.0, min.segment.length=1.0) +
scale_shape_manual(values=c(18:21)) +
scale_fill_manual(name='risk group', values=cl$Risk) +
scale_color_manual(name='risk group', values=cl$Risk) +
theme(text=element_text(family='Arial'), axis.text.x=element_text(size=34, color='black'), axis.title.x=element_text(size=34),
axis.text.y=element_text(size=34, color='black'), axis.title.y=element_text(size=34),
legend.text=element_text(size=22), legend.title=element_text(size=22, face='plain'),
aspect.ratio=1, panel.background = element_blank(),
axis.line.x=element_line(size=0.5, colour = 'black', linetype='solid'),
axis.line.y=element_line(size=0.5, colour = 'black', linetype='solid'),
panel.grid.major = element_blank(), panel.grid.minor = element_blank()) +
scale_x_continuous(lim=XLIM, breaks=pretty(XLIM,5)) +
scale_y_continuous(lim=YLIM, breaks=pretty(YLIM,5)) +
xlab(paste0('PC1: ', ve[1], '% variance')) + ylab(paste0('PC2: ', ve[2], '% variance'))
dev.print(device=svg, file='/fast/projects/peifer_wgs/work/work/2017-11-08_Fuchs_totalRNAseq/raw/unified/figures/plotPCA_Vermeulen et al_prognostic_geneset_genes_vsc.svg', width=16, height=16, bg='white', antialias='subpixel', pointsize=20, family='Arial')
dev.off()
#}}}
# [circRNAs, log10-transformed CPMs, all risk groups] boxplot of LR-up and HR-up genes
#{{{
# split by risk group
x<-as.data.table(as.data.frame(mcols(nb.circs)[, c('bid', 'circ_name', 'cpm')]))
x<-dcast(x, bid ~ circ_name, value.var='cpm', fun.aggregate=sum)
y<-as.data.frame(x[, -1])
rownames(y)<-x[, bid]
stopifnot( length(setdiff(rownames(y), rownames(nb.genes)))==0 )
x<-y[ rownames(nb.genes), ]
LRcircs<-colnames(x)[grep(paste0(verm$gene_name[ verm$risk_group_up %in% 'LR' ], collapse='|'), colnames(x))]
HRcircs<-colnames(x)[grep(paste0(verm$gene_name[ verm$risk_group_up %in% 'HR' ], collapse='|'), colnames(x))]
stopifnot( length(LRcircs)+ length(HRcircs)==ncol(x) )
nb.<-split(x, nb.genes$risk_group)
l.LR<-lapply(nb., function(x){ log10(1+unname(unlist(c(x[, LRcircs])))) })
l.HR<-lapply(nb., function(x){ log10(1+unname(unlist(c(x[, HRcircs])))) })
l.LR<-l.LR[ unique(nb.meta$risk_group) ]
l.HR<-l.HR[ unique(nb.meta$risk_group) ]
L<-append(l.LR, l.HR)
# boxplot
x11(width=18, height=14, title='', bg='white', type='cairo', pointsize=20, antialias='subpixel', family='Arial')
par(mar=c(5.0, 10.0, 0.5, 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)
options(scipen=0)
#YTICK<-pretty(c(0, max(ceiling(sapply(L, max, na.rm=T)))), 4)
YTICK<-pretty(c(0, 0.2), 4)
plot(0:1, 0:1, xlim=c(0, length(L))+c(0.5, 0.5), type='n', ylim=range(YTICK), axes=F, ann=F, xaxs='i')
bp<-boxplot(L, col=unique(nb.meta$col), ylab='', xlab='', show.names=F, frame.plot=F, medcol='lightgrey', boxwex=0.8, xpd=F, outline=F, boxcol=unique(nb.meta$col), range=0, add=T)
mtext(expression(log[10](1+CPM)), side=2, line=5, padj=-0.5, las=0, cex=2.4)
mtext(text=c('LR-up', 'HR-up'), side=1, line=1, at=seq(median(seq_along(l.LR)), length(L), length(l.LR)), las=1, adj=0.5, cex=2.4, col='black')
mtext(text=c(paste0('(', table(verm$risk_group_up)['LR'], ')'), paste0('(', table(verm$risk_group_up)['HR'], ')')), side=1, line=3, at=seq(median(seq_along(l.LR)), length(L), length(l.LR)), las=1, adj=0.5, cex=2.4, col='black')
draw_highlights(L=length(L), STEP=length(l.LR), YMAX=max(YTICK), YMIN=0.0)
legend('topleft', legend=names(l.LR), col=unique(nb.meta$col), bty='n', lty=1, lwd=15, pch=NA, cex=1.8, xpd=T, y.intersp=0.60, x.intersp=0.2, seg.len=0.5)
#dev.print(device=pdf, file='/fast/projects/peifer_wgs/work/work/2017-11-08_Fuchs_totalRNAseq/raw/unified/figures/boxplot_Vermeulen et al_prognostic_geneset_circRNAs_CPMs.pdf', width=18, height=14, bg='white', colormodel='cmyk', pointsize=20, useDingbats=F, family='Arial')
dev.print(device=svg, file='/fast/projects/peifer_wgs/work/work/2017-11-08_Fuchs_totalRNAseq/raw/unified/figures/boxplot_Vermeulen et al_prognostic_geneset_circRNAs_CPMs.svg', width=18, height=14, bg='white', antialias='subpixel', pointsize=20, family='Arial')
dev.off()
#}}}
#}}}
#
# => /fast/projects/peifer_wgs/work/work/2017-11-08_Fuchs_totalRNAseq/raw/Vermeulen et al_prognostic_geneset.RData
# [run once] Prepare circRNAs and genes for the analysis. We compute:
#
# gene TPMs, raw counts and variance-stabilized log2-transformed counts
# circRNA raw counts and variance-stabilized log2-transformed counts based on size factors computed from gene counts
#
# PCA for genes and circRNAs is done THROUGHOUT TUMORS AND CELL LINES using centered but not scaled variance-stabilized
# (and log2-transformed) counts
#
#{{{
rm(list=ls())
library(GenomicAlignments)
library(rtracklayer)
library(data.table)
library(DESeq2)
library(vsn)
library(RColorBrewer)
library(gplots)
library(ggplot2)
library(pheatmap)
library(openxlsx)
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_circ_gene_expression.R')
# load reference
# discard chrM/chrY genes from the analysis
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')]
seqlevels(hsa, pruning.mode='coarse')<-seqlevels(hsa)[ grep('chrM|chrY', seqlevels(hsa), invert=T) ]
# remove failed samples and Pilot samples
load('/fast/projects/peifer_wgs/work/work/2017-11-08_Fuchs_totalRNAseq/raw/metadata.RData')
meta<-rbind(meta.tum, meta.cel, fill=T)
meta<-meta[ !(failed) & !grepl('CBPilote', bid) ]
# add sex metadata to the tumor samples
#load('/fast/projects/peifer_wgs/work/work/2017-11-08_Fuchs_totalRNAseq/raw/sex_determination.RData')
#meta<-sex[ meta, on='bid'][, -c(1:3)]
#rm(sex)
#
# N.B. latest clinical annotation includes sex besides for CB3009 which we find it to be male
meta[, sex:=SEX][, SEX:=NULL]
meta[ PAT_ID_BERLIN %in% 'CB3009', sex:='M' ]
# load our cohort of circRNAs
load('/fast/projects/peifer_wgs/work/work/2017-11-08_Fuchs_totalRNAseq/raw/unified/circRNAs_across_tissues.RData')
rm(list=ls(pattern='\\.(genes|circs|meta|prefailed|all)|GENES'))
# circRNA counts and gene counts (for all genes) + TPMs (for the selected genes)
# make sure the correct samples are kept throughout
nb<-load_circ_gene_expression(CIRCS=CIRCS, GENES=mcols(hsa)[, c('gene_id', 'gene_name')], META=meta, nb.tumors.only=F, nb.only=T, gene.tpm=T)
circ<-nb$circs[ nb$circs$bid %in% meta$bid ]
gns.tpm<-t(nb$genes[ meta$bid, grep('risk_group|cell_model|tissue', colnames(nb$genes), invert=T)])
stopifnot( length(setdiff(hsa$gene_id, rownames(nb$counts)))==0 )
gns.cnt<-ceiling(nb$counts[hsa$gene_id, meta$bid]) # remove chrM, chrY counts, the resulting matrix form is: (gene_id X sample)
rm(nb)
# remove unexpressed genes
gns.cnt<-gns.cnt[rowSums(gns.cnt)!=0, ]
gns.tpm<-gns.tpm[rowSums(gns.tpm)!=0, ]
# compute size factors across all samples (tumors and cell lines)
# compute variance-stabilized gene counts
dds<-DESeqDataSetFromMatrix(countData=gns.cnt, colData=data.frame(risk_group=factor(meta$risk_group), cell_model=factor(meta$cell_model), row.names=meta$bid), design=~1)
gns.sf<-sizeFactors(estimateSizeFactors(dds, type='poscounts'))
gns.vs<-assay(varianceStabilizingTransformation(dds, fitType='local'))
rm(dds)
# PCA on variance-stabilized (and glog2-transformed) gene counts centered but not scaled
gns.pca<-prcomp(t(gns.vs), center=T, scale.=F)
gns.ve<-round(1000 * gns.pca$sdev^2/sum(gns.pca$sdev^2))/10
# CHECK: compute size factors across tumors
# compute variance-stabilized gene counts for the tumors
#
#{{{
#m<-meta[ !(failed) & !is.na(risk_group) ]
#g<-gns.cnt[, m$bid]
#dds<-DESeqDataSetFromMatrix(countData=g, colData=data.frame(risk_group=factor(m$risk_group), row.names=m$bid), design=~1)
#gns.sf.tumors<-sizeFactors(estimateSizeFactors(dds, type='poscounts'))
#gns.vs.tumors<-assay(varianceStabilizingTransformation(dds, fitType='local'))
#rm(dds)
# how different are the tumor sizefactors between the methods?
#x<-gns.sf[ names(gns.sf.tumors) ]
#y<-gns.sf.tumors
#summary(x-y)
#
# Min. 1st Qu. Median Mean 3rd Qu. Max.
# -0.07566 -0.01798 -0.00850 -0.00619 0.00501 0.04903
# PCA on variance-stabilized (and glog2-transformed) gene counts centered but not scaled
#gns.pca.tumors<-prcomp(t(gns.vs.tumors), center=T, scale.=F)
#gns.ve.tumors<-round(1000 * gns.pca.tumors$sdev^2/sum(gns.pca$sdev^2))/10
#}}}
# summarize circRNA counts at the gene level
# force size factors to be those based from gene counts
# variance-stabilize
# PCA on variance-stabilized (and glog2-transformed) counts centered by not scaled
crs.cnt<-data.table(data.frame(mcols(circ)[, c('gene_id', 'jc_count', 'bid')]))[, .(jc_count=sum(jc_count)), by=.(bid, gene_id)]
crs.cnt<-dcast(crs.cnt, bid ~ gene_id, value.var='jc_count', fun.aggregate=sum)
crs.cnt<-t(as.matrix(data.frame(crs.cnt[, -1], row.names=crs.cnt$bid, check.names=F)))[, meta$bid]
dds<-DESeqDataSetFromMatrix(countData=crs.cnt, colData=data.frame(risk_group=factor(meta$risk_group), cell_model=factor(meta$cell_model), row.names=meta$bid), design=~1)
sizeFactors(dds)<-gns.sf
crs.vs<-assay(varianceStabilizingTransformation(dds, fitType='local'))
crs.pca<-prcomp(t(crs.vs), center=T, scale.=F)
crs.ve<-round(1000 * crs.pca$sdev^2/sum(crs.pca$sdev^2))/10
rm(dds,circ)
# save all including the reference for convenience
save(list=c('hsa', ls(pattern='(gns|crs)\\.'), 'meta', 'CIRCS'), file='/fast/projects/peifer_wgs/work/work/2017-11-08_Fuchs_totalRNAseq/raw/unified/DESeq2_circRNAs+genes_all_libraries.RData')
#}}}
#
# => /fast/projects/peifer_wgs/work/work/2017-11-08_Fuchs_totalRNAseq/raw/unified/DESeq2_circRNAs+genes_all_libraries.RData
# [tumors + cell lines] clustering
# DESeq2 analysis
#{{{
rm(list=ls())
library(GenomicAlignments)
library(rtracklayer)
library(data.table)
library(DESeq2)
library(vsn)
library(RColorBrewer)
library(gplots)
library(ggplot2)
library(ggrepel)
library(pheatmap)
library(openxlsx)
library(extrafont) # first time used need to run: font_import() , to load all for PDF device run: loadfonts(device='pdf')
loadfonts()
# functions
#{{{
gene_results<-function(res=NULL, annot=NULL){
m<-res[ intersect(annot$gene_id, rownames(res)), c('baseMean', 'log2FoldChange')]
m$gene_name<-annot$gene_name[ match( rownames(m), annot$gene_id ) ]
m$col<-annot$col[ match( rownames(m), annot$gene_id ) ]
return(m)
}
do_deseq2<-function(DDS, CT, Type='', condition='Risk', lfcThreshold=0.0, lfcShrinkType='apeglm', include.annot=F, names.trim, ...){
# DDS = DESeqDataSet object of samples belonging to two conditions
# CT = metadata data.frame of only samples belonging to the two conditions
# Type = 'genes' or 'circRNAs' to add to figure/data names when saved
# condition = CT metadata column to use that defines the two conditions so we can look up the corresponding colors
# lfcThreshold = lfcThreshold to use in DESeq2
# lfcShrinkType = which method to use to estimate shrunken MAP log2FC?
# include.annot = shall we annotate special genes in the MAplot?
# names.trim = regular expression to use to trim sample names when plotting, e.g. '-11-R01$', pass '' for no trimming
# N.B. you NEED to define this if you pass down unnamed arguments with ...
# ... = list of plotting parameters for par() and for the y-axis mtext to pass down when doing the MA-plot
# save open graphics devices by start
#DEV_START<-dev.list()
# variance stabilizing transformation including normalization by library size factors glog2-transformed back to counts
VSC<-assay(varianceStabilizingTransformation(DDS, fitType='local', blind=T))
# remove genes that have identical expression throughout the samples
VSC<-VSC[ apply(VSC, 1, function(x){ any(x!=x[1]) }), ]
# PCA on variance-stabilized (and glog2-transformed) counts centered but not scaled
PCA<-prcomp(t(VSC), center=T, scale.=F) # PCA on the samples is done when the samples are the rows
VE<-round(1000 * PCA$sdev^2/sum(PCA$sdev^2))/10
stopifnot( all(rownames(PCA$x)==colnames(VSC)) )
PCA$x<-cbind(PCA$x, CT)
# differential expression analysis
# use Cook's distance to flag outliers but do not replace their values
DDS<-DESeq(DDS, fitType='local', minReplicatesForReplace=Inf, betaPrior=F)
RES<-results(DDS, alpha=0.05, lfcThreshold=lfcThreshold, altHypothesis='greaterAbs', cooksCutoff=T)
RES<-lfcShrink(dds=DDS, coef=tail(resultsNames(DDS), 1), res=RES, type=lfcShrinkType)
RES<-RES[ order(RES$padj, decreasing=F), ]
CND<-paste0(rev(levels(colData(DDS)[, condition])), collapse=' vs ')
x11()
plotDispEsts(DDS) # just to see
dev.off()
# add gene_names
RES$gene_name<-hsa$gene_name[ match(rownames(RES), hsa$gene_id) ]
# MA-plot
x11(width=16, height=16, title='', bg='white', type='cairo', pointsize=20, antialias='subpixel', family='Arial')
YLIM<-pretty(range(RES$log2FoldChange, na.rm=T))
YLIM<-c(YLIM[1], tail(YLIM, 1))
XLIM<-pretty(range(RES$baseMean, na.rm=T), 5)
XLIM<-c(0.1, tail(XLIM, 1))
if(...length()>0){
dots<-list(...)[[1]] # it is already a list
par(dots$par)
YLAB.LINE<-dots$ylab.line
} else {
par(mar=c(5.0, 7.0, 1.0, 2.5), mgp=c(3,1,0), oma=c(0,0,0,0), las=1, xpd=F, bty='n', cex.lab=2.4, cex.axis=2.4, tcl=-0.2)
YLAB.LINE<-3
}
options(scipen=+20)
plotMA(RES, xlab='', ylab='', main='', ylim=YLIM, xlim=XLIM, cex=1.2, colSig='red3')
mtext(CND, side=3, line=0, padj=+1.5, cex=1.4)
mtext(expression(log[2]('fold change')), side=2, line=YLAB.LINE, padj=-0.2, cex=2.4, las=3)
mtext('Mean expression', side=1, line=4, padj=-0.3, cex=2.4, las=1)
if (include.annot){
r<-gene_results(RES, annot)
points(r$baseMean , r$log2FoldChange, pch=21, lwd=6, col='black', bg=r$col, cex=1.4)
legend('bottomright', legend=r$gene_name, bty='n', lty=0, lwd=0, pch=21, col='black', pt.bg=r$col, pt.cex=1.8, pt.lwd=4, cex=1.2, x.intersp=-0.4, y.intersp=0.4)
}
if(lfcThreshold>0){
abline(h=c(-lfcThreshold, lfcThreshold), lty=1, lwd=4, col='cyan4')
}
#identify(RES$baseMean, RES$log2FoldChange, labels=RES$gene_name, cex=0.7, offset=0.2, xpd=T)
dev.print(device=svg, file=paste0('/fast/projects/peifer_wgs/work/work/2017-11-08_Fuchs_totalRNAseq/raw/unified/figures/plotMA_', Type, '_', sub(' vs ', '_', CND), '.svg'), width=16, height=16, bg='white', antialias='subpixel', pointsize=20, family='Arial')
rm(YLIM,XLIM)
dev.off()
# mean-sd plots to see if variance strongly depends on mean
X11(width=12, height=12, title='', bg='white', type='cairo', pointsize=20, antialias='subpixel', family='Arial')
par(mar=c(5,4,0.1,0.5), mgp=c(3,1,0), oma=c(0,0,0,0), las=1, xpd=F, bty='n', cex.lab=1.4, cex.axis=1.4)
meanSdPlot(VSC)
dev.print(device=svg, file=paste0('/fast/projects/peifer_wgs/work/work/2017-11-08_Fuchs_totalRNAseq/raw/unified/figures/meanSD_', Type, '_', sub(' vs ', '_', CND), '.svg'), width=14, height=14, bg='white', antialias='subpixel', pointsize=20, family='Arial')
dev.off()
# heatmap based on Euclidean distances of variance stabilized (and glog2-transformed) normalized counts
x11(width=14, height=12, title='', bg='white', type='cairo', pointsize=20, antialias='subpixel', family='Arial')
v<-VSC
ex<-as.data.frame(colData(DDS)[, condition, drop=F])
stopifnot( all.equal( rownames(ex), rownames(CT) ) )
cl<-setNames(list(setNames( unique(CT$col), unique(CT[, condition, drop=T]) )), colnames(ex))
if(names.trim!=''){
colnames(v)<-sub(names.trim, '', colnames(v))
rownames(ex)<-sub(names.trim, '', rownames(ex))
}
d<-dist(t(v), method='euclidean')
hc<-hclust(d, method='ward.D2')
ph<-pheatmap(as.matrix(d), color=colorRampPalette(brewer.pal(9,'GnBu'))(20), border_color=NA, scale='none',
cluster_rows=hc,
cluster_cols=hc,
#cutree_row=4, cutree_col=4,
annotation_legend=T, annotation_names_row=T, annotation_names_col=T,
annotation_col=ex, annotation_row=ex, annotation_colors=cl,
drop_levels=F, show_rownames=T, show_colnames=T,
display_numbers=T, number_format='%.1f', number_color='grey39',
fontsize=18, fontsize_row=18, fontsize_col=18, fontsize_number=10)
dev.print(device=svg, file=paste0('/fast/projects/peifer_wgs/work/work/2017-11-08_Fuchs_totalRNAseq/raw/unified/figures/heatmap_', Type, '_vsc_', sub(' vs ', '_', CND), '.svg'), width=16, height=16, bg='white', antialias='subpixel', pointsize=20, family='Arial')
rm(v,d,cl,ex,hc,ph)
dev.off()
# heatmap based on Spearman correlations of raw counts
x11(width=14, height=12, title='', bg='white', type='cairo', pointsize=20, antialias='subpixel', family='Arial')
a<-assay(DDS)
ex<-as.data.frame(colData(DDS)[, condition, drop=F])
stopifnot( all.equal( rownames(ex), rownames(CT) ) )
cl<-setNames(list(setNames( unique(CT$col), unique(CT[, condition, drop=T]) )), colnames(ex))
if(names.trim!=''){
colnames(a)<-sub(names.trim, '', colnames(a))
rownames(ex)<-sub(names.trim, '', rownames(ex))
}
d<-cor(a, method='spearman', use='pairwise.complete.obs')
hc<-hclust(as.dist(1-d), method='ward.D2')
ph<-pheatmap(as.matrix(d), color=rev(colorRampPalette(brewer.pal(9,'RdBu'))(20)), border_color=NA, scale='none',
breaks=seq(-1, 1, length.out=21),
cluster_rows=hc,
cluster_cols=hc,
#cutree_row=4, cutree_col=4,
annotation_legend=T, annotation_names_row=T, annotation_names_col=T,
annotation_col=ex, annotation_row=ex, annotation_colors=cl,
drop_levels=F, show_rownames=T, show_colnames=T,
#display_numbers=T, number_format='%.1f', number_color='grey39',
fontsize=18, fontsize_row=18, fontsize_col=18, fontsize_number=10)
dev.print(device=svg, file=paste0('/fast/projects/peifer_wgs/work/work/2017-11-08_Fuchs_totalRNAseq/raw/unified/figures/heatmap_', Type, '_cor_', sub(' vs ', '_', CND), '.svg'), width=16, height=16, bg='white', antialias='subpixel', pointsize=20, family='Arial')
rm(a,d,cl,ex,hc,ph)
dev.off()
# PCA based on variance-stabilized, glog2-transformed, centered but not scaled counts
XLIM<-pretty(range(PCA$x[, 'PC1']), 5)
XLIM<-c(XLIM[1], XLIM[length(XLIM)])
YLIM<-pretty(range(PCA$x[, 'PC2']), 5)
YLIM<-c(YLIM[1], YLIM[length(YLIM)])
x11(width=12, height=12, title='', bg='white', type='cairo', pointsize=20, antialias='subpixel', family='Arial')
x<-PCA$x[, c('PC1', 'PC2', condition, 'col')]
x[, condition]<-factor(x[, condition], levels=unique(x[, condition]))
if(names.trim!=''){
rownames(x)<-sub(names.trim, '', rownames(x))
}
print(
ggplot(x, aes(PC1, PC2, color=get(condition))) +
geom_point(size=10) +
#geom_text_repel(aes(label=rownames(x)), size=10, box.padding=0.5, segment.size=1.0, min.segment.length=1.0) +
scale_shape_manual(values=18) +
scale_fill_manual(name='sample', values=unique(x$col)) +
scale_color_manual(name='sample', values=unique(x$col)) +
theme(text = element_text(family='Arial'), axis.text.x=element_text(size=34), axis.title.x=element_text(size=34),
axis.title.y=element_text(size=34), axis.text.y=element_text(size=34),
legend.text=element_text(size=22), legend.title=element_text(size=22, face='plain'), aspect.ratio=1, panel.background = element_blank(),
axis.line.x=element_line(size=0.2, colour = 'black', linetype='solid'),
axis.line.y=element_line(size=0.2, colour = 'black', linetype='solid'),
panel.grid.major = element_blank(), panel.grid.minor = element_blank()) +
scale_x_continuous(lim=XLIM, breaks=pretty(XLIM,5)) +
scale_y_continuous(lim=YLIM, breaks=pretty(YLIM,5)) +
xlab(paste0('PC1: ', VE[1], '% variance')) + ylab(paste0('PC2: ', VE[2], '% variance'))
)
dev.print(device=svg, file=paste0('/fast/projects/peifer_wgs/work/work/2017-11-08_Fuchs_totalRNAseq/raw/unified/figures/plotPCA_', Type, '_vsc_', sub(' vs ', '_', CND), '.svg'), width=16, height=16, bg='white', antialias='subpixel', pointsize=20, family='Arial')
rm(XLIM,YLIM)
dev.off()
# save DESeq results along with gene counts
options(scipen=0)
save(DDS,CND,RES,VSC,PCA,VE, file=paste0('/fast/projects/peifer_wgs/work/work/2017-11-08_Fuchs_totalRNAseq/raw/unified/DESeq2_', Type, '_', sub(' vs ', '_', CND), '.RData'), compress=T)
# convert to table
x<-RES
x$gene_id<-rownames(x)
x<-x[, c('gene_id', 'gene_name', 'baseMean', 'log2FoldChange', 'pvalue', 'padj')]
rownames(x)<-NULL
x<-as.data.frame(x)
write.table(x, file=paste0('/fast/projects/peifer_wgs/work/work/2017-11-08_Fuchs_totalRNAseq/raw/unified/DESeq2_', Type, '_', sub(' vs ', '_', CND), '.tsv'), quote=F, sep='\t', row.names=F, col.names=T)
write.xlsx(x, file=paste0('/fast/projects/peifer_wgs/work/work/2017-11-08_Fuchs_totalRNAseq/raw/unified/DESeq2_', Type, '_', sub(' vs ', '_', CND), '.xlsx'), row.names=F, col.names=T, sheetName=gsub(' ', '_', CND))
rm(x)
#readline("Hit ENTER to close all figures: ")
#for (n in setdiff(dev.list(), DEV_START)){ dev.off(n) }
return(list(dds=DDS, res=RES, cnd=CND))
}
#}}}
# load pre-prepared counts etc. for all samples
load('/fast/projects/peifer_wgs/work/work/2017-11-08_Fuchs_totalRNAseq/raw/unified/DESeq2_circRNAs+genes_all_libraries.RData')
# [tumors, circRNAs + genes] clustering and PCA
#{{{
# [tumors, circRNAs] heatmap based on Euclidean distance of variance stabilized (and glog2-transformed) counts
x11(width=14, height=14, title='', bg='white', type='cairo', pointsize=20, antialias='subpixel', family='Arial')
m<-meta[!is.na(risk_group), ]
x<-crs.vs[, m$bid]
colnames(x)<-sub('-11-R01', '', colnames(x))
d<-dist(t(x), method='euclidean')
hc<-hclust(d, method='ward.D2')
ex<-data.frame(Type=factor(m$risk_group, exclude=F), row.names=colnames(x))
cl<-setNames(list(setNames( unique(m$col), unique(m$risk_group) )), colnames(ex))
ph<-pheatmap(as.matrix(d), color=colorRampPalette(brewer.pal(9,'GnBu'))(20), border_color=NA, scale='none',
cluster_rows=hc,
cluster_cols=hc,
#cutree_row=4, cutree_col=4,
annotation_legend=T, annotation_names_row=T, annotation_names_col=T,
annotation_col=ex, annotation_row=ex, annotation_colors=cl,
drop_levels=F, show_rownames=T, show_colnames=T,
display_numbers=T, number_format='%.1f', number_color='grey39',
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_circRNAs_vsc_tumors.svg', width=14, height=14, bg='white', antialias='subpixel', pointsize=20, family='Arial')
rm(m,x,d,ex,hc,ph,cl)
dev.off()
# [tumors, genes] heatmap based on Euclidean distance of variance stabilized (and glog2-transformed) counts
x11(width=14, height=14, title='', bg='white', type='cairo', pointsize=20, antialias='subpixel', family='Arial')
m<-meta[!is.na(risk_group), ]
x<-gns.vs[, m$bid]
colnames(x)<-sub('-11-R01', '', colnames(x))
d<-dist(t(x), method='euclidean')
hc<-hclust(d, method='ward.D2')
ex<-data.frame(Type=factor(m$risk_group, exclude=F), row.names=colnames(x))
cl<-setNames(list(setNames( unique(m$col), unique(m$risk_group) )), colnames(ex))
ph<-pheatmap(as.matrix(d), color=colorRampPalette(brewer.pal(9,'GnBu'))(20), border_color=NA, scale='none',
cluster_rows=hc,
cluster_cols=hc,
#cutree_row=4, cutree_col=4,
annotation_legend=T, annotation_names_row=T, annotation_names_col=T,
annotation_col=ex, annotation_row=ex, annotation_colors=cl,
drop_levels=F, show_rownames=T, show_colnames=T,
display_numbers=T, number_format='%.1f', number_color='grey39',
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_genes_vsc_tumors.svg', width=14, height=14, bg='white', antialias='subpixel', pointsize=20, family='Arial')
rm(m,x,d,ex,hc,ph,cl)
dev.off()
# [tumors, circRNAs] heatmaps based on Spearman correlations of raw counts
x11(width=14, height=14, title='', bg='white', type='cairo', pointsize=20, antialias='subpixel', family='Arial')
m<-meta[!is.na(risk_group), ]
x<-crs.cnt[, m$bid]
colnames(x)<-sub('-11-R01', '', colnames(x))
d<-cor(x, method='spearman', use='pairwise.complete.obs')
hc<-hclust(as.dist(1-d), method='ward.D2')
ex<-data.frame(Type=factor(m$risk_group, exclude=F), row.names=colnames(x))
cl<-setNames(list(setNames( unique(m$col), unique(m$risk_group) )), colnames(ex))
ph<-pheatmap(as.matrix(d), color=rev(colorRampPalette(brewer.pal(9,'RdBu'))(20)), border_color=NA, scale='none',
breaks=seq(0, 1, length.out=21),
cluster_rows=hc,
cluster_cols=hc,
#cutree_row=4, cutree_col=4,
annotation_legend=T, annotation_names_row=T, annotation_names_col=T,
annotation_col=ex, annotation_row=ex, annotation_colors=cl,
drop_levels=F, show_rownames=T, show_colnames=T,
#display_numbers=T, number_format='%.1f', number_color='grey39',
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_circRNAs_cor_tumors.svg', width=14, height=14, bg='white', antialias='subpixel', pointsize=20, family='Arial')
rm(m,x,d,ex,hc,ph,cl)
dev.off()
# [tumors, genes] heatmaps based on Spearman correlations of raw counts
x11(width=14, height=14, title='', bg='white', type='cairo', pointsize=20, antialias='subpixel', family='Arial')
m<-meta[!is.na(risk_group), ]
x<-gns.cnt[, m$bid]
colnames(x)<-sub('-11-R01', '', colnames(x))
d<-cor(x, method='spearman', use='pairwise.complete.obs')
hc<-hclust(as.dist(1-d), method='ward.D2')
ex<-data.frame(Type=factor(m$risk_group, exclude=F), row.names=colnames(x))
cl<-setNames(list(setNames( unique(m$col), unique(m$risk_group) )), colnames(ex))
ph<-pheatmap(as.matrix(d), color=rev(colorRampPalette(brewer.pal(9,'RdBu'))(20)), border_color=NA, scale='none',
breaks=seq(0.7, 1, length.out=21), # reduce range since samples are highly correlated
cluster_rows=hc,
cluster_cols=hc,
#cutree_row=4, cutree_col=4,
annotation_legend=T, annotation_names_row=T, annotation_names_col=T,
annotation_col=ex, annotation_row=ex, annotation_colors=cl,
drop_levels=F, show_rownames=T, show_colnames=T,
#display_numbers=T, number_format='%.1f', number_color='grey39',
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_genes_cor_tumors.svg', width=14, height=14, bg='white', antialias='subpixel', pointsize=20, family='Arial')
rm(x,m,d,ex,hc,ph,cl)
dev.off()
# [tumors, circRNAs] PCA based on variance stabilized (and log2-transformed) counts centered but not scaled
x11(width=14, height=14, title='', bg='white', type='cairo', pointsize=20, antialias='subpixel', family='Arial')
m<-meta[!is.na(risk_group), ]
x<-crs.vs[, m$bid]
colnames(x)<-sub('-11-R01', '', colnames(x))
p<-prcomp(t(x), center=T, scale.=F)
v<-round(1000 * p$sdev^2/sum(p$sdev^2))/10
n<-cbind( data.frame( p$x[, c('PC1', 'PC2')] ), Type=m$risk_group, bid=colnames(x))
cl<-list('Type'=setNames( unique(m$col), unique(m$risk_group) ))
XLIM<-pretty(range(n[, 'PC1']), 2)
XLIM<-c(XLIM[1], XLIM[length(XLIM)])
YLIM<-pretty(range(n[, 'PC2']), 2)
YLIM<-c(YLIM[1], YLIM[length(YLIM)])
ggplot(n[, c('PC1', 'PC2', 'Type', 'bid')], aes(PC1, PC2, color=Type)) +
geom_point(size=12) +
scale_shape_manual(values=18) +
scale_fill_manual(name='Type', values=cl$Type) +
scale_color_manual(name='Type', values=cl$Type) +
theme(text=element_text(family='Arial'), axis.text.x=element_text(size=34), axis.title.x=element_text(size=34),
axis.title.y=element_text(size=34), axis.text.y=element_text(size=34),
legend.text=element_text(size=22), legend.title=element_text(size=22, face='plain'),
aspect.ratio=1, panel.background = element_blank(),
axis.line.x=element_line(size=0.2, colour = 'black', linetype='solid'),
axis.line.y=element_line(size=0.2, colour = 'black', linetype='solid'),
panel.grid.major = element_blank(), panel.grid.minor = element_blank()) +
scale_x_continuous(lim=XLIM, breaks=pretty(XLIM,5)) +
scale_y_continuous(lim=YLIM, breaks=pretty(YLIM,5)) +
xlab(paste0('PC1: ', v[1], '% variance')) + ylab(paste0('PC2: ', v[2], '% variance'))
dev.print(device=svg, file='/fast/projects/peifer_wgs/work/work/2017-11-08_Fuchs_totalRNAseq/raw/unified/figures/plotPCA_circRNAs_vsc_tumors.svg', width=14, height=14, bg='white', antialias='subpixel', pointsize=20, family='Arial')
rm(m,x,p,v,n,cl,XLIM,YLIM)
dev.off()
# [tumors, genes] PCA based on variance stabilized glog2-transformed counts centered but not scaled
x11(width=14, height=14, title='', bg='white', type='cairo', pointsize=20, antialias='subpixel', family='Arial')
m<-meta[!is.na(risk_group), ]
x<-gns.vs[, m$bid]
colnames(x)<-sub('-11-R01', '', colnames(x))
p<-prcomp(t(x), center=T, scale.=F)
v<-round(1000 * p$sdev^2/sum(p$sdev^2))/10
n<-cbind( data.frame( p$x[, c('PC1', 'PC2')] ), Type=m$risk_group, bid=colnames(x))
cl<-list('Type'=setNames( unique(m$col), unique(m$risk_group) ))
#XLIM<-pretty(range(n[, 'PC1']), 2)
#XLIM<-c(XLIM[1], XLIM[length(XLIM)])
#YLIM<-pretty(range(n[, 'PC2']), 2)
#YLIM<-c(YLIM[1], YLIM[length(YLIM)])
XLIM<-c(-150, 250) # force limits
YLIM<-c(-150, 100) # force limits
ggplot(n[, c('PC1', 'PC2', 'Type', 'bid')], aes(PC1, PC2, color=Type)) +
geom_point(size=12) +
scale_shape_manual(values=18) +
scale_fill_manual(name='Type', values=cl$Type) +
scale_color_manual(name='Type', values=cl$Type) +
theme(text=element_text(family='Arial'), axis.text.x=element_text(size=34), axis.title.x=element_text(size=34),
axis.title.y=element_text(size=34), axis.text.y=element_text(size=34),
legend.text=element_text(size=22), legend.title=element_text(size=22, face='plain'),
aspect.ratio=1, panel.background = element_blank(),
axis.line.x=element_line(size=0.2, colour = 'black', linetype='solid'),
axis.line.y=element_line(size=0.2, colour = 'black', linetype='solid'),
panel.grid.major = element_blank(), panel.grid.minor = element_blank()) +
scale_x_continuous(lim=XLIM, breaks=seq(XLIM[1], XLIM[2], length.out=5)) +
scale_y_continuous(lim=YLIM, breaks=seq(YLIM[1], YLIM[2], length.out=6)) +
xlab(paste0('PC1: ', v[1], '% variance')) + ylab(paste0('PC2: ', v[2], '% variance'))
dev.print(device=svg, file='/fast/projects/peifer_wgs/work/work/2017-11-08_Fuchs_totalRNAseq/raw/unified/figures/plotPCA_genes_vsc_tumors.svg', width=14, height=14, bg='white', antialias='subpixel', pointsize=20, family='Arial')
rm(m,x,p,v,n,cl,XLIM,YLIM)
dev.off()
#}}}
# [tumors, circRNAs] all pairwise DE analyses
#{{{
# [MNA vs HR_nMNA] DESeq2 forcing library sizes from the gene counts and including sex in the design
m<-meta[risk_group %in% c('MNA', 'HR_nMNA') ]
M<-crs.cnt[, m$bid ]
CT<-data.frame(m[, c('sex', 'risk_group', 'col'), with=F], row.names=m$bid)
DDS<-DESeqDataSetFromMatrix(countData=M, colData=data.frame(risk_group=factor(CT$risk_group), sex=factor(CT$sex), row.names=rownames(CT)), design=~sex+risk_group)
DDS$risk_group<-relevel(DDS$risk_group, 'HR_nMNA') # define first level so that the comparison log2(level 2/level 1) is done
sizeFactors(DDS)<-gns.sf[ colnames(DDS) ]
d<-do_deseq2(DDS=DDS, CT=CT, Type='circRNAs', condition='risk_group', lfcThreshold=0.0, lfcShrinkType='normal', include.annot=F, names.trim='-11-R01$', list(par=list(mar=c(5.0, 7.0, 1.0, 2.5), mgp=c(3,1,0), oma=c(0,0,0,0), las=1, xpd=F, bty='n', cex.lab=2.4, cex.axis=2.4, tcl=-0.2), ylab.line=3))
rm(m,M,CT,DDS)
# [HR_nMNA vs IMR] DESeq2 forcing library sizes from the gene counts and including sex in the design
m<-meta[risk_group %in% c('IMR', 'HR_nMNA') ]
M<-crs.cnt[, m$bid ]
CT<-data.frame(m[, c('sex', 'risk_group', 'col'), with=F], row.names=m$bid)
DDS<-DESeqDataSetFromMatrix(countData=M, colData=data.frame(risk_group=factor(CT$risk_group), sex=factor(CT$sex), row.names=rownames(CT)), design=~sex+risk_group)
DDS$risk_group<-relevel(DDS$risk_group, 'IMR') # define first level so that the comparison log2(level 2/level 1) is done
sizeFactors(DDS)<-gns.sf[ colnames(DDS) ]
d<-do_deseq2(DDS=DDS, CT=CT, Type='circRNAs', condition='risk_group', lfcThreshold=0.0, lfcShrinkType='normal', include.annot=F, names.trim='-11-R01$', list(par=list(mar=c(5.0, 8.0, 1.0, 2.5), mgp=c(3,1,0), oma=c(0,0,0,0), las=1, xpd=F, bty='n', cex.lab=2.4, cex.axis=2.4, tcl=-0.2), ylab.line=4))
rm(m,M,CT,DDS)
# [HR_nMNA vs LR] DESeq2 forcing library sizes from the gene counts and including sex in the design
m<-meta[risk_group %in% c('LR', 'HR_nMNA') ]
M<-crs.cnt[, m$bid ]
CT<-data.frame(m[, c('sex', 'risk_group', 'col'), with=F], row.names=m$bid)
DDS<-DESeqDataSetFromMatrix(countData=M, colData=data.frame(risk_group=factor(CT$risk_group), sex=factor(CT$sex), row.names=rownames(CT)), design=~sex+risk_group)
DDS$risk_group<-relevel(DDS$risk_group, 'LR') # define first level so that the comparison log2(level 2/level 1) is done
sizeFactors(DDS)<-gns.sf[ colnames(DDS) ]
d<-do_deseq2(DDS=DDS, CT=CT, Type='circRNAs', condition='risk_group', lfcThreshold=0.0, lfcShrinkType='normal', include.annot=F, names.trim='-11-R01$', list(par=list(mar=c(5.0, 8.0, 1.0, 2.5), mgp=c(3,1,0), oma=c(0,0,0,0), las=1, xpd=F, bty='n', cex.lab=2.4, cex.axis=2.4, tcl=-0.2), ylab.line=4))
rm(m,M,CT,DDS)
# [IMR vs LR] DESeq2 forcing library sizes from the gene counts and including sex in the design
m<-meta[risk_group %in% c('LR', 'IMR') ]
M<-crs.cnt[, m$bid ]
CT<-data.frame(m[, c('sex', 'risk_group', 'col'), with=F], row.names=m$bid)
DDS<-DESeqDataSetFromMatrix(countData=M, colData=data.frame(risk_group=factor(CT$risk_group), sex=factor(CT$sex), row.names=rownames(CT)), design=~sex+risk_group)
DDS$risk_group<-relevel(DDS$risk_group, 'LR') # define first level so that the comparison log2(level 2/level 1) is done
sizeFactors(DDS)<-gns.sf[ colnames(DDS) ]
d<-do_deseq2(DDS=DDS, CT=CT, Type='circRNAs', condition='risk_group', lfcThreshold=0.0, lfcShrinkType='normal', include.annot=F, names.trim='-11-R01$', list(par=list(mar=c(5.0, 8.0, 1.0, 2.5), mgp=c(3,1,0), oma=c(0,0,0,0), las=1, xpd=F, bty='n', cex.lab=2.4, cex.axis=2.4, tcl=-0.2), ylab.line=4))
rm(m,M,CT,DDS)
# [LR vs ST4S] DESeq2 forcing library sizes from the gene counts and including sex in the design
m<-meta[risk_group %in% c('ST4S', 'LR') ]
M<-crs.cnt[, m$bid ]
CT<-data.frame(m[, c('sex', 'risk_group', 'col'), with=F], row.names=m$bid)
DDS<-DESeqDataSetFromMatrix(countData=M, colData=data.frame(risk_group=factor(CT$risk_group), sex=factor(CT$sex), row.names=rownames(CT)), design=~sex+risk_group)
DDS$risk_group<-relevel(DDS$risk_group, 'LR') # define first level so that the comparison log2(level 2/level 1) is done
sizeFactors(DDS)<-gns.sf[ colnames(DDS) ]
d<-do_deseq2(DDS=DDS, CT=CT, Type='circRNAs', condition='risk_group', lfcThreshold=0.0, lfcShrinkType='normal', include.annot=F, names.trim='-11-R01$', list(par=list(mar=c(5.0, 8.0, 1.0, 2.5), mgp=c(3,1,0), oma=c(0,0,0,0), las=1, xpd=F, bty='n', cex.lab=2.4, cex.axis=2.4, tcl=-0.2), ylab.line=4))
rm(m,M,CT,DDS)
#}}}
# [tumors, genes] all pairwise DE analyses
#{{{
# [MNA vs HR_nMNA] DESeq2 including sex in the design
m<-meta[risk_group %in% c('MNA', 'HR_nMNA') ]
M<-gns.cnt[, m$bid ]
CT<-data.frame(m[, c('sex', 'risk_group', 'col'), with=F], row.names=m$bid)
DDS<-DESeqDataSetFromMatrix(countData=M, colData=data.frame(risk_group=factor(CT$risk_group), sex=factor(CT$sex), row.names=rownames(CT)), design=~sex+risk_group)
DDS$risk_group<-relevel(DDS$risk_group, 'HR_nMNA') # define first level so that the comparison log2(level 2/level 1) is done
d<-do_deseq2(DDS=DDS, CT=CT, Type='genes', condition='risk_group', lfcThreshold=0.0, lfcShrinkType='normal', include.annot=F, names.trim='-11-R01$', list(par=list(mar=c(5.0, 7.0, 1.0, 2.5), mgp=c(3,1,0), oma=c(0,0,0,0), las=1, xpd=F, bty='n', cex.lab=2.4, cex.axis=2.4, tcl=-0.2), ylab.line=3))
rm(m,M,CT,DDS)
# [HR_nMNA vs IMR] DESeq2 including sex in the design
m<-meta[risk_group %in% c('IMR', 'HR_nMNA') ]
M<-gns.cnt[, m$bid ]
CT<-data.frame(m[, c('sex', 'risk_group', 'col'), with=F], row.names=m$bid)
DDS<-DESeqDataSetFromMatrix(countData=M, colData=data.frame(risk_group=factor(CT$risk_group), sex=factor(CT$sex), row.names=rownames(CT)), design=~sex+risk_group)
DDS$risk_group<-relevel(DDS$risk_group, 'IMR') # define first level so that the comparison log2(level 2/level 1) is done
d<-do_deseq2(DDS=DDS, CT=CT, Type='genes', condition='risk_group', lfcThreshold=0.0, lfcShrinkType='normal', include.annot=F, names.trim='-11-R01$', list(par=list(mar=c(5.0, 7.0, 1.0, 2.5), mgp=c(3,1,0), oma=c(0,0,0,0), las=1, xpd=F, bty='n', cex.lab=2.4, cex.axis=2.4, tcl=-0.2), ylab.line=3))
rm(m,M,CT,DDS)
# [HR_nMNA vs LR] DESeq2 including sex in the design
m<-meta[risk_group %in% c('LR', 'HR_nMNA') ]
M<-gns.cnt[, m$bid ]
CT<-data.frame(m[, c('sex', 'risk_group', 'col'), with=F], row.names=m$bid)
DDS<-DESeqDataSetFromMatrix(countData=M, colData=data.frame(risk_group=factor(CT$risk_group), sex=factor(CT$sex), row.names=rownames(CT)), design=~sex+risk_group)
DDS$risk_group<-relevel(DDS$risk_group, 'LR') # define first level so that the comparison log2(level 2/level 1) is done
d<-do_deseq2(DDS=DDS, CT=CT, Type='genes', condition='risk_group', lfcThreshold=0.0, lfcShrinkType='normal', include.annot=F, names.trim='-11-R01$', list(par=list(mar=c(5.0, 7.0, 1.0, 2.5), mgp=c(3,1,0), oma=c(0,0,0,0), las=1, xpd=F, bty='n', cex.lab=2.4, cex.axis=2.4, tcl=-0.2), ylab.line=3))
rm(m,M,CT,DDS)
# [IMR vs LR] DESeq2 including sex in the design
m<-meta[risk_group %in% c('LR', 'IMR') ]
M<-gns.cnt[, m$bid ]
CT<-data.frame(m[, c('sex', 'risk_group', 'col'), with=F], row.names=m$bid)
DDS<-DESeqDataSetFromMatrix(countData=M, colData=data.frame(risk_group=factor(CT$risk_group), sex=factor(CT$sex), row.names=rownames(CT)), design=~sex+risk_group)
DDS$risk_group<-relevel(DDS$risk_group, 'LR') # define first level so that the comparison log2(level 2/level 1) is done
d<-do_deseq2(DDS=DDS, CT=CT, Type='genes', condition='risk_group', lfcThreshold=0.0, lfcShrinkType='normal', include.annot=F, names.trim='-11-R01$', list(par=list(mar=c(5.0, 7.0, 1.0, 2.5), mgp=c(3,1,0), oma=c(0,0,0,0), las=1, xpd=F, bty='n', cex.lab=2.4, cex.axis=2.4, tcl=-0.2), ylab.line=3))
rm(m,M,CT,DDS)
# [ST4S vs LR] DESeq2 including sex in the design
m<-meta[risk_group %in% c('ST4S', 'LR') ]
M<-gns.cnt[, m$bid ]
CT<-data.frame(m[, c('sex', 'risk_group', 'col'), with=F], row.names=m$bid)
DDS<-DESeqDataSetFromMatrix(countData=M, colData=data.frame(risk_group=factor(CT$risk_group), sex=factor(CT$sex), row.names=rownames(CT)), design=~sex+risk_group)
DDS$risk_group<-relevel(DDS$risk_group, 'LR') # define first level so that the comparison log2(level 2/level 1) is done
d<-do_deseq2(DDS=DDS, CT=CT, Type='genes', condition='risk_group', lfcThreshold=0.0, lfcShrinkType='normal', include.annot=F, names.trim='-11-R01$', list(par=list(mar=c(5.0, 7.0, 1.0, 2.5), mgp=c(3,1,0), oma=c(0,0,0,0), las=1, xpd=F, bty='n', cex.lab=2.4, cex.axis=2.4, tcl=-0.2), ylab.line=3))
rm(m,M,CT,DDS)
#}}}
# [cell models, circRNAs] DE analyses
#{{{
# [MYCN +Tet 4h vs ETOH 4h] DESeq2 forcing library sizes from the gene counts
m<-meta[grepl('CB-SKNAS-TR-MYCN', bid) & treatment %in% c('ETOH 4h', '+Tet 4h') ]
M<-crs.cnt[, m$bid ]
CT<-data.frame(m[, c('cell_model', 'treatment', 'col'), with=F], row.names=m$bid)
colnames(CT)<-c('cell_model', 'Treatment', 'col')
DDS<-DESeqDataSetFromMatrix(countData=M, colData=data.frame(Treatment=factor(CT$Treatment), row.names=rownames(CT)), design=~Treatment)
DDS$Treatment<-relevel(DDS$Treatment, 'ETOH 4h') # define first level so that the comparison log2(level 2/level 1) is done
sizeFactors(DDS)<-gns.sf[ colnames(DDS) ]
d<-do_deseq2(DDS=DDS, CT=CT, Type='circRNAs', condition='Treatment', lfcThreshold=0.0, lfcShrinkType='normal', include.annot=F, names.trim='', list(par=list(mar=c(5.0, 8.0, 1.0, 2.5), mgp=c(3,1,0), oma=c(0,0,0,0), las=1, xpd=F, bty='n', cex.lab=2.4, cex.axis=2.4, tcl=-0.2), ylab.line=4))
rm(m,M,CT,DDS)
# [MYCN +Tet 48h vs ETOH 48h] DESeq2 forcing library sizes from the gene counts
m<-meta[grepl('CB-SKNAS-TR-MYCN', bid) & treatment %in% c('ETOH 48h', '+Tet 48h') ]
M<-crs.cnt[, m$bid ]
CT<-data.frame(m[, c('cell_model', 'treatment', 'col'), with=F], row.names=m$bid)
colnames(CT)<-c('cell_model', 'Treatment', 'col')
DDS<-DESeqDataSetFromMatrix(countData=M, colData=data.frame(Treatment=factor(CT$Treatment), row.names=rownames(CT)), design=~Treatment)
DDS$Treatment<-relevel(DDS$Treatment, 'ETOH 48h') # define first level so that the comparison log2(level 2/level 1) is done
sizeFactors(DDS)<-gns.sf[ colnames(DDS) ]
d<-do_deseq2(DDS=DDS, CT=CT, Type='circRNAs', condition='Treatment', lfcThreshold=0.0, lfcShrinkType='normal', include.annot=F, names.trim='', list(par=list(mar=c(5.0, 8.0, 1.0, 2.5), mgp=c(3,1,0), oma=c(0,0,0,0), las=1, xpd=F, bty='n', cex.lab=2.4, cex.axis=2.4, tcl=-0.2), ylab.line=4))
rm(m,M,CT,DDS)
# [MYCN +Tet 48h vs +Tet 4h ] DESeq2 forcing library sizes from the gene counts
m<-meta[grepl('CB-SKNAS-TR-MYCN', bid) & treatment %in% c('+Tet 4h', '+Tet 48h') ]
M<-crs.cnt[, m$bid ]
CT<-data.frame(m[, c('cell_model', 'treatment', 'col'), with=F], row.names=m$bid)
colnames(CT)<-c('cell_model', 'Treatment', 'col')
DDS<-DESeqDataSetFromMatrix(countData=M, colData=data.frame(Treatment=factor(CT$Treatment), row.names=rownames(CT)), design=~Treatment)
DDS$Treatment<-relevel(DDS$Treatment, '+Tet 4h') # define first level so that the comparison log2(level 2/level 1) is done
sizeFactors(DDS)<-gns.sf[ colnames(DDS) ]
d<-do_deseq2(DDS=DDS, CT=CT, Type='circRNAs', condition='Treatment', lfcThreshold=0.0, lfcShrinkType='normal', include.annot=F, names.trim='', list(par=list(mar=c(5.0, 8.0, 1.0, 2.5), mgp=c(3,1,0), oma=c(0,0,0,0), las=1, xpd=F, bty='n', cex.lab=2.4, cex.axis=2.4, tcl=-0.2), ylab.line=4))
rm(m,M,CT,DDS)
#}}}
# [cell models, genes] DE analyses
#{{{
# [MYCN +Tet 4h vs ETOH 4h] DESeq2
m<-meta[grepl('CB-SKNAS-TR-MYCN', bid) & treatment %in% c('ETOH 4h', '+Tet 4h') ]
M<-gns.cnt[, m$bid ]
CT<-data.frame(m[, c('cell_model', 'treatment', 'col'), with=F], row.names=m$bid)
colnames(CT)<-c('cell_model', 'Treatment', 'col')
DDS<-DESeqDataSetFromMatrix(countData=M, colData=data.frame(Treatment=factor(CT$Treatment), row.names=rownames(CT)), design=~Treatment)
DDS$Treatment<-relevel(DDS$Treatment, 'ETOH 4h') # define first level so that the comparison log2(level 2/level 1) is done
d<-do_deseq2(DDS=DDS, CT=CT, Type='genes', condition='Treatment', lfcThreshold=0.0, lfcShrinkType='normal', include.annot=F, names.trim='', list(par=list(mar=c(5.0, 8.0, 1.0, 2.5), mgp=c(3,1,0), oma=c(0,0,0,0), las=1, xpd=F, bty='n', cex.lab=2.4, cex.axis=2.4, tcl=-0.2), ylab.line=4))
rm(m,M,CT,DDS)
# [MYCN +Tet 48h vs ETOH 48h] DESeq2
m<-meta[grepl('CB-SKNAS-TR-MYCN', bid) & treatment %in% c('ETOH 48h', '+Tet 48h') ]
M<-gns.cnt[, m$bid ]
CT<-data.frame(m[, c('cell_model', 'treatment', 'col'), with=F], row.names=m$bid)
colnames(CT)<-c('cell_model', 'Treatment', 'col')
DDS<-DESeqDataSetFromMatrix(countData=M, colData=data.frame(Treatment=factor(CT$Treatment), row.names=rownames(CT)), design=~Treatment)
DDS$Treatment<-relevel(DDS$Treatment, 'ETOH 48h') # define first level so that the comparison log2(level 2/level 1) is done
d<-do_deseq2(DDS=DDS, CT=CT, Type='genes', condition='Treatment', lfcThreshold=0.0, lfcShrinkType='normal', include.annot=F, names.trim='', list(par=list(mar=c(5.0, 8.0, 1.0, 2.5), mgp=c(3,1,0), oma=c(0,0,0,0), las=1, xpd=F, bty='n', cex.lab=2.4, cex.axis=2.4, tcl=-0.2), ylab.line=4))
rm(m,M,CT,DDS)
# [MYCN +Tet 48h vs +Tet 4h ] DESeq2
m<-meta[grepl('CB-SKNAS-TR-MYCN', bid) & treatment %in% c('+Tet 4h', '+Tet 48h') ]
M<-gns.cnt[, m$bid ]
CT<-data.frame(m[, c('cell_model', 'treatment', 'col'), with=F], row.names=m$bid)
colnames(CT)<-c('cell_model', 'Treatment', 'col')
DDS<-DESeqDataSetFromMatrix(countData=M, colData=data.frame(Treatment=factor(CT$Treatment), row.names=rownames(CT)), design=~Treatment)
DDS$Treatment<-relevel(DDS$Treatment, '+Tet 4h') # define first level so that the comparison log2(level 2/level 1) is done
d<-do_deseq2(DDS=DDS, CT=CT, Type='genes', condition='Treatment', lfcThreshold=0.0, lfcShrinkType='normal', include.annot=F, names.trim='', list(par=list(mar=c(5.0, 8.0, 1.0, 2.5), mgp=c(3,1,0), oma=c(0,0,0,0), las=1, xpd=F, bty='n', cex.lab=2.4, cex.axis=2.4, tcl=-0.2), ylab.line=4))
rm(m,M,CT,DDS)
#}}}
#}}}
# [tumors + cell lines] process of all the DESeq2 results into HTML-table-ready objects
# do MSigDB C2 enrichment analysis
# do MSigDB GSEA analysis
#
# combine the MNA vs HR_nMNA, MYCN +-Tet 4h, MYCN +- 48h, MYCN +- 120h results
#
#{{{
# [MNA vs HR_nMNA, circRNAs+genes] enrichment in MYCN targets