Last updated: 2021-02-10

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 2e443a5. 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/._layer_1_classification_rna.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/layer_1_classification_protein.csv
    Ignored:    data/layer_1_classification_rna.csv
    Ignored:    data/manual_infiltration/
    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
    Modified:   analysis/04_1_Protein_celltype_classification.rmd
    Modified:   analysis/04_1_RNA_celltype_classification.rmd
    Modified:   analysis/Supp-Figure_2.rmd
    Modified:   analysis/Supp-Figure_4.rmd
    Deleted:    code/findPackages.R

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_1.rmd) and HTML (docs/Supp-Figure_1.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 3f5af3f toobiwankenobi 2021-02-09 add .html files
Rmd 20a1458 toobiwankenobi 2021-02-04 adapt figure order
Rmd f9bb33a toobiwankenobi 2021-02-04 new Figure 5 and minor changes in figure order
Rmd 9442cb9 toobiwankenobi 2020-12-22 add all new files
Rmd 1af3353 toobiwankenobi 2020-10-16 add stuff
Rmd a6b51cd toobiwankenobi 2020-10-14 clean scripts, add new subfigures
Rmd d8819f2 toobiwankenobi 2020-10-08 read new data (nuclei expansion) and adapt scripts

Introduction

This script generates plots for Supplementary Figure 1.

Preparations

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/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)
Loading required package: SummarizedExperiment
Loading required package: MatrixGenerics
Loading required package: matrixStats

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
Loading required package: parallel

Attaching package: 'BiocGenerics'
The following objects are masked from 'package:parallel':

    clusterApply, clusterApplyLB, clusterCall, clusterEvalQ,
    clusterExport, clusterMap, parApply, parCapply, parLapply,
    parLapplyLB, parRapply, parSapply, parSapplyLB
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:base':

    expand.grid
Loading required package: IRanges
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(data.table)

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

    shift
The following object is masked from 'package:GenomicRanges':

    shift
The following object is masked from 'package:IRanges':

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

    first, second
library(ggplot2)
library(dplyr)

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

    between, first, last
The following object is masked from 'package:Biobase':

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

    intersect, setdiff, union
The following object is masked from 'package:GenomeInfoDb':

    intersect
The following objects are masked from 'package:IRanges':

    collapse, desc, intersect, setdiff, slice, union
The following objects are masked from 'package:S4Vectors':

    first, intersect, rename, setdiff, setequal, union
The following objects are masked from 'package:BiocGenerics':

    combine, intersect, setdiff, union
The following object is masked from 'package:matrixStats':

    count
The following objects are masked from 'package:stats':

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

    intersect, setdiff, setequal, union
library(stringr)
library(ggpubr)
library(ComplexHeatmap)
Loading required package: grid
========================================
ComplexHeatmap version 2.4.3
Bioconductor page: http://bioconductor.org/packages/ComplexHeatmap/
Github page: https://github.com/jokergoo/ComplexHeatmap
Documentation: http://jokergoo.github.io/ComplexHeatmap-reference

If you use it in published research, please cite:
Gu, Z. Complex heatmaps reveal patterns and correlations in multidimensional 
  genomic data. Bioinformatics 2016.

This message can be suppressed by:
  suppressPackageStartupMessages(library(ComplexHeatmap))
========================================
library(circlize)
========================================
circlize version 0.4.12
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(gridExtra)

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

    combine
The following object is masked from 'package:Biobase':

    combine
The following object is masked from 'package:BiocGenerics':

    combine
library(ggbeeswarm)
library(ggrepel)
library(ggpmisc)

Attaching package: 'ggpmisc'
The following object is masked from 'package:ggplot2':

    annotate
library(ggrastr)

Load and process the data

