Package 'seurust'

Title: 'Rust' Native Kernels for 'Seurat'
Description: Provides 'Rust' implementations of performance-critical 'Seurat' native routines such as log-normalization, sparse row scaling, shared nearest-neighbor graph construction, and integration helpers. Install alongside 'Seurat' to use the same function signatures with a 'Rust' backend. Builds require 'Cargo' and 'rustc' (>= 1.81); CRAN source builds include offline crate sources under 'src/rust'.
Authors: Nebil Ibrahim [aut, cre], Rahul Satija [ctb] (Original Seurat native APIs), Satija Lab and Collaborators [cph] (Original Seurat / ModularityOptimizer code)
Maintainer: Nebil Ibrahim <[email protected]>
License: MIT + file LICENSE
Version: 0.1.5
Built: 2026-09-27 08:27:12 UTC
Source: https://github.com/NebilI/seurust

Help Index


Build a shared nearest-neighbor graph

Description

Rust/extendr reimplementation matching Seurat's native API for ComputeSNN.

Usage

ComputeSNN(nn_ranked, prune)

Arguments

nn_ranked

Matrix of 1-based neighbor indices (cells x k); integer or double.

prune

Numeric threshold.

Value

A dgCMatrix SNN graph.

Author(s)

Nebil Ibrahim [email protected]


Build an SNN graph and write it to a file

Description

Rust/extendr reimplementation matching Seurat's native API for DirectSNNToFile. Computes the SNN graph as ComputeSNN does and writes its lower triangle to filename in the same tab-separated format as WriteEdgeFile.

Usage

DirectSNNToFile(nn_ranked, prune, display_progress, filename)

Arguments

nn_ranked

Matrix of 1-based neighbor indices (cells x k); integer or double.

prune

Numeric pruning threshold.

display_progress

Logical.

filename

Output path.

Value

The SNN graph as a dgCMatrix, as returned by Seurat.

Author(s)

Nebil Ibrahim [email protected]


Distances between cells and their listed neighbors

Description

Rust/extendr reimplementation matching Seurat's native API for fast_dist.

Usage

fast_dist(x, y, n)

Arguments

x, y

Numeric matrices of embeddings with the same number of columns (cells in rows).

n

A list with one element per row of x, each a vector of 1-based row indices into y. Integer and double vectors are both accepted.

Value

A list the same length (and with the same names) as n, holding the distances in the same order as the neighbor indices. An empty list if length(n) != nrow(x), matching Seurat.

Author(s)

Nebil Ibrahim [email protected]


Fast covariance of a dense matrix

Description

Rust/extendr reimplementation matching Seurat's native API for FastCov.

Usage

FastCov(mat, center = TRUE)

Arguments

mat

Numeric matrix.

center

Logical.

Value

A covariance matrix.

Author(s)

Nebil Ibrahim [email protected]


Fast cross-covariance of two dense matrices

Description

Rust/extendr reimplementation matching Seurat's native API for FastCovMats.

Usage

FastCovMats(mat1, mat2, center = TRUE)

Arguments

mat1, mat2

Numeric matrices.

center

Logical.

Value

A cross-covariance matrix.

Author(s)

Nebil Ibrahim [email protected]


Fast exp-mean of sparse matrix rows

Description

Rust/extendr reimplementation matching Seurat's native API for FastExpMean.

Usage

FastExpMean(mat, display_progress)

Arguments

mat

A dgCMatrix.

display_progress

Logical.

Value

Numeric vector.

Author(s)

Nebil Ibrahim [email protected]


Fast log variance-to-mean ratio

Description

Rust/extendr reimplementation matching Seurat's native API for FastLogVMR.

Usage

FastLogVMR(mat, display_progress)

Arguments

mat

A dgCMatrix.

display_progress

Logical.

Value

Numeric vector.

Author(s)

Nebil Ibrahim [email protected]


Fast row-bind of two dense matrices

Description

Rust/extendr reimplementation matching Seurat's native API for FastRBind.

Usage

FastRBind(mat1, mat2)

Arguments

mat1, mat2

Numeric matrices.

Value

A row-bound numeric matrix.

Author(s)

Nebil Ibrahim [email protected]


Scale and/or center sparse matrix rows

Description

Rust/extendr reimplementation matching Seurat's native API for FastSparseRowScale.

Usage

FastSparseRowScale(
  mat,
  scale = TRUE,
  center = TRUE,
  scale_max = 10,
  display_progress = TRUE
)

Arguments

mat

A dgCMatrix.

scale, center

Logical.

scale_max

Numeric.

display_progress

Logical.

Value

Dense numeric matrix.

Author(s)

Nebil Ibrahim [email protected]


Scale sparse rows with known statistics

Description

Rust/extendr reimplementation matching Seurat's native API for FastSparseRowScaleWithKnownStats.

Usage

