Skip to contents

Generates phenotype prediction scores based on permuted spatial coordinates, enabling permutation-based significance testing of spatial features in glmnet models.

Usage

GeneratePermutations(
  model,
  resolution = c("spot", "single_cell"),
  coordinate = NULL,
  family = c("cox", "binomial", "gaussian"),
  r = 2,
  k = 50,
  n = 50,
  seed = 2025,
  sample_information_decon = NULL,
  sample_information_cellType = NULL
)

Arguments

model

A fitted glmnet model object, typically from cv.glmnet(), containing model and lambda.

resolution

Character; one of "spot" or "single_cell".

coordinate

A matrix or data.frame of spatial coordinates. Row names must match spot or cell IDs.

family

Character; glmnet family used for prediction ("cox", "binomial", or "gaussian").

r

Numeric; radius for neighborhood definition (used for "spot"). Default is 2.

k

Integer; number of neighbors (used for "single_cell"). Default is 50.

n

Integer; number of permutations to run. Default is 50.

seed

Integer; random seed for reproducibility. Default is 2025.

sample_information_decon

A list of spot-level cell type proportions (only used if resolution = "spot"). Each entry is a data.frame with rows as spots and columns as cell types.

sample_information_cellType

A list of single-cell annotations (only used if resolution = "single_cell"). Each entry is a character vector of cell types.

Value

A numeric vector of predicted phenotype scores from each permutation replicate.

Details

This function permutes the row names of the coordinate matrix to shuffle spatial positions, recalculates the local cell type neighborhood features via Cell_type_neighborhood(), and predicts phenotype scores using the input glmnet model. The process is repeated n times to generate a null distribution of prediction scores.

The function relies on:

  • sample_information_decon: global matrix of cell type proportions (for spot mode).

  • sample_information_cellType: global named vector of cell types (for single-cell mode).

Author

Bin Duan

Examples

if (FALSE) { # \dontrun{

data("osmFISH_bulk_decon")
data("osmFISH_bulk_pheno")
data("osmFISH_bulk_coordinate")

model <- BuildPhenoModelAutoAlpha(
  expr = osmFISH_bulk_decon,
  pheno = osmFISH_bulk_pheno,
  family = "binomial")

data("osmFISH_metadata_cellType")
perm_scores <- GeneratePermutations(
  model = model,
  resolution = "single_cell",
  coordinate = osmFISH_bulk_coordinate,
  family = "binomial",
  r = 2,
  n = 100,
  sample_information_cellType = osmFISH_metadata_cellType
)
hist(perm_scores, breaks = 20, main = "Permutation Null Distribution")
} # }