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/11_Bcell_Patch_Detection.Rmd) and HTML (docs/11_Bcell_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 73aa800 toobiwankenobi 2022-02-22 add .html for static website
Rmd d6a945a toobiwankenobi 2021-12-06 updated figures
Rmd 3da15db toobiwankenobi 2021-11-24 changes for revision

Introduction

This script detects interaction networks of a given celltype (here: B 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.

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/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(SingleCellExperiment)
library(ggplot2)
library(scater)
library(viridis)
library(igraph)
library(CATALYST)
library(reshape2)
library(cowplot)
library(ggridges)
library(tidyverse)
library(viridis)
library(dplyr)
library(cytomapper)
library(concaveman)
library(data.table)
library(sf)
library(ggbeeswarm)
library(RANN)

Load data

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

Find patches of B cells and their milieus

A B cell cluster is defined by at least 20 adjacent B cells (Bcell and BnTcell, max distance of 15µm between them). A milieu is defined by all cells within a cluster and the proximity (enlarging distance = 15µm)

sce_prot$bcell_patch <- NULL
sce_prot$bcell_milieu <- NULL
sce_prot$bcell_patch_score <- NULL

start = Sys.time()

# quantiles of cell radius
quantile(sqrt(sce_prot[,sce_prot$celltype %in% c("B cell")]$Area/pi))
      0%      25%      50%      75%     100% 
1.128379 2.820948 3.385138 3.908820 9.097284 
# find B cell clusters
sce_prot <- findPatch(sce_prot, sce_prot[,colData(sce_prot)$celltype %in% c("B cell", "BnT cell")]$cellID, 
                    'cellID', 'Center_X', 'Center_Y', 'ImageNumber', 
                    distance = 15, min_clust_size = 10, output_colname = "bcell_patch")
Time difference of 10.19127 mins
[1] "patches successfully added to sce object"
# number of B cell clusters
length(unique(sce_prot$bcell_patch))
[1] 375
# define cells within/surrounding a cluster of B cells
sce_prot <- findMilieu(sce_prot, 
                     'cellID', 'Center_X', 'Center_Y', 'ImageNumber', 'bcell_patch', 
                     distance = 30, output_colname = "bcell_milieu")
Time difference of 2.777045 mins
[1] "milieus successfully added to sce object"
# number of chemokine communities
length(unique(sce_prot$bcell_milieu))
[1] 375
end = Sys.time()
print(end-start)
Time difference of 12.97945 mins

Plot some patches

example <- findPatch(sce_prot[,sce_prot$Description %in% c("D4")], sce_prot[,sce_prot$celltype %in% c("B cell", "BnT cell")]$cellID, 
                    'cellID', 
                    'Center_X', 'Center_Y', 
                    'ImageNumber', 
                    distance = 15, 
                    min_clust_size = 10,
                    output_colname = "example_patch")
Time difference of 0.4569645 secs
[1] "patches successfully added to sce object"
example <- findMilieu(example, 
              'cellID', 
              'Center_X', 'Center_Y', 
              'ImageNumber', 
              'example_patch', 
              distance = 30,
              output_colname = "example_milieu",
              plot = TRUE)

Version Author Date
5418dcd toobiwankenobi 2022-02-22
Time difference of 1.115749 secs
[1] "milieus successfully added to sce object"

Save SCE object

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.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] RANN_2.6.1                  ggbeeswarm_0.6.0           
 [3] sf_1.0-5                    data.table_1.14.2          
 [5] concaveman_1.1.0            cytomapper_1.6.0           
 [7] EBImage_4.36.0              forcats_0.5.1              
 [9] stringr_1.4.0               purrr_0.3.4                
[11] readr_2.1.2                 tidyr_1.2.0                
[13] tibble_3.1.6                tidyverse_1.3.1            
[15] ggridges_0.5.3              cowplot_1.1.1              
[17] reshape2_1.4.4              CATALYST_1.18.1            
[19] igraph_1.2.11               viridis_0.6.2              
[21] viridisLite_0.4.0           scater_1.22.0              
[23] scuttle_1.4.0               ggplot2_3.3.5              
[25] SingleCellExperiment_1.16.0 SummarizedExperiment_1.24.0
[27] Biobase_2.54.0              GenomicRanges_1.46.1       
[29] GenomeInfoDb_1.30.1         IRanges_2.28.0             
[31] S4Vectors_0.32.3            BiocGenerics_0.40.0        
[33] MatrixGenerics_1.6.0        matrixStats_0.61.0         
[35] dplyr_1.0.7                 workflowr_1.7.0            

loaded via a namespace (and not attached):
  [1] scattermore_0.7             flowWorkspace_4.6.0        
  [3] knitr_1.37                  irlba_2.3.5                
  [5] multcomp_1.4-18             DelayedArray_0.20.0        
  [7] RCurl_1.98-1.5              doParallel_1.0.16          
  [9] generics_0.1.2              flowCore_2.6.0             
 [11] ScaledMatrix_1.2.0          terra_1.5-17               
 [13] callr_3.7.0                 TH.data_1.1-0              
 [15] proxy_0.4-26                ggpointdensity_0.1.0       
 [17] tzdb_0.2.0                  xml2_1.3.3                 
 [19] lubridate_1.8.0             httpuv_1.6.5               
 [21] assertthat_0.2.1            xfun_0.29                  
 [23] hms_1.1.1                   jquerylib_0.1.4            
 [25] evaluate_0.14               promises_1.2.0.1           
 [27] fansi_1.0.2                 dbplyr_2.1.1               
 [29] readxl_1.3.1                Rgraphviz_2.38.0           
 [31] DBI_1.1.2                   htmlwidgets_1.5.4          
 [33] ellipsis_0.3.2              ggcyto_1.22.0              
 [35] ggnewscale_0.4.5            ggpubr_0.4.0               
 [37] backports_1.4.1             V8_4.0.0                   
 [39] cytolib_2.6.1               svgPanZoom_0.3.4           
 [41] RcppParallel_5.1.5          sparseMatrixStats_1.6.0    
 [43] vctrs_0.3.8                 abind_1.4-5                
 [45] withr_2.4.3                 ggforce_0.3.3              
 [47] aws.signature_0.6.0         svglite_2.0.0              
 [49] cluster_2.1.2               crayon_1.4.2               
 [51] drc_3.0-1                   units_0.7-2                
 [53] pkgconfig_2.0.3             tweenr_1.0.2               
 [55] vipor_0.4.5                 rlang_1.0.0                
 [57] lifecycle_1.0.1             sandwich_3.0-1             
 [59] modelr_0.1.8                rsvd_1.0.5                 
 [61] cellranger_1.1.0            rprojroot_2.0.2            
 [63] polyclip_1.10-0             graph_1.72.0               
 [65] tiff_0.1-11                 Matrix_1.4-0               
 [67] raster_3.5-15               carData_3.0-5              
 [69] Rhdf5lib_1.16.0             zoo_1.8-9                  
 [71] reprex_2.0.1                base64enc_0.1-3            
 [73] beeswarm_0.4.0              whisker_0.4                
 [75] GlobalOptions_0.1.2         processx_3.5.2             
 [77] pheatmap_1.0.12             png_0.1-7                  
 [79] rjson_0.2.21                bitops_1.0-7               
 [81] shinydashboard_0.7.2        getPass_0.2-2              
 [83] KernSmooth_2.23-20          rhdf5filters_1.6.0         
 [85] ConsensusClusterPlus_1.58.0 DelayedMatrixStats_1.16.0  
 [87] classInt_0.4-3              shape_1.4.6                
 [89] jpeg_0.1-9                  rstatix_0.7.0              
 [91] ggsignif_0.6.3              aws.s3_0.3.21              
 [93] beachmat_2.10.0             scales_1.1.1               
 [95] magrittr_2.0.2              plyr_1.8.6                 
 [97] hexbin_1.28.2               zlibbioc_1.40.0            
 [99] compiler_4.1.2              RColorBrewer_1.1-2         
[101] plotrix_3.8-2               clue_0.3-60                
[103] cli_3.1.1                   XVector_0.34.0             
[105] ncdfFlow_2.40.0             ps_1.6.0                   
[107] FlowSOM_2.2.0               MASS_7.3-55                
[109] tidyselect_1.1.1            stringi_1.7.6              
[111] RProtoBufLib_2.6.0          highr_0.9                  
[113] yaml_2.2.2                  BiocSingular_1.10.0        
[115] locfit_1.5-9.4              latticeExtra_0.6-29        
[117] ggrepel_0.9.1               grid_4.1.2                 
[119] sass_0.4.0                  tools_4.1.2                
[121] parallel_4.1.2              CytoML_2.6.0               
[123] circlize_0.4.13             rstudioapi_0.13            
[125] foreach_1.5.2               git2r_0.29.0               
[127] gridExtra_2.3               farver_2.1.0               
[129] Rtsne_0.15                  digest_0.6.29              
[131] shiny_1.7.1                 Rcpp_1.0.8                 
[133] car_3.0-12                  broom_0.7.12               
[135] later_1.3.0                 httr_1.4.2                 
[137] ComplexHeatmap_2.10.0       colorspace_2.0-2           
[139] rvest_1.0.2                 XML_3.99-0.8               
[141] fs_1.5.2                    splines_4.1.2              
[143] RBGL_1.70.0                 sp_1.4-6                   
[145] systemfonts_1.0.3           xtable_1.8-4               
[147] jsonlite_1.7.3              R6_2.5.1                   
[149] pillar_1.7.0                htmltools_0.5.2            
[151] mime_0.12                   nnls_1.4                   
[153] glue_1.6.1                  fastmap_1.1.0              
[155] BiocParallel_1.28.3         BiocNeighbors_1.12.0       
[157] fftwtools_0.9-11            class_7.3-20               
[159] codetools_0.2-18            mvtnorm_1.1-3              
[161] utf8_1.2.2                  lattice_0.20-45            
[163] bslib_0.3.1                 curl_4.3.2                 
[165] colorRamps_2.3              gtools_3.9.2               
[167] survival_3.2-13             rmarkdown_2.11             
[169] munsell_0.5.0               e1071_1.7-9                
[171] rhdf5_2.38.0                GetoptLong_1.0.5           
[173] GenomeInfoDbData_1.2.7      iterators_1.0.13           
[175] HDF5Array_1.22.1            haven_2.4.3                
[177] gtable_0.3.0