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/Table_ClinicalData.rmd) and HTML (docs/Table_ClinicalData.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
Rmd a4bcb73 toobiwankenobi 2022-02-09 clean repo
Rmd 45e4546 toobiwankenobi 2022-02-06 clean repo for publication

Introduction

library(SingleCellExperiment)
Loading required package: SummarizedExperiment
Loading required package: MatrixGenerics
Loading required package: matrixStats

Attaching package: 'MatrixGenerics'
The following objects are masked from 'package:matrixStats':

    colAlls, colAnyNAs, colAnys, colAvgsPerRowSet, colCollapse,
    colCounts, colCummaxs, colCummins, colCumprods, colCumsums,
    colDiffs, colIQRDiffs, colIQRs, colLogSumExps, colMadDiffs,
    colMads, colMaxs, colMeans2, colMedians, colMins, colOrderStats,
    colProds, colQuantiles, colRanges, colRanks, colSdDiffs, colSds,
    colSums2, colTabulates, colVarDiffs, colVars, colWeightedMads,
    colWeightedMeans, colWeightedMedians, colWeightedSds,
    colWeightedVars, rowAlls, rowAnyNAs, rowAnys, rowAvgsPerColSet,
    rowCollapse, rowCounts, rowCummaxs, rowCummins, rowCumprods,
    rowCumsums, rowDiffs, rowIQRDiffs, rowIQRs, rowLogSumExps,
    rowMadDiffs, rowMads, rowMaxs, rowMeans2, rowMedians, rowMins,
    rowOrderStats, rowProds, rowQuantiles, rowRanges, rowRanks,
    rowSdDiffs, rowSds, rowSums2, rowTabulates, rowVarDiffs, rowVars,
    rowWeightedMads, rowWeightedMeans, rowWeightedMedians,
    rowWeightedSds, rowWeightedVars
Loading required package: GenomicRanges
Loading required package: stats4
Loading required package: BiocGenerics

Attaching package: 'BiocGenerics'
The following objects are masked from 'package:stats':

    IQR, mad, sd, var, xtabs
The following objects are masked from 'package:base':

    anyDuplicated, append, as.data.frame, basename, cbind, colnames,
    dirname, do.call, duplicated, eval, evalq, Filter, Find, get, grep,
    grepl, intersect, is.unsorted, lapply, Map, mapply, match, mget,
    order, paste, pmax, pmax.int, pmin, pmin.int, Position, rank,
    rbind, Reduce, rownames, sapply, setdiff, sort, table, tapply,
    union, unique, unsplit, which.max, which.min
Loading required package: S4Vectors

Attaching package: 'S4Vectors'
The following objects are masked from 'package:base':

    expand.grid, I, unname
Loading required package: IRanges
Loading required package: GenomeInfoDb
Loading required package: Biobase
Welcome to Bioconductor

    Vignettes contain introductory material; view with
    'browseVignettes()'. To cite Bioconductor, see
    'citation("Biobase")', and for packages 'citation("pkgname")'.

Attaching package: 'Biobase'
The following object is masked from 'package:MatrixGenerics':

    rowMedians
The following objects are masked from 'package:matrixStats':

    anyMissing, rowMedians
library(dplyr)

Attaching package: 'dplyr'
The following object is masked from 'package:Biobase':

    combine
The following objects are masked from 'package:GenomicRanges':

    intersect, setdiff, union
The following object is masked from 'package:GenomeInfoDb':

    intersect
The following objects are masked from 'package:IRanges':

    collapse, desc, intersect, setdiff, slice, union
The following objects are masked from 'package:S4Vectors':

    first, intersect, rename, setdiff, setequal, union
The following objects are masked from 'package:BiocGenerics':

    combine, intersect, setdiff, union
The following object is masked from 'package:matrixStats':

    count
The following objects are masked from 'package:stats':

    filter, lag
The following objects are masked from 'package:base':

    intersect, setdiff, setequal, union
library(lubridate)

Attaching package: 'lubridate'
The following objects are masked from 'package:GenomicRanges':

    intersect, setdiff, union
The following object is masked from 'package:GenomeInfoDb':

    intersect
The following objects are masked from 'package:IRanges':

    %within%, intersect, setdiff, union
The following objects are masked from 'package:S4Vectors':

    intersect, second, second<-, setdiff, union
The following objects are masked from 'package:BiocGenerics':

    intersect, setdiff, union
The following objects are masked from 'package:base':

    date, intersect, setdiff, union
library(stringr)

Load Clinical Data

clinical_data_protein <- read.csv2("data/data_for_analysis/protein/clinical_data_protein.csv", sep = ",")
sce_prot = readRDS(file = "data/data_for_analysis/sce_protein.rds")
sce_prot <- sce_prot[,sce_prot$Location != "CTRL"]

Information to add

info <- as.data.frame(colData(sce_prot)) %>%
  distinct(BlockID, .keep_all = TRUE) %>%
  select(BlockID, MM_location_simplified)

clinical_data_protein <- left_join(clinical_data_protein, info)
Joining, by = "BlockID"

Information for Clinical Data Table

BlockID level

block_level <- clinical_data_protein %>%
  filter(Location != "CTRL") %>%
  distinct(BlockID, .keep_all = TRUE) %>%
  select(PatientID, BlockID, Age_range, Gender, Primary_melanoma_type, MM_location, Cancer_Stage, Mutation,
         Last_sys_treatment_before_surgery, Treatment_after_surgery, MM_location_simplified, Status_at_3m)

# total blocks
length(unique(block_level$BlockID))
[1] 86
# Sex
block_level %>%
  group_by(Gender) %>%
  summarise(n=n()) %>%
  mutate(percentage = round(n / sum(n) *100,2)) %>%
  as.data.frame()
  Gender  n percentage
1      f 36      41.86
2      m 50      58.14
# Age
block_level %>%
  group_by(Age_range) %>%
  summarise(n=n()) %>%
  mutate(percentage = round(n / sum(n) *100,2)) %>%
  as.data.frame()
  Age_range  n percentage
1       <45  9      10.47
2       ≥60 55      63.95
3     45-59 22      25.58
# Primary Melanoma Type
block_level %>%
  group_by(Primary_melanoma_type) %>%
  summarise(n=n()) %>%
  mutate(percentage = n / sum(n) *100) %>%
  mutate(Primary_melanoma_type = ifelse(percentage > 5 | Primary_melanoma_type == "unknown", Primary_melanoma_type, "other")) %>%
  group_by(Primary_melanoma_type) %>%
  summarise(n=sum(n), percentage=round(sum(percentage),2)) %>%
  as.data.frame()
  Primary_melanoma_type  n percentage
1     acral lentiginous  9      10.47
2             cutaneous 67      77.91
3                 other  6       6.98
4               unknown  4       4.65
# Met Location
block_level %>%
  group_by(MM_location) %>%
  summarise(n=n()) %>%
  mutate(percentage = n / sum(n) *100) %>%
  mutate(MM_location = ifelse(percentage > 5, MM_location, "other")) %>%
  group_by(MM_location) %>%
  summarise(n=sum(n), percentage=round(sum(percentage),2)) %>%
  as.data.frame()
        MM_location  n percentage
1             brain  6       6.98
2                LN 27      31.40
3             other 16      18.60
4 skin_subcutaneous 26      30.23
5     skin_undefine  6       6.98
6       soft tissue  5       5.81
# Cancer Stage
block_level %>%
  group_by(Cancer_Stage) %>%
  summarise(n=n()) %>%
  mutate(percentage = round(n / sum(n) *100,2)) %>%
  as.data.frame()
  Cancer_Stage  n percentage
1          III 31      36.05
2    III or IV  2       2.33
3           IV 50      58.14
4      unknown  3       3.49
# Mutation
block_level %>%
  group_by(Mutation) %>%
  summarise(n=n()) %>%
  mutate(percentage = n / sum(n) *100) %>%
  mutate(Mutation = ifelse(percentage > 5 | Mutation == "unknown", Mutation, "other")) %>%
  group_by(Mutation) %>%
  summarise(n=sum(n), percentage=sum(percentage))
# A tibble: 5 × 3
  Mutation     n percentage
  <chr>    <int>      <dbl>
1 BRAF        38      44.2 
2 NRAS        26      30.2 
3 other        3       3.49
4 unknown      4       4.65
5 wt          15      17.4 
# Systemic Treatment Before
block_level %>%
  group_by(Last_sys_treatment_before_surgery) %>%
  summarise(n=n()) %>%
  mutate(percentage = n / sum(n) *100) %>%
  mutate(Last_sys_treatment_before_surgery = ifelse(percentage > 5 | is.na(Last_sys_treatment_before_surgery) == T, Last_sys_treatment_before_surgery, "other")) %>%
  group_by(Last_sys_treatment_before_surgery) %>%
  summarise(n=sum(n)) %>%
  mutate(percentage = round(n / sum(n) *100,2)) %>%
  as.data.frame()
  Last_sys_treatment_before_surgery  n percentage
1                              aPD1 17      19.77
2                             other 12      13.95
3                         untreated 56      65.12
4                              <NA>  1       1.16
# Systemic Treatment After
block_level %>%
  mutate(Last_sys_treatment_before_surgery = ifelse(is.na(Last_sys_treatment_before_surgery), 
                                                    "unknown", Last_sys_treatment_before_surgery)) %>%
  mutate(Treatment_after_surgery = ifelse(is.na(Treatment_after_surgery), 
                                                    "unknown", Treatment_after_surgery)) %>%
  mutate(treatmentGroup_before = ifelse(Last_sys_treatment_before_surgery == "untreated", 
         "Naive", "Pre-Treated")) %>%
  mutate(treatmentGroup_before = ifelse(Last_sys_treatment_before_surgery == "unknown", 
         "Unknown", treatmentGroup_before)) %>%
  mutate(treatmentGroups = paste(treatmentGroup_before, Treatment_after_surgery, sep = "_")) %>%
  group_by(treatmentGroup_before, treatmentGroups) %>%
  summarise(n=n()) %>%
  ungroup() %>%
  mutate(percentage = n / sum(n) *100) %>%
  mutate(treatmentGroups = ifelse(percentage > 5, treatmentGroups, paste(treatmentGroup_before, "other", sep = "_"))) %>%
  group_by(treatmentGroups) %>%
  summarise(n=sum(n), percentage=round(sum(percentage),2)) %>%
  as.data.frame()
`summarise()` has grouped output by 'treatmentGroup_before'. You can override
using the `.groups` argument.
           treatmentGroups  n percentage
1               Naive_aPD1 22      25.58
2       Naive_BRAFi + MEKi  6       6.98
3              Naive_other 18      20.93
4          Naive_untreated 10      11.63
5         Pre-Treated_aPD1  9      10.47
6 Pre-Treated_BRAFi + MEKi  8       9.30
7        Pre-Treated_other 12      13.95
8            Unknown_other  1       1.16
# Response Information 3M after 
block_level %>%
  group_by(Status_at_3m) %>%
  summarise(n=n()) %>%
  mutate(percentage = n / sum(n) *100) %>%
  mutate(Status_at_3m = ifelse(percentage > 5, Status_at_3m, "other")) %>%
  group_by(Status_at_3m) %>%
  summarise(n=sum(n), percentage=round(sum(percentage),2)) %>%
  as.data.frame()
  Status_at_3m  n percentage
1           NR 30      34.88
2            R 16      18.60
3         <NA> 40      46.51

Patient level

Which paramters are unique for patients (not multiple levels per patient)

unique_variables <- block_level %>%
  reshape2::melt(id.vars="PatientID", variable.name="Variable", value.name="Value") %>%
  group_by(PatientID, Variable) %>%
  distinct(Value, .keep_all = T) %>%
  summarise(n=n())
`summarise()` has grouped output by 'PatientID'. You can override using the
`.groups` argument.
multiple_levels <- unique(as.character(unique_variables[unique_variables$n > 1,]$Variable))
all_variables <- unique(as.character(unique_variables$Variable))
unique_variables <- setdiff(all_variables, multiple_levels)
patient_level <- block_level %>%
  distinct(PatientID, Age_range, Gender, Primary_melanoma_type, Cancer_Stage)

# total blocks
length(unique(patient_level$PatientID))
[1] 69
# Sex
patient_level %>%
  group_by(Gender) %>%
  summarise(n=n()) %>%
  mutate(percentage = round(n / sum(n) *100,2)) %>%
  as.data.frame()
  Gender  n percentage
1      f 28      40.58
2      m 41      59.42
# Age
patient_level %>%
  group_by(Age_range) %>%
  summarise(n=n()) %>%
  mutate(percentage = round(n / sum(n) *100,2)) %>%
  as.data.frame()
  Age_range  n percentage
1       <45  6       8.70
2       ≥60 47      68.12
3     45-59 16      23.19
# Primary Melanoma Type
patient_level %>%
  group_by(Primary_melanoma_type) %>%
  summarise(n=n()) %>%
  mutate(percentage = n / sum(n) *100) %>%
  mutate(Primary_melanoma_type = ifelse(percentage > 5, Primary_melanoma_type, "other")) %>%
  group_by(Primary_melanoma_type) %>%
  summarise(n=sum(n), percentage=round(sum(percentage),2)) %>%
  as.data.frame()
  Primary_melanoma_type  n percentage
1     acral lentiginous  4       5.80
2             cutaneous 57      82.61
3                 other  4       5.80
4               unknown  4       5.80
# Cancer Stage
patient_level %>%
  group_by(Cancer_Stage) %>%
  summarise(n=n()) %>%
  mutate(percentage = round(n / sum(n) *100,2)) %>%
  as.data.frame()
  Cancer_Stage  n percentage
1          III 29      42.03
2    III or IV  2       2.90
3           IV 35      50.72
4      unknown  3       4.35

Whole Data Table as CSV

# join with T cell Score, B cell Score, Dysfunction Score
scores <- as.data.frame(colData(sce_prot)) %>%
  distinct(Description, .keep_all = T) %>%
  select(Description, Tcell_density_score_image, bcell_patch_score, dysfunction_score)

clinicalDat <- left_join(scores, clinical_data_protein)
Joining, by = "Description"
clinicalDat$IHC_T_score <- NULL
clinicalDat$Age_range <- ifelse(clinicalDat$Age_range =="≥60", ">=60", clinicalDat$Age_range)

# correct clinicalDat$Last_prev_therapy
clinicalDat$Last_prev_therapy <- str_replace_all(clinicalDat$Last_prev_therapy, "-", ".")
clinicalDat$Last_prev_therapy <- format(as.Date(my(clinicalDat$Last_prev_therapy)),"01-%b-20%y")

write.csv2(clinicalDat, "data/data_for_analysis/Table_S4.csv", row.names = FALSE)

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

other attached packages:
 [1] stringr_1.4.0               lubridate_1.8.0            
 [3] dplyr_1.0.7                 SingleCellExperiment_1.16.0
 [5] SummarizedExperiment_1.24.0 Biobase_2.54.0             
 [7] GenomicRanges_1.46.1        GenomeInfoDb_1.30.1        
 [9] IRanges_2.28.0              S4Vectors_0.32.3           
[11] BiocGenerics_0.40.0         MatrixGenerics_1.6.0       
[13] matrixStats_0.61.0          workflowr_1.7.0            

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.8             lattice_0.20-45        getPass_0.2-2         
 [4] ps_1.6.0               assertthat_0.2.1       rprojroot_2.0.2       
 [7] digest_0.6.29          utf8_1.2.2             plyr_1.8.6            
[10] R6_2.5.1               evaluate_0.14          httr_1.4.2            
[13] pillar_1.7.0           zlibbioc_1.40.0        rlang_1.0.0           
[16] rstudioapi_0.13        whisker_0.4            callr_3.7.0           
[19] jquerylib_0.1.4        Matrix_1.4-0           rmarkdown_2.11        
[22] RCurl_1.98-1.5         DelayedArray_0.20.0    compiler_4.1.2        
[25] httpuv_1.6.5           xfun_0.29              pkgconfig_2.0.3       
[28] htmltools_0.5.2        tidyselect_1.1.1       tibble_3.1.6          
[31] GenomeInfoDbData_1.2.7 fansi_1.0.2            crayon_1.4.2          
[34] later_1.3.0            bitops_1.0-7           grid_4.1.2            
[37] jsonlite_1.7.3         lifecycle_1.0.1        DBI_1.1.2             
[40] git2r_0.29.0           magrittr_2.0.2         cli_3.1.1             
[43] stringi_1.7.6          XVector_0.34.0         reshape2_1.4.4        
[46] fs_1.5.2               promises_1.2.0.1       bslib_0.3.1           
[49] ellipsis_0.3.2         vctrs_0.3.8            generics_0.1.2        
[52] tools_4.1.2            glue_1.6.1             purrr_0.3.4           
[55] processx_3.5.2         fastmap_1.1.0          yaml_2.2.2            
[58] knitr_1.37             sass_0.4.0