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_8.rmd) and HTML (docs/Supp-Figure_8.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 f9a3a83 toobiwankenobi 2022-02-08 clean repo for release
Rmd b20b6fb toobiwankenobi 2022-02-02 update code for Supp Figures

Introduction

This script generates plots for Supplementary Figure 8.

Preparations

Load libraries

sapply(list.files("code/helper_functions", full.names = TRUE), source)

Attaching package: 'dplyr'
The following objects are masked from 'package:stats':

    filter, lag
The following objects are masked from 'package:base':

    intersect, setdiff, setequal, union
        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(data.table)

Attaching package: 'data.table'
The following objects are masked from 'package:dplyr':

    between, first, last
library(ggplot2)
library(broom)
library(dplyr)
library(tidyverse)
── Attaching packages ─────────────────────────────────────── tidyverse 1.3.1 ──
✓ tibble  3.1.6     ✓ purrr   0.3.4
✓ tidyr   1.2.0     ✓ stringr 1.4.0
✓ readr   2.1.2     ✓ forcats 0.5.1
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
x data.table::between() masks dplyr::between()
x dplyr::filter()       masks stats::filter()
x data.table::first()   masks dplyr::first()
x dplyr::lag()          masks stats::lag()
x data.table::last()    masks dplyr::last()
x purrr::transpose()    masks data.table::transpose()
library(cowplot)
library(ggbeeswarm)
library(gridExtra)

Attaching package: 'gridExtra'
The following object is masked from 'package:dplyr':

    combine
library(SingleCellExperiment)
Loading required package: SummarizedExperiment
Loading required package: MatrixGenerics
Loading required package: matrixStats

Attaching package: 'matrixStats'
The following object is masked from 'package:dplyr':

    count

Attaching package: 'MatrixGenerics'
The following objects are masked from 'package:matrixStats':

    colAlls, colAnyNAs, colAnys, colAvgsPerRowSet, colCollapse,
    colCounts, colCummaxs, colCummins, colCumprods, colCumsums,
    colDiffs, colIQRDiffs, colIQRs, colLogSumExps, colMadDiffs,
    colMads, colMaxs, colMeans2, colMedians, colMins, colOrderStats,
    colProds, colQuantiles, colRanges, colRanks, colSdDiffs, colSds,
    colSums2, colTabulates, colVarDiffs, colVars, colWeightedMads,
    colWeightedMeans, colWeightedMedians, colWeightedSds,
    colWeightedVars, rowAlls, rowAnyNAs, rowAnys, rowAvgsPerColSet,
    rowCollapse, rowCounts, rowCummaxs, rowCummins, rowCumprods,
    rowCumsums, rowDiffs, rowIQRDiffs, rowIQRs, rowLogSumExps,
    rowMadDiffs, rowMads, rowMaxs, rowMeans2, rowMedians, rowMins,
    rowOrderStats, rowProds, rowQuantiles, rowRanges, rowRanks,
    rowSdDiffs, rowSds, rowSums2, rowTabulates, rowVarDiffs, rowVars,
    rowWeightedMads, rowWeightedMeans, rowWeightedMedians,
    rowWeightedSds, rowWeightedVars
Loading required package: GenomicRanges
Loading required package: stats4
Loading required package: BiocGenerics

Attaching package: 'BiocGenerics'
The following object is masked from 'package:gridExtra':

    combine
The following objects are masked from 'package:dplyr':

    combine, intersect, setdiff, union
The following objects are masked from 'package:stats':

    IQR, mad, sd, var, xtabs
The following objects are masked from 'package:base':

    anyDuplicated, append, as.data.frame, basename, cbind, colnames,
    dirname, do.call, duplicated, eval, evalq, Filter, Find, get, grep,
    grepl, intersect, is.unsorted, lapply, Map, mapply, match, mget,
    order, paste, pmax, pmax.int, pmin, pmin.int, Position, rank,
    rbind, Reduce, rownames, sapply, setdiff, sort, table, tapply,
    union, unique, unsplit, which.max, which.min
Loading required package: S4Vectors

Attaching package: 'S4Vectors'
The following object is masked from 'package:tidyr':

    expand
The following objects are masked from 'package:data.table':

    first, second
The following objects are masked from 'package:dplyr':

    first, rename
The following objects are masked from 'package:base':

    expand.grid, I, unname
Loading required package: IRanges

Attaching package: 'IRanges'
The following object is masked from 'package:purrr':

    reduce
The following object is masked from 'package:data.table':

    shift
The following objects are masked from 'package:dplyr':

    collapse, desc, slice
Loading required package: GenomeInfoDb
Loading required package: Biobase
Welcome to Bioconductor

    Vignettes contain introductory material; view with
    'browseVignettes()'. To cite Bioconductor, see
    'citation("Biobase")', and for packages 'citation("pkgname")'.

Attaching package: 'Biobase'
The following object is masked from 'package:MatrixGenerics':

    rowMedians
The following objects are masked from 'package:matrixStats':

    anyMissing, rowMedians
library(scater)
Loading required package: scuttle
library(reshape2)

Attaching package: 'reshape2'
The following object is masked from 'package:tidyr':

    smiths
The following objects are masked from 'package:data.table':

    dcast, melt
library(circlize)
========================================
circlize version 0.4.13
CRAN page: https://cran.r-project.org/package=circlize
Github page: https://github.com/jokergoo/circlize
Documentation: https://jokergoo.github.io/circlize_book/book/

If you use it in published research, please cite:
Gu, Z. circlize implements and enhances circular visualization
  in R. Bioinformatics 2014.

This message can be suppressed by:
  suppressPackageStartupMessages(library(circlize))
========================================
library(rstatix)

Attaching package: 'rstatix'
The following object is masked from 'package:IRanges':

    desc
The following object is masked from 'package:stats':

    filter
library(corrplot)
corrplot 0.92 loaded
library(ggpubr)

Attaching package: 'ggpubr'
The following object is masked from 'package:cowplot':

    get_legend

Load Data

# SCE object
sce_rna = readRDS(file = "data/data_for_analysis/sce_RNA.rds")
sce_rna <- sce_rna[,sce_rna$Location != "CTRL"]

targets <- metadata(sce_rna)$chemokines_morethan600_withcontrol

Supp Figure 8A

Patients per Location

sce_rna$MM_location <- ifelse(sce_rna$MM_location %in% c("skin", "skin_undefine"), "skin_undefined", sce_rna$MM_location)

groups <- data.frame(colData(sce_rna)) %>%
  distinct(ImageNumber, .keep_all = T) %>%
  group_by(MM_location) %>%
  distinct(PatientID, .keep_all = T) %>%
  summarise(n=n()) %>%
  filter(n>=10) %>%
  arrange(-n)

Boxplot/Barplot per Location for every chemokine combination

fractions_per_image <- data.frame(colData(sce_rna)) %>%
  group_by(ImageNumber, MM_location, expressor, celltype) %>%
  summarise(n = n()) %>%
  group_by(ImageNumber) %>%
  mutate(fraction_per_image = n / sum(n)) %>%
  group_by(ImageNumber, expressor) %>%
  mutate(group_fraction = sum(fraction_per_image)) %>%
  ungroup() %>%
  filter(expressor %in% targets & MM_location %in% groups$MM_location)
`summarise()` has grouped output by 'ImageNumber', 'MM_location', 'expressor'.
You can override using the `.groups` argument.
# fraction of expressor cells per image 
fraction_expressor_per_image <- fractions_per_image %>%
  distinct(ImageNumber, MM_location, expressor, .keep_all = T) %>%
  reshape2::dcast(ImageNumber + MM_location ~ expressor, value.var = "group_fraction", fill = 0) %>%
  reshape2::melt(id.vars = c("ImageNumber", "MM_location"), variable.name = "expressor", 
                 value.name = "fraction_per_image")

# fraction of celltype expressing a certain combi per image
celltype_fractions <- fractions_per_image %>%
  distinct(ImageNumber, celltype, expressor, .keep_all = T) %>%
  reshape2::dcast(ImageNumber + MM_location + expressor ~ celltype, value.var = "fraction_per_image", fill = 0) %>%
  reshape2::melt(id.vars = c("ImageNumber", "MM_location", "expressor"), 
                 variable.name = "celltype", value.name = "fraction_per_image") %>%
  reshape2::dcast(ImageNumber + MM_location + celltype ~ expressor, value.var = "fraction_per_image", fill = 0) %>%
  reshape2::melt(id.vars = c("ImageNumber", "MM_location", "celltype"), 
                 variable.name = "expressor", value.name = "fraction_per_image") %>%
  group_by(MM_location, expressor, celltype) %>%
  summarise(sum_fraction = sum(fraction_per_image)) %>% # sum-up fractions over all images 
  group_by(MM_location, expressor) %>%
  mutate(proportions = sum_fraction / sum(sum_fraction)) # calculate proportions for each expressor
`summarise()` has grouped output by 'MM_location', 'expressor'. You can override
using the `.groups` argument.

Plot

# calculate signif of expressor-fractions per MM_location
fraction_expressor_per_image %>%
  group_by(expressor) %>%
  wilcox_test(fraction_per_image ~ MM_location) %>%
  adjust_pvalue(method = "BH") %>%
  add_significance("p.adj",cutpoints = c(0, 1e-04, 0.001, 0.01, 0.1, 1)) %>%
  arrange(p.adj)
# A tibble: 14 × 10
   expressor    .y.           group1 group2    n1    n2 statistic       p  p.adj
   <fct>        <chr>         <chr>  <chr>  <int> <int>     <dbl>   <dbl>  <dbl>
 1 CCL19        fraction_per… LN     skin_…    49    52     1739  0.00129 0.0181
 2 CXCL13       fraction_per… LN     skin_…    49    52     1634. 0.0138  0.0966
 3 CCL22        fraction_per… LN     skin_…    49    52     1557  0.0548  0.145 
 4 CXCL12_CCL2  fraction_per… LN     skin_…    49    52     1535  0.062   0.145 
 5 CXCL8        fraction_per… LN     skin_…    49    52     1580  0.0378  0.145 
 6 CXCL9_CCL19  fraction_per… LN     skin_…    49    52     1523  0.0487  0.145 
 7 CCL18        fraction_per… LN     skin_…    49    52     1501  0.124   0.217 
 8 CXCL10_CCL2  fraction_per… LN     skin_…    49    52     1054  0.121   0.217 
 9 CXCL10       fraction_per… LN     skin_…    49    52     1095  0.225   0.315 
10 CXCL12       fraction_per… LN     skin_…    49    52     1457  0.215   0.315 
11 CCL4         fraction_per… LN     skin_…    49    52     1382  0.465   0.592 
12 CCL2         fraction_per… LN     skin_…    49    52     1326. 0.724   0.845 
13 CXCL10_CXCL9 fraction_per… LN     skin_…    49    52     1270  0.981   0.981 
14 CXCL9        fraction_per… LN     skin_…    49    52     1288  0.926   0.981 
# … with 1 more variable: p.adj.signif <chr>
plot_list <- list()
for(i in groups$MM_location) {
  a <- fraction_expressor_per_image %>%
    filter(MM_location == i) %>%  
    group_by(ImageNumber, expressor) %>%
    ggplot(., aes(y=as.factor(expressor), x=fraction_per_image)) + 
    geom_boxplot() + 
    geom_point(alpha=0.2) +
    theme_bw() +
    theme(axis.title.y = element_blank(),
          axis.text.y = element_text(hjust=0.5)) +
    xlab("Cell Fraction per Image") + 
    coord_cartesian(xlim = c(0,0.05))
  
  b <- celltype_fractions %>%
    filter(MM_location == i) %>%  
    ggplot(., aes(y=expressor, x=-proportions, fill=celltype)) + 
    geom_bar(stat = "identity") +
    theme_bw() +
    theme(axis.text.y = element_blank(),
          axis.title.y = element_blank()) +
    guides(fill=guide_legend(title = "Cell Type",nrow=2,byrow=TRUE)) +
    xlab("Producing Cell Types") +
          scale_fill_manual(values = unname(metadata(sce_rna)$colour_vectors$celltype),
                        breaks = names(metadata(sce_rna)$colour_vectors$celltype),
                        labels = names(metadata(sce_rna)$colour_vectors$celltype)) +
    scale_x_continuous(breaks=c(-1.00,-0.75,-0.5, -0.25, 0.00),
                     labels=c("100%", "75%", "50%", "25%", "0%"))
  
  leg <- get_legend(b)
  
  grid.arrange(b+theme(legend.position = "none"),a,nrow=1,
               widths = c(.75,1),
               top = i)
}

Version Author Date
ff22877 toobiwankenobi 2022-02-22

Version Author Date
ff22877 toobiwankenobi 2022-02-22
grid.arrange(leg)

Version Author Date
ff22877 toobiwankenobi 2022-02-22

Supp Figure 8B

Chemokines cross-correlation

# top abundant chemokines
cur_rna <- data.frame(colData(sce_rna))

# sum
rna_sum <- cur_rna %>%
  group_by(Description, expressor) %>%
  summarise(n = n()) %>%
  reshape2::dcast(Description ~ expressor, value.var = "n", fill = 0) 
`summarise()` has grouped output by 'Description'. You can override using the
`.groups` argument.
# only keep highly abundant chemokines
rna_sum <- rna_sum[,colnames(rna_sum) %in% targets]

# correlation
cor <- cor(rna_sum, rna_sum, method = "pearson")

corrplot(cor, 
         order = "FPC",
         addCoef.col = "black",
         method = "circle",
         tl.col="black",
         tl.cex = 1.5)

Version Author Date
ff22877 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] stats4    stats     graphics  grDevices utils     datasets  methods  
[8] base     

