Last updated: 2021-02-04

Checks: 7 0

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.


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 20a1458. 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:    code/.DS_Store
    Ignored:    code/._.DS_Store
    Ignored:    code/helper_functions/._findCommunity.R
    Ignored:    data/.DS_Store
    Ignored:    data/._.DS_Store
    Ignored:    data/._density_infiltration_BlockID.csv
    Ignored:    data/._layer_1_classification_rna.csv
    Ignored:    data/._manual_infiltration_scoring.csv
    Ignored:    data/._manual_infiltration_scoring_BlockID.csv
    Ignored:    data/._manual_infiltration_scoring_RC.csv
    Ignored:    data/._manual_infiltration_scoring_TH.csv
    Ignored:    data/._survdat_for_modelling.csv
    Ignored:    data/12plex_validation/
    Ignored:    data/200323_TMA_256_Hot Cold_Clinical Data_Updated Response Data_For Collaborators_latest updated_Mar_2020_for_Coxph_modeling.csv
    Ignored:    data/colour_vector.rds
    Ignored:    data/density_infiltration_BlockID.csv
    Ignored:    data/fraction_and_infiltration_scoring.csv
    Ignored:    data/layer_1_classification_protein.csv
    Ignored:    data/layer_1_classification_protein.rds
    Ignored:    data/layer_1_classification_rna.csv
    Ignored:    data/manual_infiltration_scoring.csv
    Ignored:    data/manual_infiltration_scoring_BlockID.csv
    Ignored:    data/manual_infiltration_scoring_RC.csv
    Ignored:    data/manual_infiltration_scoring_TH.csv
    Ignored:    data/protein/
    Ignored:    data/rna/
    Ignored:    data/safety_copy_SCE/
    Ignored:    data/sce_RNA.rds
    Ignored:    data/sce_protein.rds
    Ignored:    data/survdat_for_modelling.csv
    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

