Last updated: 2022-02-10

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 a2860df. 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:    analysis/.DS_Store
    Ignored:    analysis/._.DS_Store
    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:   analysis/Figure_5.rmd
    Modified:   analysis/Supp-Figure_12.rmd
    Modified:   analysis/Supp-Figure_13.rmd
    Modified:   analysis/Supp-Figure_5.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/06_RNA_chemokine_patch_detection.rmd) and HTML (docs/06_RNA_chemokine_patch_detection.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 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
Rmd 2e443a5 toobiwankenobi 2021-02-09 remove files that are not needed

Introduction

Preparations

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 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(ComplexHeatmap)
library(SingleCellExperiment)
library(ggplot2)
library(ggrepel)
library(dplyr)
library(data.table)
library(stringr)
library(sf)
library(concaveman)
library(RANN)

Load data

sce = readRDS(file = "data/data_for_analysis/sce_RNA.rds")

Chemokine Patch Detection and Analysis

Detect Pachtes for Single Chemokines

Here we use our patch detection algorithm to detect patches of cells that express a certain chemokine. The following settings are used: - We loop through all chemokines. If a cell produces mulitple chemokines, each chemokine is treated in a separate round of patch detection. - min_clust_size: 1, even a single cell without producing neighbours is considered a patch. In the next chunk, we select only patches that at least contain 10 producing cells. - distance patch neighbours: 25µm - expansion milieu: 30µm

start = Sys.time()
cur_sce <- data.frame(colData(sce))
# loop through all chemokines
for(i in names(cur_sce[,grepl(glob2rx("C*L*"),names(cur_sce))])) {

  # find clusters
  sce <- findPatch(input_sce = sce, 
                    IDs_of_interest = cur_sce[cur_sce[,names(cur_sce) == i] == 1,]$cellID, 
                    'cellID', 
                    'Center_X', 'Center_Y', 
                    'ImageNumber', 
                    distance = 25, 
                    min_clust_size = 1,
                    output_colname = paste(tolower(i), "only_clust", sep = ""))

  
  # define cells within/surrounding a cluster of chemokine producing cells
  sce <- findMilieu(sce, 
                     'cellID', 
                     'Center_X', 
                     'Center_Y', 
                     'ImageNumber', 
                     paste(tolower(i), "only_clust", sep = ""), 
                     distance = 30,
                     output_colname = paste(tolower(i), "only_comm", sep = ""))
} 
Time difference of 5.514605 secs
[1] "patches successfully added to sce object"
Time difference of 17.19932 mins
[1] "milieus successfully added to sce object"
Time difference of 4.668736 secs
[1] "patches successfully added to sce object"
Time difference of 12.49801 mins
[1] "milieus successfully added to sce object"
Time difference of 3.967457 secs
[1] "patches successfully added to sce object"
Time difference of 12.58078 mins
[1] "milieus successfully added to sce object"
Time difference of 17.62502 secs
[1] "patches successfully added to sce object"
Time difference of 20.10345 mins
[1] "milieus successfully added to sce object"
Time difference of 9.109623 secs
[1] "patches successfully added to sce object"
Time difference of 21.92445 mins
[1] "milieus successfully added to sce object"
Time difference of 12.13334 secs
[1] "patches successfully added to sce object"
Time difference of 19.18648 mins
[1] "milieus successfully added to sce object"
Time difference of 12.39393 secs
[1] "patches successfully added to sce object"
Time difference of 26.49773 mins
[1] "milieus successfully added to sce object"
Time difference of 1.585672 secs
[1] "patches successfully added to sce object"
Time difference of 6.12763 mins
[1] "milieus successfully added to sce object"
Time difference of 16.86196 secs
[1] "patches successfully added to sce object"
Time difference of 17.50565 mins
[1] "milieus successfully added to sce object"
Time difference of 0.8439357 secs
[1] "patches successfully added to sce object"
Time difference of 3.367174 mins
[1] "milieus successfully added to sce object"
Time difference of 8.333804 secs
[1] "patches successfully added to sce object"
Time difference of 11.68944 mins
[1] "milieus successfully added to sce object"
end = Sys.time()
print(end-start)
Time difference of 2.837728 hours

Define pure clusters that contain more than 10 producing cells

Here we select patches which contain at least 10 producing cells. We then assign a to all milieu cells from that patch the milieu ID that was already assigned above. All smaller patches get a 0.

cur_sce <- data.frame(colData(sce))

for(i in names(cur_sce[,grepl(glob2rx("*only_clust"),names(cur_sce))])) {
 
   # select cluster with more than 10 producing cells
  clust <- cur_sce %>%
    group_by_at(i) %>%
    summarise(n=n()) %>%
    distinct_at(i, .keep_all = TRUE) %>%
    filter(n>10)
  
  # remove cluster 0 (non-producing cells)
  clust <- clust[clust[,i] > 0,]
  
  # create new column
  name <- str_split(i, "_")[[1]][1]
  name <- paste0(name,"_pure")
  cur_sce[,name] <- 0
  
  # add cluster id to new column for all cells (producing AND non-producing) that are part of that community
  if(nrow(clust) > 0){
    colname_comm <- paste0(str_split(i, "_")[[1]][1],"_comm")
    cur_sce[cur_sce[,colname_comm] %in% clust[,i][[1]], name] <- as.numeric(cur_sce[cur_sce[,colname_comm] %in% clust[,i][[1]], colname_comm])
  }
}

# add to sce
sce$ccl4_pure <- cur_sce$ccl4only_pure
sce$ccl18_pure <- cur_sce$ccl18only_pure
sce$cxcl8_pure <- cur_sce$cxcl8only_pure
sce$cxcl10_pure <- cur_sce$cxcl10only_pure
sce$cxcl12_pure <- cur_sce$cxcl12only_pure
sce$cxcl13_pure <- cur_sce$cxcl13only_pure
sce$ccl2_pure <- cur_sce$ccl2only_pure
sce$ccl22_pure <- cur_sce$ccl22only_pure
sce$cxcl9_pure <- cur_sce$cxcl9only_pure
sce$ccl8_pure <- cur_sce$ccl8only_pure
sce$ccl19_pure <- cur_sce$ccl19only_pure

Save SCE

saveRDS(sce, file = "data/data_for_analysis/sce_RNA.rds")

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

other attached packages:
 [1] RANN_2.6.1                  concaveman_1.1.0           
 [3] sf_1.0-5                    stringr_1.4.0              
 [5] data.table_1.14.2           ggrepel_0.9.1              
 [7] ggplot2_3.3.5               SingleCellExperiment_1.16.0
 [9] SummarizedExperiment_1.24.0 Biobase_2.54.0             
[11] GenomicRanges_1.46.1        GenomeInfoDb_1.30.1        
[13] IRanges_2.28.0              S4Vectors_0.32.3           
[15] BiocGenerics_0.40.0         MatrixGenerics_1.6.0       
[17] matrixStats_0.61.0          ComplexHeatmap_2.10.0      
[19] dplyr_1.0.7                 workflowr_1.7.0            

loaded via a namespace (and not attached):
 [1] bitops_1.0-7           fs_1.5.2               doParallel_1.0.16     
 [4] RColorBrewer_1.1-2     httr_1.4.2             rprojroot_2.0.2       
 [7] tools_4.1.2            bslib_0.3.1            utf8_1.2.2            
[10] R6_2.5.1               KernSmooth_2.23-20     DBI_1.1.2             
[13] colorspace_2.0-2       GetoptLong_1.0.5       withr_2.4.3           
[16] tidyselect_1.1.1       processx_3.5.2         curl_4.3.2            
[19] compiler_4.1.2         git2r_0.29.0           cli_3.1.1             
[22] DelayedArray_0.20.0    sass_0.4.0             scales_1.1.1          
[25] classInt_0.4-3         callr_3.7.0            proxy_0.4-26          
[28] digest_0.6.29          rmarkdown_2.11         XVector_0.34.0        
[31] pkgconfig_2.0.3        htmltools_0.5.2        fastmap_1.1.0         
[34] rlang_1.0.0            GlobalOptions_0.1.2    rstudioapi_0.13       
[37] shape_1.4.6            jquerylib_0.1.4        generics_0.1.2        
[40] jsonlite_1.7.3         RCurl_1.98-1.5         magrittr_2.0.2        
[43] GenomeInfoDbData_1.2.7 Matrix_1.4-0           Rcpp_1.0.8            
[46] munsell_0.5.0          fansi_1.0.2            lifecycle_1.0.1       
[49] stringi_1.7.6          whisker_0.4            yaml_2.2.2            
[52] zlibbioc_1.40.0        parallel_4.1.2         promises_1.2.0.1      
[55] crayon_1.4.2           lattice_0.20-45        circlize_0.4.13       
[58] knitr_1.37             ps_1.6.0               pillar_1.7.0          
[61] rjson_0.2.21           codetools_0.2-18       glue_1.6.1            
[64] evaluate_0.14          getPass_0.2-2          V8_4.0.0              
[67] png_0.1-7              vctrs_0.3.8            httpuv_1.6.5          
[70] foreach_1.5.2          gtable_0.3.0           purrr_0.3.4           
[73] clue_0.3-60            assertthat_0.2.1       xfun_0.29             
[76] e1071_1.7-9            later_1.3.0            class_7.3-20          
[79] tibble_3.1.6           iterators_1.0.13       units_0.7-2           
[82] cluster_2.1.2          ellipsis_0.3.2