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_7.rmd) and HTML (docs/Supp-Figure_7.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 b20b6fb toobiwankenobi 2022-02-02 update code for Supp Figures
Rmd 3da15db toobiwankenobi 2021-11-24 changes for revision

Introduction

This script generates plots for Supplementary Figure 7.

In this script we will sequentially load all melanoma datasets from http://tisch.comp-genomics.org/

we will then calculate the proportions of each cell type expressing individual chemokines. under the hypothesis that the scRNAseq data is the ground truth. We will then compare these proportions to the observed proportions in IMC and thereby estimate whether we likely observe spatial spill over in IMC.

Load Libraries

set.seed(12345)
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(Seurat)
library(hdf5r)
library(SingleCellExperiment)
library(scater)
library(dittoSeq)
library(scran)
library(ComplexHeatmap)
library(outliers)
library(purrr)
library(data.table)
library(dplyr)
library(tidyr)
library(cowplot)
library(ggpubr)

Load Data

sce_rna <- readRDS(file = "data/data_for_analysis/sce_RNA.rds")

SKCM_GSE115978 <- read_Data(data = "data/data_for_analysis/scRNAseq/SKCM_GSE115978_aPD1_expression.h5",
                      metadata_file = "data/data_for_analysis/scRNAseq/SKCM_GSE115978_aPD1_CellMetainfo_table.tsv",
                      name = "SKCM_GSE115978",
                      sorting = "all")
Warning in sparseMatrix(i = indices[] + 1, p = indptr[], x = as.numeric(x =
counts[]), : 'giveCsparse' has been deprecated; setting 'repr = "T"' for you
Note: Using an external vector in selections is ambiguous.
ℹ Use `all_of(targets)` instead of `targets` to silence this message.
ℹ See <https://tidyselect.r-lib.org/reference/faq-external-vector.html>.
This message is displayed once per session.
HNSC_GSE139324 <- read_Data(data = "data/data_for_analysis/scRNAseq/HNSC_GSE139324_expression.h5",
                      metadata_file = "data/data_for_analysis/scRNAseq/HNSC_GSE139324_CellMetainfo_table.tsv",
                      name = "HNSC_GSE139324",
                      sorting = "immune")
Warning in sparseMatrix(i = indices[] + 1, p = indptr[], x = as.numeric(x =
counts[]), : 'giveCsparse' has been deprecated; setting 'repr = "T"' for you
NSCLC_GSE131907 <- read_Data(data = "data/data_for_analysis/scRNAseq/NSCLC_GSE131907_expression.h5",
                      metadata_file = "data/data_for_analysis/scRNAseq/NSCLC_GSE131907_CellMetainfo_table.tsv",
                      name = "NSCLC_GSE131907",
                      sorting = "all")
Warning in sparseMatrix(i = indices[] + 1, p = indptr[], x = as.numeric(x =
counts[]), : 'giveCsparse' has been deprecated; setting 'repr = "T"' for you
PAAD_CRA001160 <- read_Data(data = "data/data_for_analysis/scRNAseq/PAAD_CRA001160_expression.h5",
                      metadata_file = "data/data_for_analysis/scRNAseq/PAAD_CRA001160_CellMetainfo_table.tsv",
                      name = "PAAD_CRA001160",
                      sorting = "all")
Warning in sparseMatrix(i = indices[] + 1, p = indptr[], x = as.numeric(x =
counts[]), : 'giveCsparse' has been deprecated; setting 'repr = "T"' for you
UVM_GSE139829 <- read_Data(data = "data/data_for_analysis/scRNAseq/UVM_GSE139829_expression.h5",
                      metadata_file = "data/data_for_analysis/scRNAseq/UVM_GSE139829_CellMetainfo_table.tsv",
                      name = "UVM_GSE139829",
                      sorting = "all")
Warning in sparseMatrix(i = indices[] + 1, p = indptr[], x = as.numeric(x =
counts[]), : 'giveCsparse' has been deprecated; setting 'repr = "T"' for you
SKCM_GSE72056 <- read_Data(data = "data/data_for_analysis/scRNAseq/SKCM_GSE72056_expression.h5",
                      metadata_file = "data/data_for_analysis/scRNAseq/SKCM_GSE72056_CellMetainfo_table.tsv",
                      name = "SKCM_GSE72056",
                      sorting = "all")
Warning in sparseMatrix(i = indices[] + 1, p = indptr[], x = as.numeric(x =
counts[]), : 'giveCsparse' has been deprecated; setting 'repr = "T"' for you
# merge the datasets
sc_dat <- rbind(HNSC_GSE139324, NSCLC_GSE131907, PAAD_CRA001160,SKCM_GSE115978, SKCM_GSE72056, UVM_GSE139829)
comp_dataset <- c("HNSC_GSE139324","NSCLC_GSE131907","PAAD_CRA001160","SKCM_GSE115978","SKCM_GSE72056","UVM_GSE139829")

Analysis

IMC data

cur_dat <- as_tibble(colData(sce_rna))

cur_dat <- cur_dat %>%
  group_by(celltype,.drop = FALSE) %>%
  mutate(total_celltype_count = n()) %>%
  select(celltype,total_celltype_count,cellID, CCL2,CCL4,CCL8,CCL18,CCL19,CCL22,CXCL8,CXCL9,CXCL10,CXCL12,CXCL13)

imc_long <- cur_dat %>%
  pivot_longer(cols = c(CCL2,CCL4,CCL8,CCL18,CCL19,CCL22,CXCL8,CXCL9,CXCL10,CXCL12,CXCL13),names_to = "chemokine")

imc_long <- imc_long %>%
  group_by(chemokine,.drop = FALSE) %>%
  mutate(total_chem_count = sum(value)) %>%
  ungroup() %>%
  group_by(celltype,chemokine,.drop = FALSE) %>%
  mutate(celltype_chemokine_sum=sum(value)) %>%
  ungroup() %>%
  select(celltype,celltype_chemokine_sum,chemokine,total_celltype_count,total_chem_count) %>%
  distinct() %>%
  mutate(frac_of_chemokine_pos = celltype_chemokine_sum/total_chem_count,
         frac_of_celltype = celltype_chemokine_sum/total_celltype_count) %>%
  ungroup()

imc_long$sorting <- "all"
imc_long$dataset <- "IMC"

only celltypes available in IMC as well

here we will unify the naming of cell types that are available in both datasets.

unique(sc_dat$celltype)
 [1] "B"               "CD8- T cell"     "CD8+ T cell"     "DC"             
 [5] "Mast"            "Mono/Macro"      "NK"              "Plasma"         
 [9] "Tprolif"         "Endothelial"     "Epithelial"      "Fibroblasts"    
[13] "Oligodendrocyte" "Acinar"          "Ductal"          "Endocrine"      
[17] "Malignant"       "Stellate"       
#sc_dat[which(sc_dat$celltype == "B"),]$celltype <- "HLA-DR"
#sc_dat[which(sc_dat$celltype == "CD4Tconv"),]$celltype <- "CD8- T cell"
#sc_dat[which(sc_dat$celltype == "CD8Tex"),]$celltype <- "CD8+ T cell"
#sc_dat[which(sc_dat$celltype == "CD8T"),]$celltype <- "CD8+ T cell"
sc_dat[which(sc_dat$celltype == "Endothelial"),]$celltype <- "Vasculature"
sc_dat[which(sc_dat$celltype == "Fibroblasts"),]$celltype <- "Stroma"
sc_dat[which(sc_dat$celltype == "Malignant"),]$celltype <- "Tumor"
sc_dat[which(sc_dat$celltype == "Mono/Macro"),]$celltype <- "Macrophage"

#sc_dat[which(sc_dat$celltype == "Treg"),]$celltype <- "CD8- T cell"
#sc_dat[which(sc_dat$celltype == "Plasma"),]$celltype <- "CD38"

unique(sc_dat$celltype)
 [1] "B"               "CD8- T cell"     "CD8+ T cell"     "DC"             
 [5] "Mast"            "Macrophage"      "NK"              "Plasma"         
 [9] "Tprolif"         "Vasculature"     "Epithelial"      "Stroma"         
[13] "Oligodendrocyte" "Acinar"          "Ductal"          "Endocrine"      
[17] "Tumor"           "Stellate"       
celltypes <- c("CD8- T cell","CD8+ T cell","Vasculature", "Stroma","Macrophage","Tumor")

merge scRNA-seq and IMC data

we will also unify the cell type names wherever possible

plot_dat <- sc_dat %>%
  filter(celltype %in% celltypes, dataset %in% comp_dataset)

# order IMC data correct for merging 
imc_long <- imc_long[,colnames(plot_dat)]

all_dat <- rbind(plot_dat,imc_long)
all_dat$datatype <- "scRNAseq"
all_dat[which(all_dat$dataset == "IMC"),]$datatype <- "IMC"
test_dat <- all_dat %>%
  group_by(chemokine, celltype) %>%
  nest() %>%         
  mutate(n = map_dbl(data, ~ nrow(.x)), # number of entries
         G = map(data, ~ grubbs.test(.x$frac_of_chemokine_pos)$statistic[[1]]), # G statistic
         U = map(data, ~ grubbs.test(.x$frac_of_chemokine_pos)$statistic[[2]]), # U statistic
         grubbs = map(data, ~ grubbs.test(.x$frac_of_chemokine_pos)$alternative), # Alternative hypotesis
         p_grubbs = map_dbl(data, ~ grubbs.test(.x$frac_of_chemokine_pos)$p.value)) %>% # p-value
  mutate(G = signif(unlist(G), 3),
         U = signif(unlist(U), 3),
         grubbs = unlist(grubbs),
         p_grubbs = signif(p_grubbs, 3)) %>%
  select(-data) %>%
  arrange(p_grubbs)
Warning in pt(t, n - 2): NaNs produced

Warning in pt(t, n - 2): NaNs produced

Warning in pt(t, n - 2): NaNs produced

Warning in pt(t, n - 2): NaNs produced

Warning in pt(t, n - 2): NaNs produced

Warning in pt(t, n - 2): NaNs produced

Warning in pt(t, n - 2): NaNs produced

Warning in pt(t, n - 2): NaNs produced

Warning in pt(t, n - 2): NaNs produced

Warning in pt(t, n - 2): NaNs produced

Warning in pt(t, n - 2): NaNs produced

Warning in pt(t, n - 2): NaNs produced

Warning in pt(t, n - 2): NaNs produced

Warning in pt(t, n - 2): NaNs produced

Warning in pt(t, n - 2): NaNs produced

Warning in pt(t, n - 2): NaNs produced
# merge the test_dat data with the IMC data
test_dat <- left_join(test_dat,imc_long[,c("celltype","chemokine","frac_of_chemokine_pos")],by=c("celltype","chemokine"))

# define whether a detected outlier is an IMC datapoint and apply 0.05 significant value cut-off
sig_dat <- test_dat %>%
  mutate(value = gsub("[^0-9.]", "",  grubbs),
         is_IMC = value == frac_of_chemokine_pos,
         sig = p_grubbs <= 0.05) %>%
  filter(sig == TRUE,is_IMC == TRUE)

Supp Figure 7A

ggplot()+
  geom_boxplot(data = all_dat,aes(x=celltype,y=frac_of_chemokine_pos))+
  geom_point(data = all_dat[which(all_dat$dataset != "IMC"),],aes(x=celltype,y=frac_of_chemokine_pos,col=as.factor(dataset)))+
  geom_point(data = all_dat[which(all_dat$datatype == "IMC"),],aes(x=celltype,y=frac_of_chemokine_pos),col="red",shape=18, size=5)+
  geom_text(data = sig_dat,aes(x=celltype,y=0.75,label = p_grubbs), color= "red", angle=90) +
  facet_wrap(.~chemokine)+
  theme_bw()+
  theme(axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0.5),
        text = element_text(size=14)) +
  ylab("Fraction of chemokine+ cells") +
  guides(col=guide_legend(title="Dataset")) +
  xlab("")

Version Author Date
235386f toobiwankenobi 2022-02-22

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

other attached packages:
 [1] ggpubr_0.4.0                cowplot_1.1.1              
 [3] tidyr_1.2.0                 data.table_1.14.2          
 [5] purrr_0.3.4                 outliers_0.14              
 [7] ComplexHeatmap_2.10.0       scran_1.22.1               
 [9] dittoSeq_1.6.0              scater_1.22.0              
[11] ggplot2_3.3.5               scuttle_1.4.0              
[13] SingleCellExperiment_1.16.0 SummarizedExperiment_1.24.0
[15] Biobase_2.54.0              GenomicRanges_1.46.1       
[17] GenomeInfoDb_1.30.1         IRanges_2.28.0             
[19] S4Vectors_0.32.3            BiocGenerics_0.40.0        
[21] MatrixGenerics_1.6.0        matrixStats_0.61.0         
[23] hdf5r_1.3.5                 SeuratObject_4.0.4         
[25] Seurat_4.1.0                dplyr_1.0.7                
[27] workflowr_1.7.0            

loaded via a namespace (and not attached):
  [1] utf8_1.2.2                reticulate_1.24          
  [3] tidyselect_1.1.1          htmlwidgets_1.5.4        
  [5] BiocParallel_1.28.3       Rtsne_0.15               
  [7] munsell_0.5.0             ScaledMatrix_1.2.0       
  [9] codetools_0.2-18          ica_1.0-2                
 [11] statmod_1.4.36            future_1.23.0            
 [13] miniUI_0.1.1.1            withr_2.4.3              
 [15] colorspace_2.0-2          highr_0.9                
 [17] knitr_1.37                rstudioapi_0.13          
 [19] ROCR_1.0-11               ggsignif_0.6.3           
 [21] tensor_1.5                listenv_0.8.0            
 [23] labeling_0.4.2            git2r_0.29.0             
 [25] GenomeInfoDbData_1.2.7    polyclip_1.10-0          
 [27] farver_2.1.0              bit64_4.0.5              
 [29] pheatmap_1.0.12           rprojroot_2.0.2          
 [31] parallelly_1.30.0         vctrs_0.3.8              
 [33] generics_0.1.2            xfun_0.29                
 [35] doParallel_1.0.16         R6_2.5.1                 
 [37] clue_0.3-60               ggbeeswarm_0.6.0         
 [39] rsvd_1.0.5                locfit_1.5-9.4           
 [41] bitops_1.0-7              spatstat.utils_2.3-0     
 [43] DelayedArray_0.20.0       assertthat_0.2.1         
 [45] promises_1.2.0.1          scales_1.1.1             
 [47] beeswarm_0.4.0            gtable_0.3.0             
 [49] beachmat_2.10.0           globals_0.14.0           
 [51] processx_3.5.2            goftest_1.2-3            
 [53] rlang_1.0.0               GlobalOptions_0.1.2      
 [55] splines_4.1.2             rstatix_0.7.0            
 [57] lazyeval_0.2.2            broom_0.7.12             
 [59] spatstat.geom_2.3-1       yaml_2.2.2               
 [61] reshape2_1.4.4            abind_1.4-5              
 [63] backports_1.4.1           httpuv_1.6.5             
 [65] tools_4.1.2               ellipsis_0.3.2           
 [67] spatstat.core_2.3-2       jquerylib_0.1.4          
 [69] RColorBrewer_1.1-2        ggridges_0.5.3           
 [71] Rcpp_1.0.8                plyr_1.8.6               
 [73] sparseMatrixStats_1.6.0   zlibbioc_1.40.0          
 [75] RCurl_1.98-1.5            ps_1.6.0                 
 [77] rpart_4.1.16              deldir_1.0-6             
 [79] GetoptLong_1.0.5          pbapply_1.5-0            
 [81] viridis_0.6.2             zoo_1.8-9                
 [83] ggrepel_0.9.1             cluster_2.1.2            
 [85] fs_1.5.2                  magrittr_2.0.2           
 [87] scattermore_0.7           circlize_0.4.13          
 [89] lmtest_0.9-39             RANN_2.6.1               
 [91] whisker_0.4               fitdistrplus_1.1-6       
 [93] patchwork_1.1.1           mime_0.12                
 [95] evaluate_0.14             xtable_1.8-4             
 [97] shape_1.4.6               gridExtra_2.3            
 [99] compiler_4.1.2            tibble_3.1.6             
[101] KernSmooth_2.23-20        crayon_1.4.2             
[103] htmltools_0.5.2           mgcv_1.8-38              
[105] later_1.3.0               DBI_1.1.2                
[107] MASS_7.3-55               car_3.0-12               
[109] Matrix_1.4-0              cli_3.1.1                
[111] parallel_4.1.2            metapod_1.2.0            
[113] igraph_1.2.11             pkgconfig_2.0.3          
[115] getPass_0.2-2             plotly_4.10.0            
[117] spatstat.sparse_2.1-0     foreach_1.5.2            
[119] vipor_0.4.5               bslib_0.3.1              
[121] dqrng_0.3.0               XVector_0.34.0           
[123] stringr_1.4.0             callr_3.7.0              
[125] digest_0.6.29             sctransform_0.3.3        
[127] RcppAnnoy_0.0.19          spatstat.data_2.1-2      
[129] rmarkdown_2.11            leiden_0.3.9             
[131] uwot_0.1.11               edgeR_3.36.0             
[133] DelayedMatrixStats_1.16.0 shiny_1.7.1              
[135] rjson_0.2.21              lifecycle_1.0.1          
[137] nlme_3.1-155              jsonlite_1.7.3           
[139] carData_3.0-5             BiocNeighbors_1.12.0     
[141] viridisLite_0.4.0         limma_3.50.0             
[143] fansi_1.0.2               pillar_1.7.0             
[145] lattice_0.20-45           fastmap_1.1.0            
[147] httr_1.4.2                survival_3.2-13          
[149] glue_1.6.1                iterators_1.0.13         
[151] png_0.1-7                 bluster_1.4.0            
[153] bit_4.0.4                 stringi_1.7.6            
[155] sass_0.4.0                BiocSingular_1.10.0      
[157] irlba_2.3.5               future.apply_1.8.1