FastSparseRowScaleWithKnownStats(
  mat,
  mu,
  sigma,
  scale = TRUE,
  center = TRUE,
  scale_max = 10,
  display_progress = TRUE
)

Arguments

mat

A dgCMatrix.

mu, sigma

Row means and sds.

scale, center

Logical.

scale_max

Numeric.

display_progress

Logical.

Value

Dense numeric matrix.

Author(s)

Nebil Ibrahim [email protected]


Find integration anchor weights

Description

Rust/extendr reimplementation matching Seurat's native API for FindWeightsC.

Usage

FindWeightsC(
  cells2,
  distances,
  anchor_cells2,
  integration_matrix_rownames,
  cell_index,
  anchor_score,
  min_dist,
  sd,
  display_progress
)

Arguments

cells2, anchor_cells2, integration_matrix_rownames

Character vectors.

distances, anchor_score, min_dist, sd

Numeric.

cell_index

Integer.

display_progress

Logical.

Value

A dgCMatrix.

Author(s)

Nebil Ibrahim [email protected]


Convert a sparse graph to neighbor lists

Description

Rust/extendr reimplementation matching Seurat's native API for GraphToNeighborHelper. Reads each row of mat (cell k's neighbors are the non-zero columns of row k), exactly like Seurat. Every row must have the same number of non-zero entries.

Usage

GraphToNeighborHelper(mat)

Arguments

mat

Sparse adjacency matrix (cells x cells), dgCMatrix or coercible.

Value

An unnamed list of two nrow(mat) x k numeric matrices: 1-based neighbor indices and the corresponding distances, both sorted by increasing distance.

Author(s)

Nebil Ibrahim [email protected]


Integrate expression using anchor weights

Description

Rust/extendr reimplementation matching Seurat's native API for IntegrateDataC.

Usage

IntegrateDataC(integration_matrix, weights, expression_cells2)

Arguments

integration_matrix, weights, expression_cells2

Sparse matrices.

Value

A dgCMatrix.

Author(s)

Nebil Ibrahim [email protected]


Log-normalize a sparse count matrix

Description

Rust/extendr reimplementation matching Seurat's native API for LogNorm.

Usage

LogNorm(data, scale_factor, display_progress = TRUE)

Arguments

data

A dgCMatrix of counts.

scale_factor

Numeric scale factor.

display_progress

Logical.

Value

A log-normalized dgCMatrix.

Author(s)

Nebil Ibrahim [email protected]

Examples

## Not run: 
library(Matrix)
mat <- sparseMatrix(i = c(1, 3, 2), j = c(1, 2, 3), x = 1:3, dims = c(3, 3))
LogNorm(mat, scale_factor = 1e4, display_progress = FALSE)

## End(Not run)

Replace columns of a sparse matrix

Description

Rust/extendr reimplementation matching Seurat's native API for ReplaceColsC.

Usage

ReplaceColsC(mat, col_idx, replacement)

Arguments

mat

A dgCMatrix.

col_idx

Integer column indices.

replacement

A dgCMatrix.

Value

A dgCMatrix.

Author(s)

Nebil Ibrahim [email protected]


Row means for dgCMatrix storage

Description

Rust/extendr reimplementation matching Seurat's native API for row_mean_dgcmatrix.

Usage

row_mean_dgcmatrix(x, i, rows, cols)

Arguments

x

Numeric values.

i

Integer row indices.

rows, cols

Dimensions.

Value

Numeric vector.

Author(s)

Nebil Ibrahim [email protected]


Row sums for dgCMatrix storage

Description

Rust/extendr reimplementation matching Seurat's native API for row_sum_dgcmatrix.

Usage

row_sum_dgcmatrix(x, i, rows, cols)

Arguments

x

Numeric values.

i

Integer row indices.

rows

Number of rows.

cols

Number of columns.

Value

Numeric vector.

Author(s)

Nebil Ibrahim [email protected]


Row variances for dgCMatrix storage

Description

Rust/extendr reimplementation matching Seurat's native API for row_var_dgcmatrix.

Usage

row_var_dgcmatrix(x, i, rows, cols)

Arguments

x

Numeric values.

i

Integer row indices.

rows, cols

Dimensions.

Value

Numeric vector.

Author(s)

Nebil Ibrahim [email protected]


Merge two sparse matrices by row names

Description

Rust/extendr reimplementation matching Seurat's native API for RowMergeMatrices. Seurat's C++ entry point only accepts row-compressed (RsparseMatrix) inputs and errors on a dgCMatrix. This version accepts either layout (or any coercible matrix) and converts to row-compressed form first; for RsparseMatrix inputs the result is identical to Seurat's.

Usage

RowMergeMatrices(mat1, mat2, mat1_rownames, mat2_rownames, all_rownames)

Arguments

mat1, mat2

Sparse matrices, preferably row-compressed (dgRMatrix); other matrix classes are coerced.

