Last updated: 2026-03-31

Checks: 7 0

Knit directory: muse/

This reproducible R Markdown analysis was created with workflowr (version 1.7.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(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 6890ab3. 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/97516b79-8d08-46a6-b329-5d0a25b0be98.h5ad
    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.csv
    Ignored:    data/pbmc3k.csv.gz
    Ignored:    data/pbmc3k.h5ad
    Ignored:    data/pbmc3k/
    Ignored:    data/pbmc3k_bpcells_mat/
    Ignored:    data/pbmc3k_export.mtx
    Ignored:    data/pbmc3k_matrix.mtx
    Ignored:    data/pbmc3k_seurat.rds
    Ignored:    data/pbmc4k_filtered_gene_bc_matrices.tar.gz
    Ignored:    data/pbmc_1k_v3_filtered_feature_bc_matrix.h5
    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.5.2/

Untracked files:
    Untracked:  .claude/
    Untracked:  CLAUDE.md
    Untracked:  analysis/.claude/
    Untracked:  analysis/aucc.Rmd
    Untracked:  analysis/bimodal.Rmd
    Untracked:  analysis/bioc.Rmd
    Untracked:  analysis/bioc_scrnaseq.Rmd
    Untracked:  analysis/chick_weight.Rmd
    Untracked:  analysis/likelihood.Rmd
    Untracked:  analysis/modelling.Rmd
    Untracked:  analysis/sampleqc.Rmd
    Untracked:  analysis/wordpress_readability.Rmd
    Untracked:  bpcells_matrix/
    Untracked:  data/Caenorhabditis_elegans.WBcel235.113.gtf.gz
    Untracked:  data/GCF_043380555.1-RS_2024_12_gene_ontology.gaf.gz
    Untracked:  data/SeuratObj.rds
    Untracked:  data/arab.rds
    Untracked:  data/astronomicalunit.csv
    Untracked:  data/davetang039sblog.WordPress.2026-02-12.xml
    Untracked:  data/femaleMiceWeights.csv
    Untracked:  data/lung_bcell.rds
    Untracked:  m3/
    Untracked:  women.json

Unstaged changes:
    Modified:   analysis/isoform_switch_analyzer.Rmd
    Modified:   analysis/linear_models.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/xcell2.Rmd) and HTML (docs/xcell2.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 6890ab3 Dave Tang 2026-03-31 Cell Type Enrichment Analysis with xCell2

xCell2 provides methods for cell type enrichment analysis using cell type signatures. Cell type enrichment analysis and cellular deconvolution are computational techniques aimed at deciphering the cellular heterogeneity in bulk transcriptomics samples.

xCell2 is the successor to the original xCell package (Aran et al., 2017). It leverages the Cell Ontology to map hierarchical relationships between cell types and applies spillover correction to address overlapping signature genes.

Installation

Install xCell2.

options(repos = c(CRAN = "https://cloud.r-project.org"))
if (!require("BiocManager", quietly = TRUE))
    install.packages("BiocManager")

BiocManager::install("xCell2")

Reference data

Use pre-trained references from the xCell2 References Repository.

bpe_github_pages <- "https://dviraran.github.io/xCell2refs/references/BlueprintEncode.xCell2Ref.rds"
bpe_github       <- "https://github.com/dviraran/xCell2refs/raw/refs/heads/main/references/BlueprintEncode.xCell2Ref.rds"

BlueprintEncode.xCell2Ref <- readRDS(url(bpe_github_pages, 'rb'))
test <- readRDS(url(bpe_github, 'rb'))

identical(BlueprintEncode.xCell2Ref, test)
[1] TRUE

Class.

class(BlueprintEncode.xCell2Ref)
[1] "xCell2Object"
attr(,"package")
[1] "xCell2"

Structure.

str(BlueprintEncode.xCell2Ref, max.level = 2)
Formal class 'xCell2Object' [package "xCell2"] with 5 slots
  ..@ signatures  :List of 14265
  ..@ dependencies:List of 43
  ..@ params      : tibble [43 × 5] (S3: tbl_df/tbl/data.frame)
  ..@ spill_mat   : num [1:43, 1:43] 1 0.25 0 0 0 0 0 0 0 0 ...
  .. ..- attr(*, "dimnames")=List of 2
  ..@ genes_used  : chr [1:19859] "TSPAN6" "TNMD" "DPM1" "SCYL3" ...

Calculating Cell Type Enrichment with xCell2Analysis

Check what identifiers are used.

data("DICE_demo.xCell2Ref", package = "xCell2")
genes_ref <- getGenesUsed(DICE_demo.xCell2Ref)
genes_ref[1:10]
 [1] "CD28"  "S100B" "IL2RB" "CD3E"  "KRT72" "CTLA4" "CD3D"  "GNLY"  "IL7R" 
[10] "MAL"  

Demo data.

data("mix_demo", package = "xCell2")
head(mix_demo)
        F0303   F0304   F0305
CD28   26.900  31.988  15.948
S100B  36.400  22.165  28.784
IL2RB  58.092 208.761  67.207
CD3E  182.613 251.774 156.480
KRT72  13.938  29.051  13.267
CTLA4   8.349  15.686   6.010

Calculate the percentage of overlapping genes

genes_mix <- rownames(mix_demo)
overlap_percentage <- round(length(intersect(genes_mix, genes_ref)) / length(genes_ref) * 100, 2)
print(paste0("Overlap between mixture and reference genes is: ", overlap_percentage, "%"))
[1] "Overlap between mixture and reference genes is: 100%"

Ensure the overlap is sufficient (default minimum: 90%). You can adjust this threshold in xCell2Analysis using the minSharedGenes parameter:

xcell2_results <- xCell2Analysis(
  mix = mix_demo,
  xcell2object = DICE_demo.xCell2Ref,
  minSharedGenes = 0.8 # Allow for a lower overlap threshold
)
Starting xCell2 Analysis...
Calculating enrichment scores for all cell types...
Performing spillover correction...
xCell2 Analysis completed successfully.
class(xcell2_results)
[1] "matrix" "array" 

Key Parameters of xCell2Analysis:

  • mix: The bulk mixture of gene expression matrix to analyze, with genes in rows and samples in columns. The gene nomenclature must match the reference, see Ensuring Gene Compatibility.
  • xcell2object: A pre-trained reference object of class xCell2Object, created using the xCell2Train function. Pre-trained references are also available for common use cases. See Using Pre-trained xCell2 References.
  • minSharedGenes: The minimum fraction of shared genes required between the bulk mixture (mix) and the reference (xcell2object). The default value is 0.9. If the overlap is insufficient, the function will terminate with an error. Adjust this threshold if necessary, but note that higher overlap ensures more reliable results. To check gene overlap, see Ensuring Gene Compatibility.
  • rawScores: A Boolean indicating whether to return raw enrichment scores (default: FALSE). Raw enrichment scores are computed directly from gene signatures without applying linear transformation or spillover correction. This option can be useful for debugging or advanced workflows.
  • spillover: A Boolean indicating whether to apply spillover correction on the enrichment scores (default: TRUE). Spillover correction addresses signature genes overlaps between closely related cell types, improving specificity. For details, see How Does xCell2 Correct Spillover?.
  • spilloverAlpha: A numeric value (default: 0.5) controlling the strength of spillover correction. Lower values apply weaker correction, while higher values apply stronger correction. Adjust this parameter based on the similarity of cell types in your reference. See Spillover Correction in xCell2.
  • BPPARAM: A BiocParallelParam instance that determines the parallelization strategy. This parameter allows you to leverage multi-core processing for faster computation. For more details, see Parallelization in xCell2.

The xCell2Analysis function return a matrix of cell type enrichment scores with the following structure:

  • Rows: Represent individual cell types found in the reference.
  • Columns: Correspond to the samples in your input mixture.
xcell2_results
                            F0303       F0304   F0305
B cells               0.006400000 0.000000000 0.00648
Monocytes             0.097510000 0.000000000 0.11778
NK cells              0.000000000 0.018030000 0.00200
T cells, CD8+         0.006057754 0.001442649 0.00000
T cells, CD4+         0.009153069 0.020716882 0.00000
T cells, CD4+, memory 0.001950000 0.009530000 0.00000
  1. Enrichment Scores Are Not Proportions:
    • While the raw enrichment scores in xCell2 undergo a linear transformation that makes them resemble proportions, they are not actual proportions.
    • The transformation ensures that scores are on a linear scale within the range of 0 to 1, but they might not sum to 1 across all cell types in a sample.
  2. Differences from Cellular Deconvolution Methods:
    • Cellular deconvolution methods typically model bulk expression data as a linear combination of all reference cell type profiles, which forces the estimated proportions to sum to 1.
    • However, this assumption is often unrealistic, as reference datasets rarely capture all cell type in a complex tissue sample. Missing cell types in the reference can lead to skewed or inaccurate proportions.
  3. Interpreting the Scale of Scores:
    • Higher scores indicate a stronger enrichment of a cell type in the corresponding sample relative to the others.
    • Use the scores to compare cell type compositions across samples and identify differences rather than report their absolute value.

sessionInfo()
R version 4.5.2 (2025-10-31)
Platform: x86_64-pc-linux-gnu
Running under: Ubuntu 24.04.4 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.26.so;  LAPACK version 3.12.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] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] xCell2_1.2.3    workflowr_1.7.2

