• Dependencies
  • Data
  • Create objects

Last updated: 2025-03-05

Checks: 7 0

Knit directory: muse/

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(20200712) 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 78c20ac. 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:    .Rproj.user/
    Ignored:    data/1M_neurons_filtered_gene_bc_matrices_h5.h5
    Ignored:    data/293t/
    Ignored:    data/293t_3t3_filtered_gene_bc_matrices.tar.gz
    Ignored:    data/293t_filtered_gene_bc_matrices.tar.gz
    Ignored:    data/5k_Human_Donor1_PBMC_3p_gem-x_5k_Human_Donor1_PBMC_3p_gem-x_count_sample_filtered_feature_bc_matrix.h5
    Ignored:    data/5k_Human_Donor2_PBMC_3p_gem-x_5k_Human_Donor2_PBMC_3p_gem-x_count_sample_filtered_feature_bc_matrix.h5
    Ignored:    data/5k_Human_Donor3_PBMC_3p_gem-x_5k_Human_Donor3_PBMC_3p_gem-x_count_sample_filtered_feature_bc_matrix.h5
    Ignored:    data/5k_Human_Donor4_PBMC_3p_gem-x_5k_Human_Donor4_PBMC_3p_gem-x_count_sample_filtered_feature_bc_matrix.h5
    Ignored:    data/Parent_SC3v3_Human_Glioblastoma_filtered_feature_bc_matrix.tar.gz
    Ignored:    data/brain_counts/
    Ignored:    data/cl.obo
    Ignored:    data/cl.owl
    Ignored:    data/jurkat/
    Ignored:    data/jurkat:293t_50:50_filtered_gene_bc_matrices.tar.gz
    Ignored:    data/jurkat_293t/
    Ignored:    data/jurkat_filtered_gene_bc_matrices.tar.gz
    Ignored:    data/pbmc20k/
    Ignored:    data/pbmc20k_seurat/
    Ignored:    data/pbmc3k/
    Ignored:    data/pbmc4k_filtered_gene_bc_matrices.tar.gz
    Ignored:    data/pbmc_1k_v3_raw_feature_bc_matrix.h5
    Ignored:    data/refdata-gex-GRCh38-2020-A.tar.gz
    Ignored:    data/seurat_1m_neuron.rds
    Ignored:    data/t_3k_filtered_gene_bc_matrices.tar.gz
    Ignored:    r_packages_4.4.1/

