Single-cell reference mapping with Seurat method
Usage
RunSeuratMap(
srt_query,
srt_ref,
query_assay = NULL,
ref_pca = NULL,
ref_assay = srt_ref[[ref_pca]]@assay.used,
ref_dims = 1:30,
ref_umap = NULL,
ref_group = NULL,
normalization.method = "LogNormalize",
reduction_project_method = "pcaproject",
k.anchor = 5,
k.filter = 200,
k.score = 30,
k.weight = 100,
projection_method = c("model", "knn"),
nn_method = NULL,
k = 30,
distance_metric = "cosine",
vote_fun = "mean"
)
Arguments
- srt_query
An object of class Seurat storing the query cells.
- srt_ref
An object of class Seurat storing the reference cells.
- query_assay
A character string specifying the assay name for the query cells. If not provided, the default assay for the query object will be used.
- ref_pca
A character string specifying the name of the PCA reduction in the reference object to use for calculating the distance metric.
- ref_assay
A character string specifying the assay name for the reference cells. If not provided, the default assay for the reference object will be used.
- ref_dims
A numeric vector specifying the dimension indices from the reference reduction to be used for calculating the distance metric.
- ref_umap
A character string specifying the name of the UMAP reduction in the reference object. If not provided, the first UMAP reduction found in the reference object will be used.
- ref_group
A character string specifying a metadata column name in the reference object to use for grouping.
- normalization.method
The normalization method to use. Default is "LogNormalize".
- reduction_project_method
Dimensional reduction to perform when finding anchors. Default is "pcaproject".
- k.anchor
How many neighbors (k) to use when finding anchors. Default is 5.
- k.filter
How many neighbors (k) to use when filtering anchors. Set to NA to turn off filtering. Default is 200.
- k.score
How many neighbors (k) to use when scoring anchors. Default is 30.
- k.weight
Number of neighbors to consider when weighting anchors. Default is 100.
- projection_method
A character string specifying the projection method to use. Options are "model" and "knn". If "model" is selected, the function will try to use a pre-trained UMAP model in the reference object for projection. If "knn" is selected, the function will directly find the nearest neighbors using the distance metric.
- nn_method
A character string specifying the nearest neighbor search method to use. Options are "raw", "annoy", and "rann". If "raw" is selected, the function will use the brute-force method to find the nearest neighbors. If "annoy" is selected, the function will use the Annoy library for approximate nearest neighbor search. If "rann" is selected, the function will use the RANN library for approximate nearest neighbor search. If not provided, the function will choose the search method based on the size of the query and reference datasets.
- k
A number of nearest neighbors to find for each cell in the query object.
- distance_metric
A character string specifying the distance metric to use for calculating the pairwise distances between cells. Options include: "pearson", "spearman", "cosine", "correlation", "jaccard", "ejaccard", "dice", "edice", "hamman", "simple matching", and "faith". Additional distance metrics can also be used, such as "euclidean", "manhattan", "hamming", etc.
- vote_fun
A character string specifying the function to be used for aggregating the nearest neighbors in the reference object. Options are "mean", "median", "sum", "min", "max", "sd", "var", etc. If not provided, the default is "mean".
Examples
data(panc8_sub)
srt_ref <- panc8_sub[, panc8_sub$tech != "fluidigmc1"]
srt_query <- panc8_sub[, panc8_sub$tech == "fluidigmc1"]
srt_ref <- integration_scop(
srt_ref,
batch = "tech",
integration_method = "Seurat"
)
#> ℹ [2025-09-20 13:49:08] Run Seurat integration...
#> ℹ [2025-09-20 13:49:08] Spliting `srt_merge` into `srt_list` by column "tech"...
#> ℹ [2025-09-20 13:49:08] Checking a list of <Seurat> object...
#> ! [2025-09-20 13:49:08] Data 1/4 of the `srt_list` is "unknown"
#> ℹ [2025-09-20 13:49:08] Perform `NormalizeData()` with `normalization.method = 'LogNormalize'` on the data 1/4 of the `srt_list`...
#> ℹ [2025-09-20 13:49:10] Perform `Seurat::FindVariableFeatures()` on the data 1/4 of the `srt_list`...
#> ! [2025-09-20 13:49:10] Data 2/4 of the `srt_list` is "unknown"
#> ℹ [2025-09-20 13:49:10] Perform `NormalizeData()` with `normalization.method = 'LogNormalize'` on the data 2/4 of the `srt_list`...
#> ℹ [2025-09-20 13:49:12] Perform `Seurat::FindVariableFeatures()` on the data 2/4 of the `srt_list`...
#> ! [2025-09-20 13:49:12] Data 3/4 of the `srt_list` is "unknown"
#> ℹ [2025-09-20 13:49:12] Perform `NormalizeData()` with `normalization.method = 'LogNormalize'` on the data 3/4 of the `srt_list`...
#> ℹ [2025-09-20 13:49:14] Perform `Seurat::FindVariableFeatures()` on the data 3/4 of the `srt_list`...
#> ! [2025-09-20 13:49:14] Data 4/4 of the `srt_list` is "unknown"
#> ℹ [2025-09-20 13:49:14] Perform `NormalizeData()` with `normalization.method = 'LogNormalize'` on the data 4/4 of the `srt_list`...
#> ℹ [2025-09-20 13:49:16] Perform `Seurat::FindVariableFeatures()` on the data 4/4 of the `srt_list`...
#> ℹ [2025-09-20 13:49:17] Use the separate HVF from srt_list
#> ℹ [2025-09-20 13:49:17] Number of available HVF: 2000
#> ℹ [2025-09-20 13:49:17] Finished check
#> ℹ [2025-09-20 13:49:19] Perform FindIntegrationAnchors
#> Warning: Different features in new layer data than already exists for scale.data
#> Warning: Different features in new layer data than already exists for scale.data
#> Warning: Different features in new layer data than already exists for scale.data
#> Warning: Different features in new layer data than already exists for scale.data
#> ℹ [2025-09-20 13:49:38] Perform integration(Seurat)
#> Warning: Layer counts isn't present in the assay object; returning NULL
#> Warning: Different cells in new layer data than already exists for scale.data
#> Warning: Layer counts isn't present in the assay object; returning NULL
#> Warning: Different cells in new layer data than already exists for scale.data
#> Warning: Layer counts isn't present in the assay object; returning NULL
#> ℹ [2025-09-20 13:49:47] Perform ScaleData
#> ℹ [2025-09-20 13:49:47] Perform linear dimension reduction ("pca")
#> ℹ [2025-09-20 13:49:48] Perform FindClusters ("louvain")
#> ℹ [2025-09-20 13:49:48] Reorder clusters...
#> ! [2025-09-20 13:49:48] Using `Seurat::AverageExpression()` to calculate pseudo-bulk data for <Assay>
#> ℹ [2025-09-20 13:49:48] Perform nonlinear dimension reduction (umap)
#> ℹ [2025-09-20 13:49:48] Non-linear dimensionality reduction (umap) using (Seuratpca) dims (1-11) as input
#> ℹ [2025-09-20 13:49:53] Non-linear dimensionality reduction (umap) using (Seuratpca) dims (1-11) as input
#> ✔ [2025-09-20 13:49:59] Run Seurat integration done
CellDimPlot(srt_ref, group.by = c("celltype", "tech"))
#> Warning: No shared levels found between `names(values)` of the manual scale and the
#> data's fill values.
#> Warning: No shared levels found between `names(values)` of the manual scale and the
#> data's fill values.
# Projection
srt_query <- RunSeuratMap(
srt_query = srt_query,
srt_ref = srt_ref,
ref_pca = "Seuratpca",
ref_umap = "SeuratUMAP2D",
k.weight = 50
)
#> Warning: Layer ‘data’ is empty
#> Warning: no non-missing arguments to min; returning Inf
#> Warning: no non-missing arguments to max; returning -Inf
#> Warning: no non-missing arguments to max; returning -Inf
#> ! [2025-09-20 13:50:00] Infinite values detected
#> ℹ [2025-09-20 13:50:00] Detected srt_query data type: unknown
#> ! [2025-09-20 13:50:00] Negative values detected
#> ℹ [2025-09-20 13:50:00] Detected srt_ref data type: unknown
#> ! [2025-09-20 13:50:00] Data type is unknown or different between srt_query and srt_ref.
#> ℹ [2025-09-20 13:50:00] Run FindTransferAnchors
#> Warning: No layers found matching search pattern provided
#> Projecting cell embeddings
#> Finding neighborhoods
#> Finding anchors
#> Found 25 anchors
#> Filtering anchors
#> Retained 25 anchors
#> Requested to reuse weights matrix, but no weights found. Computing new weights.
#> Warning: Layer counts isn't present in the assay object; returning NULL
#> Warning: Layer counts isn't present in the assay object; returning NULL
#>
#> Integrating dataset 2 with reference dataset
#> Warning: Number of anchors is less than k.weight. Lowering k.weight for sample pair.
#> Finding integration vectors
#> Finding integration vector weights
#> Error in FindWeights(object = merged.obj, integration.name = integration.name, reduction = dr.weights, dims = dims, k = k.weight, sd.weight = sd.weight, eps = eps, verbose = verbose): Number of anchor cells is less than k.weight. Consider lowering k.weight to less than 5 or increase k.anchor.
ProjectionPlot(
srt_query = srt_query,
srt_ref = srt_ref,
query_group = "celltype",
ref_group = "celltype"
)
#> Error in srt_query[[query_reduction]]: ‘ref.embeddings’ not found in this Seurat object
#>