dynverse / anndata

Annotated multivariate observation data in R
https://anndata.dynverse.org
Other
43 stars 4 forks source link

Error in py_set_attr_impl(x, name, value) #5

Closed akhst7 closed 3 years ago

akhst7 commented 3 years ago

Hi,

I am trying add some layers to my AnnData file and get an error as follows;

pbmc10k.ad$layers<-list(unsp, rna)
Error in py_set_attr_impl(x, name, value) : 
  ValueError: dictionary update sequence element #0 has length 1; 2 is required

Files in questions are as follows;

pbmc10k.ad
AnnData object with n_obs × n_vars = 10194 × 36601
    obs: 'nCount_RNA', 'nFeature_RNA', 'nCount_SCT', 'nFeature_SCT', 'SCT_snn_res.0.8', 'seurat_clusters', 'nCount_unspliced', 'nFeature_unspliced'
    var: 'name'
    obsm: 'X_pca', 'X_umap'
> unsp<-pbmc10k.ad$obs["nCount_unspliced"]
> dim(unsp)
[1] 10194     1
> head(unsp)
                   nCount_unspliced
AAACCCACATAACTCG-1            12648
AAACCCACATGTAACC-1             7323
AAACCCAGTGAGTCAG-1            10260
AAACCCAGTGCTTATG-1             1509
AAACGAACAGTCAGTT-1            12001
AAACGAACATTCGGGC-1             6243
> rna<-pbmc10k.ad$obs["nCount_RNA"]
> dim(rna)
[1] 10194     1
> head(pbmc10k.ad$obs["nCount_RNA"])
                   nCount_RNA
AAACCCACATAACTCG-1      22575
AAACCCACATGTAACC-1       7758
AAACCCAGTGAGTCAG-1      21733
AAACCCAGTGCTTATG-1        860
AAACGAACAGTCAGTT-1      15311
AAACGAACATTCGGGC-1      10013
> package.version("anndata")
[1] "0.7.5.1"

Python dict issue ? Anyway, I appreciate any help on this.

Thanks.

rcannood commented 3 years ago

Hi @akhst7,

This is an oversight on my part. Could you try running the following? Does this already work for you?

pbmc10k.ad$layers[["unsp"]] <- unsp
pbmc10k.ad$layers[["rna"]] <- rna

If it does, please leave this issue open so that I know to add the functionality mentioned in the first post.

Kind regards, Robrecht

akhst7 commented 3 years ago

@rcannood,

Thanks for the response. I tired above but this failed as well.

> pbmc10k.ad$layers[["unsp"]]<-unsp
 Error in py_call_impl(callable, dots$args, dots$keywords) : 
  ValueError: Value passed for key 'unsp' is of incorrect shape. Values of layers must match dimensions (0, 1) of parent. Value had shape (10194, 1) while it should have had (10194, 36601). 
6.
stop(structure(list(message = "ValueError: Value passed for key 'unsp' is of incorrect shape. Values of layers must match dimensions (0, 1) of parent. Value had shape (10194, 1) while it should have had (10194, 36601).", 
    call = py_call_impl(callable, dots$args, dots$keywords), 
    cppstack = structure(list(file = "", line = -1L, stack = c("1   reticulate.so                       0x000000010df4a65e _ZN4Rcpp9exceptionC2EPKcb + 222", 
    "2   reticulate.so                       0x000000010df52735 _ZN4Rcpp4stopERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEE + 53",  ... 
5.
_validate_value at aligned_mapping.py#52
4.
__setitem__ at aligned_mapping.py#151
3.
x$.__enclos_env__$private$.layers$`__setitem__`(name, value) 
2.
`[[<-.LayersR6`(`*tmp*`, "unsp", value = structure(list(nCount_unspliced = c(12648, 
7323, 10260, 1509, 12001, 6243, 4795, 5154, 15202, 6330, 11564, 
8443, 4031, 2754, 4417, 2299, 2514, 3265, 2292, 5548, 4473, 9594, 
4167, 5108, 10666, 1961, 1473, 14621, 6071, 8165, 1922, 4738,  ... 
1.
`[[<-`(`*tmp*`, "unsp", value = structure(list(nCount_unspliced = c(12648, 
7323, 10260, 1509, 12001, 6243, 4795, 5154, 15202, 6330, 11564, 
8443, 4031, 2754, 4417, 2299, 2514, 3265, 2292, 5548, 4473, 9594, 
4167, 5108, 10666, 1961, 1473, 14621, 6071, 8165, 1922, 4738,  ... 
rcannood commented 3 years ago

Hi @akhst7,

This issue is caused by anndata itself, not the R wrapper for it. You can't assign unsp to the layers, because it has a different dimension than the rest of your anndata file.

See the discussion at theislab/anndata#237 for more information.

Kind regards, Robrecht