-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path041_ANALYSIS_03_xbulk_coex.R
1605 lines (1082 loc) · 59.1 KB
/
041_ANALYSIS_03_xbulk_coex.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
pdata <- list(); gc()
pdata$figuresDir <- paste0(workspace$workspaceDir, "041_ANALYSIS_03_xbulk_coex_FIGURES/")
pdata$genes <- readRDS(paste0(workspace$outputDir, "genes_metadata.rds")) # genes
pdata$celltypes <- c("excitatory", "inhibitory", "opc", "oligodendrocyte", "astrocyte", "microglia")
names(pdata$celltypes) <- pdata$celltypes
fdata$mkrs <- readRDS(paste0(workspace$outputDir, "umkrs.rds"))
pdata$ctprofiles <- read_rds(paste0(workspace$outputDir, "sc_stats_ctprofiles.rds"))
pdata$go <- readRDS(paste0(workspace$outputDir, "gene_ontology.rds"))
pdata$files$coexmats <- tibble(outfile = list.files(workspace$outputDir)) %>%
filter(grepl("coexmats", outfile)) %>%
mutate(outfile_name = gsub(".rds", "", outfile)) %>%
mutate(strs = strsplit(outfile_name, "_")) %>%
mutate(level = strs %>% sapply(function(currStr) { currStr[1] })) %>%
mutate(type = strs %>% sapply(function(currStr) { currStr[2] })) %>%
mutate(dataset = strs %>% sapply(function(currStr) { currStr[3] })) %>%
mutate(cell_type = strs %>% sapply(function(currStr) { currStr[4] })) %>%
dplyr::select(outfile, level, type, dataset, cell_type)
pdata$files$lnktbls <- tibble(outfile = list.files(workspace$outputDir)) %>%
filter(grepl("lnktbls", outfile)) %>%
mutate(outfile_name = gsub(".rds", "", outfile)) %>%
mutate(strs = strsplit(outfile_name, "_")) %>%
mutate(level = strs %>% sapply(function(currStr) { currStr[1] })) %>%
mutate(type = strs %>% sapply(function(currStr) { currStr[2] })) %>%
mutate(cell_type = strs %>% sapply(function(currStr) { currStr[3] })) %>%
dplyr::select(outfile, level, type, cell_type)
pdata$files$exprmats <- tibble(outfile = list.files(workspace$outputDir)) %>%
filter(grepl("exprmats", outfile)) %>%
mutate(outfile_name = gsub(".rds", "", outfile)) %>%
mutate(strs = strsplit(outfile_name, "_")) %>%
mutate(level = strs %>% sapply(function(currStr) { currStr[1] })) %>%
mutate(type = strs %>% sapply(function(currStr) { currStr[2] })) %>%
mutate(dataset = strs %>% sapply(function(currStr) { currStr[3] })) %>%
dplyr::select(outfile, level, type, dataset)
pdata$files$uexprdats <- tibble(outfile = list.files(workspace$outputDir)) %>%
filter(grepl("uexprdats", outfile)) %>%
mutate(outfile_name = gsub(".rds", "", outfile)) %>%
mutate(strs = strsplit(outfile_name, "_")) %>%
mutate(type = strs %>% sapply(function(currStr) { currStr[1] })) %>%
mutate(dataset = strs %>% sapply(function(currStr) { currStr[2] })) %>%
dplyr::select(outfile, type, dataset)
pdata$ctp <- read_rds(paste0(workspace$outputDir, "sc_stats_ctprofiles.rds"))
pdata$mkrs <- read_rds(paste0(workspace$outputDir, "umkrs.rds"))
# +++++++++++++++++++
# quickly examine a few metadata properties
fdata <- list(); gc()
fdata$exprmats <- list(rosmap = "bk_exprmats_rosmap.rds", velmeshev = "bk_exprmats_velmeshev.rds")
fdata$exprmats <- fdata$exprmats %>% lapply(function(file) { read_rds(paste0(workspace$outputDir, file)) })
fdata$exprmats$rosmap$samples
fdata$exprmats$velmeshev$samples
# +++++++++++++++++++++++++++
# now, compare the genes detected in each cell type and dataset
fdata <- list(); gc()
fdata$datasets <- pdata$files$exprmats %>% filter(level == "bk", dataset %in% c("rosmap", "velmeshev"))
fdata$datasets <- fdata$datasets$outfile %>% session$dataWrangler$attachNames(fdata$datasets$dataset)
fdata$datasets <- fdata$datasets %>% lapply(function(currDataset) { readRDS(paste0(workspace$outputDir, currDataset))$exprmat })
fdata$ctp <- fdata$datasets %>% session$collectionUtils$lapplyWithName(function(datasetName, exprmat) {
ctp <- exprmat %>% rowMeans()
ctp %>%
session$dataWrangler$vectorToTibble() %>%
dplyr::select(gene_id = variable, expr = value) %>%
mutate(level = "bk", dataset = datasetName)
}) %>% session$dataWrangler$rbind()
# =================================
# COMMIT ==========================
# fdata$ctp %>% saveRDS(paste0(workspace$outputDir, "bk_stats_ctprofiles.rds"))
# =================================
pdata$ctprofiles <- read_rds(paste0(workspace$outputDir, "bk_stats_ctprofiles.rds"))
# +++++++++++++++++++++++++++
# now, compare the gene expressions
# first in terms of detected genes overlap
# and then in terms of expression levels
fdata <- list()
fdata$ctp$bk <- read_rds(paste0(workspace$outputDir, "bk_stats_ctprofiles.rds"))
fdata$ctp$sc <- read_rds(paste0(workspace$outputDir, "sc_stats_ctprofiles.rds")) %>% filter(dataset %in% fdata$ctp$bk$dataset)
fdata$genesFlat$bk <- fdata$ctp$bk$dataset %>% unique() %>% session$dataWrangler$attachNames() %>%
session$collectionUtils$lapply(function(datasetName) { fdata$ctp$bk %>% filter(dataset == datasetName) %>% session$dataWrangler$extractColumn("gene_id") %>% unique() })
fdata$genesMat$bk <- fdata$ctp$bk %>% dplyr::select(gene_id, dataset) %>% unique() %>%
mutate(in_set = 1) %>%
spread(dataset, in_set) %>%
session$dataWrangler$fillNa(colNames = unique(fdata$ctp$bk$dataset), value = 0) %>%
session$dataWrangler$setColAsRownames("gene_id")
# 1. compare between the 2 bulk tissue datasets
# Velmeshev is effectively a superset of Rosmap; which is reassuring
fdata$genesMat$bk %>% UpSetR::upset(nsets = 7, text.scale = 2, keep.order = TRUE, nintersects = NA)
# let's take a look at the correlation in expression
# the two datasets highly agree in terms of co-expression? levels for the intersecting genes
xdata <- list()
xdata$genes <- fdata$genesFlat$bk$rosmap %>% intersect(fdata$genesFlat$bk$velmeshev)
xdata$main <- fdata$ctp$bk %>% filter(gene_id %in% xdata$genes) %>% dplyr::select(gene_id, dataset, expr) %>% spread(dataset, expr)
xdata$pearson <- cor(xdata$main$rosmap, xdata$main$velmeshev)[1, 1]
xdata$main %>%
session$graphingUtils$ggplot(aes(x = rosmap, y = velmeshev)) +
geom_point(shape = 1) +
geom_smooth(method = "lm", se = FALSE) +
ggtitle("", "Correlation in expression between\nVelmeshev.Bulk and Rosmap.Bulk")
# 2. compare each dataset its single cell counterpart; per cell type
# first let's look at per cell type, how many genes overlap
xdata <- list()
xdata$dataset <- "rosmap"
xdata$main <- fdata$ctp$sc %>% filter(dataset == xdata$dataset) %>% dplyr::select(gene_id, cell_type, expr_sc = expr) %>%
left_join(fdata$ctp$bk %>% filter(dataset == xdata$dataset) %>% dplyr::select(gene_id, expr_bk = expr))
xdata$main <- xdata$main %>% mutate(detected_bk = !is.na(expr_bk))
xdata$smry <- xdata$main %>% group_by(cell_type, detected_bk) %>% summarize(n_gene = n()) %>% ungroup()
(fdata$ctp$sc %>% filter(dataset == xdata$dataset))$gene_id %>% unique() %>% length() # total number of genes at the SC
(fdata$ctp$sc %>% filter(dataset == xdata$dataset))$gene_id %>% unique() %>%
intersect((fdata$ctp$bk %>% filter(dataset == xdata$dataset))$gene_id) %>% length() # total number of SC genes also detected at the BK
xdata$main %>% filter(detected_bk) %>%
group_by(cell_type) %>% summarize(cor_coef = cor(expr_sc, expr_bk)[1, 1])
xdata$main %>% filter(detected_bk) %>%
session$graphingUtils$ggplot(aes(x = expr_bk, y = expr_sc)) +
geom_point(shape = 1) +
scale_y_continuous(trans = "log2") +
geom_smooth(method = "lm", se = FALSE) +
facet_wrap(~cell_type) +
ggtitle("", paste0("Correlation in mean expression between SC and bulk data\n", xdata$dataset))
# 3. out of curiosity, let's see how the genes overlap among the different cell types, within each dataset?
fdata$ctp$sc %>% filter(dataset == "rosmap") %>% dplyr::select(gene_id, cell_type) %>%
mutate(in_set = 1) %>%
spread(cell_type, in_set) %>%
session$dataWrangler$fillNa(colNames = unique(fdata$ctp$sc$cell_type), value = 0) %>%
session$dataWrangler$setColAsRownames("gene_id") %>%
UpSetR::upset(nsets = 6, text.scale = 2, keep.order = TRUE, nintersects = NA)
fdata$ctp$sc %>% filter(dataset == "rosmap") %>% dplyr::select(gene_id, cell_type, expr) %>%
spread(cell_type, expr) %>%
session$dataWrangler$setColAsRownames("gene_id") %>%
na.omit() %>%
GGally::ggpairs()
# ++++++++++++++
# figures
# Now, examine the overall topolog (node degrees, etc)
# and focus on those edges that are reproducible across datasets
fdata <- list(); gc()
fdata$files <- list(rosmap = "bk_coexmats_rosmap.rds", velmeshev = "bk_coexmats_velmeshev.rds")
fdata$lnkmats <- fdata$files %>% mclapply(function(currFile) {
lnkmat <- read_rds(paste0(workspace$outputDir, currFile))
lnkmat[which(lnkmat >= 0.99)] <- 1
lnkmat[which(lnkmat < 0.99)] <- 0
return(lnkmat)
}, mc.cores = length(fdata$files))
fdata$lnkmats %>% saveRDS(paste0(workspace$outputDir, paste0("bk_lnkmats.rds")))
pdata$files$lnkmats <- tibble(outfile = list.files(workspace$outputDir)) %>%
filter(grepl("lnkmats", outfile)) %>%
mutate(outfile_name = gsub(".rds", "", outfile)) %>%
mutate(strs = strsplit(outfile_name, "_")) %>%
mutate(level = strs %>% sapply(function(currStr) { currStr[1] })) %>%
mutate(type = strs %>% sapply(function(currStr) { currStr[2] })) %>%
mutate(cell_type = strs %>% sapply(function(currStr) { currStr[3] })) %>%
dplyr::select(outfile, level, type, cell_type)
# +++++++++++++++++++++
# compute and examine node degrees
fdata <- list(); gc()
fdata$lnkmats <- read_rds(paste0(workspace$outputDir, "bk_lnkmats.rds"))
fdata$degrees <- fdata$lnkmats %>% session$collectionUtils$lapplyWithName(function(currDataset, currlnkmat) {
currlnkmat %>% workspace$utils$computeNodeDegrees() %>% mutate(dataset = currDataset)
}) %>% session$dataWrangler$rbind()
# add in log transformed column
fdata$degrees <- fdata$degrees %>% mutate(node_degree_log10 = log10(node_degree + 1))
fdata$degrees %>% group_by(dataset) %>% summarize(node_degree_max = max(node_degree)) %>% arrange(desc(node_degree_max)) %>% ungroup()
# in vs. out of network (having least one edge)
fdata$degrees %>%
mutate(in_network = (node_degree > 0)) %>%
group_by(dataset, in_network) %>% summarize(n_gene = n()) %>% ungroup() %>%
session$graphingUtils$ggplot(aes(x = in_network, y = n_gene)) +
geom_bar(stat = "identity") +
geom_text(aes(label = n_gene), size = 6, vjust = -0.5) +
facet_wrap(~dataset) +
xlab("Number of genes in network")
# cumulative distribution of node degrees
fdata$degrees %>%
session$graphingUtils$ggplot(aes(x = node_degree_log10, color = dataset)) +
stat_ecdf() +
geom_vline(xintercept = 2, linetype = "dashed")
# correlation of node degrees
fdata$degrees %>%
dplyr::select(gene_id, dataset, node_degree_log10) %>% unique() %>%
spread(dataset, node_degree_log10) %>%
na.omit() %>%
session$dataWrangler$setColAsRownames("gene_id") %>%
GGally::ggpairs()
# ++++++++++++++++++++++++++++++=
# compute how well each bulk tissue co-expression network recovers the edges at the subject & sc level, in each of velmeshev and rosmap
# for each dataset: rosmap & velmeshev
# for each cell type: the 6 cell types
# how well does it recover sc links? how well does it recover sbj links?
fdata <- list(); gc()
# compute lnktbls for the bulk coexmats
fdata$coexmatFiles <- pdata$files$coexmats %>% filter(level == "bk")
fdata$datasets <- fdata$coexmatFiles$outfile
names(fdata$datasets) <- fdata$coexmatFiles$dataset
# fdata$datasets <- fdata$datasets[c("rosmap-ihc", "rosmap-ihcres")] # filter for only target dataset here
1:length(fdata$datasets) %>% mclapply(function(i) {
currFile <- fdata$datasets[i]
currDataset <- names(fdata$datasets[i])
lnkmat <- read_rds(paste0(workspace$outputDir, currFile))
lnkmat[which(lnkmat >= 0.99)] <- 1
lnkmat[which(lnkmat < 0.99)] <- 0
lnktbl <- tibble(pair = lnkmat %>% workspace$utils$getPairIds(), lnk = lnkmat %>% workspace$utils$vectorize())
# ++++++++++++++++++++++++
# COMMIT
lnktbl %>% saveRDS(paste0(workspace$outputDir, paste0("bk_lnktbls_", currDataset, ".rds")))
}, mc.cores = length(fdata$datasets))
# ++++++++++++++++++++++++++++++=
# compute the level of reproducibility between velmeshev and rosmap at the bulk tissue level
fdata <- list(); gc()
fdata$lnktblFiles <- pdata$files$lnktbls %>% filter(level == "bk") %>% dplyr::select(everything(), dataset = cell_type) %>%
filter(dataset %in% c("velmeshev", "rosmap", "velmeshev-mgpres", "rosmap-mgppres"))
fdata$lnktbls <- fdata$lnktblFiles$outfile %>% session$dataWrangler$attachNames(fdata$lnktblFiles$dataset)
fdata$lnktbls <- fdata$lnktbls %>% session$collectionUtils$lapply(function(file) { readRDS(paste0(workspace$outputDir, file)) })
fdata$positives <- fdata$lnktbls %>% session$collectionUtils$lapply(function(lnktbl) { lnktbl %>% filter(lnk == 1) })
fdata$negatives <- fdata$lnktbls %>% session$collectionUtils$lapply(function(lnktbl) { lnktbl %>% filter(lnk == 0) })
fdata$datasets <- fdata$lnktbls %>% names() %>% session$dataWrangler$attachNames()
fdata$fishers <- fdata$datasets %>% session$collectionUtils$lapply(function(dataset_T) {
datasets_P <- fdata$datasets[str_sub(fdata$datasets, 1, 3) != str_sub(dataset_T, 1, 3)]
if (grepl("pres$", dataset_T)) {
datasets_P <- datasets_P[grepl("pres$", datasets_P)]
} else {
datasets_P <- datasets_P[!(grepl("pres$", datasets_P))]
}
print(paste0("dataset_T = ", dataset_T, " vs. ", datasets_P))
datasets_P %>% lapply(function(datasetP) {
pred_T <- fdata$positives[[datasetP]]
pred_F <- fdata$negatives[[datasetP]]
lnks_T <- fdata$positives[[dataset_T]]
# compute fisher's in parallel for the 6 cell types...
session$evaluationUtils$fisher(predicted = pred_T$pair,
notPredicted = pred_F$pair,
trueSet = lnks_T$pair,
alternative = "greater")
})
})
# ++++++++++++++++++++++++
# COMMIT
fdata$fishers %>% saveRDS(paste0(workspace$outputDir, paste0("bk_repro_fisher.rds")))
# ++++++++++++++++++++++++++++++=
# save the formatted version
fdata <- list(); gc()
fdata$fishers <- read_rds(paste0(workspace$outputDir, paste0("bk_repro_fisher.rds")))
fdata$main <- fdata$fishers %>% session$collectionUtils$lapplyWithName(function(dataset_T, currfishers1) {
currfishers1 %>% session$collectionUtils$lapplyWithName(function(dataset_P, currFisher) {
currFisher$stats %>% as.data.frame() %>% t() %>% as_tibble() %>%
mutate(pvalue = currFisher$test$p.value) %>%
mutate(level = "bk", dataset = dataset_P, dat_truth = dataset_T)
}) %>% session$dataWrangler$rbind()
}) %>% session$dataWrangler$rbind()
# ++++++++++++++++++++++++
# COMMIT
fdata$output$fishers <- fdata$fishers
fdata$output$tbl <- fdata$main
fdata$output %>% saveRDS(paste0(workspace$outputDir, paste0("bk_repro_fisher.rds")))
# ++++++++++++++++++++++++
# ++++++++++++++++++++++++++++++=
# gather all the lnktbls, compute fisher in parallel
fdata <- list(); gc()
fdata$lnktblFiles <- pdata$files$lnktbls %>% filter(level == "bk") %>% dplyr::select(everything(), dataset = cell_type)
fdata$datasets <- fdata$lnktblFiles$dataset
names(fdata$datasets) <- fdata$datasets
# fdata$datasets <- fdata$datasets[c("rosmap-ihc", "rosmap-ihcres")] # filter for only target dataset here
fdata$main <- fdata$datasets %>% lapply(function(currDataset) {
print(paste0("working on dataset: ", currDataset))
# set up current predictions; which is the bulk tissue networks;
# question: how well are the sc & sbj network edges recovered in the bulk tissue networks?
pred_lnktbl <- readRDS(paste0(workspace$outputDir, paste0("bk_lnktbls_", currDataset, ".rds")))
pred_T <- pred_lnktbl %>% filter(lnk == 1)
pred_F <- pred_lnktbl %>% filter(lnk == 0)
# for each level
list(sc = "sc", sbj = "sbj") %>% lapply(function(currLevel) {
print(paste0("working on level: ", currLevel))
currFiles <- pdata$files$lnktbls %>% filter(level == currLevel)
celltypes <- currFiles$outfile
names(celltypes) <- currFiles$cell_type
print(paste0("running fisher's exact tests in parallel for the different cell types..."))
celltypes %>% mclapply(function(currFile) {
lnksDataset <- unlist(strsplit(currDataset, "-"))[1]
lnks_T <- readRDS(paste0(workspace$outputDir, currFile))[[lnksDataset]] %>% filter(lnk == 1)
# compute fisher's in parallel for the 6 cell types...
session$evaluationUtils$fisher(predicted = pred_T$pair,
notPredicted = pred_F$pair,
trueSet = lnks_T$pair,
alternative = "greater")
}, mc.cores = length(celltypes))
})
})
# ++++++++++++++++++++++++
# COMMIT
fdata$main %>% saveRDS(paste0(workspace$outputDir, paste0("bk_preservation_fisher.rds")))
# ++++++++++++++++
# save tbl version of fishers
fdata <- list(); gc()
fdata$main <- readRDS(paste0(workspace$outputDir, paste0("bk_preservation_fisher.rds")))
fdata$main <- fdata$main %>% session$collectionUtils$lapplyWithName(function(currDataset, currfishers1) {
currfishers1 %>% session$collectionUtils$lapplyWithName(function(currLevel, currfishers2) {
currfishers2 %>% session$collectionUtils$lapplyWithName(function(currCelltype, currFisher) {
currFisher$stats %>% as.data.frame() %>% t() %>% as_tibble() %>%
mutate(pvalue = currFisher$test$p.value) %>%
mutate(dataset = currDataset, level = currLevel, cell_type = currCelltype)
}) %>% session$dataWrangler$rbind()
}) %>% session$dataWrangler$rbind()
}) %>% session$dataWrangler$rbind()
# ++++++++++++++++++++++++
# COMMIT
fdata$output$fishers <- fdata$fishers
fdata$output$tbl <- fdata$main
fdata$output %>% saveRDS(paste0(workspace$outputDir, paste0("bk_preservation_fisher.rds")))
# ++++++++++++++++++++++++
# ++++++++++++++++++++++++++++++=
# look at how well xCell and xSubject are preserved in bulk tissue
fdata <- list(); gc()
fdata$main <- c(xcell_reproducibility = "sc_repro_fisher.rds",
xsbj_reproducibility = "sbj_repro_fisher.rds",
xsbj_preservation = "sc_sbj_preservation_fisher.rds",
xbulk_reproducibility = "bk_repro_fisher.rds",
xbulk_preservation = "bk_preservation_fisher.rds")
fdata$main <- fdata$main %>% session$collectionUtils$lapply(function(file) { read_rds(paste0(workspace$outputDir, file)) })
fdata$tbls <- fdata$main %>% session$collectionUtils$lapply(function(fisher) { fisher$tbl })
pdata$fishers <- fdata # SOFT COMMIT
# ++++++++++++++++++++++++++++++++++++++++++++++=
# 3. xBulk co-expression networks are somewhat reproducible (plot the other levels as well for these two datasets )
fdata <- list(); gc()
fdata$datasets <- c("velmeshev", "rosmap") %>% session$dataWrangler$attachNames()
fdata$tbls <- pdata$fishers$tbls
fdata$main <- fdata$tbls$xbulk_reproducibility %>%
mutate(cell_type = "bulk") %>%
mutate(level = "xbulk") %>%
dplyr::select(level, cell_type, dat_ref = dat_truth, dat_test = dataset, or, recovered_n, recovered_frac) %>%
mutate(cell_type = dat_ref %>% sapply(function(str) { if (grepl(".*res$", str)) { "bulk_mgpres" } else { "bulk" }})) %>%
mutate(dat_ref = str_extract(dat_ref, "^[a-z]+")) %>%
rbind(fdata$tbls$xsbj_reproducibility %>%
mutate(level = "xsbj") %>%
dplyr::select(level, cell_type, dat_ref = dat_truth, dat_test = dat_sample, or, recovered_n, recovered_frac) %>%
filter(dat_ref %in% fdata$datasets, dat_test %in% fdata$datasets) %>%
mutate(dat_ref = workspace$utils$fmtDataset(dat_ref),
cell_type = workspace$utils$fmtCelltypes(cell_type))) %>%
rbind(fdata$tbls$xcell_reproducibility %>%
mutate(level = "xcell") %>%
dplyr::select(level, cell_type, dat_ref = dat_truth, dat_test = dat_sample, or, recovered_n, recovered_frac) %>%
filter(dat_ref %in% fdata$datasets, dat_test %in% fdata$datasets) %>%
mutate(dat_ref = workspace$utils$fmtDataset(dat_ref),
cell_type = workspace$utils$fmtCelltypes(cell_type)))
fdata$main %>%
session$graphingUtils$ggplot(aes(x = cell_type, y = or)) +
geom_bar(stat = "identity") +
geom_text(aes(label = round(or, 1)), vjust = -0.5, size = 5) +
facet_wrap(~dat_ref*level, scales = "free_x") +
session$graphingUtils$tiltX(angle = 90) +
ylim(0, 200)
# =================================================
# OUTPUT FIGURE
xdata <- list()
xdata$figName <- "figure_01.eps"
xdata$main <- fdata$main %>% mutate(level = level %>% sapply(function(str) {
if (str == "xbulk") { "xBulk" }
else if (str == "xsbj") { "xSubject" }
else { "xCell" }
}))
xdata$plot <- xdata$main %>%
session$graphingUtils$ggplot(aes(x = cell_type, y = or)) +
geom_bar(stat = "identity") +
geom_text(aes(label = round(or, 1)), vjust = -0.5, size = 5) +
facet_wrap(~dat_ref*level, scales = "free_x") +
session$graphingUtils$tiltX(angle = 90) +
ylim(0, 200) +
ggtitle("Reproducibility of co-expression edges between the Velmeshev and ROSMAP datasets") +
theme(plot.title = element_text(size = 20), plot.subtitle = element_text(size = 14)) +
ylab("Odds ratio")
xdata$plot
ggsave(filename = paste0(pdata$figuresDir, xdata$figName),
plot = xdata$plot, device = "eps", units = "cm", width = 20, height = 30, dpi = 1000)
# =================================================
# =================================================
# OUTPUT FIGURE
# TODO move this to the next figure !
xdata <- list()
xdata$figName <- "figure_0XXXX.eps"
xdata$main <- fdata$main %>%
mutate(dataset = workspace$utils$fmtDataset(dataset),
cell_type = workspace$utils$fmtCelltypes(cell_type)) %>%
mutate(level = level %>% sapply(function(str) {
if (str == "sc") { "xCell" }
else { "xSubject" }
}))
xdata$plot <- xdata$main %>% session$graphingUtils$ggplot(aes(x = cell_type, y = or)) +
geom_bar(aes(fill = level), position = "dodge", stat = "identity") +
facet_wrap(~dataset, ncol = 2) +
session$graphingUtils$tiltX(angle = 90) +
scale_fill_hue(l = 45) +
xlab("Cell type") +
ylab("Preservation of co-expression edges\n(Odds ratio)") +
labs(fill = "Level")
xdata$plot
ggsave(filename = paste0(pdata$figuresDir, xdata$figName),
plot = xdata$plot, device = "eps", units = "cm", width = 25, height = 13, dpi = 1000)
# =================================================
# ++++++++++++================================
# ok, here plot xcell and xsubject reproducibility against preservation at the xbulk level
# first for rosmap
fdata <- list(); gc()
fdata$dataset <- "rosmap"
fdata$repro <- pdata$fishers$tbls$xcell_reproducibility %>% filter(dat_truth == fdata$dataset) %>%
group_by(cell_type) %>%
summarize(or = mean(or)) %>%
mutate(level = "xCell") %>%
rbind(pdata$fishers$tbls$xsbj_reproducibility %>% filter(dat_truth == fdata$dataset) %>%
group_by(cell_type) %>%
summarize(or = mean(or)) %>%
mutate(level = "xSubject")) %>%
dplyr::select(cell_type, level, or)
fdata$preserv <- pdata$fishers$tbls$xbulk_preservation %>%
filter(dataset %in% fdata$dataset) %>%
dplyr::select(cell_type, level, or) %>%
mutate(level = level %>% sapply(function(str) {
if (str == "sc") { "xCell" } else { "xSubject" }
}))
# =================================================
# OUTPUT FIGURE
xdata <- list()
xdata$figName <- "figure_02.eps"
xdata$main <- fdata$repro %>%
dplyr::select(cell_type, level, reproducbility = or) %>%
left_join(fdata$preserv %>% dplyr::select(cell_type, level, preservation = or), by = c("cell_type", "level"))
xdata$plot <- xdata$main %>%
session$graphingUtils$ggplot(aes(x = preservation, y = reproducbility)) +
geom_point(aes(color = level, shape = cell_type), size = 4) +
geom_abline(slope = 1, linetype = "dashed") +
scale_color_manual(values = c("#bf8502", "#0576b5")) +
scale_x_continuous(trans = "log2", limits = c(2, 150)) +
scale_y_continuous(trans = "log2", limits = c(2, 150)) +
xlab("Preservation of co-expression at the xBulk level\n(Odds ratio - log2 scale)") +
ylab("Reproducibility of co-expression at the\nxCell and xSubject levels\n(Odds ratio - log2 scale)") +
ggtitle("Reproducibility of xCell or xSubject co-expression\nvs. their preservation at the xBulk level", "ROSMAP")
xdata$plot
ggsave(filename = paste0(pdata$figuresDir, xdata$figName),
plot = xdata$plot, device = "eps", units = "cm", width = 20, height = 15)
# =================================================
# first for velmeshev
fdata <- list(); gc()
fdata$dataset <- "velmeshev"
fdata$repro <- pdata$fishers$tbls$xcell_reproducibility %>% filter(dat_truth == fdata$dataset) %>%
group_by(cell_type) %>%
summarize(or = mean(or)) %>%
mutate(level = "xCell") %>%
rbind(pdata$fishers$tbls$xsbj_reproducibility %>% filter(dat_truth == fdata$dataset) %>%
group_by(cell_type) %>%
summarize(or = mean(or)) %>%
mutate(level = "xSubject")) %>%
dplyr::select(cell_type, level, or)
fdata$preserv <- pdata$fishers$tbls$xbulk_preservation %>%
filter(dataset %in% fdata$dataset) %>%
dplyr::select(cell_type, level, or) %>%
mutate(level = level %>% sapply(function(str) {
if (str == "sc") { "xCell" } else { "xSubject" }
}))
# =================================================
# OUTPUT FIGURE
xdata <- list()
xdata$figName <- "figure_03.eps"
xdata$main <- fdata$repro %>%
dplyr::select(cell_type, level, reproducbility = or) %>%
left_join(fdata$preserv %>% dplyr::select(cell_type, level, preservation = or), by = c("cell_type", "level"))
xdata$plot <- xdata$main %>%
session$graphingUtils$ggplot(aes(x = preservation, y = reproducbility)) +
geom_point(aes(color = level, shape = cell_type), size = 4) +
geom_abline(slope = 1, linetype = "dashed") +
scale_color_manual(values = c("#bf8502", "#0576b5")) +
scale_x_continuous(trans = "log2", limits = c(2, 150)) +
scale_y_continuous(trans = "log2", limits = c(2, 150)) +
xlab("Preservation of co-expression at the xBulk level\n(Odds ratio - log2 scale)") +
ylab("Reproducibility of co-expression at the\nxCell and xSubject levels\n(Odds ratio - log2 scale)") +
ggtitle("Reproducibility of xCell or xSubject co-expression\nvs. their preservation at the xBulk level", "Velmeshev")
xdata$plot
ggsave(filename = paste0(pdata$figuresDir, xdata$figName),
plot = xdata$plot, device = "eps", units = "cm", width = 20, height = 15)
# =================================================
# ++++++++++++++++++++++++++++++++++++++++++++++=
fdata <- list(); gc()
fdata$main <- c(rosmap_ihc = "bk_exprmats_rosmap-ihcres.rds",
rosmap_mgp = "bk_exprmats_rosmap-mgpres.rds",
velmeshev_mgp = "bk_exprmats_velmeshev-mgpres.rds")
fdata$main <- fdata$main %>% session$collectionUtils$lapply(function(file) { read_rds(paste0(workspace$outputDir, file)) })
# =======================
pdata$ccvs <- fdata # SOFT COMMIT ###### !!!!!!!!!!!!!!!!!!
# =====================
# ++++++++++++++++======================================
# let's make sure that the markers I used aren't severely co-expressed at the xSubject level
# check for "uniform distribution" of the co-expressions...
fdata <- list()
fdata$mkrs <- pdata$mkrs$mkrsFlat
fdata$mkrCoexTbl <- fdata$mkrs %>% session$collectionUtils$lapplyWithName(function(celltype, mkrs) {
currCoexmats <- pdata$files$coexmats %>% filter(level == "sbj", dataset %in% c("velmeshev", "rosmap"), cell_type == celltype)
currCoexmats <- currCoexmats$outfile %>% session$dataWrangler$attachNames()
currCoexmats %>% lapply(function(currCoexmat) {
coexmat <- read_rds(paste0(workspace$outputDir, currCoexmat))
genes <- mkrs %>% intersect(rownames(coexmat))
coexmat <- coexmat[genes, genes]
coextbl <- coexmat %>% workspace$utils$vectorize() %>% session$dataWrangler$vectorToTibble() %>%
dplyr::select(coex = value) %>%
mutate(coex_file = currCoexmat, cell_type = celltype) %>%
dplyr::select(cell_type, coex_file, coex)
coextbl <- coexmat %>% workspace$utils$getCoords() %>% cbind(coextbl) %>% as_tibble()
return(coextbl)
}) %>% session$dataWrangler$rbind()
}) %>% session$dataWrangler$rbind()
# lets get rid of the to the most co-regulated genes in oligodendrocyte and see how things change
fdata$mkrCoexTbl %>%
filter(cell_type == "oligodendrocyte", coex_file == "sbj_coexmats_velmeshev_oligodendrocyte.rds") %>%
filter(coex > 0.9) -> x
x$gene_a %>%
c(x$gene_b) %>% as_tibble() %>% group_by(value) %>% summarize(n = n()) %>% arrange(desc(n)) -> y
pdata$ccvs$main$velmeshev_mgp$mgps$rotations$oligodendrocyte %>%
session$dataWrangler$setRownameAsColumn("value") %>% dplyr::select(value, PC6) %>%
left_join(y, by = "value") %>%
session$graphingUtils$ggplot(aes(x = n, y = PC6)) + geom_point()
pdata$ccvs$main$rosmap_mgp$ccvModels$ctpMat
y %>% filter(n < 20) %>% session$dataWrangler$extractColumn("value") -> y
workspace$utils$computeMgps(list(oligo = y), pdata$ccvs$main$velmeshev_mgp$ccvModels$exprmats$orig) -> yy
yy$main %>%
session$dataWrangler$setRownameAsColumn("sample") %>%
mutate(orig = pdata$ccvs$main$velmeshev_mgp$mgps$estimates$oligodendrocyte[rownames(yy$main)]) -> z
z %>% session$graphingUtils$ggplot(aes(x = oligo, y = orig)) + geom_point()
cor(z$oligo, z$orig)
# =================================================
# OUTPUT FIGURE
xdata <- list()
xdata$figName <- "sfigure_01.eps"
xdata$plot <- fdata$mkrCoexTbl %>%
session$graphingUtils$ggplot(aes(x = coex)) +
geom_histogram() +
facet_wrap(~cell_type*coex_file) +
ggtitle("Within cell type co-expression among marker genes at the xSubject level")
xdata$plot
ggsave(filename = paste0(pdata$figuresDir, xdata$figName),
plot = xdata$plot, device = "eps", units = "cm", width = 40, height = 30)
# ================================================
# ++++++++++++++++++++++=======================================================
# the other thing is to check whether cell type specificity makes a gene's R^2 higher
fdata <- list(); gc()
fdata$minfc <- pdata$mkrs$minfc
fdata$minfc <- fdata$minfc %>% filter(!(gene_id %in% unlist(pdata$mkrs$mkrsFlat)))
# compute the variance
fdata$vars$velmeshev <- fdata$minfc %>%
filter(dataset == "velmeshev") %>% group_by(gene_id) %>% summarize(log2_expr_var = log2(var(expr))) %>% ungroup()
fdata$vars$rosmap <- fdata$minfc %>%
filter(dataset == "rosmap") %>% group_by(gene_id) %>% summarize(log2_expr_var = log2(var(expr))) %>% ungroup()
# for ihc
fdata$main$ihc <- pdata$ccvs$main$rosmap_ihc$ccvModel$stats$lmStats %>% dplyr::select(gene_id, rsqr)
fdata$main$ihc <- fdata$main$ihc %>% inner_join(fdata$vars$rosmap, by = "gene_id")
fdata$main$ihc <- fdata$main$ihc %>% mutate(method = "ihc")
# for rosmap-mgp
fdata$main$rosmapMgp <- pdata$ccvs$main$rosmap_mgp$ccvModels$stats$lmStats %>% dplyr::select(gene_id, rsqr)
fdata$main$rosmapMgp <- fdata$main$rosmapMgp %>% inner_join(fdata$vars$rosmap, by = "gene_id")
fdata$main$rosmapMgp <- fdata$main$rosmapMgp %>% mutate(method = "rosmap-mgp")
# for velmeshev-mgp
fdata$main$velmeshevMgp <- pdata$ccvs$main$velmeshev_mgp$ccvModels$stats$lmStats %>% dplyr::select(gene_id, rsqr)
fdata$main$velmeshevMgp <- fdata$main$velmeshevMgp %>% inner_join(fdata$vars$velmeshev, by = "gene_id")
fdata$main$velmeshevMgp <- fdata$main$velmeshevMgp %>% mutate(method = "velmeshev-mgp")
# all
fdata$main$all <- fdata$main$ihc %>% rbind(fdata$main$rosmapMgp) %>% rbind(fdata$main$velmeshevMgp)
fdata$corVals <- fdata$main$all %>%
group_by(method) %>% summarize(cor_coef = cor(rsqr, log2_expr_var)[1, 1])
# =================================================
# OUTPUT FIGURE ---- ihc
xdata <- list()
xdata$figName <- "figure_04.png"
xdata$figName2 <- "figure_04_1.png"
xdata$main <- fdata$main$all %>% filter(method == "ihc")
xdata$plot2 <- xdata$main %>% session$graphingUtils$ggplot(aes(x = rsqr)) + geom_density(fill = "grey80") +
xlim(0, 1) +
theme(axis.title.x=element_blank(),
axis.text.x=element_blank(),
axis.ticks.x=element_blank(),
axis.title.y=element_blank(),
axis.text.y=element_blank(),
axis.ticks.y=element_blank())
xdata$plot2
ggsave(filename = paste0(pdata$figuresDir, xdata$figName2),
plot = xdata$plot2, device = "png", units = "cm", width = 18, height = 10)
xdata$plot <- xdata$main %>%
session$graphingUtils$ggplot(aes(x = log2_expr_var, y = rsqr)) +
geom_point(shape = 1) +
geom_smooth(method = "lm", se = FALSE) +
ylim(0, 1) +
xlab("Variation across cell types\nlog2(variance)") +
ylab(bquote("PVE by cell type proportions"~(R^2))) +
ggtitle("Association between cross cell type\nvariability and CCV influence across genes", "ROSMAP-IHC")
xdata$plot
ggsave(filename = paste0(pdata$figuresDir, xdata$figName),
plot = xdata$plot, device = "png", units = "cm", width = 18, height = 18)
# =================================================
# =================================================
# OUTPUT FIGURE ---- rosmap-mgp
xdata <- list()
xdata$figName <- "figure_05.png"
xdata$figName2 <- "figure_05_1.png"
xdata$main <- fdata$main$all %>% filter(method == "rosmap-mgp")
xdata$plot2 <- xdata$main %>% session$graphingUtils$ggplot(aes(x = rsqr)) + geom_density(fill = "grey80") +
xlim(0, 1) +
theme(axis.title.x=element_blank(),
axis.text.x=element_blank(),
axis.ticks.x=element_blank(),
axis.title.y=element_blank(),
axis.text.y=element_blank(),
axis.ticks.y=element_blank())
xdata$plot2
ggsave(filename = paste0(pdata$figuresDir, xdata$figName2),
plot = xdata$plot2, device = "png", units = "cm", width = 18, height = 10)
xdata$plot <- xdata$main %>%
session$graphingUtils$ggplot(aes(x = log2_expr_var, y = rsqr)) +
geom_point(shape = 1) +
geom_smooth(method = "lm", se = FALSE) +
ylim(0, 1) +
xlab("Variation across cell types\nlog2(variance)") +
ylab(bquote("PVE by cell type proportions"~(R^2))) +
ggtitle("Association between cross cell type\nvariability and CCV influence across genes", "ROSMAP-MGP")
xdata$plot
ggsave(filename = paste0(pdata$figuresDir, xdata$figName),
plot = xdata$plot, device = "png", units = "cm", width = 18, height = 18)
# =================================================
# =================================================
# OUTPUT FIGURE ---- ihc
xdata <- list()
xdata$figName <- "figure_06.png"
xdata$figName2 <- "figure_06_1.png"
xdata$main <- fdata$main$all %>% filter(method == "velmeshev-mgp")
xdata$plot2 <- xdata$main %>% session$graphingUtils$ggplot(aes(x = rsqr)) + geom_density(fill = "grey80") +
xlim(0, 1) +
theme(axis.title.x=element_blank(),
axis.text.x=element_blank(),
axis.ticks.x=element_blank(),
axis.title.y=element_blank(),
axis.text.y=element_blank(),
axis.ticks.y=element_blank())
xdata$plot2
ggsave(filename = paste0(pdata$figuresDir, xdata$figName2),
plot = xdata$plot2, device = "png", units = "cm", width = 18, height = 10)
xdata$plot <- xdata$main %>%
session$graphingUtils$ggplot(aes(x = log2_expr_var, y = rsqr)) +
geom_point(shape = 1) +
geom_smooth(method = "lm", se = FALSE) +
ylim(0, 1) +
xlab("Variation across cell types\nlog2(variance)") +
ylab(bquote("PVE by cell type proportions"~(R^2))) +
ggtitle("Association between cross cell type\nvariability and CCV influence across genes", "Velmeshev-MGP")
xdata$plot
ggsave(filename = paste0(pdata$figuresDir, xdata$figName),
plot = xdata$plot, device = "png", units = "cm", width = 18, height = 18)
# =================================================
# ++++++++++++++++++++++++++++++++++++++++++++++=
# 5. CCV correction reduces concordance with xCell network, but improves concordance with xSubject
# let's first start with the IHC dataset
fdata <- list(); gc()
fdata$main <- pdata$ccvs$main$velmeshev_mgp$ccvModel
fdata$stats <- fdata$main$stats %>% lapply(na.omit)
xdata <- list()
xdata$proportions <- fdata$main$ctpMat %>%
session$dataWrangler$setRownameAsColumn("sample") %>%
gather(cell_type, proportion, -sample)
xdata$proportions %>%
session$graphingUtils$ggplot(aes(x = sample, y = proportion, fill = cell_type)) +
geom_bar(stat = "identity") +
session$graphingUtils$tiltX(angle = 90) +
ylab("Cell type proportion")
xdata <- list()
xdata$mean <- fdata$stats$lmStats$rsqr %>% mean()
fdata$stats$lmStats %>% session$graphingUtils$ggplot(aes(x = rsqr)) + geom_histogram() +
geom_vline(xintercept = xdata$mean, linetype = "dashed", color = "red", size = 1) +
ggtitle("R^2 distribution - IHC")
fdata$stats$lmStats %>% session$graphingUtils$ggplot(aes(x = pvalue)) + geom_histogram() +
ggtitle("P-value distribution - IHC")
(fdata$sigGenes <- fdata$stats$lmStats %>% filter(qvalue < 0.1))
fdata$stats$coefStats %>%
session$graphingUtils$ggplot(aes(x = rsqr_indep)) + geom_histogram() + facet_wrap(~cell_type)
# sanity check that beta values are positive --- genes would be positively correlated with cell type proportions
fdata$stats$coefStats %>% mutate(significant = gene_id %in% fdata$sigGenes$gene_id) %>%
session$graphingUtils$ggplot(aes(x = beta, y = significant)) +
geom_boxplot() +
geom_vline(xintercept = 0, linetype = "dashed", color = "red", size = 1) +
facet_wrap(~cell_type)
fdata$stats$coefStats %>% filter(gene_id %in% fdata$sigGenes$gene_id) %>% arrange(desc(rsqr_indep)) %>% left_join(pdata$genes, by = "gene_id") %>% View()
# TWO GENES TO HIGHLIGHT AS EXAMPLES
# ENSG00000144285 - SCN2A
# ENSG00000198780 - FAM169A
# pdata$mkrs$minfc %>% filter(gene_id == "ENSG00000198780")
# plot these genes as functions of cell type proportions
xdata <- list()
xdata$ccv <- fdata$main$ctpMat %>% session$dataWrangler$setRownameAsColumn("sample") %>%
gather(cell_type, proportion, -sample)
xdata$gene <- "ENSG00000144285"
xdata$geneSymbol <- pdata$genes %>% filter(gene_id == xdata$gene)
xdata$expr <- fdata$main$exprmats$orig[xdata$gene,] %>% session$dataWrangler$vectorToTibble() %>% dplyr::select(sample = variable, expr = value)
xdata$ccv %>% left_join(xdata$expr, by = "sample") %>%
session$graphingUtils$ggplot(aes(x = proportion , y = expr)) +
geom_point() +
geom_smooth(method = "lm", se = FALSE) +
facet_wrap(~cell_type) +
ggtitle(paste0("Expression of ", xdata$geneSymbol$gene, "\nby neuron fractions (IHC estimates)"))
# plot the co-expression of these genes before and after
xdata <- list()
xdata$genes <- pdata$genes %>% filter(gene_id %in% c("ENSG00000144285", "ENSG00000198780"))
xdata$expr <- fdata$main$exprmats$residual[xdata$genes$gene_id,] %>% t() %>% session$dataWrangler$setRownameAsColumn("sample")
names(xdata$expr) <- c("sample", xdata$genes$gene)
xdata$corCoef <- xdata$expr$FAM169A %>% cor(xdata$expr$SCN1A)
xdata$expr %>%
session$graphingUtils$ggplot(aes(x = SCN1A, y = FAM169A)) +