Last updated: 2020-07-27

Checks: 7 0

Knit directory: single-cell-topics/analysis/

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(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 9d9b47e. 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/b_cells/
    Ignored:    data/cd14_monocytes/
    Ignored:    data/cd34_filtered/
    Ignored:    data/cd4_t_helper/
    Ignored:    data/cd56_nk/
    Ignored:    data/cytotoxic_t/
    Ignored:    data/memory_t/
    Ignored:    data/naive_cytotoxic/
    Ignored:    data/naive_t/
    Ignored:    data/pbmc_purified.RData
    Ignored:    data/regulatory_t/

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/prepare_purified_pbmc.Rmd) and HTML (docs/prepare_purified_pbmc.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 9d9b47e Peter Carbonetto 2020-07-27 wflow_publish(“prepare_purified_pbmc.Rmd”, view = FALSE, verbose = TRUE)
html 372e1ac Peter Carbonetto 2020-07-27 Build site.
Rmd a75eba1 Peter Carbonetto 2020-07-27 Added code and workflowr analysis for preparing FACS-purified PBMC data sets.

These are the steps taken to prepare the mixture of FACS-purified PBMC data for topic modeling analysis. These data are the “reference transcriptome” profiles generated via single-cell RNA-seq of 10 bead-enriched subpopulations as described in Zheng et al (2017).

Note: In Zheng et al (2017), the clustering analysis suggests that the subpopulations are mostly “homogenous”, with a couple exceptions, the CD14+ and CD34+ subpopulations. For the CD14+ monocytes, two clusters were observed, and they were identified as “CD14+ monocytes” and “dendritic cells”. See Supplementary Figures 6 and 7 in that paper.

Download the “Gene/cell matrix (filtered)” tar.gz file from the 10x Genomics website for each of the following 10 data sets: CD14+ Monocytes, CD19+ B Cells, CD34+ Cells, CD4+ Helper T Cells, CD4+/CD25+ Regulatory T Cells, CD4+/CD45RA+/CD25- Naive T cells, CD4+/CD45RO+ Memory T Cells, CD56+ Natural Killer Cells, CD8+ Cytotoxic T cells and CD8+/CD45RA+ Naive Cytotoxic T Cells. Unpack the individual tar archives and re-organize the files into 10 subdirectories, each containing three (compressed) files, barcodes.tsv.gz, genes.tsv.gz and matrix.mtx.gz. The “datasets” variable lists the names of all subdirectories used, along with the “cell type” labels that Zheng et al (2017) assigned to each of the 10 data sets:

datasets <- list("CD19+ B"                      = "b_cells",
                 "CD14+ Monocyte"               = "cd14_monocytes",
                 "CD34+"                        = "cd34_filtered",
                 "CD4+ T Helper2"               = "cd4_t_helper",
                 "CD56+ NK"                     = "cd56_nk",
                 "CD8+ Cytotoxic T"             = "cytotoxic_t",
                 "CD4+/CD45RO+ Memory"          = "memory_t",
                 "CD8+/CD45RA+ Naive Cytotoxic" = "naive_cytotoxic",
                 "CD4+/CD45RA+/CD25- Naive T"   = "naive_t",
                 "CD4+/CD25 T Reg"              = "regulatory_t")

Load the packages used in the analysis below, and some functions written specifically for loading and preparing these data.

library(tools)
library(Matrix)
library(readr)
source("../code/purified_pbmc.R")

Call read_purified_pbmc_data, which imports the individual data sets into R, and combines them:

out     <- read_purified_pbmc_data("../data",datasets)
samples <- out$samples
genes   <- out$genes
counts  <- out$counts
rm(out)
# Importing data from these files:
# ../data/b_cells/genes.tsv.gz 
# ../data/b_cells/barcodes.tsv.gz 
# ../data/b_cells/matrix.mtx.gz 
# ../data/cd14_monocytes/genes.tsv.gz 
# ../data/cd14_monocytes/barcodes.tsv.gz 
# ../data/cd14_monocytes/matrix.mtx.gz 
# ../data/cd34_filtered/genes.tsv.gz 
# ../data/cd34_filtered/barcodes.tsv.gz 
# ../data/cd34_filtered/matrix.mtx.gz 
# ../data/cd4_t_helper/genes.tsv.gz 
# ../data/cd4_t_helper/barcodes.tsv.gz 
# ../data/cd4_t_helper/matrix.mtx.gz 
# ../data/cd56_nk/genes.tsv.gz 
# ../data/cd56_nk/barcodes.tsv.gz 
# ../data/cd56_nk/matrix.mtx.gz 
# ../data/cytotoxic_t/genes.tsv.gz 
# ../data/cytotoxic_t/barcodes.tsv.gz 
# ../data/cytotoxic_t/matrix.mtx.gz 
# ../data/memory_t/genes.tsv.gz 
# ../data/memory_t/barcodes.tsv.gz 
# ../data/memory_t/matrix.mtx.gz 
# ../data/naive_cytotoxic/genes.tsv.gz 
# ../data/naive_cytotoxic/barcodes.tsv.gz 
# ../data/naive_cytotoxic/matrix.mtx.gz 
# ../data/naive_t/genes.tsv.gz 
# ../data/naive_t/barcodes.tsv.gz 
# ../data/naive_t/matrix.mtx.gz 
# ../data/regulatory_t/genes.tsv.gz 
# ../data/regulatory_t/barcodes.tsv.gz 
# ../data/regulatory_t/matrix.mtx.gz

Remove genes that are not expressed in any of the cells.

j      <- which(colSums(counts > 0) >= 1)
genes  <- genes[j,]
counts <- counts[,j]

After filtering out genes with no expression, the count data are stored in a 94,655 x 21,952 sparse matrix, with rows corresponding to samples, and columns corresponding to genes. This matrix is very sparse—less than 3% of the counts are greater than zero:

cat(sprintf("Number of samples: %d\n",nrow(counts)))
cat(sprintf("Number of genes: %d\n",ncol(counts)))
cat(sprintf("Proportion of counts that are non-zero: %0.1f%%.\n",
            100*mean(counts > 0)))
# Number of samples: 94655
# Number of genes: 21952
# Proportion of counts that are non-zero: 2.9%.

This is the breakdown of samples by data set:

summary(samples["celltype"],maxsum = 10)
#                          celltype    
#  CD19+ B                     :10085  
#  CD14+ Monocyte              : 2612  
#  CD34+                       : 9232  
#  CD4+ T Helper2              :11213  
#  CD56+ NK                    : 8385  
#  CD8+ Cytotoxic T            :10209  
#  CD4+/CD45RO+ Memory         :10224  
#  CD8+/CD45RA+ Naive Cytotoxic:11953  
#  CD4+/CD45RA+/CD25- Naive T  :10479  
#  CD4+/CD25 T Reg             :10263

Save the processed data.

save(list = c("samples","genes","counts"),
     file = "pbmc_purified.RData")
resaveRdaFiles("pbmc_purified.RData")

sessionInfo()
# R version 3.5.1 (2018-07-02)
# Platform: x86_64-pc-linux-gnu (64-bit)
# Running under: Scientific Linux 7.4 (Nitrogen)
# 
# Matrix products: default
# BLAS/LAPACK: /software/openblas-0.2.19-el7-x86_64/lib/libopenblas_haswellp-r0.2.19.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] tools     stats     graphics  grDevices utils     datasets  methods  
# [8] base     
# 
# other attached packages:
# [1] readr_1.3.1   Matrix_1.2-15
# 
# loaded via a namespace (and not attached):
#  [1] Rcpp_1.0.4.6    knitr_1.20      whisker_0.3-2   magrittr_1.5   
#  [5] workflowr_1.6.2 hms_0.4.2       lattice_0.20-38 R6_2.3.0       
#  [9] rlang_0.4.0     stringr_1.3.1   grid_3.5.1      git2r_0.26.1   
# [13] htmltools_0.3.6 yaml_2.2.0      rprojroot_1.3-2 digest_0.6.18  
# [17] tibble_2.1.1    crayon_1.3.4    later_0.7.5     promises_1.0.1 
# [21] fs_1.3.1        glue_1.3.0      evaluate_0.12   rmarkdown_1.10 
# [25] stringi_1.2.4   pillar_1.3.1    compiler_3.5.1  backports_1.1.2
# [29] httpuv_1.4.5    pkgconfig_2.0.2