Last updated: 2020-09-10
Checks: 7 0
Knit directory: single-cell-topics/analysis/
This reproducible R Markdown analysis was created with workflowr (version 1.6.2.9000). 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.
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 5a29ee0. 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: data/droplet.RData
Ignored: data/pbmc_68k.RData
Ignored: data/pbmc_purified.RData
Ignored: data/pulseseq.RData
Ignored: output/droplet/fits-droplet.RData
Ignored: output/droplet/rds/
Ignored: output/pbmc-68k/fits-pbmc-68k.RData
Ignored: output/pbmc-68k/rds/
Ignored: output/pbmc-purified/fits-pbmc-purified.RData
Ignored: output/pbmc-purified/rds/
Ignored: output/pulseseq/fits-pulseseq.RData
Ignored: output/pulseseq/rds/
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/bcells_and_nkcells.Rmd
) and HTML (docs/bcells_and_nkcells.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 | 5a29ee0 | Peter Carbonetto | 2020-09-10 | workflowr::wflow_publish(“bcells_and_nkcells.Rmd”, verbose = TRUE) |
Rmd | 88ed67f | Peter Carbonetto | 2020-09-10 | Added improved beta and z-score scatterplots to bcells_and_nkcells analysis. |
Rmd | 58a255f | Peter Carbonetto | 2020-09-10 | Added steps to perform diff count analysis in bcells_and_nkcells.Rmd. |
Rmd | 5c3a5f4 | Peter Carbonetto | 2020-09-09 | A few small edits to the text in the bcells_and_nkcells analysis. |
html | 8cdad6c | Peter Carbonetto | 2020-09-08 | Build site. |
Rmd | b0a57a9 | Peter Carbonetto | 2020-09-08 | workflowr::wflow_publish(“bcells_and_nkcells.Rmd”) |
html | 35d7ca9 | Peter Carbonetto | 2020-09-08 | Build site. |
Rmd | 8ba727c | Peter Carbonetto | 2020-09-08 | workflowr::wflow_publish(“bcells_and_nkcells.Rmd”) |
html | bffd7cd | Peter Carbonetto | 2020-09-08 | Removed the additional histograms in the bcells_and_nkcells analysis. |
Rmd | f5a2e42 | Peter Carbonetto | 2020-09-08 | workflowr::wflow_publish(“bcells_and_nkcells.Rmd”) |
html | abb8ab4 | Peter Carbonetto | 2020-09-08 | Added histograms to bcells_and_nkcells analysis. |
Rmd | dc544c4 | Peter Carbonetto | 2020-09-08 | workflowr::wflow_publish(“bcells_and_nkcells.Rmd”) |
html | 02953bd | Peter Carbonetto | 2020-09-08 | Build site. |
Rmd | 4525eda | Peter Carbonetto | 2020-09-08 | workflowr::wflow_publish(“bcells_and_nkcells.Rmd”) |
html | 2e5917d | Peter Carbonetto | 2020-09-08 | Performed first build of bcells_and_nkcells page. |
Rmd | faea79b | Peter Carbonetto | 2020-09-08 | workflowr::wflow_publish(“bcells_and_nkcells.Rmd”) |
Rmd | 681efe3 | Peter Carbonetto | 2020-09-08 | Added steps to bcells_and_nkcells analysis to run cluster-based differential expression analysis. |
Rmd | 77499e2 | Peter Carbonetto | 2020-09-07 | Implemented first steps of bcells_and_nkcells analysis. |
Rmd | d749c17 | Peter Carbonetto | 2020-09-07 | Added notes to plots_pbmc; committed pbmc-clustering.RData output. |
In the previous analysis of the purified and 68k PBMC data sets, we identified clusters in both data sets corresponding to B-cells and natural killer cells. Each of these clusters is characterized by high proportions from a single topic. Here we show a surprising result: the clusters are enriched for the top marker genes for these cell types (e.g., CD79A, NKG7), but not the associated topics.
Load the packages used in the analysis below.
library(Matrix)
library(dplyr)
library(fastTopics)
library(ggplot2)
library(ggrepel)
library(cowplot)
source("../code/more_plots.R")
Load the mixture of FACS-purified PBMC data and the \(k = 6\) Poisson NMF model fit.
fit_purified <-
readRDS("../output/pbmc-purified/rds/fit-pbmc-purified-scd-ex-k=6.rds")$fit
load("../data/pbmc_purified.RData")
counts_purified <- counts
genes_purified <- genes
rm(samples,genes,counts)
Load the “unsorted” 68k PBMC data and the \(k = 6\) Poisson NMF model fit.
fit_68k <- readRDS("../output/pbmc-68k/rds/fit-pbmc-68k-scd-ex-k=6.rds")$fit
load("../data/pbmc_68k.RData")
counts_68k <- counts
genes_68k <- genes
rm(samples,genes,counts)
Load the clustering of the purified and 68k data set that was determined in the “plots_pbmc” analysis.
load("../output/pbmc-clustering.RData")
Compute the differential expression statistics for the purified data.
timing <- system.time(
diff_count_purified <- diff_count_analysis(fit_purified,counts_purified))
cat(sprintf("Computation took %0.2f seconds.\n",timing["elapsed"]))
# Fitting 21952 x 6 = 131712 univariate Poisson models.
# Computing log-fold change statistics.
# Computation took 155.91 seconds.
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.
Compute the differential expression statistics for the 68k data.
timing <- system.time(
diff_count_68k <- diff_count_analysis(fit_68k,counts_68k))
cat(sprintf("Computation took %0.2f seconds.\n",timing["elapsed"]))
# Fitting 20387 x 6 = 122322 univariate Poisson models.
# Computing log-fold change statistics.
# Computation took 79.61 seconds.
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.
Perform a differential expression analysis using the clustering of the purified data.
fit_clusters_purified <-
init_poisson_nmf_from_clustering(counts_purified,samples_purified$cluster)
diff_count_clusters_purified <- diff_count_analysis(fit_clusters_purified,
counts_purified)
# All topic proportions are either zero or one; using simpler single-topic calculations for model parameter estimates
# Fitting 21952 x 6 = 131712 univariate Poisson models.
# Computing log-fold change statistics.
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.
Perform a differential expression analysis using the clustering of the 68k data.
fit_clusters_68k <- init_poisson_nmf_from_clustering(counts_68k,
samples_68k$cluster)
diff_count_clusters_68k <- diff_count_analysis(fit_clusters_68k,counts_68k)
# All topic proportions are either zero or one; using simpler single-topic calculations for model parameter estimates
# Fitting 20387 x 9 = 183483 univariate Poisson models.
# Computing log-fold change statistics.
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.
In the purified data set, compare the gene-wise z-scores from topic 3 to the z-scores from cluster B.
p1 <- logfoldchange_scatterplot(diff_count_clusters_purified$beta[,"B"],
diff_count_purified$beta[,3],
diff_count_purified$colmeans) +
labs(x = "cluster B",y = "topic 3",title = "log-fold change (beta)")
p2 <- zscores_scatterplot(diff_count_clusters_purified$Z[,"B"],
diff_count_purified$Z[,3],
diff_count_purified$colmeans,
genes_purified$symbol,
label_above_score = 250,
zmax = 650) +
labs(x = "cluster B",y = "topic 3",title = "z-scores")
plot_grid(p1,p2)
B-cell marker CD79A only emerges in the cluster, and shows no enrichment in the corresponding topic. This is not a fluke—we observe the exact same result in the 68k data when we compare the gene-wise z-scores from topic 5 to the z-scores from cluster A2:
p3 <- logfoldchange_scatterplot(diff_count_clusters_68k$beta[,"A2"],
diff_count_68k$beta[,5],
diff_count_68k$colmeans) +
labs(x = "cluster A2",y = "topic 5",title = "log-fold change (beta)")
p4 <- zscores_scatterplot(diff_count_clusters_68k$Z[,"A2"],
diff_count_68k$Z[,5],
diff_count_68k$colmeans,
genes_68k$symbol,
label_above_score = 175,
zmax = 500) +
labs(x = "cluster A2",y = "topic 5",title = "z-scores")
plot_grid(p3,p4)
We observe a similar—yet more striking—result in natural killer cells. In the purified data set, compare the gene-wise z-scores from topic 4 to the z-scores from cluster A1:
p5 <- logfoldchange_scatterplot(diff_count_clusters_purified$beta[,"A1"],
diff_count_purified$beta[,4],
diff_count_purified$colmeans) +
labs(x = "cluster A1",y = "topic 4",title = "log-fold change (beta)")
p6 <- zscores_scatterplot(diff_count_clusters_purified$Z[,"A1"],
diff_count_purified$Z[,4],
diff_count_purified$colmeans,
genes_purified$symbol,
label_above_score = 250,
zmax = 750) +
labs(x = "cluster A1",y = "topic 4",title = "z-scores")
plot_grid(p5,p6)
Genes NKG7 and GNLY (granulysin), both characteristic NK genes, are very strongly enriched in the cluster, and not at all in the topic.
The 68k data, comparing the gene-wise z-scores from topic 3 to the z-scores from cluster A1b, replicates this striking result:
p7 <- logfoldchange_scatterplot(diff_count_clusters_68k$beta[,"A1b"],
diff_count_68k$beta[,3],
diff_count_68k$colmeans) +
labs(x = "cluster A1b",y = "topic 3",title = "log-fold change (beta)")
p8 <- zscores_scatterplot(diff_count_clusters_68k$Z[,"A1b"],
diff_count_68k$Z[,3],
diff_count_68k$colmeans,
genes_68k$symbol,
label_above_score = 250) +
labs(x = "cluster A1b",y = "topic 3",title = "z-scores")
plot_grid(p7,p8)
These results suggest the clusters and topics appear to be highlighting different biological patterns.
sessionInfo()
# R version 3.6.2 (2019-12-12)
# Platform: x86_64-apple-darwin15.6.0 (64-bit)
# Running under: macOS Catalina 10.15.6
#
# Matrix products: default
# BLAS: /Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRblas.0.dylib
# LAPACK: /Library/Frameworks/R.framework/Versions/3.6/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] stats graphics grDevices utils datasets methods base
#
# other attached packages:
# [1] cowplot_1.0.0 ggrepel_0.9.0 ggplot2_3.3.0 fastTopics_0.3-175
# [5] dplyr_0.8.3 Matrix_1.2-18
#
# loaded via a namespace (and not attached):
# [1] Rcpp_1.0.5 lattice_0.20-38 tidyr_1.0.0
# [4] prettyunits_1.1.1 assertthat_0.2.1 zeallot_0.1.0
# [7] rprojroot_1.3-2 digest_0.6.23 R6_2.4.1
# [10] backports_1.1.5 MatrixModels_0.4-1 evaluate_0.14
# [13] coda_0.19-3 httr_1.4.1 pillar_1.4.3
# [16] rlang_0.4.5 progress_1.2.2 lazyeval_0.2.2
# [19] data.table_1.12.8 irlba_2.3.3 SparseM_1.78
# [22] whisker_0.4 rmarkdown_2.3 labeling_0.3
# [25] Rtsne_0.15 stringr_1.4.0 htmlwidgets_1.5.1
# [28] munsell_0.5.0 compiler_3.6.2 httpuv_1.5.2
# [31] xfun_0.11 pkgconfig_2.0.3 mcmc_0.9-6
# [34] htmltools_0.4.0 tidyselect_0.2.5 tibble_2.1.3
# [37] workflowr_1.6.2.9000 quadprog_1.5-8 codetools_0.2-16
# [40] viridisLite_0.3.0 crayon_1.3.4 withr_2.1.2
# [43] later_1.0.0 MASS_7.3-51.4 grid_3.6.2
# [46] jsonlite_1.6 gtable_0.3.0 lifecycle_0.1.0
# [49] git2r_0.26.1 magrittr_1.5 scales_1.1.0
# [52] RcppParallel_4.4.2 stringi_1.4.3 farver_2.0.1
# [55] fs_1.3.1 promises_1.1.0 vctrs_0.2.1
# [58] tools_3.6.2 glue_1.3.1 purrr_0.3.3
# [61] hms_0.5.2 yaml_2.2.0 colorspace_1.4-1
# [64] plotly_4.9.2 knitr_1.26 quantreg_5.54
# [67] MCMCpack_1.4-5