# load data
cells1 = fread("data/12plex_validation/overexpression/20190305/cell.csv", header = T,sep=",")
cells2 = fread("data/12plex_validation/overexpression/20190306/cell.csv", header = T,sep=",")
meta1 = fread("data/12plex_validation/overexpression/20190305/Image.csv",header = T,sep=",")
Warning in require_bit64_if_needed(ans): Some columns are type 'integer64'
but package bit64 is not installed. Those columns will print as strange
looking floating point data. There is no need to reload the data. Simply
install.packages('bit64') to obtain the integer64 print method and print the
data again.
meta2 = fread("data/12plex_validation/overexpression/20190306/Image.csv",header = T,sep=",")
Warning in require_bit64_if_needed(ans): Some columns are type 'integer64'
but package bit64 is not installed. Those columns will print as strange
looking floating point data. There is no need to reload the data. Simply
install.packages('bit64') to obtain the integer64 print method and print the
data again.
panel = fread( "data/12plex_validation/overexpression/20190305/20190305_A431_overexpression.csv")

# extract replicate and stain info
meta1 = meta1[,.(ImageNumber,FileName_CellImage, Group_Number, Metadata_Target)]
meta1[,':=' (replicate = getInfoFromString(FileName_CellImage,"_",1)), by=ImageNumber]
meta2 = meta2[,.(ImageNumber,FileName_CellImage, Group_Number, Metadata_Target)]
meta2[,':=' (replicate = getInfoFromString(FileName_CellImage,"_",1)), by=ImageNumber]

# sort Metal Number in same order than in the Image.csv file
panel$`Metal Number` = str_extract(panel$`Metal Tag`, "[0-9]+")
panel = panel[order(panel$`Metal Number`),]
panel$channel = c(1:nrow(panel))

cells_long1 = melt.data.table(cells1,id.vars = c("ImageNumber", "ObjectNumber"),variable.factor = F)
cells_long2 = melt.data.table(cells2,id.vars = c("ImageNumber", "ObjectNumber"),variable.factor = F)

# create unique ID with Image and ObjectNumber
cells_long1[,id := paste(ImageNumber,ObjectNumber,sep ="_")]
cells_long2[,id := paste(ImageNumber,ObjectNumber,sep ="_")]

# multiply value by 2E16 since it divided by this number in CellProfiler
cells_long1$value = cells_long1$value * 65535
cells_long2$value = cells_long2$value * 65535

# calculate counts_asinh
cells_long1[,':=' (channel = as.integer(getInfoFromFileList(variable,sep="_",strPos = 4,censorStr = "c")),
                 counts_asinh = asinh(value/1)),
                 by=id]
cells_long2[,':=' (channel = as.integer(getInfoFromFileList(variable,sep="_",strPos = 4,censorStr = "c")),
                 counts_asinh = asinh(value/1)),
                 by=id]

# take only FullStack entries and not FullStackFiltered
cells_long1[,measurement:=getInfoFromString(variable,"_",3),by=variable]
cells_long1[,signal_type:=getInfoFromString(variable,"_",2),by=variable]
cells_long2[,measurement:=getInfoFromString(variable,"_",3),by=variable]
cells_long2[,signal_type:=getInfoFromString(variable,"_",2),by=variable]

unique(cells_long1$signal_type)
[1] "MeanIntensityCorrectedLS" "MeanIntensityCorrected"  
[3] "MeanIntensity"           
unique(cells_long2$signal_type)
[1] "MeanIntensityCorrectedLS" "MeanIntensityCorrected"  
[3] "MeanIntensity"           

Merge meta data with cells data

cells1 = merge(cells_long1, meta1,by="ImageNumber")
cells2 = merge(cells_long2, meta2,by="ImageNumber")

cells = rbind(cells1, cells2)

Exclude DNA, Histone and panCytokeratin data and then get the info of PPIB staining

# exclude some channels, make sure to exclude the right ones!
cells_panel = merge(cells,panel[,.(channel,Target, `Metal Tag`, `Metal Number`)],by="channel")
cells_panel = cells_panel[Target %in% c("T1","T2","T3","T4","T5","T6","T7","T8","T9","T10","T11","T12"),]
cells_panel = cells_panel[measurement != "FullStack",]
cells_panel = cells_panel[signal_type != "MeanIntensityCorrectedLS",]
unique(cells_panel$signal_type)
[1] "MeanIntensityCorrected" "MeanIntensity"         
cells_panel_LScorrected = cells_panel[cells_panel$signal_type == "MeanIntensityCorrectedLS",]
cells_panel_uncorrected = cells_panel[cells_panel$signal_type == "MeanIntensity",]
cells_panel_corrected = cells_panel[cells_panel$signal_type == "MeanIntensityCorrected",]

