Last updated: 2022-02-09
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 a2860df. 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: analysis/.DS_Store
Ignored: analysis/._.DS_Store
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: analysis/Figure_5.rmd
Modified: analysis/Supp-Figure_12.rmd
Modified: analysis/Supp-Figure_13.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/01_Protein_read_data.rmd
) and HTML (docs/01_Protein_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 |
---|---|---|---|---|
html | 4109ff1 | toobiwankenobi | 2021-07-07 | delete html files and adapt gitignore |
html | 3203891 | toobiwankenobi | 2021-02-19 | change celltype names |
Rmd | ee1595d | toobiwankenobi | 2021-02-12 | clean repo and adapt files |
html | ee1595d | toobiwankenobi | 2021-02-12 | clean repo and adapt files |
Rmd | 2e443a5 | toobiwankenobi | 2021-02-09 | remove files that are not needed |
html | 3f5af3f | toobiwankenobi | 2021-02-09 | add .html files |
Rmd | 2c11d5c | toobiwankenobi | 2020-08-05 | add new scripts |
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.
First, we will load the libraries needed for this part of the analysis.
library(data.table)
library(SingleCellExperiment)
# load the single cell data
cells <- as.data.frame(fread(file = "data/data_for_analysis/protein/cell.csv",stringsAsFactors = FALSE))
# load the image level metadata
image_mat <- as.data.frame(read.csv(file = "data/data_for_analysis/protein/Image.csv",stringsAsFactors = FALSE))
# load the panel information
panel_mat <- read.csv(file = "data/data_for_analysis/protein/melanoma_1.06_protein.csv", sep= ",", stringsAsFactors = FALSE )
# get an example file that contains the channel order
tags <- read.csv( "data/data_for_analysis/protein/20191021_ZTMA256.1_slide3_TH_s0_p9_r1_a1_ac_full.csv", header = FALSE)
# load acqusition meta data
acquisition_meta <- read.csv(file = "data/data_for_analysis/protein/acquisition_metadata.csv", stringsAsFactors = FALSE)
# load the clinical data. this is a clinical datatable that already contains the ImageNumbers. It has been prepared in the clinical metadata preparation.Rmd script (prepared for RNA and protein dataset separately)
clinical_mat <- read.csv("data/data_for_analysis/protein/clinical_data_protein.csv",stringsAsFactors = FALSE)
cur_counts <- cells[,grepl("Intensity_MeanIntensityCorrected_FullStackFiltered",colnames(cells))]
the single cell data needs to be multiplied with the scaling factor (16 bit)
cur_counts <- cur_counts * image_mat$Scaling_FullStack[1]
# to order the channels according to channel number
channelNumber <- as.numeric(sub("^.*_c", "", colnames(cur_counts)))
cur_counts <- cur_counts[,order(channelNumber,decreasing = FALSE)]
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
this data frame contains the metadata for ever single cell and will later on be the colData in the single cell experiment object
the metadata will also have an entry called “Parent_nuclei” which holds information to the ObjectNumber of the Nuclei that the cell was derived from. due to the down-scaling of the images some nuclei are lost and thus some cells do not have a Parent_nuclei
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,
Parent_nuclei = cells$Parent_nuclei,
in_tumor = in_tumor)
# add a unique cellID to each cell consisting of "dataset"+"ImageNumber"+"ObjectNumber"
cell_meta$cellID <- paste0("protein_",cell_meta$ImageNumber, "_",cell_meta$CellNumber)
rownames(cell_meta) <- cell_meta$cellID
# before we can add the clinical metadata to the cell_meta file we first have to make sure that the clinical metadata is also ordered according to the single cell data. In this case the reference for each single cell is the imagenubmer. so we need to order the clinical data by image number first.
clinical_mat <- clinical_mat[order(clinical_mat$ImageNumber),]
cell_meta <- cell_meta[order(cell_meta$ImageNumber),]
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),]
# we also revise the nomenclature of the clean targets to not contain special characters like "-" etc
panel_mat$clean_target
[1] "Vimentin" "Caveolin-1" "Histone H3" "SMA" "CD15"
[6] "H3K27me3" "CD7" "CXCR2" "HLA-DR" "S100"
[11] "CD19" "CD45RA" "Sox9" "TOX1" "CD20"
[16] "CD68" "pERK1/2" "CD3" "CD36" "p75"
[21] "PD-1" "MiTF" "CD11b" "Granzyme B" "PD-L1"
[26] "TCF1/7" "CD45RO" "FOXP3" "CD278/ICOS" "b-Catenin"
[31] "CD8a" "Collagen I" "Ki-67" "CD11c" "pS6"
[36] "CD4" "IDO1" "SOX10" "CD303" "CD206/MMR"
[41] "cleaved PARP" "DNA1" "DNA2" "Ki-67 Pt198" "CD45"
[46] "MPO"
clean_target <- c("Vimentin", "Caveolin1", "HistoneH3", "SMA","CD15", "H3K27me3", "CD7","CXCR2", "HLADR", "S100", "CD19", "CD45RA", "Sox9", "TOX1", "CD20", "CD68",
"pERK", "CD3", "CD36", "p75", "PD1", "MiTF", "CD11b", "GrzB", "PDL1", "TCF7", "CD45RO", "FOXP3", "ICOS", "bCatenin", "CD8", "Collagen1", "Ki67",
"CD11c", "pS6", "CD4", "IDO1", "SOX10", "CD303", "CD206", "PARP", "DNA1", "DNA2", "Ki67Pt198", "CD45", "MPO")
panel_mat$clean_target <- clean_target
rownames(panel_mat) <- panel_mat$clean_target
# 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
# asinh transformed counts as well as add the nuclear count data
assay(sce, "asinh") <- asinh(counts(sce))
# order according to ImageNumber
clinical_mat <- clinical_mat[order(clinical_mat$ImageNumber),]
metadata(sce) <- as.list(clinical_mat)
saveRDS(sce,file = "data/data_for_analysis/sce_protein.rds")
sessionInfo()
R version 4.1.2 (2021-11-01)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 20.04.3 LTS
Matrix products: default
BLAS/LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.8.so
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
[3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
[5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
[7] LC_PAPER=en_US.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats4 stats graphics grDevices utils datasets methods
[8] base
other attached packages:
[1] SingleCellExperiment_1.16.0 SummarizedExperiment_1.24.0
[3] Biobase_2.54.0 GenomicRanges_1.46.1
[5] GenomeInfoDb_1.30.1 IRanges_2.28.0
[7] S4Vectors_0.32.3 BiocGenerics_0.40.0
[9] MatrixGenerics_1.6.0 matrixStats_0.61.0
[11] data.table_1.14.2 workflowr_1.7.0
loaded via a namespace (and not attached):
[1] xfun_0.29 bslib_0.3.1 lattice_0.20-45
[4] vctrs_0.3.8 htmltools_0.5.2 yaml_2.2.2
[7] utf8_1.2.2 rlang_1.0.0 jquerylib_0.1.4
[10] later_1.3.0 pillar_1.7.0 glue_1.6.1
[13] GenomeInfoDbData_1.2.7 lifecycle_1.0.1 stringr_1.4.0
[16] zlibbioc_1.40.0 evaluate_0.14 knitr_1.37
[19] callr_3.7.0 fastmap_1.1.0 httpuv_1.6.5
[22] ps_1.6.0 fansi_1.0.2 Rcpp_1.0.8
[25] promises_1.2.0.1 DelayedArray_0.20.0 jsonlite_1.7.3
[28] XVector_0.34.0 fs_1.5.2 digest_0.6.29
[31] stringi_1.7.6 processx_3.5.2 getPass_0.2-2
[34] grid_4.1.2 rprojroot_2.0.2 cli_3.1.1
[37] tools_4.1.2 bitops_1.0-7 magrittr_2.0.2
[40] sass_0.4.0 RCurl_1.98-1.5 tibble_3.1.6
[43] crayon_1.4.2 whisker_0.4 pkgconfig_2.0.3
[46] Matrix_1.4-0 ellipsis_0.3.2 rmarkdown_2.11
[49] httr_1.4.2 rstudioapi_0.13 R6_2.5.1
[52] git2r_0.29.0 compiler_4.1.2