mat1_rownames, mat2_rownames, all_rownames

Character vectors.

Value

A dgCMatrix.

Author(s)

Nebil Ibrahim [email protected]


Row variances of a dense matrix

Description

Rust/extendr reimplementation matching Seurat's native API for RowVar.

Usage

RowVar(x)

Arguments

x

Numeric matrix.

Value

Numeric vector of row variances.

Author(s)

Nebil Ibrahim [email protected]


Run modularity clustering on an SNN graph

Description

Rust/extendr reimplementation matching Seurat's native API for RunModularityClusteringCpp.

Usage

RunModularityClusteringCpp(
  SNN,
  modularityFunction = 1,
  resolution = 1,
  algorithm = 1,
  nRandomStarts = 1,
  nIterations = 1,
  randomSeed = 0,
  printOutput = FALSE,
  edgefilename = ""
)

Arguments

SNN

Sparse SNN graph.

modularityFunction, algorithm, nRandomStarts, nIterations, randomSeed

Integers.

resolution

Numeric.

printOutput

Logical.

edgefilename

Optional path.

Value

Integer cluster assignments.

Author(s)

Nebil Ibrahim [email protected]


Downsample UMIs globally

Description

Rust/extendr reimplementation matching Seurat's native API for RunUMISampling.

Usage

RunUMISampling(data, sample_val, upsample = FALSE, display_progress = TRUE)

Arguments

data

A dgCMatrix.

sample_val

Numeric.

upsample

Logical.

display_progress

Logical.

Value

A dgCMatrix.

Author(s)

Nebil Ibrahim [email protected]


Downsample UMIs per cell

Description

Rust/extendr reimplementation matching Seurat's native API for RunUMISamplingPerCell.

Usage

RunUMISamplingPerCell(data, sample_val, upsample = FALSE, display_progress = TRUE)

Arguments

data

A dgCMatrix.

sample_val

Numeric.

upsample

Logical.

display_progress

Logical.

Value

A dgCMatrix.

Author(s)

Nebil Ibrahim [email protected]


Score query cells using an SNN graph

Description

Rust/extendr reimplementation matching Seurat's native API for ScoreHelper.

Usage

ScoreHelper(
  snn,
  query_pca,
  query_dists,
  corrected_nns,
  k_snn,
  subtract_first_nn,
  display_progress
)

Arguments

snn

Sparse SNN graph.

query_pca, query_dists, corrected_nns

Numeric inputs.

k_snn

Integer.

subtract_first_nn, display_progress

Logical.

Value

Numeric scores.

Author(s)

Nebil Ibrahim [email protected]


Smallest non-zero SNN distances

Description

Rust/extendr reimplementation matching Seurat's native API for SNN_SmallestNonzero_Dist.

Usage

SNN_SmallestNonzero_Dist(snn, mat, n, nearest_dist)

Arguments

snn

Sparse SNN graph.

mat

Numeric matrix.

n

Integer.

nearest_dist

Numeric vector.

Value

Numeric vector.

Author(s)

Nebil Ibrahim [email protected]


Sparse row variances

Description

Rust/extendr reimplementation matching Seurat's native API for SparseRowVar.

Usage

SparseRowVar(mat, display_progress)

Arguments

mat

A dgCMatrix.

display_progress

Logical.

Value

Numeric vector.

Author(s)

Nebil Ibrahim [email protected]


Sparse row variances given means

Description

Rust/extendr reimplementation matching Seurat's native API for SparseRowVar2.

Usage

SparseRowVar2(mat, mu, display_progress)

Arguments

mat

A dgCMatrix.

mu

Row means.

display_progress

Logical.

Value

Numeric vector.

Author(s)

Nebil Ibrahim [email protected]


Sparse row variances with clipping

Description

Rust/extendr reimplementation matching Seurat's native API for SparseRowVarStd.

Usage

SparseRowVarStd(mat, mu, sd, vmax, display_progress)

Arguments

mat

A dgCMatrix.

mu

Row means.

sd

Row sds.

vmax

Clip value.

display_progress

Logical.

Value

Numeric vector.

Author(s)

Nebil Ibrahim [email protected]


Standardize columns of a dense matrix

Description

Rust/extendr reimplementation matching Seurat's native API for Standardize.

Usage

Standardize(mat, display_progress = TRUE)

Arguments

mat

Numeric matrix.

display_progress

Logical.

Value

A numeric matrix.

Author(s)

Nebil Ibrahim [email protected]


Write SNN edges to a file

Description

Rust/extendr reimplementation matching Seurat's native API for WriteEdgeFile.

Usage

WriteEdgeFile(snn, filename, display_progress)

Arguments

snn

Sparse SNN graph.

filename

Path.

display_progress

Logical.

Value

Invisibly returns NULL.

Author(s)

Nebil Ibrahim [email protected]