Supp Figure 1E

Unspecific Amplifier Binding

results = matrix(nrow=12, ncol = 12)
rownames(results) = unique(cells_panel$Target)
colnames(results) = unique(cells_panel$Target)
results = as.data.frame(results)

cells_panel_corrected = as.data.frame(cells_panel_corrected)

# calculate percentage of unspecific binding
for(i in unique(cells_panel$Target)){
  mean_target = mean(cells_panel_corrected[cells_panel_corrected["Metadata_Target"] == i & cells_panel_corrected["Target"] == i, "value"])
  for(j in unique(cells_panel$Target)){
    row_index = which(rownames(results) %in% i)
    col_index = which(colnames(results) %in% j)
    results[row_index, col_index] = mean(cells_panel_corrected[cells_panel_corrected["Metadata_Target"] == j & cells_panel_corrected["Target"] == i, "value"]) / mean_target * 100
  }
}

# set crosstalk to 0 from one channel to same channel
results[results == 100] <- 0

a = Heatmap(as.matrix(results),
        col = colorRamp2(c(0,1,3), c("white","blue", "red")),
        row_order = order(as.numeric(gsub("T", "", unique(cells_panel_corrected$Target)))),
        column_order =  order(as.numeric(gsub("T", "", unique(cells_panel_corrected$Target)))),
        heatmap_legend_param = list(title = "% cross-talk", size =15),
        column_names_side = "top",
        column_title = "Stained Channel",
        row_title = "Other Channels",
        row_names_side = "left",
        column_names_rot = 0,
        column_names_gp = gpar(fontsize = 15),
        row_names_gp = gpar(fontsize = 15),
        column_names_centered = T,
        cell_fun = function(j, i, x, y, width, height, fill) {
        grid.text(sprintf("%.1f", as.matrix(results)[i, j]), x, y, gp = gpar(fontsize = 10))
})
draw(a)

Supp Figure 1D

Boxplot with uncorrected and corrected signal

cells_panel2 <- cells_panel
cells_panel2[cells_panel2$signal_type == "MeanIntensity", ]$signal_type = "uncorrected"
cells_panel2[cells_panel2$signal_type == "MeanIntensityCorrected", ]$signal_type = "spill-over corrected"

ggplot(cells_panel2[cells_panel2$Metadata_Target == "T9",], aes(x=`Metal Tag`, y=counts_asinh, fill=signal_type)) +
  geom_boxplot(outlier.shape = NA, lwd=0.5) +
  theme_bw() +
  theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1),
        text = element_text(size=18)) +
  guides(fill=guide_legend(title="Signal")) +
  ylab("Mean Count (asinh)") +
  xlab("") +
  facet_wrap(~Metadata_Target,labeller = as_labeller(c(T9 = "mRNA probe for Channel 9 (Er168)")))

Remove previous data

rm(list = ls())

# Reload 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                                 

Load the data

cells1 = fread("data/12plex_validation/HeLa/20190208/cell.csv", header = T,sep=",")
cells3 = fread("data/12plex_validation/HeLa/20190215/cell.csv", header = T,sep=",")
cells4 = fread("data/12plex_validation/HeLa/20190222/cell.csv", header = T,sep=",")

meta1 = fread("data/12plex_validation/HeLa/20190208/Image.csv",header = T,sep=",")
meta3 = fread("data/12plex_validation/HeLa/20190215/Image.csv",header = T,sep=",")
meta4 = fread("data/12plex_validation/HeLa/20190222/Image.csv",header = T,sep=",")

meta1 = meta1[,.(ImageNumber,FileName_CellImage)]
meta3 = meta3[,.(ImageNumber,FileName_CellImage)]
meta4 = meta4[,.(ImageNumber,FileName_CellImage)]

meta1[,':=' (replicate = getInfoFromString(FileName_CellImage,"_",1),stain = getInfoFromString(FileName_CellImage,"_",6), 
             secondary_stain = getInfoFromString(FileName_CellImage,"_",7)),by=ImageNumber]
