theislab / zellkonverter

Conversion between scRNA-seq objects
https://theislab.github.io/zellkonverter/
Other
144 stars 27 forks source link

read dimnames correctly when using 'native' input #93

Closed mtmorgan closed 1 year ago

mtmorgan commented 1 year ago
mtmorgan commented 1 year ago

Previous code assumed that the "_index" was stored in .h5ad as "_index", but the specification allows this to be remapped. So an .h5ad file with

    ## rhdf5::h5readAttributes(file, "var") |> str()
    ## List of 4
    ##  $ _index          : chr "feature_id"
    ##  $ column-order    : chr [1:4(1d)] "feature_is_filtered" "feature_name" "feature_reference" "feature_biotype"
    ##  $ encoding-type   : chr "dataframe"
    ##  $ encoding-version: chr "0.2.0"

would NOT have rownames assigned, even though they were present in h5ad.

A complicated example is

suppressPackageStartupMessages({
    library(cellxgenedp)
    library(zellkonverter)
    library(HDF5Array)
})

h5ad_file <-
    files(db(overwrite = FALSE)) |>
    filter(file_id == "e2874fd9-af11-4adf-a47a-f380b7606434") |>
    files_download(dry.run = FALSE)

sce <- readH5AD(h5ad_file, use_hdf5 = TRUE, reader = "R")
SingleCellExperiment::rowData(sce) # no rownames
lazappi commented 1 year ago

Thanks @mtmorgan! I have merged this as is to make sure it gets into the release but please open a new PR adding yourself as a contributor if you like.