other attached packages:
 [1] ggpubr_0.4.0                corrplot_0.92              
 [3] rstatix_0.7.0               circlize_0.4.13            
 [5] reshape2_1.4.4              scater_1.22.0              
 [7] scuttle_1.4.0               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          gridExtra_2.3              
[19] ggbeeswarm_0.6.0            cowplot_1.1.1              
[21] forcats_0.5.1               stringr_1.4.0              
[23] purrr_0.3.4                 readr_2.1.2                
[25] tidyr_1.2.0                 tibble_3.1.6               
[27] tidyverse_1.3.1             broom_0.7.12               
[29] ggplot2_3.3.5               data.table_1.14.2          
[31] dplyr_1.0.7                 workflowr_1.7.0            

loaded via a namespace (and not attached):
 [1] colorspace_2.0-2          ggsignif_0.6.3           
 [3] ellipsis_0.3.2            rprojroot_2.0.2          
 [5] XVector_0.34.0            GlobalOptions_0.1.2      
 [7] BiocNeighbors_1.12.0      fs_1.5.2                 
 [9] rstudioapi_0.13           farver_2.1.0             
[11] ggrepel_0.9.1             fansi_1.0.2              
[13] lubridate_1.8.0           xml2_1.3.3               
[15] sparseMatrixStats_1.6.0   knitr_1.37               
[17] jsonlite_1.7.3            dbplyr_2.1.1             
[19] compiler_4.1.2            httr_1.4.2               
[21] backports_1.4.1           assertthat_0.2.1         
[23] Matrix_1.4-0              fastmap_1.1.0            
[25] cli_3.1.1                 later_1.3.0              
[27] BiocSingular_1.10.0       htmltools_0.5.2          
[29] tools_4.1.2               rsvd_1.0.5               
[31] gtable_0.3.0              glue_1.6.1               
[33] GenomeInfoDbData_1.2.7    Rcpp_1.0.8               
[35] carData_3.0-5             cellranger_1.1.0         
[37] jquerylib_0.1.4           vctrs_0.3.8              
[39] DelayedMatrixStats_1.16.0 xfun_0.29                
[41] ps_1.6.0                  beachmat_2.10.0          
[43] rvest_1.0.2               lifecycle_1.0.1          
[45] irlba_2.3.5               getPass_0.2-2            
[47] zlibbioc_1.40.0           scales_1.1.1             
[49] hms_1.1.1                 promises_1.2.0.1         
[51] parallel_4.1.2            yaml_2.2.2               
[53] sass_0.4.0                stringi_1.7.6            
[55] highr_0.9                 ScaledMatrix_1.2.0       
[57] BiocParallel_1.28.3       shape_1.4.6              
[59] rlang_1.0.0               pkgconfig_2.0.3          
[61] bitops_1.0-7              evaluate_0.14            
[63] lattice_0.20-45           labeling_0.4.2           
[65] processx_3.5.2            tidyselect_1.1.1         
[67] plyr_1.8.6                magrittr_2.0.2           
[69] R6_2.5.1                  generics_0.1.2           
[71] DelayedArray_0.20.0       DBI_1.1.2                
[73] pillar_1.7.0              haven_2.4.3              
[75] whisker_0.4               withr_2.4.3              
[77] abind_1.4-5               RCurl_1.98-1.5           
[79] car_3.0-12                modelr_0.1.8             
[81] crayon_1.4.2              utf8_1.2.2               
[83] tzdb_0.2.0                rmarkdown_2.11           
[85] viridis_0.6.2             grid_4.1.2               
[87] readxl_1.3.1              callr_3.7.0              
[89] git2r_0.29.0              reprex_2.0.1             
[91] digest_0.6.29             httpuv_1.6.5             
[93] munsell_0.5.0             beeswarm_0.4.0           
[95] viridisLite_0.4.0         vipor_0.4.5              
[97] bslib_0.3.1