meta3[,':=' (replicate = getInfoFromString(FileName_CellImage,"_",1),stain = getInfoFromString(FileName_CellImage,"_",6), 
             secondary_stain = getInfoFromString(FileName_CellImage,"_",7)),by=ImageNumber]
meta4[,':=' (replicate = getInfoFromString(FileName_CellImage,"_",1),stain = getInfoFromString(FileName_CellImage,"_",7), 
             secondary_stain = getInfoFromString(FileName_CellImage,"_",8), 
             another_stain = getInfoFromString(FileName_CellImage,"_",6)),by=ImageNumber]

# rename positive stain 
meta1[meta1$stain=="positive" & meta1$secondary_stain == "noAb",]$stain = "positive without Ab"
meta1[meta1$stain=="positive" & meta1$secondary_stain == "withAb",]$stain = "positive with Ab"
#meta2[meta2$stain=="positive" & meta2$secondary_stain == "noAb",]$stain = "positive without Ab"
#meta2[meta2$stain=="positive" & meta2$secondary_stain == "withAb",]$stain = "positive with Ab"
meta3[meta3$stain=="positive" & meta3$secondary_stain == "noAb",]$stain = "positive without Ab"
meta3[meta3$stain=="positive" & meta3$secondary_stain == "withAb",]$stain = "positive with Ab"
meta3[meta3$stain=="negative" & meta3$secondary_stain == "s0",]$stain = "negative 1st"
meta3[meta3$stain=="negative" & meta3$secondary_stain == "new",]$stain = "negative"
meta4[meta4$stain=="noAb",]$stain = "positive without Ab"
meta4[meta4$stain=="withAb",]$stain = "positive with Ab"
meta4[meta4$another_stain=="negative",]$stain = "negative"
meta4[meta4$another_stain=="T12",]$stain = "T12"

# change stain name
meta3[meta3$stain=="T7new",]$stain = "T7"
meta3[meta3$stain=="T5new",]$stain = "T5"
meta3[meta3$stain=="T11new",]$stain = "T11"
meta3[meta3$replicate =="20190221",]$replicate = "20190215"

panel = fread( "data/12plex_validation/HeLa/20190212_HeLa_12plex_validation.csv")

# sort Metal Number in same order than in the Image.csv file!!
panel$`Metal Number` = str_extract(panel$`Metal Tag`, "[0-9]+")
panel = panel[order(panel$`Metal Number`),]
panel$channel = c(1:nrow(panel))

# melt table
cells1_long = melt.data.table(cells1,id.vars = c("ImageNumber", "ObjectNumber"),variable.factor = F)
cells3_long = melt.data.table(cells3,id.vars = c("ImageNumber", "ObjectNumber"),variable.factor = F)
cells4_long = melt.data.table(cells4,id.vars = c("ImageNumber", "ObjectNumber"),variable.factor = F)

# multiply value by 2E16 since it divided by this number in CellProfiler
cells1_long$value = cells1_long$value * 65535
cells3_long$value = cells3_long$value * 65535
cells4_long$value = cells4_long$value * 65535

cells1_long[,id := paste(ImageNumber,ObjectNumber,sep ="_")]
cells1_long[,':=' (channel = as.integer(getInfoFromFileList(variable,sep="_",strPos = 4,censorStr = "c")),
                 counts_asinh = asinh(value/1)),
                 by=id]

cells3_long[,id := paste(ImageNumber,ObjectNumber,sep ="_")]
cells3_long[,':=' (channel = as.integer(getInfoFromFileList(variable,sep="_",strPos = 4,censorStr = "c")),
                 counts_asinh = asinh(value/1)),
                 by=id]

cells4_long[,id := paste(ImageNumber,ObjectNumber,sep ="_")]
cells4_long[,':=' (channel = as.integer(getInfoFromFileList(variable,sep="_",strPos = 4,censorStr = "c")),
                 counts_asinh = asinh(value/1)),
                 by=id]

