Skip to content

Commit

Permalink
change function names
Browse files Browse the repository at this point in the history
  • Loading branch information
zskylarli committed Jun 12, 2024
1 parent 8a2eb36 commit c503f95
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 20 deletions.
19 changes: 13 additions & 6 deletions R/SEraster.R
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ createRasterizedObject <- function(input, out, name) {
return(output)
}

#' rasterizeGeneExpression
#' RunRasterizeGeneExpression
#'
#' @description Function to rasterize feature x observation matrix in spatially-resolved
#' omics data represented as Seurat objects.
Expand Down Expand Up @@ -126,7 +126,7 @@ createRasterizedObject <- function(input, out, name) {
#' @importFrom Matrix colSums
#'
#' @export
rasterizeGeneExpression <- function(
RunRasterizeGeneExpression <- function(
input,
assay_name = NULL,
image = NULL,
Expand Down Expand Up @@ -219,7 +219,7 @@ rasterizeGeneExpression <- function(
}
}

#' rasterizeCellType
#' RunRasterizeCellType
#'
#' @description Function to rasterize cell type labels in spatially-resolved
#' omics data represented as Seurat object class.
Expand Down Expand Up @@ -279,7 +279,7 @@ rasterizeGeneExpression <- function(
#'
#' @export
#'
rasterizeCellType <- function(
RunRasterizeCellType <- function(
input,
col_name,
assay_name = NULL,
Expand Down Expand Up @@ -373,7 +373,7 @@ rasterizeCellType <- function(
}
}

#' permutateByRotation
#' RunPermutateByRotation
#'
#' @description Function to permutate a given input Seurat object(s)
#' by rotating the x,y coordinates around the midrange point.
Expand Down Expand Up @@ -404,7 +404,7 @@ rasterizeCellType <- function(
#'
#' @export
#'
permutateByRotation <- function(input, n_perm = 1, verbose = FALSE) {
RunPermutateByRotation <- function(input, n_perm = 1, verbose = FALSE) {
angles <- seq(0, 360, by = 360/n_perm)[1:n_perm]

if (verbose) {
Expand All @@ -428,6 +428,10 @@ permutateByRotation <- function(input, n_perm = 1, verbose = FALSE) {
assay_name <- DefaultAssay(spe)
pos_orig <- data.frame(GetTissueCoordinates(spe, scale = NULL))
colnames(pos_orig) <- c("x", "y")
if("cell" %in% colnames(pos_orig)){
rownames(pos_orig) <- pos_orig$cell
}

stopifnot("Column 1 and 2 of the spatialCoords slot should be named x and y, respectively." = colnames(pos_orig)[1:2] == c("x", "y"))

lapply(angles, function(angle) {
Expand All @@ -452,6 +456,9 @@ permutateByRotation <- function(input, n_perm = 1, verbose = FALSE) {
assay_name <- DefaultAssay(input)
pos_orig <- GetTissueCoordinates(input, scale = NULL)
colnames(pos_orig) <- c("x", "y")
if("cell" %in% colnames(pos_orig)){
rownames(pos_orig) <- pos_orig$cell
}
stopifnot("Column 1 and 2 of the spatialCoords slot should be named x and y, respectively." = colnames(pos_orig)[1:2] == c("x", "y"))

output_list <- list()
Expand Down
12 changes: 6 additions & 6 deletions docs/SEraster.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ For continuous variables such as gene expression or other molecular information,
Let's try rasterizing the gene expression of the Xenium mouse brain dataset we loaded.

```{r}
rastGexp <- SeuratWrappers::rasterizeGeneExpression(xenium.obj, assay_name = "Xenium", resolution = 100)
rastGexp <- RunRasterizeGeneExpression(xenium.obj, assay_name = "Xenium", resolution = 100)
# check dimensions of spot by gene matrix after rasterization
dim(rastGexp[['Xenium']])
Expand Down Expand Up @@ -116,7 +116,7 @@ ImageDimPlot(xenium.obj, group.by='seurat_clusters')
```

```{r}
rastCt <- SeuratWrappers::rasterizeCellType(xenium.obj, col_name = "seurat_clusters", resolution = 200)
rastCt <- RunRasterizeCellType(xenium.obj, col_name = "seurat_clusters", resolution = 200)
# check the dimension of the cell-types-by-cells matrix after rasterizing cell-type labels
dim(rastCt[['seurat_clusters']])
Expand All @@ -137,10 +137,10 @@ Let's see how the rasterized VisiumHD mouse brain dataset looks with various res

```{r}
# rasterize at defined resolution
rast2000 <- SeuratWrappers::rasterizeGeneExpression(visiumhd.obj, assay_name="Spatial.016um", resolution = 2000)
rast2000 <- RunRasterizeGeneExpression(visiumhd.obj, assay_name="Spatial.016um", resolution = 2000)
rast2000 <- NormalizeData(rast2000)
rast1000 <- SeuratWrappers::rasterizeGeneExpression(visiumhd.obj, assay_name="Spatial.016um", resolution = 1000)
rast1000 <- RunRasterizeGeneExpression(visiumhd.obj, assay_name="Spatial.016um", resolution = 1000)
rast1000 <- NormalizeData(rast1000)
# visualize
Expand All @@ -159,10 +159,10 @@ In addition to a single `Seurat` spatial object, `rasterizeGeneExpression` and `
```{r}
# permutate
DefaultAssay(xenium.obj) <- "Xenium"
spe_list <- SeuratWrappers::permutateByRotation(xenium.obj, n_perm = 3)
spe_list <- RunPermutateByRotation(xenium.obj, n_perm = 3)
# rasterize permutated datasets at once
out_list <- SeuratWrappers::rasterizeGeneExpression(spe_list, assay_name = "Xenium", resolution = 200)
out_list <- RunRasterizeGeneExpression(spe_list, assay_name = "Xenium", resolution = 200)
for (i in seq_along(out_list)) {
# extract rotated angle
Expand Down
16 changes: 8 additions & 8 deletions docs/SEraster.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Getting Started With SEraster
================
Compiled: May 30, 2024
Compiled: June 07, 2024

# Getting Started with SEraster

Expand Down Expand Up @@ -83,7 +83,7 @@ Let’s try rasterizing the gene expression of the Xenium mouse brain
dataset we loaded.

``` r
rastGexp <- SeuratWrappers::rasterizeGeneExpression(xenium.obj, assay_name = "Xenium", resolution = 100)
rastGexp <- RunRasterizeGeneExpression(xenium.obj, assay_name = "Xenium", resolution = 100)

# check dimensions of spot by gene matrix after rasterization
dim(rastGexp[['Xenium']])
Expand Down Expand Up @@ -154,7 +154,7 @@ ImageDimPlot(xenium.obj, group.by='seurat_clusters')
![](SEraster_files/figure-gfm/unnamed-chunk-11-2.png)<!-- -->

``` r
rastCt <- SeuratWrappers::rasterizeCellType(xenium.obj, col_name = "seurat_clusters", resolution = 200)
rastCt <- RunRasterizeCellType(xenium.obj, col_name = "seurat_clusters", resolution = 200)

# check the dimension of the cell-types-by-cells matrix after rasterizing cell-type labels
dim(rastCt[['seurat_clusters']])
Expand Down Expand Up @@ -190,10 +190,10 @@ various resolutions using square pixels, which is specified by `shape`.

``` r
# rasterize at defined resolution
rast2000 <- SeuratWrappers::rasterizeGeneExpression(visiumhd.obj, assay_name="Spatial.016um", resolution = 2000)
rast2000 <- RunRasterizeGeneExpression(visiumhd.obj, assay_name="Spatial.016um", resolution = 2000)
rast2000 <- NormalizeData(rast2000)

rast1000 <- SeuratWrappers::rasterizeGeneExpression(visiumhd.obj, assay_name="Spatial.016um", resolution = 1000)
rast1000 <- RunRasterizeGeneExpression(visiumhd.obj, assay_name="Spatial.016um", resolution = 1000)
rast1000 <- NormalizeData(rast1000)

# visualize
Expand Down Expand Up @@ -235,10 +235,10 @@ vs. disease tissues.
``` r
# permutate
DefaultAssay(xenium.obj) <- "Xenium"
spe_list <- SeuratWrappers::permutateByRotation(xenium.obj, n_perm = 3)
spe_list <- RunPermutateByRotation(xenium.obj, n_perm = 3)

# rasterize permutated datasets at once
out_list <- SeuratWrappers::rasterizeGeneExpression(spe_list, assay_name = "Xenium", resolution = 200)
out_list <- RunRasterizeGeneExpression(spe_list, assay_name = "Xenium", resolution = 200)

for (i in seq_along(out_list)) {
# extract rotated angle
Expand Down Expand Up @@ -288,7 +288,7 @@ sessionInfo()
## [13] hcabm40k.SeuratData_3.0.0 cbmc.SeuratData_3.1.4
## [15] bonemarrowref.SeuratData_1.0.0 bmcite.SeuratData_0.3.0
## [17] SeuratData_0.2.2.9001 SeuratWrappers_0.3.6
## [19] Seurat_5.1.0 SeuratObject_5.0.2
## [19] Seurat_5.0.3.9922 SeuratObject_5.0.2
## [21] sp_2.1-3
##
## loaded via a namespace (and not attached):
Expand Down

0 comments on commit c503f95

Please sign in to comment.