| Title: | GPU-Aware Single-Cell Analysis Workflows |
|---|---|
| Description: | Provides single-cell analysis primitives for sparse count matrices, including library-size normalization, log-normalization, highly variable feature selection, principal component analysis, and nearest-neighbour construction. Integrates the 'cudaverse' numerical and sparse layers while preserving matrix identifiers and recording the computation backend for each stage. Optional adapters preserve native 'SingleCellExperiment' and 'SeuratObject' version 5 object structures. |
| Authors: | Yaoxiang Li [aut, cre] |
| Maintainer: | Yaoxiang Li <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.4.0 |
| Built: | 2026-10-27 20:24:40 UTC |
| Source: | https://github.com/cran/cudacellr |
Construct a nearest-neighbour representation
cuda_cell_neighbors( embedding, k = 15L, metric = c("euclidean", "cosine"), device = c("auto", "cuda", "cpu"), batch_size = 256L )cuda_cell_neighbors( embedding, k = 15L, metric = c("euclidean", "cosine"), device = c("auto", "cuda", "cpu"), batch_size = 256L )
embedding |
Cell-by-component matrix or |
k |
Number of neighbours. |
metric |
Distance metric. |
device |
Computation device. |
batch_size |
Maximum query rows per exact kNN distance block. Smaller values reduce peak distance memory. |
A cuda_knn object retaining cell names from the embedding.
cuda_cell_neighbors( matrix(rnorm(60), 20, 3), k = 5, batch_size = 4, device = "cpu" )cuda_cell_neighbors( matrix(rnorm(60), 20, 3), k = 5, batch_size = 4, device = "cpu" )
Run PCA on highly variable single-cell features
cuda_cell_pca( counts, n_components = 30L, n_hvg = 2000L, scale. = TRUE, device = c("auto", "cuda", "cpu"), scale_factor = 10000, log1p = TRUE, min_mean = 0 )cuda_cell_pca( counts, n_components = 30L, n_hvg = 2000L, scale. = TRUE, device = c("auto", "cuda", "cpu"), scale_factor = 10000, log1p = TRUE, min_mean = 0 )
counts |
Feature-by-cell matrix. |
n_components |
Number of principal components. |
n_hvg |
Number of highly variable features. |
scale. |
Whether to scale selected features before PCA. |
device |
Device passed to |
scale_factor |
Target library size used during normalization. |
log1p |
Whether to apply |
min_mean |
Minimum feature mean used during highly variable feature selection. |
A cuda_pca object with an additional features element. Cell
names label PCA score rows and selected feature names label loadings.
set.seed(2) counts <- matrix(rpois(30 * 20, lambda = 2), 30, 20) cuda_cell_pca(counts, n_components = 3, n_hvg = 10, device = "cpu")set.seed(2) counts <- matrix(rpois(30 * 20, lambda = 2), 30, 20) cuda_cell_pca(counts, n_components = 3, n_hvg = 10, device = "cpu")
Select highly variable features
cuda_hvg(counts, n_top = 2000L, min_mean = 0)cuda_hvg(counts, n_top = 2000L, min_mean = 0)
counts |
Feature-by-cell count or normalized expression matrix. |
n_top |
Number of features to select. |
min_mean |
Minimum feature mean. |
A data frame ordered by dispersion with feature statistics and a
selected indicator. The index column retains the original feature
position even when feature names are duplicated.
set.seed(1) counts <- Matrix::rsparsematrix(20, 10, density = 0.3) counts@x <- abs(round(counts@x * 5)) cuda_hvg(counts, n_top = 5)set.seed(1) counts <- Matrix::rsparsematrix(20, 10, density = 0.3) counts@x <- abs(round(counts@x * 5)) cuda_hvg(counts, n_top = 5)
Counts are expected with features in rows and cells in columns.
cuda_normalize_counts(counts, scale_factor = 10000, log1p = TRUE)cuda_normalize_counts(counts, scale_factor = 10000, log1p = TRUE)
counts |
A base matrix, |
scale_factor |
Target library size. |
log1p |
Whether to apply |
A sparse Matrix::dgCMatrix with the input feature and cell names.
counts <- Matrix::Matrix(matrix(c(1, 0, 3, 2, 4, 1), 3), sparse = TRUE) cuda_normalize_counts(counts)counts <- Matrix::Matrix(matrix(c(1, 0, 3, 2, 4, 1), 3), sparse = TRUE) cuda_normalize_counts(counts)
These methods expose the shared cudaverse::cuda_provenance() contract for
SingleCellExperiment and Seurat objects produced by cudacellr.
## S3 method for class 'SingleCellExperiment' cuda_provenance(x) ## S3 method for class 'Seurat' cuda_provenance(x)## S3 method for class 'SingleCellExperiment' cuda_provenance(x) ## S3 method for class 'Seurat' cuda_provenance(x)
x |
A supported native single-cell container. |
A cuda_provenance data frame.
cudacell_sce() reads one assay, runs cudacell_workflow(), and returns a
modified copy of the input object. Existing assays, row and column
metadata, reduced dimensions, alternative experiments, pairings, and
top-level metadata are retained. New results are stored in native
SingleCellExperiment locations:
cudacell_sce( x, assay = "counts", n_hvg = 2000L, n_components = 30L, k = 15L, device = c("auto", "cuda", "cpu"), batch_size = 256L, scale_factor = 10000, log1p = TRUE, min_mean = 0, scale. = TRUE, normalized_assay = NULL, reduced_dim = "CUDACELL_PCA", col_pair = "CUDACELL_KNN", row_data_prefix = "cudacell", set_size_factors = FALSE, overwrite = FALSE, realize = FALSE )cudacell_sce( x, assay = "counts", n_hvg = 2000L, n_components = 30L, k = 15L, device = c("auto", "cuda", "cpu"), batch_size = 256L, scale_factor = 10000, log1p = TRUE, min_mean = 0, scale. = TRUE, normalized_assay = NULL, reduced_dim = "CUDACELL_PCA", col_pair = "CUDACELL_KNN", row_data_prefix = "cudacell", set_size_factors = FALSE, overwrite = FALSE, realize = FALSE )
x |
A |
assay |
Exact name of the feature-by-cell count assay. |
n_hvg |
Number of highly variable features. |
n_components |
Number of PCA components. |
k |
Number of neighbours per cell. |
device |
Computation device. |
batch_size |
Maximum query rows per exact kNN distance block. |
scale_factor |
Target library size used during normalization. |
log1p |
Whether to apply |
min_mean |
Minimum feature mean used for HVG selection. |
scale. |
Whether to scale selected features before PCA. |
normalized_assay |
Name for the added normalized assay. |
reduced_dim |
Name for the added PCA reduced dimension. |
col_pair |
Name for the added directed kNN |
row_data_prefix |
Prefix for added feature statistics and the namespaced column size factor. |
set_size_factors |
Whether to also replace the canonical
|
overwrite |
Whether explicitly named cudacellr output fields may be replaced. Other object content is never overwritten. |
realize |
Whether a delayed assay may be explicitly materialized as a
sparse |
normalized expression in an assay;
PCA scores in a reduced dimension;
highly variable feature statistics in rowData;
directed nearest-neighbour relationships in a colPair;
parameters and compute provenance in metadata(x)$cudacellr.
The selected assay must currently be a base matrix or Matrix object.
Delayed assays are never realized silently. Set realize = TRUE only after
confirming that the selected assay fits in memory.
A valid SingleCellExperiment of the same class as x.
if (requireNamespace("SingleCellExperiment", quietly = TRUE)) { counts <- matrix( rpois(30 * 12, lambda = 2), nrow = 30, dimnames = list(paste0("gene_", 1:30), paste0("cell_", 1:12)) ) sce <- SingleCellExperiment::SingleCellExperiment( assays = list(counts = counts) ) sce <- cudacell_sce( sce, n_hvg = 10, n_components = 3, k = 3, device = "cpu" ) SingleCellExperiment::reducedDim(sce, "CUDACELL_PCA") cuda_provenance(sce) }if (requireNamespace("SingleCellExperiment", quietly = TRUE)) { counts <- matrix( rpois(30 * 12, lambda = 2), nrow = 30, dimnames = list(paste0("gene_", 1:30), paste0("cell_", 1:12)) ) sce <- SingleCellExperiment::SingleCellExperiment( assays = list(counts = counts) ) sce <- cudacell_sce( sce, n_hvg = 10, n_components = 3, k = 3, device = "cpu" ) SingleCellExperiment::reducedDim(sce, "CUDACELL_PCA") cuda_provenance(sce) }
cudacell_seurat() reads one exact assay layer, runs
cudacell_workflow(), and returns a modified copy of the input object.
The full Seurat package is not required; the object contract uses
SeuratObject version 5 or newer.
cudacell_seurat( x, assay = NULL, layer = "counts", n_hvg = 2000L, n_components = 30L, k = 15L, device = c("auto", "cuda", "cpu"), batch_size = 256L, scale_factor = 10000, log1p = TRUE, min_mean = 0, scale. = TRUE, output_assay = "CUDACELL", reduction = "cudacell_pca", reduction_key = "CUDACELLPC_", neighbor = "cudacell_knn", metadata_prefix = "cudacell", overwrite = FALSE, realize = FALSE )cudacell_seurat( x, assay = NULL, layer = "counts", n_hvg = 2000L, n_components = 30L, k = 15L, device = c("auto", "cuda", "cpu"), batch_size = 256L, scale_factor = 10000, log1p = TRUE, min_mean = 0, scale. = TRUE, output_assay = "CUDACELL", reduction = "cudacell_pca", reduction_key = "CUDACELLPC_", neighbor = "cudacell_knn", metadata_prefix = "cudacell", overwrite = FALSE, realize = FALSE )
x |
A |
assay |
Exact input assay name. |
layer |
Exact feature-by-cell count layer name. |
n_hvg |
Number of highly variable features. |
n_components |
Number of PCA components. |
k |
Number of neighbours per cell. |
device |
Computation device. |
batch_size |
Maximum query rows per exact kNN distance block. |
scale_factor |
Target library size used during normalization. |
log1p |
Whether to apply |
min_mean |
Minimum feature mean used for HVG selection. |
scale. |
Whether to scale selected features before PCA. |
output_assay |
Name for the added normalized |
reduction |
Name for the added PCA |
reduction_key |
Seurat key for PCA dimensions. It must start with a letter, contain only letters or digits, and end in an underscore. |
neighbor |
Name for the added exact kNN |
metadata_prefix |
Prefix for feature statistics and the cell-level size-factor column. |
overwrite |
Whether the named cudacellr output fields may be replaced. Other object state is never overwritten. |
realize |
Whether a non-memory-backed layer may be explicitly
materialized as a sparse |
Results are stored in native, namespaced locations:
normalized expression and feature statistics in a new Assay5;
PCA embeddings and loadings in a DimReduc;
exact kNN indices and distances in a Neighbor;
library-size factors in cell metadata;
parameters and compute provenance in the cudacell_seurat tool record.
Existing assays and layers, reductions, graphs, neighbours, identities,
cell metadata, images, commands, miscellaneous data, and tool records are
retained. Every output collision is checked before device selection or
computation. overwrite = TRUE replaces only the explicitly named
cudacellr outputs.
Feature metadata use the requested prefix. <prefix>_hvg_rank is the
one-based global dispersion rank across all input features;
<prefix>_hvg identifies the selected top n_hvg features.
Non-memory-backed layers are never realized silently. Set realize = TRUE
only after confirming that the selected layer fits in memory. The selected
layer must contain every object cell in the same order.
A valid Seurat object. The input object is not modified.
if (requireNamespace("SeuratObject", quietly = TRUE)) { counts <- Matrix::Matrix( matrix( rpois(30 * 12, lambda = 2), nrow = 30, dimnames = list( paste0("gene_", 1:30), paste0("cell_", 1:12) ) ), sparse = TRUE ) object <- SeuratObject::CreateSeuratObject(counts) object <- cudacell_seurat( object, n_hvg = 10, n_components = 3, k = 3, device = "cpu" ) SeuratObject::Embeddings(object[["cudacell_pca"]]) cuda_provenance(object) }if (requireNamespace("SeuratObject", quietly = TRUE)) { counts <- Matrix::Matrix( matrix( rpois(30 * 12, lambda = 2), nrow = 30, dimnames = list( paste0("gene_", 1:30), paste0("cell_", 1:12) ) ), sparse = TRUE ) object <- SeuratObject::CreateSeuratObject(counts) object <- cudacell_seurat( object, n_hvg = 10, n_components = 3, k = 3, device = "cpu" ) SeuratObject::Embeddings(object[["cudacell_pca"]]) cuda_provenance(object) }
Run the initial cudacellr workflow
cudacell_workflow( counts, n_hvg = 2000L, n_components = 30L, k = 15L, device = c("auto", "cuda", "cpu"), batch_size = 256L, scale_factor = 10000, log1p = TRUE, min_mean = 0, scale. = TRUE )cudacell_workflow( counts, n_hvg = 2000L, n_components = 30L, k = 15L, device = c("auto", "cuda", "cpu"), batch_size = 256L, scale_factor = 10000, log1p = TRUE, min_mean = 0, scale. = TRUE )
counts |
Feature-by-cell count matrix. |
n_hvg |
Number of variable features. |
n_components |
PCA components. |
k |
Neighbours per cell. |
device |
Computation device. |
batch_size |
Maximum query rows per exact kNN distance block. |
scale_factor |
Target library size used during normalization. |
log1p |
Whether to apply |
min_mean |
Minimum feature mean used during highly variable feature selection. |
scale. |
Whether to scale selected features before PCA. |
A list containing normalized counts, variable features, PCA, and kNN. Feature and cell identifiers are retained throughout all stages.
set.seed(3) counts <- matrix(rpois(40 * 25, 2), 40, 25) cudacell_workflow( counts, n_hvg = 15, n_components = 5, k = 5, device = "cpu" )set.seed(3) counts <- matrix(rpois(40 * 25, 2), 40, 25) cudacell_workflow( counts, n_hvg = 15, n_components = 5, k = 5, device = "cpu" )