Unstaged changes:
    Modified:   .gitignore

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_community_definition.rmd) and HTML (docs/06_RNA_chemokine_community_definition.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 fb0f7cb SchulzDan 2020-08-24 more paths adapted
Rmd 73881bb toobiwankenobi 2020-07-30 add code to files from old repo
Rmd cf46cfa toobiwankenobi 2020-07-28 create files

Introduction

This script detects interaction networks of a given celltype (here: chemokine producing cells) and defines these networks as clusters. Once a cluster is defined, an algorithm screens the neighbourhood of those clusters to identify cells within/surrounding a cluster. These cells are defined as the community of a cluster.

Preparations

Load packages and helper functions

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/findClusters.R
value   ?                                   
visible FALSE                               
        code/helper_functions/findCommunity.R
value   ?                                    
visible FALSE                                
        code/helper_functions/getCellCount.R
value   ?                                   
visible FALSE                               
        code/helper_functions/getInfoFromString.R
value   ?                                        
visible FALSE                                    
        code/helper_functions/getSpotnumber.R
value   ?                                    
visible FALSE                                
        code/helper_functions/plotBarFracCluster.R
value   ?                                         
visible FALSE                                     
        code/helper_functions/plotCellCounts.R
value   ?                                     
visible FALSE                                 
        code/helper_functions/plotCellFrac.R
value   ?                                   
visible FALSE                               
        code/helper_functions/plotCellFracGroups.R
value   ?                                         
visible FALSE                                     
        code/helper_functions/plotCellFracGroupsSubset.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(SingleCellExperiment)
library(ggplot2)
library(scater)
library(igraph)
library(reshape2)
library(cowplot)
library(ggridges)
library(tidyverse)
library(viridis)
library(dplyr)
library(sp)
library(sf)
library(RANN)

Load data

sce = readRDS(file = "data/sce_rna.rds")

Clusters/Communities - General

Find clusters of chemokine-producing cells and define communities

A cluster of chemokine-producing cells consists of cells (min. 10) that have a max distance of 20µm to the next chemokine producing cells. A community is defined by cells which surround (max 25µm) the border of a cluster (definded by the convex hull of the cluster).

# average cell diameter
sqrt(mean(sce$Area)/pi)
[1] 4.346728
sqrt(median(sce$Area)/pi)
[1] 4.14593
quantile(sqrt(sce$Area/pi))
       0%       25%       50%       75%      100% 
 1.128379  3.431831  4.145930  4.886025 14.002817 
# find chemokine clusters
sce <- findClusters(sce, sce[,colData(sce)$chemokine == TRUE]$cellID , 
                    'cellID', 
                    'Center_X', 'Center_Y', 
                    'ImageNumber', 
                    distance = 20, 
                    min_clust_size = 10,
                    output_colname = "chemokine_cluster")
Time difference of 5.366572 mins
[1] "clusters successfully added to sce object"
# number of chemokine clusters
length(unique(sce$chemokine_cluster))
[1] 739
# define cells within/surrounding a cluster of chemokine producing cells
sce <- findCommunity(sce, 
                     'cellID', 
                     'Center_X', 'Center_Y', 
                     'ImageNumber', 
                     'chemokine_cluster', 
                     distance = 25,
                     output_colname = "chemokine_community")
Time difference of 3.817586 mins
[1] "communities successfully added to sce object"
# number of chemokine communities
length(unique(sce$chemokine_community))
[1] 739

Clusters/Communities - CXCL13

Find CXCL13 communities (for TLS definition with protein data set)

# find CXCL13 clusters
sce <- findClusters(sce, 
                    sce[,colData(sce)$CXCL13 == 1]$cellID , 
                    'cellID', 
                    'Center_X', 'Center_Y', 
                    'ImageNumber', 
                    distance = 30, 
                    min_clust_size = 10,
                    output_colname = "cxcl13_cluster")
Time difference of 12.61451 secs
[1] "clusters successfully added to sce object"
# number of chemokine clusters
length(unique(sce$cxcl13_cluster))
[1] 113
# define cells within/surrounding a cluster of chemokine producing cells
sce <- findCommunity(sce, 
                     'cellID', 
                     'Center_X', 
                     'Center_Y', 
                     'ImageNumber', 
                     'cxcl13_cluster', 
                     distance = 1,
                     output_colname = "cxcl13_community")
Time difference of 53.63682 secs
[1] "communities successfully added to sce object"
# number of chemokine communities
length(unique(sce$cxcl13_community))
[1] 113

Save SCE object

saveRDS(sce, file = "data/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] RANN_2.6.1                  sf_0.9-7                   
 [3] sp_1.4-5                    viridis_0.5.1              
 [5] viridisLite_0.3.0           forcats_0.5.0              
 [7] stringr_1.4.0               dplyr_1.0.2                
 [9] purrr_0.3.4                 readr_1.4.0                
[11] tidyr_1.1.2                 tibble_3.0.4               
[13] tidyverse_1.3.0             ggridges_0.5.3             
[15] cowplot_1.1.1               reshape2_1.4.4             
[17] igraph_1.2.6                scater_1.16.2              
[19] ggplot2_3.3.3               SingleCellExperiment_1.12.0
[21] SummarizedExperiment_1.20.0 Biobase_2.50.0             
[23] GenomicRanges_1.42.0        GenomeInfoDb_1.26.2        
[25] IRanges_2.24.1              S4Vectors_0.28.1           
[27] BiocGenerics_0.36.0         MatrixGenerics_1.2.0       
[29] matrixStats_0.57.0          workflowr_1.6.2            

loaded via a namespace (and not attached):
 [1] ggbeeswarm_0.6.0          colorspace_2.0-0         
 [3] ellipsis_0.3.1            class_7.3-17             
 [5] rprojroot_2.0.2           XVector_0.30.0           
 [7] BiocNeighbors_1.6.0       fs_1.5.0                 
 [9] rstudioapi_0.13           fansi_0.4.1              
[11] lubridate_1.7.9.2         xml2_1.3.2               
[13] knitr_1.30                jsonlite_1.7.2           
[15] broom_0.7.3               dbplyr_2.0.0             
[17] compiler_4.0.3            httr_1.4.2               
[19] backports_1.2.1           assertthat_0.2.1         
[21] Matrix_1.3-2              cli_2.2.0                
[23] later_1.1.0.1             BiocSingular_1.4.0       
[25] htmltools_0.5.0           tools_4.0.3              
[27] rsvd_1.0.3                gtable_0.3.0             
[29] glue_1.4.2                GenomeInfoDbData_1.2.4   
[31] V8_3.4.0                  Rcpp_1.0.5               
[33] cellranger_1.1.0          vctrs_0.3.6              
[35] DelayedMatrixStats_1.10.1 xfun_0.20                
[37] rvest_0.3.6               lifecycle_0.2.0          
[39] irlba_2.3.3               zlibbioc_1.36.0          
[41] scales_1.1.1              hms_0.5.3                
[43] promises_1.1.1            curl_4.3                 
[45] yaml_2.2.1                gridExtra_2.3            
[47] stringi_1.5.3             e1071_1.7-4              
[49] BiocParallel_1.22.0       rlang_0.4.10             
[51] pkgconfig_2.0.3           bitops_1.0-6             
[53] evaluate_0.14             lattice_0.20-41          
[55] tidyselect_1.1.0          plyr_1.8.6               
[57] magrittr_2.0.1            R6_2.5.0                 
[59] generics_0.1.0            DelayedArray_0.16.0      
[61] DBI_1.1.0                 pillar_1.4.7             
[63] haven_2.3.1               whisker_0.4              
[65] withr_2.3.0               units_0.6-7              
[67] RCurl_1.98-1.2            modelr_0.1.8             
[69] crayon_1.3.4              KernSmooth_2.23-18       
[71] rmarkdown_2.6             grid_4.0.3               
[73] readxl_1.3.1              data.table_1.13.6        
[75] git2r_0.28.0              reprex_0.3.0             
[77] digest_0.6.27             classInt_0.4-3           
[79] httpuv_1.5.4              munsell_0.5.0            
[81] beeswarm_0.2.3            concaveman_1.1.0         
[83] vipor_0.4.5