Skip to content

Commit

Permalink
Compatibility with SeuratWrappers
Browse files Browse the repository at this point in the history
  • Loading branch information
jleechung committed Feb 29, 2024
1 parent 66a2dd9 commit a2df5fd
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 125 deletions.
17 changes: 7 additions & 10 deletions R/computation.R
Original file line number Diff line number Diff line change
Expand Up @@ -280,15 +280,12 @@ ComputeBanksy <- function(bank, compute_agf = FALSE,
length(M), ' harmonics.')
}

# Extract locs
locs <- bank@cell.locs

if (is.list(bank@own.expr)) {


# Multi-dataset case
locs <- lapply(bank@cell.locs, function(x) {
x <- data.table(x, keep.rownames = TRUE)
setnames(x, 'rn', 'cell_ID')
})

# Compute knn list for all datasets
knn_lst <- lapply(locs, function(dlocs) {
lapply(k_geom, function(kg) {
Expand Down Expand Up @@ -328,8 +325,7 @@ ComputeBanksy <- function(bank, compute_agf = FALSE,

} else {
# Single dataset case
locs <- data.table(bank@cell.locs, keep.rownames = TRUE)
setnames(locs, 'rn', 'cell_ID')
locs <- bank@cell.locs
knn_list <- lapply(k_geom, function(kg) {
computeNeighbors(locs,
spatial_mode = spatial_mode, k_geom = kg, n = n,
Expand Down Expand Up @@ -449,9 +445,10 @@ getBanksyMatrix <- function(bank, lambda = 0.2, M = 0, verbose = TRUE) {


getSpatialDims <- function(locs, dimensions, alpha) {

cellID <- seq_len(nrow(locs))
names(cellID) <- locs$cell_ID
locs <- locs[, grepl('sdim', colnames(locs)), with = FALSE]
names(cellID) <- rownames(locs)
locs <- locs[, grepl('sdim', colnames(locs)), drop = FALSE]

if (dimensions != "all") {
if (all(dimensions %in% colnames(locs)))
Expand Down
2 changes: 1 addition & 1 deletion README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ scale the resulting matrices.

```{r, eval = T}
bank <- NormalizeBanksy(bank)
bank <- ComputeBanksy(bank, k_geom = c(15, 30))
bank <- ComputeBanksy(bank, k_geom = 15)
bank <- ScaleBanksy(bank)
```

Expand Down
217 changes: 103 additions & 114 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,21 @@ augmenting the transcriptomic profile of each cell with an average of
the transcriptomes of its spatial neighbors. By incorporating
neighborhood information for clustering, BANKSY is able to

- improve cell-type assignment in noisy data
- distinguish subtly different cell-types stratified by
microenvironment
- identify spatial zones sharing the same microenvironment
- improve cell-type assignment in noisy data
- distinguish subtly different cell-types stratified by microenvironment
- identify spatial zones sharing the same microenvironment

BANKSY is applicable to a wide array of spatial technologies (e.g. 10x
Visium, Slide-seq, MERFISH) and scales well to large datasets. For more
details, check out:

- the
[preprint](https://www.biorxiv.org/content/10.1101/2022.04.14.488259v1),
- a
[tweetorial](https://twitter.com/vipul1891/status/1515323372535644166?s=20&t=Bc6rz8VeWWptF67FejGYfQ)
on BANKSY,
- and a [Python version](https://github.com/prabhakarlab/Banksy_py) of
this package.
- the
[preprint](https://www.biorxiv.org/content/10.1101/2022.04.14.488259v1),
- a
[tweetorial](https://twitter.com/vipul1891/status/1515323372535644166?s=20&t=Bc6rz8VeWWptF67FejGYfQ)
on BANKSY,
- and a [Python version](https://github.com/prabhakarlab/Banksy_py) of
this package.

## Installation

Expand All @@ -45,9 +44,9 @@ Installation should take less than three minutes.

1. Installation of `leidenAlg` has non-zero exit status

- Refer to the [`leidenAlg` package
website](https://github.com/kharchenkolab/leidenAlg#installation)
for installation details.
- Refer to the [`leidenAlg` package
website](https://github.com/kharchenkolab/leidenAlg#installation) for
installation details.

## Documentation

Expand All @@ -60,32 +59,32 @@ webpage](https://prabhakarlab.github.io/Banksy/).
of main functions and their usage, along with several vignettes which
detail different use cases:

- [Working with Banksy
objects](https://prabhakarlab.github.io/Banksy/articles/banksy-object.html):
Introduction to the *BanksyObject* class which serves as a container
for *Banksy*.

- [Mouse hippocampus VeraFISH
dataset](https://prabhakarlab.github.io/Banksy/articles/hippocampus-analysis.html):
Illustrates a grid search of parameters which best cluster cells.

- [Human dorsolateral prefrontal cortex 10x Visium
dataset](https://prabhakarlab.github.io/Banksy/articles/dlpfc-analysis.html):
Illustrates analysis of multiple spatial transcriptomic datasets.

- [Mouse hypothalamus MERFISH
dataset](https://prabhakarlab.github.io/Banksy/articles/hypothalamus-analysis.html):
Illustrates visualization functionality with a dataset with 3
spatial dimensions.

- [Interoperability with
SingleCellExperiment](https://prabhakarlab.github.io/Banksy/articles/single-cell-exp.html):
Illustrates BANKSY interoperability with Bioconductor
[SingleCellExperiment](https://bioconductor.org/packages/release/bioc/html/SingleCellExperiment.html)
framework for interfacing with packages like
[scran](https://bioconductor.org/packages/release/bioc/html/scran.html)
or
[scater](https://bioconductor.org/packages/release/bioc/html/scater.html).
- [Working with Banksy
objects](https://prabhakarlab.github.io/Banksy/articles/banksy-object.html):
Introduction to the *BanksyObject* class which serves as a container
for *Banksy*.

- [Mouse hippocampus VeraFISH
dataset](https://prabhakarlab.github.io/Banksy/articles/hippocampus-analysis.html):
Illustrates a grid search of parameters which best cluster cells.

- [Human dorsolateral prefrontal cortex 10x Visium
dataset](https://prabhakarlab.github.io/Banksy/articles/dlpfc-analysis.html):
Illustrates analysis of multiple spatial transcriptomic datasets.

- [Mouse hypothalamus MERFISH
dataset](https://prabhakarlab.github.io/Banksy/articles/hypothalamus-analysis.html):
Illustrates visualization functionality with a dataset with 3 spatial
dimensions.

- [Interoperability with
SingleCellExperiment](https://prabhakarlab.github.io/Banksy/articles/single-cell-exp.html):
Illustrates BANKSY interoperability with Bioconductor
[SingleCellExperiment](https://bioconductor.org/packages/release/bioc/html/SingleCellExperiment.html)
framework for interfacing with packages like
[scran](https://bioconductor.org/packages/release/bioc/html/scran.html)
or
[scater](https://bioconductor.org/packages/release/bioc/html/scater.html).

*Banksy* is also interoperable with
[Seurat](https://satijalab.org/seurat/) via *SeuratWrappers*.
Expand Down Expand Up @@ -189,22 +188,14 @@ and scale the resulting matrices.

``` r
bank <- NormalizeBanksy(bank)
bank <- ComputeBanksy(bank, k_geom = c(15, 30))
bank <- ComputeBanksy(bank, k_geom = 15)
#> Computing neighbors...
#> Spatial mode is kNN median
#> Parameters: k_geom = 15
#> Done
#> Computing neighbors...
#> Spatial mode is kNN median
#> Parameters: k_geom = 30
#> Done
#> Computing harmonic m = 0
#> Using 15 neighbors
#> Done
#> Computing harmonic m = 1
#> Using 30 neighbors
#> Centering
#> Done
bank <- ScaleBanksy(bank)
```

Expand All @@ -213,12 +204,12 @@ Run PCA on the BANKSY matrix for `lambda=0` (no spatial information) and

``` r
bank <- RunBanksyPCA(bank, lambda = c(0, 0.2))
#> Running PCA for M=1 lambda=0
#> BANKSY matrix with own.expr, F0, F1
#> Squared lambdas: 1, 0, 0
#> Running PCA for M=1 lambda=0.2
#> BANKSY matrix with own.expr, F0, F1
#> Squared lambdas: 0.8, 0.1333, 0.0667
#> Running PCA for M=0 lambda=0
#> BANKSY matrix with own.expr, F0
#> Squared lambdas: 1, 0
#> Running PCA for M=0 lambda=0.2
#> BANKSY matrix with own.expr, F0
#> Squared lambdas: 0.8, 0.2
```

Next, we obtain cluster assignments using graph-based clustering with
Expand Down Expand Up @@ -265,11 +256,7 @@ plotSpatialFeatures(bank, by = features, type = feature.types, main = main,
Runtime for analysis
</summary>

<<<<<<< HEAD
#> Time difference of 1.915979 mins
=======
#> Time difference of 38.77595 secs
>>>>>>> main
#> Time difference of 46.16683 secs

</details>
<details>
Expand All @@ -279,16 +266,19 @@ Session information

``` r
sessionInfo()
#> R version 4.2.1 (2022-06-23 ucrt)
#> Platform: x86_64-w64-mingw32/x64 (64-bit)
#> Running under: Windows 10 x64 (build 19043)
#> R version 4.3.2 (2023-10-31)
#> Platform: aarch64-apple-darwin20 (64-bit)
#> Running under: macOS Sonoma 14.2.1
#>
#> Matrix products: default
#> BLAS: /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/lib/libRblas.0.dylib
#> LAPACK: /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/lib/libRlapack.dylib; LAPACK version 3.11.0
#>
#> locale:
#> [1] LC_COLLATE=English_Singapore.utf8 LC_CTYPE=English_Singapore.utf8
#> [3] LC_MONETARY=English_Singapore.utf8 LC_NUMERIC=C
#> [5] LC_TIME=English_Singapore.utf8
#> [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
#>
#> time zone: Europe/London
#> tzcode source: internal
#>
#> attached base packages:
#> [1] stats graphics grDevices utils datasets methods base
Expand All @@ -297,54 +287,53 @@ sessionInfo()
#> [1] Banksy_0.1.5
#>
#> loaded via a namespace (and not attached):
#> [1] bitops_1.0-7 matrixStats_0.62.0
#> [3] doParallel_1.0.17 RColorBrewer_1.1-3
#> [5] progress_1.2.2 GenomeInfoDb_1.34.4
#> [7] tools_4.2.1 utf8_1.2.2
#> [9] R6_2.5.1 irlba_2.3.5.1
#> [11] uwot_0.1.14 DBI_1.1.3
#> [13] BiocGenerics_0.44.0 colorspace_2.0-3
#> [15] GetoptLong_1.0.5 withr_2.5.0
#> [17] tidyselect_1.2.0 gridExtra_2.3
#> [19] prettyunits_1.1.1 compiler_4.2.1
#> [21] cli_3.4.1 Biobase_2.58.0
#> [23] DelayedArray_0.24.0 labeling_0.4.2
#> [25] scales_1.2.1 stringr_1.5.0
#> [27] digest_0.6.30 dbscan_1.1-11
#> [29] rmarkdown_2.19 XVector_0.38.0
#> [31] dichromat_2.0-0.1 pkgconfig_2.0.3
#> [33] htmltools_0.5.4 MatrixGenerics_1.10.0
#> [35] highr_0.10 fastmap_1.1.0
#> [37] maps_3.4.1 rlang_1.1.1
#> [39] GlobalOptions_0.1.2 pals_1.7
#> [41] rstudioapi_0.14 farver_2.1.1
#> [43] shape_1.4.6 generics_0.1.3
#> [45] mclust_6.0.0 dplyr_1.0.10
#> [47] RCurl_1.98-1.9 magrittr_2.0.3
#> [49] GenomeInfoDbData_1.2.9 Matrix_1.5-3
#> [51] Rcpp_1.0.9 munsell_0.5.0
#> [53] S4Vectors_0.36.0 fansi_1.0.3
#> [55] lifecycle_1.0.3 stringi_1.7.8
#> [57] leidenAlg_1.1.0 yaml_2.3.6
#> [59] ggalluvial_0.12.3 SummarizedExperiment_1.28.0
#> [61] zlibbioc_1.44.0 plyr_1.8.8
#> [63] grid_4.2.1 parallel_4.2.1
#> [65] crayon_1.5.2 lattice_0.20-45
#> [67] sccore_1.0.2 mapproj_1.2.9
#> [69] circlize_0.4.15 hms_1.1.2
#> [71] knitr_1.41 ComplexHeatmap_2.14.0
#> [73] pillar_1.8.1 igraph_1.3.5
#> [75] GenomicRanges_1.50.1 rjson_0.2.21
#> [77] codetools_0.2-18 stats4_4.2.1
#> [79] glue_1.6.2 evaluate_0.19
#> [81] data.table_1.14.6 png_0.1-7
#> [83] vctrs_0.5.1 foreach_1.5.2
#> [85] gtable_0.3.1 clue_0.3-62
#> [87] assertthat_0.2.1 ggplot2_3.4.0
#> [89] xfun_0.36 tibble_3.1.8
#> [91] RcppHungarian_0.2 iterators_1.0.14
#> [93] IRanges_2.32.0 cluster_2.1.4
#> [95] ellipsis_0.3.2
#> [1] tidyselect_1.2.0 farver_2.1.1
#> [3] dplyr_1.1.4 bitops_1.0-7
#> [5] fastmap_1.1.1 RCurl_1.98-1.14
#> [7] digest_0.6.34 lifecycle_1.0.4
#> [9] cluster_2.1.6 ggalluvial_0.12.5
#> [11] magrittr_2.0.3 dbscan_1.1-12
#> [13] compiler_4.3.2 progress_1.2.3
#> [15] rlang_1.1.3 tools_4.3.2
#> [17] igraph_2.0.1.1 utf8_1.2.4
#> [19] yaml_2.3.8 data.table_1.15.0
#> [21] knitr_1.45 labeling_0.4.3
#> [23] prettyunits_1.2.0 S4Arrays_1.2.0
#> [25] mclust_6.0.1 DelayedArray_0.28.0
#> [27] plyr_1.8.9 mapproj_1.2.11
#> [29] RColorBrewer_1.1-3 abind_1.4-5
#> [31] withr_3.0.0 BiocGenerics_0.48.1
#> [33] grid_4.3.2 stats4_4.3.2
#> [35] fansi_1.0.6 colorspace_2.1-0
#> [37] ggplot2_3.4.4 scales_1.3.0
#> [39] iterators_1.0.14 pals_1.8
#> [41] dichromat_2.0-0.1 SummarizedExperiment_1.32.0
#> [43] cli_3.6.2 rmarkdown_2.25
#> [45] crayon_1.5.2 leidenAlg_1.1.2
#> [47] generics_0.1.3 rstudioapi_0.15.0
#> [49] rjson_0.2.21 RcppHungarian_0.3
#> [51] zlibbioc_1.48.0 maps_3.4.2
#> [53] parallel_4.3.2 XVector_0.42.0
#> [55] matrixStats_1.2.0 vctrs_0.6.5
#> [57] Matrix_1.6-5 hms_1.1.3
#> [59] IRanges_2.36.0 GetoptLong_1.0.5
#> [61] S4Vectors_0.40.2 irlba_2.3.5.1
#> [63] clue_0.3-65 foreach_1.5.2
#> [65] glue_1.7.0 codetools_0.2-19
#> [67] uwot_0.1.16 shape_1.4.6
#> [69] gtable_0.3.4 GenomeInfoDb_1.38.6
#> [71] GenomicRanges_1.54.1 ComplexHeatmap_2.18.0
#> [73] munsell_0.5.0 tibble_3.2.1
#> [75] pillar_1.9.0 htmltools_0.5.7
#> [77] GenomeInfoDbData_1.2.11 circlize_0.4.15
#> [79] R6_2.5.1 doParallel_1.0.17
#> [81] evaluate_0.23 sccore_1.0.4
#> [83] lattice_0.22-5 Biobase_2.62.0
#> [85] highr_0.10 png_0.1-8
#> [87] Rcpp_1.0.12 gridExtra_2.3
#> [89] SparseArray_1.2.4 xfun_0.42
#> [91] MatrixGenerics_1.14.0 pkgconfig_2.0.3
#> [93] GlobalOptions_0.1.2
```

</details>
Expand Down
Binary file modified man/figures/README-unnamed-chunk-14-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified man/figures/README-unnamed-chunk-15-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit a2df5fd

Please sign in to comment.