| Title: | Infer Cell-Cell Communication from Spatial Transcriptomics |
|---|---|
| Description: | Identifies cell-cell communication hotspots in spatial transcriptomics data using bivariate Local Moran's I statistics on hexagonally binned cells. Provides functions for spatial weighting, ligand-receptor pair filtering, hotspot detection, and visualisation of sender-receiver cell-type interactions. |
| Authors: | Yunshun Chen [aut, cre], Lei Qin [aut], Lizhong Chen [aut] |
| Maintainer: | Yunshun Chen <[email protected]> |
| License: | GPL (>= 3) |
| Version: | 1.0.2 |
| Built: | 2026-10-11 15:25:19 UTC |
| Source: | https://github.com/chenlaboratory/blisa |
Identifies cell-cell communication hotspots in spatial transcriptomics data using bivariate Local Moran's I statistics on hexagonally binned cells. Provides functions for spatial weighting, ligand-receptor pair filtering, hotspot detection, and visualisation of sender-receiver cell-type interactions.
Maintainer: Yunshun Chen [email protected]
Authors:
Lei Qin [email protected]
Lizhong Chen
Useful links:
Report bugs at https://github.com/ChenLaboratory/blisa/issues
Generic function for running BLISA (Bivariate Local Indicator of Spatial
Association). Dispatches on the class of x:
blisa.default accepts a pre-binned gene-by-bin count
matrix and a matching bins polygon object.
blisa.SpatialExperiment accepts a cell-level
SpatialExperiment object and bins cells into hexagonal tiles
internally via hexBinCells before running the analysis.
blisa(x, ...) ## Default S3 method: blisa( x, bins, LR_df = NULL, bin_size = 50, dmax = 250, nsim = 999, p_cutoff = 0.05, min_ligand = 10, min_receptor = 10, min_cells = 1, n_cells_col = NA, annotation_col = "annotation", default_mode = "diffuse", diffuse_category = c("Secreted Signaling", "Non-protein Signaling"), species = c("human", "mouse"), genes = NULL, counts_by_group = NULL, fast = TRUE, cpu_threads = 4L, verbose = FALSE, ... ) ## S3 method for class 'SpatialExperiment' blisa( x, bin_size = 50, LR_df = NULL, group = "cell_type", genes = NULL, min_cells = 1, min_total_counts = 10, platform = c("auto", "xenium", "visium"), verbose = FALSE, ... )blisa(x, ...) ## Default S3 method: blisa( x, bins, LR_df = NULL, bin_size = 50, dmax = 250, nsim = 999, p_cutoff = 0.05, min_ligand = 10, min_receptor = 10, min_cells = 1, n_cells_col = NA, annotation_col = "annotation", default_mode = "diffuse", diffuse_category = c("Secreted Signaling", "Non-protein Signaling"), species = c("human", "mouse"), genes = NULL, counts_by_group = NULL, fast = TRUE, cpu_threads = 4L, verbose = FALSE, ... ) ## S3 method for class 'SpatialExperiment' blisa( x, bin_size = 50, LR_df = NULL, group = "cell_type", genes = NULL, min_cells = 1, min_total_counts = 10, platform = c("auto", "xenium", "visium"), verbose = FALSE, ... )
x |
A gene-by-bin count matrix (for |
... |
Additional arguments passed to the relevant method. |
bins |
An |
LR_df |
Data frame of ligand-receptor pairs with columns
|
bin_size |
Numeric. Width of each hexagonal bin in coordinate units
(e.g. microns). Passed to |
dmax |
Numeric. Maximum distance for diffuse-mode neighbours.
Default |
nsim |
Integer. Number of permutations for Moran's I significance.
Default |
p_cutoff |
Numeric. P-value threshold for High-High hotspots.
Default |
min_ligand |
Numeric. Minimum ligand count threshold. Default |
min_receptor |
Numeric. Minimum receptor count threshold.
Default |
min_cells |
Integer. Minimum number of cells per bin. For a
|
n_cells_col |
Character or |
annotation_col |
Character. Column in |
default_mode |
Character. CCC mode assigned to LR pairs whose
annotation does not match |
diffuse_category |
Character vector of annotation categories treated as diffuse signalling. |
species |
Character. Which CellChatDB to download when
|
genes |
Character vector of gene names to consider when matching
ligand-receptor pairs. Defaults to |
counts_by_group |
Named list of gene-by-bin count matrices, one per
group level (e.g. cell type), as returned by |
fast |
Logical. When |
cpu_threads |
Integer. Number of OpenMP threads used by
|
verbose |
Logical. If |
group |
Character. Column name in |
min_total_counts |
Numeric. Bins whose total counts (summed over all
genes) fall below this threshold are dropped during binning by
|
platform |
Character. |
A list; see individual method documentation for details.
An object of class blisa with four components:
Data frame of BLISA results for each LR pair, including
ccc_mode, sig_numbers, sig_index, sig_pval,
all_pval, all_lisa, all_quadrant, and original
columns from LR_df. all_quadrant is a character vector of
hotspot quadrant labels ("High-High", "Low-Low", etc.)
for every bin; non-tested bins are NA.
Bin-level sf object of hexagonal polygons.
Spatial weights list from computeSpatialWeights.
NULL unless counts_by_group is supplied,
in which case a wide data frame of interaction scores from
runCCI: rows are "Sender->Receiver" group pairs,
columns are LR pairs.
blisa(default): Method for a gene-by-bin count matrix.
blisa(SpatialExperiment): Method for a cell-level SpatialExperiment object.
For cell-level platforms (e.g. Xenium) it bins cells into hexagonal tiles
via hexBinCells; for Visium it treats each spot as a bin via
visiumSpotBins. Either way it then delegates to
blisa.default. The path is chosen by platform.
## Not run: # Download and cache the example Xenium breast cancer dataset (~21 MB) data_url <- paste0( "https://github.com/ChenLaboratory/example_data/releases/", "download/v1.0.0/spe_xenium_bc_s1rep1.rds" ) cache_dir <- tools::R_user_dir("blisa", "cache") data_file <- file.path(cache_dir, "spe_xenium_bc_s1rep1.rds") if (!file.exists(data_file)) { dir.create(cache_dir, recursive = TRUE, showWarnings = FALSE) download.file(data_url, data_file, mode = "wb") } spe <- readRDS(data_file) # blisa.SpatialExperiment method: bins cells, runs LISA, scores CCI result <- blisa(spe, bin_size = 50, group = "cell_type") result ## End(Not run)## Not run: # Download and cache the example Xenium breast cancer dataset (~21 MB) data_url <- paste0( "https://github.com/ChenLaboratory/example_data/releases/", "download/v1.0.0/spe_xenium_bc_s1rep1.rds" ) cache_dir <- tools::R_user_dir("blisa", "cache") data_file <- file.path(cache_dir, "spe_xenium_bc_s1rep1.rds") if (!file.exists(data_file)) { dir.create(cache_dir, recursive = TRUE, showWarnings = FALSE) download.file(data_url, data_file, mode = "wb") } spe <- readRDS(data_file) # blisa.SpatialExperiment method: bins cells, runs LISA, scores CCI result <- blisa(spe, bin_size = 50, group = "cell_type") result ## End(Not run)
Rolls up per-ligand-receptor (LR) pair BLISA hotspot results to the signalling
pathway level, grouping LR pairs by a pathway annotation column (e.g.
CellChatDB's pathway_name). For each pathway it returns the spots that
are hotspots for the pathway, a per-spot pathway p-value, and the LR pair
driving each spot.
blisaPathway( x, method = c("minP", "simes", "fisher"), pathway_col = "pathway_name", p_cutoff = 0.05, p_adjust = c("none", "BH") )blisaPathway( x, method = c("minP", "simes", "fisher"), pathway_col = "pathway_name", p_cutoff = 0.05, p_adjust = c("none", "BH") )
x |
A |
method |
Character. Per-spot combination: |
pathway_col |
Character. Column of |
p_cutoff |
Numeric. Significance threshold for |
p_adjust |
Character. Multiple-testing adjustment across spots for
|
The per-spot pathway p-value is computed by one of three methods:
"minP"The union of each LR pair's significant hotspot spots, with the minimum
p-value per spot. p_cutoff and p_adjust are ignored.
"simes"Per-spot Simes combination across all LR pairs
in the pathway, using the full per-spot p-values (all_pval)
restricted to the High-High co-expression direction.
Non-High-High/untested contributions are set to 1.
"fisher"As "simes" but Fisher's method.
For "simes"/"fisher", a spot is a pathway hotspot when its
combined p-value is p_cutoff (after optional p_adjust).
A blisa object whose LR_results slot is the pathway-level
table (one row per pathway, row names = pathway, ordered by
sig_numbers descending), so the standard blisa methods work directly
(plotHotspots, plotLRrank, print). The
bins and spatial_weights slots are carried over from x
(when it is a blisa object); CCI_scores is NULL. The
LR_results columns are:
Number of pathway hotspot spots.
Number of LR pairs annotated to the pathway.
List column: the hotspot spot indices.
List column: the per-spot pathway p-values.
List column: all LR pair IDs in the pathway.
List column: per spot, the LR pair(s) with the smallest contributing p-value.
## Not run: res <- blisa(spe, platform = "visium") blisaPathway(res) # min-P (original behaviour) blisaPathway(res, method = "simes", p_adjust = "BH") ## End(Not run)## Not run: res <- blisa(spe, platform = "visium") blisaPathway(res) # min-P (original behaviour) blisaPathway(res, method = "simes", p_adjust = "BH") ## End(Not run)
Builds queen (nearby) and distance-decay (diffuse) spatial weight matrices
from a bin-level sf object, excluding bins that have no neighbours.
computeSpatialWeights(bins, bin_size = 50, dmax = 250)computeSpatialWeights(bins, bin_size = 50, dmax = 250)
bins |
An |
bin_size |
Numeric. Bin spacing used to define queen adjacency
( |
dmax |
Numeric. Maximum distance for diffuse-mode neighbours. |
A list with:
Spatial weights list for nearby (queen) mode.
Spatial weights list for diffuse (distance-decay) mode.
Integer indices of bins used in queen-mode Moran.
Integer indices of bins used in diffuse-mode Moran.
Integer indices of original queen-mode isolates.
Integer indices of original diffuse-mode isolates.
Full (unsubset) neighbour list for nearby mode, indexed over all bins.
Full (unsubset) neighbour list for diffuse mode, indexed over all bins.
## Not run: set.seed(42) pts <- sf::st_as_sf( data.frame(x = runif(300, 0, 1000), y = runif(300, 0, 1000)), coords = c("x", "y"), crs = NA ) bins <- sf::st_sf( geometry = sf::st_make_grid(pts, cellsize = 100, what = "polygons", square = FALSE) ) sw <- computeSpatialWeights(bins, bin_size = 100, dmax = 300) names(sw) ## End(Not run)## Not run: set.seed(42) pts <- sf::st_as_sf( data.frame(x = runif(300, 0, 1000), y = runif(300, 0, 1000)), coords = c("x", "y"), crs = NA ) bins <- sf::st_sf( geometry = sf::st_make_grid(pts, cellsize = 100, what = "polygons", square = FALSE) ) sw <- computeSpatialWeights(bins, bin_size = 100, dmax = 300) names(sw) ## End(Not run)
Retains only LR pairs where at least one bin/spot has counts at or above
min_ligand for every ligand subunit and min_receptor for every
receptor subunit.
filterLRpairs( counts, min_ligand = 10, min_receptor = 10, LR_df = NULL, species = c("human", "mouse") )filterLRpairs( counts, min_ligand = 10, min_receptor = 10, LR_df = NULL, species = c("human", "mouse") )
counts |
Gene-by-bin count matrix (dense or sparse). Row names must be gene symbols. |
min_ligand |
Numeric. Minimum count threshold for ligand genes. At least one bin must meet or exceed this value. Default 10. |
min_receptor |
Numeric. Minimum count threshold for receptor genes. At least one bin must meet or exceed this value. Default 10. |
LR_df |
Data frame of ligand-receptor pairs with columns
|
species |
Character. Which CellChatDB to download when |
A subset of LR_df containing only pairs that pass the
expression thresholds for both ligand and receptor.
## Not run: # Supply a small custom LR_df to avoid a network download LR_df <- data.frame( ligand.symbol = c("GENE1", "GENE3"), receptor.symbol = c("GENE2", "GENE4"), annotation = c("Secreted Signaling", "ECM-Receptor"), row.names = c("LR1", "LR2") ) set.seed(1) counts <- matrix( rpois(4 * 50, lambda = c(20, 1, 5, 20)), nrow = 4, ncol = 50, dimnames = list(c("GENE1", "GENE2", "GENE3", "GENE4"), paste0("bin_", 1:50)) ) filterLRpairs(counts, min_ligand = 10, min_receptor = 10, LR_df = LR_df) ## End(Not run)## Not run: # Supply a small custom LR_df to avoid a network download LR_df <- data.frame( ligand.symbol = c("GENE1", "GENE3"), receptor.symbol = c("GENE2", "GENE4"), annotation = c("Secreted Signaling", "ECM-Receptor"), row.names = c("LR1", "LR2") ) set.seed(1) counts <- matrix( rpois(4 * 50, lambda = c(20, 1, 5, 20)), nrow = 4, ncol = 50, dimnames = list(c("GENE1", "GENE2", "GENE3", "GENE4"), paste0("bin_", 1:50)) ) filterLRpairs(counts, min_ligand = 10, min_receptor = 10, LR_df = LR_df) ## End(Not run)
Aggregates single-cell spatial data into hexagonal bins and returns a
bin-level count matrix together with a matching sf polygon object,
ready to pass directly to blisa.default.
hexBinCells( coords_df, counts_matrix, bin_size = 50, min_cells = 1, min_total_counts = 10, group = NULL, verbose = FALSE )hexBinCells( coords_df, counts_matrix, bin_size = 50, min_cells = 1, min_total_counts = 10, group = NULL, verbose = FALSE )
coords_df |
Data frame or matrix with columns |
counts_matrix |
Gene-by-cell count matrix (dense or sparse). Row names
must be gene symbols; column names must be cell IDs present in
|
bin_size |
Numeric. Approximate width of each hexagonal bin in
coordinate units (e.g. microns). Analogous to |
min_cells |
Integer. Bins containing fewer than |
min_total_counts |
Numeric. Bins whose total counts (summed over all
genes) fall below this threshold are dropped from the output, alongside
the |
group |
Factor or character vector of length |
verbose |
Logical. If |
A list with:
Gene-by-bin sparse count matrix (all cells combined).
Column i corresponds to row i of bins.
An sf object of hexagonal bin polygons with an
n_cells column recording how many cells fall in each bin and a
total_counts column recording the summed counts per bin. Row
order matches the columns of counts_matrix.
(Only when group is supplied.) A named list
of gene-by-bin sparse matrices, one per cell-type level, with the same
bin order as counts_matrix.
## Not run: set.seed(42) n <- 500 coords <- data.frame( x_centroid = runif(n, 0, 1000), y_centroid = runif(n, 0, 1000), row.names = paste0("cell_", seq_len(n)) ) counts <- Matrix::Matrix( matrix(rpois(20L * n, lambda = 5), nrow = 20L, ncol = n, dimnames = list(paste0("gene_", 1:20), paste0("cell_", seq_len(n)))), sparse = TRUE ) group <- sample(c("TypeA", "TypeB"), n, replace = TRUE) binned <- hexBinCells(coords, counts, bin_size = 100, group = group) str(binned, max.level = 1) ## End(Not run)## Not run: set.seed(42) n <- 500 coords <- data.frame( x_centroid = runif(n, 0, 1000), y_centroid = runif(n, 0, 1000), row.names = paste0("cell_", seq_len(n)) ) counts <- Matrix::Matrix( matrix(rpois(20L * n, lambda = 5), nrow = 20L, ncol = n, dimnames = list(paste0("gene_", 1:20), paste0("cell_", seq_len(n)))), sparse = TRUE ) group <- sample(c("TypeA", "TypeB"), n, replace = TRUE) binned <- hexBinCells(coords, counts, bin_size = 100, group = group) str(binned, max.level = 1) ## End(Not run)
Test if an object is a blisa object
is.blisa(x)is.blisa(x)
x |
Any R object. |
Logical.
is.blisa(list()) # FALSE is.blisa("not a blisa") # FALSEis.blisa(list()) # FALSE is.blisa("not a blisa") # FALSE
Generic function. Draws a clustered heatmap (via ComplexHeatmap)
with rows as Sender Receiver cell-type pairs and columns
as LR pairs. Row annotations colour-code the sender and receiver cell types.
plotCCI(x, ...) ## S3 method for class 'blisa' plotCCI( x, top_lr = 20, top_pairs = 30, lr_pairs = NULL, sender = NULL, receiver = NULL, colors = NULL, colours = NULL, main = NULL, ... ) ## Default S3 method: plotCCI( x, top_lr = 20, top_pairs = 30, lr_pairs = NULL, sender = NULL, receiver = NULL, colors = NULL, colours = NULL, main = NULL, ... )plotCCI(x, ...) ## S3 method for class 'blisa' plotCCI( x, top_lr = 20, top_pairs = 30, lr_pairs = NULL, sender = NULL, receiver = NULL, colors = NULL, colours = NULL, main = NULL, ... ) ## Default S3 method: plotCCI( x, top_lr = 20, top_pairs = 30, lr_pairs = NULL, sender = NULL, receiver = NULL, colors = NULL, colours = NULL, main = NULL, ... )
x |
A |
... |
Additional arguments passed to the relevant method. |
top_lr |
Integer or |
top_pairs |
Integer or |
lr_pairs |
Character vector or |
sender |
Character vector or |
receiver |
Character vector or |
colors |
Named character vector mapping cell-type names to colours,
used for the sender/receiver row annotations. When |
colours |
Alias for |
main |
Character or |
Invisibly returns the Heatmap object.
plotCCI(blisa): Method for a blisa object. Extracts
CCI_scores and delegates to plotCCI.default. Stops with an
informative error if CCI_scores is NULL.
plotCCI(default): Method for a CCI scores data frame (e.g. the
CCI_scores slot of a blisa object).
plotCCILR for a sender-by-receiver heatmap of a
single LR pair; plotCCIsummary for an aggregated
sender-by-receiver heatmap across all LR pairs.
## Not run: # Continuing from the blisa() example: # result <- blisa(spe, bin_size = 50, group = "cell_type") plotCCI(result, top_lr = 20, top_pairs = 30) ## End(Not run)## Not run: # Continuing from the blisa() example: # result <- blisa(spe, bin_size = 50, group = "cell_type") plotCCI(result, top_lr = 20, top_pairs = 30) ## End(Not run)
Generic function. Reshapes the CCI data frame into a receiver-by-sender cell-type matrix for one selected LR pair and draws a clustered heatmap.
plotCCILR(x, ...) ## S3 method for class 'blisa' plotCCILR(x, index = 1, ligand = NULL, receptor = NULL, main = NULL, ...) ## Default S3 method: plotCCILR(x, lr_pair, main = NULL, ...)plotCCILR(x, ...) ## S3 method for class 'blisa' plotCCILR(x, index = 1, ligand = NULL, receptor = NULL, main = NULL, ...) ## Default S3 method: plotCCILR(x, lr_pair, main = NULL, ...)
x |
A |
... |
Additional arguments passed to the relevant method. |
index |
Integer. Row index into |
ligand |
Character. Ligand gene symbol. When both |
receptor |
Character. Receptor gene symbol. Must be supplied together
with |
main |
Character or |
lr_pair |
Character. Column name in the CCI scores data frame
corresponding to the ligand-receptor pair to visualise
(e.g. |
A Heatmap object.
plotCCILR(blisa): Method for a blisa object. The LR pair is
selected by index (default 1, the top-ranked pair) unless both
ligand and receptor are supplied, in which case the matching
row is located automatically and index is ignored. Stops with an
informative error if CCI_scores is NULL or the selected LR
pair has no significant hotspots.
plotCCILR(default): Method for a CCI scores data frame (e.g. the
CCI_scores slot of a blisa object). The LR pair is selected
by column name via lr_pair.
plotCCI for an overview heatmap across all LR pairs;
plotCCIsummary for an aggregated sender-by-receiver heatmap.
## Not run: # Continuing from the blisa() example: # result <- blisa(spe, bin_size = 50, group = "cell_type") plotCCILR(result, index = 1) ## End(Not run)## Not run: # Continuing from the blisa() example: # result <- blisa(spe, bin_size = 50, group = "cell_type") plotCCILR(result, index = 1) ## End(Not run)
For a selected ligand-receptor pair, identifies the dominant interacting cell-type pair at each significant hotspot bin and draws a spatial map of the tissue coloured by those pairs. Receiver cells are those inside hotspot bins; sender cells are drawn from the immediate neighbourhood.
plotCCIspatial( x, counts_by_group, index = 1, ligand = NULL, receptor = NULL, top_pairs = 30 )plotCCIspatial( x, counts_by_group, index = 1, ligand = NULL, receptor = NULL, top_pairs = 30 )
x |
A |
counts_by_group |
Named list of gene-by-bin count matrices, one per
cell type. Typically the |
index |
Integer. Row index into |
ligand |
Character. Ligand gene symbol. When both |
receptor |
Character. Receptor gene symbol. Must be supplied together
with |
top_pairs |
Integer. Maximum number of distinct cell-type pairs to show
in the legend; remaining pairs are grouped as |
A ggplot object.
plotHotspots for a significance-based spatial map of
hotspot bins.
## Not run: # Continuing from the blisa() example: # result <- blisa(spe, bin_size = 50, group = "cell_type") binned <- hexBinCells( as.data.frame(SpatialExperiment::spatialCoords(spe)), SummarizedExperiment::assay(spe, "counts"), bin_size = 50, group = spe$cell_type ) plotCCIspatial(result, binned$counts_by_group, index = 1) ## End(Not run)## Not run: # Continuing from the blisa() example: # result <- blisa(spe, bin_size = 50, group = "cell_type") binned <- hexBinCells( as.data.frame(SpatialExperiment::spatialCoords(spe)), SummarizedExperiment::assay(spe, "counts"), bin_size = 50, group = spe$cell_type ) plotCCIspatial(result, binned$counts_by_group, index = 1) ## End(Not run)
Generic function. Aggregates CCI scores across all (or the top-ranked)
ligand-receptor pairs and draws a clustered receiver-by-sender heatmap, one
cell per Sender Receiver combination.
plotCCIsummary(x, ...) ## S3 method for class 'blisa' plotCCIsummary( x, top_lr = NULL, sender = NULL, receiver = NULL, agg_fun = sum, main = NULL, ... ) ## Default S3 method: plotCCIsummary( x, top_lr = NULL, sender = NULL, receiver = NULL, agg_fun = sum, main = NULL, ... )plotCCIsummary(x, ...) ## S3 method for class 'blisa' plotCCIsummary( x, top_lr = NULL, sender = NULL, receiver = NULL, agg_fun = sum, main = NULL, ... ) ## Default S3 method: plotCCIsummary( x, top_lr = NULL, sender = NULL, receiver = NULL, agg_fun = sum, main = NULL, ... )
x |
A |
... |
Additional arguments passed to the relevant method. |
top_lr |
Integer or |
sender |
Character vector or |
receiver |
Character vector or |
agg_fun |
Function used to aggregate scores across LR pairs for each
Sender |
main |
Character or |
A Heatmap object.
plotCCIsummary(blisa): Method for a blisa object. Stops with an
informative error if CCI_scores is NULL.
plotCCIsummary(default): Method for a CCI scores data frame (e.g. the
CCI_scores slot of a blisa object).
plotCCILR for a per-LR-pair version of this plot;
plotCCI for a heatmap with LR pairs as columns.
## Not run: # Continuing from the blisa() example: # result <- blisa(spe, bin_size = 50, group = "cell_type") plotCCIsummary(result) plotCCIsummary(result, top_lr = 10, agg_fun = mean) ## End(Not run)## Not run: # Continuing from the blisa() example: # result <- blisa(spe, bin_size = 50, group = "cell_type") plotCCIsummary(result) plotCCIsummary(result, top_lr = 10, agg_fun = mean) ## End(Not run)
Generic function. Plots each bin coloured by significance status: empty, non-significant, or significant hotspot (continuous gradient of -log10 p-value or 1 - p-value).
plotHotspots(x, ...) ## S3 method for class 'blisa' plotHotspots( x, index = 1, ligand = NULL, receptor = NULL, as_points = FALSE, size = 1.5, background = NULL, log_pval = TRUE, p_cutoff = NULL, spots = NULL, spot_pval = NULL, title = NULL, ... )plotHotspots(x, ...) ## S3 method for class 'blisa' plotHotspots( x, index = 1, ligand = NULL, receptor = NULL, as_points = FALSE, size = 1.5, background = NULL, log_pval = TRUE, p_cutoff = NULL, spots = NULL, spot_pval = NULL, title = NULL, ... )
x |
A |
... |
Additional arguments passed to the method. |
index |
Integer. Row index into |
ligand |
Character. Ligand gene symbol. When both |
receptor |
Character. Receptor gene symbol. Must be supplied together
with |
as_points |
Logical. If |
size |
Numeric. Point size when |
background |
A |
log_pval |
Logical. If |
p_cutoff |
Numeric or |
spots |
Integer vector or |
spot_pval |
Numeric vector. P-values for |
title |
Character or |
A ggplot object.
plotHotspots(blisa): Method for a blisa object.
## Not run: # Continuing from the blisa() example: # result <- blisa(spe, bin_size = 50, group = "cell_type") plotHotspots(result, index = 1) plotHotspots(result, index = 1, log_pval = FALSE) ## End(Not run)## Not run: # Continuing from the blisa() example: # result <- blisa(spe, bin_size = 50, group = "cell_type") plotHotspots(result, index = 1) plotHotspots(result, index = 1, log_pval = FALSE) ## End(Not run)
Generic function for ranking LR pairs. Dispatches on the class of x:
plotLRrank.blisa accepts a blisa object and uses its
LR_results slot directly.
plotLRrank.data.frame accepts the LR_results data
frame directly.
plotLRrank(x, ...) ## S3 method for class 'blisa' plotLRrank(x, top = 30, pt_size = 4, flip = FALSE, size_by = "auto", ...) ## S3 method for class 'data.frame' plotLRrank( x, top = 30, pt_size = 4, flip = FALSE, item_label = "Ligand-Receptor Pair", size_by = NULL, ... )plotLRrank(x, ...) ## S3 method for class 'blisa' plotLRrank(x, top = 30, pt_size = 4, flip = FALSE, size_by = "auto", ...) ## S3 method for class 'data.frame' plotLRrank( x, top = 30, pt_size = 4, flip = FALSE, item_label = "Ligand-Receptor Pair", size_by = NULL, ... )
x |
A |
... |
Additional arguments passed to the relevant method. |
top |
Integer or |
pt_size |
Numeric. Point size passed to |
flip |
Logical. When |
size_by |
Character or |
item_label |
Character. Axis label for the ranked items. Defaults to
|
A ggplot object.
plotLRrank(blisa): Method for a blisa object. Extracts
LR_results and delegates to plotLRrank.data.frame.
plotLRrank(data.frame): Method for a data frame of LR results (e.g. the
LR_results slot of a blisa object).
## Not run: # Continuing from the blisa() example: # result <- blisa(spe, bin_size = 50, group = "cell_type") plotLRrank(result, top = 30) plotLRrank(result, top = 20, flip = TRUE) ## End(Not run)## Not run: # Continuing from the blisa() example: # result <- blisa(spe, bin_size = 50, group = "cell_type") plotLRrank(result, top = 30) plotLRrank(result, top = 20, flip = TRUE) ## End(Not run)
Generic function for scoring cell-cell interactions. Dispatches on the
class of x:
runCCI.blisa accepts a blisa object. If
CCI_scores are already present and overwrite = FALSE
(the default), the object is returned unchanged. Set
overwrite = TRUE with a counts_by_group to recompute and
replace existing scores. If no scores exist, counts_by_group
must be supplied and scores are computed and attached.
runCCI.default performs the raw computation given a
blisa object and a counts_by_group list, returning only
the scores data frame. Used internally by runCCI.blisa and
blisa.default.
runCCI(x, ...) ## S3 method for class 'blisa' runCCI(x, counts_by_group = NULL, overwrite = FALSE, ...) ## Default S3 method: runCCI(x, counts_by_group, ...)runCCI(x, ...) ## S3 method for class 'blisa' runCCI(x, counts_by_group = NULL, overwrite = FALSE, ...) ## Default S3 method: runCCI(x, counts_by_group, ...)
x |
A |
... |
Additional arguments passed to the relevant method. |
counts_by_group |
Named list of gene-by-bin sparse count matrices, one
per group level (e.g. cell type). Typically the |
overwrite |
Logical. If |
See individual method documentation.
runCCI.blisa: the input blisa object with
CCI_scores populated (a wide data frame – rows are
"Sender->Receiver" group pairs, columns are LR pairs).
runCCI.default: a data frame with "Sender->Receiver"
row names and one column per significant LR pair containing the
interaction score 0.5 * log2(receiver * sender + 1).
runCCI(blisa): Method for a blisa object. If CCI_scores
are already present and overwrite = FALSE (the default), the object
is returned unchanged. Set overwrite = TRUE with a
counts_by_group to recompute and replace existing scores. If no
scores exist, counts_by_group must be supplied and scores are
computed and attached to x$CCI_scores.
runCCI(default): Default method. Performs the raw CCI computation and
returns only the scores data frame. Typically called internally; use
runCCI.blisa to compute and attach scores to a blisa object
in one step.
## Not run: # Continuing from the blisa() example: # result <- blisa(spe, bin_size = 50, group = "cell_type") # CCI is computed automatically when group is supplied to blisa(); # access the scores directly: head(result$CCI_scores) # Or compute / recompute scores explicitly: binned <- hexBinCells( as.data.frame(SpatialExperiment::spatialCoords(spe)), SummarizedExperiment::assay(spe, "counts"), bin_size = 50, group = spe$cell_type ) result2 <- runCCI(result, counts_by_group = binned$counts_by_group, overwrite = TRUE) ## End(Not run)## Not run: # Continuing from the blisa() example: # result <- blisa(spe, bin_size = 50, group = "cell_type") # CCI is computed automatically when group is supplied to blisa(); # access the scores directly: head(result$CCI_scores) # Or compute / recompute scores explicitly: binned <- hexBinCells( as.data.frame(SpatialExperiment::spatialCoords(spe)), SummarizedExperiment::assay(spe, "counts"), bin_size = 50, group = spe$cell_type ) result2 <- runCCI(result, counts_by_group = binned$counts_by_group, overwrite = TRUE) ## End(Not run)
Turns a 10x Visium SpatialExperiment (as produced by
scider::readVisium()) into the pre-binned inputs expected by
blisa.default, treating each Visium spot as one bin. The spot
coordinates are rebuilt from the integer array_col/array_row
indices onto an exact, de-tilted hexagonal lattice with 100 um
(spot_pitch) spacing – the standalone equivalent of
scider::realignVisium().
visiumSpotBins( spe, spot_pitch = NULL, in_tissue_only = TRUE, hexagons = TRUE, min_total_counts = 10, verbose = FALSE )visiumSpotBins( spe, spot_pitch = NULL, in_tissue_only = TRUE, hexagons = TRUE, min_total_counts = 10, verbose = FALSE )
spe |
A Visium |
spot_pitch |
Numeric or |
in_tissue_only |
Logical. Keep only spots with |
hexagons |
Logical. If |
min_total_counts |
Numeric. Drop spots whose total counts fall below
this threshold. Default |
verbose |
Logical. Print progress messages. Default |
On Visium, each spot is already a spatial bin, so no cell-to-bin aggregation
is needed (unlike hexBinCells). Because array_col
increments by 2 within a row and alternate rows shift array_col by 1,
the half-row stagger is already encoded in the indices; the lattice therefore
needs no odd/even phase correction. Only the bin centroids are used by
computeSpatialWeights; the hexagon polygons are for plotting
(they do tessellate the lattice exactly).
When array_col/array_row are absent (e.g. a
SpatialExperiment not built by scider::readVisium()), the
function falls back to using spatialCoords(spe) directly: spots are
still one bin each, but the de-tilt/exact-lattice step is skipped. In that
case, if spot_pitch is NULL, the pitch is measured from the
coordinates as the median nearest-neighbour distance. Since the physical
Visium pitch is 100 um, 100 / pitch is microns-per-unit; the
coordinates are rescaled to microns by that factor (near-identity when
they are already microns), so the returned pitch is 100 and downstream
bin_size/dmax are in microns. If you instead supply
spot_pitch, no rescaling is done and everything stays in the
coordinates' native units.
A list with:
Gene-by-spot count matrix (columns match bins).
An sf object of per-spot bins with bin_id,
n_cells (always 1), total_counts, and img_x/
img_y (the raw image-registered spot coordinates, for overlaying
plots on the H&E image) columns. Row order matches the columns of
counts_matrix.
The spot spacing used (= the recommended bin_size).
"micron", "pixel/other", or NA
(when spot_pitch was supplied) – the inferred coordinate unit.