Last updated: 2021-02-12

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 is untracked by Git. 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 2e443a5. 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:    .Rhistory
    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

Untracked files:
    Untracked:  analysis/00_prepare_clinical_dat.rmd
    Untracked:  code/helper_functions/findMilieu.R
    Untracked:  code/helper_functions/findPatch.R

Unstaged changes:
    Modified:   .gitignore
    Modified:   analysis/01_Protein_read_data.rmd
    Modified:   analysis/01_RNA_read_data.rmd
    Modified:   analysis/02_Protein_annotations.rmd
    Modified:   analysis/02_RNA_annotations.rmd
    Modified:   analysis/03_Protein_quality_control.rmd
    Modified:   analysis/03_RNA_quality_control.rmd
    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/05_RNA_chemokine_expressing_cells.rmd
    Modified:   analysis/06_RNA_chemokine_patch_detection.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/Summary_Statistics.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
    Modified:   analysis/XX_hazard_ratio.rmd
    Modified:   analysis/_site.yml
    Modified:   analysis/index.Rmd
    Deleted:    code/findPackages.R
    Deleted:    code/helper_functions/findClusters.R
    Deleted:    code/helper_functions/findCommunity.R
    Deleted:    code/helper_functions/getCellCount.R
    Deleted:    code/helper_functions/plotBarFracCluster.R
    Deleted:    code/helper_functions/plotCellFrac.R
    Deleted:    code/helper_functions/plotCellFracGroups.R
    Deleted:    code/helper_functions/plotCellFracGroupsSubset.R
    Modified:   code/helper_functions/scatter_function.R
    Modified:   code/helper_functions/validityChecks.R
    Deleted:    data/mask_comparison/20190809_ZTMA256.1_slide2_TH_s1_p1_r15_a15_ac_full.tiff
    Deleted:    data/mask_comparison/20190809_ZTMA256.1_slide2_TH_s1_p1_r15_a15_ac_ilastik_s2_Probabilities_equalized_cellmask.tiff
    Deleted:    data/mask_comparison/20191023_ZTMA256.1_slide3_TH_s0_p10_r4_a4_ac_full.tiff
    Deleted:    data/mask_comparison/20191023_ZTMA256.1_slide3_TH_s0_p10_r4_a4_ac_ilastik_s2_Probabilities_equalized_cellmask.tiff

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.


There are no past versions. Publish this analysis with wflow_publish() to start tracking its development.


Introduction

In this script, we load the clinical data and clean and prepare the data for further analysis. Furthermore, we create two .csv files containing the clinical data for RNA and Protein TMA separately in order to attach them to the SingleCellExperiment in a later step.

Preparations

knitr::opts_chunk$set(echo = TRUE, message= FALSE)
knitr::opts_knit$set(root.dir = rprojroot::find_rstudio_root_file())

Load libraries

library(dplyr)

Load the data

# load clinical data and TMA data to link images with patients
clinical_mat <- read.csv(file = "data/data_for_analysis/200323_TMA_256_clinical_data_March2020.csv",
                         sep=",",stringsAsFactors = FALSE)
clinical_mat <- clinical_mat[is.na(clinical_mat$SpotNr) == FALSE,]

spot_mat <- read.csv(file = "data/data_for_analysis/191119_TMA_spotmatrix.csv", sep= ";",stringsAsFactors = FALSE)

# remove missing value rows from spot_mat
spot_mat <- spot_mat[is.na(spot_mat$SpotNr) == FALSE,]
# in the spot_mat  BlockID "B2017.47224" has a space incorporated: "B2017.47224 ". We will rename this BlockID here.
spot_mat[which(spot_mat$BlockID == "B2017.47224 "),]$BlockID <- "B2017.47224"

# load image metadata as output from CellProfiler
image_mat_prot <- read.csv(file = "data/data_for_analysis/protein/Image.csv", stringsAsFactors = FALSE)
image_mat_rna <- read.csv(file = "data/data_for_analysis/rna/Image.csv", stringsAsFactors = FALSE)

Data cleaning

Assign clean column names

colnames(clinical_mat)
 [1] "SpotNr"                                                                                                                                                                                     
 [2] "Internal.Pat..ID"                                                                                                                                                                           
 [3] "Block.ID"                                                                                                                                                                                   
 [4] "IHC.T.cell.scoring"                                                                                                                                                                         
 [5] "Age.range"                                                                                                                                                                                  
 [6] "Gender"                                                                                                                                                                                     
 [7] "MM.location"                                                                                                                                                                                
 [8] "melanoma.subtype..site.of.primary.tumor."                                                                                                                                                   
 [9] "Cancer.Stage"                                                                                                                                                                               
