View source: R/countInteractions.R
countInteractions | R Documentation |
Function to calculate the average number of neighbors B that a cell of type A has using different approaches.
countInteractions(
object,
group_by,
label,
colPairName,
method = c("classic", "histocat", "patch"),
patch_size = NULL
)
object |
a |
group_by |
a single character indicating the |
label |
single character specifying the |
colPairName |
single character indicating the |
method |
which cell-cell interaction counting method to use (see details) |
patch_size |
if |
a DataFrame containing one row per group_by
entry and unique
label
entry combination (from_label
, to_label
). The
ct
entry stores the interaction count as described in the details.
NA
is returned if a certain label is not present in this grouping
level.
In principle, the countInteractions
function counts the number
of edges (interactions) between each set of unique entries in
colData(object)[[label]]
. Simplified, it counts for each cell of
type A the number of neighbors of type B.
This count is averaged within each unique entry
colData(object)[[group_by]]
in three different ways:
1. method = "classic"
: The count is divided by the total number of
cells of type A. The final count can be interpreted as "How many neighbors
of type B does a cell of type A have on average?"
2. method = "histocat"
: The count is divided by the number of cells
of type A that have at least one neighbor of type B. The final count can be
interpreted as "How many many neighbors of type B has a cell of type A on
average, given it has at least one neighbor of type B?"
3. method = "patch"
: For each cell, the count is binarized to 0
(less than patch_size
neighbors of type B) or 1 (more or equal to
patch_size
neighbors of type B). The binarized counts are averaged
across all cells of type A. The final count can be interpreted as "What
fraction of cells of type A have at least a given number of neighbors of
type B?"
Vito Zanotelli
Jana Fischer
adapted by Nils Eling (nils.eling@dqbm.uzh.ch)
testInteractions
for testing cell-cell
interactions per grouping level.
library(cytomapper)
data(pancreasSCE)
pancreasSCE <- buildSpatialGraph(pancreasSCE, img_id = "ImageNb",
type = "knn", k = 3)
# Classic style calculation
(out <- countInteractions(pancreasSCE,
group_by = "ImageNb",
label = "CellType",
method = "classic",
colPairName = "knn_interaction_graph"))
# Histocat style calculation
(out <- countInteractions(pancreasSCE,
group_by = "ImageNb",
label = "CellType",
method = "histocat",
colPairName = "knn_interaction_graph"))
# Patch style calculation
(out <- countInteractions(pancreasSCE,
group_by = "ImageNb",
label = "CellType",
method = "patch",
patch_size = 3,
colPairName = "knn_interaction_graph"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.