-
Notifications
You must be signed in to change notification settings - Fork 4
/
proteogenomics_analyses.R
1936 lines (1518 loc) · 134 KB
/
proteogenomics_analyses.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
library(stringr)
library(gplots)
library(LSD)
library(devtools)
library(ConsensusClusterPlus)
library(VennDiagram)
library(enrichR)
library(multiOmicsViz)
library(biomaRt)
library(ggbiplot)
library(ComplexHeatmap)
library(RColorBrewer)
library(dendextend)
library(data.table)
library(survminer)
library(survival)
library(Rtsne)
setwd("~/projects/proteogenomics")
source("~/scripts/data_processing_functions.R") #primarily proteomics data processing functions
source("scripts/main/heatmap.4.R") #slight modification of https://github.com/obigriffith/biostar-tutorials/blob/master/Heatmaps/heatmap.3.R to make heatmap font size adjustable
#read input ----
protein_expression = read.delim("data/main/original_data/v2.1/tmt29_processed_data_uncorrected.txt", header = TRUE, stringsAsFactors = FALSE, check.names = FALSE)
protein_annotation = read.delim("data/main/original_data/v2.1/tmt29_protein_group_annotation.txt", header = TRUE, stringsAsFactors = FALSE)
protein_expression = merge(protein_annotation, protein_expression, by = "ProteinGroup")
protein_expression = subset(protein_expression, All_Reverse_Flag == 0)
tmt_meta = read.delim("data/main/original_data/v2.1/tmt29_sample_annotation.txt", header = TRUE, stringsAsFactors = FALSE)
#need to take out the following samples for treatment prior to surgery; very last sample ...7303 has problem with DNA so skip
#these 06s identifiers are internal Moffitt identifers. Samples have been renamed in supplemental data for the manuscript, e.g. SCC001, SCC002, etc.
skip_samples = c("06S15101140", "06S15101158", "06S15101159", "06S15101176", "06S15101180", "06S15101185", "06S15101193", "06S10347307")
tmt_meta = subset(tmt_meta, !(TissueID %in% skip_samples))
#Get rid of pools; going to call the sample names directly from the metadata column
tumor_tmt_colnames = subset(tmt_meta, TissueID != "Pool")$TissueID
protein_expression[protein_expression == 0] = NA #no imputation except in select cases (e.g. PCA)
wilkerson_genes_centroids = read.delim("data/main/wilkerson.scc/predictor.centroids.csv", sep = ",", header = TRUE, stringsAsFactors = FALSE) #used for getting gene symbols for looking at specific Wilkerson SCC signature genes and their correlations
gene_expression = read.delim("data/main/proteogenomics_cel_file_expression_sampleidmap_08-15-16.txt", header = TRUE, stringsAsFactors = FALSE) #microarray gene expression
gene_expression_best = read.delim("data/main/gene_expression_best_03-24-17.txt", header = TRUE, stringsAsFactors = FALSE) #already log2'd; processed with get_best_probe() from data_processing_functions.R
gene_expression_06s_mapping = read.delim("data/main/proteogenomics_cel_file_meta_03-15-17.txt", header = TRUE, stringsAsFactors = FALSE)
mutation_status_prelim = read.delim("data/main/preliminary_mutations_12-20-16/LUSC_PG_genes_all.list_minGQ15.status_mapped_sample.txt", header = TRUE, stringsAsFactors = FALSE) #this is called "preliminary" but hasn't changed and was used in the final analysis for the manuscript
mutation_gene_list = names(mutation_status_prelim)[names(mutation_status_prelim) != "tumor_06s" & names(mutation_status_prelim) != "dna_sample"]
tumor_mutation_burden = read.delim("data/main/tmb_07-21-17.txt", header = TRUE, stringsAsFactors = FALSE) # used to look if there is any association with proteomic subtype and mutation burden
mutation_status_prelim_tmb = merge(mutation_status_prelim, tumor_mutation_burden, by.x = "dna_sample", by.y = "sample")
sqlc_classification_combined = read.delim("data/main/squamous_subtype_classifications_microarray_rnaseq_2018-05-10.txt", header = TRUE, stringsAsFactors = FALSE)
clinical = read.delim("data/main/sqlc116_clinical_05-23-17.txt", header = TRUE, stringsAsFactors = FALSE)
rnaseq_meta = read.delim("data/main/v2.2_lusq_proteogenomics_rnaseq_metadata_with_batches_2018-05-09.txt", header = TRUE, stringsAsFactors = FALSE) #updated metadata for remapped batch 3
rnaseq_meta = subset(rnaseq_meta, Redo != "Original" & Sample.Family.ID != "---") #don't include original samples that needed to be rerun
smoking = read.delim("data/main/smoking_trimmed_merged_06-16-17.txt", header = TRUE, stringsAsFactors = FALSE)
lsqcc_tcc_signatures = read.delim("data/main/original_data/LSQCC-signatures_TCC_from_steven_10-04-17.txt", header = TRUE, stringsAsFactors = FALSE)
#scaling factors used for multi-plex normalization
scaling_factors = read.delim("data/main/original_data/v2.1/tmt29_replicate_scaling_factors_uncorrected..txt", header = TRUE, stringsAsFactors = FALSE)
scaling_factors = scaling_factors[str_detect(scaling_factors$Plex, "01$"), ]
scaling_factors$Plex = str_replace(scaling_factors$Plex, "\\_01$", "") #use first technical replicate
scaling_factors$TMT.Sample.Name = paste(scaling_factors$Plex, scaling_factors$SampleName, sep = "_")
scaling_factors = subset(scaling_factors, SampleName != "TMT-126")
#combine into master metadata file to line up data by sample and for easy reference
tmt_meta = merge(tmt_meta, gene_expression_06s_mapping, by = "TissueID", all = TRUE)
tmt_meta = merge(tmt_meta, mutation_status_prelim_tmb, by.x = "TissueID", by.y = "tumor_06s", all = TRUE)
tmt_meta = merge(tmt_meta, sqlc_classification_combined, by.x = "TissueID", by.y = "tumor_06s", all = TRUE)
tmt_meta = merge(tmt_meta, clinical, by.x = "TissueID", by.y = "Aliquot.Sample.ID")
tmt_meta = merge(tmt_meta, rnaseq_meta, by = "TissueID")
tmt_meta = merge(tmt_meta, smoking, by.x = "TissueID", by.y = "Aliquot.ID")
tmt_meta = merge(tmt_meta, lsqcc_tcc_signatures, by.x = "TissueID", by.y = "row.names", all = TRUE)
tmt_meta = merge(tmt_meta, scaling_factors, by = "TMT.Sample.Name")
number_of_samples = nrow(tmt_meta) #use this for calculations needing a percentage of the total number of samples
rnaseq_expression = read.delim("data/main/original_data/v2.2_lusq116_rnaseq_iron_untilt_filt3_debatched.txt", header = TRUE, stringsAsFactors = FALSE, check.names = FALSE)
#get TMT columns, gene columns, and patients; order is the same since these are coming from the meta file
tumor_06s = subset(tmt_meta, TissueID != "Pool")$TissueID
#rnaseq consensus cluster ----
rnaseq_colnames = tmt_meta$GenomicsSample
rnaseq_expression$sd = apply(rnaseq_expression[, rnaseq_colnames], 1, function(x) {
sd(na.omit(x))
})
rnaseq_expression$mean = apply(rnaseq_expression[, rnaseq_colnames], 1, function(x) {
mean(na.omit(x))
})
rnaseq_expression$mads = apply(rnaseq_expression[, rnaseq_colnames], 1, function(x) {
mad(na.omit(x))
})
rnaseq_expression$na_count = rowSums(is.na(rnaseq_expression[, rnaseq_colnames]))
rnaseq_expression_heatmap = subset(rnaseq_expression, na_count < number_of_samples * 0.1 ) #less than 10% missingness
#get top 1000 variable genes
rnaseq_expression_heatmap = rnaseq_expression_heatmap[rev(order(rnaseq_expression_heatmap$mads))[1:1000], rnaseq_colnames]
title_rnaseq = tempdir()
#title_rnaseq = "output/main/cc_results/rnaseq_cc_complete_madtop1k_10pct_missing_1krep_2018-05-10"
consensus_rnaseq_matrix = as.matrix(rnaseq_expression_heatmap[, rnaseq_colnames])
consensus_rnaseq_matrix = sweep(consensus_rnaseq_matrix, 1, apply(consensus_rnaseq_matrix, 1, median, na.rm = T))
rnaseq_results = ConsensusClusterPlus(consensus_rnaseq_matrix, maxK = 13, reps = 1000, pItem = 0.8, pFeature = 1, title = title_rnaseq, clusterAlg = "hc", distance = "pearson", seed = 1234, plot = "png", innerLinkage = "complete", finalLinkage = "complete", corUse = "pairwise.complete.obs")
#extract consensus clustering
tmt_meta = merge(tmt_meta, as.data.frame(rnaseq_results[[5]]["consensusClass"]), by.x = "GenomicsSample", by.y = "row.names")
names(tmt_meta)[names(tmt_meta) == "consensusClass"] = "consensusClassK5_rnaseq"
#coloring to mirror the cc plots
setcolors = brewer.pal(5, "Set2")
k5_rnaseq_cc_group1_color = setcolors[1]
k5_rnaseq_cc_group2_color = setcolors[2]
k5_rnaseq_cc_group3_color = setcolors[3]
k5_rnaseq_cc_group4_color = setcolors[4]
k5_rnaseq_cc_group5_color = setcolors[5]
#order RNAseq meta by cc clustering
tmt_meta = tmt_meta[order(tmt_meta$consensusClassK5_rnaseq), ] #order according to consensus class for displaying mutations and classifications
gene_mutations_for_heatmap = c("TP53", "MLL2", "NFE2L2", "CDKN2A", "NOTCH1", "APC", "KEAP1", "PIK3CA", "PTEN", "RB1")
k5_rnaseq_coloring = tmt_meta[, rev(c(gene_mutations_for_heatmap, "Classification_rnaseq", "consensusClassK5_rnaseq"))]
k5_rnaseq_coloring$consensusClassK5_rnaseq = str_replace(k5_rnaseq_coloring$consensusClassK5_rnaseq, "^1$", fixed(k5_rnaseq_cc_group1_color))
k5_rnaseq_coloring$consensusClassK5_rnaseq = str_replace(k5_rnaseq_coloring$consensusClassK5_rnaseq, "^2$", fixed(k5_rnaseq_cc_group2_color))
k5_rnaseq_coloring$consensusClassK5_rnaseq = str_replace(k5_rnaseq_coloring$consensusClassK5_rnaseq, "^3$", fixed(k5_rnaseq_cc_group3_color))
k5_rnaseq_coloring$consensusClassK5_rnaseq = str_replace(k5_rnaseq_coloring$consensusClassK5_rnaseq, "^4$", fixed(k5_rnaseq_cc_group4_color))
k5_rnaseq_coloring$consensusClassK5_rnaseq = str_replace(k5_rnaseq_coloring$consensusClassK5_rnaseq, "^5$", fixed(k5_rnaseq_cc_group5_color))
k5_rnaseq_coloring$Classification_rnaseq = str_replace(k5_rnaseq_coloring$Classification_rnaseq, "classical", "red")
k5_rnaseq_coloring$Classification_rnaseq = str_replace(k5_rnaseq_coloring$Classification_rnaseq, "basal", "blue")
k5_rnaseq_coloring$Classification_rnaseq = str_replace(k5_rnaseq_coloring$Classification_rnaseq, "secretory", "green")
k5_rnaseq_coloring$Classification_rnaseq = str_replace(k5_rnaseq_coloring$Classification_rnaseq, "primitive", "black")
k5_rnaseq_coloring[, gene_mutations_for_heatmap] = apply(k5_rnaseq_coloring[, gene_mutations_for_heatmap], 2, function(x) { str_replace(x, "mut", "aquamarine4")})
k5_rnaseq_coloring[, gene_mutations_for_heatmap] = apply(k5_rnaseq_coloring[, gene_mutations_for_heatmap], 2, function(x) { str_replace(x, "wt", "lightgrey")})
k5_rnaseq_coloring[, gene_mutations_for_heatmap] = apply(k5_rnaseq_coloring[, gene_mutations_for_heatmap], 2, function(x) { str_replace(x, "trunc", "aquamarine")})
colnames(k5_rnaseq_coloring)[colnames(k5_rnaseq_coloring) == "consensusClassK5_rnaseq"] = "RNAseq"
colnames(k5_rnaseq_coloring)[colnames(k5_rnaseq_coloring) == "Classification_rnaseq"] = "Wilkerson"
heatmap_obj = heatmap.4(rnaseq_expression_heatmap[, tmt_meta$GenomicsSample], Colv = FALSE, col = bluered, trace = "none", density.info = "none", main = "", scale = "row", dendrogram = "none", labRow = FALSE, labCol = FALSE, ColSideColors = as.matrix(k5_rnaseq_coloring), margins = c(2,2), ColSideColorsSize = 16, xlab = "Patients", ylab = "Genes", na.color = "darkgrey", breaks = c(-2, seq(-2, 0, length = 50), seq(0, 2, length = 50)), distfun = function(c){as.dist(1 - cor(t(c), use = "pairwise.complete.obs"))})
legend("bottomleft", legend = c("WT", "Mut", "Trunc", "Classical", "Basal", "Secretory", "Primitive"), fill = c("lightgrey", "aquamarine4", "aquamarine", "red", "blue", "green", "black"), cex = 1)
#protein consensus cluster ----
protein_expression$sd = apply(protein_expression[, tumor_tmt_colnames], 1, function(x) {
sd(na.omit(x))
})
protein_expression$mean = apply(protein_expression[, tumor_tmt_colnames], 1, function(x) {
mean(na.omit(x))
})
protein_expression$mads = apply(protein_expression[, tumor_tmt_colnames], 1, function(x) {
mad(na.omit(x))
})
protein_expression$na_count = rowSums(is.na(protein_expression[, tumor_tmt_colnames]))
protein_expression_10pct = subset(protein_expression, na_count < number_of_samples * 0.1 ) #10% missingness
protein_expression_heatmap = protein_expression_10pct[rev(order(protein_expression_10pct$mads))[1:1000], tumor_tmt_colnames]
row.names(protein_expression_heatmap) = protein_expression_10pct[rev(order(protein_expression_10pct$mads))[1:1000], "Symbol"]
protein_expression_heatmap = protein_expression_10pct[rev(order(protein_expression_10pct$mads))[1:1000], c("Accession", "Symbol", tumor_tmt_colnames)]
title_protein = tempdir()
consensus_protein_matrix = as.matrix(protein_expression_heatmap[, tumor_tmt_colnames])
consensus_protein_matrix = sweep(consensus_protein_matrix, 1, apply(consensus_protein_matrix, 1, median, na.rm= T))
protein_results = ConsensusClusterPlus(consensus_protein_matrix, maxK = 13, reps= 1000, pItem= 0.8, pFeature= 1, title = title_protein, clusterAlg= "hc", distance= "pearson", seed= 1234, plot= "png", innerLinkage = "complete", finalLinkage = "complete", corUse = "pairwise.complete.obs")
#extract consensus clustering into tmt_meta file
tmt_meta = merge(tmt_meta, as.data.frame(protein_results[[4]]["consensusClass"]), by.x = "TissueID", by.y = "row.names")
names(tmt_meta)[names(tmt_meta) == "consensusClass"] = "consensusClassK4_protein"
tmt_meta = merge(tmt_meta, as.data.frame(protein_results[[5]]["consensusClass"]), by.x = "TissueID", by.y = "row.names")
names(tmt_meta)[names(tmt_meta) == "consensusClass"] = "consensusClassK5_protein"
#protein subtype
tmt_meta$subtype = NA
for (i in 1:nrow(tmt_meta)) {
if (tmt_meta$consensusClassK5_protein[i] == 1 | tmt_meta$consensusClassK5_protein[i] == 3) {
tmt_meta$subtype[i] = "Inflamed" #immune lump group
}
if (tmt_meta$consensusClassK5_protein[i] == 2 | tmt_meta$consensusClassK5_protein[i] == 4) {
tmt_meta$subtype[i] = "Redox" #metabolism lump group
}
if (tmt_meta$consensusClassK5_protein[i] == 5) {
tmt_meta$subtype[i] = "Mixed" #mixed lump group
}
}
#protein subtype numeric
tmt_meta$subtype_numeric = NA
for (i in 1:nrow(tmt_meta)) {
if (tmt_meta$consensusClassK5_protein[i] == 1 | tmt_meta$consensusClassK5_protein[i] == 3) {
tmt_meta$subtype_numeric[i] = 1 #immune lump group
}
if (tmt_meta$consensusClassK5_protein[i] == 2 | tmt_meta$consensusClassK5_protein[i] == 4) {
tmt_meta$subtype_numeric[i] = 2 #metabolism lump group
}
if (tmt_meta$consensusClassK5_protein[i] == 5) {
tmt_meta$subtype_numeric[i] = 3 #mixed lump group
}
}
#protein heatmaps ----
k4_protein_cc_group1_color = "#33A22B"
k4_protein_cc_group2_color = "#B1DF8A"
k4_protein_cc_group3_color = "#A5CEE2"
k4_protein_cc_group4_color = "#F89998"
darkcolors = brewer.pal(5, "Dark2")
k5_protein_cc_group1_color = darkcolors[1]
k5_protein_cc_group3_color = darkcolors[1]
k5_protein_cc_group2_color = darkcolors[2]
k5_protein_cc_group4_color = darkcolors[2]
k5_protein_cc_group5_color = darkcolors[3]
#re-cluster groups defined by consesnsus clustering for visualizing expression in the heatmap
protein_expression_heatmap_group1 = scale(protein_expression_heatmap[, subset(tmt_meta, consensusClassK5_protein == 1)$TissueID], center = TRUE)
protein_expression_heatmap_group1_dist = as.dist(1 - cor(protein_expression_heatmap_group1, use = "pairwise.complete.obs"))
protein_expression_heatmap_group1_clust = hclust(protein_expression_heatmap_group1_dist, method = "complete")
protein_expression_heatmap_group1_order = colnames(protein_expression_heatmap_group1)[protein_expression_heatmap_group1_clust$order]
protein_expression_heatmap_group2 = scale(protein_expression_heatmap[, subset(tmt_meta, consensusClassK5_protein == 2)$TissueID], center = TRUE)
protein_expression_heatmap_group2_dist = as.dist(1 - cor(protein_expression_heatmap_group2, use = "pairwise.complete.obs"))
protein_expression_heatmap_group2_clust = hclust(protein_expression_heatmap_group2_dist, method = "complete")
protein_expression_heatmap_group2_order = colnames(protein_expression_heatmap_group2)[protein_expression_heatmap_group2_clust$order]
protein_expression_heatmap_group3 = scale(protein_expression_heatmap[, subset(tmt_meta, consensusClassK5_protein == 3)$TissueID], center = TRUE)
protein_expression_heatmap_group3_dist = as.dist(1 - cor(protein_expression_heatmap_group3, use = "pairwise.complete.obs"))
protein_expression_heatmap_group3_clust = hclust(protein_expression_heatmap_group3_dist, method = "complete")
protein_expression_heatmap_group3_order = colnames(protein_expression_heatmap_group3)[protein_expression_heatmap_group3_clust$order]
protein_expression_heatmap_group4 = scale(protein_expression_heatmap[, subset(tmt_meta, consensusClassK5_protein == 4)$TissueID], center = TRUE)
protein_expression_heatmap_group4_dist = as.dist(1 - cor(protein_expression_heatmap_group4, use = "pairwise.complete.obs"))
protein_expression_heatmap_group4_clust = hclust(protein_expression_heatmap_group4_dist, method = "complete")
protein_expression_heatmap_group4_order = colnames(protein_expression_heatmap_group4)[protein_expression_heatmap_group4_clust$order]
protein_expression_heatmap_group5 = scale(protein_expression_heatmap[, subset(tmt_meta, consensusClassK5_protein == 5)$TissueID], center = TRUE)
protein_expression_heatmap_group5_dist = as.dist(1 - cor(protein_expression_heatmap_group5, use = "pairwise.complete.obs"))
protein_expression_heatmap_group5_clust = hclust(protein_expression_heatmap_group5_dist, method = "complete")
protein_expression_heatmap_group5_order = colnames(protein_expression_heatmap_group5)[protein_expression_heatmap_group5_clust$order]
final_heatmap_ordering = c(protein_expression_heatmap_group1_order, protein_expression_heatmap_group3_order, protein_expression_heatmap_group2_order, protein_expression_heatmap_group4_order, protein_expression_heatmap_group5_order)
tmt_meta = tmt_meta[match(final_heatmap_ordering, tmt_meta$TissueID), ] #match the final ordering to the metadata
#matrix
k5_protein_coloring = tmt_meta[, rev(c(gene_mutations_for_heatmap, "Classification_rnaseq", "consensusClassK5_rnaseq", "consensusClassK5_protein"))]
k5_protein_coloring$consensusClassK5_rnaseq = str_replace(k5_protein_coloring$consensusClassK5_rnaseq, "^1$", fixed(k5_rnaseq_cc_group1_color))
k5_protein_coloring$consensusClassK5_rnaseq = str_replace(k5_protein_coloring$consensusClassK5_rnaseq, "^2$", fixed(k5_rnaseq_cc_group2_color))
k5_protein_coloring$consensusClassK5_rnaseq = str_replace(k5_protein_coloring$consensusClassK5_rnaseq, "^3$", fixed(k5_rnaseq_cc_group3_color))
k5_protein_coloring$consensusClassK5_rnaseq = str_replace(k5_protein_coloring$consensusClassK5_rnaseq, "^4$", fixed(k5_rnaseq_cc_group4_color))
k5_protein_coloring$consensusClassK5_rnaseq = str_replace(k5_protein_coloring$consensusClassK5_rnaseq, "^5$", fixed(k5_rnaseq_cc_group5_color))
k5_protein_coloring$Classification_rnaseq = str_replace(k5_protein_coloring$Classification_rnaseq, "classical", "red")
k5_protein_coloring$Classification_rnaseq = str_replace(k5_protein_coloring$Classification_rnaseq, "basal", "blue")
k5_protein_coloring$Classification_rnaseq = str_replace(k5_protein_coloring$Classification_rnaseq, "secretory", "green")
k5_protein_coloring$Classification_rnaseq = str_replace(k5_protein_coloring$Classification_rnaseq, "primitive", "black")
k5_protein_coloring[, gene_mutations_for_heatmap] = apply(k5_protein_coloring[, gene_mutations_for_heatmap], 2, function(x) { str_replace(x, "mut", "#4DAF4A")})
k5_protein_coloring[, gene_mutations_for_heatmap] = apply(k5_protein_coloring[, gene_mutations_for_heatmap], 2, function(x) { str_replace(x, "wt", "lightgrey")})
k5_protein_coloring[, gene_mutations_for_heatmap] = apply(k5_protein_coloring[, gene_mutations_for_heatmap], 2, function(x) { str_replace(x, "trunc", "#984EA3")})
k5_protein_coloring$consensusClassK5_protein = str_replace(k5_protein_coloring$consensusClassK5_protein, "^1$", fixed(k5_protein_cc_group1_color))
k5_protein_coloring$consensusClassK5_protein = str_replace(k5_protein_coloring$consensusClassK5_protein, "^2$", fixed(k5_protein_cc_group2_color))
k5_protein_coloring$consensusClassK5_protein = str_replace(k5_protein_coloring$consensusClassK5_protein, "^3$", fixed(k5_protein_cc_group3_color))
k5_protein_coloring$consensusClassK5_protein = str_replace(k5_protein_coloring$consensusClassK5_protein, "^4$", fixed(k5_protein_cc_group4_color))
k5_protein_coloring$consensusClassK5_protein = str_replace(k5_protein_coloring$consensusClassK5_protein, "^5$", fixed(k5_protein_cc_group5_color))
k5_protein_coloring$CD3 = str_replace(k5_protein_coloring$CD3, "high", "darkred")
k5_protein_coloring$CD3 = str_replace(k5_protein_coloring$CD3, "low", "steelblue")
k5_protein_coloring$CD4 = str_replace(k5_protein_coloring$CD4, "high", "darkred")
k5_protein_coloring$CD4 = str_replace(k5_protein_coloring$CD4, "low", "steelblue")
k5_protein_coloring$CD8 = str_replace(k5_protein_coloring$CD8, "high", "darkred")
k5_protein_coloring$CD8 = str_replace(k5_protein_coloring$CD8, "low", "steelblue")
k5_protein_coloring$PDL1 = str_replace(k5_protein_coloring$PDL1, "high", "darkred")
k5_protein_coloring$PDL1 = str_replace(k5_protein_coloring$PDL1, "low", "steelblue")
k5_protein_coloring$PD1 = str_replace(k5_protein_coloring$PD1, "high", "darkred")
k5_protein_coloring$PD1 = str_replace(k5_protein_coloring$PD1, "low", "steelblue")
k5_protein_coloring$TMB_status = str_replace(k5_protein_coloring$TMB_status, "high", "darkred")
k5_protein_coloring$TMB_status = str_replace(k5_protein_coloring$TMB_status, "low", "steelblue")
colnames(k5_protein_coloring)[colnames(k5_protein_coloring) == "consensusClassK5_rnaseq"] = "RNAseq"
colnames(k5_protein_coloring)[colnames(k5_protein_coloring) == "consensusClassK5_protein"] = "Proteomics Group"
colnames(k5_protein_coloring)[colnames(k5_protein_coloring) == "Classification_rnaseq"] = "Wilkerson et al."
heatmap_obj = heatmap.4(protein_expression_heatmap[, tmt_meta$TissueID], Colv = FALSE, col = bluered, trace = "none", density.info = "none", main = "", scale = "row", dendrogram = "none", labRow = FALSE, labCol = FALSE, ColSideColors = as.matrix(k5_protein_coloring[, c(19:ncol(k5_protein_coloring))]), ColSideColorsSize = 20, cexCol = 1.5, margins = c(2,2), na.color = "darkgrey", breaks = c(-2, seq(-2, 0, length = 50), seq(0, 2, length = 50)), xlab = "Patients", ylab = "Protein Expression", distfun = function(c){as.dist(1 - cor(t(c), use = "pairwise.complete.obs"))}, colsep = c(23, 43, 55, 94), sepcolor = "black")
legend("bottomleft", legend = c("WT", "Mut", "Trunc", "Classical", "Basal", "Secretory", "Primitive"), fill = c("lightgrey", "#4DAF4A", "#984EA3", "red", "blue", "green", "black"), cex = 1)
#heatmap object for dendrogram needs labeled rows or it defaults to the numeric row numbering from the original protein expression matrix
row.names(protein_expression_heatmap) = protein_expression_heatmap$Accession
heatmap_obj = heatmap.4(protein_expression_heatmap[, tmt_meta$TissueID], Colv = FALSE, col = bluered, trace = "none", density.info = "none", main = "", scale = "row", dendrogram = "none", labRow = protein_expression_heatmap$Accession, labCol = FALSE, ColSideColors = as.matrix(k5_protein_coloring[, c(19:ncol(k5_protein_coloring))]), ColSideColorsSize = 20, cexCol = 1.5, margins = c(2,2), na.color = "darkgrey", breaks = c(-2, seq(-2, 0, length = 50), seq(0, 2, length = 50)), xlab = "Patients", ylab = "Protein Expression", distfun = function(c){as.dist(1 - cor(t(c), use = "pairwise.complete.obs"))}, colsep = c(23, 43, 55, 94), sepcolor = "black")
#extract dendrogram
heat_hclust = heatmap_obj$rowDendrogram
#plot(heat_hclust, labels = FALSE, axes = FALSE)
#labels_colors(heat_hclust) = c("red", "black", "blue", "green", "darkred")
plot(heat_hclust)
#plot(color_branches(heat_hclust, k = 7))
#heat_hclust_cut = cutree(heat_hclust, k = 7)
#heat_hclust_cut = cutree(heat_hclust, h = 1.4)
cut_at = 1.5
plot(color_branches(heat_hclust, h = cut_at, labels = F))
cutree(heat_hclust, h = cut_at)[heatmap_obj$rowInd]
heat_cut_table = as.data.frame(cutree(heat_hclust, h = cut_at)[heatmap_obj$rowInd])
names(heat_cut_table) = "cluster"
paste(row.names(subset(heat_cut_table, heat_cut_table$cluster == 1)), collapse = ",")
#reversed order of heatmap
unique(heat_cut_table$cluster)
#1.4
#[1] 5 6 3 2 7 4 1
#1.5
#[1] 4 3 2 5 1
heat_cut_table = merge(heat_cut_table, protein_expression_10pct[, c("Symbol", "Accession")], by.x = "row.names", by.y = "Accession", sort = FALSE)
names(heat_cut_table) = c("Acession", "cluster", "Symbol")
heat_cut_table = heat_cut_table[, c(3, 1, 2)]
subset(heat_cut_table, cluster == 1)$Symbol
#sorted by padj, get top hit
#4 bicarbonate transport (GO:0015701) padj 0.0003474
#3 glutathione metabolic process (GO:0006749) padj 4.053e-10
#2 platelet degranulation (GO:0002576) padj 1.453e-19
#5 extracellular matrix organization (GO:0030198) padj 9.660e-22
#1 neutrophil degranulation (GO:0043312) padj 4.944e-21
#correlation: protein/rnaseq ----
protein_rnaseq_expression_for_correlations = merge(protein_expression_10pct , rnaseq_expression, by.x = "Symbol", by.y = "Symbol")
correlation_table_rnaseq_by_gene = data.frame(Accession = protein_rnaseq_expression_for_correlations$Symbol, spearman_corr = NA, stringsAsFactors = FALSE)
for (i in 1:nrow(protein_rnaseq_expression_for_correlations)) {
corr_result = tryCatch({
proteins_for_corr = as.numeric(protein_rnaseq_expression_for_correlations[i, tmt_meta$TissueID])
genes_for_corr = as.numeric(protein_rnaseq_expression_for_correlations[i, tmt_meta$GenomicsSample])
if (sum(!is.na(proteins_for_corr)) >= number_of_samples * 0.1 & sum(!is.na(genes_for_corr)) >= number_of_samples * 0.1) {
cor.test(proteins_for_corr, genes_for_corr, method = "spearman", use = "pairwise.complete.obs")
} else {
NA
}
}, error = function(e) {
NA
})
if (is.na(corr_result)) {
correlation_table_rnaseq_by_gene$spearman_corr[i] = NA
correlation_table_rnaseq_by_gene$pval[i] = NA
} else {
correlation_table_rnaseq_by_gene$spearman_corr[i] = corr_result$estimate
correlation_table_rnaseq_by_gene$pval[i] = corr_result$p.value
}
}
correlation_table_rnaseq_by_gene$padj = p.adjust(correlation_table_rnaseq_by_gene$pval, method = "BH")
correlation_table_rnaseq_by_gene$plot_color = NA
correlation_table_rnaseq_by_gene$plot_color[correlation_table_rnaseq_by_gene$spearman_corr > 0] = "red"
correlation_table_rnaseq_by_gene$plot_color[correlation_table_rnaseq_by_gene$spearman_corr <= 0] = "blue"
hist(correlation_table_rnaseq_by_gene$spearman_corr, breaks = 50, col = c(rep("blue", 12), rep("red", 37)), main = "", xlab = "", xlim = c(-1, 1), yaxt = "n", ylab = "", ylim = c(0, 400), cex.axis = 3, cex.lab = 3)
axis(side = 2, at = seq(0, 400, 100), cex.axis = 3)
meanspear = mean(na.omit(correlation_table_rnaseq_by_gene$spearman_corr))
abline(v = meanspear, lwd = 2, lty = "dashed")
text(x = meanspear - 0.45, y = 400, paste("Mean = ", round(meanspear, 2)), pos = 1, cex = 3)
correlation_table_rnaseq_by_gene = correlation_table_rnaseq_by_gene[order(correlation_table_rnaseq_by_gene$spearman_corr), ]
png("output/main/pathway_correlation_waterfall_plot_2018-12-06.png", width = 1600, height = 1600)
plot(0, type = "n", xlim = c(1, nrow(correlation_table_rnaseq_by_gene)), ylim = c(-12, 1), xlab = "", ylab = "", bty = "n", xaxt = "n", yaxt = "n")
axis(side = 2, at = c(-1, 0, 1), cex.axis = 2)
segments(x0 = 1:nrow(correlation_table_rnaseq_by_gene), y0 = 0, x1 = 1:nrow(correlation_table_rnaseq_by_gene), y1 = correlation_table_rnaseq_by_gene$spearman_corr, col = correlation_table_rnaseq_by_gene$plot_color)
#mtext("SpearmanCorrelation", side = 2, adj = 1, line = 2)
text_start_y = -1.5
y0_start = text_start_y - 0.25
y1_start = text_start_y - 0.75
text(x = 0, y = text_start_y, "neutrophil degranulation (GO:0043312)", offset = 0, pos = 4, cex = 3)
neutrophil_genes = pathway_list$`neutrophil degranulation (GO:0043312)`
neutrophil_df_for_corr_plot = subset(correlation_table_rnaseq_by_gene, Accession %in% neutrophil_genes)
segments(x0 = which(correlation_table_rnaseq_by_gene$Accession %in% neutrophil_df_for_corr_plot$Accession), y0 = y0_start, x1 = which(correlation_table_rnaseq_by_gene$Accession %in% neutrophil_df_for_corr_plot$Accession), y1 = y1_start, col = correlation_table_rnaseq_by_gene$plot_color[which(correlation_table_rnaseq_by_gene$Accession %in% neutrophil_df_for_corr_plot$Accession)])
text(x = 0, y = text_start_y - 1, "extracellular matrix organization (GO:0030198)", offset = 0, pos = 4, cex = 3)
ecm_genes = pathway_list$`extracellular matrix organization (GO:0030198)`
ecm_df_for_corr_plot = subset(correlation_table_rnaseq_by_gene, Accession %in% ecm_genes)
segments(x0 = which(correlation_table_rnaseq_by_gene$Accession %in% ecm_df_for_corr_plot$Accession), y0 = y0_start - 1, x1 = which(correlation_table_rnaseq_by_gene$Accession %in% ecm_df_for_corr_plot$Accession), y1 = y1_start - 1, col = correlation_table_rnaseq_by_gene$plot_color[which(correlation_table_rnaseq_by_gene$Accession %in% ecm_df_for_corr_plot$Accession)])
text(x = 0, y = text_start_y - 2, "negative regulation of apoptotic process (GO:0043066)", offset = 0, pos = 4, cex = 3)
apoptosis_genes = pathway_list$`negative regulation of apoptotic process (GO:0043066)`
apoptosis_df_for_corr_plot = subset(correlation_table_rnaseq_by_gene, Accession %in% apoptosis_genes)
segments(x0 = which(correlation_table_rnaseq_by_gene$Accession %in% apoptosis_df_for_corr_plot$Accession), y0 = y0_start - 2, x1 = which(correlation_table_rnaseq_by_gene$Accession %in% apoptosis_df_for_corr_plot$Accession), y1 = y1_start - 2, col = correlation_table_rnaseq_by_gene$plot_color[which(correlation_table_rnaseq_by_gene$Accession %in% apoptosis_df_for_corr_plot$Accession)])
text(x = 0, y = text_start_y - 3, "cellular response to oxidative stress (GO:0034599)", offset = 0, pos = 4, cex = 3)
oxstress_genes = pathway_list$`cellular response to oxidative stress (GO:0034599)`
oxstress_df_for_corr_plot = subset(correlation_table_rnaseq_by_gene, Accession %in% oxstress_genes)
segments(x0 = which(correlation_table_rnaseq_by_gene$Accession %in% oxstress_df_for_corr_plot$Accession), y0 = y0_start - 3, x1 = which(correlation_table_rnaseq_by_gene$Accession %in% oxstress_df_for_corr_plot$Accession), y1 = y1_start - 3, col = correlation_table_rnaseq_by_gene$plot_color[which(correlation_table_rnaseq_by_gene$Accession %in% oxstress_df_for_corr_plot$Accession)])
text(x = 0, y = text_start_y - 4, "canonical glycolysis (GO:0061621)", offset = 0, pos = 4, cex = 3)
glycolysis_genes = pathway_list$`canonical glycolysis (GO:0061621)`
glycolysis_df_for_corr_plot = subset(correlation_table_rnaseq_by_gene, Accession %in% glycolysis_genes)
segments(x0 = which(correlation_table_rnaseq_by_gene$Accession %in% glycolysis_df_for_corr_plot$Accession), y0 = y0_start - 4, x1 = which(correlation_table_rnaseq_by_gene$Accession %in% glycolysis_df_for_corr_plot$Accession), y1 = y1_start - 4, col = correlation_table_rnaseq_by_gene$plot_color[which(correlation_table_rnaseq_by_gene$Accession %in% glycolysis_df_for_corr_plot$Accession)])
#well correlated
# neutrophil degranulation (GO:0043312)
# extracellular matrix organization (GO:0030198)
# negative regulation of apoptotic process (GO:0043066)
# cellular response to oxidative stress (GO:0034599)
# canonical glycolysis (GO:0061621)
abline(h = text_start_y - 4.8, lty = 2)
text(x = 0, y = text_start_y - 5, "SRP targeting to membrane (GO:0006614)", offset = 0, pos = 4, cex = 3)
srp_genes = pathway_list$`SRP-dependent cotranslational protein targeting to membrane (GO:0006614)`
srp_df_for_corr_plot = subset(correlation_table_rnaseq_by_gene, Accession %in% srp_genes)
segments(x0 = which(correlation_table_rnaseq_by_gene$Accession %in% srp_df_for_corr_plot$Accession), y0 = y0_start - 5, x1 = which(correlation_table_rnaseq_by_gene$Accession %in% srp_df_for_corr_plot$Accession), y1 = y1_start - 5, col = correlation_table_rnaseq_by_gene$plot_color[which(correlation_table_rnaseq_by_gene$Accession %in% srp_df_for_corr_plot$Accession)])
text(x = 0, y = text_start_y - 6, "nonsense-mediated decay (GO:0000184)", offset = 0, pos = 4, cex = 3)
nmd_genes = pathway_list$`nuclear-transcribed mRNA catabolic process, nonsense-mediated decay (GO:0000184)`
nmd_df_for_corr_plot = subset(correlation_table_rnaseq_by_gene, Accession %in% nmd_genes)
segments(x0 = which(correlation_table_rnaseq_by_gene$Accession %in% nmd_df_for_corr_plot$Accession), y0 = y0_start - 6, x1 = which(correlation_table_rnaseq_by_gene$Accession %in% nmd_df_for_corr_plot$Accession), y1 = y1_start - 6, col = correlation_table_rnaseq_by_gene$plot_color[which(correlation_table_rnaseq_by_gene$Accession %in% nmd_df_for_corr_plot$Accession)])
text(x = 0, y = text_start_y - 7, "rRNA processing (GO:0006364)", offset = 0, pos = 4, cex = 3)
rrna_genes = pathway_list$`rRNA processing (GO:0006364)`
rrna_df_for_corr_plot = subset(correlation_table_rnaseq_by_gene, Accession %in% rrna_genes)
segments(x0 = which(correlation_table_rnaseq_by_gene$Accession %in% rrna_df_for_corr_plot$Accession), y0 = y0_start - 7, x1 = which(correlation_table_rnaseq_by_gene$Accession %in% rrna_df_for_corr_plot$Accession), y1 = y1_start - 7, col = correlation_table_rnaseq_by_gene$plot_color[which(correlation_table_rnaseq_by_gene$Accession %in% rrna_df_for_corr_plot$Accession)])
text(x = 0, y = text_start_y - 8, "translational initiation (GO:0006413)", offset = 0, pos = 4, cex = 3)
transinit_genes = pathway_list$`translational initiation (GO:0006413)`
transinit_df_for_corr_plot = subset(correlation_table_rnaseq_by_gene, Accession %in% transinit_genes)
segments(x0 = which(correlation_table_rnaseq_by_gene$Accession %in% transinit_df_for_corr_plot$Accession), y0 = y0_start - 8, x1 = which(correlation_table_rnaseq_by_gene$Accession %in% transinit_df_for_corr_plot$Accession), y1 = y1_start - 8, col = correlation_table_rnaseq_by_gene$plot_color[which(correlation_table_rnaseq_by_gene$Accession %in% transinit_df_for_corr_plot$Accession)])
text(x = 0, y = text_start_y - 9, "translation (GO:0006412)", offset = 0, pos = 4, cex = 3)
transl_genes = pathway_list$`translation (GO:0006412)`
transl_df_for_corr_plot = subset(correlation_table_rnaseq_by_gene, Accession %in% transl_genes)
segments(x0 = which(correlation_table_rnaseq_by_gene$Accession %in% transl_df_for_corr_plot$Accession), y0 = y0_start - 9, x1 = which(correlation_table_rnaseq_by_gene$Accession %in% transl_df_for_corr_plot$Accession), y1 = y1_start - 9, col = correlation_table_rnaseq_by_gene$plot_color[which(correlation_table_rnaseq_by_gene$Accession %in% transl_df_for_corr_plot$Accession)])
dev.off()
#poorly correlated
#SRP-dependent cotranslational protein targeting to membrane (GO:0006614)
#nuclear-transcribed mRNA catabolic process, nonsense-mediated decay (GO:0000184)
#rRNA processing (GO:0006364)
#translational initiation (GO:0006413)
#MAPK cascade (GO:0000165)
#pairwise comparison of sample groups ----
differential_expression = function(expression_in, condition1_samples_in, condition2_samples_in, accession_column = "Symbol", plot_title = "", plot_location = "output/main/") {
condition1_v_condition2_results_table = data.frame(Accession = expression_in[, accession_column], stringsAsFactors = FALSE)
condition1_v_condition2_results_table$condition1_log2_mean = apply(expression_in, 1, function(x) {
mean(na.omit(as.numeric(x[condition1_samples_in])))
})
condition1_v_condition2_results_table$condition2_log2_mean = apply(expression_in, 1, function(x){
mean(na.omit(as.numeric(x[condition2_samples_in])))
})
condition1_v_condition2_results_table$condition2_condition1_log2fc = condition1_v_condition2_results_table$condition2_log2_mean - condition1_v_condition2_results_table$condition1_log2_mean
condition1_v_condition2_results_table$wilcoxon_p = apply(expression_in, 1, function(x) {
tryCatch({wilcox.test(as.numeric(na.omit(x[condition1_samples_in])), as.numeric(na.omit(x[condition2_samples_in])))$p.value
},error = function(e) {
NA
})
})
condition1_v_condition2_results_table$wilcoxon_padj = p.adjust(condition1_v_condition2_results_table$wilcoxon_p, method = "BH")
condition1_v_condition2_results_table$volcano_colors = NA
condition1_v_condition2_results_table$volcano_text = NA
return(condition1_v_condition2_results_table)
}
#redox vs all with fold change
metabolism_proteincc_samples = subset(tmt_meta, consensusClassK5_protein == 2 | consensusClassK5_protein == 4)$TissueID
notmetabolism_proteincc_samples = subset(tmt_meta, consensusClassK5_protein != 2 & consensusClassK5_protein != 4)$TissueID
metabolism_notmetabolism_de = differential_expression(expression_in = protein_expression_10pct, condition1_samples_in = notmetabolism_proteincc_samples, condition2_samples_in = metabolism_proteincc_samples, plot_title = "metabolism vs notmetabolism", plot_location = "output/main/", accession_column = "Symbol")
paste(subset(metabolism_notmetabolism_de, abs(metabolism_notmetabolism_de$condition2_condition1_log2fc) >= log2(1.5) & metabolism_notmetabolism_de$wilcoxon_padj <= 0.05)$Accession, collapse = ",")
metabolism_de_genes = subset(metabolism_notmetabolism_de, abs(metabolism_notmetabolism_de$condition2_condition1_log2fc) >= log2(1.5) & metabolism_notmetabolism_de$wilcoxon_padj <= 0.05)$Accession
metabolismhigher_de_genes = subset(metabolism_notmetabolism_de, metabolism_notmetabolism_de$condition2_condition1_log2fc >= log2(1.5) & metabolism_notmetabolism_de$wilcoxon_padj <= 0.05)$Accession
metabolism_notmetabolism_de_enrichr = enrichr(subset(metabolism_notmetabolism_de, abs(metabolism_notmetabolism_de$condition2_condition1_log2fc) >= log2(1.5) & metabolism_notmetabolism_de$wilcoxon_padj <= 0.05)$Accession, "GO_Biological_Process_2017")
png(filename = "output/main/pathway_enrichment/metabolism_vs_all_protein_fc.png", width = 800, height = 400)
par(mar = c(5.1, 38, 2, 2.1))
plot_enrichr_results(enrichr_in = metabolism_notmetabolism_de_enrichr$GO_Biological_Process_2017, number_of_pathways_to_plot = 5, xlim_in = c(0, 40), ylim_in = c(0, 40), plot_title = "redox vs not redox")
dev.off()
metabolismhigher_notmetabolism_de_enrichr = enrichr(subset(metabolism_notmetabolism_de, metabolism_notmetabolism_de$condition2_condition1_log2fc >= log2(1.5) & metabolism_notmetabolism_de$wilcoxon_padj <= 0.05)$Accession, "GO_Biological_Process_2017")
paste(subset(metabolism_notmetabolism_de, metabolism_notmetabolism_de$condition2_condition1_log2fc >= log2(1.5) & metabolism_notmetabolism_de$wilcoxon_padj <= 0.05)$Accession, collapse = ",")
metabolismhigher_notmetabolism_de_proteins = subset(metabolism_notmetabolism_de, metabolism_notmetabolism_de$condition2_condition1_log2fc >= log2(1.5) & metabolism_notmetabolism_de$wilcoxon_padj <= 0.05)$Accession
metabolism_notmetabolismhigher_de_enrichr = enrichr(subset(metabolism_notmetabolism_de, metabolism_notmetabolism_de$condition2_condition1_log2fc <= log2(0.6667) & metabolism_notmetabolism_de$wilcoxon_padj <= 0.05)$Accession, "GO_Biological_Process_2017")
png(filename = "output/main/pathway_enrichment/metabolismhigher_vs_notmetabolism_protein_fc.png", width = 900, height = 200)
par(mar = c(5.1, 38, 2, 2.1))
plot_enrichr_results(enrichr_in = metabolismhigher_notmetabolism_de_enrichr$GO_Biological_Process_2017, number_of_pathways_to_plot = 5, xlim_in = c(0, 300), ylim_in = c(0, 10), plot_title = "")
dev.off()
#inflamed vs all with fold change
immune_proteincc_samples = subset(tmt_meta, consensusClassK5_protein == 1 | consensusClassK5_protein == 3)$TissueID
notimmune_proteincc_samples = subset(tmt_meta, consensusClassK5_protein != 1 & consensusClassK5_protein != 3)$TissueID
immune_notimmune_de = differential_expression(expression_in = protein_expression_10pct, condition1_samples_in = notimmune_proteincc_samples, condition2_samples_in = immune_proteincc_samples, plot_title = "immune vs notimmune", plot_location = "output/main/", accession_column = "Symbol")
paste(subset(immune_notimmune_de, abs(immune_notimmune_de$condition2_condition1_log2fc) >= log2(1.5) & immune_notimmune_de$wilcoxon_padj <= 0.05)$Accession, collapse = ",")
immune_de_genes = subset(immune_notimmune_de, abs(immune_notimmune_de$condition2_condition1_log2fc) >= log2(1.5) & immune_notimmune_de$wilcoxon_padj <= 0.05)$Accession
immunehigher_de_genes = subset(immune_notimmune_de, immune_notimmune_de$condition2_condition1_log2fc >= log2(1.5) & immune_notimmune_de$wilcoxon_padj <= 0.05)$Accession
immune_notimmune_de_enrichr = enrichr(subset(immune_notimmune_de, abs(immune_notimmune_de$condition2_condition1_log2fc) >= log2(1.5) & immune_notimmune_de$wilcoxon_padj <= 0.05)$Accession, "GO_Biological_Process_2017")
png(filename = "output/main/pathway_enrichment/immune_vs_all_protein_fc.png", width = 800, height = 400)
par(mar = c(5.1, 38, 2, 2.1))
plot_enrichr_results(enrichr_in = immune_notimmune_de_enrichr$GO_Biological_Process_2017, number_of_pathways_to_plot = 5, xlim_in = c(0, 40), ylim_in = c(0, 10), plot_title = "inflamed vs not inflamed")
dev.off()
immunehigher_notimmune_de_enrichr = enrichr(subset(immune_notimmune_de, immune_notimmune_de$condition2_condition1_log2fc >= log2(1.5) & immune_notimmune_de$wilcoxon_padj <= 0.05)$Accession, "GO_Biological_Process_2017")
immunehigher_notimmune_de_proteins = subset(immune_notimmune_de, immune_notimmune_de$condition2_condition1_log2fc >= log2(1.5) & immune_notimmune_de$wilcoxon_padj <= 0.05)$Accession
paste(subset(immune_notimmune_de, immune_notimmune_de$condition2_condition1_log2fc >= log2(1.5) & immune_notimmune_de$wilcoxon_padj <= 0.05)$Accession, collapse = ",")
immune_notimmunehigher_de_enrichr = enrichr(subset(immune_notimmune_de, immune_notimmune_de$condition2_condition1_log2fc <= log2(0.6667) & immune_notimmune_de$wilcoxon_padj <= 0.05)$Accession, "GO_Biological_Process_2017")
png(filename = "output/main/pathway_enrichment/immunehigher_vs_notimmune_protein_fc.png", width = 900, height = 200)
par(mar = c(5.1, 38, 2, 2.1))
plot_enrichr_results(enrichr_in = immunehigher_notimmune_de_enrichr$GO_Biological_Process_2017, number_of_pathways_to_plot = 5, xlim_in = c(0, 300), ylim_in = c(0, 10), plot_title = "")
dev.off()
#Mixed vs all with fold change
Mixed_proteincc_samples = subset(tmt_meta, consensusClassK5_protein == 5)$TissueID
notMixed_proteincc_samples = subset(tmt_meta, consensusClassK5_protein != 5)$TissueID
Mixed_notMixed_de = differential_expression(expression_in = protein_expression_10pct, condition1_samples_in = notMixed_proteincc_samples, condition2_samples_in = Mixed_proteincc_samples, plot_title = "Mixed vs notMixed", plot_location = "output/main/", accession_column = "Symbol")
paste(subset(Mixed_notMixed_de, abs(Mixed_notMixed_de$condition2_condition1_log2fc) >= log2(1.5) & Mixed_notMixed_de$wilcoxon_padj <= 0.05)$Accession, collapse = ",")
Mixed_de_genes = subset(Mixed_notMixed_de, abs(Mixed_notMixed_de$condition2_condition1_log2fc) >= log2(1.5) & Mixed_notMixed_de$wilcoxon_padj <= 0.05)$Accession
Mixedhigher_de_genes = subset(Mixed_notMixed_de, Mixed_notMixed_de$condition2_condition1_log2fc >= log2(1.5) & Mixed_notMixed_de$wilcoxon_padj <= 0.05)$Accession
Mixed_notMixed_de_enrichr = enrichr(subset(Mixed_notMixed_de, abs(Mixed_notMixed_de$condition2_condition1_log2fc) >= log2(1.5) & Mixed_notMixed_de$wilcoxon_padj <= 0.05)$Accession, "GO_Biological_Process_2017")
png(filename = "output/main/pathway_enrichment/Mixed_vs_all_protein_fc.png", width = 800, height = 200)
par(mar = c(5.1, 38, 2, 2.1))
plot_enrichr_results(enrichr_in = Mixed_notMixed_de_enrichr$GO_Biological_Process_2017, number_of_pathways_to_plot = 5, xlim_in = c(0, 40), ylim_in = c(0, 40), plot_title = "Mixed vs all")
dev.off()
Mixedhigher_notMixed_de_enrichr = enrichr(subset(Mixed_notMixed_de, Mixed_notMixed_de$condition2_condition1_log2fc >= log2(1.5) & Mixed_notMixed_de$wilcoxon_padj <= 0.05)$Accession, "GO_Biological_Process_2017")
Mixedhigher_notMixed_de_proteins = subset(Mixed_notMixed_de, Mixed_notMixed_de$condition2_condition1_log2fc >= log2(1.5) & Mixed_notMixed_de$wilcoxon_padj <= 0.05)$Accession
Mixed_notMixedhigher_de_enrichr = enrichr(subset(Mixed_notMixed_de, Mixed_notMixed_de$condition2_condition1_log2fc <= log2(0.6667) & Mixed_notMixed_de$wilcoxon_padj <= 0.05)$Accession, "GO_Biological_Process_2017")
png(filename = "output/main/pathway_enrichment/Mixedhigher_vs_notMixed_protein_fc.png", width = 900, height = 200)
par(mar = c(5.1, 38, 2, 2.1))
plot_enrichr_results(enrichr_in = Mixedhigher_notMixed_de_enrichr$GO_Biological_Process_2017, number_of_pathways_to_plot = 5, xlim_in = c(0, 300), ylim_in = c(0, 10), plot_title = "")
dev.off()
#ESTIMATE scores ----
#for headers with characters that R doesn't like, need to edit the score names by hand and replace some "." with "-"; checknames argument is not being run in the above ESTIMATE commands so the RNA sample names in the header might not match the ESTIMATE output
estimate_scores = read.delim("output/main/estimate_rnaseq_output_scores_2018-05-10.gct", header = TRUE, row.names = 1, stringsAsFactors = FALSE, skip = 2, check.names = FALSE)
estimate_scores$Description = NULL
Inflamed_stromal = estimate_scores["StromalScore", tmt_meta$GenomicsSample[tmt_meta$consensusClassK5_protein == 1 | tmt_meta$consensusClassK5_protein == 3]]
Inflamed_immune = estimate_scores["ImmuneScore", tmt_meta$GenomicsSample[tmt_meta$consensusClassK5_protein == 1 | tmt_meta$consensusClassK5_protein == 3]]
Inflamed_estimate = estimate_scores["ESTIMATEScore", tmt_meta$GenomicsSample[tmt_meta$consensusClassK5_protein == 1 | tmt_meta$consensusClassK5_protein == 3]]
Redox_stromal = estimate_scores["StromalScore", tmt_meta$GenomicsSample[tmt_meta$consensusClassK5_protein == 4 | tmt_meta$consensusClassK5_protein == 4]]
Redox_immune = estimate_scores["ImmuneScore", tmt_meta$GenomicsSample[tmt_meta$consensusClassK5_protein == 4 | tmt_meta$consensusClassK5_protein == 4]]
Redox_estimate = estimate_scores["ESTIMATEScore", tmt_meta$GenomicsSample[tmt_meta$consensusClassK5_protein == 4 | tmt_meta$consensusClassK5_protein == 4]]
Mixed_stromal = estimate_scores["StromalScore", tmt_meta$GenomicsSample[tmt_meta$consensusClassK5_protein == 5]]
Mixed_immune = estimate_scores["ImmuneScore", tmt_meta$GenomicsSample[tmt_meta$consensusClassK5_protein == 5]]
Mixed_estimate = estimate_scores["ESTIMATEScore", tmt_meta$GenomicsSample[tmt_meta$consensusClassK5_protein == 5]]
png(filename = "output/main/ESTIMATE_2018-06-18.png", width = 900, height = 500)
par(mfrow = c(1,3))
par(mar = c(8.1, 5.1, 4.1, 2.1))
boxplot(list("Inflamed" = as.numeric(Inflamed_immune), "Redox" = as.numeric(Redox_immune), "Mixed" = as.numeric(Mixed_immune)), ylab = "Score", main = "", cex.lab = 2, cex.axis = 2, col = c(darkcolors[1], darkcolors[2], darkcolors[3]))
boxplot(list("Inflamed" = as.numeric(Inflamed_stromal), "Redox" = as.numeric(Redox_stromal), "Mixed" = as.numeric(Mixed_stromal)), ylab = "Score", main = "", cex.lab = 2, cex.axis = 2, col = c(darkcolors[1], darkcolors[2], darkcolors[3]))
boxplot(list("Inflamed" = as.numeric(Inflamed_estimate), "Redox" = as.numeric(Redox_estimate), "Mixed" = as.numeric(Mixed_estimate)), ylab = "Score", main = "", cex.lab = 2, cex.axis = 2, col = c(darkcolors[1], darkcolors[2], darkcolors[3]))
dev.off()
#CNV data and prep RNA and protein for integration with CNV ----
cnv_data = read.delim("data/main/Gene_CNV_400kbp.50counts_noXYgene_2018-02-12.txt", header = TRUE, stringsAsFactors = FALSE, row.names = 1, check.names = FALSE)
cnv_meta = read.delim("data/main/original_data/cytoscan_run_batch_meta_09-25-17.txt", header = TRUE, stringsAsFactors = FALSE)
cnv_meta$duplicated = duplicated(cnv_meta$TissueID)
cnv_meta_duplicated = subset(cnv_meta, duplicated == TRUE)
cnv_meta_duplicated = subset(cnv_meta_duplicated, !(TissueID == "06S15101193" & Attempt == 2)) #duplicated twice in attempt 2 and attempt 3; remove
cnv_meta = subset(cnv_meta, !(TissueID %in% cnv_meta_duplicated$TissueID) & Attempt == 1 & DNA.Aliquot != "Positive_control") #get non-duplicated and non-control entries
cnv_meta = rbind(cnv_meta, cnv_meta_duplicated)
names(cnv_data) = str_replace(names(cnv_data), "^X0", "0")
tmt_meta_for_cnv = subset(tmt_meta, TissueID %in% names(cnv_data))
tmt_meta_for_cnv = merge(tmt_meta_for_cnv, cnv_meta, by = "TissueID")
cnv_data = cnv_data[, tmt_meta_for_cnv$TissueID]
rnaseq_expression_for_cnv = rnaseq_expression
row.names(rnaseq_expression_for_cnv) = rnaseq_expression_for_cnv$Symbol
rnaseq_expression_for_cnv$Symbol = NULL
rnaseq_expression_for_cnv = rnaseq_expression_for_cnv[, tmt_meta_for_cnv$GenomicsSample]
names(cnv_data) = tmt_meta_for_cnv$TissueID
names(rnaseq_expression_for_cnv) = tmt_meta_for_cnv$TissueID
protein_expression_for_cnv = protein_expression_10pct[, c("Symbol", tmt_meta_for_cnv$TissueID)]
protein_expression_for_cnv = protein_expression_for_cnv[!duplicated(protein_expression_for_cnv$Symbol), ]
row.names(protein_expression_for_cnv) = protein_expression_for_cnv$Symbol
cnv_protein_merged = merge(cnv_data, protein_expression_for_cnv, by.x = "row.names", by.y = "Symbol")
#CNV correlation with protein ----
cnv_protein_merged[cnv_protein_merged == 0] = NA
correlation_table_cnv_protein = data.frame(Accession = cnv_protein_merged$Row.names, spearman_corr = NA, stringsAsFactors = FALSE)
for (i in 1:nrow(cnv_protein_merged)) {
corr_result = tryCatch({
cnv_for_corr = as.numeric(cnv_protein_merged[i, paste(tmt_meta_for_cnv$TissueID, "x", sep = ".")])
proteins_for_corr = as.numeric(cnv_protein_merged[i, paste(tmt_meta_for_cnv$TissueID, "y", sep = ".")])
if (sum(!is.na(proteins_for_corr)) >= number_of_samples * 0.1 & sum(!is.na(cnv_for_corr)) >= number_of_samples * 0.1) {
cor.test(proteins_for_corr, cnv_for_corr, method = "spearman", use = "pairwise.complete.obs")
} else {
NA
}
}, error = function(e) {
NA
})
if (is.na(corr_result)) {
correlation_table_cnv_protein$spearman_corr[i] = NA
correlation_table_cnv_protein$pval[i] = NA
} else {
correlation_table_cnv_protein$spearman_corr[i] = corr_result$estimate
correlation_table_cnv_protein$pval[i] = corr_result$p.value
}
}
correlation_table_cnv_protein$padj = p.adjust(correlation_table_cnv_protein$pval, method = "BH")
correlation_table_cnv_protein$hist_color = NA
correlation_table_cnv_protein$hist_color[correlation_table_cnv_protein$spearman_corr > 0] = "red"
correlation_table_cnv_protein$hist_color[correlation_table_cnv_protein$spearman_corr <= 0] = "blue"
hist(correlation_table_cnv_protein$spearman_corr, breaks = 50, col = c(rep("blue", 20), rep("red", 37)), main = "", xlab = "Spearman's Correlation", xlim = c(-1, 1), yaxt = "n", ylab = "Count", ylim = c(0, 300), cex.axis = 1.5, cex.lab = 1.5)
axis(side = 2, at = seq(0, 500, 100), cex.axis = 1.5)
meanspear = mean(na.omit(correlation_table_cnv_protein$spearman_corr))
abline(v = meanspear, lwd = 2, lty = "dashed")
text(x = meanspear + .4, y = 315, paste("Mean = ", round(meanspear, 2)), pos = 1, cex = 1.5)
#poster
png("output/main/rnaseq_protein_cnv_protein_correlation_histograms_2018-06-21.png", width = 1200, height = 800)
par(mfrow = c(1, 2))
hist(correlation_table_cnv_protein$spearman_corr, breaks = 50, col = c(rep("blue", 28), rep("red", 37)), main = "", xlab = "", xlim = c(-1, 1), yaxt = "n", ylab = "", ylim = c(0, 400), cex.axis = 2, cex.lab = 2)
axis(side = 2, at = seq(0, 400, 100), cex.axis = 2)
meanspear = mean(na.omit(correlation_table_cnv_protein$spearman_corr))
hist(correlation_table_rnaseq_by_gene$spearman_corr, breaks = 50, col = c(rep("blue", 21), rep("red", 37)), main = "", xlab = "", xlim = c(-1, 1), yaxt = "n", ylab = "", ylim = c(0, 400), cex.axis = 2, cex.lab = 2)
axis(side = 2, at = seq(0, 400, 100), cex.axis = 2)
dev.off()
#combine rna-protein and cn-protein tables for paper
correlation_table_rna_protein_cn_protein = merge(correlation_table_rnaseq_by_gene, correlation_table_cnv_protein, by = "Accession", all = TRUE)
correlation_table_cnv_protein_positive = subset(correlation_table_cnv_protein, spearman_corr > 0.5 & padj < 0.25)
correlation_table_rnaseq_by_gene_positive = subset(correlation_table_rnaseq_by_gene, spearman_corr > 0.5 & padj < 0.25)
correlation_table_cnv_protein_positive_matched = subset(correlation_table_cnv_protein_positive, Accession %in% correlation_table_rnaseq_by_gene_positive$Accession)
dim(correlation_table_cnv_protein_positive_matched)
metabolism_correlations = correlation_table_cnv_protein_positive_matched[correlation_table_cnv_protein_positive_matched$hgnc_symbol %in% metabolismhigher_de_genes, ]
metabolism_correlations[order(metabolism_correlations$chromosome_name), ]
#TCGA mut status comparisons ----
tcga_meta = read.delim("data/main/tcga_classification_with_mut_2018-03-06.txt", header = TRUE, stringsAsFactors = FALSE)
tcga_meta[is.na(tcga_meta)] = "wt"
tcga_meta[tcga_meta == ""] = "wt"
table(subset(tcga_meta, tcga_meta$Classification == "secretory")$TP53 == "wt")
table(subset(tcga_meta, tcga_meta$Classification != "secretory")$TP53 == "wt")
table(subset(tmt_meta, subtype == "Inflamed")$TP53 == "wt")
table(subset(tmt_meta, subtype != "Inflamed")$TP53 == "wt")
table(subset(tcga_meta, Classification == "classical")$NFE2L2 != "wt")
table(subset(tmt_meta, subtype == "Redox")$NFE2L2 != "wt")
table(subset(tmt_meta, subtype == "Redox")$KEAP1 != "wt")
nrow(subset(tmt_meta, NFE2L2 != "wt" | KEAP1 != "wt"))
table(subset(tmt_meta, NFE2L2 != "wt" | KEAP1 != "wt")$subtype)
#boxplots protein ----
inflamed_proteincc_samples = subset(tmt_meta, consensusClassK5_protein == 1 | consensusClassK5_protein == 3)$TissueID
redox_proteincc_samples = subset(tmt_meta, consensusClassK5_protein == 2 | consensusClassK5_protein == 4)$TissueID
mixed_proteincc_samples = subset(tmt_meta, consensusClassK5_protein == 5)$TissueID
gene_symbol_boxplot = "CD40"
boxplot(list(Inflamed = as.numeric(protein_expression[protein_expression$Symbol == gene_symbol_boxplot, inflamed_proteincc_samples]), Redox = as.numeric(protein_expression[protein_expression$Symbol == gene_symbol_boxplot, redox_proteincc_samples]), Mixed = as.numeric(protein_expression[protein_expression$Symbol == gene_symbol_boxplot, mixed_proteincc_samples])), main = paste(gene_symbol_boxplot, "", sep = " "), ylab = "Log2 Expression")
#CNV regions for heatmaps ----
cnv_long = read.delim("data/main/Standard_400kbp.50counts_updated_processed_20171220.txt", header = TRUE, stringsAsFactors = FALSE)
cnv_long_3q26.1 = cnv_long[str_detect(cnv_long$chromosome_band, "^3\\_q26\\.1"), ]
tmt_meta$cnv_3q261 = tmt_meta$TissueID %in% cnv_long_3q26.1$TissueID
cnv_long_3q26 = cnv_long[str_detect(cnv_long$chromosome_band, "^3\\_q26"), ]
tmt_meta$cnv_3q26 = tmt_meta$TissueID %in% cnv_long_3q26$TissueID
cnv_long_3q2x = cnv_long[str_detect(cnv_long$chromosome_band, "^3\\_q2[5-7]"), ]
tmt_meta$cnv_3q2x = tmt_meta$TissueID %in% cnv_long_3q2x$TissueID
cnv_long_1q31 = cnv_long[str_detect(cnv_long$chromosome_band, "^1\\_q31"), ]
tmt_meta$cnv_1q31 = tmt_meta$TissueID %in% cnv_long_1q31$TissueID
cnv_long_5p1x = cnv_long[str_detect(cnv_long$chromosome_band, "^5\\_p1[3-4]"), ]
tmt_meta$cnv_5p1x = tmt_meta$TissueID %in% cnv_long_5p1x$TissueID
#cnv count plot ----
gt_x_samples = 0
chromosome_coords = read.delim("data/main/chromosome_start_end_from_hg19_2018-04-05.txt", header = TRUE, stringsAsFactors = FALSE)
cnv_long = read.delim("data/main/Standard_400kbp.50counts_updated_processed_20171220.txt", header = TRUE, stringsAsFactors = FALSE)
#subset by subtype needs to be commented out to get summary gains/losses for manuscript
#pick one
#cnv_long = subset(cnv_long, TissueID %in% subset(tmt_meta, subtype == "Redox")$TissueID)
#cnv_long = subset(cnv_long, TissueID %in% subset(tmt_meta, subtype == "Inflamed")$TissueID)
#cnv_long = subset(cnv_long, TissueID %in% subset(tmt_meta, subtype == "Mixed")$TissueID)
cnv_long = subset(cnv_long, TissueID %in% tmt_meta$TissueID)
cnv_long$chromosome_band = paste("0", cnv_long$chromosome_band, sep = "")
cnv_long$chromosome_band = str_replace(cnv_long$chromosome_band, "010", "10")
cnv_long$chromosome_band = str_replace(cnv_long$chromosome_band, "011", "11")
cnv_long$chromosome_band = str_replace(cnv_long$chromosome_band, "012", "12")
cnv_long$chromosome_band = str_replace(cnv_long$chromosome_band, "013", "13")
cnv_long$chromosome_band = str_replace(cnv_long$chromosome_band, "014", "14")
cnv_long$chromosome_band = str_replace(cnv_long$chromosome_band, "015", "15")
cnv_long$chromosome_band = str_replace(cnv_long$chromosome_band, "016", "16")
cnv_long$chromosome_band = str_replace(cnv_long$chromosome_band, "017", "17")
cnv_long$chromosome_band = str_replace(cnv_long$chromosome_band, "018", "18")
cnv_long$chromosome_band = str_replace(cnv_long$chromosome_band, "019", "19")
cnv_long$chromosome_band = str_replace(cnv_long$chromosome_band, "020", "20")
cnv_long$chromosome_band = str_replace(cnv_long$chromosome_band, "021", "21")
cnv_long$chromosome_band = str_replace(cnv_long$chromosome_band, "022", "22")
cnv_coords = data.frame(rbindlist(lapply(str_split(cnv_long$Full.Location, ":|-"), function(x) {data.frame(t(x), stringsAsFactors = FALSE)})), stringsAsFactors = FALSE) #split the full location into a list
names(cnv_coords) = c("chromosome", "startpos", "endpos")
cnv_coords$chromosome = NULL #delete chromosome information since it's repeated
cnv_coords$startpos = as.numeric(cnv_coords$startpos)
cnv_coords$endpos = as.numeric(cnv_coords$endpos)
cnv_long = data.frame(cbind(cnv_long, cnv_coords), stringsAsFactors = FALSE)
#losses plot setup
cnv_long_cnstate_loss = subset(cnv_long, Type == "Loss")
cnv_long_cnstate_loss = cnv_long_cnstate_loss[order(cnv_long_cnstate_loss$chromosome_band), ]
cnv_long_cnstate_loss_unique = unique(cnv_long_cnstate_loss[, c("TissueID", "chromosome_band")]) #TissueID's can have repeated chromosome + band combinations which overinflates the counts
cnv_long_cnstate_loss_bandfreq = data.frame(table(cnv_long_cnstate_loss_unique$chromosome_band), stringsAsFactors = FALSE)
names(cnv_long_cnstate_loss_bandfreq) = c("chromosome_band", "Freq")
cnv_long_cnstate_loss_bandfreq$chromosome_band = as.character(cnv_long_cnstate_loss_bandfreq$chromosome_band)
cnv_long_cnstate_loss_bandfreq = subset(cnv_long_cnstate_loss_bandfreq, Freq > gt_x_samples) #only include counts greater than x samples defined above
cnv_long_cnstate_loss_bandfreq$Chromosome = as.numeric(str_match(cnv_long_cnstate_loss_bandfreq$chromosome_band, "^[0-9]*"))
cnv_long_cnstate_loss_bandfreq$Genes = ""
cnv_long_cnstate_loss_bandfreq$startpos = 0
cnv_long_cnstate_loss_bandfreq$endpos = 0
for(i in 1:nrow(cnv_long_cnstate_loss_bandfreq)) {
cnv_long_cnstate_loss_bandfreq$Genes[i] = paste(subset(cnv_long_cnstate_loss, chromosome_band == cnv_long_cnstate_loss_bandfreq$chromosome_band[i])$Genes, collapse = ", ") #populate genes in cnv bandfreq dataframe to use for annotating the plot
cnv_long_cnstate_loss_bandfreq$startpos[i] = mean(subset(cnv_long_cnstate_loss, chromosome_band == cnv_long_cnstate_loss_bandfreq$chromosome_band[i])$startpos)
cnv_long_cnstate_loss_bandfreq$endpos[i] = mean(subset(cnv_long_cnstate_loss, chromosome_band == cnv_long_cnstate_loss_bandfreq$chromosome_band[i])$endpos)
}
plot_losses_df = list()
for (i in 1:22) {
cnv_long_cnstate_loss_bandfreq_sub = subset(cnv_long_cnstate_loss_bandfreq, Chromosome == i)
if (nrow(cnv_long_cnstate_loss_bandfreq_sub) > 0) {
chrom_lowerbound = min(cnv_long_cnstate_loss_bandfreq_sub$startpos)
chrom_upperbound = chromosome_coords$end[i]
cnv_long_cnstate_loss_bandfreq_sub$y_values = i + cnv_long_cnstate_loss_bandfreq_sub$startpos / chrom_upperbound
plot_losses_df[[i]] = data.frame(x_values = cnv_long_cnstate_loss_bandfreq_sub$Freq, y_values = cnv_long_cnstate_loss_bandfreq_sub$y_values, chromosome_band = cnv_long_cnstate_loss_bandfreq_sub$chromosome_band, Genes = cnv_long_cnstate_loss_bandfreq_sub$Genes, stringsAsFactors = FALSE)
}
}
plot_losses_df = as.data.frame(rbindlist(plot_losses_df))
plot_losses_df$x_values = plot_losses_df$x_values / number_of_samples * 100
#gains plot setup
cnv_long_cnstate_gain = subset(cnv_long, Type == "Gain")
cnv_long_cnstate_gain = cnv_long_cnstate_gain[order(cnv_long_cnstate_gain$chromosome_band), ]
cnv_long_cnstate_gain_unique = unique(cnv_long_cnstate_gain[, c("TissueID", "chromosome_band")]) #TissueID's can have repeated chromosome + band combinations which overinflates the counts
cnv_long_cnstate_gain_bandfreq = data.frame(table(cnv_long_cnstate_gain_unique$chromosome_band), stringsAsFactors = FALSE)
names(cnv_long_cnstate_gain_bandfreq) = c("chromosome_band", "Freq")
cnv_long_cnstate_gain_bandfreq$chromosome_band = as.character(cnv_long_cnstate_gain_bandfreq$chromosome_band)
cnv_long_cnstate_gain_bandfreq = subset(cnv_long_cnstate_gain_bandfreq, Freq > gt_x_samples) #only include counts greater than x samples defined above
cnv_long_cnstate_gain_bandfreq$Chromosome = as.numeric(str_match(cnv_long_cnstate_gain_bandfreq$chromosome_band, "^[0-9]*"))
cnv_long_cnstate_gain_bandfreq$Genes = ""
cnv_long_cnstate_gain_bandfreq$startpos = 0
cnv_long_cnstate_gain_bandfreq$endpos = 0
for(i in 1:nrow(cnv_long_cnstate_gain_bandfreq)) {
cnv_long_cnstate_gain_bandfreq$Genes[i] = paste(subset(cnv_long_cnstate_gain, chromosome_band == cnv_long_cnstate_gain_bandfreq$chromosome_band[i])$Genes, collapse = ", ") #populate genes in cnv bandfreq dataframe to use for annotating the plot
cnv_long_cnstate_gain_bandfreq$startpos[i] = mean(subset(cnv_long_cnstate_gain, chromosome_band == cnv_long_cnstate_gain_bandfreq$chromosome_band[i])$startpos)
cnv_long_cnstate_gain_bandfreq$endpos[i] = mean(subset(cnv_long_cnstate_gain, chromosome_band == cnv_long_cnstate_gain_bandfreq$chromosome_band[i])$endpos)
}
plot_gains_df = list()
for (i in 1:22) {
cnv_long_cnstate_gain_bandfreq_sub = subset(cnv_long_cnstate_gain_bandfreq, Chromosome == i)
if (nrow(cnv_long_cnstate_gain_bandfreq_sub) > 0) {
chrom_upperbound = chromosome_coords$end[i]
cnv_long_cnstate_gain_bandfreq_sub$y_values = i + cnv_long_cnstate_gain_bandfreq_sub$startpos / chrom_upperbound
plot_gains_df[[i]] = data.frame(x_values = cnv_long_cnstate_gain_bandfreq_sub$Freq, y_values = cnv_long_cnstate_gain_bandfreq_sub$y_values, chromosome_band = cnv_long_cnstate_gain_bandfreq_sub$chromosome_band, Genes = cnv_long_cnstate_gain_bandfreq_sub$Genes, stringsAsFactors = FALSE)
}
}
plot_gains_df = as.data.frame(rbindlist(plot_gains_df))
plot_gains_df$x_values = plot_gains_df$x_values / number_of_samples * 100
annotate_regions_in_cnv_plot = TRUE
png(filename = "output/main/cnv_gain_loss_counts_2018-12-11.png", height = 800, width = 1000)
par(mar = c(5.1, 1, 4.1, 1.5))
par(mfrow = c(1,2))
par(cex.axis = 1.5, cex.lab = 1.5, cex.main = 1.5, cex.sub = 1.5)
cex_text_parameter = 1.5
plot(0, type = "n", ylim = c(26, 0), bty = "n", xaxt = "n", yaxt = "n", xlab = "Percent Patients with Loss", xlim = c(55, 0))
for (i in 1:nrow(plot_losses_df)) {
segments(x0 = 0, y0 = plot_losses_df$y_values[i], x1 = plot_losses_df$x_values[i], y1 = plot_losses_df$y_values[i], col = "blue")
}
axis(side = 4, at = c(1:23), lab = c(1:22, ""), las = 2) #y axis with labels
axis(side = 1, at = seq(50, 0, -10), line = -2) #x axis
if (annotate_regions_in_cnv_plot == TRUE) {
KEAP1_locations = subset(plot_losses_df, str_detect(plot_losses_df$Genes, " KEAP1,|^KEAP1, |, KEAP1$"))
KEAP1_max_x = max(KEAP1_locations$x_values)
KEAP1_min_y = min(KEAP1_locations$y_values)
KEAP1_max_y = max(KEAP1_locations$y_values)
segments(x0 = KEAP1_max_x + 2.5, y0 = KEAP1_min_y, x1 = KEAP1_max_x + 5, y1 = KEAP1_min_y) #top horizontal line
segments(x0 = KEAP1_max_x + 5, y0 = KEAP1_min_y, x1 = KEAP1_max_x + 5, y1 = KEAP1_max_y) #vertical line
segments(x0 = KEAP1_max_x + 5, y0 = KEAP1_max_y, x1 = KEAP1_max_x + 2.5, y1 = KEAP1_max_y) #bottom horizontal line
segments(x0 = KEAP1_max_x + 5, y0 = (KEAP1_min_y + KEAP1_max_y) / 2, x1 = KEAP1_max_x + 7.5, y1 = (KEAP1_min_y + KEAP1_max_y) / 2) #midpoint horizontal line
text("KEAP1", x = KEAP1_max_x + 7.5, y = (KEAP1_min_y + KEAP1_max_y) / 2, pos = 2, offset = 0, cex = cex_text_parameter)
chrom03_p_locations = subset(plot_losses_df, str_detect(plot_losses_df$chromosome_band, "03\\_p"))
chrom03_p_max_x = max(chrom03_p_locations$x_values)
chrom03_p_min_y = min(chrom03_p_locations$y_values)
chrom03_p_max_y = max(chrom03_p_locations$y_values)
segments(x0 = chrom03_p_max_x + 2.5, y0 = chrom03_p_min_y, x1 = chrom03_p_max_x + 5, y1 = chrom03_p_min_y) #top horizontal line
segments(x0 = chrom03_p_max_x + 5, y0 = chrom03_p_min_y, x1 = chrom03_p_max_x + 5, y1 = chrom03_p_max_y) #vertical line
segments(x0 = chrom03_p_max_x + 5, y0 = chrom03_p_max_y, x1 = chrom03_p_max_x + 2.5, y1 = chrom03_p_max_y) #bottom horizontal line
segments(x0 = chrom03_p_max_x + 5, y0 = (chrom03_p_min_y + chrom03_p_max_y) / 2, x1 = chrom03_p_max_x + 7.5, y1 = (chrom03_p_min_y + chrom03_p_max_y) / 2) #midpoint horizontal line
text("3p", x = chrom03_p_max_x + 7.5, y = (chrom03_p_min_y + chrom03_p_max_y) / 2, pos = 2, offset = 0, cex = cex_text_parameter)
chrom05_q_locations = subset(plot_losses_df, str_detect(plot_losses_df$chromosome_band, "05\\_q"))
chrom05_q_max_x = max(chrom05_q_locations$x_values)
chrom05_q_min_y = min(chrom05_q_locations$y_values)
chrom05_q_max_y = max(chrom05_q_locations$y_values)
segments(x0 = chrom05_q_max_x + 2.5, y0 = chrom05_q_min_y, x1 = chrom05_q_max_x + 5, y1 = chrom05_q_min_y) #top horizontal line
segments(x0 = chrom05_q_max_x + 5, y0 = chrom05_q_min_y, x1 = chrom05_q_max_x + 5, y1 = chrom05_q_max_y) #vertical line
segments(x0 = chrom05_q_max_x + 5, y0 = chrom05_q_max_y, x1 = chrom05_q_max_x + 2.5, y1 = chrom05_q_max_y) #bottom horizontal line
segments(x0 = chrom05_q_max_x + 5, y0 = (chrom05_q_min_y + chrom05_q_max_y) / 2, x1 = chrom05_q_max_x + 7.5, y1 = (chrom05_q_min_y + chrom05_q_max_y) / 2) #midpoint horizontal line
text("5q", x = chrom05_q_max_x + 7.5, y = (chrom05_q_min_y + chrom05_q_max_y) / 2, pos = 2, offset = 0, cex = cex_text_parameter)
chrom09_p_locations = subset(plot_losses_df, str_detect(plot_losses_df$chromosome_band, "09\\_p"))
chrom09_p_max_x = max(chrom09_p_locations$x_values)
chrom09_p_min_y = min(chrom09_p_locations$y_values)
chrom09_p_max_y = max(chrom09_p_locations$y_values)
segments(x0 = chrom09_p_max_x + 2.5, y0 = chrom09_p_min_y, x1 = chrom09_p_max_x + 5, y1 = chrom09_p_min_y) #top horizontal line
segments(x0 = chrom09_p_max_x + 5, y0 = chrom09_p_min_y, x1 = chrom09_p_max_x + 5, y1 = chrom09_p_max_y) #vertical line
segments(x0 = chrom09_p_max_x + 5, y0 = chrom09_p_max_y, x1 = chrom09_p_max_x + 2.5, y1 = chrom09_p_max_y) #bottom horizontal line
segments(x0 = chrom09_p_max_x + 5, y0 = (chrom09_p_min_y + chrom09_p_max_y) / 2, x1 = chrom09_p_max_x + 7.5, y1 = (chrom09_p_min_y + chrom09_p_max_y) / 2) #midpoint horizontal line
text("9p", x = chrom09_p_max_x + 7.5, y = (chrom09_p_min_y + chrom09_p_max_y) / 2, pos = 2, offset = 0, cex = cex_text_parameter)
}
par(mar = c(5.1, 1.5, 4.1, 1))
#plot(plot_gains_df$x_values, plot_gains_df$y_values, ylim = c(26, 0), bty = "n", xaxt = "n", yaxt = "n", xlab = "Percentage Gain", xlim = c(10, 50), type = "l", col = "red")
plot(0, type = "n", ylim = c(26, 0), bty = "n", xaxt = "n", yaxt = "n", xlab = "Percent Patients with Gain", xlim = c(0, 55))
for (i in 1:nrow(plot_gains_df)) {
segments(x0 = 0, y0 = plot_gains_df$y_values[i], x1 = plot_gains_df$x_values[i], y1 = plot_gains_df$y_values[i], col = "red")
}
axis(side = 2, at = c(1:23), lab = rep("", 23)) #yaxis without labels
#axis(side = 1, at = seq(10, 70, 10), line = -0.5) #x axis
axis(side = 1, at = seq(0, 50, 10), line = -2) #x axis
if (annotate_regions_in_cnv_plot == TRUE) {
#plot p63 sox2 pik3ca locations
p63_sox2_pik3ca_locations = subset(plot_gains_df, str_detect(plot_gains_df$Genes, " TP63,| SOX2,| PIK3CA,"))
p63_sox2_pik3ca_max_x = max(p63_sox2_pik3ca_locations$x_values) + 10
p63_sox2_pik3ca_min_y = min(p63_sox2_pik3ca_locations$y_values)
p63_sox2_pik3ca_max_y = max(p63_sox2_pik3ca_locations$y_values)
segments(x0 = p63_sox2_pik3ca_max_x + 2.5, y0 = p63_sox2_pik3ca_min_y, x1 = p63_sox2_pik3ca_max_x + 5, y1 = p63_sox2_pik3ca_min_y) #top horizontal line
segments(x0 = p63_sox2_pik3ca_max_x + 5, y0 = p63_sox2_pik3ca_min_y, x1 = p63_sox2_pik3ca_max_x + 5, y1 = p63_sox2_pik3ca_max_y) #vertical line
segments(x0 = p63_sox2_pik3ca_max_x + 5, y0 = p63_sox2_pik3ca_max_y, x1 = p63_sox2_pik3ca_max_x + 2.5, y1 = p63_sox2_pik3ca_max_y) #bottom horizontal line
segments(x0 = p63_sox2_pik3ca_max_x + 5, y0 = (p63_sox2_pik3ca_min_y + p63_sox2_pik3ca_max_y) / 2, x1 = p63_sox2_pik3ca_max_x + 7.5, y1 = (p63_sox2_pik3ca_min_y + p63_sox2_pik3ca_max_y) / 2) #midpoint horizontal line
text("TP63/SOX2/PIK3CA", x = p63_sox2_pik3ca_max_x + 7.5, y = (p63_sox2_pik3ca_min_y + p63_sox2_pik3ca_max_y) / 2, pos = 4, offset = 0, cex = cex_text_parameter)
nrf2_locations = subset(plot_gains_df, str_detect(plot_gains_df$Genes, " NFE2L2,"))
nrf2_max_x = max(nrf2_locations$x_values)
nrf2_min_y = min(nrf2_locations$y_values)
nrf2_max_y = max(nrf2_locations$y_values)
segments(x0 = nrf2_max_x + 2.5, y0 = nrf2_min_y, x1 = nrf2_max_x + 5, y1 = nrf2_min_y) #top horizontal line
segments(x0 = nrf2_max_x + 5, y0 = nrf2_min_y, x1 = nrf2_max_x + 5, y1 = nrf2_max_y) #vertical line
segments(x0 = nrf2_max_x + 5, y0 = nrf2_max_y, x1 = nrf2_max_x + 2.5, y1 = nrf2_max_y) #bottom horizontal line
segments(x0 = nrf2_max_x + 5, y0 = (nrf2_min_y + nrf2_max_y) / 2, x1 = nrf2_max_x + 7.5, y1 = (nrf2_min_y + nrf2_max_y) / 2) #midpoint horizontal line
text("NFE2L2", x = nrf2_max_x + 7.5, y = (nrf2_min_y + nrf2_max_y) / 2, pos = 4, offset = 0, cex = cex_text_parameter)
cdk6_locations = subset(plot_gains_df, str_detect(plot_gains_df$Genes, " CDK6,"))
cdk6_max_x = max(cdk6_locations$x_values)
cdk6_min_y = min(cdk6_locations$y_values)
cdk6_max_y = max(cdk6_locations$y_values)
segments(x0 = cdk6_max_x + 2.5, y0 = cdk6_min_y, x1 = cdk6_max_x + 5, y1 = cdk6_min_y) #top horizontal line
segments(x0 = cdk6_max_x + 5, y0 = cdk6_min_y, x1 = cdk6_max_x + 5, y1 = cdk6_max_y) #vertical line
segments(x0 = cdk6_max_x + 5, y0 = cdk6_max_y, x1 = cdk6_max_x + 2.5, y1 = cdk6_max_y) #bottom horizontal line
segments(x0 = cdk6_max_x + 5, y0 = (cdk6_min_y + cdk6_max_y) / 2, x1 = cdk6_max_x + 7.5, y1 = (cdk6_min_y + cdk6_max_y) / 2) #midpoint horizontal line
text("CDK6", x = cdk6_max_x + 7.5, y = (cdk6_min_y + cdk6_max_y) / 2, pos = 4, offset = 0, cex = cex_text_parameter)
bcl2l1_locations = subset(plot_gains_df, str_detect(plot_gains_df$Genes, " BCL2L1,"))
bcl2l1_max_x = max(bcl2l1_locations$x_values)
bcl2l1_min_y = min(bcl2l1_locations$y_values)
bcl2l1_max_y = max(bcl2l1_locations$y_values)
segments(x0 = bcl2l1_max_x + 2.5, y0 = bcl2l1_min_y, x1 = bcl2l1_max_x + 5, y1 = bcl2l1_min_y) #top horizontal line
segments(x0 = bcl2l1_max_x + 5, y0 = bcl2l1_min_y, x1 = bcl2l1_max_x + 5, y1 = bcl2l1_max_y) #vertical line
segments(x0 = bcl2l1_max_x + 5, y0 = bcl2l1_max_y, x1 = bcl2l1_max_x + 2.5, y1 = bcl2l1_max_y) #bottom horizontal line
segments(x0 = bcl2l1_max_x + 5, y0 = (bcl2l1_min_y + bcl2l1_max_y) / 2, x1 = bcl2l1_max_x + 7.5, y1 = (bcl2l1_min_y + bcl2l1_max_y) / 2) #midpoint horizontal line
text("BCL2L1", x = bcl2l1_max_x + 7.5, y = (bcl2l1_min_y + bcl2l1_max_y) / 2, pos = 4, offset = 0, cex = cex_text_parameter)
ccnd_locations = subset(plot_gains_df, str_detect(plot_gains_df$Genes, " CCND1,"))
ccnd_max_x = max(ccnd_locations$x_values)
ccnd_min_y = min(ccnd_locations$y_values)
ccnd_max_y = max(ccnd_locations$y_values)
segments(x0 = ccnd_max_x + 2.5, y0 = ccnd_min_y, x1 = ccnd_max_x + 5, y1 = ccnd_min_y) #top horizontal line
segments(x0 = ccnd_max_x + 5, y0 = ccnd_min_y, x1 = ccnd_max_x + 5, y1 = ccnd_max_y) #vertical line
segments(x0 = ccnd_max_x + 5, y0 = ccnd_max_y, x1 = ccnd_max_x + 2.5, y1 = ccnd_max_y) #bottom horizontal line
segments(x0 = ccnd_max_x + 5, y0 = (ccnd_min_y + ccnd_max_y) / 2, x1 = ccnd_max_x + 7.5, y1 = (ccnd_min_y + ccnd_max_y) / 2) #midpoint horizontal line
text("CCND1", x = ccnd_max_x + 7.5, y = (ccnd_min_y + ccnd_max_y) / 2, pos = 4, offset = 0, cex = cex_text_parameter)
PDGFRA_locations = subset(plot_gains_df, str_detect(plot_gains_df$Genes, " PDGFRA,|^PDGFRA, |, PDGFRA$"))
PDGFRA_max_x = max(PDGFRA_locations$x_values)
PDGFRA_min_y = min(PDGFRA_locations$y_values)
PDGFRA_max_y = max(PDGFRA_locations$y_values)
segments(x0 = PDGFRA_max_x + 2.5, y0 = PDGFRA_min_y, x1 = PDGFRA_max_x + 5, y1 = PDGFRA_min_y) #top horizontal line
segments(x0 = PDGFRA_max_x + 5, y0 = PDGFRA_min_y, x1 = PDGFRA_max_x + 5, y1 = PDGFRA_max_y) #vertical line
segments(x0 = PDGFRA_max_x + 5, y0 = PDGFRA_max_y, x1 = PDGFRA_max_x + 2.5, y1 = PDGFRA_max_y) #bottom horizontal line
segments(x0 = PDGFRA_max_x + 5, y0 = (PDGFRA_min_y + PDGFRA_max_y) / 2, x1 = PDGFRA_max_x + 7.5, y1 = (PDGFRA_min_y + PDGFRA_max_y) / 2) #midpoint horizontal line
text("PDGFRA", x = PDGFRA_max_x + 7.5, y = (PDGFRA_min_y + PDGFRA_max_y) / 2, pos = 4, offset = 0, cex = cex_text_parameter)
EGFR_locations = subset(plot_gains_df, str_detect(plot_gains_df$Genes, " EGFR,|^EGFR, |, EGFR$"))
EGFR_max_x = max(EGFR_locations$x_values) + 15
EGFR_min_y = min(EGFR_locations$y_values)
EGFR_max_y = max(EGFR_locations$y_values)
segments(x0 = EGFR_max_x + 2.5, y0 = EGFR_min_y, x1 = EGFR_max_x + 5, y1 = EGFR_min_y) #top horizontal line
segments(x0 = EGFR_max_x + 5, y0 = EGFR_min_y, x1 = EGFR_max_x + 5, y1 = EGFR_max_y) #vertical line
segments(x0 = EGFR_max_x + 5, y0 = EGFR_max_y, x1 = EGFR_max_x + 2.5, y1 = EGFR_max_y) #bottom horizontal line
segments(x0 = EGFR_max_x + 5, y0 = (EGFR_min_y + EGFR_max_y) / 2, x1 = EGFR_max_x + 7.5, y1 = (EGFR_min_y + EGFR_max_y) / 2) #midpoint horizontal line
text("EGFR", x = EGFR_max_x + 7.5, y = (EGFR_min_y + EGFR_max_y) / 2, pos = 4, offset = 0, cex = cex_text_parameter)
FGFR1_locations = subset(plot_gains_df, str_detect(plot_gains_df$Genes, " FGFR1,|^FGFR1, |, FGFR1$"))
FGFR1_max_x = max(FGFR1_locations$x_values) + 10
FGFR1_min_y = min(FGFR1_locations$y_values)
FGFR1_max_y = max(FGFR1_locations$y_values)
segments(x0 = FGFR1_max_x + 2.5, y0 = FGFR1_min_y, x1 = FGFR1_max_x + 5, y1 = FGFR1_min_y) #top horizontal line
segments(x0 = FGFR1_max_x + 5, y0 = FGFR1_min_y, x1 = FGFR1_max_x + 5, y1 = FGFR1_max_y) #vertical line
segments(x0 = FGFR1_max_x + 5, y0 = FGFR1_max_y, x1 = FGFR1_max_x + 2.5, y1 = FGFR1_max_y) #bottom horizontal line