[10] "Mutation"                                                                                                                                                                                   
[11] "Number.of.treatments.before.surgery"                                                                                                                                                        
[12] "Name.of.last.drug.used"                                                                                                                                                                     
[13] "Last.systemic.treatment.before.surgery"                                                                                                                                                     
[14] "date..last.prev.therapy"                                                                                                                                                                    
[15] "Date.of.surgery"                                                                                                                                                                            
[16] "Drug.used.after.surgery"                                                                                                                                                                    
[17] "Next.systemic.treatment.after.surgery..PC.Paliative.Care."                                                                                                                                  
[18] "Adjuvant"                                                                                                                                                                                   
[19] "start.of.treatment"                                                                                                                                                                         
[20] "end.of.treatment"                                                                                                                                                                           
[21] "Reason.to.stop.treatment..EOT..end.of.treatment..PD..progression..SE..side.effects..TC..therapy.change..NA..not.applicable."                                                                
[22] "Date.of.progression"                                                                                                                                                                        
[23] "Response.at..3m..R.or.NR.or.NA..for.MR.or.no.treatment..or.adjuvant.at.3m."                                                                                                                 
[24] "X.at.3m..PD.progressive.disease..SD.stable.disease..PR.partial.response..CR.complete.response..MR.mixed.response..RFS.relapse.free.survival..adjuvant.patients."                            
[25] "Time.of.response.assesment..3m.for.all.except.for.adjuvant.12m."                                                                                                                            
[26] "Response.at..6m..PD.progressive.disease..SD.stable.disease..PR.partial.response..CR.complete.response..MR.mixed.response..RFS.relapse.free.survival..adjuvant.patients...TC..therapy.change"
[27] "Response.at..12m..PD.progressive.disease..SD.stable.disease..PR.partial.response..CR.complete.response..MR.mixed.response..RFS.relapse.free.survival..adjuvant...NY..not.yet"               
[28] "Last.PET"                                                                                                                                                                                   
[29] "Death.Date"                                                                                                                                                                                 
clean_names <- c("SpotNr","PatientID","BlockID","IHC_T_score","Age_range","Gender",
                 "MM_location","Primary_melanoma_type","Cancer_Stage","Mutation",
                 "Nr_treatments_before_surgery","Name_last_drug_used","Last_sys_treatment_before_surgery",
                 "Last_prev_therapy","Date_surgery","Drug_after_surgery","Treatment_after_surgery","Adjuvant",
                 "Start_treatment","End_treatment","Reason_to_stop_treatment","Date_progression",
                 "Status_at_3m","Response_at_3m","Time_of_response_assesment","Response_at_6m",
                 "Response_at_12m","Last_PET","Date_death")

colnames(clinical_mat) <- clean_names

# empty but non NA date_progression is equal to no progression
clinical_mat <- data.frame(clinical_mat)
clinical_mat$relapse <- NA
clinical_mat[is.na(clinical_mat$Date_progression) & is.na(clinical_mat$Nr_treatments_before_surgery) == FALSE,]$relapse <- "untreated/lost"
clinical_mat[clinical_mat$Date_progression %in% c("") & is.na(clinical_mat$Nr_treatments_before_surgery) == FALSE,]$relapse <- "no relapse"
clinical_mat[is.na(clinical_mat$relapse) & is.na(clinical_mat$Nr_treatments_before_surgery) == FALSE,]$relapse <- "relapse"
clinical_mat[is.na(clinical_mat$Nr_treatments_before_surgery),]$relapse <- "control"

Calculate survival data

Starting point is the beginning of the surgery, end point is death/progression or last PET

Convert Characters to Date

clinical_mat$Date_surgery <- as.Date(clinical_mat$Date_surgery, format = "%d.%m.%Y")
clinical_mat$Date_death <- as.Date(clinical_mat$Date_death, format = "%d.%m.%Y")
clinical_mat$Date_progression <- as.Date(clinical_mat$Date_progression, format = "%d.%m.%Y")
clinical_mat$Last_PET <- as.Date(clinical_mat$Last_PET, format = "%d.%m.%Y")
clinical_mat$Start_treatment <- as.Date(clinical_mat$Start_treatment, format = "%d.%m.%Y")
clinical_mat$End_treatment <- as.Date(clinical_mat$End_treatment, format = "%d.%m.%Y")

Calculate time until last PET or death