Untracked files:
    Untracked:  analysis/bioc_scrnaseq.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/sce.Rmd) and HTML (docs/sce.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 78c20ac Dave Tang 2025-03-05 The SingleCellExperiment class

From Introduction to Single-Cell Analysis with Bioconductor:

… the SingleCellExperiment class (from the SingleCellExperiment package) serves as the common currency for data exchange across 70+ single-cell-related Bioconductor packages. This class implements a data structure that stores all aspects of our single-cell data - gene-by-cell expression data, per-cell metadata and per-gene annotation (Figure 4.1) - and manipulate them in a synchronized manner.

Dependencies

Install Bioconductor packages using BiocManager::install().

if (!require("BiocManager", quietly = TRUE))
  install.packages("BiocManager")

BiocManager::install("SingleCellExperiment")
BiocManager::install("TENxIO")
install.packages("hdf5r")
install.packages("Seurat")

Load libraries.

suppressPackageStartupMessages(library(SingleCellExperiment))
suppressPackageStartupMessages(library(TENxIO))
suppressPackageStartupMessages(library(hdf5r))
suppressPackageStartupMessages(library(Seurat))

Data

Download data.

outdir <- 'data/'

pbmc5k_1_url <- "https://cf.10xgenomics.com/samples/cell-exp/9.0.0/5k_Human_Donor1_PBMC_3p_gem-x_5k_Human_Donor1_PBMC_3p_gem-x/5k_Human_Donor1_PBMC_3p_gem-x_5k_Human_Donor1_PBMC_3p_gem-x_count_sample_filtered_feature_bc_matrix.h5"
pbmc5k_2_url <- "https://cf.10xgenomics.com/samples/cell-exp/9.0.0/5k_Human_Donor2_PBMC_3p_gem-x_5k_Human_Donor2_PBMC_3p_gem-x/5k_Human_Donor2_PBMC_3p_gem-x_5k_Human_Donor2_PBMC_3p_gem-x_count_sample_filtered_feature_bc_matrix.h5"
pbmc5k_1_h5 <- paste0(outdir, basename(pbmc5k_1_url))
pbmc5k_2_h5 <- paste0(outdir, basename(pbmc5k_2_url))

download_file <- function(url, outfile){
  fn <- basename(url)
  if(file.exists(outfile) == FALSE){
    download.file(url, destfile = outfile)
  } else {
    message(paste0(outfile, " already exists"))
  }
}

download_file(pbmc5k_1_url, pbmc5k_1_h5)
data/5k_Human_Donor1_PBMC_3p_gem-x_5k_Human_Donor1_PBMC_3p_gem-x_count_sample_filtered_feature_bc_matrix.h5 already exists
download_file(pbmc5k_2_url, pbmc5k_2_h5)
data/5k_Human_Donor2_PBMC_3p_gem-x_5k_Human_Donor2_PBMC_3p_gem-x_count_sample_filtered_feature_bc_matrix.h5 already exists

Create objects

Create SingleCellExperiment files.

create_sce_obj <- function(h5){
  con <- TENxH5(h5)
  import(con)
}

pbmc5k_1 <- create_sce_obj(pbmc5k_1_h5)
Warning in rhdf5::h5read(file, name = paste0(group, ranges), index = list(1L),
: Object 'matrix/features/interval' does not exist in this HDF5 file.
pbmc5k_1
class: SingleCellExperiment 
dim: 38606 5710 
metadata(1): TENxFile
assays(1): counts
rownames(38606): ENSG00000290825 ENSG00000243485 ... ENSG00000278817
  ENSG00000277196
rowData names(3): ID Symbol Type
colnames(5710): AAACCAAAGGTGACGA-1 AAACCCTGTGACGAGT-1 ...
  TGTGTTAGTCAATCGT-1 TGTGTTGAGGATCTCA-1
colData names(0):
reducedDimNames(0):
mainExpName: Gene Expression
altExpNames(0):

Seurat object.

min_cells <- 10
min_features <- 500

pbmc5k_1_seurat <- Seurat::CreateSeuratObject(
  counts = Seurat::Read10X_h5(pbmc5k_1_h5),
  min.cells = min_cells,
  min.features = min_features
)
pbmc5k_1_seurat
An object of class Seurat 
20935 features across 5672 samples within 1 assay 
Active assay: RNA (20935 features, 0 variable features)
 1 layer present: counts

Filter SingleCellExperiment object in the same way; the order and manner of filtering is important or else you can not reproduce Seurat’s behaviour.

filter_sce <- function(sce, min.features, min.cells){
  detected_genes_in_bcs <- colSums(counts(sce) > 0)
  sce <- sce[, detected_genes_in_bcs >= min.features]
  detected_genes <- rowSums(counts(sce) > 0)
  sce <- sce[detected_genes >= min.cells, ]
  sce
}

pbmc5k_1_filtered <- filter_sce(pbmc5k_1, min_features, min_cells)
pbmc5k_1_filtered
class: SingleCellExperiment 
dim: 20935 5672 
metadata(1): TENxFile
assays(1): counts
rownames(20935): ENSG00000238009 ENSG00000241860 ... ENSG00000271254
  ENSG00000278817
rowData names(3): ID Symbol Type
colnames(5672): AAACCAAAGGTGACGA-1 AAACCCTGTGACGAGT-1 ...
  TGTGTTAGTCAATCGT-1 TGTGTTGAGGATCTCA-1
colData names(0):
reducedDimNames(0):
mainExpName: Gene Expression
altExpNames(0):

Compare barcodes.

all(colnames(pbmc5k_1_seurat) == colnames(pbmc5k_1_filtered))
[1] TRUE

sessionInfo()
R version 4.4.1 (2024-06-14)
Platform: x86_64-pc-linux-gnu
Running under: Ubuntu 22.04.5 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3 
LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.20.so;  LAPACK version 3.10.0

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       

time zone: Etc/UTC
tzcode source: system (glibc)

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

other attached packages:
 [1] Seurat_5.1.0                SeuratObject_5.0.2         
 [3] sp_2.1-4                    hdf5r_1.3.11               
 [5] TENxIO_1.8.2                SingleCellExperiment_1.28.1
 [7] SummarizedExperiment_1.36.0 Biobase_2.66.0             
 [9] GenomicRanges_1.58.0        GenomeInfoDb_1.42.3        
[11] IRanges_2.40.1              S4Vectors_0.44.0           
[13] BiocGenerics_0.52.0         MatrixGenerics_1.18.1      
[15] matrixStats_1.4.1           workflowr_1.7.1            

loaded via a namespace (and not attached):
  [1] RcppAnnoy_0.0.22        splines_4.4.1           later_1.3.2            
  [4] BiocIO_1.16.0           tibble_3.2.1            R.oo_1.26.0            
  [7] polyclip_1.10-7         fastDummies_1.7.4       lifecycle_1.0.4        
 [10] rprojroot_2.0.4         globals_0.16.3          processx_3.8.4         
 [13] lattice_0.22-6          MASS_7.3-60.2           magrittr_2.0.3         
 [16] plotly_4.10.4           sass_0.4.9              rmarkdown_2.28         
 [19] jquerylib_0.1.4         yaml_2.3.10             httpuv_1.6.15          
 [22] sctransform_0.4.1       spam_2.11-0             spatstat.sparse_3.1-0  
 [25] reticulate_1.39.0       cowplot_1.1.3           pbapply_1.7-2          
 [28] RColorBrewer_1.1-3      abind_1.4-8             zlibbioc_1.52.0        
 [31] Rtsne_0.17              purrr_1.0.2             R.utils_2.12.3         
 [34] git2r_0.35.0            GenomeInfoDbData_1.2.13 ggrepel_0.9.6          
 [37] irlba_2.3.5.1           listenv_0.9.1           spatstat.utils_3.1-0   
 [40] goftest_1.2-3           RSpectra_0.16-2         spatstat.random_3.3-2  
 [43] fitdistrplus_1.2-1      parallelly_1.38.0       leiden_0.4.3.1         
 [46] codetools_0.2-20        DelayedArray_0.32.0     tidyselect_1.2.1       
 [49] UCSC.utils_1.2.0        farver_2.1.2            spatstat.explore_3.3-3 
 [52] jsonlite_1.8.9          progressr_0.15.0        ggridges_0.5.6         
 [55] survival_3.6-4          tools_4.4.1             ica_1.0-3              
 [58] Rcpp_1.0.13             glue_1.8.0              gridExtra_2.3          
 [61] SparseArray_1.6.1       BiocBaseUtils_1.8.0     xfun_0.48              
 [64] HDF5Array_1.34.0        dplyr_1.1.4             fastmap_1.2.0          
 [67] rhdf5filters_1.18.0     fansi_1.0.6             callr_3.7.6            
 [70] digest_0.6.37           R6_2.5.1                mime_0.12              
 [73] colorspace_2.1-1        scattermore_1.2         tensor_1.5             
 [76] spatstat.data_3.1-2     R.methodsS3_1.8.2       utf8_1.2.4             
 [79] tidyr_1.3.1             generics_0.1.3          data.table_1.16.2      
 [82] httr_1.4.7              htmlwidgets_1.6.4       S4Arrays_1.6.0         
 [85] whisker_0.4.1           uwot_0.2.2              pkgconfig_2.0.3        
 [88] gtable_0.3.6            lmtest_0.9-40           XVector_0.46.0         
 [91] htmltools_0.5.8.1       dotCall64_1.2           scales_1.3.0           
 [94] png_0.1-8               spatstat.univar_3.0-1   knitr_1.48             
 [97] rstudioapi_0.17.1       tzdb_0.4.0              reshape2_1.4.4         
[100] nlme_3.1-164            cachem_1.1.0            zoo_1.8-12             
[103] rhdf5_2.50.2            stringr_1.5.1           KernSmooth_2.23-24     
[106] parallel_4.4.1          miniUI_0.1.1.1          pillar_1.9.0           
[109] grid_4.4.1              vctrs_0.6.5             RANN_2.6.2             
[112] promises_1.3.0          xtable_1.8-4            cluster_2.1.6          
[115] evaluate_1.0.1          readr_2.1.5             cli_3.6.3              
[118] compiler_4.4.1          rlang_1.1.4             crayon_1.5.3           
[121] future.apply_1.11.3     ps_1.8.1                getPass_0.2-4          
[124] plyr_1.8.9              fs_1.6.4                stringi_1.8.4          
[127] viridisLite_0.4.2       deldir_2.0-4            munsell_0.5.1          
[130] lazyeval_0.2.2          spatstat.geom_3.3-3     Matrix_1.7-0           
[133] RcppHNSW_0.6.0          hms_1.1.3               patchwork_1.3.0        
[136] bit64_4.5.2             future_1.34.0           Rhdf5lib_1.28.0        
[139] ggplot2_3.5.1           shiny_1.9.1             ROCR_1.0-11            
[142] igraph_2.1.1            bslib_0.8.0             bit_4.5.0