Last updated: 2026-07-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 1d3a283. 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/SC3pv3_GEX_Human_PBMC_filtered_feature_bc_matrix.h5
Untracked: data/SC3pv3_GEX_Human_PBMC_raw_feature_bc_matrix.h5
Untracked: data/SeuratObj.rds
Untracked: data/arab.rds
Untracked: data/astronomicalunit.csv
Untracked: data/azimuth_pbmc/
Untracked: data/davetang039sblog.WordPress.2026-02-12.xml
Untracked: data/femaleMiceWeights.csv
Untracked: data/lung_bcell.rds
Untracked: data/tmp/
Untracked: m3/
Untracked: output/decontx_corrected.rds
Untracked: output/dropletutils_cells.rds
Untracked: output/soupx_corrected.rds
Untracked: posts/
Untracked: women.json
Unstaged changes:
Modified: analysis/isoform_switch_analyzer.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/azimuth.Rmd) and HTML
(docs/azimuth.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 | 1d3a283 | Dave Tang | 2026-07-31 | Running Azimuth on pbmc3k and explaining the steps |
| html | 6c3efd8 | Dave Tang | 2026-07-31 | Build site. |
| Rmd | 43ca580 | Dave Tang | 2026-07-31 | Checking out an Azimuth model |
Azimuth provides a reference and a query cell is placed individually on this reference, and then labelled by a weighted vote using the reference cells it lands near.
Install as per the official instructions.
if (!requireNamespace('remotes', quietly = TRUE)) {
install.packages('remotes')
}
remotes::install_github('satijalab/azimuth', ref = 'master')
We will examine the Human PBMC reference that has been downloaded using zenodo_get.
zenodo_get -r 4546839
An Azimuth model holds two files:
ref.Rds, a Seurat object carrying the reference cells,
their labels and a precomputed dimensional
reductionidx.annoy, an approximate nearest neighbor index over
that reduction.azimuth_model <- paste0("data/azimuth_pbmc/")
stopifnot(dir.exists(azimuth_model))
RunAzimuth() calls
Azimuth:::LoadReference() internally; we will call the same
function directly. It accepts a local directory or a URL, and returns a
list of two Seurat objects:
$map used for the annotation, and$plot a lighter copy used only for drawing the
reference UMAP.azimuth_obj <- Azimuth:::LoadReference(path = azimuth_model)
azimuth_obj
$map
An object of class Seurat
5228 features across 36433 samples within 2 assays
Active assay: refAssay (5000 features, 0 variable features)
1 layer present: data
1 other assay present: ADT
2 dimensional reductions calculated: refUMAP, refDR
$plot
An object of class Seurat
1 features across 24760 samples within 1 assay
Active assay: RNA (1 features, 0 variable features)
2 layers present: counts, data
1 dimensional reduction calculated: refUMAP
refAssay is the default assay.
ref_assay_name <- SeuratObject::DefaultAssay(azimuth_obj$map)
ref_assay_name
[1] "refAssay"
We already saw above that there are 5,000 features.
all_features <- rownames(azimuth_obj$map)
length(all_features)
[1] 5000
refDR is the reduction the reference was built with. Its
feature loadings define the coordinate system query cells are projected
into, so its rownames are the genes that can influence where a query
cell lands.
refdr_loadings <- SeuratObject::Loadings(azimuth_obj$map[["refDR"]])
refdr_features <- rownames(refdr_loadings)
dim(refdr_loadings)
[1] 5000 50
SCTAssay.
assay_obj <- azimuth_obj$map[[ref_assay_name]]
assay_obj
SCTAssay data with 5000 features for 36433 cells, and 1 SCTModel(s)
First 10 features:
S100A9, GNLY, S100A8, LYZ, IGKC, NKG7, IGLC2, IGHM, PPBP, CCL5
all(row.names(assay_obj) == all_features)
[1] TRUE
The labels Azimuth can transfer are simply the reference’s metadata columns.
head(azimuth_obj$map@meta.data)
celltype.l1 celltype.l2 celltype.l3 ori.index
L1_AAACGAATCCTCACCA other T gdT gdT_3 27
L1_AAACGCTAGAGCATTA CD8 T CD8 TEM CD8 TEM_2 30
L1_AAACGCTCAACGATCT CD8 T CD8 TCM CD8 TCM_1 35
L1_AAACGCTGTGCTCGTG other T dnT dnT_2 40
L1_AAACGCTTCTTGGTCC B B intermediate B intermediate lambda 42
L1_AAAGAACCAAGCGGAT CD4 T CD4 TCM CD4 TCM_3 46
nCount_refAssay nFeature_refAssay
L1_AAACGAATCCTCACCA 0 0
L1_AAACGCTAGAGCATTA 0 0
L1_AAACGCTCAACGATCT 0 0
L1_AAACGCTGTGCTCGTG 0 0
L1_AAACGCTTCTTGGTCC 0 0
L1_AAAGAACCAAGCGGAT 0 0
Neighbour names.
neighbour_names <- names(methods::slot(azimuth_obj$map, "neighbors"))
neighbour_names
[1] "refdr.annoy.neighbors"
Directly import from my server.
pbmc3k <- readRDS(url("https://davetang.org/file/pbmc3k_seurat.rds", "rb"))
pbmc3k
An object of class Seurat
32738 features across 2700 samples within 1 assay
Active assay: RNA (32738 features, 0 variable features)
1 layer present: counts
RunAzimuth() is a wrapper around the entire mapping
pipeline, so a single call does everything from loading the reference to
writing the predicted labels back into the query object. The messages it
prints are a running commentary of those steps.
pbmc3k_anno <- Azimuth::RunAzimuth(query = pbmc3k, reference = azimuth_model)
Warning: Overwriting miscellanous data for model
Warning: Adding a dimensional reduction (refUMAP) without the associated assay
being present
Warning: Adding a dimensional reduction (refUMAP) without the associated assay
being present
detected inputs from HUMAN with id type Gene.name
reference rownames detected HUMAN with id type Gene.name
Normalizing query using reference SCT model
Warning: No layers found matching search pattern provided
Warning: 952 features of the features specified were not present in both the reference query assays.
Continuing with remaining 4048 features.
Only one SCT model detected; no need to select.
Projecting cell embeddings
Finding query neighbors
Finding neighborhoods
Finding anchors
Found 3015 anchors
Finding integration vectors
Finding integration vector weights
Predicting cell labels
Predicting cell labels
Warning: Feature names cannot have underscores ('_'), replacing with dashes
('-')
Predicting cell labels
Warning: Feature names cannot have underscores ('_'), replacing with dashes
('-')
Integrating dataset 2 with reference dataset
Finding integration vectors
Integrating data
Warning: Keys should be one or more alphanumeric characters followed by an
underscore, setting key from integrated_dr_ to integrateddr_
Computing nearest neighbors
Warning: The default method for RunUMAP has changed from calling Python UMAP via reticulate to the R-native UWOT using the cosine metric
To use Python UMAP via reticulate, set umap.method to 'umap-learn' and metric to 'correlation'
This message will be shown once per session
Running UMAP projection
Warning in RunUMAP.default(object = neighborlist, reduction.model =
reduction.model, : Number of neighbors between query and reference is not equal
to the number of neighbors within reference
02:36:00 Read 2700 rows
02:36:00 Processing block 1 of 1
02:36:00 Commencing smooth kNN distance calibration using 1 thread with target n_neighbors = 20
02:36:00 Initializing by weighted average of neighbor coordinates using 1 thread
02:36:00 Commencing optimization for 67 epochs, with 54000 positive edges
02:36:01 Finished
Warning: No assay specified, setting assay as RNA by default.
Projecting reference PCA onto query
Finding integration vector weights
Projecting back the query cells into original PCA space
Finding integration vector weights
Computing scores:
Finding neighbors of original query cells
Finding neighbors of transformed query cells
Computing query SNN
Determining bandwidth and computing transition probabilities
Total elapsed time: 1.89865231513977
pbmc3k_anno
An object of class Seurat
32833 features across 2700 samples within 4 assays
Active assay: RNA (32738 features, 0 variable features)
1 layer present: counts
3 other assays present: prediction.score.celltype.l1, prediction.score.celltype.l2, prediction.score.celltype.l3
2 dimensional reductions calculated: integrated_dr, ref.umap
The first three warnings come from LoadReference(),
the function we called ourselves above.
Overwriting miscellanous data for model is
bookkeeping as the stored SCT model is attached to
refAssay
Adding a dimensional reduction (refUMAP) without the associated assay being present
appears once for $map and once for $plot
because the trimmed objects keep the UMAP coordinates but not the assay
the UMAP was originally computed from.
detected inputs from HUMAN with id type Gene.name
and the matching line for the reference are Azimuth checking that both
objects use the same species and the same flavour of gene
identifier.
Normalizing query using reference SCT model is the
key step for comparability: rather than fitting a fresh SCTransform
model on pbmc3k, Azimuth computes the query’s Pearson
residuals using the gene-level regression parameters that were fit on
the reference, putting query and reference values on a common
scale.
No layers found matching search pattern provided is
Seurat v5 layer bookkeeping. The feature message tells us that of the
reference’s 5,000 SCT features, 952 are absent from pbmc3k,
so the mapping proceeds on the 4,048 shared genes; these are the genes
from refdr_features that can actually influence where a
query cell lands.
Projecting cell embeddings multiplies the query
residuals by the refDR feature loadings. No PCA is computed
on the query; it simply inherits the reference’s coordinate
system.
Finding query neighbors /
Finding neighborhoods / Finding anchors is
FindTransferAnchors() using the idx.annoy
index to look up reference neighbours quickly. An anchor is a
query–reference cell pair that are mutual nearest neighbours in
refDR space, and 3,015 of them were found for the 2,700
query cells.
Finding integration vectors and the progress bar for
integration vector weights then decide how much each anchor
contributes to each query cell, weighted by distance.
Predicting cell labels appears three times because
the PBMC reference carries three annotation levels:
celltype.l1, celltype.l2 and
celltype.l3. For each level, the labels of the anchor
reference cells become a weighted vote, giving every query cell a score
for every possible label.
Integrating dataset 2 with reference dataset
corrects the projected query coordinates towards the reference using the
same anchors, producing the integrated_dr
reduction.
Computing nearest neighbors and
Running UMAP projection do not compute a new UMAP. They
feed the query neighbours into the reference’s saved uwot model so that
the query cells land in the reference’s existing 2D coordinates, giving
the ref.umap reduction. This is what makes query and
reference plottable on the same axes.
The final block of projecting the reference PCA onto the query,
projecting the query back into its original PCA space, then comparing
neighbourhoods is MappingScore(). It asks whether each
query cell keeps the same neighbours after a round trip through the
reference space. A cell that does is well described by the reference; a
low score hints that the cell is a type the reference does not contain,
which is worth knowing because every query cell gets a label whether or
not the reference has a sensible one for it.
The returned object has 32,833 features across 4 assays.
RNA is still the active assay with the original 32,738
genes and only a counts layer, i.e. the SCT normalisation
used internally is not handed back. The extra 95 features are the rows
of prediction.score.celltype.l1,
prediction.score.celltype.l2 and
prediction.score.celltype.l3, one row per candidate label
at that level plus a max row. The labels themselves are in
the metadata as predicted.celltype.l1,
predicted.celltype.l2 and
predicted.celltype.l3 with their matching
.score columns, alongside mapping.score.
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] future_1.75.0 Azimuth_0.5.1 shinyBS_0.65.0 Seurat_5.5.1
[5] SeuratObject_5.4.0 sp_2.2-3 lubridate_1.9.5 forcats_1.0.1
[9] stringr_1.6.0 dplyr_1.2.1 purrr_1.2.2 readr_2.1.6
[13] tidyr_1.3.2 tibble_3.3.1 ggplot2_4.0.3 tidyverse_2.0.0
[17] workflowr_1.7.2
loaded via a namespace (and not attached):
[1] fs_2.1.0 ProtGenerics_1.42.0
[3] matrixStats_1.5.0 spatstat.sparse_3.2-0
[5] bitops_1.0-9 DirichletMultinomial_1.52.0
[7] TFBSTools_1.48.0 httr_1.4.8
[9] RColorBrewer_1.1-3 tools_4.5.2
[11] sctransform_0.4.3 R6_2.6.1
[13] DT_0.34.0 lazyeval_0.2.3
[15] uwot_0.2.4 rhdf5filters_1.22.0
[17] withr_3.0.3 gridExtra_2.3.1
[19] progressr_1.0.0 cli_3.6.6
[21] Biobase_2.70.0 spatstat.explore_3.8-2
[23] fastDummies_1.7.6 EnsDb.Hsapiens.v86_2.99.0
[25] shinyjs_2.1.1 sass_0.4.10
[27] S7_0.2.2 spatstat.data_3.1-9
[29] ggridges_0.5.7 pbapply_1.7-4
[31] Rsamtools_2.26.0 parallelly_1.48.0
[33] BSgenome_1.78.0 rstudioapi_0.18.0
[35] RSQLite_3.53.3 generics_0.1.4
[37] BiocIO_1.20.0 gtools_3.9.5
[39] ica_1.0-3 spatstat.random_3.5-1
[41] googlesheets4_1.1.2 Matrix_1.7-4
[43] S4Vectors_0.48.1 abind_1.4-8
[45] lifecycle_1.0.5 whisker_0.4.1
[47] yaml_2.3.12 SummarizedExperiment_1.40.0
[49] rhdf5_2.54.1 SparseArray_1.10.10
[51] Rtsne_0.17 grid_4.5.2
[53] blob_1.3.0 promises_1.5.0
[55] shinydashboard_0.7.3 crayon_1.5.3
[57] pwalign_1.6.0 miniUI_0.1.2
[59] lattice_0.22-7 cowplot_1.2.0
[61] GenomicFeatures_1.62.0 cigarillo_1.0.0
[63] KEGGREST_1.50.0 pillar_1.11.1
[65] knitr_1.51 GenomicRanges_1.62.1
[67] rjson_0.2.23 future.apply_1.20.2
[69] codetools_0.2-20 fastmatch_1.1-8
[71] glue_1.8.1 getPass_0.2-4
[73] spatstat.univar_3.2-0 data.table_1.18.4
[75] vctrs_0.7.3 png_0.1-9
[77] spam_2.11-4 cellranger_1.1.0
[79] gtable_0.3.6 cachem_1.1.0
[81] xfun_0.60 Signac_1.17.1
[83] S4Arrays_1.10.1 mime_0.13
[85] Seqinfo_1.0.0 survival_3.8-3
[87] gargle_1.6.1 RcppRoll_0.3.2
[89] fitdistrplus_1.2-6 ROCR_1.0-12
[91] nlme_3.1-168 bit64_4.8.2
[93] RcppAnnoy_0.0.23 GenomeInfoDb_1.46.2
[95] rprojroot_2.1.1 bslib_0.11.0
[97] irlba_2.3.7 KernSmooth_2.23-26
[99] otel_0.2.0 SeuratDisk_0.0.0.9021
[101] seqLogo_1.76.0 BiocGenerics_0.56.0
[103] DBI_1.3.0 tidyselect_1.2.1
[105] processx_3.8.6 bit_4.6.0
[107] compiler_4.5.2 curl_7.1.0
[109] git2r_0.36.2 hdf5r_1.3.12
[111] DelayedArray_0.36.1 plotly_4.12.1
[113] rtracklayer_1.70.1 scales_1.4.0
[115] caTools_1.18.4 lmtest_0.9-40
[117] callr_3.7.6 rappdirs_0.3.4
[119] digest_0.6.39 goftest_1.2-3
[121] presto_1.0.0 spatstat.utils_3.2-4
[123] rmarkdown_2.31 XVector_0.50.0
[125] htmltools_0.5.9 pkgconfig_2.0.3
[127] sparseMatrixStats_1.22.0 MatrixGenerics_1.22.0
[129] fastmap_1.2.0 ensembldb_2.34.0
[131] rlang_1.3.0 htmlwidgets_1.6.4
[133] UCSC.utils_1.6.1 shiny_1.14.0
[135] farver_2.1.2 jquerylib_0.1.4
[137] zoo_1.8-15 jsonlite_2.0.0
[139] BiocParallel_1.44.0 RCurl_1.98-1.19
[141] magrittr_2.0.5 dotCall64_1.2
[143] patchwork_1.3.2 Rhdf5lib_1.32.0
[145] Rcpp_1.1.2 reticulate_1.46.0
[147] stringi_1.8.7 MASS_7.3-65
[149] plyr_1.8.9 parallel_4.5.2
[151] listenv_1.0.0 ggrepel_0.9.8
[153] deldir_2.0-4 Biostrings_2.78.0
[155] splines_4.5.2 tensor_1.5.1
[157] hms_1.1.4 BSgenome.Hsapiens.UCSC.hg38_1.4.5
[159] ps_1.9.1 igraph_2.3.3
[161] spatstat.geom_3.8-2 RcppHNSW_0.7.0
[163] reshape2_1.4.5 stats4_4.5.2
[165] TFMPvalue_1.0.0 XML_3.99-0.23
[167] evaluate_1.0.5 JASPAR2020_0.99.10
[169] tzdb_0.5.0 httpuv_1.6.17
[171] RANN_2.6.2 polyclip_1.10-7
[173] SeuratData_0.2.2.9002 scattermore_1.2
[175] xtable_1.8-8 restfulr_0.0.17
[177] AnnotationFilter_1.34.0 RSpectra_0.16-2
[179] later_1.4.8 googledrive_2.1.2
[181] viridisLite_0.4.3 memoise_2.0.1
[183] AnnotationDbi_1.72.0 GenomicAlignments_1.46.0
[185] IRanges_2.44.0 cluster_2.1.8.1
[187] timechange_0.4.0 globals_0.19.1