-
Notifications
You must be signed in to change notification settings - Fork 0
/
Machine learning identifies robust matrisome markers and regulatory mechanisms in cancer.Rmd
1861 lines (1560 loc) · 70 KB
/
Machine learning identifies robust matrisome markers and regulatory mechanisms in cancer.Rmd
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
---
title: Machine learning identifies robust matrisome markers and regulatory mechanisms in cancer
self_contained: yes
output:
html_document:
df_print: paged
html_notebook: default
pdf_document: default
---
<style>
body {
text-align: justify}
</style>
FOREWORD
This notebook contains the whole code necessary to regenerate our findings and conclusions, and is provided "as it is" for re-use and re-discovery. None of the contributors is a professional programmer, so the code is slow, intricate and (in parts) unpleasant to look and to execute. It is also a dynamic entity, built by the Authors while they themselves were learning more and more about coding, so the way the same job is executed in different parts of the code may vary largely. We cannot guarantee that its execution will not stuck your PC or, in the worst case, permanently damage it. By running any part of this code you accept this risk.
There are two important notes before moving on the the actual code:
1) graphs and tables might have been post-produced manually for publication, so their appearance might differ from what is generated executing the chunks below. Nevertheless, no content is changed in its substance.
2) executing the whole code requires A LOT of libraries pre-installed. We do not provide any command to install them and, thus, advise those who want to re-execute these commands to check for the libraries needed in the various chunks before running any part of the code.
3) as a default, we do not automatically save graphs but export tables automatically. Users are free to decide which graph they want.
# STEP 0: SETUP WORKING DIRECTORIES
```{r eval = F}
setwd(" ") # change to need
dir.data <- getwd()
dir.create("RESULTS")
setwd(paste(dir.data,"/RESULTS",sep=""))
dir.res <- getwd()
setwd(dir.data)
library(dplyr)
library(data.table)
```
# STEP 1: INITIAL DATA SETUP
This section generates the RDS object that contains all data for analysis. These steps are left for transparency but users should start from #2.
Form a clinical annotation data frame with relevant parameters. This will be eventually subsetted to account for samples with missing information, etc. and to reduce the other data layers to a common set of samples.
```{r eval = F}
clin1 <- fread("TCGAclindata_sampletype.txt", header=T, sep="\t")
clin1 <- as.data.frame(clin1)
clin1 <- clin1[!clin1$sample_type == "Solid Tissue Normal",]
m1 <- clin1$sample
clin2 <- fread("TCGAclindata.txt", header=T, sep="\t")
clin2 <- as.data.frame(clin2)
m2 <- clin2$sample
m <- intersect(m1,m2)
clin2 <- subset(clin2, clin2$sample %in% m)
clin3 <- fread("TCGASubtype.20170308.txt", header=T, sep="\t", fill=T)
clin3 <- as.data.frame(clin3)
clin3 <- subset(clin3, clin3$sample %in% m)
m <- clin3$sampleID
clin2 <- subset(clin2, clin2$sample %in% m)
names(clin3)[1] <- "sample"
fin.clin <- merge(clin2,clin3[,c(1,9)],by="sample")
```
Load and subset gene programs.
```{r eval = F}
tab <- fread("gene_programs.txt", header = T, sep="\t")
tab <- as.data.frame(tab)
tab$X <- NULL
gp <- subset(tab, tab$sample %in% m)
fin.clin <- subset(fin.clin, fin.clin$sample %in% gp$sample)
gp <- subset(gp, !duplicated(gp$sample))
```
Load and subset CNAs and mutations. These will be double-subsetted to samples with clinical data available and the matrisome. Mutations are also further filtered to remove silent mutations.
```{r eval = F}
gis <- fread("Gistic2_CopyNumber_Gistic2_all_thresholded.by_genes.txt", header=T, sep="\t")
mut <- fread("mc3.v0.2.8.PUBLIC.xena.txt", header=T, sep="\t")
gis <- as.data.frame(gis)
mut <- as.data.frame(mut)
rownames(gis) <- gis[,1] #manipulate GIS file to format as the other files#
gis[,1] <- NULL
gis <- as.data.frame(t(gis))
gis$sample <- as.character(rownames(gis))
rownames(gis) <- NULL
gis <- gis[,c(24777,2:24776)]
gis$sample <- gsub("\\.", "-", gis$sample)
gis <- subset(gis, gis$sample %in% gp$sample)
fin.clin <- subset(fin.clin, fin.clin$sample %in% gis$sample)
gp <- subset(gp, gp$sample %in% gis$sample)
mut <- subset(mut, mut$sample %in% gis$sample)
mn <- read.table("matrisome_hs.txt", header=T, sep="\t") #cut to matrisome genes#
mn <- mn$Gene.Symbol
mn <- as.character(mn)
rownames(gis) <- gis[,1]
gis[,1] <- NULL
gis <- gis[,colnames(gis) %in% mn]
gis$sample <- rownames(gis)
rownames(gis) <- NULL
gis <- gis[,c(1015,1:1014)]
mut <- mut[mut$gene %in% mn,]
mut <- subset(mut, !mut$effect == "Silent")
```
Load and subset miRNAs. These will be double-subsetted to samples with clinical data available and the matrisome as target. miRNA-mRNA interactions are taken from http://mirtarbase.mbc.nctu.edu.tw/php/download.php and subsetted to remove weak entries.
```{r eval = F}
mirna <- fread("miRNAs.txt", header = T, sep="\t")
mints <- fread("hsa_MTI.txt", header = T, sep="\t")
mints <- as.data.frame(mints)
mints <- subset(mints, !mints$`Support Type` == "Functional MTI (Weak)")
mints <- subset(mints, mints$`Target Gene` %in% mn)
mirna <- subset(mirna, mirna$sample %in% mints$miRNA)
mirna <- as.data.frame(mirna)
rownames(mirna) <- mirna[,1]
mirna[,1] <- NULL
mirna <- as.data.frame(t(mirna))
mirna$sample <- rownames(mirna)
mirna <- mirna[,c(251,1:250)]
rownames(mirna) <- NULL
mirna$sample <- gsub("\\.", "-", mirna$sample)
mirna <- subset(mirna, mirna$sample %in% gp$sample)
#back-subsetting the other data we collected so far would drop GBM entirely (+ some samples from other tumors), which we wish to retain. So, we keep it and insert 0s in our miRNA frame. GBM, later on, will not model miRNA effects#
add <- data.frame(sample=fin.clin$sample[!fin.clin$sample %in% mirna$sample], matrix(0,218,250))
names(add)[2:ncol(add)] <- names(mirna[2:ncol(mirna)])
mirna <- bind_rows(mirna,add)
```
Load and subset purity data. The immune/stroma fraction is calculated as 1-purity, whose measure is CPE (consensus from other methods). Data are from https://www.nature.com/articles/ncomms9971/ .
```{r eval = F}
library(TCGAbiolinks)
pur <- Tumor.purity
names(pur)[1] <- "sample"
pur$sample <- gsub('.{1}$', '', pur$sample)
pur <- subset(pur, pur$sample %in% gp$sample)
pur$CPE <- gsub(",",".",pur$CPE)
pur$CPE <- as.numeric(pur$CPE)
pur <- pur[,c(1,7)]
pur$st.fraction <- 1-pur$CPE
pur <- subset(pur,!duplicated(pur$sample))
#back-subsetting the other data we collected so far would drop ESCA, STAD, LAML and PCPG entirely, which we wish to retain. So, we keep them and insert 1s in our purity frame. ESCA, STAD, LAML and PCPG, later on, will not model miRNA effects#
add <- data.frame(sample=fin.clin$sample[!fin.clin$sample %in% pur$sample], matrix(0,876,2))
names(add)[2:3] <- names(pur)[2:3]
pur <- bind_rows(pur,add)
```
Load and subset matrisome gene expression data.
```{r eval = F}
p1 <- read.table("panc1.txt", header=T, sep="\t")
p2 <- read.table("panc2.txt", header=T, sep="\t")
p3 <- read.table("panc3.txt", header=T, sep="\t")
p4 <- read.table("panc4.txt", header=T, sep="\t")
m <- merge(p1, p2, by="sample")
m <- merge(m, p3, by="sample")
m <- merge(m, p4, by="sample")
m <- subset(m, m$sample %in% gp$sample)
matrisome.expr <- m
m <- NULL
mn <- read.table("matrisome_hs.txt", header=T, sep="\t") #cut to matrisome genes#
```
Load and subset transcription factor (TF) data.
```{r eval = F}
library(tftargets)
res <- list()
for(i in 1:length(TRRUST)){
z <- TRRUST[[i]]
df <- data.frame(TF=names(TRRUST)[i], target=z)
res[[i]] <- df
}
tr <- bind_rows(res)
res <- list()
for(i in 1:length(Marbach2016)){
z <- Marbach2016[[i]]
df <- data.frame(TF=names(Marbach2016)[i], target=z)
res[[i]] <- df
}
mar <- bind_rows(res)
tf <- bind_rows(tr,mar)
tf <- unique(tf)
tf <- subset(tf, tf$target %in% mn$Gene.Symbol)
dat <- fread("EB++AdjustPANCAN_IlluminaHiSeq_RNASeqV2.geneExp.xena.txt", header=T, sep="\t")
dat <- subset(dat, dat$sample %in% unique(tf$TF))
dat <- as.data.frame(dat)
rownames(dat) <- dat[,1]
dat[,1] <- NULL
dat <- as.data.frame(t(dat))
dat$sample <- rownames(dat)
dat <- dat[,c(744,1:743)]
rownames(dat) <- NULL
dat$sample <- gsub("\\.", "-",dat$sample)
dat <- subset(dat, dat$sample %in% gp$sample)
```
Load and subset Illumina Methyl450 data. These will be double-subsetted to samples with clinical data available and the matrisome as target. Data are mean of probes throughout the gene.
```{r eval = F}
m1 <- fread("met1.txt", header=T, sep="\t")
m2 <- fread("met2.txt", header=T, sep="\t")
m3 <- fread("met3.txt", header=T, sep="\t")
m4 <- fread("met4.txt", header=T, sep="\t")
m5 <- fread("met5.txt", header=T, sep="\t")
m6 <- fread("met6.txt", header=T, sep="\t")
m7 <- fread("met7.txt", header=T, sep="\t")
m8 <- fread("met8.txt", header=T, sep="\t")
m9 <- fread("met9.txt", header=T, sep="\t")
m <- merge(m1,m2,by="sample")
m <- merge(m,m3,by="sample")
m <- merge(m,m4,by="sample")
m <- merge(m,m5,by="sample")
m <- merge(m,m6,by="sample")
m <- merge(m,m7,by="sample")
m <- merge(m,m8,by="sample")
m <- merge(m,m9,by="sample")
m <- m[na.omit(m)]
met <- subset(m, m$sample %in% gp$sample)
#back-subsetting the other data we collected so far would drop PCPG entirely, which we wish to retain. So, we keep it and insert 0s in our methylation frame. This will not alter modelling methylation in PCPG later on as we would have imputed 0s in the final binder#
add <- data.frame(sample=fin.clin$sample[!fin.clin$sample %in% met$sample], matrix(0,2640,2052))
names(add)[2:ncol(add)] <- names(met)[2:ncol(met)]
met <- bind_rows(met,add)
```
Dump data into a final RDS object. This now has 9 data layers (clinical, mutations, CNAs, gene programs, miRNAs, purity, matrisome gene expression, TF gene expression and methylation) and 3 vocabularies (miRNA targets, TF targets and matrisome genes & categories).
```{r eval = F}
l <- list(clinical.data=fin.clin, mutation.data=mut, cna.data=gis, gp.data=gp, mirna.data=mirna, mirna.vocabulary=mints, tumor.purity=pur, matrisome.vocabulary = mn, matrisome.data=matrisome.expr, tf.vocabulary=tf, tf.data=dat, methylation.data=met)
saveRDS(l, "data dump.rds")
rm(list=ls())
gc()
```
# STEP 2: IDENTIFY TRANSCRIPTIONAL LANDMARKS OF TUMOR MATRISOME
At first, we try to address the question whether matrisome expression is, overall, affected by the molecular/clinical subtype of the different tumors. Visual inspection of results from t-SNE (Tsne parameters are taken from https://www.nature.com/articles/s41467-019-13056-x#Sec2) and Spearman correlation suggest that each tumor is a cluster per se, negating that molecular differences in subtypes have an impact on the tumor matrisome. The only deviation from this rule is in the neuroendocrine cluster, where also KICH, one subtype of THCA and one of UCS are found. Notably, their correlation is much higher with PCPG and ACC than with GBM-LGG, suggesting more commonalities in "peripheral nervous system-like" tumor matrisomes.
The dominant factors in shaping the tumor matrisome seem to be the cell- and tissue-of-origin, pulling tumors that share a common physiopathological identity (see, e.g., squamous and neuroendocrine tumors) together and suggesting a major structure with 5 matrisome "types" separating blood, liver, neuroendocrine, squamous and adenomatous/sarcomatous tumors - the latter 3 further subdivided into their single constituents. The same conclusions can be drawn from mixed gaussian model (MGM) clustering and UMAP-augmented density-based clustering (DBSCAN).
```{r eval = F}
data <- readRDS("data dump.rds")
tr1 <- as.data.frame(table(data$clinical.data$Subtype_Selected))
tr1 <- tr1[tr1$Freq >= 10,] #removes 6 tumor subtypes and 44 samples#
sel <- subset(data$clinical.data, data$clinical.data$Subtype_Selected %in% tr1$Var1)
sel <- sel[,c(1,3,35)]
m <- subset(data$matrisome.data, data$matrisome.data$sample %in% sel$sample)
m <- merge(sel,m,by="sample")
m[,1] <- NULL
m[is.na(m)] <- 0
library(Rtsne)
m2 <- normalize_input(as.matrix(m[,3:ncol(m)]))
#visualization with t-SNE#
set.seed(123)
rt <- Rtsne(m2, pca_center = F, perplexity = 663, eta = 553)
d <- data.frame(labels=m[,2],tum.type=m[,1],x=rt$Y[,1],y=rt$Y[,2])
d$histo.type <- ifelse(d$tum.type == "OV","Gyn",
ifelse(d$tum.type == "UCEC", "Gyn",
ifelse(d$tum.type == "UCS", "Gyn",
ifelse(d$tum.type == "GBM", "Neuroendocrine",
ifelse(d$tum.type == "LGG", "Neuroendocrine",
ifelse(d$tum.type == "PCPG","Neuroendocrine",
ifelse(d$tum.type == "ACC", "Neuroendocrine",
ifelse(d$tum.type == "COAD", "Gi",
ifelse(d$tum.type == "READ", "Gi",
ifelse(d$tum.type == "STAD", "Gi-associated",
ifelse(d$tum.type == "LIHC", "Gi-associated",
ifelse(d$tum.type == "ESCA", "Squamous",
ifelse(d$tum.type == "HNSC", "Squamous",
ifelse(d$tum.type == "LUSC", "Squamous",
ifelse(d$tum.type == "LAML", "Blood",
ifelse(d$tum.type == "KICH", "Renal",
ifelse(d$tum.type == "KIRC", "Renal",
ifelse(d$tum.type == "KIRP", "Renal",
"other"))))))))))))))))))
library(ggplot2)
#global graph - option is given to add a shape code for the cell/tissue-of-orign patterns#
ggplot(data = d, aes(x,y)) + geom_point(aes(colour = labels #,
#shape = histo.type
), size = 1) +
#scale_shape_manual(values=as.factor(d$histo.type)) +
theme_void() #+ facet_wrap(~labels)
#major tumor types#
ggplot(data = d, aes(x,y)) + geom_point(aes(colour = tum.type), size = 1) +
theme_void() #+ facet_wrap(~tum.type)
#cell/tissue-of-origin patterns#
ggplot(data = d, aes(x,y) ) + geom_point(aes(colour = histo.type), size = 1) +
theme_bw() #+ facet_wrap(~tum.type)
#correlation table and plot#
res <- aggregate(m[,c(3:ncol(m))], by=list(m$Subtype_Selected), mean)
rownames(res) <- res[,1]
res[,1] <- NULL
res <- t(res)
res <- as.matrix(res)
res <- cor(res, method = "spearman")
library(pheatmap)
out <- pheatmap(res, fontsize = 5, cutree_rows = 5, cutree_cols = 5)
#unsupervised clustering by gaussian mixture modelling#
library(mclust)
m2 <- as.data.frame(m2)
res <- list()
set.seed(123)
for(i in 1:10){
z <- m2[sample(nrow(m2), 660), ]
bic <- mclustBIC(z, G=c(2:20))
mod1 <- Mclust(z, x = bic)
res[[i]] <- data.frame(iteration=i, N.of.components=mod1$G)
}
res <- bind_rows(res)
n <- round(mean(res[,2]),0)
k <- kmeans(m2, n)
df <- data.frame(tum.type=m$Subtype_Selected, cl=k$cluster)
library(corrplot)
library(RColorBrewer)
corrplot(cor(t(table(df$tum.type,df$cl))), tl.cex = 0.3, tl.col = "black", col = c("blue","white","red"))
#density-based clustering, using UMAP to increase performance of DBSCAN#
library(umap)
library(dbscan)
clustembed <- umap(m2,
n_neighbors=30,
min_dist=0.01,
n_components=10,
random_state=42)
plot(density(table(df$tum.type))) #density of tumor subtype sizes
abline(v=30, col=c("red"))
dbs <- hdbscan(clustembed$layout, minPts = 60) #at least twice the theoretical size of the average tumor type. Smaller values, closer to real distribution, give N clusters ) N tumor types#
df <- data.frame(tum.type=m$Subtype_Selected, cl=dbs$cluster)
corrplot(cor(t(table(df$tum.type,df$cl))), tl.cex = 0.3, tl.col = "black", col = c("blue","white","red"))
```
Based on the results above, we next try to identify genes that best represent the tumors in these clusters, following the idea that tumors in the same cluster should share at least some of them. To this this hypothesis we use a 4-stage procedure as follows:
Stage 1: Mann-Whitney U (MWU) test for gene expression, with FDR-correction. Each tumor subtype is tested against all other, except for those in the same cluster. Clusters have been loosely defined in the step above: LAML, LIHC, Neuroendocrine, Squamous and Adenomatous/Sarcomatous (rest). For the latter, since tumor types within show practically no correlation with each other, no cluster exclusion is performed.
```{r eval = F}
ndf <- data.frame(m[,c(1,2)], m2)
cn <- colnames(res[,out$tree_col[["order"]]])
ann <- data.frame(tum.type=cn, cl=c(
rep(1,7),
rep(2,3),
rep(3,19),
rep(4,60)))
ndf <- merge(ann,ndf,by.x="tum.type",by.y="Subtype_Selected")
res <- list()
res2 <- list()
for(i in unique(ndf$tum.type)){
print(paste0("testing ",i))
z1 <- subset(ndf, ndf$tum.type == i)
z2 <- subset(ndf, !ndf$tum.type == i)
z2 <- if(unique(z1$cl == 4)){z2 <- z2}else
{subset(z2, !z2$cl %in% z1$cl)}
z1 <- z1[,c(4:ncol(z1))]
z2 <- z2[,c(4:ncol(z2))]
for(q in 1:ncol(z1)){
print(paste0(i," ***testing ",names(z1)[q]))
x <- z1[,q]
y <- z2[,q]
w <- wilcox.test(x,y)
fc <- sign(mean(x)/mean(y))*log2(abs(mean(x)/mean(y)))
w <- data.frame(gene=names(z1)[q], tumor.type=i, FC=fc, side=ifelse(mean(x)>mean(y),"increased","decreased"),pval=w$p.value)
res[[q]] <- w
}
res2[[i]] <- bind_rows(res)
}
res2 <- bind_rows(res2)
res2$adj.pval <- p.adjust(res2$pval, "fdr")
res2 <- na.omit(res2)
res2 <- subset(res2,res2$adj.pval < 0.05 & res2$side == "increased")
nd <- d[,c(1,5)]
nr <- merge(nd,res2,by.x="labels", by.y = "tumor.type")
nr <- unique(nr)
setwd(dir.res)
fwrite(nr, "step2_MWU test_all genes.txt", row.names = F, quote = F)
setwd(dir.data)
#setwd(dir.res)
#nr <- fread("step2_MWU test_all genes.txt", header=T, quote = F) #if restarting#
#nr <- as.data.frame(nr)
#setwd(dir.data)
```
Stage 2: weighted gene coexpression networks (WGCNA) for the same tumor subtypes.
```{r eval = F}
#programmatic WGCNA#
ndf <- data.frame(m[,c(1,2)], m2)
library(WGCNA)
res <- list()
ct <- 0
l <- length(unique(nr$labels))
for(i in unique(nr$labels)){
ct <- ct+1
s <- subset(nr, nr$labels == i)
s1 <- subset(ndf, ndf$Subtype_Selected %in% s$labels)
print(paste0(ct, " of ", l, " : calculating WGCN"))
#1 correlation network
cm <- s1[,c(3:ncol(s1))]
cm[is.na(cm)] <- 0
cm <- cm[, colSums(cm != 0) > 0]
cm <- cm[vapply(cm, function(x) length(unique(x)) > 1, logical(1L))]
cm <- cor(cm, method="spearman")
#adjacency matrix
a <- 0.5+(0.5*cm)
print("finding and testing beta values")
beta <- pickSoftThreshold(
s1[, c(3:ncol(s1))],
dataIsExpr = TRUE,
weights = NULL,
RsquaredCut = 0.85,
powerVector = c(seq(1, 10, by = 1), seq(12, 20, by = 2)),
removeFirst = FALSE, nBreaks = 10, blockSize = NULL,
corFnc = cor, corOptions = list(use = 'p'),
networkType = "unsigned",
moreNetworkConcepts = FALSE,
gcInterval = NULL,
verbose = 0, indent = 0)
beta <- beta$powerEstimate
beta2 <- ifelse(min(cm^beta)==0,beta,ifelse(min(cm^(beta+1))==0,beta+1,
ifelse(min(cm^(beta+2))==0,beta+2,12)))
a <- cm^beta2
#topological measure and module construction
tom <- GTOMdist(a, degree = 1)
hc <- hclust(as.dist(tom), method = "average")
cls <- cutreeDynamic(hc, minClusterSize = 10, distM = as.matrix(as.dist(tom)))
cls <- data.frame(gene=rownames(cm), cluster.assignment=cls)
cls <- subset(cls, cls$cluster.assignment > 0)
if(nrow(cls) > 0){df <- cls}else{df <- data.frame(gene="none",cluster.assignment=0)
print("no modules detected! Moving on to next iteration")}
df$tumor.type <- i
res[[i]] <- df
}
res <- bind_rows(res)
setwd(dir.res)
fwrite(res, "step2_WGCNA test_all genes.txt", row.names = F, quote = F)
setwd(dir.data)
#setwd(dir.res)
#res <- fread("step2_WGCNA test_all genes.txt", header=T, quote = F) #if restarting#
#res <- as.data.frame(res)
#setwd(dir.data)
```
Stage 3: pruning results via adaptive lasso (10X CV) regression. Variables are defined by the comparison of MWU e WGCNA and tested against a logistic class assignment (1/0) based on the tumor subtype.
```{r eval = F}
fin <- list()
library(parallel)
library(snow)
library(foreach)
library(doSNOW)
cores <- detectCores()
cl <- makeCluster(cores-1)
registerDoSNOW(cl)
library(glmnet)
for(i in unique(res$tumor.type)){
z <- subset(nr, nr$labels == i)
z2 <- subset(res, res$tumor.type == i)
n <- intersect(z$gene,z2$gene)
#module regression
if(length(n)==0){df2 <- data.frame(gene="none",coef=0,tumor=i)
print(" *** no common variables from MWU-WGCNA. Skipping calculations!")}else{
print(paste0(i," : regressing ", length(n), " genes against class assignment"))
subz <- subset(ndf, select=colnames(ndf)%in%n)
if(ncol(subz)<=3){df2 <- data.frame(gene="none",coef=0,tumor=i)
print(" *** not enough variables. Skipping calculations!")}else{
subz$target <- ifelse(ndf$Subtype_Selected == i,1,0)
subz <- subz[,c(ncol(subz),1:(ncol(subz)-1))]
subz[is.na(subz)] <- 0
print(" *** 10X ridge regression")
ridge_cv <- cv.glmnet(x = as.matrix(subz[,2:ncol(subz)]), y = subz[,1],
type.measure = "deviance",
nfold = 10,
family = "binomial",
alpha = 0,
parallel = T)
bc <- coef(ridge_cv, s = ridge_cv$lambda.min)
bc <- as.numeric(bc)[-1]
print(" *** 10X adaptive lasso regression")
alasso_cv <- cv.glmnet(x = as.matrix(subz[,2:ncol(subz)]), y = subz[,1],
type.measure = "deviance",
nfold = 10,
family = "binomial",
alpha = 1,
penalty.factor = 1 / abs(bc),
keep = TRUE,
parallel = T)
al <- coef(alasso_cv, s = alasso_cv$lambda.min)
al <- data.frame(gene=rownames(al)[2:nrow(al)],coef=al[2:nrow(al),1])
al <- subset(al, al$coef > 0)
if(nrow(al)==0){df2 <- data.frame(gene="none",coef=0,tumor=i)
print(" *** no regressors found!")}else{
print(" *** writing results")
df2 <- data.frame(al, tumor=i)
}
}}
fin[[i]] <- df2
}
fin <- bind_rows(fin)
stopCluster(cl)
fin <- subset(fin,!fin$gene == "none") #computation possible for 87/89 tumor subtypes#
#barplot(table(fin$tumor),las=2, col = rainbow(length(unique(fin$tumor)))) #visualization, if desired#
setwd(dir.res)
fwrite(fin, "step2_AdaLASSO_significant genes.txt", row.names = F, quote = F)
setwd(dir.data)
#setwd(dir.res)
#fin <- fread("step2_AdaLASSO_significant genes.txt", header=T, quote = F) #if restarting#
#fin <- as.data.frame(fin)
#setwd(dir.data)
```
Stage 4: finally, the expression of each matrisome gene is fitted into a bimodal distribution via expectation maximization (EM) of mixtures of univariate normals, genes are selected and allocated to each tumor type if their expression is equal or bigger than the mean + 2SD of the total, and DEGs and EMs are confronted. Only genes common to the both lists, per tumor type, are kept. With this final step, the total of DEGs that represent our data is 724 (316 unique).
```{r eval = F}
l <- list() #overall pheatmap/tSNE with DEGS. All tumors are well separated#
for(i in unique(fin$tumor)){
z <- subset(fin, fin$tumor == i)
z$coef <- 1
z2 <- data.frame(tumor=i,t(z$coef))
colnames(z2)[2:ncol(z2)] <- z$gene
l[[i]] <- z2
}
l <- bind_rows(l)
l[is.na(l)] <- 0
rownames(l) <- l[,1]
l[,1] <- NULL
pheatmap(l, breaks = c(-1,0,1), color = c("white","red"), fontsize = 5)
l2 <- t(l)
l2 <- cor(l2)
pheatmap(l2, breaks = c(-1,0.2,1), color = c("white","red"), fontsize = 5)
nn <- merge(fin,ndf[,1:3],by.x="tumor",by.y="tum.type")
nn <- unique(nn)
tab <- ndf[, colnames(ndf) %in% unique(nn$gene)]
rt <- Rtsne(tab, pca_center = F, perplexity = 663, eta = 553)
d <- data.frame(labels=m[,1],tum.type=m[,2],x=rt$Y[,1],y=rt$Y[,2])
library(ggplot2)
library(ggsci)
ggplot(data = d, aes(x,y)) + geom_point(aes(colour = as.factor(labels)), size = 1) + theme_void()
cms <- list() #colMeans per tumor type - to briefly check distributions#
for(i in unique(fin$tumor)){
z <- subset(ndf, ndf$Subtype_Selected == i)
z2 <- colMeans(z[,c(3:ncol(z))])
z2 <- data.frame(tumor=i,t(z2))
cms[[i]] <- z2
}
cms <- bind_rows(cms)
cms[is.na(cms)] <- 0
library(fitdistrplus) #evaluate distribution types. They are all parametrizations of normal distributions#
l <- list()
for(i in unique(cms$tumor)){
p <- subset(cms, cms$tumor==i)
print(paste0("fitting distributions to ",i))
fit <- fitDist(as.numeric(p[,c(2:ncol(p))]), k = 2, type = "realline", trace = FALSE, try.gamlss = TRUE)
l[[i]] <- data.frame(tumor=i,fam=fit$family)
}
l <- bind_rows(l)
library(mixtools) #EM#
l <- list()
for(i in c(3:ncol(ndf))){
x <- ndf[,i]
print(paste0("running EM for ",names(cms)[i]))
if(var(x)<0.001){print("0 variance, EM skipped!")
df <- data.frame(tumor="none",values=0,gene=names(cms)[i])}else{
skip_to_next <- F
set.seed(123)
tryCatch(normalmixEM(x,k=2), error = function(e) { skip_to_next <<- TRUE})
if(skip_to_next){print("too many starts (one variance is 0), EM skipped!")
df <- data.frame(tumor="none",values=0,gene=names(cms)[i])}else{
set.seed(123)
gm <- normalmixEM(x,k=2)
tr <- gm$mu[2]+(2*gm$sigma[2])
df <- data.frame(tumor=ndf$Subtype_Selected,values=x, gene=names(cms)[i])
df <- subset(df, df$values >= tr)
if(nrow(df)==0){df <- data.frame(tumor="none",values=0,gene=names(cms)[i])}else{df <- df}}}
l[[i]] <- df
}
l <- bind_rows(l)
l <- subset(l, !l$tumor == "none")
fin2 <- list() #compare against DEGs#
for(i in unique(fin$tumor)){
print(paste0("selecting DEGs for ",i))
z <- subset(fin, fin$tumor == i)
z1 <- unique(z[,1])
z <- subset(l, l$tumor == i)
z2 <- unique(z[,3])
it <- intersect(z1,z2)
if(length(it)==0){df <- data.frame(tumor=i,gene="none")}else{
df <- data.frame(tumor=i,gene=it)}
fin2[[i]] <- df
}
fin2 <- bind_rows(fin2)
fin2 <- merge(fin2, ndf[,c(1:2)],by.x="tumor",by.y="Subtype_Selected")
fin2 <- unique(fin2)
#barplot(table(fin2$cancer.type.abbreviation),las=2)
EMdf <- l
l <- list() #overall pheatmap/tSNE with DEGS. All tumors are well separated#
for(i in unique(fin2$cancer.type.abbreviation)){
z <- subset(fin2, fin2$cancer.type.abbreviation == i)
z2 <- data.frame(tumor=i,t(rep(1,length(unique(z$gene)))))
colnames(z2)[2:ncol(z2)] <- unique(z$gene)
l[[i]] <- z2
}
l <- bind_rows(l)
l[is.na(l)] <- 0
rownames(l) <- l[,1]
l[,1] <- NULL
pheatmap(l, breaks = c(-1,0,1), color = c("white","red"), fontsize = 5)
l2 <- t(l)
l2 <- cor(l2)
pheatmap(l2, breaks = c(-1,0.2,1), color = c("white","red"), fontsize = 5)
tab <- ndf[, colnames(ndf) %in% unique(fin2$gene)]
rt <- Rtsne(tab, pca_center = F, perplexity = 663, eta = 553)
d <- data.frame(labels=ndf[,1],tum.type=ndf[,2],x=rt$Y[,1],y=rt$Y[,2])
ggplot(data = d, aes(x,y)) + geom_point(aes(colour = as.factor(labels)), size = 1) + theme_void()
setwd(dir.res)
fwrite(fin2, "step2_pruned by EM_significant genes.txt", row.names = F, quote = F)
setwd(dir.data)
#setwd(dir.res)
#fin2 <- fread("step2_pruned by EM_significant genes.txt", header=T, quote = F) #if restarting#
#fin2 <- as.data.frame(fin2)
#setwd(dir.data)
```
# STEP 3: SPARSE PRINCIPAL COMPONENT REGRESSION - & RANDOM FOREST REGRESSION - BASED INFERENCE OF REGULATORY INTERACTIONS
The approach chosen leverages on sparse principal component regression (SPCR) and random forest regression (RFR) to model all possible regulators against each matrisome gene per each tumor subtype. This step is computationally very intensive, poorly to no optimized, and might take several days to complete on a standard machine. Users are advised to skip these parts and move directly to step 4, where the results of this section (provided with the data dump) are drawn and integrated. The remainder of the code is left for users who want to attempt reconstructing this section too.
To better cope with our data we introduce two restrictions before regressing possible regulators against the DEGs defined above:
- we only model tumor subtypes with at least 10 patients
- we only model matrisome genes with at least 10 non-zero expression patients
(these first 2 conditions should avoid foreseeable non-convergence problems)
Select tumor types and matrisome genes based on patient numbers and non-zero expression.
```{r eval = F}
data <- readRDS("data dump.rds")
setwd(dir.res)
fin2 <- fread("step2_pruned by EM_significant genes.txt", header=T, sep=",")
fin2 <- as.data.frame(fin2)
setwd(dir.data)
fin2 <- subset(fin2, !fin2$gene == "none")
tr1 <- as.data.frame(table(data$clinical.data$Subtype_Selected))
tr1 <- tr1[tr1$Freq >= 10,] #removes 6 tumor subtypes#
tr1 <- subset(tr1, tr1$Var1 %in% fin2$tumor) #removes 6 more subtypes#
res <- list()
for(i in tr1$Var1){
print(paste0("checking DEGs in ",i))
z <- subset(tr1, tr1$Var1 == i)
z <- as.character(z[,1])
cl <- subset(data$clinical.data, data$clinical.data$Subtype_Selected == i)
m <- subset(data$matrisome.data, data$matrisome.data$sample %in% cl$sample)
m[,1] <- NULL
ge <- subset(fin2, fin2$tumor == i)
m <- subset(m, select = colnames(m) %in% ge$gene)
m[is.na(m)] <- 0
n <- colSums(m != 0) > 0
n <- n[n=="TRUE"]
res[[i]] <- data.frame(tumor.type=i, vars=as.character(names(n)))
}
res <- bind_rows(res)
tg.selector <- res
res <- NULL
```
SPCR-GLM. This workflow builds largely on the previous work by Kawano et al. (https://www.sciencedirect.com/science/article/pii/S0167947318300562). No parallelization, very slow procedure (especially penalty estimation). To speed up completion, we ran this chunk on a server with 32 xeon cores running Microsoft R Open 3.5.3 with MKL BLAS. The results will be integrated into the data dump next to ease re-running this section. The analysis finishes with results for 77 tumor subtypes, 259 unique matrisome genes and 374 unique regressors.
```{r eval = F}
library(glmnet)
library(spcr)
res <- list()
res2 <- list()
ct <- 0
for(q in unique(tg.selector$tumor.type)){
ct <- ct+1
v <- subset(tg.selector, tg.selector$tumor.type == q)
v <- v$vars
#select the tumor subtype#
z <- subset(data$clinical.data, data$clinical.data$Subtype_Selected %in% q)
z <- z[order(z$sample),]
sz <- z$sample
print(paste0("tumor type ",ct," of ", length(unique(tg.selector$tumor.type)),": initiate analyses for ", q))
for(i in v){
print(paste0("*** ",ct," of ",length(unique(tg.selector$tumor.type)),
", gene: ",i,
" - forming covariate matrix "))
#select the matrisome expression per gene#
y <- subset(data$matrisome.data, data$matrisome.data[,1] %in% sz)
y <- y[order(y$sample),]
y <- y[,colnames(y) %in% i]
y[is.na(y)] <- 0
if(length(y[y>0])==0){print("*** warning: Y is NA/0 in this subtype! Failsafe mechanism evoked")
df <- data.frame(vars="none", B.loadings=0, matrisome.gene=i, tumor=q, warning="Y failsafe triggered")
res[[i]] <- df}else{
#select the methylation values per gene#
x1 <- as.data.frame(data$methylation.data)
x1[is.na(x1)] <- 0
x1 <- x1[order(x1$sample),]
x1 <- subset(x1, x1$sample %in% sz)
x1 <- x1[,colnames(x1) %in% c("sample",i)]
names(x1)[2] <- "met"
if(length(x1) == 0){x1 <- data.frame(sample=sz, met=rep(0, length(y)))}else{
if(class(x1)=="data.frame"){x1 <- x1}else{x1 <- data.frame(sample=sz, met=rep(0, length(y)))}
}
#select the CNA values per gene#
x2 <- data$cna.data
x2 <- x2[order(x2$sample),]
x2 <- subset(x2, x2$sample %in% sz)
x2 <- x2[,colnames(x2) %in% c("sample",i)]
names(x2)[2] <- "CNA"
if(length(x2) == 0){x2 <- data.frame(sample=sz, cna=rep(0, length(y)))}else{
if(class(x2)=="data.frame"){x2 <- x2}else{x2 <- data.frame(sample=sz, cna=rep(0, length(y)))}
}
#select the mutations per gene#
x3 <- data$mutation.data
x3 <- subset(x3, x3$gene %in% i)
x3 <- x3[order(x3$sample),]
x3 <- subset(x3, x3$sample %in% sz)
if(nrow(x3) == 0){x3 <- data.frame(sample=sz, mut=rep(0, length(y)))}else{
if(class(x3)!="data.frame"){x3 <- data.frame(sample=sz, mut=rep(0, length(y)))}else{
n <- as.matrix(table(x3$sample,x3$Amino_Acid_Change))
x3 <- as.data.frame.matrix(n)
x3$sample <- rownames(x3)
rownames(x3) <- NULL
}}
#select the gene program per tumor subtype#
x4 <- subset(data$gp.data, data$gp.data$sample %in% sz)
x4 <- x4[order(x4$sample),]
x4 <- Filter(function(x)!all(is.na(x)), x4)
if(nrow(x4) == 0){x4 <- data.frame(sample=sz, gp=rep(0, length(y)))}else{x4 <- x4}
#select the miRNA quantity per gene#
s <- subset(data$mirna.vocabulary, data$mirna.vocabulary$`Target Gene` %in% i)
if(nrow(s) == 0){x5 <- data.frame(sample=sz, mirna=rep(0, length(y)))}else{
if(class(s)!="data.frame"){x5 <- data.frame(sample=sz, mirna=rep(0, length(y)))}else{
s <- unique(s$miRNA)
s2 <- data$mirna.data
s2 <- subset(s2, s2$sample %in% sz)
s2 <- s2[order(s2$sample),]
x5 <- s2[,colnames(s2) %in% c("sample",s)]
s <- NULL
s2 <- NULL
}}
if(class(x5)!="data.frame"){x5 <- data.frame(sample=sz, mirna=rep(0, length(y)))}else{x5 <- x5}
#select the purity per tumor subtype#
x6 <- subset(data$tumor.purity, data$tumor.purity$sample %in% sz)
x6 <- x6[,c(1,3)]
#select the TF expression per gene#
s <- subset(data$tf.vocabulary, data$tf.vocabulary$target %in% i)
if(nrow(s) == 0){x7 <- data.frame(sample=sz, tf=rep(0, length(y)))}else{
if(class(x7)!="data.frame"){x7 <- data.frame(sample=sz, tf=rep(0, length(y)))}else{
s <- unique(s$TF)
s2 <- data$tf.data
s2 <- subset(s2, s2$sample %in% sz)
s2 <- s2[order(s2$sample),]
x7 <- s2[,colnames(s2) %in% c("sample",s)]
s <- NULL
s2 <- NULL
}}
if(class(x7)!="data.frame"){x7 <- data.frame(sample=sz, tf=rep(0, length(y)))}else{x7 <- x7}
#create the X frame for regression#
nx <- Reduce(function(x,y) merge(x = x, y = y, by = "sample", all=T),
list(x1,x2,x3,x4,x5,x6,x7))
nx[is.na(nx)] <- 0
rownames(nx) <- nx$sample
nx$sample <- NULL
nx <- nx[, colSums(nx != 0) > 0]
xnx <- nx[vapply(nx, function(x) length(unique(x)) > 1, logical(1L))]
xnx <- scale(xnx, center = T, scale = T)
xnx <- xnx[order(rownames(xnx)),]
print("*** calculating adaptive sparse PCR")
sp <- cv.spcr(as.matrix(xnx), as.vector(y), k=1, adaptive = T, center = F, scale = F)
nsp <- spcr(as.matrix(xnx), as.vector(y), k=1, adaptive = T, center = F, scale = F, lambda.B = sp$lambda.B.cv, lambda.gamma = sp$lambda.gamma.cv)
nsp <- data.frame(vars=colnames(xnx),coef=nsp$loadings.B)
nsp <- subset(nsp, nsp$coef > 0)
if(nrow(nsp)==0){
print(paste0("*** no explanatory variables found for ",i))
df <- data.frame(vars="none", B.loadings=0, matrisome.gene=i, tumor=q, warning="no aPCR variable")}else{
print(paste0("*** writing variables found for ",i))
df <- data.frame(vars=nsp$vars, B.loadings=nsp$coef, matrisome.gene=i, tumor=q, warning="selected aPCR variable")}}
res[[i]] <- df
}
res2[[q]] <- bind_rows(res)
}
res2 <- bind_rows(res2)
res2 <- subset(res2, !res2$vars == "none")
res2 <- unique(res2)
fwrite(res2, "step3_SPCR_results.txt", sep="\t", row.names = F, quote = F)
tab1 <- as.data.frame(table(res2$tumor))
tab2 <- as.data.frame(table(res2$tumor,res2$vars))
tab3 <- as.data.frame(table(res2$tumor,res2$matrisome.gene))
tab <- merge(tab1,merge(tab2,tab3,by="Var1"),by="Var1")
tab <- subset(tab, !tab$Freq.x == 0 & !tab$Freq.y == 0)
tab <- unique(tab)
colnames(tab) <- c("Tumor.type","N.of.interactions","Regulators","Freq.of.regulators","matrisome.target","Freq.of.target")
#tab <- tab[,c(1:3,5)]
fwrite(tab, "step3_table of interactions_SPCR.txt", sep="\t", row.names = F, quote = F)
```
Random Forest Regression (RFR). No parallelization, very slow procedure (especially optimization of parameters such as max nodes), significantly more than SPCR-GLM. To speed up completion, we ran this chunk on a server with 32 xeon cores running Microsoft R Open 3.5.3 with MKL BLAS. The results are provided to ease re-running this section. The analysis finishes with results for 83 tumor subtypes, 315 unique matrisome genes and 377 unique regressors.
```{r eval = F}
library(randomForest)
library(caret)
library(e1071)
res <- list()
res2 <- list()
ct <- 0
for(q in unique(tg.selector$tumor.type)){
ct <- ct+1
v <- subset(tg.selector, tg.selector$tumor.type == q)
v <- v$vars
#select the tumor subtype#
z <- subset(data$clinical.data, data$clinical.data$Subtype_Selected %in% q)
z <- z[order(z$sample),]
sz <- z$sample
print(paste0("tumor type ",ct," of ", length(unique(tg.selector$tumor.type)),": initiate analyses for ", q))
for(i in v){
print(paste0("*** ",ct," of ",length(unique(tg.selector$tumor.type)),
", gene: ",i,
" - forming covariate matrix "))
#select the matrisome expression per gene#
y <- subset(data$matrisome.data, data$matrisome.data[,1] %in% sz)
y <- y[order(y$sample),]
y <- y[,colnames(y) %in% i]
y[is.na(y)] <- 0
if(length(y[y>0])==0){print("*** warning: Y is NA/0 in this subtype! Failsafe mechanism evoked")
df <- data.frame(vars="none", B.loadings=0, matrisome.gene=i, tumor=q, warning="Y failsafe triggered")
res[[i]] <- df}else{
#select the methylation values per gene#
x1 <- as.data.frame(data$methylation.data)
x1[is.na(x1)] <- 0
x1 <- x1[order(x1$sample),]
x1 <- subset(x1, x1$sample %in% sz)
x1 <- x1[,colnames(x1) %in% c("sample",i)]
names(x1)[2] <- "met"
if(length(x1) == 0){x1 <- data.frame(sample=sz, met=rep(0, length(y)))}else{
if(class(x1)=="data.frame"){x1 <- x1}else{x1 <- data.frame(sample=sz, met=rep(0, length(y)))}
}
#select the CNA values per gene#
x2 <- data$cna.data
x2 <- x2[order(x2$sample),]
x2 <- subset(x2, x2$sample %in% sz)
x2 <- x2[,colnames(x2) %in% c("sample",i)]
names(x2)[2] <- "CNA"
if(length(x2) == 0){x2 <- data.frame(sample=sz, cna=rep(0, length(y)))}else{
if(class(x2)=="data.frame"){x2 <- x2}else{x2 <- data.frame(sample=sz, cna=rep(0, length(y)))}
}
#select the mutations per gene#
x3 <- data$mutation.data
x3 <- subset(x3, x3$gene %in% i)
x3 <- x3[order(x3$sample),]
x3 <- subset(x3, x3$sample %in% sz)
if(nrow(x3) == 0){x3 <- data.frame(sample=sz, mut=rep(0, length(y)))}else{
if(class(x3)!="data.frame"){x3 <- data.frame(sample=sz, mut=rep(0, length(y)))}else{
n <- as.matrix(table(x3$sample,x3$Amino_Acid_Change))
x3 <- as.data.frame.matrix(n)
x3$sample <- rownames(x3)
rownames(x3) <- NULL
}}
#select the gene program per tumor subtype#
x4 <- subset(data$gp.data, data$gp.data$sample %in% sz)
x4 <- x4[order(x4$sample),]
x4 <- Filter(function(x)!all(is.na(x)), x4)
if(nrow(x4) == 0){x4 <- data.frame(sample=sz, gp=rep(0, length(y)))}else{x4 <- x4}
#select the miRNA quantity per gene#
s <- subset(data$mirna.vocabulary, data$mirna.vocabulary$`Target Gene` %in% i)
if(nrow(s) == 0){x5 <- data.frame(sample=sz, mirna=rep(0, length(y)))}else{
if(class(s)!="data.frame"){x5 <- data.frame(sample=sz, mirna=rep(0, length(y)))}else{
s <- unique(s$miRNA)