Last updated: 2021-02-19
Checks: 6 1
Knit directory: melanoma_publication_old_data/
This reproducible R Markdown analysis was created with workflowr (version 1.6.2). The Checks tab describes the reproducibility checks that were applied when the results were created. The Past versions tab lists the development history.
The R Markdown file has unstaged changes. To know which version of the R Markdown file created these results, you’ll want to first commit it to the Git repo. If you’re still working on the analysis, you can ignore this warning. When you’re finished, you can run wflow_publish
to commit the R Markdown file and build the HTML.
Great job! The global environment was empty. Objects defined in the global environment can affect the analysis in your R Markdown file in unknown ways. For reproduciblity it’s best to always run the code in an empty environment.
The command set.seed(20200728)
was run prior to running the code in the R Markdown file. Setting a seed ensures that any results that rely on randomness, e.g. subsampling or permutations, are reproducible.
Great job! Recording the operating system, R version, and package versions is critical for reproducibility.
Nice! There were no cached chunks for this analysis, so you can be confident that you successfully produced the results during this run.
Great job! Using relative paths to the files within your workflowr project makes it easier to run your code on other machines.
Great! You are using Git for version control. Tracking code development and connecting the code version to the results is critical for reproducibility.
The results in this page were generated with repository version ee1595d. See the Past versions tab to see a history of the changes made to the R Markdown and HTML files.
Note that you need to be careful to ensure that all relevant files for the analysis have been committed to Git prior to generating the results (you can use wflow_publish
or wflow_git_commit
). workflowr only checks the R Markdown file, but you know if there are other scripts or data files that it depends on. Below is the status of the Git repository when the results were generated:
Ignored files:
Ignored: .DS_Store
Ignored: .Rproj.user/
Ignored: ._.DS_Store
Ignored: analysis/._clinical metadata preparation.Rmd
Ignored: code/.DS_Store
Ignored: code/._.DS_Store
Ignored: data/.DS_Store
Ignored: data/._.DS_Store
Ignored: data/data_for_analysis/
Ignored: data/full_data/
Ignored: output/.DS_Store
Ignored: output/._.DS_Store
Ignored: output/._protein_neutrophil.png
Ignored: output/._rna_neutrophil.png
Ignored: output/PSOCKclusterOut/
Ignored: output/bcell_grouping.png
Ignored: output/dysfunction_correlation.pdf
Unstaged changes:
Modified: .gitignore
Modified: analysis/04_1_Protein_celltype_classification.rmd
Modified: analysis/04_1_RNA_celltype_classification.rmd
Modified: analysis/04_2_RNA_classification_subclustering.rmd
Modified: analysis/04_2_protein_classification_subclustering.rmd
Modified: analysis/07_TCF7_PD1_gating.rmd
Modified: analysis/08_color_vectors.rmd
Modified: analysis/09_Tcell_Score.Rmd
Modified: analysis/10_Dysfunction_Score.rmd
Modified: analysis/11_Bcell_Score.Rmd
Modified: analysis/Figure_1.rmd
Modified: analysis/Figure_2.rmd
Modified: analysis/Figure_3.rmd
Modified: analysis/Figure_4.rmd
Modified: analysis/Figure_5.rmd
Modified: analysis/Supp-Figure_1.rmd
Modified: analysis/Supp-Figure_2.rmd
Modified: analysis/Supp-Figure_3.rmd
Modified: analysis/Supp-Figure_4.rmd
Modified: analysis/Supp-Figure_5.rmd
Note that any generated files, e.g. HTML, png, CSS, etc., are not included in this status report because it is ok for generated content to have uncommitted changes.
These are the previous versions of the repository in which changes were made to the R Markdown (analysis/Supp-Figure_3.rmd
) and HTML (docs/Supp-Figure_3.html
) files. If you’ve configured a remote Git repository (see ?wflow_git_remote
), click on the hyperlinks in the table below to view the files as they were in that past version.
File | Version | Author | Date | Message |
---|---|---|---|---|
Rmd | ee1595d | toobiwankenobi | 2021-02-12 | clean repo and adapt files |
html | ee1595d | toobiwankenobi | 2021-02-12 | clean repo and adapt files |
html | 3f5af3f | toobiwankenobi | 2021-02-09 | add .html files |
Rmd | afa7957 | toobiwankenobi | 2021-02-08 | minor changes on figures and figure order |
Rmd | 20a1458 | toobiwankenobi | 2021-02-04 | adapt figure order |
Rmd | f9bb33a | toobiwankenobi | 2021-02-04 | new Figure 5 and minor changes in figure order |
Rmd | 73caa28 | toobiwankenobi | 2021-01-12 | minor corrections |
Rmd | 9442cb9 | toobiwankenobi | 2020-12-22 | add all new files |
Rmd | 1af3353 | toobiwankenobi | 2020-10-16 | add stuff |
Rmd | a6b51cd | toobiwankenobi | 2020-10-14 | clean scripts, add new subfigures |
This script generates plots for Supplementary Figure 3.
sapply(list.files("code/helper_functions", full.names = TRUE), source)
code/helper_functions/calculateSummary.R
value ?
visible FALSE
code/helper_functions/censor_dat.R
value ?
visible FALSE
code/helper_functions/detect_mRNA_expression.R
value ?
visible FALSE
code/helper_functions/DistanceToClusterCenter.R
value ?
visible FALSE
code/helper_functions/findMilieu.R code/helper_functions/findPatch.R
value ? ?
visible FALSE FALSE
code/helper_functions/getInfoFromString.R
value ?
visible FALSE
code/helper_functions/getSpotnumber.R
value ?
visible FALSE
code/helper_functions/plotCellCounts.R
value ?
visible FALSE
code/helper_functions/plotCellFractions.R
value ?
visible FALSE
code/helper_functions/plotDist.R
value ?
visible FALSE
code/helper_functions/scatter_function.R
value ?
visible FALSE
code/helper_functions/sceChecks.R
value ?
visible FALSE
code/helper_functions/validityChecks.R
value ?
visible FALSE
library(SingleCellExperiment)
library(dplyr)
library(ggplot2)
library(ggbeeswarm)
library(tidyr)
library(scater)
library(dittoSeq)
library(gridExtra)
library(cowplot)
library(data.table)
library(ggpmisc)
library(ggpubr)
library(rstatix)
# SCE object
sce_rna = readRDS(file = "data/data_for_analysis/sce_RNA.rds")
sce_prot = readRDS(file = "data/data_for_analysis/sce_protein.rds")
# meta data
dat_relation = fread(file = "data/data_for_analysis/protein/Object relationships.csv",stringsAsFactors = FALSE)
dat_relation_rna = fread(file = "data/data_for_analysis/RNA/Object relationships.csv",stringsAsFactors = FALSE)
targets <- metadata(sce_rna)$chemokines_morethan600_withcontrol
targets <- metadata(sce_rna)$chemokines_morethan600_withcontrol
frac <- data.frame(colData(sce_rna)) %>%
filter(Location != "CTRL") %>%
group_by(Description, Tcell_density_score_image, expressor) %>%
summarise(n=n()) %>%
mutate(fraction = n / sum(n)) %>%
filter(expressor %in% targets) %>%
reshape2::dcast(Description + Tcell_density_score_image ~ expressor, value.var = "fraction", fill = 0) %>%
reshape2::melt(id.vars = c("Description", "Tcell_density_score_image"), variable.name = "expressor", value.name = "fraction")
stat.test <- frac %>%
group_by(expressor) %>%
kruskal_test(data = ., fraction ~ Tcell_density_score_image) %>%
adjust_pvalue(method = "BH") %>%
add_significance("p.adj",cutpoints = c(0, 1e-04, 0.001, 0.01, 0.1, 1)) %>%
arrange(p.adj) %>%
mutate(group1 = expressor, group2 = expressor) %>%
add_x_position()
frac$expressor <- factor(frac$expressor, levels = stat.test$expressor)
ggplot(frac, aes(x=expressor, y = fraction)) +
geom_boxplot(alpha=.75, outlier.size = 0.5, aes(fill = Tcell_density_score_image)) +
stat_pvalue_manual(x = "group1", y.position = 0.055, stat.test, size = 4) +
scale_color_discrete(guide = FALSE) +
theme_bw() +
theme(text = element_text(size = 15),
axis.text.x = element_text(angle = 45, vjust = 1, hjust=1)) +
guides(fill=guide_legend(title="T cell Score")) +
xlab("") +
ylab("Fractions") +
coord_cartesian(ylim = c(0,0.06))
tumor_marker_protein <- c("bCatenin", "Sox9", "pERK", "p75", "Ki67", "SOX10", "PARP", "S100", "MiTF")
tumor_marker_rna <- c("Mart1", "pRB")
# rna data
dat_rna <- data.frame(t(assay(sce_rna[tumor_marker_rna, sce_rna$celltype == "Tumor"], "asinh")))
dat_rna$cellID <- rownames(dat_rna)
dat_rna <- left_join(dat_rna, data.frame(colData(sce_rna))[,c("cellID", "Tcell_density_score_image", "Description", "MM_location", "Location")])
# filter
dat_rna <- dat_rna %>%
filter(Location != "CTRL")
# mean per image
dat_rna <- dat_rna %>%
select(-cellID) %>%
group_by(Description, Tcell_density_score_image) %>%
summarise_if(is.numeric, mean, na.rm = TRUE)
# melt
dat_rna <- dat_rna %>%
reshape2::melt(id.vars = c("Description", "Tcell_density_score_image"), variable.name = "channel", value.name = "asinh")
# protein data
dat_prot <- data.frame(t(assay(sce_prot[tumor_marker_protein,, sce_prot$celltype == "Tumor"], "asinh")))
dat_prot$cellID <- rownames(dat_prot)
dat_prot <- left_join(dat_prot, data.frame(colData(sce_prot))[,c("cellID", "Tcell_density_score_image", "Description", "MM_location", "Location")])
# filter
dat_prot <- dat_prot %>%
filter(Location != "CTRL")
# mean per image
dat_prot <- dat_prot %>%
select(-cellID) %>%
group_by(Description, Tcell_density_score_image) %>%
summarise_if(is.numeric, mean, na.rm = TRUE)
# melt
dat_prot <- dat_prot %>%
reshape2::melt(id.vars = c("Description", "Tcell_density_score_image"), variable.name = "channel", value.name = "asinh")
# join both data sets
comb <- rbind(dat_prot, dat_rna)
# adjusted wilcox.test for groups
group_comparison <- list(c("absent", "high"), c("med", "high"))
stat.test <- comb %>%
group_by(channel) %>%
wilcox_test(data = ., asinh ~ Tcell_density_score_image) %>%
adjust_pvalue(method = "BH") %>%
add_significance("p.adj",cutpoints = c(0, 1e-04, 0.001, 0.01, 0.1, 1)) %>%
add_xy_position(x = "Tcell_density_score_image", dodge = 0.8, comparisons = group_comparison) %>%
filter(is.na(y.position) == FALSE)
# plot
p <- ggplot(comb, aes(x=Tcell_density_score_image, y=asinh)) +
geom_boxplot(alpha=0.2, lwd=1, aes(fill=Tcell_density_score_image)) +
geom_quasirandom(alpha=0.6, size=2, aes(col=Tcell_density_score_image)) +
scale_color_discrete(guide = FALSE) +
theme_bw() +
theme(text = element_text(size=18),
axis.text.x = element_blank(),
axis.ticks = element_blank(),
axis.title.x = element_blank()) +
facet_wrap(~channel, scales = "free") +
stat_pvalue_manual(stat.test, label = "p.adj.signif", size = 7) +
xlab("") +
ylab("Mean Count per Image (asinh)") +
scale_y_continuous(expand = expansion(mult = c(0.05, 0.1))) +
guides(fill=guide_legend(title="T cell Score", override.aes = c(lwd=0.5, alpha=1)))
leg <- get_legend(p)
grid.arrange(p + theme(legend.position = "none"))
grid.arrange(leg)
# prepare data and add cellID
dat_relation_rna$cellID_first <- paste("RNA", paste(dat_relation_rna$`First Image Number`, dat_relation_rna$`First Object Number`, sep = "_"), sep = "_")
dat_relation_rna$cellID_second <- paste("RNA", paste(dat_relation_rna$`Second Image Number`, dat_relation_rna$`Second Object Number`, sep = "_"), sep = "_")
# add celltype status to first and second label
celltype_first <- data.frame(colData(sce_rna))[,c("cellID", "celltype", "celltype_clustered")]
colnames(celltype_first) <- c("cellID_first", "celltype_first", "celltype_clust_first")
celltype_second <- data.frame(colData(sce_rna))[,c("cellID", "celltype", "celltype_clustered")]
colnames(celltype_second) <- c("cellID_second", "celltype_second", "celltype_clust_second")
dat_relation_rna <- left_join(dat_relation_rna, celltype_first, by = "cellID_first")
dat_relation_rna <- left_join(dat_relation_rna, celltype_second, by = "cellID_second")
colnames(dat_relation_rna)[5] <- "FirstImageNumber"
# number of interactions CD8+ T cell and tumor per image
dat_relation_sub <- dat_relation_rna[dat_relation_rna$celltype_first %in% c("CD8+ T cell") &
dat_relation_rna$celltype_second == "Tumor"]
# count number of interactions
count <- dat_relation_sub %>%
group_by(FirstImageNumber) %>%
summarise(n=n())
names(count)[1] <- "ImageNumber"
# fraction of exhausted cd8 per image
expressor_frac <- data.frame(colData(sce_rna)) %>%
group_by(ImageNumber, expressor) %>%
summarise(n=n()) %>%
mutate(fraction=n/sum(n)) %>%
filter(expressor %in% targets) %>%
reshape2::dcast(ImageNumber ~ expressor, value.var = "fraction", fill = 0) %>%
reshape2::melt(id.vars = c("ImageNumber"), variable.name = "expressor", value.name = "fraction")
# correlation plot
cur_dat <- left_join(expressor_frac, count)
cur_dat[is.na(cur_dat$n),]$n <- 0
ggplot(cur_dat, aes(x=log10(fraction), y=log10(n))) +
geom_point(size=2) +
geom_smooth(method="lm") +
stat_cor(method = "pearson",
aes(label = paste0("atop(", ..r.label.., ",", ..rr.label.. ,")")),
size = 3, cor.coef.name = "R", label.sep="\n", label.x = -1.875, label.y = 0.3) +
theme_bw() +
theme(text = element_text(size=15)) +
xlab("Chemokine Fraction (log10)") +
ylab("Number of CD8/Tumor Interactions (log10)") +
facet_wrap(~expressor)
Warning: Removed 684 rows containing non-finite values (stat_smooth).
Warning: Removed 684 rows containing non-finite values (stat_cor).
sessionInfo()
R version 4.0.3 (2020-10-10)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 20.04 LTS
Matrix products: default
BLAS/LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.8.so
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
[3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
[5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=C
[7] LC_PAPER=en_US.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] parallel stats4 stats graphics grDevices utils datasets
[8] methods base
other attached packages:
[1] rstatix_0.6.0 ggpubr_0.4.0
[3] ggpmisc_0.3.7 data.table_1.13.6
[5] cowplot_1.1.1 gridExtra_2.3
[7] dittoSeq_1.0.2 scater_1.16.2
[9] tidyr_1.1.2 ggbeeswarm_0.6.0
[11] ggplot2_3.3.3 dplyr_1.0.2
[13] SingleCellExperiment_1.12.0 SummarizedExperiment_1.20.0
[15] Biobase_2.50.0 GenomicRanges_1.42.0
[17] GenomeInfoDb_1.26.2 IRanges_2.24.1
[19] S4Vectors_0.28.1 BiocGenerics_0.36.0
[21] MatrixGenerics_1.2.0 matrixStats_0.57.0
[23] workflowr_1.6.2
loaded via a namespace (and not attached):
[1] colorspace_2.0-0 ggsignif_0.6.0
[3] ellipsis_0.3.1 rio_0.5.16
[5] ggridges_0.5.3 rprojroot_2.0.2
[7] XVector_0.30.0 BiocNeighbors_1.6.0
[9] fs_1.5.0 rstudioapi_0.13
[11] farver_2.0.3 ggrepel_0.9.0
[13] splines_4.0.3 knitr_1.30
[15] broom_0.7.3 pheatmap_1.0.12
[17] compiler_4.0.3 backports_1.2.1
[19] Matrix_1.3-2 limma_3.44.3
[21] later_1.1.0.1 BiocSingular_1.4.0
[23] htmltools_0.5.0 tools_4.0.3
[25] rsvd_1.0.3 gtable_0.3.0
[27] glue_1.4.2 GenomeInfoDbData_1.2.4
[29] reshape2_1.4.4 Rcpp_1.0.5
[31] carData_3.0-4 cellranger_1.1.0
[33] vctrs_0.3.6 nlme_3.1-151
[35] DelayedMatrixStats_1.10.1 xfun_0.20
[37] stringr_1.4.0 openxlsx_4.2.3
[39] lifecycle_0.2.0 irlba_2.3.3
[41] edgeR_3.30.3 zlibbioc_1.36.0
[43] scales_1.1.1 hms_0.5.3
[45] promises_1.1.1 RColorBrewer_1.1-2
[47] yaml_2.2.1 curl_4.3
[49] stringi_1.5.3 zip_2.1.1
[51] BiocParallel_1.22.0 rlang_0.4.10
[53] pkgconfig_2.0.3 bitops_1.0-6
[55] evaluate_0.14 lattice_0.20-41
[57] purrr_0.3.4 labeling_0.4.2
[59] tidyselect_1.1.0 plyr_1.8.6
[61] magrittr_2.0.1 R6_2.5.0
[63] generics_0.1.0 DelayedArray_0.16.0
[65] pillar_1.4.7 haven_2.3.1
[67] whisker_0.4 foreign_0.8-81
[69] withr_2.3.0 mgcv_1.8-33
[71] abind_1.4-5 RCurl_1.98-1.2
[73] tibble_3.0.4 crayon_1.3.4
[75] car_3.0-10 rmarkdown_2.6
[77] viridis_0.5.1 locfit_1.5-9.4
[79] grid_4.0.3 readxl_1.3.1
[81] git2r_0.28.0 forcats_0.5.0
[83] digest_0.6.27 httpuv_1.5.4
[85] munsell_0.5.0 beeswarm_0.2.3
[87] viridisLite_0.3.0 vipor_0.4.5