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/00_prepare_clinical_dat.rmd) and HTML (docs/00_prepare_clinical_dat.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 73aa800 toobiwankenobi 2022-02-22 add .html for static website
Rmd ef31e95 toobiwankenobi 2022-02-17 change dates in clinical data
html 4109ff1 toobiwankenobi 2021-07-07 delete html files and adapt gitignore
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

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)
library(lubridate)
library(stringr)

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

remove exact dates

# remove exact date in clinical data - Protein
full_mat_prot$Date_death <- format(as.Date(full_mat_prot$Date_death),"01-%b-20%y")
full_mat_prot$Date_surgery <- format(as.Date(full_mat_prot$Date_surgery),"01-%b-20%y")
full_mat_prot$Date_progression <- format(as.Date(full_mat_prot$Date_progression),"01-%b-20%y")
full_mat_prot$Start_treatment <- format(as.Date(full_mat_prot$Start_treatment),"01-%b-20%y")
full_mat_prot$End_treatment <- format(as.Date(full_mat_prot$End_treatment),"01-%b-20%y")
full_mat_prot$Last_PET <- format(as.Date(full_mat_prot$Last_PET),"01-%b-20%y")
full_mat_prot$Last_prev_therapy <- str_replace_all(full_mat_prot$Last_prev_therapy, "-", ".")
full_mat_prot$Last_prev_therapy <- format(as.Date(my(full_mat_prot$Last_prev_therapy)),"01-%b-20%y")

# remove exact date in clinical data - RNA
full_mat_rna$Date_death <- format(as.Date(full_mat_rna$Date_death),"01-%b-20%y")
full_mat_rna$Date_surgery <- format(as.Date(full_mat_rna$Date_surgery),"01-%b-20%y")
full_mat_rna$Date_progression <- format(as.Date(full_mat_rna$Date_progression),"01-%b-20%y")
full_mat_rna$Start_treatment <- format(as.Date(full_mat_rna$Start_treatment),"01-%b-20%y")
full_mat_rna$End_treatment <- format(as.Date(full_mat_rna$End_treatment),"01-%b-20%y")
full_mat_rna$Last_PET <- format(as.Date(full_mat_rna$Last_PET),"01-%b-20%y")
full_mat_rna$Last_prev_therapy <- str_replace_all(full_mat_rna$Last_prev_therapy, "-", ".")
full_mat_rna$Last_prev_therapy <- format(as.Date(my(full_mat_rna$Last_prev_therapy)),"01-%b-20%y")

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

other attached packages:
[1] stringr_1.4.0   lubridate_1.8.0 dplyr_1.0.7     workflowr_1.7.0

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.8       bslib_0.3.1      compiler_4.1.2   pillar_1.7.0    
 [5] later_1.3.0      git2r_0.29.0     jquerylib_0.1.4  tools_4.1.2     
 [9] getPass_0.2-2    digest_0.6.29    jsonlite_1.7.3   evaluate_0.14   
[13] tibble_3.1.6     lifecycle_1.0.1  pkgconfig_2.0.3  rlang_1.0.0     
[17] DBI_1.1.2        cli_3.1.1        rstudioapi_0.13  yaml_2.2.2      
[21] xfun_0.29        fastmap_1.1.0    httr_1.4.2       knitr_1.37      
[25] generics_0.1.2   sass_0.4.0       fs_1.5.2         vctrs_0.3.8     
[29] tidyselect_1.1.1 rprojroot_2.0.2  glue_1.6.1       R6_2.5.1        
[33] processx_3.5.2   fansi_1.0.2      rmarkdown_2.11   purrr_0.3.4     
[37] callr_3.7.0      magrittr_2.0.2   whisker_0.4      ps_1.6.0        
[41] promises_1.2.0.1 htmltools_0.5.2  ellipsis_0.3.2   assertthat_0.2.1
[45] httpuv_1.6.5     utf8_1.2.2       stringi_1.7.6    crayon_1.4.2