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

chore: catch up to suite #1081

Merged
merged 69 commits into from
Dec 9, 2024
Merged
Changes from 18 commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
f41142b
temp
jiajic Oct 16, 2024
3436f49
chore: bump version for dev and drop remotes
jiajic Oct 30, 2024
7291349
Merge pull request #1062 from jiajic/suite_dev
jiajic Oct 30, 2024
1821c80
Merge branch 'suite' into suite_dev
jiajic Nov 1, 2024
578f39e
Update convenience_xenium.R
jiajic Nov 6, 2024
ae212be
Revert "temp"
jiajic Nov 6, 2024
16a30bf
Merge branch 'suite_dev' into xen_update
jiajic Nov 6, 2024
f61dcfd
Update convenience_xenium.R
jiajic Nov 6, 2024
8b0950f
temporarily lower R ver
jiajic Nov 6, 2024
ad9314f
Update convenience_xenium.R
jiajic Nov 6, 2024
f981835
Update convenience_xenium.R
jiajic Nov 6, 2024
eff1c71
Update convenience_xenium.R
jiajic Nov 6, 2024
8bf5431
Update convenience_xenium.R
jiajic Nov 6, 2024
0157ba8
fix tif path checking
jiajic Nov 7, 2024
2eb20b5
Update convenience_xenium.R
jiajic Nov 7, 2024
57788f0
fix: allow overwrite passing though ...
jiajic Nov 7, 2024
8555ccf
fix: change when image input type is checked
jiajic Nov 7, 2024
52abd97
fix: missing comma
jiajic Nov 7, 2024
5359eb2
fix: warning that the "focus" dir does not exist
jiajic Nov 7, 2024
4d35750
fix: focus img dir assignment
jiajic Nov 7, 2024
a23ca0e
Update convenience_xenium.R
jiajic Nov 7, 2024
0559c44
fix: ignore subdirectories within image focus dir
jiajic Nov 7, 2024
4a9da54
add centroid creation step
jiajic Nov 7, 2024
84c9cd2
Update convenience_xenium.R
jiajic Nov 7, 2024
1e33aa1
enh: update conv. fun
jiajic Nov 7, 2024
4e4e2dd
revert default changes
jiajic Nov 7, 2024
7f70a92
update prints and run docs
jiajic Nov 7, 2024
34d10ad
Revert "temporarily lower R ver"
jiajic Nov 7, 2024
ae5eab2
Merge pull request #1064 from jiajic/xen_update
jiajic Nov 7, 2024
fbdb139
chore: update news
jiajic Nov 7, 2024
4613aa8
chore: update news
jiajic Nov 8, 2024
89a031a
chore: add back remotes
jiajic Nov 8, 2024
084d645
Merge pull request #1065 from jiajic/suite_dev
jiajic Nov 8, 2024
ec38ab8
Merge pull request #1066 from drieslab/suite_dev
jiajic Nov 8, 2024
e5a266b
fix: account for when no morphology focus imgs found
jiajic Nov 15, 2024
92fdce2
fix: focus path detection when no focus directory but image is present
jiajic Nov 15, 2024
ede47ac
Update convenience_xenium.R
jiajic Nov 15, 2024
12412c3
fix: list naming indexing
jiajic Nov 15, 2024
a778a4d
add biocstyle
josschavezf Nov 16, 2024
dad552b
run devtools::document
josschavezf Nov 16, 2024
9fcd742
Merge pull request #1070 from josschavezf/suite_dev
josschavezf Nov 16, 2024
38e202a
add website changes
josschavezf Nov 16, 2024
049ec15
Merge branch 'suite_dev' of https://github.com/josschavezf/Giotto int…
josschavezf Nov 16, 2024
a816e98
Merge pull request #1071 from josschavezf/suite_dev
josschavezf Nov 16, 2024
ea1fa21
Merge branch 'suite_dev' into suite
josschavezf Nov 16, 2024
3b309ac
Merge pull request #1072 from josschavezf/suite
josschavezf Nov 16, 2024
4c4f2ca
chore: merge conflict
jiajic Nov 16, 2024
1321982
Merge pull request #1074 from jiajic/suite_dev
jiajic Nov 16, 2024
a13453e
segmentations
JunxiangXu Nov 19, 2024
2fb7f3f
Merge pull request #1076 from JunxiangXu/suite_dev
jiajic Nov 19, 2024
9138988
change scrublet seed setting
jiajic Nov 20, 2024
e3464a2
allow access to transcript datatable
jiajic Nov 20, 2024
ebff423
refactor: var explained
jiajic Nov 21, 2024
4d29198
enh: labelTransfer with integration
jiajic Nov 22, 2024
5035de8
chore: docs
jiajic Nov 22, 2024
be6ad66
chore: fix typo
jiajic Nov 25, 2024
4b22026
fix param passing
jiajic Nov 25, 2024
bfc8d26
Update clustering.R
jiajic Nov 26, 2024
74826a7
fix: prevent drop during matrix indexing
jiajic Dec 4, 2024
11d2880
enh: labelTransfer() harmony integration
jiajic Dec 8, 2024
771acc2
enh: labelTransfer() harmony integration
jiajic Dec 9, 2024
faf11e1
chore: reexport dotplot
jiajic Dec 9, 2024
fbee521
chore: update news
jiajic Dec 9, 2024
74dd669
chore: docs
jiajic Dec 9, 2024
eca4404
chore: merge conflict
jiajic Dec 9, 2024
d4f3e6f
chore: docs
jiajic Dec 9, 2024
402b4c9
Update NEWS.md
jiajic Dec 9, 2024
8ad8609
Merge pull request #1079 from jiajic/suite_dev
jiajic Dec 9, 2024
f3a78f6
Merge pull request #1080 from drieslab/suite_dev
jiajic Dec 9, 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
8 changes: 4 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: Giotto
Title: Spatial Single-Cell Transcriptomics Toolbox
Version: 4.1.5
Version: 4.1.6
Authors@R: c(
person("Ruben", "Dries", email = "[email protected]",
role = c("aut", "cre"), comment = c(ORCID = "0000-0001-7650-7754")),
@@ -28,7 +28,7 @@ RoxygenNote: 7.3.2
Depends:
R (>= 4.4.1),
methods,
GiottoClass (>= 0.4.1)
GiottoClass (>= 0.4.5)
Imports:
BiocParallel,
BiocSingular,
@@ -37,8 +37,8 @@ Imports:
dbscan (>= 1.1-3),
ggraph,
ggplot2 (>= 3.1.1),
GiottoUtils (>= 0.2.0),
GiottoVisuals (>= 0.2.6),
GiottoUtils (>= 0.2.2),
GiottoVisuals (>= 0.2.10),
igraph (>= 1.2.4.1),
Matrix (>= 1.6-2),
MatrixGenerics,
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -182,6 +182,7 @@ export(doRandomWalkCluster)
export(doSNNCluster)
export(doScrubletDetect)
export(doStardistSegmentation)
export(dotPlot)
export(estimateAutomatedImageRegistrationWithSIFT)
export(estimateImageBg)
export(exportGiottoViewer)
@@ -753,6 +754,7 @@ importFrom(GiottoVisuals,dimGenePlot3D)
importFrom(GiottoVisuals,dimPlot)
importFrom(GiottoVisuals,dimPlot2D)
importFrom(GiottoVisuals,dimPlot3D)
importFrom(GiottoVisuals,dotPlot)
importFrom(GiottoVisuals,getColors)
importFrom(GiottoVisuals,giottoSankeyPlan)
importFrom(GiottoVisuals,plotHeatmap)
21 changes: 21 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,25 @@

# Giotto 4.1.6 (2024/12/09)

## Bug fixes
* `doScrubletDetect()` seed setting

## Enhancements
* `labelTransfer()` now has `integration_method = "harmony"` for label transferring with an integration pipeline. See ?labelTransfer and the `integration_method` section.
* `importXenium()` `load_transcripts()` can now return a `data.table` rather than the `giottoPoints` representation

## New
* `doMesmerSegmentation()` and `doStardistSegmentation()` segmentation wrappers
* `.varexp()` internal for calculating SVD variance determined with support for partial SVDs
* `.cumvar()` internal for calculating cumulative variance explained
* re-export of `dotPlot()` from GiottoVisuals

## Changes
* GiottoClass req raised to 0.4.5
* GiottoUtils req raised to 0.2.2
* GiottoVisuals req raised to 0.2.10


# Giotto 4.1.5 (2024/11/08)

## Enhancements
343 changes: 327 additions & 16 deletions R/clustering.R

Large diffs are not rendered by default.

10 changes: 9 additions & 1 deletion R/convenience_xenium.R
Original file line number Diff line number Diff line change
@@ -238,6 +238,7 @@ setMethod(
dropcols = c(),
qv_threshold = obj@qv,
cores = determine_cores(),
output = c("giottoPoints", "data.table"),
verbose = NULL) {
.xenium_transcript(
path = path,
@@ -247,6 +248,7 @@ setMethod(
dropcols = dropcols,
qv_threshold = qv_threshold,
cores = cores,
output = output,
verbose = verbose
)
}
@@ -690,6 +692,7 @@ importXenium <- function(xenium_dir = NULL, qv_threshold = 20) {
dropcols = c(),
qv_threshold = 20,
cores = determine_cores(),
output = c("giottoPoints", "data.table"),
verbose = NULL) {
if (missing(path)) {
stop(wrap_txt(
@@ -704,6 +707,8 @@ importXenium <- function(xenium_dir = NULL, qv_threshold = 20) {
vmsg(.v = verbose, .is_debug = TRUE, "[TX_READ] FMT =", e)
vmsg(.v = verbose, .is_debug = TRUE, path)

output <- match.arg(output, choices = c("giottoPoints", "data.table"))

# read in as data.table
a <- list(
path = path,
@@ -726,6 +731,8 @@ importXenium <- function(xenium_dir = NULL, qv_threshold = 20) {
y <- NULL # NSE var
if (flip_vertical) tx[, y := -y]

if (output == "data.table") return(tx)

# create gpoints
gpointslist <- createGiottoPoints(
x = tx,
@@ -734,7 +741,8 @@ importXenium <- function(xenium_dir = NULL, qv_threshold = 20) {
verbose = FALSE
)

if (inherits(gpointslist, "list")) {
# enforce list
if (!inherits(gpointslist, "list")) {
gpointslist <- list(gpointslist)
}

55 changes: 36 additions & 19 deletions R/dimension_reduction.R
Original file line number Diff line number Diff line change
@@ -1928,24 +1928,9 @@ jackstrawPlot <- function(
}
n <- ncol(dat)
m <- nrow(dat)
ndf <- min(m, n - 1, ncp) # this is a limitation of svd singular values
sum_of_squared_singular_vals <- sum(dat^2)

# pick SVD fun based on whether partial or full is appropriate
# These biocsingular functions should not scale or center
svd_fun <- if (ndf >= 0.5 * m || ndf >= 100) {
BiocSingular::runExactSVD
} else {
BiocSingular::runIrlbaSVD
} # partial SVDs

.calc_svd_var_explained <- function(x, k) {
res <- svd_fun(x, k = k)
singular_val_square <- res$d[1:k]^2
return(singular_val_square / sum_of_squared_singular_vals)
}

dstat <- .calc_svd_var_explained(dat, k = ndf)
ndf <- min(m, n - 1, ncp) # this is also calculated in .varexp

dstat <- .varexp(dat, k = ncp)
cum_var_explained <- cumsum(dstat)

# randomize and compare
@@ -1961,7 +1946,7 @@ jackstrawPlot <- function(
for (i in seq_len(iter)) {
pb()
dat0 <- t(apply(dat, 1, sample))
dstat0[i, ] <- .calc_svd_var_explained(dat0, k = ndf)
dstat0[i, ] <- .varexp(dat0, k = ncp)
}
})

@@ -1977,7 +1962,39 @@ jackstrawPlot <- function(
return(list(r = r, p = p, cum_var_explained = cum_var_explained))
}

# calculate SVD variance explained, with support for partial SVDs
.varexp <- function(dat, k = 20) {
if (missing(dat)) {
stop("`dat` is required!")
}
n <- ncol(dat)
m <- nrow(dat)
ndf <- min(m, n - 1, k) # this is a limitation of svd singular values
sum_of_squared_singular_vals <- sum(dat^2)

# pick SVD fun based on whether partial or full is appropriate
# These biocsingular functions should not scale or center
svd_fun <- if (ndf >= 0.5 * m || ndf >= 100) {
BiocSingular::runExactSVD
} else {
BiocSingular::runIrlbaSVD
} # partial SVDs

res <- svd_fun(dat, k)
singular_val_square <- res$d[1:k]^2
perc <- singular_val_square / sum_of_squared_singular_vals
return(perc)
}

# cumulative variance explained
.cumvar <- function(dat, k = 20, last = TRUE) {
a <- get_args_list(keep = c("dat", "k"))
res <- cumsum(do.call(.varexp, a))
if (last) {
res <- tail(res, 1L)
}
return(res)
}


#' @title signPCA
6 changes: 4 additions & 2 deletions R/normalize.R
Original file line number Diff line number Diff line change
@@ -425,8 +425,10 @@ normalizeGiotto <- function(gobject,
)

### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ###
gobject <- setGiotto(gobject, norm_expr, initialize = FALSE)
gobject <- setGiotto(gobject, norm_scaled_expr, initialize = FALSE)
gobject <- setGiotto(
gobject, norm_expr, verbose = verbose, initialize = FALSE)
gobject <- setGiotto(
gobject, norm_scaled_expr, verbose = verbose, initialize = FALSE)
### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ###

## 6. return Giotto object
11 changes: 5 additions & 6 deletions R/python_scrublet.R
Original file line number Diff line number Diff line change
@@ -73,11 +73,9 @@ doScrubletDetect <- function(

# set seed
if (!is.null(seed)) {
seed_number <- as.numeric(seed)
reticulate::py_set_seed(
seed = seed_number,
disable_hash_randomization = TRUE
)
seed_number <- as.integer(seed)
} else {
seed_number <- random_seed()
}

# Set feat_type and spat_unit
@@ -116,7 +114,8 @@ doScrubletDetect <- function(
min_counts = min_counts,
min_cells = min_cells,
min_gene_variability_pctl = min_gene_variability_pctl,
n_prin_comps = n_prin_comps
n_prin_comps = n_prin_comps,
seed_number = seed_number
)

scrublet_out <- data.table::data.table(
10 changes: 5 additions & 5 deletions R/spatial_enrichment.R
Original file line number Diff line number Diff line change
@@ -2279,7 +2279,7 @@ enrich_deconvolution <- function(
ct_exp,
cutoff) {
##### generate enrich 0/1 matrix based on expression matrix
ct_exp <- ct_exp[rowSums(ct_exp) > 0, ]
ct_exp <- ct_exp[rowSums(ct_exp) > 0, , drop = FALSE]
enrich_matrix <- matrix(0, nrow = dim(ct_exp)[1], ncol = dim(ct_exp)[2])
rowmax_col <- Rfast::rowMaxs(ct_exp)
for (i in seq_along(rowmax_col)) {
@@ -2321,9 +2321,9 @@ enrich_deconvolution <- function(
ct_gene <- c(ct_gene, sig_gene_j)
}
uniq_ct_gene <- intersect(rownames(expr), unique(ct_gene))
select_sig_exp <- ct_exp[uniq_ct_gene, ct]
select_sig_exp <- ct_exp[uniq_ct_gene, ct, drop = FALSE]
cluster_i_cell <- which(cluster_info == cluster_sort[i])
cluster_cell_exp <- expr[uniq_ct_gene, cluster_i_cell]
cluster_cell_exp <- expr[uniq_ct_gene, cluster_i_cell, drop = FALSE]

cluster_i_dwls <- optimize_deconvolute_dwls(
cluster_cell_exp, select_sig_exp
@@ -2383,9 +2383,9 @@ spot_deconvolution <- function(
ct_gene <- c(ct_gene, sig_gene_j)
}
uniq_ct_gene <- intersect(rownames(expr), unique(ct_gene))
select_sig_exp <- ct_exp[uniq_ct_gene, ct_i]
select_sig_exp <- ct_exp[uniq_ct_gene, ct_i, drop = FALSE]
cluster_i_cell <- which(cluster_info == cluster_sort[i])
cluster_cell_exp <- expr[uniq_ct_gene, cluster_i_cell]
cluster_cell_exp <- expr[uniq_ct_gene, cluster_i_cell, drop = FALSE]
###### calculate
###### overlap signature with spatial genes
all_exp <- Matrix::rowMeans(cluster_cell_exp)
2 changes: 2 additions & 0 deletions R/suite_reexports.R
Original file line number Diff line number Diff line change
@@ -471,6 +471,8 @@ GiottoClass::writeGiottoLargeImage
#' @export
GiottoVisuals::addGiottoImageToSpatPlot
#' @export
GiottoVisuals::dotPlot
#' @export
GiottoVisuals::dimCellPlot
#' @export
GiottoVisuals::dimCellPlot2D
5 changes: 3 additions & 2 deletions inst/python/python_scrublet.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import scrublet as scr

def python_scrublet(counts_matrix, expected_doublet_rate, min_counts, min_cells, min_gene_variability_pctl, n_prin_comps):
def python_scrublet(counts_matrix, expected_doublet_rate, min_counts, min_cells, min_gene_variability_pctl, n_prin_comps, seed_number=1234):

min_counts = int(min_counts)
min_cells = int(min_cells)
min_gene_variability_pctl = int(min_gene_variability_pctl)
n_prin_comps = int(n_prin_comps)
random_state = int(seed_number)

scrub = scr.Scrublet(counts_matrix=counts_matrix, expected_doublet_rate=expected_doublet_rate)
scrub = scr.Scrublet(counts_matrix=counts_matrix, expected_doublet_rate=expected_doublet_rate, random_state=random_state)
doublet_scores, predicted_doublets = scrub.scrub_doublets(min_counts=min_counts,min_cells=min_cells, min_gene_variability_pctl=min_gene_variability_pctl, n_prin_comps=n_prin_comps)

return_list = []
51 changes: 48 additions & 3 deletions man/labelTransfer.Rd
3 changes: 2 additions & 1 deletion man/reexports.Rd