Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BayesSpace v1.11.3 #111

Open
wants to merge 39 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
6b73168
fix: bugs when reading H5
Jun 3, 2023
3c8d3a9
fix: bugs
Jun 4, 2023
5f73f19
fix: bugs
Jun 5, 2023
86de359
fix: added sinity check and core tuning
senbaikang Jul 5, 2023
3c0f502
doc: updated doc
senbaikang Jul 5, 2023
40fdaa1
fix: fixed bugs & faster code
senbaikang Sep 7, 2023
e20e5a3
feat: adaptive mcmc
senbaikang Sep 11, 2023
d6abb37
feat: adaptive mcmc
senbaikang Sep 20, 2023
7186e72
feat: adaptive MCMC
senbaikang Sep 22, 2023
94a9df0
feat: label adjustment
senbaikang Sep 25, 2023
7129c45
fix: bugs
senbaikang Oct 4, 2023
e25d9b2
feat: option for restricted adaptive MCMC
senbaikang Oct 5, 2023
a9c094e
fix: [v1.11.7] bugs in func
senbaikang Dec 8, 2023
b5bd8f2
fix: bugs
senbaikang Feb 6, 2024
f69e023
fix: [v1.11.8] bugs in processing z
senbaikang Feb 16, 2024
6d02fdf
fix: [v1.11.8] bugs in processing z
senbaikang Feb 16, 2024
483645e
fix: bug
senbaikang Feb 19, 2024
65736e4
fix: updated outdated functions
senbaikang Feb 19, 2024
98c1d15
fix: updated outdated functions
senbaikang Feb 19, 2024
8d34497
fix: updated outdated functions
senbaikang Feb 19, 2024
2190e56
feat: [v1.11.10] refactored neighbor finding for subspots
senbaikang Mar 7, 2024
554b98b
fix: bugs
senbaikang Mar 7, 2024
79e11b9
Support for VisiumHD (#1)
senbaikang Mar 7, 2024
fc0d4c7
fix: bugs
senbaikang Mar 8, 2024
4a347ce
fix: cleaned up coords assignment for subspots
senbaikang Mar 13, 2024
6140799
fix: bug in plotting clusters
senbaikang Mar 13, 2024
06b5cf6
feat: [v1.13.1] plot clusters align with the image
senbaikang Mar 14, 2024
ec91302
fix: bugs
senbaikang Mar 14, 2024
d7ad525
feat: [v1.13.2] parallelized PCA
senbaikang Mar 18, 2024
6b28b43
feat: [v1.13.2] removed unrelated probes; parallized modeling of gene…
senbaikang Mar 19, 2024
db2d58d
feat: [v1.13.4] thining in c++ code
senbaikang Mar 20, 2024
dff61c8
fix: bugs
senbaikang Mar 24, 2024
18be765
feat: [v1.13.5] customized number of subspots
senbaikang Mar 25, 2024
9a5f742
fix: bugs
senbaikang Mar 25, 2024
d3e9275
doc: updated doc
senbaikang Mar 26, 2024
1fc79ae
fix: typo
senbaikang Apr 2, 2024
b9640f9
feat: [v1.13.6] added a few helper functions
senbaikang Apr 8, 2024
df216c1
fix: bugs
senbaikang Oct 15, 2024
0d6b7ac
doc: update NEWS
senbaikang Oct 15, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
^renv$
^renv\.lock$
^.*\.Rproj$
^\.Rproj\.user$
^inst/profiling$
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,5 @@ docs/

*.nb.html
*.rds

src/indicators
13 changes: 8 additions & 5 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: BayesSpace
Version: 1.11.0
Date: 2023-05-03
Version: 1.13.6
Date: 2024-04-02
Title: Clustering and Resolution Enhancement of Spatial Transcriptomes
Authors@R: c(
person("Edward", "Zhao", role=c("aut"), email="[email protected]"),
Expand Down Expand Up @@ -33,20 +33,23 @@ Imports:
DirichletReg,
xgboost,
utils,
tidyverse,
dplyr,
ggplot2,
tibble,
tidyr,
scales,
BiocFileCache,
BiocSingular,
BiocParallel
License: MIT + file LICENSE
RoxygenNote: 7.2.3
RoxygenNote: 7.3.2
LinkingTo:
Rcpp,
RcppArmadillo,
RcppDist,
RcppProgress
NeedsCompilation: yes
SystemRequirements: C++11
SystemRequirements: C++17
Encoding: UTF-8
Suggests:
testthat,
Expand Down
21 changes: 21 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
# Generated by roxygen2: do not edit by hand

export(adjustClusterLabels)
export(clusterPlot)
export(computeCorr)
export(coreTune)
export(counts2h5)
export(enhanceFeatures)
export(exampleSCE)
export(featurePlot)
export(getRDS)
export(mapSubspot2Ref)
export(mcmcChain)
export(paraLapply)
export(qPlot)
Expand All @@ -22,6 +27,9 @@ importFrom(BiocParallel,SerialParam)
importFrom(BiocParallel,SnowParam)
importFrom(BiocParallel,bplapply)
importFrom(BiocSingular,ExactParam)
importFrom(BiocSingular,FastAutoParam)
importFrom(BiocSingular,IrlbaParam)
importFrom(BiocSingular,RandomParam)
importFrom(DirichletReg,DR_data)
importFrom(DirichletReg,DirichReg)
importFrom(Matrix,colSums)
Expand All @@ -48,9 +56,16 @@ importFrom(SummarizedExperiment,assay)
importFrom(SummarizedExperiment,assayNames)
importFrom(SummarizedExperiment,colData)
importFrom(SummarizedExperiment,rowData)
importFrom(arrow,read_parquet)
importFrom(assertthat,assert_that)
importFrom(coda,mcmc)
importFrom(dplyr,"%>%")
importFrom(dplyr,case_when)
importFrom(dplyr,group_by)
importFrom(dplyr,inner_join)
importFrom(dplyr,mutate)
importFrom(dplyr,n)
importFrom(dplyr,select)
importFrom(ggplot2,aes_)
importFrom(ggplot2,coord_equal)
importFrom(ggplot2,geom_line)
Expand All @@ -65,18 +80,23 @@ importFrom(ggplot2,theme_bw)
importFrom(ggplot2,theme_void)
importFrom(ggplot2,xlab)
importFrom(ggplot2,ylab)
importFrom(magrittr,"%>%")
importFrom(mclust,Mclust)
importFrom(mclust,mclustBIC)
importFrom(microbenchmark,microbenchmark)
importFrom(parallel,detectCores)
importFrom(purrr,compact)
importFrom(purrr,discard)
importFrom(purrr,imap)
importFrom(purrr,keep)
importFrom(purrr,map)
importFrom(rhdf5,h5createDataset)
importFrom(rhdf5,h5createFile)
importFrom(rhdf5,h5createGroup)
importFrom(rhdf5,h5ls)
importFrom(rhdf5,h5read)
importFrom(rhdf5,h5write)
importFrom(rjson,fromJSON)
importFrom(scales,muted)
importFrom(scater,logNormCounts)
importFrom(scater,runPCA)
Expand All @@ -94,6 +114,7 @@ importFrom(stats,rnbinom)
importFrom(stats,rnorm)
importFrom(stats,runif)
importFrom(tibble,as_tibble)
importFrom(tibble,column_to_rownames)
importFrom(tidyr,uncount)
importFrom(utils,download.file)
importFrom(utils,read.csv)
Expand Down
26 changes: 22 additions & 4 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
# BayesSpace 1.15.0

## New Bioconductor release (3.20)

### Major updates

- Accelerate resolution enhancement with multithreaded `spatialEnhance`
- Improve mixing of MCMC for `spatialEnhance` with adaptive MCMC
- Support VisiumHD

### Minor improvements and fixes

- Support SpaceRanger v2.0+
- Find the optimal number of cores with `coreTune` before enhancing resolution
- Adjust the proportion of samples to be removed during burnin using `adjustClusterLabels`
- Faster neighbor finding for subspots
- Customize resolution enhancement for VisiumHD data

# BayesSpace 1.5.1

## Minor improvements and fixes
Expand Down Expand Up @@ -81,10 +99,10 @@
## Minor improvements and fixes

- Addressed reviewer concerns (https://github.com/Bioconductor/Contributions/issues/1624)
* Updated stop/warning/message statements to remove redundancies and
unnecessary use of `paste()`.
* Removed inline conditional statements.
* Cache downloaded RDS in `getRDS()` (see above).
- Updated stop/warning/message statements to remove redundancies and
unnecessary use of `paste()`.
- Removed inline conditional statements.
- Cache downloaded RDS in `getRDS()` (see above).
- `spatialCluster()` and `spatialEnhance()` handle the edge case where only one
iteration is kept after excluding burn-in.
- The `coda::mcmc` object returned by `mcmcChain()` now specifies the thinning
Expand Down
11 changes: 5 additions & 6 deletions R/BayesSpace.R
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
#' BayesSpace: A package for processing spatial transcriptomes
#'
#'
#' Tools for clustering and enhancing the resolution of spatial gene expression
#' experiments. BayesSpace clusters a low-dimensional representation of the gene
#' expression matrix, incorporating a spatial prior to encourage neighboring
#' spots to cluster together. The method can enhance the resolution of the
#' low-dimensional representation into "sub-spots", for which features such as
#' gene expression or cell type composition can be imputed.
#'
#'
#' @details
#' For an overview of the functionality provided by the package, please see the
#' vignette:
#' \code{vignette("BayesSpace", package="BayesSpace")}
#'
#'
#' @docType package
#'
#' @name BayesSpace
#'
#'
#' @keywords internal
#'
#' @importFrom Rcpp evalCpp
#' @importFrom SummarizedExperiment assayNames
#' @importFrom SingleCellExperiment altExpNames
#' @useDynLib BayesSpace
#' @useDynLib BayesSpace, .registration=TRUE
NULL
"_PACKAGE"
28 changes: 18 additions & 10 deletions R/RcppExports.R
Original file line number Diff line number Diff line change
@@ -1,23 +1,31 @@
# Generated by using Rcpp::compileAttributes() -> do not edit by hand
# Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393

iterate <- function(Y, df_j, nrep, n, d, gamma, q, init, mu0, lambda0, alpha, beta) {
.Call(`_BayesSpace_iterate`, Y, df_j, nrep, n, d, gamma, q, init, mu0, lambda0, alpha, beta)
iterate <- function(Y, df_j, nrep, thin, n, d, gamma, q, init, mu0, lambda0, alpha, beta) {
.Call(`_BayesSpace_iterate`, Y, df_j, nrep, thin, n, d, gamma, q, init, mu0, lambda0, alpha, beta)
}

iterate_vvv <- function(Y, df_j, nrep, n, d, gamma, q, init, mu0, lambda0, alpha, beta) {
.Call(`_BayesSpace_iterate_vvv`, Y, df_j, nrep, n, d, gamma, q, init, mu0, lambda0, alpha, beta)
iterate_vvv <- function(Y, df_j, nrep, thin, n, d, gamma, q, init, mu0, lambda0, alpha, beta) {
.Call(`_BayesSpace_iterate_vvv`, Y, df_j, nrep, thin, n, d, gamma, q, init, mu0, lambda0, alpha, beta)
}

iterate_t <- function(Y, df_j, nrep, n, d, gamma, q, init, mu0, lambda0, alpha, beta) {
.Call(`_BayesSpace_iterate_t`, Y, df_j, nrep, n, d, gamma, q, init, mu0, lambda0, alpha, beta)
iterate_t <- function(Y, df_j, nrep, thin, n, d, gamma, q, init, mu0, lambda0, alpha, beta) {
.Call(`_BayesSpace_iterate_t`, Y, df_j, nrep, thin, n, d, gamma, q, init, mu0, lambda0, alpha, beta)
}

iterate_t_vvv <- function(Y, df_j, nrep, n, d, gamma, q, init, mu0, lambda0, alpha, beta) {
.Call(`_BayesSpace_iterate_t_vvv`, Y, df_j, nrep, n, d, gamma, q, init, mu0, lambda0, alpha, beta)
iterate_t_vvv <- function(Y, df_j, nrep, thin, n, d, gamma, q, init, mu0, lambda0, alpha, beta) {
.Call(`_BayesSpace_iterate_t_vvv`, Y, df_j, nrep, thin, n, d, gamma, q, init, mu0, lambda0, alpha, beta)
}

iterate_deconv <- function(Y, df_j, tdist, nrep, n, n0, d, gamma, q, init, subspots, verbose, jitter_scale, c, mu0, lambda0, alpha, beta, thread_num = 1L) {
.Call(`_BayesSpace_iterate_deconv`, Y, df_j, tdist, nrep, n, n0, d, gamma, q, init, subspots, verbose, jitter_scale, c, mu0, lambda0, alpha, beta, thread_num)
iterate_deconv <- function(subspot_positions, dist, spot_neighbors, Y, tdist, nrep, thin, n, n0, d, gamma, q, init, subspots, verbose, jitter_scale, adapt_before, c, mu0, lambda0, alpha, beta, thread_num = 1L) {
.Call(`_BayesSpace_iterate_deconv`, subspot_positions, dist, spot_neighbors, Y, tdist, nrep, thin, n, n0, d, gamma, q, init, subspots, verbose, jitter_scale, adapt_before, c, mu0, lambda0, alpha, beta, thread_num)
}

map_subspot2ref <- function(subspot_coords, ref_coords, thread_num = 1L) {
.Call(`_BayesSpace_map_subspot2ref`, subspot_coords, ref_coords, thread_num)
}

compute_corr <- function(m1, m2, thread_num = 1L) {
.Call(`_BayesSpace_compute_corr`, m1, m2, thread_num)
}

30 changes: 6 additions & 24 deletions R/mcmcChain.R
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,12 @@ NULL
#' @importFrom purrr map
.read_chain <- function(h5.fname, params = NULL, is.enhanced = FALSE) {
if (is.null(params)) {
if (is.enhanced)
params <- c("z", "mu", "lambda", "weights", "Y")
else {
params <- h5ls(h5.fname)$name
params <- params[params != "plogLik"]
}
}

.read_param <- function(par.name) {
Expand Down Expand Up @@ -178,16 +183,6 @@ NULL
.clean_chain <- function(out, method = c("cluster", "enhance"), thin=100)
{
method <- match.arg(method)
n_iter <- nrow(out$z) # this is technically n_iters / 100 for enhance

## Only one iteration included; need to cast vectors back to matrices
if (is.null(n_iter)) {
out$z <- matrix(out$z, nrow=1)
out$mu <- matrix(out$mu, nrow=1)
if ("weights" %in% names(out)) {
out$weights <- matrix(out$mu, nrow=1)
}
}

n <- ncol(out$z)
d <- ncol(out$lambda[[1]])
Expand All @@ -206,22 +201,9 @@ NULL
colnames(out$plogLik) <- c("pLogLikelihood")
if (method == "enhance") {
out$Y <- .flatten_matrix_list(out$Y, "Y", n, d)
out$Ychange <- as.matrix(out$Ychange)
colnames(out$Ychange) <- c("Ychange")
}

if (method == "enhance") {
## manually thin mu until updated in c++;
## keep init values for consistency with others
thinned_idx <- c(1, seq(thin, (n_iter - 1) * thin, thin))
out$mu <- out$mu[thinned_idx, ]

## Subset of a one-column matrix is a vector, not a matrix
out$Ychange <- as.matrix(out$Ychange[thinned_idx, ])
out$Ychange <- as.matrix(out$Ychange)
colnames(out$Ychange) <- c("Ychange")

out$plogLik <- as.matrix(out$plogLik[thinned_idx, ])
colnames(out$plogLik) <- c("pLogLikelihood")
}

out
Expand Down
2 changes: 1 addition & 1 deletion R/parallelize.R
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ paraLapply <- function(X, FUN, BPPARAM = NULL, cores = 1L, type = c("serial", "f
if (verbose) {
message(sprintf("[DEBUG] Provided effective arguments for the customized function: %s", .list2vec(.extra.args)))
}

do.call(
bplapply,
c(
Expand Down
4 changes: 2 additions & 2 deletions R/qTune.R
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ qTune <- function(sce, qs = seq(3, 7), burn.in = 100, nrep = 1000, cores = 1L, .

## Get neighbors
platform <- ifelse(is.null(args$platform), "Visium", args$platform)
df_j <- .find_neighbors(sce, platform)
df_j <- .find_neighbors(sce, platform)[[2]]

## Parse args from ... for cluster initialization
init.args <- c("init", "init.method")
Expand Down Expand Up @@ -115,7 +115,7 @@ qTune <- function(sce, qs = seq(3, 7), burn.in = 100, nrep = 1000, cores = 1L, .
},
cores = cores,
type = "fork",
verbose = FALSE
verbose = TRUE
)

attr(sce, "q.logliks") <- do.call(rbind, logliks)
Expand Down
Loading