Last updated: 2021-02-11

Checks: 6 1

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.


The R Markdown file has unstaged changes. To know which version of the R Markdown file created these results, you’ll want to first commit it to the Git repo. If you’re still working on the analysis, you can ignore this warning. When you’re finished, you can run wflow_publish to commit the R Markdown file and build the HTML.

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:    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

Untracked files:
    Untracked:  analysis/00_prepare_clinical_dat.rmd
    Untracked:  code/helper_functions/findMilieu.R
    Untracked:  code/helper_functions/findPatch.R

Unstaged changes:
    Modified:   .gitignore
    Modified:   analysis/01_Protein_read_data.rmd
    Modified:   analysis/01_RNA_read_data.rmd
    Modified:   analysis/02_Protein_annotations.rmd
    Modified:   analysis/02_RNA_annotations.rmd
    Modified:   analysis/03_Protein_quality_control.rmd
    Modified:   analysis/03_RNA_quality_control.rmd
    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/05_RNA_chemokine_expressing_cells.rmd
    Modified:   analysis/06_RNA_chemokine_patch_detection.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/Summary_Statistics.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
    Modified:   analysis/XX_hazard_ratio.rmd
    Deleted:    code/findPackages.R
    Deleted:    code/helper_functions/findClusters.R
    Deleted:    code/helper_functions/findCommunity.R
    Deleted:    code/helper_functions/getCellCount.R
    Deleted:    code/helper_functions/plotBarFracCluster.R
    Deleted:    code/helper_functions/plotCellFrac.R
    Deleted:    code/helper_functions/plotCellFracGroups.R
    Deleted:    code/helper_functions/plotCellFracGroupsSubset.R
    Deleted:    code/helper_functions/scatter_function.R
    Modified:   code/helper_functions/validityChecks.R
    Deleted:    data/mask_comparison/20190809_ZTMA256.1_slide2_TH_s1_p1_r15_a15_ac_full.tiff
    Deleted:    data/mask_comparison/20190809_ZTMA256.1_slide2_TH_s1_p1_r15_a15_ac_ilastik_s2_Probabilities_equalized_cellmask.tiff
    Deleted:    data/mask_comparison/20191023_ZTMA256.1_slide3_TH_s0_p10_r4_a4_ac_full.tiff
    Deleted:    data/mask_comparison/20191023_ZTMA256.1_slide3_TH_s0_p10_r4_a4_ac_ilastik_s2_Probabilities_equalized_cellmask.tiff

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/01_RNA_read_data.rmd) and HTML (docs/01_RNA_read_data.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 2e443a5 toobiwankenobi 2021-02-09 remove files that are not needed
html 3f5af3f toobiwankenobi 2021-02-09 add .html files
Rmd cf46cfa toobiwankenobi 2020-07-28 create files

Preparations

This file will load the single-cell data and store it in an SingleCellExperiment data container. In order to successfully run this script, several .csv files have to provided in the data folder of this repository.

Load Libraries

library(data.table)
library(SingleCellExperiment)

Load data (DOWNLOAD DATA SET AND STORE FILES IN CORRESPONDING FOLDER WITH CORRECT NAMING)

# load cell data
cells <- data.frame(fread(file = "data/data_for_analysis/rna/cell.csv",stringsAsFactors = FALSE))

# load image metadata as output from CellProfiler
image_mat <- read.csv(file = "data/data_for_analysis/rna/Image.csv", stringsAsFactors = FALSE)

# load panel information as exported from AirLab and modified to contain ilastik and full columns and nicely written Target names.
panel_mat <- read.csv(file = "data/data_for_analysis/rna/panel_mat.csv", stringsAsFactors = FALSE )

# load the channel order information. this information is created from the jupyter notebook in the tiffs folder for every single tiff that is created. 
# since it is the same panel for all images we just select one single file. the order or the metals in this file is the actual channels order.
tags <- read.csv( "data/data_for_analysis/rna/20190731_ZTMA256.1_slide2_TH_s1_p14_r1_a1_ac_full.csv", header = FALSE)

# load clinical data and TMA data to link images with patients
clinical_mat <- read.csv(file = "data/data_for_analysis/rna/clinical_data_RNA.csv",stringsAsFactors = FALSE)

Pre-processing

Generate the counts data frame

cur_counts <- cells[,grepl("Intensity_MeanIntensityCorrected_FullStackFiltered",colnames(cells))]

Get the scaling factor

the single cell data needs to be multiplied with the scaling factor (16 bit)

cur_counts <- cur_counts * image_mat$Scaling_FullStack[1]

# order the channels according to channel number
channelNumber <- as.numeric(sub("^.*_c", "", colnames(cur_counts)))
cur_counts <- cur_counts[,order(channelNumber,decreasing = FALSE)]

Get the information whether a cell is in the tumor mask

any cell that has more than 25 % of its Area in the tumor mask is considered as “TRUE” meaning inside the tumor.

tumor_mask <- cells$Intensity_MeanIntensity_tumormask * image_mat$Scaling_FullStack[1]
in_tumor <- tumor_mask > 0.25

Prepare the cell level metadata (colData)

cell_meta <- DataFrame(CellNumber = cells$ObjectNumber,
                       ImageNumber = cells$ImageNumber,
                       Center_X = cells$Location_Center_X,
                       Center_Y = cells$Location_Center_Y,
                       Area = cells$AreaShape_Area,
                       MajorAxisLength = cells$AreaShape_MajorAxisLength,
                       MinorAxisLength = cells$AreaShape_MinorAxisLength,
                       NumberOfNeighbors = cells$Neighbors_NumberOfNeighbors_8,
                       in_tumor = in_tumor)

# add a unique cellID to each cell consisting of "dataset"+"ImageNumber"+"ObjectNumber"
cell_meta$cellID <- paste0("RNA_",cell_meta$ImageNumber, "_",cell_meta$CellNumber)
rownames(cell_meta) <- cell_meta$cellID

# order according to ImageNumber
cell_meta <- cell_meta[order(cell_meta$ImageNumber),]

Prepare the row-level metadata (panel/marker information)

here we prepare all the metadata for the rows in the single cell experiment object (rowData)

# the channel numbers are the rownumbers in the "tags" file that we create above
tags$channel <- as.numeric(rownames(tags))
colnames(tags) <- c("Metal.Tag","channel")

# include the channel information in the panel metadata (panel_mat)
panel_mat <- merge(panel_mat,tags,by="Metal.Tag")

# now we order the panel metadata by channel. therefore we first modify the column names
panel_mat <- panel_mat[order(panel_mat$channel,decreasing = FALSE),]

# rename CD8a -> CD8 in Targets
panel_mat$Target[26] <- "CD8"

# assign rownames
rownames(panel_mat) <- panel_mat$Target

Create SCE object

Create the single cell experiment object

# create the SCE object
sce <- SingleCellExperiment(assays = list(counts = t(cur_counts)))

# Set marker name as rownames and cellID as colnames
rownames(sce) <- rownames(panel_mat)
colnames(sce) <- rownames(cell_meta)

# add the column and row metadata
colData(sce) <- cell_meta
rowData(sce) <- panel_mat

# we also generate here the generically implemented "logcounts" as asinh transformed counts
assay(sce, "asinh") <- asinh(SingleCellExperiment::counts(sce))

Assign the clinical data to the metadata slot

# order according to ImageNumber
clinical_mat <- clinical_mat[order(clinical_mat$ImageNumber),]
metadata(sce) <- as.list(clinical_mat)

Save the SCE object

saveRDS(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] parallel  stats4    stats     graphics  grDevices utils     datasets 
[8] methods   base     

other attached packages:
 [1] SingleCellExperiment_1.12.0 SummarizedExperiment_1.20.0
 [3] Biobase_2.50.0              GenomicRanges_1.42.0       
 [5] GenomeInfoDb_1.26.2         IRanges_2.24.1             
 [7] S4Vectors_0.28.1            BiocGenerics_0.36.0        
 [9] MatrixGenerics_1.2.0        matrixStats_0.57.0         
[11] data.table_1.13.6           workflowr_1.6.2            

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.5             XVector_0.30.0         pillar_1.4.7          
 [4] compiler_4.0.3         later_1.1.0.1          git2r_0.28.0          
 [7] zlibbioc_1.36.0        bitops_1.0-6           tools_4.0.3           
[10] digest_0.6.27          lattice_0.20-41        evaluate_0.14         
[13] lifecycle_0.2.0        tibble_3.0.4           pkgconfig_2.0.3       
[16] rlang_0.4.10           Matrix_1.3-2           DelayedArray_0.16.0   
[19] rstudioapi_0.13        yaml_2.2.1             xfun_0.20             
[22] GenomeInfoDbData_1.2.4 stringr_1.4.0          knitr_1.30            
[25] fs_1.5.0               vctrs_0.3.6            grid_4.0.3            
[28] rprojroot_2.0.2        glue_1.4.2             R6_2.5.0              
[31] rmarkdown_2.6          magrittr_2.0.1         whisker_0.4           
[34] promises_1.1.1         ellipsis_0.3.1         htmltools_0.5.0       
[37] httpuv_1.5.4           stringi_1.5.3          RCurl_1.98-1.2        
[40] crayon_1.3.4