# take only FullStack entries and not FullStackFiltered (not possible with RNA measurement, only with Ab's)
cells1_long[,measurement:=getInfoFromString(variable,"_",3),by=variable]
cells3_long[,measurement:=getInfoFromString(variable,"_",3),by=variable]
cells4_long[,measurement:=getInfoFromString(variable,"_",3),by=variable]

cells1_long = cells1_long[measurement=="FullStack",]
cells3_long = cells3_long[measurement=="FullStack",]
cells4_long = cells4_long[measurement=="FullStack",]

Merge meta dat with cells data and then then merge all the files to have one file with all three replicates

cells1_long = merge(cells1_long,meta1,by="ImageNumber")
cells3_long = merge(cells3_long,meta3,by="ImageNumber")
cells4_long = merge(cells4_long,meta4,by="ImageNumber")

# select only 1 negative measuremenet in 3th measurement
cells3_long = cells3_long[cells3_long$stain != "negative 1st", ]

# remove additional columns which are not needed
cells1_long = cells1_long[,!("secondary_stain")]
cells3_long = cells3_long[,!("secondary_stain")]
cells4_long = cells4_long[,!("secondary_stain")]
cells4_long = cells4_long[,!("another_stain")]


cells = rbind(cells1_long, cells3_long)
cells = rbind(cells, cells4_long)

Merge cells and panel data and exclude non-relevant channels

# exclude certain channels, make sure to exclude the right ones!
cells_panel <- merge(cells,panel[,.(channel,Target)],by="channel")
cells_panel <- cells_panel[Target %in% c("T1","T2","T3","T4","T5","T6","T7","T8","T9","T10","T11","T12"),]

Load data frolm 8plex validation and make it comparable

# import data from 8plex validation
cells_panel_8plex = readRDS(file = "data/12plex_validation/HeLa/2018_data_8plex_validation_DS.rds")

# make both data.frames same so they can be merged
cells_panel = cells_panel[, !("measurement")]
cells_panel_8plex = cells_panel_8plex[, !("AreaShape_Area")]

# rename the stains in the 8plex data
unique(cells_panel_8plex$stain)
 [1] "C1"     "C2"     "C3"     "C4"     "C5"     "C6"     "C7"     "C8"    
 [9] "all"    "oldMix" "neg"   
cells_panel_8plex = cells_panel_8plex[!(stain %in% ("oldMix")), ]
cells_panel_8plex[stain == "C1", ]$stain = "T1"
cells_panel_8plex[stain == "C2", ]$stain = "T4"
cells_panel_8plex[stain == "C3", ]$stain = "T3"
cells_panel_8plex[stain == "C4", ]$stain = "T8"
cells_panel_8plex[stain == "C5", ]$stain = "T12"
cells_panel_8plex[stain == "C6", ]$stain = "T2"
cells_panel_8plex[stain == "C7", ]$stain = "T9"
cells_panel_8plex[stain == "C8", ]$stain = "T6"
cells_panel_8plex[stain == "all", ]$stain = "positive with Ab"
cells_panel_8plex[stain == "neg", ]$stain = "negative"
cells_panel_8plex[Target == "C1", ]$Target = "T1"
cells_panel_8plex[Target == "C2", ]$Target = "T4"
cells_panel_8plex[Target == "C3", ]$Target = "T3"
cells_panel_8plex[Target == "C4", ]$Target = "T8"
cells_panel_8plex[Target == "C5", ]$Target = "T12"
cells_panel_8plex[Target == "C6", ]$Target = "T2"
cells_panel_8plex[Target == "C7", ]$Target = "T9"
cells_panel_8plex[Target == "C8", ]$Target = "T6"

# check
unique(cells_panel_8plex$stain)
 [1] "T1"               "T4"               "T3"               "T8"              
 [5] "T12"              "T2"               "T9"               "T6"              
 [9] "positive with Ab" "negative"        
unique(cells_panel_8plex$Target)
[1] "T1"  "T4"  "T3"  "T8"  "T12" "T2"  "T9"  "T6" 
all(colnames(cells_panel) == colnames(cells_panel_8plex))
[1] TRUE
# merge both files
cells_panel_12plex = rbind(cells_panel, cells_panel_8plex)

Supp Figure 1A

Throw out the DNA, histone and panCytokeratin data and then get the info of PPIB staining

