diff --git a/NEWS.md b/NEWS.md index 2a428d9..fa7cedb 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,6 +2,8 @@ * Bioconductor 3.20, October 2024 +* Fix correctly assign levels to factors in R reader with **anndata** v0.7 files (Fixes #122) + ## zellkonverter 1.15.3 (2024-10-04) * Correctly assign levels to factors in R reader (Fixes #122) diff --git a/R/read.R b/R/read.R index 36537b7..09f9827 100644 --- a/R/read.R +++ b/R/read.R @@ -368,7 +368,8 @@ readH5AD <- function(file, X_name = NULL, use_hdf5 = FALSE, levels <- as.vector( rhdf5::h5read(file, file.path(path, "__categories", cat_name)) ) - out_cols[[cat_name]] <- factor(out_cols[[cat_name]], levels = levels) + codes <- out_cols[[cat_name]] + 1L + out_cols[[cat_name]] <- factor(levels[codes], levels = levels) } ## rhdf5::h5readAttributes(file, "var") |> str()