Skip to contents

Compute the cost matrix between single cells and spatial spots based on expression similarity. The cost matrix is used as input to the linear assignment problem solver.

Usage

compute_cost_matrix(
  sc_data,
  st_data,
  method = c("pearson", "spearman", "euclidean"),
  use_cpp = TRUE
)

Arguments

sc_data

Normalized single-cell expression matrix (genes x cells).

st_data

Normalized spatial expression matrix (genes x spots).

method

Distance/similarity metric:

"pearson"

Pearson correlation (default). Cost = -correlation.

"spearman"

Spearman rank correlation. Cost = -correlation.

"euclidean"

Euclidean distance.

use_cpp

Logical. If TRUE, use C++ implementation. Default is TRUE.

Value

A cost matrix of dimensions (n_cells x n_spots).

Details

For correlation-based methods, the cost is computed as \(-r\) where \(r\) is the correlation coefficient. This transforms the similarity measure into a cost for minimization. This matches the Python CytoSPACE implementation exactly.

Examples

if (FALSE) { # \dontrun{
cost <- compute_cost_matrix(sc_norm, st_norm, method = "pearson")
} # }