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 d246c15. 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
    Modified:   analysis/Supp-Figure_10.rmd
    Modified:   analysis/_site.yml
    Deleted:    analysis/license.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_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
html 5418dcd toobiwankenobi 2022-02-22 add remaining pngs and new .htmls
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

Introduction

This script generates plots for Supplementary Figure 5.

Preparations

Load libraries

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)

Read the data

# 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 )

Supp Figure 5A

Clinical features of the cohort

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.

Number of Samples

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))  

Version Author Date
235386f toobiwankenobi 2022-02-22

Supp Figure 5B

Select one random file per celltype and load file

# 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)

Supp Figure 5C

Select one random file per celltype and load file

# 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)