# subset
cells_panel_12plex_sub = cells_panel_12plex[stain == Target,]

# relevel factor
cells_panel_12plex_sub$Target <- factor(cells_panel_12plex_sub$Target, levels = c("T1","T2","T3","T4","T5","T6","T7","T8","T9","T10","T11","T12"))

# check out difference in signal intensity for PPIB in the different channels
ggplot(data = cells_panel_12plex_sub[Target %in%c("T1","T2","T3","T4","T5","T6","T7","T8","T9","T10","T11","T12"),], aes(x=as.factor(Target),y=counts_asinh)) +
  geom_boxplot(fill="deepskyblue1")+
  theme_minimal()+
  theme(text = element_text(size=25), axis.text.x = element_text(angle = 90, hjust = 1)) +
  ylab("Mean Intensity Count per Cell [asinh]") + 
  xlab("Target Channels") + 
  geom_hline(yintercept = mean(cells_panel_12plex_sub$counts_asinh), linetype = 2) +
  scale_x_discrete(breaks=c("T1", "T2", "T3","T4","T5","T6","T7","T8", "T9", "T10","T11", "T12"),
                      labels= c("T1 PPIB","T2 PPIB","T3 PPIB", "T4 PPIB", "T5 PPIB","T6 PPIB","T7 PPIB","T8 PPIB","T9 PPIB","T10 PPIB", "T11 PPIB", "T12 PPIB")) 

Signal range

cells_panel_12plex_sub %>%
  group_by(stain) %>%
  summarize(mean_per_channel = mean(counts_asinh)) %>%
  mutate(sd = sd(mean_per_channel), mean = mean(mean_per_channel), min = min(mean_per_channel), max = max(mean_per_channel))
`summarise()` ungrouping output (override with `.groups` argument)
# A tibble: 12 x 6
   stain mean_per_channel    sd  mean   min   max
   <chr>            <dbl> <dbl> <dbl> <dbl> <dbl>
 1 T1                1.58 0.195  1.48  1.14  1.77
 2 T10               1.44 0.195  1.48  1.14  1.77
 3 T11               1.14 0.195  1.48  1.14  1.77
 4 T12               1.68 0.195  1.48  1.14  1.77
 5 T2                1.68 0.195  1.48  1.14  1.77
 6 T3                1.38 0.195  1.48  1.14  1.77
 7 T4                1.64 0.195  1.48  1.14  1.77
 8 T5                1.21 0.195  1.48  1.14  1.77
 9 T6                1.37 0.195  1.48  1.14  1.77
10 T7                1.77 0.195  1.48  1.14  1.77
11 T8                1.48 0.195  1.48  1.14  1.77
12 T9                1.39 0.195  1.48  1.14  1.77

Supp Figure 1C

Influence of Antibody Incubation

dd = cells_panel[stain == "positive without Ab" | stain == "positive with Ab",]

# relevel factor
dd$Target <- factor(dd$Target, levels = c("T1","T2","T3","T4","T5","T6","T7","T8","T9","T10","T11","T12"))
dd$stain <- ifelse(dd$stain == "positive with Ab", "+ Antibodies", "- Antibodies")

# plot
ggplot(data=dd, aes(x=Target, y=counts_asinh, fill = stain)) + 
  geom_boxplot() +
  scale_x_discrete(breaks=c("T1", "T2", "T3","T4","T5","T6","T7","T8", "T9", "T11","T10", "T12"),
                      labels= c("T1 POLR2A","T2 PPIB","T3 UBC", "T4 HPRT1", "T5 TUB","T6 RPL28","T7 RPL5","T8 B2M","T9 ACTB","T10 LDHA", "T11 RPLP0", "T12 GAPDH")) +
  theme_minimal()+
  theme(text = element_text(size=25), axis.text.x = element_text(angle = 90, hjust = 1)) + 
  ylab("Mean Intensity Count per Cell [asinh]") +
  xlab("Target Channels") + 
  scale_fill_discrete(name = "Protocol Type") 

Supp Figure 1B

Compare Positive Controls with RNAseq data

