Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@

* MINOR CHANGE: `load_cellxgene_census` requires a dated Census release, since `latest` and `stable` give different datasets over time.

* MAJOR CHANGE: Move to anndata 0.13 (base images v1.3.0), which writes zarr v3 with sharded arrays, so a dataset has far fewer files. `ANNDATA_AUTO_SHARD_ZARR_V3=1` makes the sharding explicit, and the deprecated `ANNDATA_ZARR_WRITE_FORMAT` is dropped. Test resources regenerated.

* BUG FIX: The Census and NeurIPS loaders no longer name the `var` index after the `feature_id` column, which anndata 0.13 refuses to write back after reading. `log_scran_pooling` no longer needs the `anndata` R package, and `atac_tfidf` no longer pins `numpy<2`, which held it on anndata 0.12.

* MINOR CHANGE: Pin BLAS, OpenMP and numba to 4 threads in every Docker image. The PCA (and with it the kNN graph) depended on the number of cores of the machine.

* MAJOR CHANGE: Raw scRNA-seq datasets must have CELLxGENE-style ontology term ids for the assay, cell type, developmental stage, disease, self-reported ethnicity, sex and tissue. The multimodal loaders use a new `file_multimodal_raw` spec, in which these stay optional.
Expand Down
4 changes: 2 additions & 2 deletions _viash.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ links:

config_mods: |
.runners[.type == "nextflow"].config.labels := { lowmem : "memory = 20.Gb", midmem : "memory = 50.Gb", highmem : "memory = 100.Gb", lowcpu : "cpus = 5", midcpu : "cpus = 15", highcpu : "cpus = 30", lowtime : "time = 1.h", midtime : "time = 4.h", hightime : "time = 8.h", veryhightime : "time = 24.h" }
.engines[.type == "docker"].setup += { type: "docker", env: ["ANNDATA_ZARR_WRITE_FORMAT=3", "OMP_NUM_THREADS=4", "OPENBLAS_NUM_THREADS=4", "MKL_NUM_THREADS=4", "NUMBA_NUM_THREADS=4"] }
.engines[.type == "docker"].setup += { type: "docker", env: ["ANNDATA_AUTO_SHARD_ZARR_V3=1", "OMP_NUM_THREADS=4", "OPENBLAS_NUM_THREADS=4", "MKL_NUM_THREADS=4", "NUMBA_NUM_THREADS=4"] }

repositories:
- name: openproblems
Expand All @@ -32,6 +32,6 @@ repositories:
info:
test_resources:
# created by scripts/create_test_resources/cxg_mouse_pancreas_atlas.ipynb
- path: lamin://openproblems/data-dev/collection/Ajn1Lo8zZomVzKtQ0004
- path: lamin://openproblems/data-dev/collection/Ajn1Lo8zZomVzKtQ0005
dest: resources_test/common/cxg_mouse_pancreas_atlas
strip_prefix: resources_test/datasets/cxg_mouse_pancreas_atlas/
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ def convert_matrix(adata):
mod1_var["feature_id"] = np.where(mod1_var.gene_id.isna(), mod1_var.feature_name, mod1_var.gene_id.astype(str))
mod1_var.drop("gene_id", axis=1, inplace=True)
mod1_var.set_index("feature_id", drop=False, inplace=True)
mod1_var.index.name = None

mod1_obs = pd.DataFrame(adata_mod1.obs)
remove_mod_col(mod1_obs, par["mod2"])
Expand All @@ -89,6 +90,7 @@ def convert_matrix(adata):
mod2_var["feature_id"] = np.where(mod2_var.gene_id.isna(), mod2_var.feature_name, mod2_var.gene_id.astype(str))
mod2_var.drop("gene_id", axis=1, inplace=True)
mod2_var.set_index("feature_id", drop=False, inplace=True)
mod2_var.index.name = None

mod2_obs = pd.DataFrame(adata_mod2.obs)
remove_mod_col(mod2_obs, par["mod1"])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,13 @@ def convert_matrix(adata):
if "_" in adata_mod1.var.index[0]:
adata_mod1.var['feature_name'] = [str(s).split('_')[1] for s in adata_mod1.var.index.tolist()]
adata_mod1.var.set_index('feature_id',drop=False, inplace=True)
adata_mod1.var.index.name = None

# set feature_name (proteins have only partial ensemble IDs))
adata_mod2.var['feature_id'] = adata_mod2.var.index.tolist() # feature id needs to be filled in
adata_mod2.var['feature_name'] = adata_mod2.var.index.tolist()
adata_mod2.var.set_index('feature_name',drop=False, inplace=True)
adata_mod2.var.index.name = None


# remove adata.X
Expand Down
1 change: 1 addition & 0 deletions src/loaders/scrnaseq/cellxgene_census/script.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ def main(par, meta):

# use feature_id as var_names
adata.var_names = adata.var["feature_id"]
adata.var.index.name = None

# not needed as long as we have our own implementation of `get_anndata`
# move .X to .layers["counts"]
Expand Down
1 change: 0 additions & 1 deletion src/normalization/atac_tfidf/config.vsh.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ engines:
- type: python
packages:
- muon
- numpy<2
runners:
- type: executable
- type: nextflow
Expand Down
19 changes: 10 additions & 9 deletions src/normalization/log_scran_pooling/script.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cat(">> Loading dependencies\n")
library(anndata, warn.conflicts = FALSE)
requireNamespace("reticulate", quietly = TRUE)
requireNamespace("scran", quietly = TRUE)
requireNamespace("BiocParallel", quietly = TRUE)
library(Matrix, warn.conflicts = FALSE)
Expand All @@ -14,26 +14,27 @@ par <- list(
## VIASH END

cat(">> Load data\n")
# anndata::read_zarr() calls itself in R anndata 0.8.0, read through python instead
adata <- reticulate::import("anndata")$read_zarr(par$input)
counts <- as(t(adata$layers[["counts"]]), "CsparseMatrix")
# read through python anndata, since anndataR can't read sharded zarr yet
ad <- reticulate::import("anndata", convert = FALSE)
adata <- ad$read_zarr(par$input)
counts <- as(t(reticulate::py_to_r(adata$layers[["counts"]])), "CsparseMatrix")

cat(">> Normalizing data\n")
size_factors <- scran::calculateSumFactors(
counts,
min.mean = 0.1,
BPPARAM = BiocParallel::MulticoreParam()
)
lognorm <- log1p(sweep(adata$layers[["counts"]], 1, size_factors, "*"))
lognorm <- log1p(Matrix::Diagonal(x = size_factors) %*% Matrix::t(counts))

cat(">> Storing in anndata\n")
adata$obs[[par$obs_size_factors]] <- size_factors
adata$layers[[par$layer_output]] <- lognorm
norm_id <- par[["normalization_id"]]
if (is.null(norm_id)) {
norm_id <- meta[["name"]]
}
adata$uns[["normalization_id"]] <- norm_id
reticulate::py_set_item(adata$obs, par$obs_size_factors, reticulate::r_to_py(size_factors))
reticulate::py_set_item(adata$layers, par$layer_output, reticulate::r_to_py(as(lognorm, "CsparseMatrix")))
reticulate::py_set_item(adata$uns, "normalization_id", norm_id)

cat(">> Writing to file\n")
zzz <- adata$write_zarr(par$output)
adata$write_zarr(par$output)