Last updated: 2021-02-18

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 ee1595d. 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:    ._.DS_Store
    Ignored:    analysis/._clinical metadata preparation.Rmd
    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/
    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
    Modified:   analysis/04_1_Protein_celltype_classification.rmd
    Modified:   analysis/04_1_RNA_celltype_classification.rmd
    Modified:   analysis/04_2_RNA_classification_subclustering.rmd
    Modified:   analysis/04_2_protein_classification_subclustering.rmd
    Modified:   analysis/07_TCF7_PD1_gating.rmd
    Modified:   analysis/08_color_vectors.rmd
    Modified:   analysis/09_Tcell_Score.Rmd
    Modified:   analysis/10_Dysfunction_Score.rmd
    Modified:   analysis/11_Bcell_Score.Rmd
    Modified:   analysis/Figure_1.rmd
    Modified:   analysis/Figure_2.rmd
    Modified:   analysis/Figure_3.rmd
    Modified:   analysis/Figure_4.rmd
    Modified:   analysis/Figure_5.rmd
    Modified:   analysis/Supp-Figure_1.rmd
    Modified:   analysis/Supp-Figure_2.rmd
    Modified:   analysis/Supp-Figure_3.rmd
    Modified:   analysis/Supp-Figure_4.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/05_RNA_chemokine_expressing_cells.rmd) and HTML (docs/05_RNA_chemokine_expressing_cells.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 ee1595d toobiwankenobi 2021-02-12 clean repo and adapt files
html ee1595d toobiwankenobi 2021-02-12 clean repo and adapt files
html 3f5af3f toobiwankenobi 2021-02-09 add .html files
Rmd 9442cb9 toobiwankenobi 2020-12-22 add all new files
Rmd 77466b7 Tobias Hoch 2020-10-22 work on subfigures
Rmd d8819f2 toobiwankenobi 2020-10-08 read new data (nuclei expansion) and adapt scripts
Rmd 73881bb toobiwankenobi 2020-07-30 add code to files from old repo
Rmd cf46cfa toobiwankenobi 2020-07-28 create files

Introduction

Here, we define chemokine-expressing cells

Preparations

knitr::opts_chunk$set(echo = TRUE, message= FALSE)
knitr::opts_knit$set(root.dir = rprojroot::find_rstudio_root_file())

Load libraries

source("code/helper_functions/detect_mRNA_expression.R")
source("code/helper_functions/validityChecks.R")
library(SingleCellExperiment)
library(dplyr)
library(ggplot2)
library(scater)
library(CATALYST)
library(reshape2)
library(LSD)
library(data.table)
library(ComplexHeatmap)
library(corrplot)
library(pheatmap)
library(grid)
library(gridExtra)
library(tidyr)
library(colorRamps)

Load the single cell experiment object and the image metadata

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

Detect Chemokine Expressing Cells

Detection of chemokine expressing cells

for the detection of chemokine expressing cells we make use of the fact that we also measured a negative control (DapB).

# get the names of the chemokine channels without the negative control channel
chemokine_channels = rownames(sce[which(grepl("T\\d+_",rownames(sce)) & ! grepl("DapB",rownames(sce))),])

# run function to define chemokine expressing cells 
output_list <- compute_difference(sce, 
                          cellID = "cellID", 
                          assay_name = "asinh", 
                          threshold = 0.01, 
                          mRNA_channels = chemokine_channels, 
                          negative_control = "T6_DapB", 
                          return_calc_metrics = TRUE)

# overwrite SCE object
sce <- output_list$output_sce

Plot results from chemokine detection

# check difference between DapB and signal (histogram)
for(i in chemokine_channels){
  
  # subset whole data set for visualization purposes
  diff_chemo <- output_list[[i]]
  diff_chemo_sub <- diff_chemo[sample(nrow(diff_chemo), nrow(diff_chemo)*0.1), ]
  
  a = ggplot(data = diff_chemo_sub, aes(x=diff)) + 
  geom_histogram(binwidth = 0.01) + 
  xlab(paste("DapB mRNA signal subtracted from", i, sep = " ")) + ggtitle("Raw distribution") + 
    theme(plot.title = element_text(hjust = 0.5, size = 35), 
          axis.title = element_text(size = 25), 
          axis.text =  element_text(size = 15))

  b = ggplot(data = diff_chemo_sub, aes(x=scaled_diff)) + 
  geom_histogram(binwidth = 0.1, aes(fill = 
                                       ifelse(padj <= 0.01 & scaled_diff > 0, 'p<0.01', 'n.s.'))) + 
  xlab(paste("DapB mRNA signal subtracted from", i, sep = " ")) + ggtitle("Scaled distribution") + 
    labs(fill = "legend") +
    xlim(-5,7) +
    scale_fill_manual(values = c("black", "deepskyblue1")) +
        theme(plot.title = element_text(hjust = 0.5, size = 35), 
          axis.title = element_text(size = 25), 
          legend.text = element_text(size = 20), 
          legend.title = element_text(size=20),
          axis.text =  element_text(size = 15))
  
  # significant cells defined by subtraction
  c = ggplot(data=diff_chemo_sub, aes(x=mean_negative_control, y=mean_chemokine)) + 
    geom_point(alpha=0.2, aes(col = 
                                ifelse(padj <= 0.01 & scaled_diff > 0, 'p<0.01', 'n.s.'))) + 
    scale_color_manual(values = c("black", "deepskyblue1")) +
    xlim(0,5.5) + ylim(0,5.5) +
    ylab(paste("Mean expression of", i, sep=" ")) +
    xlab("Mean DapB mRNAexpression") +
    ggtitle(paste("DapB mRNA vs.", i, sep = " ")) + 
    theme(plot.title = element_text(hjust = 0.5, size = 35), 
          axis.title = element_text(size = 25), 
          legend.position = "none",
          axis.text =  element_text(size = 15))
  #png(file = paste("~/Daniel_volume/Rout_RNA/chemokine_detection_method_comparison/",i,"difference_distribution_BH_0.01.png", sep="_"), height = 1000, width = 1600)
  grid.arrange(a,b,c, nrow = 3, ncol=1)
  #dev.off()
}
Warning: Removed 170 rows containing non-finite values (stat_bin).
Warning: Removed 4 rows containing missing values (geom_bar).

Warning: Removed 163 rows containing non-finite values (stat_bin).

Warning: Removed 4 rows containing missing values (geom_bar).

Warning: Removed 182 rows containing non-finite values (stat_bin).

Warning: Removed 4 rows containing missing values (geom_bar).

Warning: Removed 382 rows containing non-finite values (stat_bin).

Warning: Removed 4 rows containing missing values (geom_bar).
Warning: Removed 1 rows containing missing values (geom_point).

Warning: Removed 139 rows containing non-finite values (stat_bin).
Warning: Removed 4 rows containing missing values (geom_bar).

Warning: Removed 269 rows containing non-finite values (stat_bin).

Warning: Removed 4 rows containing missing values (geom_bar).

Warning: Removed 273 rows containing non-finite values (stat_bin).

Warning: Removed 4 rows containing missing values (geom_bar).

Warning: Removed 68 rows containing non-finite values (stat_bin).

Warning: Removed 4 rows containing missing values (geom_bar).
Warning: Removed 1 rows containing missing values (geom_point).

Warning: Removed 169 rows containing non-finite values (stat_bin).
Warning: Removed 4 rows containing missing values (geom_bar).

Warning: Removed 10 rows containing non-finite values (stat_bin).

Warning: Removed 4 rows containing missing values (geom_bar).

Warning: Removed 187 rows containing non-finite values (stat_bin).

Warning: Removed 4 rows containing missing values (geom_bar).

Basic Stats

Basic numbers on the chemokine expressing cells

chemokines <- data.frame(colData(sce))
chemokines <- chemokines[, chemokine_channels]

# calculate the amount of cells that are positive for 1, 2 and multiple combinations. exclude column containing the ids (12)
single_combinations = chemokines[rowSums(chemokines[,-1]) == 1,-1]

# number of single chemokines positive cells 
nrow(single_combinations)
[1] 45168
double_combinations = chemokines[rowSums(chemokines[,-1]) == 2,-1]
# number of single chemokines positive cells 
nrow(double_combinations)
[1] 8656
multiple_combinations = chemokines[rowSums(chemokines[,-1]) >= 3,-1]
# number of cells that express 3 or more chemokines
nrow(multiple_combinations)
[1] 2427
# number of double positives per chemokine
double_counts <- colSums(double_combinations)

# frequency matrix and corrplot for frequency matrix
double_combinations[double_combinations == 0] <- NA
count_matrix = psych::pairwiseCount(x=double_combinations)

# normalize the frequency matrix by the amount of double combinations that occur for each chemokine
frequency_matrix <- count_matrix
for (i in colnames(count_matrix)){
  frequency_matrix[,i] <- frequency_matrix[,i]/double_counts[i]
}

Frequency double-positive cells

The next plot shows the frequencies of all double positive cell occurences. e.g. of all T4_CXCL10 expressing cells that also express another chemokine more than 50% express T9_CXCL9.

corrplot(frequency_matrix, is.corr = FALSE, tl.col = 'black', method = 'pie', type = 'full', 
         tl.srt = 45, tl.cex = 0.8, tl.offset = 0.5, cl.length = 2, cl.cex = 1, cl.align.text = "l", cl.ratio = 0.3,
         diag=TRUE, order = "hclust")

Corrplot of Frequency matrix

Now we normalize the numbers of double positives by the numbers of all respective positive chemokines. this shows that usually between 20-40 percent of chemokine expressing cells are double positive expressors.

single_counts <- colSums(single_combinations)
frequency_matrix <- count_matrix
for (i in colnames(count_matrix)){
  frequency_matrix[,i] <- frequency_matrix[,i]/single_counts[i]
}

corrplot(frequency_matrix, is.corr = FALSE, tl.col = 'black', method = 'pie', type = 'full', 
         tl.srt = 45, tl.cex = 0.8, tl.offset = 0.5, cl.length = 2, cl.cex = 1, cl.align.text = "l", cl.ratio = 0.3,
         cl.lim = c(0,1), diag=TRUE, order = "hclust")

SCE object

Add data to SCE object

# general chemokine producer tag for every cell (logical binary)
sce$chemokine <- ifelse(rowSums(data.frame(colData(sce)[,chemokine_channels])) > 0, TRUE, FALSE)

# rename colData entry names
idx <- match(chemokine_channels, colnames(colData(sce)))
for(i in idx){
  colnames(colData(sce))[i] <- strsplit(colnames(colData(sce))[i], split = "_")[[1]][2]
}

Add expressor info and colour_vector (with control samples)

cur_df <- colData(sce)
cur_df <- as_tibble(cur_df)
cur_df <- cur_df[,grepl("CCL|CXCL|Dap",colnames(cur_df))]

for(i in colnames(cur_df)){
  cur_df[[i]] <- ifelse(cur_df[[i]]== 1,i,"NA")
}

cur_df <- cur_df %>%
  unite(expressor,sep = "_",na.rm =TRUE,remove=FALSE)

cur_df$expressor <- gsub("NA_","",cur_df$expressor)
cur_df$expressor <- gsub("_NA","",cur_df$expressor)

# summary table of all combinations
summary_cur_df <- table(cur_df$expressor)

# order table according to abundance of combinations
summary_cur_df<- summary_cur_df[order(-as.numeric(summary_cur_df))]

# combinations with more than 600 occurrences
targets <- names(which(summary_cur_df > 600))
targets <- targets[!targets == "NA"]

# add expressor info to sce object
sce$expressor <- cur_df$expressor

# add target names to metadata
metadata(sce)$chemokines_morethan600_withcontrol <- targets

Save SCE object

saveRDS(object = sce,file = "data/data_for_analysis/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] grid      parallel  stats4    stats     graphics  grDevices utils    
 [8] datasets  methods   base     

other attached packages:
 [1] colorRamps_2.3              tidyr_1.1.2                
 [3] gridExtra_2.3               pheatmap_1.0.12            
 [5] corrplot_0.84               ComplexHeatmap_2.4.3       
 [7] data.table_1.13.6           LSD_4.1-0                  
 [9] reshape2_1.4.4              CATALYST_1.12.2            
[11] scater_1.16.2               ggplot2_3.3.3              
[13] dplyr_1.0.2                 SingleCellExperiment_1.12.0
[15] SummarizedExperiment_1.20.0 Biobase_2.50.0             
[17] GenomicRanges_1.42.0        GenomeInfoDb_1.26.2        
[19] IRanges_2.24.1              S4Vectors_0.28.1           
[21] BiocGenerics_0.36.0         MatrixGenerics_1.2.0       
[23] matrixStats_0.57.0          workflowr_1.6.2            

loaded via a namespace (and not attached):
  [1] readxl_1.3.1                circlize_0.4.12            
  [3] drc_3.0-1                   plyr_1.8.6                 
  [5] igraph_1.2.6                ConsensusClusterPlus_1.52.0
  [7] splines_4.0.3               flowCore_2.0.1             
  [9] BiocParallel_1.22.0         TH.data_1.0-10             
 [11] digest_0.6.27               htmltools_0.5.0            
 [13] viridis_0.5.1               magrittr_2.0.1             
 [15] CytoML_2.0.5                cluster_2.1.0              
 [17] openxlsx_4.2.3              RcppParallel_5.0.2         
 [19] sandwich_3.0-0              flowWorkspace_4.0.6        
 [21] cytolib_2.0.3               jpeg_0.1-8.1               
 [23] colorspace_2.0-0            ggrepel_0.9.0              
 [25] haven_2.3.1                 xfun_0.20                  
 [27] crayon_1.3.4                RCurl_1.98-1.2             
 [29] jsonlite_1.7.2              hexbin_1.28.2              
 [31] graph_1.66.0                survival_3.2-7             
 [33] zoo_1.8-8                   glue_1.4.2                 
 [35] gtable_0.3.0                nnls_1.4                   
 [37] zlibbioc_1.36.0             XVector_0.30.0             
 [39] GetoptLong_1.0.5            DelayedArray_0.16.0        
 [41] ggcyto_1.16.0               car_3.0-10                 
 [43] BiocSingular_1.4.0          Rgraphviz_2.32.0           
 [45] shape_1.4.5                 abind_1.4-5                
 [47] scales_1.1.1                mvtnorm_1.1-1              
 [49] Rcpp_1.0.5                  plotrix_3.7-8              
 [51] viridisLite_0.3.0           tmvnsim_1.0-2              
 [53] clue_0.3-58                 foreign_0.8-81             
 [55] rsvd_1.0.3                  FlowSOM_1.20.0             
 [57] tsne_0.1-3                  RColorBrewer_1.1-2         
 [59] ellipsis_0.3.1              farver_2.0.3               
 [61] pkgconfig_2.0.3             XML_3.99-0.5               
 [63] labeling_0.4.2              tidyselect_1.1.0           
 [65] rlang_0.4.10                later_1.1.0.1              
 [67] munsell_0.5.0               cellranger_1.1.0           
 [69] tools_4.0.3                 generics_0.1.0             
 [71] ggridges_0.5.3              evaluate_0.14              
 [73] stringr_1.4.0               yaml_2.2.1                 
 [75] knitr_1.30                  fs_1.5.0                   
 [77] zip_2.1.1                   purrr_0.3.4                
 [79] nlme_3.1-151                RBGL_1.64.0                
 [81] whisker_0.4                 xml2_1.3.2                 
 [83] compiler_4.0.3              rstudioapi_0.13            
 [85] beeswarm_0.2.3              curl_4.3                   
 [87] png_0.1-7                   tibble_3.0.4               
 [89] stringi_1.5.3               forcats_0.5.0              
 [91] lattice_0.20-41             Matrix_1.3-2               
 [93] psych_2.0.12                vctrs_0.3.6                
 [95] pillar_1.4.7                lifecycle_0.2.0            
 [97] GlobalOptions_0.1.2         BiocNeighbors_1.6.0        
 [99] cowplot_1.1.1               bitops_1.0-6               
[101] irlba_2.3.3                 httpuv_1.5.4               
[103] R6_2.5.0                    latticeExtra_0.6-29        
[105] promises_1.1.1              RProtoBufLib_2.0.0         
[107] rio_0.5.16                  vipor_0.4.5                
[109] codetools_0.2-18            MASS_7.3-53                
[111] gtools_3.8.2                rprojroot_2.0.2            
[113] rjson_0.2.20                withr_2.3.0                
[115] mnormt_2.0.2                multcomp_1.4-15            
[117] GenomeInfoDbData_1.2.4      hms_0.5.3                  
[119] ncdfFlow_2.34.0             rmarkdown_2.6              
[121] DelayedMatrixStats_1.10.1   carData_3.0-4              
[123] Rtsne_0.15                  git2r_0.28.0               
[125] base64enc_0.1-3             ggbeeswarm_0.6.0