diff --git a/NAMESPACE b/NAMESPACE index 9110046..988aff8 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -10,8 +10,10 @@ export(spicy) export(spicyBoxPlot) export(topPairs) exportClasses(SpicyResults) +import(ggh4x) import(ggplot2) import(ggthemes) +importFrom(BiocParallel,MulticoreParam) importFrom(BiocParallel,SerialParam) importFrom(BiocParallel,bplapply) importFrom(BiocParallel,bpmapply) @@ -44,8 +46,7 @@ importFrom(dplyr,ungroup) importFrom(dplyr,where) importFrom(ggforce,geom_arc_bar) importFrom(ggforce,geom_circle) -importFrom(ggh4x,facet_grid2) -importFrom(ggh4x,strip_themed) +importFrom(ggnewscale,new_scale) importFrom(ggplot2,aes) importFrom(ggplot2,element_blank) importFrom(ggplot2,element_text) diff --git a/R/spicy.R b/R/spicy.R index 83959e9..a18c26c 100644 --- a/R/spicy.R +++ b/R/spicy.R @@ -13,9 +13,9 @@ #' vector of cell types which you would like to compare to the to vector #' @param to #' vector of cell types which you would like to compare to the from vector -#' @param imageIDCol The image ID if using SingleCellExperiment. -#' @param cellTypeCol The cell type if using SingleCellExperiment. -#' @param spatialCoordCols +#' @param imageID The image ID if using SingleCellExperiment. +#' @param cellType The cell type if using SingleCellExperiment. +#' @param spatialCoords #' The spatial coordinates if using a SingleCellExperiment. #' @param alternateResult #' An pairwise association statistic between each combination of celltypes in @@ -33,7 +33,7 @@ #' @param window.length #' A tuning parameter for controlling the level of concavity when estimating #' concave windows. -#' @param BPPARAM A BiocParallelParam object. +#' @param nCores number of cores to use for parallel processing. #' @param sigma #' A numeric variable used for scaling when fitting inhomogeneous L-curves. #' @param minLambda @@ -74,19 +74,19 @@ #' @aliases #' spicy #' spicy,spicy-method -#' @importFrom BiocParallel SerialParam #' @importFrom scam scam #' @importFrom rlang .data #' @importFrom tibble column_to_rownames +#' @importFrom BiocParallel MulticoreParam spicy <- function(cells, condition, subject = NULL, covariates = NULL, from = NULL, to = NULL, - imageIDCol = "imageID", - cellTypeCol = "cellType", - spatialCoordCols = c("x", "y"), + imageID = "imageID", + cellType = "cellType", + spatialCoords = c("x", "y"), alternateResult = NULL, verbose = FALSE, weights = TRUE, @@ -94,16 +94,18 @@ spicy <- function(cells, weightFactor = 1, window = "convex", window.length = NULL, - BPPARAM = BiocParallel::SerialParam(), + nCores = 1, sigma = NULL, Rs = NULL, minLambda = 0.05, edgeCorrect = TRUE, includeZeroCells = FALSE, ...) { + BPPARAM <- BiocParallel::MulticoreParam(workers = nCores) + if (is(cells, "SummarizedExperiment") || is(cells, "data.frame")) { cells <- .format_data( - cells, imageIDCol, cellTypeCol, spatialCoordCols, verbose + cells, imageID, cellType, spatialCoords, verbose ) } @@ -152,7 +154,7 @@ spicy <- function(cells, ## Check whether the subject parameter has a one-to-one mapping with image if (!is.null(subject)) { - if (nrow(as.data.frame(unique(cells[, subject]))) == nrow(as.data.frame(unique(cells[, imageIDCol])))) { + if (nrow(as.data.frame(unique(cells[, subject]))) == nrow(as.data.frame(unique(cells[, imageID])))) { subject <- NULL if(inherits(conditionVector, "Surv")) { @@ -185,7 +187,7 @@ spicy <- function(cells, to = to, edgeCorrect = edgeCorrect, includeZeroCells = includeZeroCells, - BPPARAM = BPPARAM + nCores = nCores ) pairwiseAssoc <- as.data.frame(pairwiseAssoc) pairwiseAssoc <- pairwiseAssoc[labels] @@ -435,14 +437,14 @@ cleanMEM <- function(mixed.lmer, BPPARAM) { #' @param edgeCorrect A logical indicating whether to perform edge correction. #' @param includeZeroCells A logical indicating whether to include cells with #' zero counts in the pairwise association calculation. -#' @param BPPARAM A BiocParallelParam object. -#' @param imageIDCol +#' @param nCores number of cores to use for parallel processing. +#' @param imageID #' The name of the imageID column if using a SingleCellExperiment or #' SpatialExperiment. -#' @param cellTypeCol +#' @param cellType #' The name of the cellType column if using a SingleCellExperiment or #' SpatialExperiment. -#' @param spatialCoordCols +#' @param spatialCoords #' The names of the spatialCoords column if using a SingleCellExperiment. #' @return Statistic from pairwise L curve of a single image. #' @@ -456,6 +458,7 @@ cleanMEM <- function(mixed.lmer, BPPARAM) { #' pairAssoc <- getPairwise(selected_cells) #' @export #' @importFrom BiocParallel bplapply +#' @importFrom BiocParallel MulticoreParam getPairwise <- function( cells, from = NULL, @@ -467,13 +470,15 @@ getPairwise <- function( minLambda = 0.05, edgeCorrect = TRUE, includeZeroCells = TRUE, - BPPARAM = BiocParallel::SerialParam(), - imageIDCol = "imageID", - cellTypeCol = "cellType", - spatialCoordCols = c("x", "y")) { + nCores = 1, + imageID = "imageID", + cellType = "cellType", + spatialCoords = c("x", "y")) { + BPPARAM <- BiocParallel::MulticoreParam(workers = nCores) + if (is(cells, "SummarizedExperiment")) { cells <- .format_data( - cells, imageIDCol, cellTypeCol, spatialCoordCols, FALSE + cells, imageID, cellType, spatialCoords, FALSE ) } diff --git a/R/utilities.R b/R/utilities.R index b9a0cd8..d8b7c0a 100644 --- a/R/utilities.R +++ b/R/utilities.R @@ -18,7 +18,7 @@ isKontextual <- function(kontextualResult) { if (is(cells, "data.frame")) { # pass } else if (is(cells, "SpatialExperiment")) { - spatialCoordCols <- names(spatialCoords(cells)) + spatialCoords <- names(spatialCoords(cells)) cells <- cells %>% colData() %>% data.frame() %>% diff --git a/man/getPairwise.Rd b/man/getPairwise.Rd index 9c5e84f..f9eece1 100644 --- a/man/getPairwise.Rd +++ b/man/getPairwise.Rd @@ -15,10 +15,10 @@ getPairwise( minLambda = 0.05, edgeCorrect = TRUE, includeZeroCells = TRUE, - BPPARAM = BiocParallel::SerialParam(), - imageIDCol = "imageID", - cellTypeCol = "cellType", - spatialCoordCols = c("x", "y") + nCores = 1, + imageID = "imageID", + cellType = "cellType", + spatialCoords = c("x", "y") ) } \arguments{ @@ -48,15 +48,15 @@ L-curves.} \item{includeZeroCells}{A logical indicating whether to include cells with zero counts in the pairwise association calculation.} -\item{BPPARAM}{A BiocParallelParam object.} +\item{nCores}{number of cores to use for parallel processing.} -\item{imageIDCol}{The name of the imageID column if using a SingleCellExperiment or +\item{imageID}{The name of the imageID column if using a SingleCellExperiment or SpatialExperiment.} -\item{cellTypeCol}{The name of the cellType column if using a SingleCellExperiment or +\item{cellType}{The name of the cellType column if using a SingleCellExperiment or SpatialExperiment.} -\item{spatialCoordCols}{The names of the spatialCoords column if using a SingleCellExperiment.} +\item{spatialCoords}{The names of the spatialCoords column if using a SingleCellExperiment.} } \value{ Statistic from pairwise L curve of a single image. diff --git a/man/spicy.Rd b/man/spicy.Rd index 6716c5c..bfd1e53 100644 --- a/man/spicy.Rd +++ b/man/spicy.Rd @@ -15,9 +15,9 @@ spicy( covariates = NULL, from = NULL, to = NULL, - imageIDCol = "imageID", - cellTypeCol = "cellType", - spatialCoordCols = c("x", "y"), + imageID = "imageID", + cellType = "cellType", + spatialCoords = c("x", "y"), alternateResult = NULL, verbose = FALSE, weights = TRUE, @@ -25,7 +25,7 @@ spicy( weightFactor = 1, window = "convex", window.length = NULL, - BPPARAM = BiocParallel::SerialParam(), + nCores = 1, sigma = NULL, Rs = NULL, minLambda = 0.05, @@ -50,11 +50,11 @@ mixed effects model as fixed effects.} \item{to}{vector of cell types which you would like to compare to the from vector} -\item{imageIDCol}{The image ID if using SingleCellExperiment.} +\item{imageID}{The image ID if using SingleCellExperiment.} -\item{cellTypeCol}{The cell type if using SingleCellExperiment.} +\item{cellType}{The cell type if using SingleCellExperiment.} -\item{spatialCoordCols}{The spatial coordinates if using a SingleCellExperiment.} +\item{spatialCoords}{The spatial coordinates if using a SingleCellExperiment.} \item{alternateResult}{An pairwise association statistic between each combination of celltypes in each image.} @@ -73,7 +73,7 @@ pair.} \item{window.length}{A tuning parameter for controlling the level of concavity when estimating concave windows.} -\item{BPPARAM}{A BiocParallelParam object.} +\item{nCores}{number of cores to use for parallel processing.} \item{sigma}{A numeric variable used for scaling when fitting inhomogeneous L-curves.}