loaded via a namespace (and not attached):
  [1] DBI_1.3.0                   httr2_1.2.2                
  [3] GSEABase_1.72.0             rlang_1.1.7                
  [5] magrittr_2.0.4              git2r_0.36.2               
  [7] otel_0.2.0                  matrixStats_1.5.0          
  [9] compiler_4.5.2              RSQLite_2.4.6              
 [11] getPass_0.2-4               reshape2_1.4.5             
 [13] png_0.1-9                   callr_3.7.6                
 [15] vctrs_0.7.2                 quadprog_1.5-8             
 [17] stringr_1.6.0               pkgconfig_2.0.3            
 [19] crayon_1.5.3                fastmap_1.2.0              
 [21] dbplyr_2.5.2                XVector_0.50.0             
 [23] promises_1.5.0              rmarkdown_2.31             
 [25] tzdb_0.5.0                  pracma_2.4.6               
 [27] graph_1.88.1                ps_1.9.1                   
 [29] purrr_1.2.1                 bit_4.6.0                  
 [31] xfun_0.57                   Rfast_2.1.5.2              
 [33] cachem_1.1.0                jsonlite_2.0.0             
 [35] progress_1.2.3              blob_1.3.0                 
 [37] later_1.4.8                 DelayedArray_0.36.0        
 [39] BiocParallel_1.44.0         parallel_4.5.2             
 [41] prettyunits_1.2.0           singscore_1.30.0           
 [43] R6_2.6.1                    RColorBrewer_1.1-3         
 [45] bslib_0.10.0                stringi_1.8.7              
 [47] limma_3.66.0                GenomicRanges_1.62.1       
 [49] jquerylib_0.1.4             Rcpp_1.1.1                 
 [51] Seqinfo_1.0.0               SummarizedExperiment_1.40.0
 [53] knitr_1.51                  readr_2.2.0                
 [55] IRanges_2.44.0              httpuv_1.6.17              
 [57] Matrix_1.7-4                tidyselect_1.2.1           
 [59] rstudioapi_0.18.0           abind_1.4-8                
 [61] yaml_2.3.12                 codetools_0.2-20           
 [63] minpack.lm_1.2-4            curl_7.0.0                 
 [65] processx_3.8.6              plyr_1.8.9                 
 [67] lattice_0.22-7              tibble_3.3.1               
 [69] S7_0.2.1                    Biobase_2.70.0             
 [71] KEGGREST_1.50.0             evaluate_1.0.5             
 [73] ontologyIndex_2.12          RcppParallel_5.1.11-2      
 [75] BiocFileCache_3.0.0         Biostrings_2.78.0          
 [77] pillar_1.11.1               BiocManager_1.30.27        
 [79] filelock_1.0.3              MatrixGenerics_1.22.0      
 [81] whisker_0.4.1               stats4_4.5.2               
 [83] generics_0.1.4              rprojroot_2.1.1            
 [85] ggplot2_4.0.2               BiocVersion_3.22.0         
 [87] S4Vectors_0.48.0            hms_1.1.4                  
 [89] scales_1.4.0                xtable_1.8-8               
 [91] glue_1.8.0                  tools_4.5.2                
 [93] AnnotationHub_4.0.0         locfit_1.5-9.12            
 [95] annotate_1.88.0             fs_2.0.1                   
 [97] XML_3.99-0.23               grid_4.5.2                 
 [99] tidyr_1.3.2                 edgeR_4.8.2                
[101] AnnotationDbi_1.72.0        SingleCellExperiment_1.32.0
[103] cli_3.6.5                   zigg_0.0.2                 
[105] rappdirs_0.3.4              S4Arrays_1.10.1            
[107] dplyr_1.2.0                 gtable_0.3.6               
[109] sass_0.4.10                 digest_0.6.39              
[111] BiocGenerics_0.56.0         SparseArray_1.10.9         
[113] farver_2.1.2                memoise_2.0.1              
[115] htmltools_0.5.9             lifecycle_1.0.5            
[117] httr_1.4.8                  statmod_1.5.1              
[119] bit64_4.6.0-1