Last updated: 2025-07-11
Checks: 6 1
Knit directory:
single-cell-jamboree/analysis/
This reproducible R Markdown analysis was created with workflowr (version 1.7.1). 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(1)
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.
To ensure reproducibility of the results, delete the cache directory
pancreas_cytokine_lsa_clustering_cache
and re-run the
analysis. To have workflowr automatically delete the cache directory
prior to building the file, set delete_cache = TRUE
when
running wflow_build()
or wflow_publish()
.
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 17a796d. 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:
Untracked files:
Untracked: analysis/lps_cache/
Untracked: analysis/mcf7_cache/
Untracked: analysis/pancreas_cytokine_S1_factors_cache/
Untracked: analysis/pancreas_cytokine_lsa_clustering_cache/
Untracked: data/GSE132188_adata.h5ad.h5
Untracked: data/GSE156175_RAW/
Untracked: data/GSE183010/
Untracked: data/Immune_ALL_human.h5ad
Untracked: data/pancreas_cytokine.RData
Untracked: data/pancreas_cytokine_lsa.RData
Untracked: data/pancreas_endocrine.RData
Untracked: data/pancreas_endocrine_alldays.h5ad
Untracked: output/panc_cyto_lsa_res/
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/pancreas_cytokine_lsa_clustering.Rmd
) and HTML
(docs/pancreas_cytokine_lsa_clustering.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 | 17a796d | Peter Carbonetto | 2025-07-11 | wflow_publish("pancreas_cytokine_lsa_clustering.Rmd", verbose = T, |
Rmd | 6f9bee5 | Peter Carbonetto | 2025-07-11 | Added back the Seurat analysis to pancreas_cytokine_lsa_clustering.Rmd. |
Rmd | 9325970 | Peter Carbonetto | 2025-07-09 | A few edits to pancreas_cytokine_lsa_clustering.Rmd. |
Rmd | 746b8f3 | Peter Carbonetto | 2025-07-09 | A few small revisions to the pancreas_cytokine_lsa_clustering analysis. |
Rmd | 5ec605f | Peter Carbonetto | 2025-07-09 | A few more edits to the pancreas_cytokine_lsa_clustering analysis. |
Rmd | ac2f5f9 | Peter Carbonetto | 2025-07-09 | A few revisions/fixes to the pancreas_cytokine_lsa_clustering analysis. |
Rmd | 7af0ecd | Eric Weine | 2025-06-17 | added umap plot to clustering |
html | 7af0ecd | Eric Weine | 2025-06-17 | added umap plot to clustering |
Rmd | a7e6cd5 | Eric Weine | 2025-06-16 | added initial clustering of LSA pancreas cytokine paper |
html | a7e6cd5 | Eric Weine | 2025-06-16 | added initial clustering of LSA pancreas cytokine paper |
Here we will prepare the single-cell RNA-seq data from Stancill
et al 2021 for analysis with the topic model and other matrix
factorization methods. The data files were obtained by downloading and
the GSE156175_RAW.tar
file from GEO
accession GSE156175. To run this script, download this file from GEO
and extract the contents into a folder called “GSE156175_RAW” in the
data directory.
Load the R packages used to perform the data processing and initial analyses:
library(Matrix)
library(tools)
library(readr)
library(cowplot)
library(fastTopics)
library(dplyr)
library(Seurat)
Set the seed for reproducibility:
set.seed(1)
Import the sample information:
barcodes1<-read_tsv("../data/GSE156175_RAW/GSM5842388_Rep1_S1_barcodes.tsv.gz",
col_names = "barcode")
barcodes2 <- read_tsv("../data/GSE156175_RAW/GSM4726017_S2_barcodes.tsv.gz",
col_names = "barcode")
barcodes3 <- read_tsv("../data/GSE156175_RAW/GSM4726018_S3_barcodes.tsv.gz",
col_names = "barcode")
barcodes4 <- read_tsv("../data/GSE156175_RAW/GSM4726019_S4_barcodes.tsv.gz",
col_names = "barcode")
barcodes1$barcode <- substr(barcodes1$barcode,1,nchar(barcodes1$barcode) - 2)
barcodes2$barcode <- substr(barcodes2$barcode,1,nchar(barcodes2$barcode) - 2)
barcodes3$barcode <- substr(barcodes3$barcode,1,nchar(barcodes3$barcode) - 2)
barcodes4$barcode <- substr(barcodes4$barcode,1,nchar(barcodes4$barcode) - 2)
barcodes1$condition <- "Untreated"
barcodes2$condition <- "IL-1B"
barcodes3$condition <- "IFNg"
barcodes4$condition <- "IL-1B_IFNg"
barcodes <- rbind(barcodes1, barcodes2, barcodes3, barcodes4)
barcodes$cell_bc <- paste0(barcodes$barcode, "_", barcodes$condition)
barcodes$condition <- factor(barcodes$condition)
Import the gene information:
genes1 <- read_tsv("../data/GSE156175_RAW/GSM5842388_Rep1_S1_features.tsv.gz",
col_names = c("ensembl", "symbol", "type"))
genes2 <- read_tsv("../data/GSE156175_RAW/GSM4726017_S2_features.tsv.gz",
col_names = c("ensembl", "symbol", "type"))
genes3 <- read_tsv("../data/GSE156175_RAW/GSM4726018_S3_features.tsv.gz",
col_names = c("ensembl", "symbol", "type"))
genes4 <- read_tsv("../data/GSE156175_RAW/GSM4726019_S4_features.tsv.gz",
col_names = c("ensembl", "symbol", "type"))
genes <- genes1
genes$type <- factor(genes$type)
Now import in the read counts:
counts1 <- t(readMM("../data/GSE156175_RAW/GSM5842388_Rep1_S1_matrix.mtx.gz"))
counts2 <- t(readMM("../data/GSE156175_RAW/GSM4726017_S2_matrix.mtx.gz"))
counts3 <- t(readMM("../data/GSE156175_RAW/GSM4726018_S3_matrix.mtx.gz"))
counts4 <- t(readMM("../data/GSE156175_RAW/GSM4726019_S4_matrix.mtx.gz"))
rownames(counts1) <- paste0(barcodes1$barcode, "_", barcodes1$condition)
rownames(counts2) <- paste0(barcodes2$barcode, "_", barcodes2$condition)
rownames(counts3) <- paste0(barcodes3$barcode, "_", barcodes3$condition)
rownames(counts4) <- paste0(barcodes4$barcode, "_", barcodes4$condition)
colnames(counts1) <- genes1$symbol
colnames(counts2) <- genes2$symbol
colnames(counts3) <- genes3$symbol
colnames(counts4) <- genes4$symbol
counts <- rbind(
as.matrix(counts1),
as.matrix(counts2),
as.matrix(counts3),
as.matrix(counts4)
)
counts <- as(counts, "CsparseMatrix")
Remove genes that are not expressed in any cell:
x <- colSums(counts)
j <- which(x > 0)
genes <- genes[j,]
counts <- counts[,j]
Remove cells in terms (i) total UMI count and (ii) very few expressed genes:
x <- rowSums(counts > 0)
i <- which(x > 2000)
barcodes <- barcodes[i,]
counts <- counts[i,]
x <- rowSums(counts)
i <- which(x <= 60000)
barcodes <- barcodes[i,]
counts <- counts[i,]
PC: The filtering step x > 2000
seems a bit
aggressive. I think we could have retained some more cells.
Remove cells with high mitochondrial counts:
mito_genes <- which(substr(genes$symbol,1,2) == "mt")
s <- rowSums(counts)
s_mito <- rowSums(counts[,mito_genes])
prop_mito <- s_mito/s
i <- which(prop_mito < 0.1)
barcodes <- barcodes[i,]
counts <- counts[i,]
PC: Again, the filtering step prop_mito < 0.1
seems a
bit aggressive.
Remove MALAT1, ribosomal genes, and mitochondrial genes:
j <- which(!(grepl("^mt-",genes$symbol) | grepl("^Rp[sl]",genes$symbol)))
genes <- genes[j,]
counts <- counts[,j]
j <- which(genes$symbol != "Malat1")
genes <- genes[j,]
counts <- counts[,j]
Remove other genes that are expressed in only 1 or 2 cells:
x <- colSums(counts > 0)
j <- which(x > 2)
genes <- genes[j,]
counts <- counts[,j]
Fit a topic model with \(K = 12\).
set.seed(1)
tm_fit <- fit_poisson_nmf(X = counts,k = 12,control = list(nc = 7),
verbose = "none")
Warning: The above code chunk cached its results, but
it won’t be re-run if previous chunks it depends on are updated. If you
need to use caching, it is highly recommended to also set
knitr::opts_chunk$set(autodep = TRUE)
at the top of the
file (in a chunk that is not cached). Alternatively, you can customize
the option dependson
for each individual chunk that is
cached. Using either autodep
or dependson
will
remove this warning. See the
knitr cache options for more details.
Here is the Structure plot:
set.seed(1)
structure_plot(tm_fit,n = Inf)
# Running tsne on 7606 x 12 matrix.
Below is a heatmap annotation of the marker genes given in the Stancill paper:
scale_rows <- function (A)
A / apply(A,1,max)
marker_genes <- c("Ins1","Ins2","Gcg","Sst","Ppy","Krt17","Ccr5",
"Col1a1","Cd34","Cpa1")
F <- poisson2multinom(tm_fit)$F
F <- F[marker_genes,]
F <- scale_rows(F)
rownames(F) <- marker_genes
annotation_heatmap(F,select_features = "all",verbose = FALSE)
Below are some comments relating my guesses about factor associations. Many of the beta associated factors are non-specific:
Now, I do celltype assignments. I used 1/3 as a threshold on the topic proportions to determine celltype because this seemed to look reasonable visually. Below is the structure plot with cells grouped by type.
L <- poisson2multinom(tm_fit)$L
L_df <- as.data.frame(L)
L_df <- L_df %>%
mutate(
cluster = case_when(
k2 > (1/3) ~ "Acinar",
k3 > (1/3) ~ "Endothelial/Mesnchymal",
k5 > (1/3) ~ "Ductal",
k8 > (1/3) ~ "Delta",
k9 > (1/3) ~ "Alpha",
k10 > (1/3) ~ "Gamma",
k11 > (1/3) ~ "Macrophage",
TRUE ~ "Beta"
)
)
structure_plot(tm_fit, grouping = L_df$cluster, gap = 30, n = Inf)
# Running tsne on 860 x 12 matrix.
# Running tsne on 5780 x 12 matrix.
# Running tsne on 359 x 12 matrix.
# Running tsne on 101 x 12 matrix.
# Running tsne on 244 x 12 matrix.
# Running tsne on 145 x 12 matrix.
# Running tsne on 107 x 12 matrix.
Overall, this clustering looks quite good, but there is a small pocket of beta cells that have loadings on the green, black, and grey factors, which indicate that they could also be alpha or delta cells. Perhaps additional investigation into these cells (e.g. with a UMAP) could help distinguish their precise types. Or, we could exclude them as not having a clear type.
Next, I investigated a UMAP plot to see how our clusters looked. Below is an elbow plot of the PCs created by Seurat:
barcodes$celltype <- L_df$cluster
counts <- counts[,!duplicated(colnames(counts))]
so <- CreateSeuratObject(counts = Matrix::t(counts), meta.data = barcodes)
# Warning: Setting row names on a tibble is deprecated.
so <- SCTransform(so, verbose = FALSE)
so <- RunPCA(so, verbose = FALSE)
ElbowPlot(so)
And here is a UMAP plot:
so <- RunUMAP(so, dims = 1:10, verbose = FALSE)
# Warning: The default method for RunUMAP has changed from calling Python UMAP via reticulate to the R-native UWOT using the cosine metric
# To use Python UMAP via reticulate, set umap.method to 'umap-learn' and metric to 'correlation'
# This message will be shown once per session
DimPlot(so, group.by = "celltype") +
theme_cowplot(font_size = 10)
There are clearly a few cells on the UMAP plot that appear to lie in a different cluster than their assignment. However, I’m not convinced that this plot is any more reliable than the topic model structure plot.
Save the processed data to an RData file:
save(list = c("barcodes","genes","counts"),
file = "pancreas_cytokine_lsa.RData")
# resaveRdaFiles("pancreas_cytokine.RData")
sessionInfo()
# R version 4.3.3 (2024-02-29)
# Platform: aarch64-apple-darwin20 (64-bit)
# Running under: macOS 15.5
#
# Matrix products: default
# BLAS: /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/lib/libRblas.0.dylib
# LAPACK: /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/lib/libRlapack.dylib; LAPACK version 3.11.0
#
# locale:
# [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
#
# time zone: America/Chicago
# tzcode source: internal
#
# attached base packages:
# [1] tools stats graphics grDevices utils datasets methods
# [8] base
#
# other attached packages:
# [1] Seurat_5.0.3 SeuratObject_5.0.1 sp_2.1-4 dplyr_1.1.4
# [5] fastTopics_0.7-25 cowplot_1.1.3 readr_2.1.5 Matrix_1.6-5
#
# loaded via a namespace (and not attached):
# [1] RcppAnnoy_0.0.22 splines_4.3.3
# [3] later_1.4.2 bitops_1.0-7
# [5] tibble_3.3.0 polyclip_1.10-6
# [7] fastDummies_1.7.3 lifecycle_1.0.4
# [9] mixsqp_0.3-54 rprojroot_2.0.4
# [11] globals_0.16.3 lattice_0.22-5
# [13] vroom_1.6.5 MASS_7.3-60.0.1
# [15] magrittr_2.0.3 plotly_4.11.0
# [17] sass_0.4.10 rmarkdown_2.29
# [19] jquerylib_0.1.4 yaml_2.3.10
# [21] httpuv_1.6.14 glmGamPoi_1.14.3
# [23] sctransform_0.4.1 spam_2.10-0
# [25] spatstat.sparse_3.0-3 reticulate_1.40.0
# [27] pbapply_1.7-2 RColorBrewer_1.1-3
# [29] abind_1.4-5 zlibbioc_1.48.2
# [31] Rtsne_0.17 quadprog_1.5-8
# [33] GenomicRanges_1.54.1 purrr_1.0.4
# [35] BiocGenerics_0.48.1 RCurl_1.98-1.14
# [37] git2r_0.33.0 GenomeInfoDbData_1.2.11
# [39] IRanges_2.36.0 S4Vectors_0.40.2
# [41] ggrepel_0.9.6 irlba_2.3.5.1
# [43] listenv_0.9.1 spatstat.utils_3.0-4
# [45] goftest_1.2-3 RSpectra_0.16-2
# [47] spatstat.random_3.2-3 fitdistrplus_1.1-11
# [49] parallelly_1.37.1 DelayedMatrixStats_1.24.0
# [51] DelayedArray_0.28.0 leiden_0.4.3.1
# [53] codetools_0.2-19 tidyselect_1.2.1
# [55] farver_2.1.2 matrixStats_1.2.0
# [57] stats4_4.3.3 spatstat.explore_3.2-7
# [59] jsonlite_2.0.0 ellipsis_0.3.2
# [61] progressr_0.14.0 ggridges_0.5.6
# [63] survival_3.5-8 progress_1.2.3
# [65] ica_1.0-3 Rcpp_1.1.0
# [67] glue_1.8.0 SparseArray_1.2.4
# [69] gridExtra_2.3 xfun_0.52
# [71] MatrixGenerics_1.14.0 GenomeInfoDb_1.38.8
# [73] withr_3.0.2 fastmap_1.2.0
# [75] digest_0.6.37 truncnorm_1.0-9
# [77] R6_2.6.1 mime_0.13
# [79] colorspace_2.1-0 scattermore_1.2
# [81] gtools_3.9.5 tensor_1.5
# [83] dichromat_2.0-0.1 spatstat.data_3.0-4
# [85] RhpcBLASctl_0.23-42 tidyr_1.3.1
# [87] generics_0.1.4 data.table_1.17.6
# [89] S4Arrays_1.2.1 prettyunits_1.2.0
# [91] httr_1.4.7 htmlwidgets_1.6.4
# [93] whisker_0.4.1 uwot_0.2.3
# [95] pkgconfig_2.0.3 gtable_0.3.6
# [97] workflowr_1.7.1 lmtest_0.9-40
# [99] XVector_0.42.0 htmltools_0.5.8.1
# [101] dotCall64_1.1-1 Biobase_2.62.0
# [103] scales_1.4.0 png_0.1-8
# [105] ashr_2.2-66 knitr_1.50
# [107] tzdb_0.4.0 reshape2_1.4.4
# [109] nlme_3.1-164 cachem_1.1.0
# [111] zoo_1.8-12 stringr_1.5.1
# [113] KernSmooth_2.23-22 parallel_4.3.3
# [115] miniUI_0.1.1.1 pillar_1.11.0
# [117] grid_4.3.3 vctrs_0.6.5
# [119] RANN_2.6.1 promises_1.3.3
# [121] xtable_1.8-4 cluster_2.1.6
# [123] evaluate_1.0.4 invgamma_1.2
# [125] cli_3.6.5 compiler_4.3.3
# [127] rlang_1.1.6 crayon_1.5.3
# [129] SQUAREM_2021.1 future.apply_1.11.2
# [131] labeling_0.4.3 plyr_1.8.9
# [133] fs_1.6.6 stringi_1.8.7
# [135] viridisLite_0.4.2 deldir_2.0-4
# [137] lazyeval_0.2.2 spatstat.geom_3.2-9
# [139] RcppHNSW_0.6.0 hms_1.1.3
# [141] patchwork_1.2.0 sparseMatrixStats_1.14.0
# [143] bit64_4.0.5 future_1.33.2
# [145] ggplot2_3.5.2 shiny_1.8.0
# [147] SummarizedExperiment_1.32.0 ROCR_1.0-11
# [149] igraph_2.0.3 RcppParallel_5.1.10
# [151] bslib_0.9.0 bit_4.0.5