... | ... |
@@ -1,6 +1,6 @@ |
1 | 1 |
#' Generate local indicators of spatial association |
2 | 2 |
#' |
3 |
-#' @param cells A SegmentedCells or data frame that contains at least the |
|
3 |
+#' @param cells A SegmentedCells, SingleCellExperiment, SpatialExperiment or data frame that contains at least the |
|
4 | 4 |
#' variables x and y, giving the coordinates of each cell, imageID and cellType. |
5 | 5 |
#' @param Rs A vector of the radii that the measures of association should be calculated. |
6 | 6 |
#' @param BPPARAM A BiocParallelParam object. |
... | ... |
@@ -1,6 +1,6 @@ |
1 | 1 |
#' Use k-means clustering to cluster local indicators of spatial association. For other clustering use lisa. |
2 | 2 |
#' |
3 |
-#' @param cells A SegmentedCells or data frame that contains at least the |
|
3 |
+#' @param cells A SegmentedCells, SingleCellExperiment, SpatialExperiment or data frame that contains at least the |
|
4 | 4 |
#' variables x and y, giving the coordinates of each cell, imageID and cellType. |
5 | 5 |
#' @param k The number of regions to cluster. |
6 | 6 |
#' @param Rs A vector of the radii that the measures of association should be calculated. |
... | ... |
@@ -126,6 +126,31 @@ lisaClust <- |
126 | 126 |
cellAnnotation(cells, regionName) <- regions |
127 | 127 |
} |
128 | 128 |
|
129 |
+ |
|
130 |
+ if(is(cells, "data.frame")){ |
|
131 |
+ cd <- cells |
|
132 |
+ cd <- cd[,c(cellType, imageID, spatialCoords)] |
|
133 |
+ colnames(cd) <- c("cellType", "imageID", "x", "y") |
|
134 |
+ cd$cellID <- as.character(seq_len(nrow(cd))) |
|
135 |
+ cd$imageCellID <- as.character(seq_len(nrow(cd))) |
|
136 |
+ cd <- spicyR::SegmentedCells(cd) |
|
137 |
+ lisaCurves <- lisa(cd, |
|
138 |
+ Rs = Rs, |
|
139 |
+ BPPARAM = BPPARAM, |
|
140 |
+ window = window, |
|
141 |
+ window.length = window.length, |
|
142 |
+ whichParallel = whichParallel, |
|
143 |
+ sigma = sigma, |
|
144 |
+ lisaFunc = lisaFunc, |
|
145 |
+ minLambda = minLambda, |
|
146 |
+ fast = fast) |
|
147 |
+ |
|
148 |
+ kM <- kmeans(lisaCurves,k) |
|
149 |
+ regions <- paste('region',kM$cluster,sep = '_') |
|
150 |
+ cells[regionName] <- regions |
|
151 |
+ } |
|
152 |
+ |
|
153 |
+ |
|
129 | 154 |
cells |
130 | 155 |
|
131 | 156 |
} |