Last updated: 2021-09-17
Checks: 7 0
Knit directory: Multispectral HCC/
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(20210728)
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 201876f. 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: analysis/.DS_Store
Ignored: analysis/figure/
Ignored: code/
Ignored: data/
Ignored: old/
Ignored: output/
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/cores.Rmd
) and HTML (docs/cores.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 | 201876f | Jovan Tanevski | 2021-09-17 | work with normalized data for profiles and de |
Rmd | b67241d | Jovan Tanevski | 2021-09-17 | switch to snmf/r and lower rank |
html | c85e3e6 | Jovan Tanevski | 2021-09-17 | Build site. |
Rmd | 825c1f2 | Jovan Tanevski | 2021-09-17 | pilot run on 1% of hepatocytes from tumor cores |
html | e7709fe | Jovan Tanevski | 2021-08-03 | Build site. |
Rmd | 421cbc4 | Jovan Tanevski | 2021-08-03 | add cores analysis placeholder |
library(tidyverse)
library(skimr)
library(uwot)
library(limma)
library(NMF)
library(factoextra)
library(cowplot)
tumor.hc <- read_csv("data/tumor_hepatocytes.csv", col_types = cols()) %>%
select(
`Cytoplasm AGS (Opal 690) Mean (Normalized Counts, Total Weighting)`,
`Cytoplasm BerEP4 (Opal 650) Mean (Normalized Counts, Total Weighting)`,
`Cytoplasm CRP (Opal 540) Mean (Normalized Counts, Total Weighting)`,
`Nucleus p-S6 (Opal 570) Mean (Normalized Counts, Total Weighting)`,
`Nucleus beta-cat. (Opal 520) Mean (Normalized Counts, Total Weighting)`
) %>% `colnames<-`(str_split(colnames(.)," ") %>% map_chr(~.x[2]) %>% make.names)
skim(tumor.hc)
Name | tumor.hc |
Number of rows | 223846 |
Number of columns | 5 |
_______________________ | |
Column type frequency: | |
numeric | 5 |
________________________ | |
Group variables | None |
Variable type: numeric
skim_variable | n_missing | complete_rate | mean | sd | p0 | p25 | p50 | p75 | p100 | hist |
---|---|---|---|---|---|---|---|---|---|---|
AGS | 0 | 1 | 0.27 | 0.41 | 0 | 0.07 | 0.12 | 0.25 | 5.23 | ▇▁▁▁▁ |
BerEP4 | 0 | 1 | 1.09 | 2.19 | 0 | 0.21 | 0.32 | 0.58 | 24.08 | ▇▁▁▁▁ |
CRP | 0 | 1 | 2.51 | 3.08 | 0 | 0.55 | 1.00 | 3.50 | 35.80 | ▇▁▁▁▁ |
p.S6 | 0 | 1 | 1.31 | 1.25 | 0 | 0.58 | 0.94 | 1.61 | 35.24 | ▇▁▁▁▁ |
beta.cat. | 0 | 1 | 0.06 | 0.14 | 0 | 0.00 | 0.00 | 0.05 | 4.04 | ▇▁▁▁▁ |
Detect outliers based on Tukey’s interquartile approach and winsorize. Follow by quantile normalization and ranking to get rid of the effect of abundance
quartiles <-apply(tumor.hc, 2, \(x) quantile(x, c(.25,.75)))
lower <- quartiles[1,] - 1.5*(quartiles[2,] - quartiles[1,])
upper <- quartiles[2,] + 1.5*(quartiles[2,] - quartiles[1,])
tumor.hc.winsorized <- tumor.hc %>% imap_dfc(\(x,y){
x[x<lower[y]] <- x[which.min(x - lower[y])]
x[x>upper[y]] <- x[which.min(x - upper[y])]
x
})
skim(tumor.hc.winsorized)
Name | tumor.hc.winsorized |
Number of rows | 223846 |
Number of columns | 5 |
_______________________ | |
Column type frequency: | |
numeric | 5 |
________________________ | |
Group variables | None |
Variable type: numeric
skim_variable | n_missing | complete_rate | mean | sd | p0 | p25 | p50 | p75 | p100 | hist |
---|---|---|---|---|---|---|---|---|---|---|
AGS | 0 | 1 | 0.12 | 0.11 | 0 | 0.05 | 0.10 | 0.17 | 0.52 | ▇▃▂▁▁ |
BerEP4 | 0 | 1 | 0.29 | 0.22 | 0 | 0.14 | 0.25 | 0.39 | 1.15 | ▇▆▂▁▁ |
CRP | 0 | 1 | 1.67 | 1.93 | 0 | 0.45 | 0.82 | 2.12 | 7.93 | ▇▁▁▁▁ |
p.S6 | 0 | 1 | 1.01 | 0.71 | 0 | 0.50 | 0.83 | 1.38 | 3.16 | ▇▇▃▂▁ |
beta.cat. | 0 | 1 | 0.01 | 0.03 | 0 | 0.00 | 0.00 | 0.00 | 0.13 | ▇▁▁▁▁ |
tumor.hc.norm <- normalizeQuantiles(data.frame(tumor.hc.winsorized))
skim(tumor.hc.norm)
Name | tumor.hc.norm |
Number of rows | 223846 |
Number of columns | 5 |
_______________________ | |
Column type frequency: | |
numeric | 5 |
________________________ | |
Group variables | None |
Variable type: numeric
skim_variable | n_missing | complete_rate | mean | sd | p0 | p25 | p50 | p75 | p100 | hist |
---|---|---|---|---|---|---|---|---|---|---|
AGS | 0 | 1 | 0.61 | 0.60 | 0.00 | 0.23 | 0.40 | 0.81 | 2.58 | ▇▂▁▁▁ |
BerEP4 | 0 | 1 | 0.62 | 0.60 | 0.03 | 0.23 | 0.40 | 0.81 | 2.58 | ▇▂▁▁▁ |
CRP | 0 | 1 | 0.62 | 0.59 | 0.00 | 0.23 | 0.40 | 0.81 | 2.58 | ▇▂▁▁▁ |
p.S6 | 0 | 1 | 0.62 | 0.59 | 0.00 | 0.23 | 0.40 | 0.81 | 2.58 | ▇▂▁▁▁ |
beta.cat. | 0 | 1 | 0.55 | 0.54 | 0.35 | 0.35 | 0.35 | 0.35 | 2.57 | ▇▁▁▁▁ |
tumor.hc.rank <- mutate_all(tumor.hc.winsorized, ~rank(., ties.method = "min"))
Pilot run. Subsample 1% of the original data.
set.seed(42)
subsamp <- sample(nrow(tumor.hc.rank), 0.01*nrow(tumor.hc.rank))
tumor.hc.pca <- prcomp(tumor.hc.norm[subsamp,])
summary(tumor.hc.pca)
Importance of components:
PC1 PC2 PC3 PC4 PC5
Standard deviation 0.6882 0.6099 0.5817 0.5112 0.4843
Proportion of Variance 0.2819 0.2214 0.2014 0.1556 0.1396
Cumulative Proportion 0.2819 0.5033 0.7048 0.8604 1.0000
tumor.hc.umap <- umap(tumor.hc.norm[subsamp, ], n_threads = 7)
We use an efficient implementation of alternating non negative least-squares with regularized to favor sparse coefficient matrices snmf/r. In this way we aim for cleaner clustering.
tumor.hc.nmf.rank <- nmfEstimateRank(as.matrix(t(tumor.hc.rank[subsamp,])),
range = seq(2,6), method = "snmf/r",
nrun = 10, seed = 42)
plot(tumor.hc.nmf.rank)
Warning: Removed 2 rows containing missing values (geom_point).
Version | Author | Date |
---|---|---|
c85e3e6 | Jovan Tanevski | 2021-09-17 |
tumor.hc.nmf <- nmf(as.matrix(t(tumor.hc.rank[subsamp,])),
rank = 3, method = "snmf/r",
nrun = 10, seed = 42)
Extract basis of NMF (signature of cluster)
basismap(tumor.hc.nmf)
Version | Author | Date |
---|---|---|
c85e3e6 | Jovan Tanevski | 2021-09-17 |
Extract coefficients of NMF (soft clustering of samples)
coefmap(tumor.hc.nmf)
Version | Author | Date |
---|---|---|
c85e3e6 | Jovan Tanevski | 2021-09-17 |
Assign clusters
nmf.clusters <- apply(tumor.hc.nmf@fit@H, 2, which.max)
Plot in 2D PCA and UMAP
fviz_pca_ind(tumor.hc.pca, geom = "point", col.ind = as.factor(nmf.clusters)) +
theme_classic()
tumor.hc.umap.clus <-
tumor.hc.umap %>%
cbind(nmf.clusters) %>%
`colnames<-`(c("U1", "U2", "Cluster")) %>%
as_tibble() %>%
mutate_at("Cluster", as.factor)
ggplot(tumor.hc.umap.clus, aes(x = U1, y = U2, color = Cluster)) +
geom_point() +
theme_classic()
Expression profiles per cluster
tumor.hc.clustered.nmf <- tumor.hc.norm[subsamp, ] %>%
mutate(Cluster = as.factor(nmf.clusters)) %>%
pivot_longer(names_to = "Marker", values_to = "Norm.value", -Cluster)
profiles <- seq_len(max(nmf.clusters)) %>% map(~
ggplot(
tumor.hc.clustered.nmf %>% filter(Cluster == .x),
aes(x = Marker, y = Norm.value, color = Marker)
) +
stat_summary(fun.data = mean_sdl, show.legend = FALSE) +
ylim(-3, 3) +
theme_classic() +
theme(axis.text.x = element_text(angle = 90, hjust = 1)))
plot_grid(plotlist = profiles, labels = paste("Cluster", seq_len(max(nmf.clusters))))
Version | Author | Date |
---|---|---|
c85e3e6 | Jovan Tanevski | 2021-09-17 |
Differential expression analysis (silhouette)
Calculate the similarity of samples using the expression and the silhouette scores based on the assigned clusters.
silhouette.nmf <- silhouette(nmf.clusters, dist(tumor.hc.norm[subsamp,]))
fviz_silhouette(silhouette.nmf)
cluster size ave.sil.width
1 1 834 0.21
2 2 276 0.21
3 3 1128 0.10
Version | Author | Date |
---|---|---|
c85e3e6 | Jovan Tanevski | 2021-09-17 |
Select only the samples with positive silhouette scores as “core samples”
core.samples <- which(silhouette.nmf[,3] > 0)
tumor.hc.core.samples <- tumor.hc.norm[subsamp,] %>% add_column(Cluster = nmf.clusters) %>%
slice(core.samples)
Calculate difference in means (mean(cluster) - mean(other)), one-vs-all t-test per marker and correct for FDR. Filter q <= 0.05
unique(tumor.hc.core.samples$Cluster) %>% map_dfr(\(c){
tumor.hc.core.samples %>%
summarize(across(-Cluster, ~t.test(.x ~ (Cluster==c))$p.value)) %>%
pivot_longer(names_to = "Marker", values_to = "p", everything()) %>%
mutate(Cluster = c, Difference = tumor.hc.core.samples %>%
group_by(Cluster == c) %>%
select(-Cluster) %>%
group_split(.keep = FALSE) %>% map(colMeans) %>% reduce(`-`))
}) %>%
mutate(q = p.adjust(p, method = "fdr"), Difference = -Difference) %>%
filter(q <= 0.05) %>% arrange(q)
Marker | p | Cluster | Difference | q |
---|---|---|---|---|
beta.cat. | 0 | 2 | 1.5812421 | 0 |
BerEP4 | 0 | 3 | -0.6642024 | 0 |
p.S6 | 0 | 1 | -0.5883269 | 0 |
p.S6 | 0 | 3 | 0.6729983 | 0 |
CRP | 0 | 1 | -0.4360204 | 0 |
CRP | 0 | 3 | 0.4639126 | 0 |
BerEP4 | 0 | 1 | 0.4870888 | 0 |
beta.cat. | 0 | 1 | -0.3628184 | 0 |
beta.cat. | 0 | 3 | -0.3783264 | 0 |
BerEP4 | 0 | 2 | 0.3956980 | 0 |
p.S6 | 0 | 2 | -0.2002105 | 0 |
sessionInfo()
R version 4.1.1 (2021-08-10)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Big Sur 10.16
Matrix products: default
BLAS: /Library/Frameworks/R.framework/Versions/4.1/Resources/lib/libRblas.0.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.1/Resources/lib/libRlapack.dylib
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] parallel stats graphics grDevices utils datasets methods
[8] base
other attached packages:
[1] RColorBrewer_1.1-2 doParallel_1.0.16 iterators_1.0.13
[4] foreach_1.5.1 cowplot_1.1.1 factoextra_1.0.7
[7] NMF_0.23.0 synchronicity_1.3.5 bigmemory_4.5.36
[10] Biobase_2.52.0 BiocGenerics_0.38.0 cluster_2.1.2
[13] rngtools_1.5 pkgmaker_0.32.2 registry_0.5-1
[16] limma_3.48.3 uwot_0.1.10 Matrix_1.3-4
[19] skimr_2.1.3 forcats_0.5.1 stringr_1.4.0
[22] dplyr_1.0.7 purrr_0.3.4 readr_2.0.1
[25] tidyr_1.1.3 tibble_3.1.4 ggplot2_3.3.5
[28] tidyverse_1.3.1 workflowr_1.6.2
loaded via a namespace (and not attached):
[1] bigmemory.sri_0.1.3 colorspace_2.0-2 ggsignif_0.6.3
[4] rio_0.5.27 ellipsis_0.3.2 rprojroot_2.0.2
[7] htmlTable_2.2.1 base64enc_0.1-3 fs_1.5.0
[10] rstudioapi_0.13 ggpubr_0.4.0 farver_2.1.0
[13] ggrepel_0.9.1 bit64_4.0.5 RSpectra_0.16-0
[16] fansi_0.5.0 lubridate_1.7.10 xml2_1.3.2
[19] splines_4.1.1 codetools_0.2-18 knitr_1.34
[22] Formula_1.2-4 jsonlite_1.7.2 broom_0.7.9
[25] gridBase_0.4-7 dbplyr_2.1.1 png_0.1-7
[28] compiler_4.1.1 httr_1.4.2 backports_1.2.1
[31] assertthat_0.2.1 fastmap_1.1.0 cli_3.0.1
[34] later_1.3.0 htmltools_0.5.2 tools_4.1.1
[37] gtable_0.3.0 glue_1.4.2 reshape2_1.4.4
[40] Rcpp_1.0.7 carData_3.0-4 cellranger_1.1.0
[43] jquerylib_0.1.4 vctrs_0.3.8 xfun_0.26
[46] openxlsx_4.2.4 rvest_1.0.1 lifecycle_1.0.0
[49] rstatix_0.7.0 scales_1.1.1 vroom_1.5.5
[52] hms_1.1.0 promises_1.2.0.1 curl_4.3.2
[55] yaml_2.2.1 gridExtra_2.3 sass_0.4.0
[58] rpart_4.1-15 latticeExtra_0.6-29 stringi_1.7.4
[61] highr_0.9 checkmate_2.0.0 zip_2.2.0
[64] repr_1.1.3 rlang_0.4.11 pkgconfig_2.0.3
[67] evaluate_0.14 lattice_0.20-44 htmlwidgets_1.5.4
[70] labeling_0.4.2 bit_4.0.4 tidyselect_1.1.1
[73] plyr_1.8.6 magrittr_2.0.1 R6_2.5.1
[76] Hmisc_4.5-0 generics_0.1.0 DBI_1.1.1
[79] foreign_0.8-81 pillar_1.6.2 haven_2.4.3
[82] whisker_0.4 withr_2.4.2 nnet_7.3-16
[85] survival_3.2-13 abind_1.4-5 car_3.0-11
[88] modelr_0.1.8 crayon_1.4.1 uuid_0.1-4
[91] utf8_1.2.2 tzdb_0.1.2 rmarkdown_2.11
[94] jpeg_0.1-9 grid_4.1.1 readxl_1.3.1
[97] data.table_1.14.0 FNN_1.1.3 git2r_0.28.0
[100] reprex_2.0.1 digest_0.6.27 xtable_1.8-4
[103] httpuv_1.6.3 munsell_0.5.0 bslib_0.3.0