Last updated: 2022-02-22
Checks: 7 0
Knit directory: MelanomaIMC/
This reproducible R Markdown analysis was created with workflowr (version 1.7.0). The Checks tab describes the reproducibility checks that were applied when the results were created. The Past versions tab lists the development history.
Great! Since the R Markdown file has been committed to the Git repository, you know the exact version of the code that produced these results.
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 73aa800. 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: Table_S4.csv
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/
Unstaged changes:
Modified: .gitignore
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_5.rmd
) and HTML (docs/Supp-Figure_5.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 | 64e5fde | toobiwankenobi | 2022-02-16 | change order and naming of supp fig files |
Rmd | 588dbb1 | toobiwankenobi | 2022-02-06 | Figure Order |
Rmd | fa0f601 | toobiwankenobi | 2022-02-06 | clean Supp Fig code |
Rmd | b20b6fb | toobiwankenobi | 2022-02-02 | update code for Supp Figures |
Rmd | 3da15db | toobiwankenobi | 2021-11-24 | changes for revision |
Rmd | c4e2793 | toobiwankenobi | 2021-08-04 | rearrange figure order to match pre-print |
html | 4109ff1 | toobiwankenobi | 2021-07-07 | delete html files and adapt gitignore |
Rmd | fc55711 | toobiwankenobi | 2021-07-07 | figure changes |
html | fc55711 | toobiwankenobi | 2021-07-07 | figure changes |
Rmd | 0f72ef1 | toobiwankenobi | 2021-05-11 | figure adaptations |
html | 0f72ef1 | toobiwankenobi | 2021-05-11 | figure adaptations |
Rmd | 4affda4 | toobiwankenobi | 2021-04-14 | figure adaptations |
html | 4affda4 | toobiwankenobi | 2021-04-14 | figure adaptations |
Rmd | 3203891 | toobiwankenobi | 2021-02-19 | change celltype names |
html | 3203891 | toobiwankenobi | 2021-02-19 | change celltype names |
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 | 9442cb9 | toobiwankenobi | 2020-12-22 | add all new files |
Rmd | 77466b7 | Tobias Hoch | 2020-10-22 | work on subfigures |
Rmd | f643fb2 | toobiwankenobi | 2020-10-19 | add tumor analysis |
Rmd | 58c40e5 | toobiwankenobi | 2020-10-19 | correct files that don’t work |
Rmd | 1af3353 | toobiwankenobi | 2020-10-16 | add stuff |
This script generates plots for Supplementary Figure 5.
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 code/helper_functions/read_Data.R
value ? ?
visible FALSE 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(reshape2)
library(tidyverse)
library(dplyr)
library(data.table)
library(ggplot2)
library(ComplexHeatmap)
library(rms)
library(ggrepel)
library(ggbeeswarm)
library(circlize)
library(ggpubr)
library(ggridges)
library(gridExtra)
library(rstatix)
library(cowplot)
library(ggrastr)
# clinical data
dat <- read_csv("data/data_for_analysis/protein/clinical_data_protein.csv")
Rows: 167 Columns: 38
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (31): BlockID, Description, TissueType, Location, PatientID, IHC_T_score...
dbl (7): SpotNr, ImageNumber, Nr_treatments_before_surgery, Time_to_death_o...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
# Protein data
sce_prot <- readRDS("data/data_for_analysis/sce_protein.rds")
sce_prot <- sce_prot[,sce_prot$Location != "CTRL"]
# take panel_meta because there are the channel names from the shiny output (and only there, not in the SCE)
panel_meta_prot <- read.csv(file = "data/data_for_analysis/protein/melanoma_1.06_protein.csv",
sep= ",", stringsAsFactors = FALSE )
# RNA data
sce_rna <- readRDS("data/data_for_analysis/sce_rna.rds")
sce_rna <- sce_rna[,sce_rna$Location != "CTRL"]
# take panel_meta because there are the channel names from the shiny output (and only there, not in the SCE)
panel_meta_rna <- read.csv(file = "data/data_for_analysis/rna/panel_mat.csv", stringsAsFactors = FALSE )
Note: as the cohort is very diverse, we are using the BlockID as the minimal unit since clinical parameters are described per BlockID. However, sometimes we do have patients of which we have multiple FFPE blocks (BlockIDs). Nonetheless, clinical parameters are not given per patient but per patient FFPE block and are therefore considered the minimial unit.
dat[dat$BlockID %in% unique(sce_prot[,sce_prot$Location == "CTRL"]$BlockID),]$MM_location <- "Control"
# remove control samples
dat <- dat[dat$BlockID %in% unique(sce_prot[,sce_prot$Location != "CTRL"]$BlockID),]
p1 <- unique(dat[,c("BlockID","MM_location")]) %>%
ggplot()+
geom_bar(aes(y=MM_location),stat ="count") +
xlab("Biopsy Blocks per Location") +
ylab("Metastasis Location") +
theme_bw()+
theme(text = element_text(size=16))
p2 <- dat %>%
ggplot()+
geom_bar(aes(x=BlockID, fill=(MM_location)),stat="count")+
theme_bw()+
theme(axis.text.x = element_blank(),
axis.ticks.x=element_blank(),
text = element_text(size=16)) +
ylab("Number of Samples") +
xlab("Biopsy Blocks") +
scale_y_continuous(limits = c(0,4), expand = c(0, 0)) +
guides(fill=guide_legend(title="Metasis Location"))
plot_grid(p1,p2,rel_widths = c(1.25,3))
# load all subsetted sce object from hierarchichal gating and combine the
label.files <- list.files("data/data_for_analysis/protein/celltype_classifier", full.names = TRUE)
file_names <- data.frame(path = label.files)
file_names$fileName <- sub(".*/", "", label.files)
file_names$celltype <- sub("\\_.*", "", file_names$fileName)
# select one random file per celltype
file_names <- file_names %>%
group_by(celltype) %>%
sample_n(1)
# Read in SCE objects
cur_sces <- lapply(file_names$path, readRDS)
for(element in cur_sces){
# current labelled sce object
sce_label <- element
cur_celltype <- unique(sce_label$cytomapper_CellLabel)
# select all gates from metadata
gates <- metadata(sce_label)[grepl("cytomapper_gate_", names(metadata(sce_label)))]
cur_img <- gates[[1]]$img_id
# subset sce to current image
cur_sce <- sce_prot[,sce_prot$ImageNumber == cur_img]
plots <- list()
for(i in names(gates)) {
plots[[i]] <- local({
# select gates and imageID
cur_gate <- as.data.frame(gates[[i]]$gate)
cur_img <- gates[[i]]$img_id
# names of channels (complicated because shiny has different channel names than SCE)
x_gate <- rownames(cur_gate)[1]
y_gate <- rownames(cur_gate)[2]
x_metal <- panel_meta_prot[panel_meta_prot$clean_target == x_gate, "Metal.Tag"]
y_metal <- panel_meta_prot[panel_meta_prot$clean_target == y_gate, "Metal.Tag"]
x_original <- rownames(rowData(cur_sce)[rowData(cur_sce)[,"Metal.Tag"] == x_metal,])
y_original <- rownames(rowData(cur_sce)[rowData(cur_sce)[,"Metal.Tag"] == y_metal,])
# select current channels
cur_counts <- as.data.frame(t(assay(cur_sce, "asinh")[c(x_original, y_original),]))
# check if cells are in gate
cur_counts$in_gate <- ifelse(cur_counts[,1] >= cur_gate[1,1] &
cur_counts[,1] <= cur_gate[1,2] &
cur_counts[,2] >= cur_gate[2,1] &
cur_counts[,2] <= cur_gate[2,2], TRUE, FALSE)
# cellIDs of cells in gate (for next gate)
cur_cells <- rownames(cur_counts[cur_counts$in_gate == TRUE,])
# update cur_sce
cur_sce <<- cur_sce[,cur_sce$cellID %in% cur_cells] ####### !!!!
# plot
p <- ggplot() +
geom_point_rast(data=cur_counts, aes(x=cur_counts[,1], y=cur_counts[,2],
color=ifelse(cur_counts[,"in_gate"] == TRUE, "red", "black")),
alpha=ifelse(cur_counts[,"in_gate"] == TRUE, 0.5,0.1)) +
geom_rect(data = cur_gate, aes(xmin=cur_gate[1,1], xmax=cur_gate[1,2], ymin=cur_gate[2,1],
ymax=cur_gate[2,2]),
color="black", alpha=0.2) +
xlab(x_gate) +
ylab(y_gate) +
scale_color_identity() +
theme_bw() +
theme(legend.position = "none") +
coord_cartesian(xlim = c(0,6.5), ylim = c(0,6.5))
p
})
}
n <- length(plots)
nCol <- floor(sqrt(n))
do.call("grid.arrange", c(plots, ncol=3,nrow=4, top=cur_celltype))
}
# load all subsetted sce object from hierarchichal gating and combine the
label.files <- list.files("data/data_for_analysis/rna/celltype_classifier", full.names = TRUE)
file_names <- data.frame(path = label.files)
file_names$fileName <- sub(".*/", "", label.files)
file_names$celltype <- sub("\\_.*", "", file_names$fileName)
# select one random file per celltype
file_names <- file_names %>%
group_by(celltype) %>%
sample_n(1)
# Read in SCE objects
cur_sces <- lapply(file_names$path, readRDS)
for(element in cur_sces){
# current labelled sce object
sce_label <- element
cur_celltype <- unique(sce_label$cytomapper_CellLabel)
# select all gates from metadata
gates <- metadata(sce_label)[grepl("cytomapper_gate_", names(metadata(sce_label)))]
cur_img <- gates[[1]]$img_id
# subset sce to current image
cur_sce <- sce_rna[,sce_rna$ImageNumber == cur_img]
plots <- list()
for(i in names(gates)) {
plots[[i]] <- local({
# select gates and imageID
cur_gate <- as.data.frame(gates[[i]]$gate)
cur_img <- gates[[i]]$img_id
# names of channels (complicated because shiny has different channel names than SCE)
x_gate <- rownames(cur_gate)[1]
x_metal <- panel_meta_rna[panel_meta_rna$clean_target == x_gate, "Metal.Tag"]
x_original <- rownames(rowData(cur_sce)[rowData(cur_sce)[,"Metal.Tag"] == x_metal,])
if(nrow(gates[[i]]$gate) == 2) {
y_gate <- rownames(cur_gate)[2]
y_metal <- panel_meta_rna[panel_meta_rna$clean_target == y_gate, "Metal.Tag"]
y_original <- rownames(rowData(cur_sce)[rowData(cur_sce)[,"Metal.Tag"] == y_metal,])
# select current channels
cur_counts <- as.data.frame(t(assay(cur_sce, "asinh")[c(x_original, y_original),]))
# check if cells are in gate
cur_counts$in_gate <- ifelse(cur_counts[,1] >= cur_gate[1,1] &
cur_counts[,1] <= cur_gate[1,2] &
cur_counts[,2] >= cur_gate[2,1] &
cur_counts[,2] <= cur_gate[2,2], TRUE, FALSE)
# cellIDs of cells in gate (for next gate)
cur_cells <- rownames(cur_counts[cur_counts$in_gate == TRUE,])
# update cur_sce
cur_sce <<- cur_sce[,cur_sce$cellID %in% cur_cells]
# plot
p <- ggplot() +
geom_point_rast(data=cur_counts, aes(x=cur_counts[,1], y=cur_counts[,2],
color=ifelse(cur_counts[,"in_gate"] == TRUE, "red", "black")),
alpha=ifelse(cur_counts[,"in_gate"] == TRUE, 0.5,0.1)) +
geom_rect(data = cur_gate, aes(xmin=cur_gate[1,1], xmax=cur_gate[1,2], ymin=cur_gate[2,1],
ymax=cur_gate[2,2]),
color="black", alpha=0.2) +
xlab(x_gate) +
ylab(y_gate) +
scale_color_identity() +
theme_bw() +
theme(legend.position = "none") +
coord_cartesian(xlim = c(0,8), ylim = c(0,8))
p
}
else {
# select current channels
cur_counts <- as.data.frame(assay(cur_sce, "asinh")[c(x_original),])
# check if cells are in gate
cur_counts$in_gate <- ifelse(cur_counts[,1] >= cur_gate[1,1] &
cur_counts[,1] <= cur_gate[1,2], TRUE, FALSE)
# cellIDs of cells in gate (for next gate)
cur_cells <- rownames(cur_counts[cur_counts$in_gate == TRUE,])
# update cur_sce
cur_sce <<- cur_sce[,cur_sce$cellID %in% cur_cells]
# plot
p <- ggplot() +
geom_jitter_rast(data=cur_counts, aes(x=rownames(cur_gate), y=cur_counts[,1],
color=ifelse(cur_counts[,"in_gate"] == TRUE, "red", "black")),
alpha=ifelse(cur_counts[,"in_gate"] == TRUE, 0.5,0.1)) +
geom_hline(yintercept = cur_gate[1,1], color="black", alpha=1) +
geom_hline(yintercept = cur_gate[1,2], color="black", alpha=1) +
xlab(x_gate) +
ylab("Expression (asinh)") +
scale_color_identity() +
theme_bw() +
theme(legend.position = "none",
axis.text.x = element_blank()) +
coord_cartesian(xlim = c(0,8), ylim = c(0,8))
p
}
})
}
n <- length(plots)
nCol <- floor(sqrt(n))
do.call("grid.arrange", c(plots, ncol=3, nrow=4, top=cur_celltype))
}
sessionInfo()
R version 4.1.2 (2021-11-01)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 20.04.3 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=en_US.UTF-8
[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] grid stats4 stats graphics grDevices utils datasets
[8] methods base
other attached packages:
[1] ggrastr_1.0.1 cowplot_1.1.1
[3] rstatix_0.7.0 gridExtra_2.3
[5] ggridges_0.5.3 ggpubr_0.4.0
[7] circlize_0.4.13 ggbeeswarm_0.6.0
[9] ggrepel_0.9.1 rms_6.2-0
[11] SparseM_1.81 Hmisc_4.6-0
[13] Formula_1.2-4 survival_3.2-13
[15] lattice_0.20-45 ComplexHeatmap_2.10.0
[17] data.table_1.14.2 forcats_0.5.1
[19] stringr_1.4.0 purrr_0.3.4
[21] readr_2.1.2 tidyr_1.2.0
[23] tibble_3.1.6 ggplot2_3.3.5
[25] tidyverse_1.3.1 reshape2_1.4.4
[27] SingleCellExperiment_1.16.0 SummarizedExperiment_1.24.0
[29] Biobase_2.54.0 GenomicRanges_1.46.1
[31] GenomeInfoDb_1.30.1 IRanges_2.28.0
[33] S4Vectors_0.32.3 BiocGenerics_0.40.0
[35] MatrixGenerics_1.6.0 matrixStats_0.61.0
[37] dplyr_1.0.7 workflowr_1.7.0
loaded via a namespace (and not attached):
[1] readxl_1.3.1 backports_1.4.1 plyr_1.8.6
[4] splines_4.1.2 TH.data_1.1-0 digest_0.6.29
[7] foreach_1.5.2 htmltools_0.5.2 fansi_1.0.2
[10] magrittr_2.0.2 checkmate_2.0.0 cluster_2.1.2
[13] doParallel_1.0.16 tzdb_0.2.0 modelr_0.1.8
[16] vroom_1.5.7 sandwich_3.0-1 jpeg_0.1-9
[19] colorspace_2.0-2 rvest_1.0.2 haven_2.4.3
[22] xfun_0.29 callr_3.7.0 crayon_1.4.2
[25] RCurl_1.98-1.5 jsonlite_1.7.3 zoo_1.8-9
[28] iterators_1.0.13 glue_1.6.1 gtable_0.3.0
[31] zlibbioc_1.40.0 XVector_0.34.0 MatrixModels_0.5-0
[34] GetoptLong_1.0.5 DelayedArray_0.20.0 car_3.0-12
[37] shape_1.4.6 abind_1.4-5 scales_1.1.1
[40] mvtnorm_1.1-3 DBI_1.1.2 Rcpp_1.0.8
[43] htmlTable_2.4.0 clue_0.3-60 bit_4.0.4
[46] foreign_0.8-82 htmlwidgets_1.5.4 httr_1.4.2
[49] RColorBrewer_1.1-2 ellipsis_0.3.2 farver_2.1.0
[52] pkgconfig_2.0.3 nnet_7.3-17 sass_0.4.0
[55] dbplyr_2.1.1 utf8_1.2.2 labeling_0.4.2
[58] tidyselect_1.1.1 rlang_1.0.0 later_1.3.0
[61] munsell_0.5.0 cellranger_1.1.0 tools_4.1.2
[64] cli_3.1.1 generics_0.1.2 broom_0.7.12
[67] evaluate_0.14 fastmap_1.1.0 yaml_2.2.2
[70] bit64_4.0.5 processx_3.5.2 knitr_1.37
[73] fs_1.5.2 nlme_3.1-155 whisker_0.4
[76] quantreg_5.87 xml2_1.3.3 compiler_4.1.2
[79] rstudioapi_0.13 beeswarm_0.4.0 png_0.1-7
[82] ggsignif_0.6.3 reprex_2.0.1 bslib_0.3.1
[85] stringi_1.7.6 highr_0.9 ps_1.6.0
[88] Matrix_1.4-0 vctrs_0.3.8 pillar_1.7.0
[91] lifecycle_1.0.1 jquerylib_0.1.4 GlobalOptions_0.1.2
[94] bitops_1.0-7 httpuv_1.6.5 R6_2.5.1
[97] latticeExtra_0.6-29 promises_1.2.0.1 vipor_0.4.5
[100] codetools_0.2-18 polspline_1.1.19 MASS_7.3-55
[103] assertthat_0.2.1 rprojroot_2.0.2 rjson_0.2.21
[106] withr_2.4.3 multcomp_1.4-18 GenomeInfoDbData_1.2.7
[109] parallel_4.1.2 hms_1.1.1 rpart_4.1.16
[112] rmarkdown_2.11 carData_3.0-5 Cairo_1.5-14
[115] git2r_0.29.0 getPass_0.2-2 lubridate_1.8.0
[118] base64enc_0.1-3