clinical_mat$Time_to_death_or_last_PET <- ifelse(is.na(clinical_mat$Date_death) == TRUE, # if no death, then
                                                   clinical_mat$Last_PET - clinical_mat$Start_treatment, # time to last PET
                                                   clinical_mat$Date_death - clinical_mat$Start_treatment) # else: time to progression

clinical_mat$censoring_death <- ifelse(is.na(clinical_mat$Date_death) == TRUE, 0, 1) # 0: no Death, 1: Death

Calculate time until last PET or relapse

clinical_mat$Time_to_progression_or_last_PET <- ifelse(is.na(clinical_mat$Date_progression) == TRUE, # if no progression, then
                                                   clinical_mat$Last_PET - clinical_mat$Start_treatment, # time to last PET
                                                   clinical_mat$Date_progression - clinical_mat$Start_treatment) # else: time to progression

clinical_mat$censoring_progression <- ifelse(is.na(clinical_mat$Date_progression) == TRUE, 0, 1) # 0: no Relapse, 1: Relapse

Combine with RNA/Protein image_mat

RNA clinical matrix

# SpotNr and Description in one mat
full_mat_rna <- spot_mat[,c("SpotNr", "BlockID", "Description", "TissueType", "Location")]

# add respective ImageNumber
image_mat_rna$Description <- image_mat_rna$Metadata_Description
full_mat_rna <- left_join(full_mat_rna, image_mat_rna[,c("ImageNumber", "Description")], by = "Description")

# join with clinical_mat
full_mat_rna <- left_join(full_mat_rna, clinical_mat[,-1], by="BlockID")

# remove Images that were not acquired or removed after initial processing (missing on TMA or too bad quality)
full_mat_rna <- full_mat_rna[is.na(full_mat_rna$ImageNumber) == FALSE,]

Protein clinical matrix

# SpotNr and Description in one mat
full_mat_prot <- spot_mat[,c("SpotNr", "BlockID", "Description", "TissueType", "Location")]

image_mat_prot$Description <- image_mat_prot$Metadata_Description

# rename "G1 - split" row in image_mat (this core was acquired in two measurements because the machine stopped due to an error)
image_mat_prot$Description <- ifelse(image_mat_prot$Description == "G1 - split", "G1", image_mat_prot$Description)

# add respective ImageNumber
full_mat_prot <- left_join(full_mat_prot, image_mat_prot[,c("ImageNumber", "Description")], by = "Description")

# join with clinical_mat
full_mat_prot <- left_join(full_mat_prot, clinical_mat[,-1], by = "BlockID")

# remove Images that were not acquired or removed after initial processing (missing on TMA or too bad quality)
full_mat_prot <- full_mat_prot[is.na(full_mat_prot$ImageNumber) == FALSE,]

compare both matrices

# check if the BlockID/PatientID of Description is the same in both data sets
rna_sub <- full_mat_rna[,c("Description", "BlockID", "PatientID")]
prot_sub <- full_mat_prot[,c("Description", "BlockID", "PatientID")]

compare <- left_join(prot_sub, rna_sub, by = "Description")
all(compare$BlockID.x == compare$BlockID.y)
[1] TRUE
unique(compare$PatientID.x == compare$PatientID.y)
[1] TRUE   NA

Save .csv Files

write.csv(x = full_mat_prot, file = "data/data_for_analysis/protein/clinical_data_protein.csv", row.names = F)
write.csv(x = full_mat_rna, file = "data/data_for_analysis/rna/clinical_data_RNA.csv", row.names = F)

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] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] dplyr_1.0.2     workflowr_1.6.2

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.5       rstudioapi_0.13  knitr_1.30       magrittr_2.0.1  
 [5] tidyselect_1.1.0 R6_2.5.0         rlang_0.4.10     stringr_1.4.0   
 [9] tools_4.0.3      xfun_0.20        git2r_0.28.0     htmltools_0.5.0 
[13] ellipsis_0.3.1   rprojroot_2.0.2  yaml_2.2.1       digest_0.6.27   
[17] tibble_3.0.4     lifecycle_0.2.0  crayon_1.3.4     purrr_0.3.4     
[21] later_1.1.0.1    vctrs_0.3.6      promises_1.1.1   fs_1.5.0        
[25] glue_1.4.2       evaluate_0.14    rmarkdown_2.6    stringi_1.5.3   
[29] compiler_4.0.3   pillar_1.4.7     generics_0.1.0   httpuv_1.5.4    
[33] pkgconfig_2.0.3