Last updated: 2023-02-20

Checks: 7 0

Knit directory: gsmash/

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(20220606) 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 25a78f0. 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:    .Rhistory
    Ignored:    .Rproj.user/

Untracked files:
    Untracked:  analysis/compare_vga_iterations_pbmc_full.Rmd
    Untracked:  output/pbmc3k_k1.rds
    Untracked:  output/pbmc3k_k1_S1.rds

Unstaged changes:
    Modified:   analysis/index.Rmd
    Modified:   analysis/overdispersed_splitting.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/run_PMF_on_droplet.Rmd) and HTML (docs/run_PMF_on_droplet.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 25a78f0 DongyueXie 2023-02-20 wflow_publish("analysis/run_PMF_on_droplet.Rmd")
html 603e676 DongyueXie 2023-01-23 Build site.
Rmd c46a9cd DongyueXie 2023-01-23 wflow_publish("analysis/run_PMF_on_droplet.Rmd")
html eb3aa65 DongyueXie 2022-12-07 Build site.
Rmd 3a2ef34 DongyueXie 2022-12-07 wflow_publish("analysis/run_PMF_on_droplet.Rmd")

The dataset is “droplet” UMI count data from Montoro et al (2018)—these are gene expression profiles of trachea epithelial cells in C57BL/6 mice obtained using droplet-based 3’ single-cell RNA-seq—for topic modeling analysis.

See here for data preparations.

I filtered out genes that expressed in less than 10 cells, and no further preprocessing. The final data matrix is

library(Matrix) 
load('/project2/mstephens/pcarbo/git/single-cell-topics/data/droplet.RData')
counts = counts[,colSums(counts!=0)>10]
dim(counts)
[1]  7193 14315

Model fitting

The model is the Empirical Bayes Poisson matrix factorization model, and \(l_0\) is fixed at log(rowMeans(Y)), \(f_0\) is initialized at log(colSums(Y)/sum(l_0)), then let the model estimates \(f_0\) during iterations.

summary_plot = function(res,counts){
  plot(res$K_trace,ylab='',xlab='iterations',main='K over iterations',pch=20)
  plot(res$sigma2,ylab='',xlab='gene',main = 'gene specific variance',pch=20,col='grey70')
  plot(colSums(counts/rowSums(counts)),res$sigma2,xlab='gene expression',ylab='gene specific varaince',pch=20,col='grey60')
  plot(colSums(counts==0)/nrow(counts),res$sigma2,xlab='gene expression sparsity',ylab='gene specific varaince',pch = 20, col='grey50')
}

Sparse loadings and factors

source('code/poisson_STM/plot_factors.R')
res = readRDS('/project2/mstephens/dongyue/poisson_mf/droplet/ebpmf_droplet_sparse.rds')
summary_plot(res,counts)

Version Author Date
603e676 DongyueXie 2023-01-23

plot.factors(res$fit_flash,samples$tissue)

plot(res$fit_flash$pve[-c(1,2)],xlab='factors',ylab='PVE')

Version Author Date
603e676 DongyueXie 2023-01-23
eb3aa65 DongyueXie 2022-12-07
f0_init = log(colSums(counts)/sum(rowMeans(counts)))
plot(res$fit_flash$F.pm[,2],f0_init,xlab='f0 estimates',ylab='f0 init values',pch=20,col='grey70')
abline(a=0,b=1)

Version Author Date
603e676 DongyueXie 2023-01-23
eb3aa65 DongyueXie 2022-12-07

Nonnegative loadings with point exponential prior, and sparse factors

source('code/poisson_STM/structure_plot.R')
res = readRDS('/project2/mstephens/dongyue/poisson_mf/droplet/ebpmf_droplet_nonnegL.rds')
summary_plot(res,counts)

f0_init = log(colSums(counts)/sum(rowMeans(counts)))
plot(res$fit_flash$F.pm[,2],f0_init,xlab='f0 estimates',ylab='f0 init value',pch=20,col='grey70')
abline(a=0,b=1)

plot.factors(res$fit_flash,samples$tissue,nonnegative = T)
Warning: Removed 313 rows containing missing values (`geom_point()`).

structure_plot_general(res$fit_flash$L.pm[,order(res$fit_flash$pve,decreasing = T)[1:14]],res$fit_flash$F.pm[,order(res$fit_flash$pve,decreasing = T)[1:14]],samples$tissue,LD=T)
Running tsne on 1117 x 12 matrix.
Running tsne on 112 x 12 matrix.
Running tsne on 683 x 12 matrix.
Running tsne on 25 x 12 matrix.
Running tsne on 41 x 12 matrix.

plot(res$fit_flash$pve[-c(1,2)],xlab='factors',ylab='PVE')

Nonnegative loadings and factors with point exponential prior

res = readRDS('/project2/mstephens/dongyue/poisson_mf/droplet/ebpmf_droplet_nonnegLF.rds')
summary_plot(res,counts)

f0_init = log(colSums(counts)/sum(rowMeans(counts)))
plot(res$fit_flash$F.pm[,2],f0_init,xlab='f0 estimates',ylab='f0 init value',pch=20,col='grey70')
abline(a=0,b=1)

plot.factors(res$fit_flash,samples$tissue,nonnegative = T)
Warning: Removed 313 rows containing missing values (`geom_point()`).

structure_plot_general(res$fit_flash$L.pm,res$fit_flash$F.pm,samples$tissue,LD=T)
Running tsne on 1117 x 12 matrix.
Running tsne on 112 x 12 matrix.
Running tsne on 683 x 12 matrix.
Running tsne on 25 x 12 matrix.
Running tsne on 41 x 12 matrix.

plot(res$fit_flash$pve[-c(1,2)],xlab='factors',ylab='PVE')


sessionInfo()
R version 4.1.0 (2021-05-18)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: CentOS Linux 7 (Core)

Matrix products: default
BLAS:   /software/R-4.1.0-no-openblas-el7-x86_64/lib64/R/lib/libRblas.so
LAPACK: /software/R-4.1.0-no-openblas-el7-x86_64/lib64/R/lib/libRlapack.so

locale:
 [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C         LC_TIME=C           
 [4] LC_COLLATE=C         LC_MONETARY=C        LC_MESSAGES=C       
 [7] LC_PAPER=C           LC_NAME=C            LC_ADDRESS=C        
[10] LC_TELEPHONE=C       LC_MEASUREMENT=C     LC_IDENTIFICATION=C 

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] fastTopics_0.6-142 ggplot2_3.4.0      Matrix_1.5-3       workflowr_1.6.2   

loaded via a namespace (and not attached):
 [1] mcmc_0.9-7         fs_1.5.0           progress_1.2.2     httr_1.4.4        
 [5] rprojroot_2.0.2    tools_4.1.0        bslib_0.2.5.1      utf8_1.2.2        
 [9] R6_2.5.1           irlba_2.3.5.1      uwot_0.1.14        DBI_1.1.1         
[13] lazyeval_0.2.2     colorspace_2.0-3   withr_2.5.0        prettyunits_1.1.1 
[17] tidyselect_1.2.0   compiler_4.1.0     git2r_0.28.0       cli_3.5.0         
[21] quantreg_5.94      SparseM_1.81       plotly_4.10.1      labeling_0.4.2    
[25] horseshoe_0.2.0    sass_0.4.0         flashier_0.2.34    scales_1.2.1      
[29] SQUAREM_2021.1     quadprog_1.5-8     pbapply_1.6-0      mixsqp_0.3-48     
[33] stringr_1.4.0      digest_0.6.30      rmarkdown_2.9      MCMCpack_1.6-3    
[37] deconvolveR_1.2-1  pkgconfig_2.0.3    htmltools_0.5.3    fastmap_1.1.0     
[41] invgamma_1.1       highr_0.9          htmlwidgets_1.5.4  rlang_1.0.6       
[45] rstudioapi_0.13    jquerylib_0.1.4    farver_2.1.1       generics_0.1.3    
[49] jsonlite_1.8.3     dplyr_1.0.10       magrittr_2.0.3     Rcpp_1.0.9        
[53] munsell_0.5.0      fansi_1.0.3        lifecycle_1.0.3    stringi_1.6.2     
[57] whisker_0.4        yaml_2.3.6         MASS_7.3-54        Rtsne_0.16        
[61] plyr_1.8.6         grid_4.1.0         parallel_4.1.0     promises_1.2.0.1  
[65] ggrepel_0.9.2      crayon_1.5.2       lattice_0.20-44    cowplot_1.1.1     
[69] splines_4.1.0      hms_1.1.2          knitr_1.33         pillar_1.8.1      
[73] softImpute_1.4-1   reshape2_1.4.4     glue_1.6.2         evaluate_0.14     
[77] trust_0.1-8        stm_1.3.6          data.table_1.14.6  RcppParallel_5.1.5
[81] vctrs_0.5.1        httpuv_1.6.1       MatrixModels_0.5-1 gtable_0.3.1      
[85] purrr_0.3.5        ebnm_1.0-11        tidyr_1.2.1        assertthat_0.2.1  
[89] ashr_2.2-54        xfun_0.24          coda_0.19-4        later_1.3.0       
[93] survival_3.2-11    viridisLite_0.4.1  truncnorm_1.0-8    tibble_3.1.8      
[97] ellipsis_0.3.2