aggregateNeighbors: Function to aggregate all neighbors of each cell.

View source: R/aggregateNeighbors.R

aggregateNeighborsR Documentation

Function to aggregate all neighbors of each cell.

Description

Function to summarize categorical or expression values of all neighbors of each cell.

Usage

aggregateNeighbors(
  object,
  colPairName,
  aggregate_by = c("metadata", "expression"),
  count_by = NULL,
  proportions = TRUE,
  assay_type = NULL,
  subset_row = NULL,
  statistic = c("mean", "median", "sd", "var"),
  name = NULL
)

Arguments

object

a SingleCellExperiment or SpatialExperiment object

colPairName

single character indicating the colPair(object) entry containing the neighbor information.

aggregate_by

character specifying whether the neighborhood should be summarized by cellular features stored in colData(object) (aggregate_by = "metdata") or by marker expression of the neighboring cells (aggregate_by = "expression").

count_by

for summarize_by = "metadata", a single character specifying the colData(object) entry containing the cellular metadata that should be summarized across each cell's neighborhood.

proportions

single logical indicating whether aggregated metadata should be returned in form of proportions instead of absolute counts.

assay_type

for summarize_by = "expression", single character indicating the assay slot to use.

subset_row

for summarize_by = "expression", an integer, logical or character vector specifying the features to use. If NULL, defaults to all features.

statistic

for summarize_by = "expression", a single character specifying the statistic to be used for summarizing the expression values across all neighboring cells. Supported entries are "mean", "median", "sd", "var". Defaults to "mean" if not specified.

name

single character specifying the name of the data frame to be saved in the colData(object). Defaults to "aggregatedNeighbors" when summarize_by = "metadata" or "statistic_aggregatedExpression" when summarize_by = "expression".

Value

returns an object of class(object) containing the aggregated values in form of a DataFrame object in colData(object)[[name]].

Author(s)

Daniel Schulz (daniel.schulz@uzh.ch)

Examples

library(cytomapper)
data(pancreasSCE)

sce <- buildSpatialGraph(pancreasSCE, img_id = "ImageNb", 
                         type = "knn", k = 3)
                         
# Aggregating neighboring cell-types
sce <- aggregateNeighbors(sce, colPairName = "knn_interaction_graph",
                         aggregate_by = "metadata",
                         count_by = "CellType")
sce$aggregatedNeighbors

# Aggregating neighboring expression values
sce <- aggregateNeighbors(sce, colPairName = "knn_interaction_graph",
                         aggregate_by = "expression",
                         assay_type = "exprs",
                         statistic = "mean")
sce$mean_aggregatedExpression
  

BodenmillerGroup/imcRtools documentation built on Oct. 30, 2024, 12:19 p.m.