-
Notifications
You must be signed in to change notification settings - Fork 3
/
OSHetero2021_FigureCode.Rmd
1785 lines (1517 loc) · 56.4 KB
/
OSHetero2021_FigureCode.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: "OSHetero2021"
author: "Sanjana Rajan, Emily Franz, Matthew Cannon"
date: "`r format(Sys.time(), '%m/%d/%Y')`"
output:
html_document:
toc: true
toc_float: true
toc_depth: 5
number_sections: false
code_folding: hide
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(
tidy = TRUE,
echo = TRUE,
cache = TRUE,
collapse = TRUE,
tidy.opts = list(width.cutoff = 95),
message = FALSE,
warning = FALSE,
cache.lazy = FALSE,
fig.show='hide'
)
```
*Seurat object loading and processing code can be found in "OSHetero2021_Load_Process.Rmd". Object outputs from that code are loaded in the code below.*
# Figure 1
**Cell line and PDX models of osteosarcoma display transcriptional heterogeneity.**
```{r Fig1_lib, cache=FALSE}
source("Downstream.v2.R")
set.seed(888)
# loading libraries
library(Seurat)
library(ggplot2)
library(msigdbr)
library(clusterProfiler)
library(grid)
library(data.table)
library(tidyverse)
library(ggridges)
message(paste("Working directory: ", getwd()))
```
## Figure 1A
A) UMAP analysis of OS-17 cells (n = 3178) grown in cell culture. Cell cycle distribution of cells (n = 3178) is visualized as pie charts.
```{r Fig1a_OS17}
load("Data/os17_cx_CCR.RData")
# Culture plot
figure1_a1 <- DimPlot(os17_cx,
reduction = "umap",
pt.size = 1,
label = T) +
coord_fixed() +
ggtitle("OS17 in Culture") +
NoAxes() +
scale_color_npg(alpha = 1)
# View Culture plot in Rmd
figure1_a1
# Save as pdf
if(!dir.exists("Figures")) {
dir.create("Figures")
}
if(!dir.exists("Figures/figure_1")) {
dir.create("Figures/figure_1")
}
pdf("Figures/figure_1/figure_1a_os17.pdf",
width = 5,
height = 5)
figure1_a1
dev.off()
# Cell cycle distribution of clusters
cid <- sort(unique(os17_cx@active.ident))
vplayout <- function(x, y) viewport(layout.pos.row = x,
layout.pos.col = y)
pdf("Figures/figure_1/figure_1a_os17_pie.pdf",
width = 6,
height = 2)
grid.newpage()
pushViewport(viewport(layout = grid.layout(1, length(unique(os17_cx@active.ident)))))
for(i in seq_along(unique(os17_cx@active.ident))){
temp <- WhichCells(os17_cx,
idents = cid[[i]])
LT.cells <- subset(os17_cx,
cells = temp)
df <- table(LT.cells$Phase)
bp <- ggplot(as.data.frame(df),
aes(x = "",
y = Freq,
fill = Var1)) +
geom_bar(width = 1,
stat = "identity")
pie <- bp +
coord_polar("y",
start = 0) +
scale_fill_brewer(palette = "Blues") +
theme_minimal() +
NoAxes() + NoLegend() +
ggtitle(paste("Cluster",
cid[[i]]))
print(pie,
vp = vplayout(ceiling(i / length(unique(os17_cx@active.ident))),
i))
}
dev.off()
```
## Figure 1B
B) UMAP analysis of NCH-OS-7 cells (n = 1998) grown as subcutaneous flank tumor. Cell cycle distribution of cells is visualized as pie charts.
```{r Fig1b_NCHOS7}
load(file = "Data/os7_cx_CCR.RData")
# Flank plots
figure_1b <- DimPlot(os7_cx,
reduction = "umap",
pt.size = 1,
label = T) +
coord_fixed() +
ggtitle("NCHOS7 in Flank") +
NoAxes() +
scale_color_npg(alpha = 1)
# View in Rmd
figure_1b
# Save as pdf
pdf("Figures/figure_1/figure_1b_nchos7.pdf",
width = 5,
height = 5)
figure_1b
dev.off()
# Cell cycle distribution of clusters
cid <- sort(unique(os7_cx@active.ident))
vplayout <- function(x, y) viewport(layout.pos.row = x, layout.pos.col = y)
pdf("Figures/figure_1/figure_1b_nchos7_pie.pdf",
width = 6,
height = 2)
grid.newpage()
pushViewport(viewport(layout = grid.layout(1, length(unique(os7_cx@active.ident)))))
for(i in seq_along(unique(os7_cx@active.ident))){
temp <- WhichCells(os7_cx,
idents = cid[[i]])
LT.cells <- subset(os7_cx,
cells = temp)
df <- table(LT.cells$Phase)
bp <- ggplot(as.data.frame(df),
aes(x="",
y=Freq,
fill=Var1)) +
geom_bar(width = 1,
stat = "identity")
pie <- bp +
coord_polar("y",
start=0) +
scale_fill_brewer(palette="Blues") +
theme_minimal() +
NoAxes() +
NoLegend() +
ggtitle(paste("Cluster",
cid[[i]]))
print(pie,
vp=vplayout(ceiling(i/length(unique(os7_cx@active.ident))),
i))
}
dev.off()
```
## Figure 1C
C) Pathway enrichment analysis for hallmark gene sets associated with genes upregulated in distinct clusters identified in the two osteosarcoma models. P values were adjusted for multiple comparisons. Boxes in grey identify non-significant enrichments, whereas boxes in red identify statistically significant enrichments. MTORC1: mechanistic target of rapamycin (mTOR) complex 1. PI3K: Phosphoinositide 3-kinase. AKT: Protein kinase B. TGF: Transforming growth-factor. TNF: tumor necrosis factor. NFKB: Nuclear Factor kappa-light-chain-enhancer of activated B cells.
```{r Fig1c_dgea, dependson='Fig1b_NCHOS7'}
# Pathway enrichment analysis
# Display adjust p-values
B.list <- list(OS17 = os17_cx,
NCHOS7 = os7_cx)
em.hm.list <- list()
for (i in seq_along(B.list)) {
em.hm.list[[i]] <- DGEA(B.list[[i]])
}
for(i in seq_along(em.hm.list)) {
em.hm.list[[i]] <- setDT(em.hm.list[[i]],
keep.rownames = TRUE)[]
}
temp1 <- em.hm.list[[1]]
temp2 <- em.hm.list[[2]]
cx.pd <- full_join(temp1,
temp2,
by = "rn")
cx.pd <- column_to_rownames(cx.pd,
var = "rn")
cx.pd[is.na(cx.pd)] <- 1
#remove "HALLMARK_"
c <- rownames(cx.pd)
c <- gsub("HALLMARK_",
"",
c)
#remove "_" by removing special characters
c <- gsub("_",
" ",
c)
rownames(cx.pd) <- c
# Take the -log10
cx.pd.log <- -log10(cx.pd)
colnames(cx.pd.log) <- c("A0",
"A1",
"A2",
"A3",
"B0",
"B1",
"B2",
"B3")
# To prevent values that show up as -0.00, we take the absolute values
cx.pd.log <- abs(cx.pd.log)
figure_1c <- cx.pd.log %>%
t() %>%
as.data.frame() %>%
rownames_to_column(var = "Sample") %>%
pivot_longer(c(-Sample),
names_to = "Pathway",
values_to = "pval",
names_repair = "minimal") %>%
mutate(Signif = pval >= (-1 * log10(0.05))) %>%
ggplot(.,
aes(x = Sample,
y = Pathway,
fill = Signif)) +
geom_tile() +
geom_text(aes(label = sprintf("%0.2f",
pval))) +
scale_fill_manual(values = c("gray",
"red")) +
scale_y_discrete(limits = rev,
position = "right") +
theme(legend.position = "right",
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
axis.ticks.x = element_blank()) +
ylab("")
figure_1c
#Save as PDF
pdf("Figures/figure_1/figure_1c.pdf",
width = 8,
height = 8)
figure_1c
dev.off()
```
# Figure 2
Figure 2. Osteosarcoma cells adopt distinct transcriptional profiles as they colonize tibia and lung microenvironments. A) Schematic of study design depicting generation of orthotopic primary and metastatic tumors. Tumors were harvested for scRNA-seq when mice reached endpoint.
## Figure 2B
B) Venn diagrams showing overlap of differentially expressed genes that are up- or down- regulated in primary or metastatic tumors relative to corresponding starting population of cells (cell line or PDX flank tumors). Region outlined in red identifies differentially expressed genes shared across at least three models.
```{r Fig2b, fig.height=10, fig.width=10}
load("Data/OS_merged_postCCR.RData")
# Set seed before subsetting and DE analysis to ensure consistent results
set.seed(100)
OS$tissue <- OS$src %>%
stringr::str_replace("Flank", "Culture")
OS <- subset(OS, subset = model != "Osteoblasts")
Idents(OS) <- OS$tissue
de_out <- list()
for (tissue_name in c("Tibia", "Lung")) {
for (cl_name in unique(OS$model)) {
message(tissue_name, " ", cl_name)
temp_seurat <- subset(OS, subset = (tissue == tissue_name |
tissue == "Culture") &
model == cl_name)
temp_de_out <-
FindMarkers(temp_seurat,
ident.1 = tissue_name,
ident.2 = "Culture",
min.pct = 0.1) %>%
filter(p_val_adj <= 0.05)
de_out[[tissue_name]][["up"]][[cl_name]] <-
temp_de_out %>%
filter(avg_log2FC > 0) %>%
rownames()
de_out[[tissue_name]][["down"]][[cl_name]] <-
temp_de_out %>%
filter(avg_log2FC < 0) %>%
rownames()
rm(temp_seurat, temp_de_out)
}
}
figure_2b <- list()
for (tissue_name in c("Tibia", "Lung")) {
for (direction in c("up", "down")) {
figure_2b[[paste0(tissue_name,
" - ",
direction)]] <-
ggvenn::ggvenn(de_out[[tissue_name]][[direction]],
fill_color = c("#0073C2FF",
"#EFC000FF",
"#868686FF",
"#CD534CFF"),
stroke_size = 0.1,
set_name_size = 2,
text_size = 1.3,
show_percentage = TRUE) +
ggtitle(paste0(tissue_name,
" - ",
direction)) +
theme(plot.title = element_text(hjust = 0.5,
vjust = -8,
size = 10,
face = "bold"),
plot.margin = margin(-2, 0, -2, 0, "cm"))
# Fix the position of the bottom two set names
figure_2b[[paste0(tissue_name,
" - ",
direction)]]$layers[[3]]$data$x <-
c(-1, -0.8, 0.8, 1)
}
}
#Save as PDF
if(!dir.exists("Figures/figure_2")) {
dir.create("Figures/figure_2")
}
pdf("Figures/figure_2/figure_2b.pdf",
width = 4,
height = 4)
# Put all four plots into one image
gridExtra::grid.arrange(grobs = figure_2b,
vp = viewport(width = 1.0, height = 0.9))
dev.off()
# Save RData obj
save(figure_2b, file = "Figures/figure_2/figure_2b.RData")
```
## Figure 2C
C) Pathway enrichment analysis with adjusted p values for hallmark gene sets associated with these shared genes
```{r Fig2c, dependson = "Fig2b", fig.height=6, fig.width=10}
### Extract genes that are shared in these datasets
load("Data/OS_merged_postCCR.RData")
# Set seed before subsetting and DE analysis to ensure consistent results
set.seed(100)
data <- list(
os17 = subset(OS, cells = WhichCells(OS, expression = model == "OS-17")),
t143B = subset(OS, cells = WhichCells(OS, expression = model == "143B")),
NCHOS2 = subset(OS, cells = WhichCells(OS, expression = model == "NCH-OS-2")),
NCHOS7 = subset(OS, cells = WhichCells(OS, expression = model == "NCH-OS-7"))
)
# Rename "Flank" to "Culture" for NCHOS samples
data$NCHOS2$src[grep("Flank", data$NCHOS2$src)] <- "Culture"
data$NCHOS7$src[grep("Flank", data$NCHOS7$src)] <- "Culture"
fig_2c_data <- tibble()
for (tissue_name in c("Tibia", "Lung")) {
for (direction in c("up", "down")) {
de_genes <- list()
for (i in seq_len(length(data))) {
Idents(data[[i]]) <- data[[i]]$src
de_genes[[i]] <-
FindMarkers(data[[i]],
ident.1 = tissue_name,
ident.2 = "Culture",
only.pos = FALSE,
min.pct = 0.1)
# Select genes that change in the direction of interest
if (direction == "up") {
de_genes[[i]] <-
de_genes[[i]][de_genes[[i]]$p_val_adj < 0.05 &
de_genes[[i]]$avg_log2FC > 0, ]
} else {
de_genes[[i]] <-
de_genes[[i]][de_genes[[i]]$p_val_adj < 0.05 &
de_genes[[i]]$avg_log2FC < 0, ]
}
}
A <- rownames(de_genes[[1]])
B <- rownames(de_genes[[2]])
C <- rownames(de_genes[[3]])
D <- rownames(de_genes[[4]])
# Preparing clusterProfiler to perform hypergeometric test on msigdb signatures
msig.gene.set <-
msigdbr(species = "Homo sapiens", category = "H") %>%
dplyr::select(gs_name, human_gene_symbol)
msig.name <-
msigdbr(species = "Homo sapiens", category = "H") %>%
dplyr::select(gs_id, gs_name)
# Getting middle "flower" of the Venn diagram
intersect <- c((intersect(intersect(intersect(A, B), C), D)),
(intersect(intersect(A, B), C)),
(intersect(intersect(A, B), D)),
(intersect(intersect(A, D), C)),
(intersect(intersect(B, D), C))) %>%
unique()
temp <-
enricher(intersect,
TERM2GENE = msig.gene.set,
TERM2NAME = msig.name)@result %>%
as_tibble() %>%
select(ID, p.adjust) %>%
dplyr::rename(pathway = ID) %>%
arrange(p.adjust) %>%
slice_head(n = 5) %>%
mutate(tissue = tissue_name,
label_y = if_else(direction == "up", 1, -1),
p.adjust = -log10(p.adjust),
pathway = str_remove(pathway, "HALLMARK_") %>%
str_replace_all("_", " "),
order = seq_len(n()))
if (direction == "down") {
temp$p.adjust <- temp$p.adjust * -1
}
fig_2c_data <- bind_rows(fig_2c_data, temp)
}
}
################ Two sided Barplot
# Properly name and order tissue types
fig_2c_data <- fig_2c_data %>%
mutate(tissue = stringr::str_replace(tissue,
"Tibia",
"Tibia Gene Sets") %>%
stringr::str_replace("Lung",
"Lung Gene Sets"),
pathway = stringr::str_wrap(pathway, width = 25))
fig_2c_data$tissue <- factor(as.factor(fig_2c_data$tissue),
levels = c("Tibia Gene Sets",
"Lung Gene Sets"))
# Create tibble that is properly ordered to use in proper plotting of tibia and lung data
lab4plot <- tibble(y = c(-4, 4, -4, 4),
x = c(0.5, 0.5, 0.5, 0.5),
label = as.factor(c("Downregulated\nduring tibia colonization",
"Upregulated\nduring tibia colonization",
"Downregulated\nduring lung colonization",
"Upregulated\nduring lung colonization")),
tissue = factor(as.factor(c("Tibia Gene Sets",
"Tibia Gene Sets",
"Lung Gene Sets",
"Lung Gene Sets")),
levels = c("Tibia Gene Sets",
"Lung Gene Sets")))
figure_2c <-
ggplot() +
geom_bar(data = fig_2c_data,
aes(x = -1 * order,
y = p.adjust,
fill = p.adjust > 0),
stat = "identity",
alpha = 0.8) +
coord_flip() +
facet_wrap(~ tissue,
ncol = 1,
scales = "free") +
geom_hline(yintercept = c(-1.5, 1.5),
color = "gray",
linetype = 2,
linewidth = 0.5) +
geom_hline(yintercept = 0,
color = "black",
linewidth = 0.5) +
geom_text(data = fig_2c_data,
aes(x = -1 * order,
y = label_y * 4,
label = pathway),
size = 1.5) +
geom_text(data = lab4plot,
aes(x = x,
y = y,
label = label),
fontface = "bold",
size = 2) +
scale_fill_manual(values = c("#377eb8", "#e41a1c")) +
theme_bw() +
theme(strip.background = element_rect(color = "white", fill = "white"),
strip.text.x = element_text(size = 9, face = "bold"),
axis.text.x = element_text(size = 4),
legend.position = "none",
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
panel.border = element_blank(),
axis.line.x = element_line(color = "black"),
axis.text.y = element_blank(),
axis.ticks.y = element_blank()) +
labs(title = "",
y = "",
x = "") +
ylim(-7, 7) +
xlim(-5.5, 1)
# Take a moment to ensure reset to null device
dev.off()
figure_2c
# Save as PDF
pdf("Figures/figure_2/figure_2c.pdf",
width = 6,
height = 9)
figure_2c
dev.off()
save(figure_2c, file = "Figures/figure_2/figure_2c.RData")
```
## Paneling figure 2
```{r panelFig2, eval = TRUE}
load("Figures/figure_2/figure_2b.RData")
load("Figures/figure_2/figure_2c.RData")
layout_matrix <- matrix(c(1, 1, 2, 2, 5, 5, 5,
3, 3, 4, 4, 5, 5, 5),
nrow = 2,
byrow = TRUE)
pdf("Figures/figure_2/figure_2.pdf",
width = 6,
height = 4)
gridExtra::grid.arrange(grobs = list(figure_2b$`Tibia - down`,
figure_2b$`Tibia - up`,
figure_2b$`Lung - down`,
figure_2b$`Lung - up`,
figure_2c),
layout_matrix = layout_matrix)
dev.off()
```
# Figure 3
Figure 3. Osteosarcoma cells retain phenotypic heterogeneity despite adaptive changes in response to changing microenvironments. A) Schematic outlining scRNA-seq bioinformatics workflow. In B-D, samples subset to equal number of cells to allow inter-model comparison (n=1500 per condition).
## Figure 3B
B) Osteosarcoma cells exhibited higher ITH scores than that of osteoblasts grown in cell culture (####p <0.001). Within model comparison, identified increase in ITH scores as cells colonize tibia and lung microenvironments, with the exception of NCH-OS-7 (****p <0.001). P values were adjusted using Šidák multiple comparisons test.
```{r Fig3b}
# Load OS data that was subsetted to be equal cell numbers across
load("Data/OSlist_1500_CCR.RData")
merged_sobjs <-
SeuratObject:::merge.Seurat(x = OS.list_1500[[1]],
y = OS.list_1500[2:length(OS.list_1500)],
add.cell.ids = names(OS.list_1500))
merged_sobjs$group <-
colnames(merged_sobjs) %>%
str_remove("_.+")
group_names <-
merged_sobjs$group %>%
unique()
# Find the genes that are variable within each sample, and combine into a vector
var_genes <- c()
for (i in seq_along(OS.list_1500)) {
OS.list_1500[[i]] <- OS.list_1500[[i]] %>%
NormalizeData(verbose = FALSE) %>%
FindVariableFeatures(verbose = FALSE)
var_genes <- c(var_genes, VariableFeatures(OS.list_1500[[i]]))
}
var_genes <- unique(var_genes)
# Process each sample to be CC regressed in the same gene space and calculate ITH score
raw_ith <- data.frame(matrix(, nrow = 1500, ncol = 0))
for (i in seq_along(group_names)) {
better_name <-
group_names[i] %>%
str_replace("\\.", " ") %>%
str_replace("cx", "Culture") %>%
str_replace("osteoblasts", "Osteoblasts") %>%
str_replace("t143", "143")
sub_obj <- subset(merged_sobjs, group == group_names[i]) %>%
NormalizeData(verbose = FALSE) %>%
FindVariableFeatures(verbose = FALSE) %>%
ScaleData(
features = var_genes,
vars.to.regress = c("S.Score", "G2M.Score"),
block.size = 100000)
z <-
GetAssayData(sub_obj, slot = "scale.data") %>%
as.data.frame() %>%
rownames_to_column("gene") %>%
as_tibble() %>%
filter(gene %in% VariableFeatures(sub_obj)) %>%
select(-gene) %>%
t()
mat <- dist(z, diag = TRUE, upper = FALSE)
mat2 <- as.matrix(mat)
mat2[upper.tri(mat2, diag = TRUE)] <- NA
raw_ith[[better_name]] <- colMeans(mat2, na.rm = TRUE)
}
# the last row will be all NAs because we removed the diagonal from the matrix
raw_ith <- na.omit(raw_ith)
ith <- pivot_longer(raw_ith,
cols = everything(),
names_to = "Sample",
values_to = "ITHScore") %>%
mutate(Sample = as.factor(Sample) %>%
fct_relevel(group_names %>%
str_replace("\\.", " ") %>%
str_replace("cx", "Culture") %>%
str_replace("osteoblasts", "Osteoblasts") %>%
str_replace("t143", "143")))
ith$logITH <- log10(ith$ITHScore)
ridge_cols <- c("#B8B8B8FF",
"#D43F3AFF", "#D43F3AFF", "#D43F3AFF",
"#EEA236FF", "#EEA236FF", "#EEA236FF",
"#357EBDFF", "#357EBDFF", "#357EBDFF",
"#5CB85CFF", "#5CB85CFF", "#5CB85CFF"
)
rplot <-
ggplot(ith, aes(x = logITH, y = Sample)) +
geom_density_ridges(scale = 2, aes(fill = Sample)) +
scale_y_discrete(expand = c(0, 0), limits = rev) +
scale_x_continuous(expand = c(0, 0)) +
scale_fill_manual(values = ridge_cols) +
theme_ridges() +
xlab("log[ITH Score]") +
theme(legend.position = "none",
axis.text.y = element_text(size = 6),
axis.text.x = element_text(size = 6),
axis.title.x = element_text(hjust = 0.5, size = 6),
axis.title.y = element_blank())
rplot
# Perform a Mann-Whitney U for each group
comps <- tribble(
~ctl, ~comp,
1, 2,
1, 5,
1, 8,
1, 11,
2, 3,
2, 4,
5, 6,
5, 7,
8, 9,
8, 10,
11, 12,
11, 13
)
comps$ctl_name <- unique(ith$Sample)[comps$ctl]
comps$comp_name <- unique(ith$Sample)[comps$comp]
comps$mwu_p <- NA
comps$overlap <- NA
comps$eff_size <- NA
# Calculate Mann-Whitney test (p-value), overlap, and effect size (Cohen d)
for (i in seq_along(comps$ctl)) {
s <- wilcox.test(raw_ith[, comps$ctl[i]], raw_ith[, comps$comp[i]])
comps$mwu_p[i] <- s$p.value
s <- overlapping::overlap(list(ctrl = raw_ith[, comps$ctl[i]],
comp = raw_ith[, comps$comp[i]]))$OV
comps$overlap[i] <- s
s <- effsize::cohen.d(raw_ith[, comps$ctl[i]], raw_ith[, comps$comp[i]])
comps$eff_size[i] <- s$estimate
}
# Convert overlap to percentage
comps$overlap <- paste0(format(comps$overlap * 100, digits = 2, trim = T), "%")
# Plot with p-values superimposed for each sample
figure_3b <-
rplot +
geom_text(data = comps,
aes(x = 1.8, y = comp_name),
label = paste0("overlap ",
comps$overlap,
", eff. size ",
format(comps$eff_size, digits = 1, trim = T),
"\n"),
size = 8,
color = "#2b2a2a")
figure_3b
#Save as PDF
if(!dir.exists("Figures/figure_3")) {
dir.create("Figures/figure_3")
}
# Save as PDF
pdf("Figures/figure_3/figure_3b.pdf",
width = 9,
height = 8)
figure_3b
dev.off()
save(figure_3b, file = "Figures/figure_3/figure_3b.RData")
```
## Figure 3C
C) UMAP analysis for merged primary and metastatic samples in each of the four models. Cells in grey represent remaining cells in merged sample. Cluster enrichment analysis shows distribution of cells in each cluster in the two microenvironment conditions (tibia, lung). While some cells in the primary and metastatic lesions adopted shared phenotypes, others adopted distinct phenotypes.
```{r Fig3c}
load("Data/OS_list_CCR.RData")
OS_list$OS17_TL <- OS_list$OS17_TL %>%
FindClusters(resolution = 0.2)
OS_list$`143B_TL` <- OS_list$`143B_TL` %>%
FindClusters(resolution = 0.15)
OS_list$NCHOS2_TL <- OS_list$NCHOS2_TL %>%
FindClusters(resolution = 0.15)
OS_list$NCHOS7_TL <- OS_list$NCHOS7_TL %>%
FindClusters(resolution = 0.2)
# Cluster distribution in each sample
# proportion of cells in lung in each cluster
lung_prop_tbl <- tibble()
for (s_obj in c(OS_list$OS17_TL,
OS_list$`143B_TL`,
OS_list$NCHOS2_TL,
OS_list$NCHOS7_TL)) {
s_obj$src <- factor(s_obj$src,
levels = c("Tibia",
"Lung"))
lung_prop_tbl <-
s_obj@meta.data %>%
as_tibble() %>%
select(model, src, seurat_clusters) %>%
group_by(model, seurat_clusters) %>%
summarize(lung_perc = sum(grepl("Lung", src)) / n() * 100,
.groups = "drop") %>%
dplyr::rename(sample = model,
cluster = seurat_clusters) %>%
bind_rows(lung_prop_tbl)
}
write_tsv(lung_prop_tbl, "Data/Fig3d_lung_prop_tbl.tsv")
#### UMAP Plots ####
sample_names <- c("OS17_TL",
"143B_TL",
"NCHOS2_TL",
"NCHOS7_TL")
figure_3c_umaps <- list()
for (s_obj in sample_names) {
# Tibia plot with lung-derived cells greyed out
temp_obj <- OS_list[[s_obj]]
lung <- vector(mode = "character")
temp <- WhichCells(temp_obj,
expression = src == "Lung")
lung <- append(lung, temp)
Idents(temp_obj, cells = lung) <- " "
cust_dim_plot <- function(x_obj, title, subtitle) {
DimPlot(x_obj,
reduction = "umap",
pt.size = 0.1,
label = T,
label.size = 1,
cols = c("light grey",
"#E64B35FF",
"#4DBBD5FF",
"#00A087FF",
"#3C5488FF"),
order = T) +
coord_fixed() +
NoLegend() +
NoAxes() +
ggtitle(title, subtitle = subtitle) +
theme(plot.title = element_text(hjust = 0.5, size = 7),
plot.subtitle = element_text(hjust = 0.5, size = 6),
plot.margin = unit(c(0, 0, 0, 0), "pt"))
}
tibia_plot <-
cust_dim_plot(temp_obj,
title = s_obj,
subtitle = "Tibia")
# Lung plot with lung-derived cells greyed out
temp_obj2 <- OS_list[[s_obj]]
tib <- vector(mode = "character")
temp <- WhichCells(temp_obj2,
expression = src == "Tibia")
tib <- append(tib, temp)
Idents(temp_obj2, cells = tib) <- " "
lung_plot <-
cust_dim_plot(temp_obj2,
title = "",
subtitle = "Lung")
figure_3c_umaps[[s_obj]] <- tibia_plot + lung_plot
pdf(paste0("Figures/figure_3/figure_3c1_",
s_obj,
".pdf"),
width = 5,
height = 5)
print(figure_3c_umaps[[s_obj]])
dev.off()
}
save(figure_3c_umaps, file = "Figures/figure_3/figure_3c_umaps.RData")
#### Bar plots ####
objlist <- c(OS_list$OS17_TL,
OS_list$`143B_TL`,
OS_list$NCHOS2_TL,
OS_list$NCHOS7_TL)
figure_3c_barplots <- list()
for (sobj in objlist) {
tident <- table(Idents(sobj),
sobj$src,
dnn = c("cluster",
"tissue")) %>%
as.data.frame() %>%
group_by(tissue) %>%
mutate(perc = Freq / sum(Freq) * 100)
tident$cluster <- as.character(tident$cluster)
tident$tissue <- factor(tident$tissue, levels = c("Tibia", "Lung"))
figure_3c_barplots[[sobj$model[1]]] <-
ggplot(tident,
aes(x = tissue,
y = perc,
fill = cluster)) +
theme_bw(base_size = 5) +
geom_col(position = "fill", width = 0.5) +
xlab("Tissue") +
ylab("Proportion") +
scale_fill_npg(alpha = 1) +
theme_minimal() +
NoLegend() +
theme(panel.grid = element_blank(),
axis.text.y = element_text(size = 5),
axis.text.x = element_text(size = 5,
angle = 45,
hjust = 1),
axis.title.x = element_text(size = 6),
axis.title.y = element_text(size = 6))
# Save plot as PDF
pdf(paste0("Figures/figure_3/figure_3c2_",
head(sobj$model, 1),
".pdf"),
width = 1,
height = 2)
print(figure_3c_barplots[[sobj$model[1]]])
dev.off()
}
save(figure_3c_barplots, file = "Figures/figure_3/figure_3c_barplots.RData")
# For Rmd visual
figure_3c2 <- ggplot(tident,
aes(x = tissue,
y = perc,
fill = cluster)) +
theme_bw(base_size = 5) +
geom_col(position = "fill", width = 0.5) +
xlab("Tissue") +
ylab("Proportion") +
scale_fill_npg(alpha = 1)
figure_3c2
```
## Figure 3D
D) Metabolic heterogeneity in glycolysis activation. We used a pathway enrichment
analysis for hallmark gene sets using genes differentially upregulated in each
cluster relative to every other cluster within the same model. P values were
adjusted for multiple comparisons. Boxes in grey identify non-significant pathway
enrichments, whereas boxes in red identify statistically significant enrichments.
Bar plot shows percentage of cells identified per cluster in lung metastases.
In B-D, samples subset to equal number of cells to allow inter-model comparison
(n=1500 per condition).
### Processing
```{r Fig3d_process, dependson='Fig3c'}
library(data.table)
#library(pheatmap)
#Create list of objects used in Figure 3 heatmap
B.list <- list(OS17 = OS_list$`OS17_TL`,
t143b = OS_list$`143B_TL`,
OS2 = OS_list$`NCHOS2_TL`,
OS7 = OS_list$`NCHOS7_TL`)
# Use DGEA function to find hallmark pathway expression
em.hm.list <- list()
set.seed(1337)
for (i in seq_len(length(B.list))) {
em.hm.list[[i]] <- DGEA(B.list[[i]]) %>%
setDT(keep.rownames = TRUE) %>%
as_tibble() %>%
rename_with(.cols = where(is.numeric), ~ str_c(names(B.list[i]), "_", .x))
}
cx.pd <- inner_join(inner_join(em.hm.list[[1]],
em.hm.list[[2]],
by = "rn"),
inner_join(em.hm.list[[3]],
em.hm.list[[4]],
by = "rn"),
by = "rn")
# Make the "rn" column the rownames -Emily
# cx.pd <- cx.pd %>%
# column_to_rownames("rn")
head(cx.pd)
##Write table to edit rownames to easily convert to dataframe
write_tsv(cx.pd, file = "Data/cxpd.tsv")
```
### Code I gave to Sanjana at some point for Figure 3d
I modified this from code she gave me to clean it up and get it working
The only data we need are the cs.pd object and the percent of lung cells per cluster
which is entered here as aka4
```{r Fig3d}
lung_percent <-
read_tsv("Data/Fig3d_lung_prop_tbl.tsv") %>%
mutate(sample_order = rank(sample) * 1000 - lung_perc,
x_label = paste0(sample, " c", cluster) %>%
reorder(sample_order))
cx.pd <-
read_tsv("Data/cxpd.tsv",
show_col_types = FALSE) %>%
pivot_longer(c(-rn),
names_to = "sample",
values_to = "pval") %>%
mutate(cluster = str_remove(sample, ".+_") %>%
as.numeric(),
sample = str_replace(sample, "OS2", "NCH-OS-2") %>%
str_replace("OS7", "NCH-OS-7") %>%
str_replace("t143b", "143B") %>%