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 file has unstaged changes. 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
    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.


These are the previous versions of the repository in which changes were made to the R Markdown (analysis/09_Tcell_Score.Rmd) and HTML (docs/09_Tcell_Score.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 2e443a5 toobiwankenobi 2021-02-09 remove files that are not needed

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

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
value   ?                                
visible 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(LSD)
library(SingleCellExperiment)
library(ggplot2)
library(scater)
library(viridis)
library(igraph)
library(CATALYST)
library(reshape2)
library(cowplot)
library(ggridges)
library(pheatmap)
library(tidyverse)

Load Data

Cytotoxic T cell Scoring

T Cell Density

We want to calculate the T cell density. we calculate this per mm2. We use the count for cytotxic T cells as defined under “03_cell_type_definition” script

cur_df <- data.frame(celltype = sce_prot$celltype,
                             ImageNumber = sce_prot$ImageNumber)

# count cell types per images
cellcount <- (t(table(cur_df)))

# here we get the imagesize from the image metadata
im_size <- (image_mat$Height_cellmask * image_mat$Width_cellmask)/1000000

# data frame
cellcount <- data.frame(cellcount)

# we calculate the density for each celltype for 1 mm2
cellcount$density <- cellcount$Freq/im_size[cellcount$ImageNumber]
cellcount <- cellcount[cellcount$celltype == "Tcytotoxic",]

# there are roughly 60 images with 50 or less cytotoxic T cells
hist(cellcount$density,breaks = 300)

# add cyotoxic T cell density to sce
cellcount$ImageNumber <- as.integer(cellcount$ImageNumber)
cur_sce <- data.frame(colData(sce_prot))
cur_sce <- left_join(cur_sce, cellcount[,c("ImageNumber", "density")])
sce_prot$cyotoxic_density_image <- cur_sce$density

T cell density score per image

  • absent: up to 40 cytotoxic T cells/mm2
  • low: 40-100 cytotoxic T cells/mm2
  • med: 100-400 cytotoxic T cells/mm2
  • high: >400 cytotoxic T cells/mm2
# define a vector with all ImgeNumbers
T_density_scores <- c(1:length(unique(cellcount$ImageNumber)))

T_density_scores  <- rep("unassigned",length(unique(cellcount$ImageNumber)))

T_absent <- which(cellcount$density <= 40)
T_low <- which(cellcount$density > 40 & cellcount[cellcount$celltype == "Tcytotoxic",]$density <= 100)
T_med <- which(cellcount$density > 100 & cellcount$density <= 400)
T_high <- which(cellcount$density > 400)

T_density_scores[T_absent] <- "absent"
T_density_scores[T_low] <- "low"
T_density_scores[T_med] <- "med"
T_density_scores[T_high] <- "high"

# now we add the information to the single cell experiment
sce_prot$Tcell_density_score_image <- T_density_scores[sce_prot$ImageNumber]
sce_prot$Tcell_density_score_image <- factor(sce_prot$Tcell_density_score_image, levels = c("absent", "low", "med", "high"))

# number of samples per group
data.frame(colData(sce_prot)) %>%
  distinct(Description, .keep_all = T) %>%
  group_by(Tcell_density_score_image) %>%
  summarise(n=n())
# A tibble: 4 x 2
  Tcell_density_score_image     n
  <fct>                     <int>
1 absent                       51
2 low                          25
3 med                          46
4 high                         45

E_I_D score compared to T_frac_score_per_ImageNumber

cur_df <- data.frame(T_density = sce_prot$Tcell_density_score_image,
                     E_I_D = sce_prot$E_I_D)

table(cur_df)
         E_I_D
T_density      D      E    E/D      I    I/E
   absent  36924 116043  18583  50857  30611
   low      8541  53869   4971  25955  34393
   med         0  77110      0  94479  69812
   high        0  59707      0 142200 137295

Add Scores to RNA data set

sce_rna$infiltration <- NULL
sce_rna$T_frac_score_per_BlockID <- NULL
sce_rna$T_frac_score_per_ImageNumber <- NULL
sce_rna$T_frac_score_per_PatientID <- NULL
sce_rna$cyotoxic_density_image <- NULL

description_data <- data.frame(colData(sce_prot)) %>%
  distinct(Description, .keep_all = TRUE)

col_rna <- data.frame(colData(sce_rna))

# left_join
col_rna <- left_join(col_rna, description_data[,c("Description", "Tcell_density_score_image", "cyotoxic_density_image")])

# add to sce (attention: cytotoxic density is calculated on protein data set!)
sce_rna$Tcell_density_score_image <- col_rna$Tcell_density_score_image
sce_rna$cyotoxic_density_image <- col_rna$density

Save updated SCE

saveRDS(sce_prot,file = "data/data_for_analysis/sce_protein.rds")
saveRDS(sce_rna,file = "data/data_for_analysis/sce_RNA.rds")

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

other attached packages:
 [1] forcats_0.5.0               stringr_1.4.0              
 [3] dplyr_1.0.2                 purrr_0.3.4                
 [5] readr_1.4.0                 tidyr_1.1.2                
 [7] tibble_3.0.4                tidyverse_1.3.0            
 [9] pheatmap_1.0.12             ggridges_0.5.3             
[11] cowplot_1.1.1               reshape2_1.4.4             
[13] CATALYST_1.12.2             igraph_1.2.6               
[15] viridis_0.5.1               viridisLite_0.3.0          
[17] scater_1.16.2               ggplot2_3.3.3              
[19] SingleCellExperiment_1.12.0 SummarizedExperiment_1.20.0
[21] Biobase_2.50.0              GenomicRanges_1.42.0       
[23] GenomeInfoDb_1.26.2         IRanges_2.24.1             
[25] S4Vectors_0.28.1            BiocGenerics_0.36.0        
[27] MatrixGenerics_1.2.0        matrixStats_0.57.0         
[29] LSD_4.1-0                   workflowr_1.6.2            

loaded via a namespace (and not attached):
  [1] backports_1.2.1             readxl_1.3.1               
  [3] circlize_0.4.12             drc_3.0-1                  
  [5] plyr_1.8.6                  ConsensusClusterPlus_1.52.0
  [7] splines_4.0.3               flowCore_2.0.1             
  [9] BiocParallel_1.22.0         TH.data_1.0-10             
 [11] digest_0.6.27               htmltools_0.5.0            
 [13] fansi_0.4.1                 magrittr_2.0.1             
 [15] CytoML_2.0.5                cluster_2.1.0              
 [17] openxlsx_4.2.3              ComplexHeatmap_2.4.3       
 [19] modelr_0.1.8                RcppParallel_5.0.2         
 [21] sandwich_3.0-0              flowWorkspace_4.0.6        
 [23] cytolib_2.0.3               jpeg_0.1-8.1               
 [25] colorspace_2.0-0            rvest_0.3.6                
 [27] ggrepel_0.9.0               haven_2.3.1                
 [29] xfun_0.20                   crayon_1.3.4               
 [31] RCurl_1.98-1.2              jsonlite_1.7.2             
 [33] hexbin_1.28.2               graph_1.66.0               
 [35] survival_3.2-7              zoo_1.8-8                  
 [37] glue_1.4.2                  gtable_0.3.0               
 [39] nnls_1.4                    zlibbioc_1.36.0            
 [41] XVector_0.30.0              GetoptLong_1.0.5           
 [43] DelayedArray_0.16.0         ggcyto_1.16.0              
 [45] car_3.0-10                  BiocSingular_1.4.0         
 [47] Rgraphviz_2.32.0            shape_1.4.5                
 [49] abind_1.4-5                 scales_1.1.1               
 [51] mvtnorm_1.1-1               DBI_1.1.0                  
 [53] Rcpp_1.0.5                  plotrix_3.7-8              
 [55] clue_0.3-58                 foreign_0.8-81             
 [57] rsvd_1.0.3                  FlowSOM_1.20.0             
 [59] tsne_0.1-3                  httr_1.4.2                 
 [61] RColorBrewer_1.1-2          ellipsis_0.3.1             
 [63] pkgconfig_2.0.3             XML_3.99-0.5               
 [65] dbplyr_2.0.0                utf8_1.1.4                 
 [67] tidyselect_1.1.0            rlang_0.4.10               
 [69] later_1.1.0.1               munsell_0.5.0              
 [71] cellranger_1.1.0            tools_4.0.3                
 [73] cli_2.2.0                   generics_0.1.0             
 [75] broom_0.7.3                 evaluate_0.14              
 [77] yaml_2.2.1                  knitr_1.30                 
 [79] fs_1.5.0                    zip_2.1.1                  
 [81] RBGL_1.64.0                 whisker_0.4                
 [83] xml2_1.3.2                  compiler_4.0.3             
 [85] rstudioapi_0.13             beeswarm_0.2.3             
 [87] curl_4.3                    png_0.1-7                  
 [89] reprex_0.3.0                stringi_1.5.3              
 [91] lattice_0.20-41             Matrix_1.3-2               
 [93] vctrs_0.3.6                 pillar_1.4.7               
 [95] lifecycle_0.2.0             GlobalOptions_0.1.2        
 [97] BiocNeighbors_1.6.0         data.table_1.13.6          
 [99] bitops_1.0-6                irlba_2.3.3                
[101] httpuv_1.5.4                R6_2.5.0                   
[103] latticeExtra_0.6-29         promises_1.1.1             
[105] gridExtra_2.3               RProtoBufLib_2.0.0         
[107] rio_0.5.16                  vipor_0.4.5                
[109] codetools_0.2-18            assertthat_0.2.1           
[111] MASS_7.3-53                 gtools_3.8.2               
[113] rprojroot_2.0.2             rjson_0.2.20               
[115] withr_2.3.0                 multcomp_1.4-15            
[117] GenomeInfoDbData_1.2.4      hms_0.5.3                  
[119] ncdfFlow_2.34.0             grid_4.0.3                 
[121] rmarkdown_2.6               DelayedMatrixStats_1.10.1  
[123] carData_3.0-4               Rtsne_0.15                 
[125] git2r_0.28.0                lubridate_1.7.9.2          
[127] base64enc_0.1-3             ggbeeswarm_0.6.0