# add gene name
cells_panel_12plex$gene <- ""
cells_panel_12plex[cells_panel_12plex$Target == "T1",]$gene <- "POLR2A"
cells_panel_12plex[cells_panel_12plex$Target == "T2",]$gene <- "PPIB"
cells_panel_12plex[cells_panel_12plex$Target == "T3",]$gene <- "UBC"
cells_panel_12plex[cells_panel_12plex$Target == "T4",]$gene <- "HPRT1"
cells_panel_12plex[cells_panel_12plex$Target == "T5",]$gene <- "TUB"
cells_panel_12plex[cells_panel_12plex$Target == "T6",]$gene <- "RPL28"
cells_panel_12plex[cells_panel_12plex$Target == "T7",]$gene <- "RPL5"
cells_panel_12plex[cells_panel_12plex$Target == "T8",]$gene <- "B2M"
cells_panel_12plex[cells_panel_12plex$Target == "T9",]$gene <- "ACTB"
cells_panel_12plex[cells_panel_12plex$Target == "T10",]$gene <- "LDHA"
cells_panel_12plex[cells_panel_12plex$Target == "T11",]$gene <- "RPLP0"
cells_panel_12plex[cells_panel_12plex$Target == "T12",]$gene <- "GAPDH"

median_per_gene <- cells_panel_12plex %>%
  filter(stain == "positive with Ab") %>%
  filter(replicate %in% c("20190208", "20190215", "20190222")) %>%
  group_by(gene) %>%
  summarise(expression_RNAScope = median(counts_asinh))
`summarise()` ungrouping output (override with `.groups` argument)
# data from human protein atlas
rna_seq <- data.frame(median_per_gene$gene)
colnames(rna_seq) <- "gene"

# Normalized Expression Data from Human Protein Atlas 
rna_seq$expression_RNAseq <- c(145.3, 89.2, 217.1, 21.3, 74.9, 1.2, 54.7, 87.9, 83.6, 72.4, 23.9, 62.9)

# merge
sum <- left_join(median_per_gene, rna_seq)
Joining, by = "gene"
# plot 
ggplot(sum, aes(x=expression_RNAseq, y=expression_RNAScope, label=gene)) + 
  geom_label_repel(size=7, fill="deepskyblue1") + 
  geom_smooth(method = "lm") +
  xlab("Normalized Expression RNA-Seq") +
  ylab("Median Expression RNAScope [asinh]") + 
   stat_poly_eq(formula = y ~ x, 
                aes(label = ..rr.label..), 
                parse = TRUE, size=10) +
  theme_minimal() + 
  theme(text = element_text(size=20)) 
`geom_smooth()` using formula 'y ~ x'

Correlation

# correlation of the two technologies
cor(sum$expression_RNAScope, sum$expression_RNAseq, method = c("spearman"))
[1] 0.8391608

Supp Figure 1F

Load Data

sce_rna <- readRDS("data/sce_RNA.rds")

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_rna[which(grepl("T\\d+_",rownames(sce_rna)) & ! grepl("DapB",rownames(sce_rna))),])
chemokine_channels_sub <- c("T2_CCL22")

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

Plot Results from Chemokine Detection

