-
Notifications
You must be signed in to change notification settings - Fork 3
/
OSHetero2022_Supplemental_Figures_ReviewerRequests.Rmd
2976 lines (2595 loc) · 89 KB
/
OSHetero2022_Supplemental_Figures_ReviewerRequests.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: "Supplemental Figures - Reviewer Requests"
author: "Emily Franz, Matthew Cannon, Ryan Roberts"
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'
)
```
```{r lib, cache=FALSE}
#source("scSeurat.R")
source("Downstream.v2.R")
set.seed(888)
# loading libraries
library(Seurat)
library(future)
library(ggplot2)
library(msigdbr)
library(clusterProfiler)
library(SingleR)
library(dplyr)
library(pheatmap)
library(RColorBrewer)
library(viridis) # inferno color palette
library(grid)
library(ggsci)
library(data.table)
library(ggvenn)
library(tibble)
library(tidyr)
library(tidyverse)
library(stringr)
library(reshape2)
library(pzfx)
library(ggridges)
library(effsize)
library(perm)
```
# Reviewer Requests
## S3: Add downregulated pathways
*6. Figure 1C, 3D, 5F— please include the pathway enrichment analysis on the downregulated genes, or please clarify the reason for only focusing on the upregulated genes for pathway enrichment analysis.*
### From Fig 1C
```{r 1c3d5fdown}
source("Downstream.v3.R")
# Prep directory
#Save as PDF
if(!dir.exists("Data/Supplement/")) {
dir.create("Data/Supplement/")
}
if(!dir.exists("Data/Supplement/requests")) {
dir.create("Data/Supplement/requests")
}
#### 1C ####
load("Data/os17_cx_CCR.RData")
load(file ="Data/os7_cx_CCR.RData")
# Pathway enrichment analysis
# Display adjust p-values
B.list <- list(OS17 = os17_cx,
NCHOS7 = os7_cx)
em.hm.list <- list()
for (i in 1:length(B.list)) {
em.hm.list[[i]] <- DGEA(B.list[[i]],
direction = "down")
}
for(i in 1:(length(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_down <- 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",
"#56B4E9")) +
scale_y_discrete(limits = rev) +
theme(legend.position = "right",
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
axis.ticks.x = element_blank()) +
ylab("")
figure_1c_down
#Save as PDF
if(!dir.exists("Figures/supplement/")) {
dir.create("Figures/supplement/")
}
if(!dir.exists("Figures/supplement/requests")) {
dir.create("Figures/supplement/requests")
}
pdf("Figures/supplement/requests/figure_1c_down.pdf",
width = 8,
height = 8)
figure_1c_down
dev.off()
```
### From Fig 3D
```{r Fig3_down}
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/Supplement/requests/Fig3d_lung_prop_tbl.tsv")
```
```{r Fig3d_down_process, dependson='Fig3_down'}
library(data.table)
library(msigdbr)
library(clusterProfiler)
source("Downstream.v3.R")
#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 (downregulated)
em.hm.list <- list()
set.seed(1337)
for (i in seq_len(length(B.list))) {
em.hm.list[[i]] <- DGEA(B.list[[i]],
direction = "down") %>%
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")
head(cx.pd)
##Write table to edit rownames to easily convert to dataframe
write_tsv(cx.pd, file = "Data/Supplement/requests/cxpd.tsv")
```
```{r Fig3d_down}
lung_percent <-
read_tsv("Data/Supplement/requests/Fig3d_lung_prop_tbl.tsv") %>%
mutate(sample_order = rank(sample) * 1000 - lung_perc,
x_label = paste0(sample, " c", cluster) %>%
reorder(sample_order))
lung_percent$sample <- factor(lung_percent$sample,
levels = c("OS-17",
"143B",
"NCH-OS-2",
"NCH-OS-7"))
cx.pd <-
read_tsv("Data/Supplement/requests/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") %>%
str_replace("OS17", "OS-17") %>%
str_remove("_.+"),
rn = str_remove(rn, "HALLMARK_") %>%
str_replace("_", " ")) %>%
left_join(lung_percent) %>%
mutate(pval = -log10(pval),
sample_order = rank(sample) * 1000 - lung_perc,
signif_bool = pval >= (-1 * log10(0.05)),
signif = if_else(signif_bool == TRUE, "p-value < 0.05", "p-value > 0.05"))
cx.pd$sample <- factor(cx.pd$sample,
levels = c("OS-17",
"143B",
"NCH-OS-2",
"NCH-OS-7"))
P1 <-
cx.pd %>%
ggplot(., aes(x = x_label, y = rn, fill = signif)) +
geom_tile() +
geom_text(aes(label = sprintf("%0.2f", pval)), size = 3) +
scale_fill_manual(values = c("#56B4E9", "gray"), name = "") +
scale_y_discrete(limits = rev, position = "right") +
theme(panel.background = element_blank(),
strip.background = element_blank(),
strip.text.x = element_blank(),
plot.margin = unit(c(0, 0, 0, 0), "cm"),
panel.border = element_rect(colour = "black", fill = NA),
axis.text.x = element_text(angle = 90,
hjust = 1,
vjust = 0.4,
size = 12),
axis.text.y = element_text(size = 12)) +
labs(x = "",
y = "") +
facet_grid(. ~ sample,
scales = "free_x",
space = "free")
P2 <-
lung_percent %>%
ggplot(., aes(x = x_label, y = lung_perc, fill = sample)) +
geom_bar(stat = "identity") +
ylab("Percent\nin lung") +
xlab("") +
labs(fill = "Model",
y = "Percent in\nmetastases(%)") +
scale_fill_brewer(palette = "Set2") +
theme(axis.text.x = element_blank(),
axis.ticks.x = element_blank(),
panel.background = element_blank(),
strip.background = element_blank(),
strip.text.x = element_blank(),
plot.margin = unit(c(0, 0, -0.2, 0), "cm"),
panel.border = element_rect(colour = "black", fill = NA)) +
facet_grid(. ~ sample,
scales = "free_x",
space = "free")
figure_3d_down <- cowplot::plot_grid(P2,
P1,
ncol = 1,
align = "v",
rel_heights = c(2, 10))
figure_3d_down
pdf("Figures/supplement/requests/figure_3d_down.pdf",
width = 14,
height = 7)
figure_3d_down
dev.off()
```
### From Fig 5F
```{r Fig5f_down}
#source("scSeurat.R")
library(rrrSingleCellUtils)
library(data.table)
library(msigdbr)
library(clusterProfiler)
source("Downstream.v3.R")
load("Data/lung_sub_enr.RData")
B.list <- list(OS17 = lung_sub_enr)
# Perform differential gene expression analysis for hallmark pathways
set.seed(100)
em.hm.list <- list()
for (i in 1:length(B.list)) {
em.hm.list[[i]] <- DGEA(B.list[[i]],
direction = "down")
}
# Achieve -log10 of the p-value
temp1 <- em.hm.list[[1]]
temp1 <- -log10(temp1)
# Remove unnecessary characters
c <- rownames(temp1)
c <- gsub("_", " ", c)
c <- gsub("HALLMARK ", "", c)
rownames(temp1) <- c
# Remove negative 0 values due to number of decimal points displayed
temp1 <- abs(temp1)
temp1 <- temp1["Enriched clones"]
# Subset to only pathways with significant pvalue (-1 * log10(0.05)) = 1.30103)
temp1["Enriched clones"] >= 1.30103 -> temp1$logical
colnames(temp1) <- c("pvalue",
"significant")
logical <- temp1$significant
temp1 <- temp1[logical, ]
temp1 <- rownames_to_column(temp1,
var = "Pathway")
# Order by -log10pvalue for plotting
temp1$Pathway <- factor(temp1$Pathway,
levels = temp1$Pathway[order(temp1$pvalue)])
# Plot
figure_5f_down <- ggplot(temp1,
aes(x = pvalue,
y = Pathway)) +
geom_bar(stat = "identity") +
theme_bw() +
ylab("") +
xlab("-log10(p-value)") +
geom_vline(xintercept = 1.5,
color = "gray",
linetype = 2,
size = 1) +
ggtitle("Downregulated Pathways in Enriched Clonal Populations")
figure_5f_down
pdf("Figures/supplement/requests/figure_5f_down.pdf",
width = 8,
height = 3)
figure_5f_down
dev.off()
```
## S33: Test if clones tend to be enriched within a single cluster
```{r bootstrapCloneEnrich, eval=TRUE}
load("Data/os17.RData")
n_clones <- 30
top_clones <-
tibble(src = os17$src,
clone = os17$lt,
cluster = paste0("c_", os17$seurat_clusters)) %>%
na.omit() %>%
group_by(src, clone, cluster) %>%
mutate(n_cells_in_cluster = n()) %>%
ungroup() %>%
group_by(src, clone) %>%
mutate(n_cells_in_clone = n()) %>%
ungroup() %>%
group_by(src) %>%
arrange(desc(n_cells_in_clone), clone, .by_group = TRUE) %>%
unique() %>%
pivot_wider(id_cols = c(src, clone, n_cells_in_clone),
names_from = cluster,
values_from = n_cells_in_cluster) %>%
filter(n_cells_in_clone >= 5) %>%
#slice_head(n = n_clones) %>%
ungroup() %>%
pivot_longer(cols = starts_with("c_"),
names_to = "cluster",
values_to = "n_cells_in_cluster") %>%
na.omit() %>%
mutate(clone = fct_reorder(clone, n_cells_in_clone))
cell_counts_to_test <-
top_clones$n_cells_in_clone %>%
unique() %>%
sort()
names(cell_counts_to_test) <- paste0("c_", cell_counts_to_test)
# Get the number of clusters represented by n randomly selected cells
max_per_cluster_n_cells <- function(sobj, n_cells) {
selected_cell_indexes <-
sample(seq_len(ncol(sobj)),
size = n_cells,
replace = FALSE)
max_n_per_cluster <-
sobj$seurat_clusters[selected_cell_indexes] %>%
table() %>%
max()
return(max_n_per_cluster)
}
# bootstrap the data n_perms times to get a distribution
perm_n_times <- function(sobj, n_cells, n_perms = 1000) {
message("Testing ", n_cells, " cells")
n_clusters <- replicate(n_perms, max_per_cluster_n_cells(sobj, n_cells))
return(n_clusters)
}
# Do this for all observed cells/clone
n_perms <- 100000
perm_table <-
sapply(cell_counts_to_test,
function(cell_num) perm_n_times(os17,
cell_num,
n_perms = n_perms),
USE.NAMES = TRUE) %>%
as.data.frame()
contin <- top_clones %>%
rowwise() %>%
mutate(p_value = (
sum(perm_table[[paste0("c_", n_cells_in_clone)]] >=
n_cells_in_cluster) /
n_perms
),
signif = p_value <= 0.05,
cluster = str_remove(cluster, "c_")) %>%
ggplot(aes(x = cluster,
y = clone,
fill = n_cells_in_cluster)) +
geom_tile() +
geom_text(aes(label = n_cells_in_cluster,
color = signif)) +
scale_color_manual(values = c("gray", "red")) +
facet_grid(src ~ ., scales = "free_y", space = "free") +
labs(x = "Cluster",
y = "Clone",
fill = "Cells in Cluster",
color = "Enriched Cluster") +
theme_bw()
contin
pdf("Figures/supplement/requests/contingencytable.pdf",
height = 10,
width = 6)
contin
dev.off()
```
## S4-5: Replicates in other cell lines (mouse)
### K7M2
```{r load_k7m2}
# k7m2
#mm10 prefix not present
## Culture
k7m2.cx.raw <- tenx_load_qc( "/gpfs0/home2/gdrobertslab/lab/Counts/S0201/filtered_feature_bc_matrix/")
k7m2.cx.raw <- subset(k7m2.cx.raw,
subset = nFeature_RNA > 2500 &
nCount_RNA < 40000 &
percent.mt < 10)
k7m2.cx.raw$src <- "Culture"
k7m2.cx.raw$model <- "K7M2"
## Tibia
k7m2.tib.raw <- tenx_load_qc( "/gpfs0/home2/gdrobertslab/lab/Counts/S0105/filtered_feature_bc_matrix/")
k7m2.tib.raw <- subset(k7m2.tib.raw,
subset = nFeature_RNA > 800 &
nCount_RNA < 50000 &
percent.mt < 15)
k7m2.tib.raw$src <- "Tibia"
k7m2.tib.raw$model <- "K7M2"
## Lung
k7m2.lung.raw <- tenx_load_qc( "/gpfs0/home2/gdrobertslab/lab/Counts/S0075-Balb-C-K7M2-Epcam-enriched/outs/filtered_feature_bc_matrix/")
k7m2.lung.raw <- subset(k7m2.lung.raw,
subset = nFeature_RNA > 1000 &
nCount_RNA < 55000 &
percent.mt < 15)
k7m2.lung.raw$src <- "Lung"
k7m2.lung.raw$model <- "K7M2"
```
```{r k7m2_1}
set.seed(100)
# Merge into a single Seurat object
k7m2_all <- merge(k7m2.cx.raw,
y = c(k7m2.tib.raw,
k7m2.lung.raw),
add.cell.ids = c("Culture",
"Tibia",
"Lung"),
project = "LineageTracing")
# Process and cluster
k7m2_all <- NormalizeData(k7m2_all) %>%
FindVariableFeatures(selection.method = "vst") %>%
ScaleData() %>%
RunPCA(pc.genes = k7m2_all@var.genes, npcs = 20) %>%
RunUMAP(reduction = "pca", dims = 1:20) %>%
FindNeighbors(reduction = "pca", dims = 1:20) %>%
FindClusters(resolution = 0.3)
if (!dir.exists("Data/Supplement/k7m2_f420")) {
dir.create("Data/Supplement/k7m2_f420")
}
save(k7m2_all, file = "Data/Supplement/k7m2_f420/k7m2_all.RData")
```
```{r k7m2_2}
load("Data/Supplement/k7m2_f420/k7m2_all.RData")
set.seed(100)
DimPlot(k7m2_all,
reduction = "umap",
pt.size = 1,
label = T) +
coord_fixed() +
ggtitle("K7M2 Clusters") +
scale_color_npg(alpha = 0.7)
# Select clusters showing broad expression of all of the following OS gene markers
FeaturePlot(k7m2_all,
features = c("Col1a1","Col1a2","Spp1"),
split.by = "src")
set.seed(100)
k7m2 <- subset(k7m2_all, subset = RNA_snn_res.0.3 == c(1, 2, 3))
k7m2 <- RunPCA(k7m2, pc.genes = k7m2@var.genes, npcs = 20) %>%
RunUMAP(reduction = "pca", dims = 1:20) %>%
FindNeighbors(reduction = "pca", dims = 1:20) %>%
FindClusters(resolution = 0.3)
# CCR Attempt to regress out the effects of cell cycle on these tumor cells
s.genes <- cc.genes$s.genes
g2m.genes <- cc.genes$g2m.genes
## Convert mouse genes to human genes
library(nichenetr)
s.genes <- convert_human_to_mouse_symbols(s.genes)
g2m.genes <- convert_human_to_mouse_symbols(g2m.genes)
k7m2 <- CellCycleScoring(object = k7m2 ,
s.features = s.genes,
g2m.features = g2m.genes,
set.ident = TRUE)
k7m2 <- ScaleData(object = k7m2,
vars.to.regress = c("S.Score",
"G2M.Score"),
features = rownames(x = k7m2))
k7m2 <- RunPCA(k7m2, pc.genes = k7m2@var.genes, npcs = 20) %>%
RunUMAP(reduction = "pca", dims = 1:20) %>%
FindNeighbors(reduction = "pca", dims = 1:20) %>%
FindClusters(resolution = 0.3)
## Find the optimum resolution for clustering
k7m2.nC <- nRes(k7m2,
res = seq(from = 0.1,
to = 0.3,
by = 0.01))
k7m2 <- RunPCA(k7m2, pc.genes = k7m2@var.genes, npcs = 20) %>%
RunUMAP(reduction = "pca", dims = 1:20) %>%
FindNeighbors(reduction = "pca", dims = 1:20) %>%
FindClusters(resolution = 0.1)
save(k7m2, file = "Data/Supplement/k7m2_f420/k7m2_tumor.RData")
```
```{r k7m2_3}
load("Data/Supplement/k7m2_f420/k7m2_tumor.RData")
DimPlot(k7m2,
reduction = "umap",
pt.size = 1,
label = T) +
coord_fixed() +
ggtitle("K7M2 Clusters") +
scale_color_npg(alpha = 1)
DimPlot(k7m2,
reduction = "umap",
pt.size = 1,
group.by = "Phase") +
coord_fixed() +
ggtitle("K7M2 by Phase") +
scale_color_npg(alpha = 1)
# Plot the data
set.seed(100)
k7m2$src <- factor(k7m2$src,
levels = c("Culture",
"Tibia",
"Lung"))
k7m2_umap <- DimPlot(k7m2,
reduction = "umap",
group.by = "src",
pt.size = 1,
label = F) +
coord_fixed() +
ggtitle("K7M2 by Source") +
scale_color_npg()
k7m2_umap
if (!dir.exists("Figures/supplement/requests/k7m2_f420")) {
dir.create("Figures/supplement/requests/k7m2_f420")
}
pdf("Figures/supplement/requests/k7m2_f420/k7m2_umap.pdf",
width = 5,
height = 5)
k7m2_umap
dev.off()
```
### F420
```{r load_F420}
# F420
#mm10 already taken out
## Culture
F420.cx.raw <- tenx_load_qc( "/gpfs0/home2/gdrobertslab/lab/Counts/S0200/filtered_feature_bc_matrix/")
F420.cx.raw <- subset(F420.cx.raw,
subset = nFeature_RNA > 2500 &
nCount_RNA < 45000 &
percent.mt < 10)
F420.cx.raw$src <- "Culture"
F420.cx.raw$model <- "F420"
## Tibia
F420.tib.raw <- tenx_load_qc( "/gpfs0/home2/gdrobertslab/lab/Counts/S0104/filtered_feature_bc_matrix/")
F420.tib.raw <- subset(F420.tib.raw,
subset = nFeature_RNA > 800 &
nCount_RNA < 50000 &
percent.mt < 15)
F420.tib.raw$src <- "Tibia"
F420.tib.raw$model <- "F420"
## Lung
## double check usage throughout rest of code - Emily (fixed issue where coming from wrong file)
## (Epcam postive:negative 1:1)
F420.lung.raw <- tenx_load_qc("/gpfs0/home2/gdrobertslab/lab/Counts/S0067/filtered_feature_bc_matrix/")
F420.lung.raw <- subset(F420.lung.raw,
subset = nFeature_RNA > 1500 &
nCount_RNA < 55000 &
percent.mt < 20)
F420.lung.raw$src <- "Lung"
F420.lung.raw$model <- "F420"
# Second sample from same batch (Epcam postive:negative 1:1)
F420.lung.raw2 <- tenx_load_qc("/gpfs0/home2/gdrobertslab/lab/Counts/S0068/filtered_feature_bc_matrix/")
F420.lung.raw2 <- subset(F420.lung.raw2,
subset = nFeature_RNA > 1500 &
nCount_RNA < 45000 &
percent.mt < 20)
F420.lung.raw2$src <- "Lung"
F420.lung.raw2$model <- "F420"
```
```{r F420_2}
# Merge into a single Seurat object
F420_all <- merge(F420.cx.raw,
y = c(F420.tib.raw,
F420.lung.raw,
F420.lung.raw2),
add.cell.ids = c("Culture",
"Tibia",
"Lung",
"Lung"),
project = "LineageTracing")
# Process and cluster
F420_all <- NormalizeData(F420_all) %>%
FindVariableFeatures(selection.method = "vst") %>%
ScaleData() %>%
RunPCA(pc.genes = F420_all@var.genes, npcs = 20) %>%
RunUMAP(reduction = "pca", dims = 1:20) %>%
FindNeighbors(reduction = "pca", dims = 1:20) %>%
FindClusters(resolution = 0.3)
DimPlot(F420_all,
reduction = "umap",
pt.size = 1,
label = T) +
coord_fixed() +
ggtitle("F420 Clusters") +
scale_color_npg(alpha = 0.7)
# Plot the data
set.seed(100)
cell.ids <- sample(colnames(F420_all))
DimPlot(F420_all,
reduction = "umap",
group.by = "src",
pt.size = 1,
label = F,
order = cell.ids) +
coord_fixed() +
ggtitle("F420 by Source") +
scale_color_npg()
save(F420_all, file = "Data/Supplement/k7m2_f420/F420_all.RData")
```
```{r f420_3}
load("Data/Supplement/k7m2_f420/F420_all.RData")
DimPlot(F420_all,
reduction = "umap",
pt.size = 1,
label = T) +
coord_fixed() +
ggtitle("F420 Clusters")
# Select clusters showing broad expression of all of the following OS gene markers
FeaturePlot(F420_all,
features = c("Col1a1","Col1a2","Spp1"),
split.by = "src")
set.seed(100)
F420 <- subset(F420_all, subset = RNA_snn_res.0.3 == c(0, 3))
F420 <- RunPCA(F420 , pc.genes = F420 @var.genes, npcs = 20) %>%
RunUMAP(reduction = "pca", dims = 1:20) %>%
FindNeighbors(reduction = "pca", dims = 1:20) %>%
FindClusters(resolution = 0.3)
# CCR Attempt to regress out the effects of cell cycle on these tumor cells
s.genes <- cc.genes$s.genes
g2m.genes <- cc.genes$g2m.genes
# Convert mouse genes to human genes
library(nichenetr)
s.genes <- convert_human_to_mouse_symbols(s.genes)
g2m.genes <- convert_human_to_mouse_symbols(g2m.genes)
F420 <- CellCycleScoring(object = F420,
s.features = s.genes,
g2m.features = g2m.genes,
set.ident = TRUE)
F420 <- ScaleData(object = F420,
vars.to.regress = c("S.Score",
"G2M.Score"),
features = rownames(x = F420))
F420 <- RunPCA(F420, pc.genes = F420@var.genes, npcs = 20) %>%
RunUMAP(reduction = "pca", dims = 1:20) %>%
FindNeighbors(reduction = "pca", dims = 1:20) %>%
FindClusters(resolution = 0.3)
## Find the optimum resolution for clustering
F420.nC <- nRes(F420,
res = seq(from = 0.1,
to = 0.3,
by = 0.01))
F420 <- RunPCA(F420, pc.genes = F420@var.genes, npcs = 20) %>%
RunUMAP(reduction = "pca", dims = 1:20) %>%
FindNeighbors(reduction = "pca", dims = 1:20) %>%
FindClusters(resolution = 0.1)
save(F420, file = "Data/Supplement/k7m2_f420/F420_tumor.RData")
```
```{r f420_4}
DimPlot(F420,
reduction = "umap",
pt.size = 1,
label = T) +
coord_fixed() +
ggtitle("F420 Clusters") +
scale_color_npg(alpha = 1)
DimPlot(F420,
reduction = "umap",
pt.size = 1,
group.by = "Phase") +
coord_fixed() +
ggtitle("F420 by Phase") +
scale_color_npg(alpha = 1)
# Plot the data
set.seed(100)
F420$src <- factor(F420$src,
levels = c("Culture",
"Tibia",
"Lung"))
F420_umap <- DimPlot(F420,
reduction = "umap",
group.by = "src",
pt.size = 1,
label = F) +
coord_equal() +
ggtitle("F420 by Source") +
scale_color_npg()
F420_umap
pdf("Figures/supplement/requests/k7m2_f420/F420_umap.pdf",
width = 5,
height = 5)
F420_umap
dev.off()
```
### S4
#### Repeat Figure 2C
C) Pathway enrichment analysis with adjusted p values for hallmark gene sets associated with these shared genes
```{r Fig2c_repeat, fig.height=6, fig.width=10}
### Extract genes that are shared in these datasets
load("Data/OS_merged_postCCR.RData")
load("Data/Supplement/k7m2_f420/k7m2_tumor.RData")
load("Data/Supplement/k7m2_f420/F420_tumor.RData")
# Set seed before subsetting and DE analysis to ensure consistent results
set.seed(100)
k7m2$tissue <- k7m2$src
F420$tissue <- F420$src
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")),
K7M2 = k7m2,
F420 = F420)
# 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"
repfig_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, ]
}
}
# Convert mouse genes to human genes
library(nichenetr)
rowname_df <- tibble(human = convert_mouse_to_human_symbols(rownames(de_genes[[5]])) %>%
as.vector(), mouse = rownames(de_genes[[5]]))
#table(rowname_df$human) %>% as.data.frame() %>% arrange(Freq * -1) %>% head()
#summary(as.factor(rowname_df$human))
rowname_df2 <- tibble(human = convert_mouse_to_human_symbols(rownames(de_genes[[6]])) %>%
as.vector(), mouse = rownames(de_genes[[6]]))
#table(rowname_df2$human) %>% as.data.frame() %>% arrange(Freq * -1) %>% head()
#summary(as.factor(rowname_df2$human))
if (tissue_name == "Tibia") {
if (direction == "up") {
de_genes[[5]] <- de_genes[[5]] %>%
rownames_to_column("mouse") %>%
full_join(rowname_df) %>%
select(-mouse) %>%
# Remove NAs and repeated genes (from conversion)
filter(!is.na(human) & human != "HLA-A") %>%
column_to_rownames("human")
message(paste0(tissue_name, " ", direction, " for de_genes_5 DONE"))
de_genes[[6]] <- de_genes[[6]] %>%
rownames_to_column("mouse") %>%
full_join(rowname_df2) %>%
select(-mouse) %>%
# Remove NAs and repeated genes (from conversion)
filter(!is.na(human) &
human != "BCL2A1" &
human != "CSF2RB" &
human != "FTL" &
human != "IFI16" &
human != "LILRB3" &
human != "LILRB4" &
human != "HLA-A" &
human != "HBA2" &
human != "H3F3A") %>%
column_to_rownames("human")
message(paste0(tissue_name, " ", direction, " for de_genes_6 DONE"))
} else {
de_genes[[5]] <- de_genes[[5]] %>%
rownames_to_column("mouse") %>%
full_join(rowname_df) %>%
select(-mouse) %>%
# Remove NAs and repeated genes (from conversion)
filter(!is.na(human) & human != "EIF3J") %>%
column_to_rownames("human")
message(paste0(tissue_name, " ", direction, " for de_genes_5 DONE"))
de_genes[[6]] <- de_genes[[6]] %>%
rownames_to_column("mouse") %>%
full_join(rowname_df2) %>%
select(-mouse) %>%
# Remove NAs and repeated genes (from conversion)
filter(!is.na(human)) %>%
column_to_rownames("human")
message(paste0(tissue_name, " ", direction, " for de_genes_6 DONE"))
}
}
if (tissue_name == "Lung") {
if (direction == "up") {
de_genes[[5]] <- de_genes[[5]] %>%