Title: | Spatial analysis of in situ cytometry data |
---|---|
Description: | The spicyR package provides a framework for performing inference on changes in spatial relationships between pairs of cell types for cell-resolution spatial omics technologies. spicyR consists of three primary steps: (i) summarizing the degree of spatial localization between pairs of cell types for each image; (ii) modelling the variability in localization summary statistics as a function of cell counts and (iii) testing for changes in spatial localizations associated with a response variable. |
Authors: | Nicolas Canete [aut], Ellis Patrick [aut, cre], Nicholas Robertson [ctb] |
Maintainer: | Ellis Patrick <[email protected]> |
License: | GPL (>=2) |
Version: | 1.17.1 |
Built: | 2024-07-20 05:33:56 UTC |
Source: | https://github.com/bioc/spicyR |
Produces a dataframe showing L-function metric for each imageID entry.
bind(results, pairName = NULL)
bind(results, pairName = NULL)
results |
Spicy test result obtained from spicy. |
pairName |
A string specifying the pairwise interaction of interest. If NULL, all pairwise interactions are shown. |
A data.frame containing the colData related to the results.
data(spicyTest) df <- bind(spicyTest)
data(spicyTest) df <- bind(spicyTest)
Perform a simple wilcoxon-rank-sum test or t-test on the columns of a data frame
colTest(df, condition, type = NULL, feature = NULL, imageID = "imageID")
colTest(df, condition, type = NULL, feature = NULL, imageID = "imageID")
df |
A data.frame or SingleCellExperiment, SpatialExperiment |
condition |
The condition of interest |
type |
The type of test, "wilcox", "ttest" or "survival". |
feature |
Can be used to calculate the proportions of this feature for each image |
imageID |
The imageID's if presenting a SingleCellExperiment |
Proportions
# Test for an association with long-duration diabetes # This is clearly ignoring the repeated measures... data("diabetesData") diabetesData <- spicyR:::.format_data( diabetesData, "imageID", "cellType", c("x", "y"), FALSE ) props <- getProp(diabetesData) condition <- spicyR:::getImagePheno(diabetesData)$stage names(condition) <- spicyR:::getImagePheno(diabetesData)$imageID condition <- condition[condition %in% c("Long-duration", "Onset")] test <- colTest(props[names(condition), ], condition)
# Test for an association with long-duration diabetes # This is clearly ignoring the repeated measures... data("diabetesData") diabetesData <- spicyR:::.format_data( diabetesData, "imageID", "cellType", c("x", "y"), FALSE ) props <- getProp(diabetesData) condition <- spicyR:::getImagePheno(diabetesData)$stage names(condition) <- spicyR:::getImagePheno(diabetesData)$imageID condition <- condition[condition %in% c("Long-duration", "Onset")] test <- colTest(props[names(condition), ], condition)
Converts colPairs object into an abundance matrix based on number of nearby interactions for every cell type.
convPairs(cells, colPair, cellType = "cellType", imageID = "imageID")
convPairs(cells, colPair, cellType = "cellType", imageID = "imageID")
cells |
A SingleCellExperiment that contains objects in the colPairs slot. |
colPair |
The name of the object in the colPairs slot for which the dataframe is constructed from. |
cellType |
The cell type if using SingleCellExperiment. |
imageID |
The image ID if using SingleCellExperiment. |
Matrix of abundances
data("diabetesData") images <- c("A09", "A11", "A16", "A17") diabetesData <- diabetesData[ , SummarizedExperiment::colData(diabetesData)$imageID %in% images ] diabetesData_SPE <- SpatialExperiment::SpatialExperiment(diabetesData, colData = SummarizedExperiment::colData(diabetesData) ) SpatialExperiment::spatialCoords(diabetesData_SPE) <- data.frame( SummarizedExperiment::colData(diabetesData_SPE)$x, SummarizedExperiment::colData(diabetesData_SPE)$y ) |> as.matrix() SpatialExperiment::spatialCoordsNames(diabetesData_SPE) <- c("x", "y") diabetesData_SPE <- imcRtools::buildSpatialGraph(diabetesData_SPE, img_id = "imageID", type = "knn", k = 20, coords = c("x", "y") ) pairAbundances <- convPairs(diabetesData_SPE, colPair = "knn_interaction_graph" )
data("diabetesData") images <- c("A09", "A11", "A16", "A17") diabetesData <- diabetesData[ , SummarizedExperiment::colData(diabetesData)$imageID %in% images ] diabetesData_SPE <- SpatialExperiment::SpatialExperiment(diabetesData, colData = SummarizedExperiment::colData(diabetesData) ) SpatialExperiment::spatialCoords(diabetesData_SPE) <- data.frame( SummarizedExperiment::colData(diabetesData_SPE)$x, SummarizedExperiment::colData(diabetesData_SPE)$y ) |> as.matrix() SpatialExperiment::spatialCoordsNames(diabetesData_SPE) <- c("x", "y") diabetesData_SPE <- imcRtools::buildSpatialGraph(diabetesData_SPE, img_id = "imageID", type = "knn", k = 20, coords = c("x", "y") ) pairAbundances <- convPairs(diabetesData_SPE, colPair = "knn_interaction_graph" )
This is a subset of the Damond et al 2019 imaging mass cytometry dataset. The data contains cells in the pancreatic islets of individuals with early onset diabetes and healthy controls. The object contains single-cell data of 160 images from 8 subjects, with 20 images per subject.
data("diabetesData")
data("diabetesData")
diabetesData_SCE a SingleCellExperiment object
Converted into a SingleCellExperiment format.
Get statistic from pairwise L curve of a single image.
getPairwise( cells, from = NULL, to = NULL, window = "convex", window.length = NULL, Rs = c(20, 50, 100), sigma = NULL, minLambda = 0.05, edgeCorrect = TRUE, includeZeroCells = TRUE, BPPARAM = BiocParallel::SerialParam(), imageIDCol = "imageID", cellTypeCol = "cellType", spatialCoordCols = c("x", "y") )
getPairwise( cells, from = NULL, to = NULL, window = "convex", window.length = NULL, Rs = c(20, 50, 100), sigma = NULL, minLambda = 0.05, edgeCorrect = TRUE, includeZeroCells = TRUE, BPPARAM = BiocParallel::SerialParam(), imageIDCol = "imageID", cellTypeCol = "cellType", spatialCoordCols = c("x", "y") )
cells |
A SummarizedExperiment that contains at least the variables x and y, giving the location coordinates of each cell, and cellType. |
from |
The 'from' cellType for generating the L curve. |
to |
The 'to' cellType for generating the L curve. |
window |
Should the window around the regions be 'square', 'convex' or 'concave'. |
window.length |
A tuning parameter for controlling the level of concavity when estimating concave windows. |
Rs |
A vector of the radii that the measures of association should be calculated. |
sigma |
A numeric variable used for scaling when fitting inhomogeneous L-curves. |
minLambda |
Minimum value for density for scaling when fitting inhomogeneous L-curves. |
edgeCorrect |
A logical indicating whether to perform edge correction. |
includeZeroCells |
A logical indicating whether to include cells with zero counts in the pairwise association calculation. |
BPPARAM |
A BiocParallelParam object. |
imageIDCol |
The name of the imageID column if using a SingleCellExperiment or SpatialExperiment. |
cellTypeCol |
The name of the cellType column if using a SingleCellExperiment or SpatialExperiment. |
spatialCoordCols |
The names of the spatialCoords column if using a SingleCellExperiment. |
Statistic from pairwise L curve of a single image.
data("diabetesData") # Subset by imageID for fast example selected_cells <- diabetesData[ , SummarizedExperiment::colData(diabetesData)$imageID == "A09" ] pairAssoc <- getPairwise(selected_cells)
data("diabetesData") # Subset by imageID for fast example selected_cells <- diabetesData[ , SummarizedExperiment::colData(diabetesData)$imageID == "A09" ] pairAssoc <- getPairwise(selected_cells)
Get proportions from a SummarizedExperiment.
getProp(cells, feature = "cellType", imageID = "imageID")
getProp(cells, feature = "cellType", imageID = "imageID")
cells |
A SingleCellExperiment, SpatialExperiment or data.frame. |
feature |
The feature of interest |
imageID |
The imageID's |
Proportions
data("diabetesData") prop <- getProp(diabetesData)
data("diabetesData") prop <- getProp(diabetesData)
Plots result of signifPlot.
signifPlot( results, fdr = FALSE, type = "bubble", breaks = NULL, comparisonGroup = NULL, colours = c("#4575B4", "white", "#D73027"), marksToPlot = NULL, cutoff = 0.05 )
signifPlot( results, fdr = FALSE, type = "bubble", breaks = NULL, comparisonGroup = NULL, colours = c("#4575B4", "white", "#D73027"), marksToPlot = NULL, cutoff = 0.05 )
results |
Data frame obtained from spicy. |
fdr |
TRUE if FDR correction is used. |
type |
Where to make a bubble plot or heatmap. |
breaks |
Vector of 3 numbers giving breaks used in pheatmap. The first number is the minimum, the second is the maximum, the third is the number of breaks. |
comparisonGroup |
A string specifying the name of the outcome group to compare with the base group. |
colours |
Vector of colours to use in pheatmap. |
marksToPlot |
Vector of marks to include in pheatmap. |
cutoff |
significance threshold for circles in bubble plot |
a pheatmap object
data(spicyTest) p <- signifPlot(spicyTest, breaks = c(-3, 3, 0.5)) # plot includes unicode characters, do not use default pdf device ggplot2::ggsave(p, filename = tempfile(), device = cairo_pdf)
data(spicyTest) p <- signifPlot(spicyTest, breaks = c(-3, 3, 0.5)) # plot includes unicode characters, do not use default pdf device ggplot2::ggsave(p, filename = tempfile(), device = cairo_pdf)
Plots boxplot for a specified cell-cell relationship
spicyBoxPlot(results, from = NULL, to = NULL, rank = NULL)
spicyBoxPlot(results, from = NULL, to = NULL, rank = NULL)
results |
Data frame obtained from spicy. |
from |
Cell type which you would like to compare to the to cell type. |
to |
Cell type which you would like to compare to the from cell type. |
rank |
Ranking of cell type in terms of p-value, the smaller the p-value the higher the rank. |
a ggplot2 boxplot
data(spicyTest) spicyBoxPlot(spicyTest, rank = 1)
data(spicyTest) spicyBoxPlot(spicyTest, rank = 1)
Performs spatial tests on spatial cytometry data.
spicy( cells, condition, subject = NULL, covariates = NULL, from = NULL, to = NULL, imageIDCol = "imageID", cellTypeCol = "cellType", spatialCoordCols = c("x", "y"), alternateResult = NULL, verbose = FALSE, weights = TRUE, weightsByPair = FALSE, weightFactor = 1, window = "convex", window.length = NULL, BPPARAM = BiocParallel::SerialParam(), sigma = NULL, Rs = NULL, minLambda = 0.05, edgeCorrect = TRUE, includeZeroCells = FALSE, ... )
spicy( cells, condition, subject = NULL, covariates = NULL, from = NULL, to = NULL, imageIDCol = "imageID", cellTypeCol = "cellType", spatialCoordCols = c("x", "y"), alternateResult = NULL, verbose = FALSE, weights = TRUE, weightsByPair = FALSE, weightFactor = 1, window = "convex", window.length = NULL, BPPARAM = BiocParallel::SerialParam(), sigma = NULL, Rs = NULL, minLambda = 0.05, edgeCorrect = TRUE, includeZeroCells = FALSE, ... )
cells |
A SummarizedExperiment or data frame that contains at least the variables x and y, giving the location coordinates of each cell, and cellType. |
condition |
Vector of conditions to be tested corresponding to each image. |
subject |
Vector of subject IDs corresponding to each image if cells is a data frame. |
covariates |
Vector of covariate names that should be included in the mixed effects model as fixed effects. |
from |
vector of cell types which you would like to compare to the to vector |
to |
vector of cell types which you would like to compare to the from vector |
imageIDCol |
The image ID if using SingleCellExperiment. |
cellTypeCol |
The cell type if using SingleCellExperiment. |
spatialCoordCols |
The spatial coordinates if using a SingleCellExperiment. |
alternateResult |
An pairwise association statistic between each combination of celltypes in each image. |
verbose |
logical indicating whether to output messages. |
weights |
logical indicating whether to include weights based on cell counts. |
weightsByPair |
logical indicating whether weights should be calculated for each cell type pair. |
weightFactor |
numeric that controls the convexity of the weight function. |
window |
Should the window around the regions be 'square', 'convex' or 'concave'. |
window.length |
A tuning parameter for controlling the level of concavity when estimating concave windows. |
BPPARAM |
A BiocParallelParam object. |
sigma |
A numeric variable used for scaling when fitting inhomogeneous L-curves. |
Rs |
A vector of radii that the measures of association should be calculated. |
minLambda |
Minimum value for density for scaling when fitting inhomogeneous L-curves. |
edgeCorrect |
A logical indicating whether to perform edge correction. |
includeZeroCells |
A logical indicating whether to include cells with zero counts in the pairwise association calculation. |
... |
Other options. |
Data frame of p-values.
data("diabetesData") # Test with random effect for patient on a pairwise combination of cell # types. spicy(diabetesData, condition = "stage", subject = "case", from = "Tc", to = "Th" ) # Test all pairwise combinations of cell types without random effect of # patient. ## Not run: spicyTest <- spicy(diabetesData, condition = "stage", subject = "case") ## End(Not run) # Test all pairwise combination of cell types with random effect of patient. ## Not run: spicy(diabetesData, condition = "condition", subject = "subject") ## End(Not run)
data("diabetesData") # Test with random effect for patient on a pairwise combination of cell # types. spicy(diabetesData, condition = "stage", subject = "case", from = "Tc", to = "Th" ) # Test all pairwise combinations of cell types without random effect of # patient. ## Not run: spicyTest <- spicy(diabetesData, condition = "stage", subject = "case") ## End(Not run) # Test all pairwise combination of cell types with random effect of patient. ## Not run: spicy(diabetesData, condition = "condition", subject = "subject") ## End(Not run)
Results from the call: spicyTest <- spicy(diabetesData, condition = "condition", subject = "subject")
data("spicyTest")
data("spicyTest")
spicyTest a spicy object
A table of the significant results from spicy tests
topPairs(x, coef = NULL, n = 10, adj = "fdr", cutoff = NULL, figures = NULL)
topPairs(x, coef = NULL, n = 10, adj = "fdr", cutoff = NULL, figures = NULL)
x |
The output from spicy. |
coef |
Which coefficient to list. |
n |
Extract the top n most significant pairs. |
adj |
Which p-value adjustment method to use, argument for p.adjust(). |
cutoff |
A p-value threshold to extract significant pairs. |
figures |
Round to 'figures' significant figures. |
A data.frame
data(spicyTest) topPairs(spicyTest)
data(spicyTest) topPairs(spicyTest)