# check difference between DapB and signal (histogram)
plot_list = list()
for(i in chemokine_channels_sub){
  
  # 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.5), ]

  a <- ggplot(data = diff_chemo_sub, aes(x=scaled_diff)) + 
  geom_histogram(binwidth = 0.05, aes(fill = 
                                       ifelse(padj <= 0.01 & scaled_diff > 0, 'p<0.01', 'n.s.'))) + 
  xlab(paste(paste("Scaled Difference ", i, sep = " "), " - DapB", sep = "")) + 
    xlim(-5,7) +
    theme_minimal() + 
    theme(text = element_text(size=20),
          legend.position = "none") + 
    scale_fill_manual(values = c("black", "deepskyblue1"))
  
  # significant cells defined by subtraction
  b <- ggplot(data=diff_chemo_sub, aes(x=mean_negative_control, y=mean_chemokine)) + 
    geom_point_rast(alpha=0.2, aes(col = 
                                ifelse(padj <= 0.01 & scaled_diff > 0, 'p<0.01', 'n.s.'))) + 
    scale_color_manual(values = c("black", "deepskyblue1"), 
                       name = "Legend") +
    guides(color = guide_legend(override.aes = list(alpha=1, size=3))) +
    xlim(0,5.5) + ylim(0,5.5) +
    ylab(paste("Mean expression of", i, sep=" ")) +
    xlab("Mean DapB mRNA expression") +
    theme_minimal() + 
    theme(text = element_text(size=20)) 

  
  grid.arrange(a,b, nrow = 1, ncol=2)
}
Warning: Removed 330 rows containing non-finite values (stat_bin).
Warning: Removed 4 rows containing missing values (geom_bar).
Warning: Removed 2 rows containing missing values (geom_point).

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] ggrastr_0.2.1               ggpmisc_0.3.7              
 [3] ggrepel_0.9.0               ggbeeswarm_0.6.0           
 [5] gridExtra_2.3               circlize_0.4.12            
 [7] ComplexHeatmap_2.4.3        ggpubr_0.4.0               
 [9] stringr_1.4.0               dplyr_1.0.2                
[11] ggplot2_3.3.3               data.table_1.13.6          
[13] SingleCellExperiment_1.12.0 SummarizedExperiment_1.20.0
[15] Biobase_2.50.0              GenomicRanges_1.42.0       
[17] GenomeInfoDb_1.26.2         IRanges_2.24.1             
[19] S4Vectors_0.28.1            BiocGenerics_0.36.0        
[21] MatrixGenerics_1.2.0        matrixStats_0.57.0         
[23] workflowr_1.6.2            

loaded via a namespace (and not attached):
 [1] nlme_3.1-151           bitops_1.0-6           fs_1.5.0              
 [4] RColorBrewer_1.1-2     rprojroot_2.0.2        tools_4.0.3           
 [7] backports_1.2.1        utf8_1.1.4             R6_2.5.0              
[10] vipor_0.4.5            mgcv_1.8-33            colorspace_2.0-0      
[13] GetoptLong_1.0.5       withr_2.3.0            tidyselect_1.1.0      
[16] curl_4.3               compiler_4.0.3         git2r_0.28.0          
[19] cli_2.2.0              Cairo_1.5-12.2         DelayedArray_0.16.0   
[22] labeling_0.4.2         scales_1.1.1           digest_0.6.27         
[25] foreign_0.8-81         rmarkdown_2.6          rio_0.5.16            
[28] XVector_0.30.0         pkgconfig_2.0.3        htmltools_0.5.0       
[31] rlang_0.4.10           GlobalOptions_0.1.2    readxl_1.3.1          
[34] rstudioapi_0.13        farver_2.0.3           shape_1.4.5           
[37] generics_0.1.0         zip_2.1.1              car_3.0-10            
[40] RCurl_1.98-1.2         magrittr_2.0.1         polynom_1.4-0         
[43] GenomeInfoDbData_1.2.4 Matrix_1.3-2           fansi_0.4.1           
[46] Rcpp_1.0.5             munsell_0.5.0          abind_1.4-5           
[49] lifecycle_0.2.0        stringi_1.5.3          whisker_0.4           
[52] yaml_2.2.1             carData_3.0-4          zlibbioc_1.36.0       
[55] promises_1.1.1         forcats_0.5.0          crayon_1.3.4          
[58] lattice_0.20-41        splines_4.0.3          haven_2.3.1           
[61] hms_0.5.3              knitr_1.30             pillar_1.4.7          
[64] rjson_0.2.20           ggsignif_0.6.0         glue_1.4.2            
[67] evaluate_0.14          vctrs_0.3.6            png_0.1-7             
[70] httpuv_1.5.4           cellranger_1.1.0       gtable_0.3.0          
[73] purrr_0.3.4            tidyr_1.1.2            assertthat_0.2.1      
[76] clue_0.3-58            xfun_0.20              openxlsx_4.2.3        
[79] broom_0.7.3            rstatix_0.6.0          later_1.1.0.1         
[82] tibble_3.0.4           beeswarm_0.2.3         cluster_2.1.0         
[85] ellipsis_0.3.1