Closed pati-ni closed 9 months ago
I have the same issue with the small example
X <- as(matrix(1:6, nrow = 2), "dgCMatrix")
obs <- data.frame(group = c("a", "b"), row.names = c("s1", "s2"))
var <- data.frame(type = c(1L, 2L, 3L), row.names = c("var1", "var2", "var3"))
ad <- anndata::AnnData(
X = X,
obs = obs,
var = var,
layers = list(
spliced = matrix(4:9, nrow = 2),
unspliced = matrix(8:13, nrow = 2)
),
obsm = list(
ones = matrix(rep(1L, 10), nrow = 2),
rand = matrix(rnorm(6), nrow = 2),
zeros = matrix(rep(0L, 10), nrow = 2)
),
varm = list(
ones = matrix(rep(1L, 12), nrow = 3),
rand = matrix(rnorm(6), nrow = 3),
zeros = matrix(rep(0L, 12), nrow = 3)
),
uns = list(
a = 1,
b = data.frame(i = 1:3, j = 4:6, value = runif(3)),
c = list(c.a = 3, c.b = 4)
)
)
With the following error,
ad$X
Error in validObject(.Object) :
invalid class “dgCMatrix” object: 'Dim' slot does not have length 2
It seems like scipy renamed a few things again (see https://github.com/rstudio/reticulate/blame/main/R/conversion.R#L649-L656).
Please downgrade scipy to <1.11 or upgrade reticulate to the latest development version by running remotes::install_github("rstudio/reticulate")
.
Can you confirm this solves your problem?
Upgrade reticulate
to the latest development version worked for me
@rcannood As your advice,I upgrade the reticulate.It`s actually solved my problem,and brought a new error
> data <- CreateSeuratObject(counts = t(data$X), meta.data = data$obs)
Error in t.default(data$X) : argument is not a matrix
It can be solved by add as.matrix to data$X
> data <- CreateSeuratObject(counts = t(as.matrix(data$X)), meta.data = data$obs)
Warning message:
In asMethod(object) :
sparse->dense coercion: allocating vector of size 9.2 GiB
Happy to hear this has solved your issue!
With respect to the newest error: this is because the $X in this case seems to be a sparse matrix. If you want to transpose a sparse matrix, you first need to call library(Matrix)
or use Matrix::t(data$X)
instead. This is usually more efficient than converting it to a dense matrix.
Can you confirm whether this also solves your problem?
I'm closing this issue since the original problem was solved. Feel free to open up a new issue for other problems that may occur :)
Thanks for your replying.
After calling library(Matrix)
at first,no error reports
> library(anndata)
> library(Matrix)
> library(Seurat)
Attaching SeuratObject
> data <- read_h5ad("ARHL_lyaer_counts_harmonyed.h5ad")
> data
AnnData object with n_obs × n_vars = 61322 × 20180
obs: 'batch', 'nUMIs', 'mito_perc', 'detected_genes', 'cell_complexity', 'n_genes', 'doublet_score', 'predicted_doublet', 'passing_mt', 'passing_nUMIs', 'passing_ngenes'
var: 'gene_ids', 'feature_types', 'mt', 'n_cells', 'percent_cells', 'robust', 'mean', 'var', 'residual_variances', 'highly_variable_rank', 'highly_variable_features'
uns: 'batch_colors', 'hvg', 'layers_counts', 'layers_raw', 'log1p', 'neighbors', 'scaled|original|cum_sum_eigenvalues', 'scaled|original|pca_var_ratios', 'scrublet', 'umap'
obsm: 'X_harmony', 'X_pca', 'X_umap', 'scaled|original|X_pca'
obsp: 'connectivities', 'distances'
> Matrix::rowMeans(data$X[1:10,])
AAACCCAAGAGGGTGG-1 AAACCCACAAATGATG-1 AAACCCACACGGTAGA-1 AAACCCACAGCTTCGG-1 AAACCCACATGGAATA-1 AAACCCAGTCGGATTT-1 AAACCCAGTCTTCATT-1 AAACCCATCAGTGATC-1
0.10138751 0.06541130 0.04479683 0.07571853 0.12462834 0.02730426 0.14400396 0.07507433
AAACCCATCTCTGCTG-1 AAACGAAAGCGAGAAA-1
0.14335976 0.07735382
> data1 <- CreateSeuratObject(counts = t(data$X), meta.data = data$obs)
> data2 <- CreateSeuratObject(counts = Matrix::t(data$X), meta.data = data$obs)
no error/warning appears,and more efficient than use as.matrix
It perfectly works
Hi,
the package is non functional in my setup when I try to load an h5ad file:
My sessionInfo():
and my python
3.10
withanndata
version0.9.1