From fa26b4739b937a24b65c36679881c9650a9b5c92 Mon Sep 17 00:00:00 2001 From: Robrecht Cannoodt Date: Thu, 19 Nov 2026 10:17:12 +0100 Subject: [PATCH 1/6] move to anndata 0.13 with sharding --- CHANGELOG.md | 2 ++ _viash.yaml | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ab714d9..88838ca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,8 @@ * 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. + * 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. diff --git a/_viash.yaml b/_viash.yaml index 28e1ccd..b2f1deb 100644 --- a/_viash.yaml +++ b/_viash.yaml @@ -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 From 91f16dbb9e09e099faf81249e47c408214367af2 Mon Sep 17 00:00:00 2001 From: Robrecht Cannoodt Date: Thu, 19 Nov 2026 10:31:51 +0100 Subject: [PATCH 2/6] do not name var index after a column --- src/loaders/multimodal/openproblems_neurips2021_bmmc/script.py | 2 ++ src/loaders/multimodal/openproblems_neurips2022_pbmc/script.py | 2 ++ src/loaders/scrnaseq/cellxgene_census/script.py | 1 + 3 files changed, 5 insertions(+) diff --git a/src/loaders/multimodal/openproblems_neurips2021_bmmc/script.py b/src/loaders/multimodal/openproblems_neurips2021_bmmc/script.py index 6edb2d5..1a14600 100644 --- a/src/loaders/multimodal/openproblems_neurips2021_bmmc/script.py +++ b/src/loaders/multimodal/openproblems_neurips2021_bmmc/script.py @@ -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"]) @@ -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"]) diff --git a/src/loaders/multimodal/openproblems_neurips2022_pbmc/script.py b/src/loaders/multimodal/openproblems_neurips2022_pbmc/script.py index 0c48f52..c609852 100644 --- a/src/loaders/multimodal/openproblems_neurips2022_pbmc/script.py +++ b/src/loaders/multimodal/openproblems_neurips2022_pbmc/script.py @@ -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 diff --git a/src/loaders/scrnaseq/cellxgene_census/script.py b/src/loaders/scrnaseq/cellxgene_census/script.py index 132dfe5..797192e 100644 --- a/src/loaders/scrnaseq/cellxgene_census/script.py +++ b/src/loaders/scrnaseq/cellxgene_census/script.py @@ -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"] From f174f1030b5cbc4f64fa62c996d3a1cf1ff58e9a Mon Sep 17 00:00:00 2001 From: Robrecht Cannoodt Date: Thu, 19 Nov 2026 11:16:14 +0100 Subject: [PATCH 3/6] fix scran and tfidf normalizers on anndata 0.13 --- src/normalization/atac_tfidf/config.vsh.yaml | 1 - src/normalization/log_scran_pooling/script.R | 19 ++++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/normalization/atac_tfidf/config.vsh.yaml b/src/normalization/atac_tfidf/config.vsh.yaml index a66d9de..a038344 100644 --- a/src/normalization/atac_tfidf/config.vsh.yaml +++ b/src/normalization/atac_tfidf/config.vsh.yaml @@ -16,7 +16,6 @@ engines: - type: python packages: - muon - - numpy<2 runners: - type: executable - type: nextflow diff --git a/src/normalization/log_scran_pooling/script.R b/src/normalization/log_scran_pooling/script.R index f35d3f5..48bf081 100644 --- a/src/normalization/log_scran_pooling/script.R +++ b/src/normalization/log_scran_pooling/script.R @@ -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) @@ -14,9 +14,10 @@ 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( @@ -24,16 +25,16 @@ size_factors <- scran::calculateSumFactors( 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) From 7d563362edbfbf22545695dc381bf38fee9dc485 Mon Sep 17 00:00:00 2001 From: Robrecht Cannoodt Date: Thu, 19 Nov 2026 11:16:14 +0100 Subject: [PATCH 4/6] update test resources --- _viash.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_viash.yaml b/_viash.yaml index b2f1deb..14d0252 100644 --- a/_viash.yaml +++ b/_viash.yaml @@ -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/ From 9dbd7867f87d6e70a944540375fdb7dc4d465871 Mon Sep 17 00:00:00 2001 From: Robrecht Cannoodt Date: Thu, 19 Nov 2026 11:16:14 +0100 Subject: [PATCH 5/6] update changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 88838ca..b7fef24 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,8 @@ * 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. From f6c202c5678fd23311a552be15061beaa757ddf7 Mon Sep 17 00:00:00 2001 From: Robrecht Cannoodt Date: Thu, 19 Nov 2026 11:16:14 +0100 Subject: [PATCH 6/6] ci force