theMILOlab / SPATA2

A Toolbox for Spatial Transcriptomics Analysis
https://themilolab.github.io/SPATA2/
105 stars 17 forks source link

issue with Visium V2: converting from adata to SPATA2 #168

Open GUOYF0412 opened 2 months ago

GUOYF0412 commented 2 months ago

Dear MILOlab, when I try to _convert my adatasp object to SPATA2, some errors occur below

spata_object <- asSPATA2(adata_object, sample_name = "D1", platform = "VisiumSmall", modality = "gene")

11:04:56 Initiating SPATA2 object of spatial platform: `VisiumSmall`
11:04:56 Transferring data.
Error: Conversion from numpy array type 20 is not supported

I check the adata_sp.h5ad object:

rhdf5::h5ls("adata_sp.h5ad")
                            group                        name       otype   dclass             dim
0                               /                           X   H5I_GROUP                         
1                              /X                        data H5I_DATASET    FLOAT        10236985
2                              /X                     indices H5I_DATASET  INTEGER        10236985
3                              /X                      indptr H5I_DATASET  INTEGER            4920
4                               /                      layers   H5I_GROUP                         
5                         /layers                      counts   H5I_GROUP                         
6                  /layers/counts                        data H5I_DATASET    FLOAT        10236985
7                  /layers/counts                     indices H5I_DATASET  INTEGER        10236985
8                  /layers/counts                      indptr H5I_DATASET  INTEGER            4920
9                         /layers                     lognorm   H5I_GROUP                         
10                /layers/lognorm                        data H5I_DATASET    FLOAT        10236985
11                /layers/lognorm                     indices H5I_DATASET  INTEGER        10236985
12                /layers/lognorm                      indptr H5I_DATASET  INTEGER            4920
13                        /layers                      scaled H5I_DATASET    FLOAT    18085 x 4919
14                              /                         obs   H5I_GROUP                         
15                           /obs                      _index H5I_DATASET   STRING            4919
16                           /obs                   array_col H5I_DATASET  INTEGER            4919
17                           /obs                   array_row H5I_DATASET  INTEGER            4919
18                           /obs                   in_tissue H5I_DATASET  INTEGER            4919
19                           /obs                  leiden 0.1   H5I_GROUP                         
20                /obs/leiden 0.1                  categories H5I_DATASET   STRING               2
21                /obs/leiden 0.1                       codes H5I_DATASET  INTEGER            4919
22                           /obs                  leiden 0.2   H5I_GROUP                         
23                /obs/leiden 0.2                  categories H5I_DATASET   STRING               5
24                /obs/leiden 0.2                       codes H5I_DATASET  INTEGER            4919
25                           /obs                  leiden 0.3   H5I_GROUP                         
26                /obs/leiden 0.3                  categories H5I_DATASET   STRING               7
27                /obs/leiden 0.3                       codes H5I_DATASET  INTEGER            4919
28                           /obs                  leiden 0.5   H5I_GROUP                         
29                /obs/leiden 0.5                  categories H5I_DATASET   STRING               8
30                /obs/leiden 0.5                       codes H5I_DATASET  INTEGER            4919
31                           /obs                  leiden 0.8   H5I_GROUP                         
32                /obs/leiden 0.8                  categories H5I_DATASET   STRING              11
33                /obs/leiden 0.8                       codes H5I_DATASET  INTEGER            4919
34                           /obs                    leiden 1   H5I_GROUP                         
35                  /obs/leiden 1                  categories H5I_DATASET   STRING              17
36                  /obs/leiden 1                       codes H5I_DATASET  INTEGER            4919
37                           /obs     log1p_n_genes_by_counts H5I_DATASET    FLOAT            4919
38                           /obs          log1p_total_counts H5I_DATASET    FLOAT            4919
39                           /obs       log1p_total_counts_mt H5I_DATASET    FLOAT            4919
40                           /obs                    n_counts H5I_DATASET    FLOAT            4919
41                           /obs           n_genes_by_counts H5I_DATASET  INTEGER            4919
42                           /obs pct_counts_in_top_100_genes H5I_DATASET    FLOAT            4919
43                           /obs pct_counts_in_top_200_genes H5I_DATASET    FLOAT            4919
44                           /obs pct_counts_in_top_500_genes H5I_DATASET    FLOAT            4919
45                           /obs  pct_counts_in_top_50_genes H5I_DATASET    FLOAT            4919
46                           /obs               pct_counts_mt H5I_DATASET    FLOAT            4919
47                           /obs                total_counts H5I_DATASET    FLOAT            4919
48                           /obs             total_counts_mt H5I_DATASET    FLOAT            4919
49                              /                        obsm   H5I_GROUP                         
50                          /obsm                       X_pca H5I_DATASET    FLOAT       50 x 4919
51                          /obsm                      X_umap H5I_DATASET    FLOAT        2 x 4919
52                          /obsm                     spatial H5I_DATASET    FLOAT        2 x 4919
53                              /                        obsp   H5I_GROUP                         
54                          /obsp              connectivities   H5I_GROUP                         
55           /obsp/connectivities                        data H5I_DATASET    FLOAT          119630
56           /obsp/connectivities                     indices H5I_DATASET  INTEGER          119630
57           /obsp/connectivities                      indptr H5I_DATASET  INTEGER            4920
58                          /obsp                   distances   H5I_GROUP                         
59                /obsp/distances                        data H5I_DATASET    FLOAT           68866
60                /obsp/distances                     indices H5I_DATASET  INTEGER           68866
61                /obsp/distances                      indptr H5I_DATASET  INTEGER            4920
62                              /                         raw   H5I_GROUP                         
63                           /raw                           X   H5I_GROUP                         
64                         /raw/X                        data H5I_DATASET    FLOAT        10236985
65                         /raw/X                     indices H5I_DATASET  INTEGER        10236985
66                         /raw/X                      indptr H5I_DATASET  INTEGER            4920
67                           /raw                         var   H5I_GROUP                         
68                       /raw/var                      _index H5I_DATASET   STRING           18085
69                       /raw/var               feature_types   H5I_GROUP                         
70         /raw/var/feature_types                  categories H5I_DATASET   STRING               1
71         /raw/var/feature_types                       codes H5I_DATASET  INTEGER           18085
72                       /raw/var                    gene_ids H5I_DATASET   STRING           18085
73                       /raw/var                      genome   H5I_GROUP                         
74                /raw/var/genome                  categories H5I_DATASET   STRING               1
75                /raw/var/genome                       codes H5I_DATASET  INTEGER           18085
76                       /raw/var           log1p_mean_counts H5I_DATASET    FLOAT           18085
77                       /raw/var          log1p_total_counts H5I_DATASET    FLOAT           18085
78                       /raw/var                 mean_counts H5I_DATASET    FLOAT           18085
79                       /raw/var                          mt H5I_DATASET     ENUM           18085
80                       /raw/var           n_cells_by_counts H5I_DATASET  INTEGER           18085
81                       /raw/var       pct_dropout_by_counts H5I_DATASET    FLOAT           18085
82                       /raw/var                total_counts H5I_DATASET    FLOAT           18085
83                           /raw                        varm   H5I_GROUP                         
84                              /                         uns   H5I_GROUP                         
85                           /uns                         hvg   H5I_GROUP                         
86                       /uns/hvg                      flavor H5I_DATASET   STRING           ( 0 )
87                           /uns                  leiden 0.1   H5I_GROUP                         
88                /uns/leiden 0.1                      params   H5I_GROUP                         
89         /uns/leiden 0.1/params                n_iterations H5I_DATASET  INTEGER           ( 0 )
90         /uns/leiden 0.1/params                random_state H5I_DATASET  INTEGER           ( 0 )
91         /uns/leiden 0.1/params                  resolution H5I_DATASET    FLOAT           ( 0 )
92                           /uns           leiden 0.1_colors H5I_DATASET   STRING               2
93                           /uns                  leiden 0.2   H5I_GROUP                         
94                /uns/leiden 0.2                      params   H5I_GROUP                         
95         /uns/leiden 0.2/params                n_iterations H5I_DATASET  INTEGER           ( 0 )
96         /uns/leiden 0.2/params                random_state H5I_DATASET  INTEGER           ( 0 )
97         /uns/leiden 0.2/params                  resolution H5I_DATASET    FLOAT           ( 0 )
98                           /uns           leiden 0.2_colors H5I_DATASET   STRING               5
99                           /uns                  leiden 0.3   H5I_GROUP                         
100               /uns/leiden 0.3                      params   H5I_GROUP                         
101        /uns/leiden 0.3/params                n_iterations H5I_DATASET  INTEGER           ( 0 )
102        /uns/leiden 0.3/params                random_state H5I_DATASET  INTEGER           ( 0 )
103        /uns/leiden 0.3/params                  resolution H5I_DATASET    FLOAT           ( 0 )
104                          /uns           leiden 0.3_colors H5I_DATASET   STRING               7
105                          /uns                  leiden 0.5   H5I_GROUP                         
106               /uns/leiden 0.5                      params   H5I_GROUP                         
107        /uns/leiden 0.5/params                n_iterations H5I_DATASET  INTEGER           ( 0 )
108        /uns/leiden 0.5/params                random_state H5I_DATASET  INTEGER           ( 0 )
109        /uns/leiden 0.5/params                  resolution H5I_DATASET    FLOAT           ( 0 )
110                          /uns           leiden 0.5_colors H5I_DATASET   STRING               8
111                          /uns                  leiden 0.8   H5I_GROUP                         
112               /uns/leiden 0.8                      params   H5I_GROUP                         
113        /uns/leiden 0.8/params                n_iterations H5I_DATASET  INTEGER           ( 0 )
114        /uns/leiden 0.8/params                random_state H5I_DATASET  INTEGER           ( 0 )
115        /uns/leiden 0.8/params                  resolution H5I_DATASET    FLOAT           ( 0 )
116                          /uns           leiden 0.8_colors H5I_DATASET   STRING              11
117                          /uns                    leiden 1   H5I_GROUP                         
118                 /uns/leiden 1                      params   H5I_GROUP                         
119          /uns/leiden 1/params                n_iterations H5I_DATASET  INTEGER           ( 0 )
120          /uns/leiden 1/params                random_state H5I_DATASET  INTEGER           ( 0 )
121          /uns/leiden 1/params                  resolution H5I_DATASET  INTEGER           ( 0 )
122                          /uns             leiden 1_colors H5I_DATASET   STRING              17
123                          /uns                       log1p   H5I_GROUP                         
124                          /uns                   neighbors   H5I_GROUP                         
125                /uns/neighbors          connectivities_key H5I_DATASET   STRING           ( 0 )
126                /uns/neighbors               distances_key H5I_DATASET   STRING           ( 0 )
127                /uns/neighbors                      params   H5I_GROUP                         
128         /uns/neighbors/params                      method H5I_DATASET   STRING           ( 0 )
129         /uns/neighbors/params                      metric H5I_DATASET   STRING           ( 0 )
130         /uns/neighbors/params                 n_neighbors H5I_DATASET  INTEGER           ( 0 )
131         /uns/neighbors/params                random_state H5I_DATASET  INTEGER           ( 0 )
132                          /uns                         pca   H5I_GROUP                         
133                      /uns/pca                      params   H5I_GROUP                         
134               /uns/pca/params                    mask_var H5I_DATASET   STRING           ( 0 )
135               /uns/pca/params         use_highly_variable H5I_DATASET     ENUM           ( 0 )
136               /uns/pca/params                 zero_center H5I_DATASET     ENUM           ( 0 )
137                      /uns/pca                    variance H5I_DATASET    FLOAT              50
138                      /uns/pca              variance_ratio H5I_DATASET    FLOAT              50
139                          /uns           rank_genes_groups   H5I_GROUP                         
140        /uns/rank_genes_groups              logfoldchanges H5I_DATASET COMPOUND           18085
141        /uns/rank_genes_groups                       names H5I_DATASET COMPOUND           18085
142        /uns/rank_genes_groups                      params   H5I_GROUP                         
143 /uns/rank_genes_groups/params                 corr_method H5I_DATASET   STRING           ( 0 )
144 /uns/rank_genes_groups/params                     groupby H5I_DATASET   STRING           ( 0 )
145 /uns/rank_genes_groups/params                      method H5I_DATASET   STRING           ( 0 )
146 /uns/rank_genes_groups/params                   reference H5I_DATASET   STRING           ( 0 )
147 /uns/rank_genes_groups/params                     use_raw H5I_DATASET     ENUM           ( 0 )
148        /uns/rank_genes_groups                       pvals H5I_DATASET COMPOUND           18085
149        /uns/rank_genes_groups                   pvals_adj H5I_DATASET COMPOUND           18085
150        /uns/rank_genes_groups                      scores H5I_DATASET COMPOUND           18085
151                          /uns                     spatial   H5I_GROUP                         
152                  /uns/spatial                          D1   H5I_GROUP                         
153               /uns/spatial/D1                      images   H5I_GROUP                         
154        /uns/spatial/D1/images                       hires H5I_DATASET    FLOAT 3 x 2000 x 1586
155        /uns/spatial/D1/images                      lowres H5I_DATASET    FLOAT   3 x 600 x 476
156               /uns/spatial/D1                    metadata   H5I_GROUP                         
157      /uns/spatial/D1/metadata       chemistry_description H5I_DATASET   STRING           ( 0 )
158      /uns/spatial/D1/metadata            software_version H5I_DATASET   STRING           ( 0 )
159      /uns/spatial/D1/metadata           source_image_path H5I_DATASET   STRING           ( 0 )
160               /uns/spatial/D1                scalefactors   H5I_GROUP                         
161  /uns/spatial/D1/scalefactors   fiducial_diameter_fullres H5I_DATASET    FLOAT           ( 0 )
162  /uns/spatial/D1/scalefactors    regist_target_img_scalef H5I_DATASET    FLOAT           ( 0 )
163  /uns/spatial/D1/scalefactors       spot_diameter_fullres H5I_DATASET    FLOAT           ( 0 )
164  /uns/spatial/D1/scalefactors         tissue_hires_scalef H5I_DATASET    FLOAT           ( 0 )
165  /uns/spatial/D1/scalefactors        tissue_lowres_scalef H5I_DATASET    FLOAT           ( 0 )
166                          /uns                        umap   H5I_GROUP                         
167                     /uns/umap                      params   H5I_GROUP                         
168              /uns/umap/params                           a H5I_DATASET    FLOAT           ( 0 )
169              /uns/umap/params                           b H5I_DATASET    FLOAT           ( 0 )
170                             /                         var   H5I_GROUP                         
171                          /var                      _index H5I_DATASET   STRING           18085
172                          /var                 dispersions H5I_DATASET    FLOAT           18085
173                          /var            dispersions_norm H5I_DATASET    FLOAT           18085
174                          /var               feature_types   H5I_GROUP                         
175            /var/feature_types                  categories H5I_DATASET   STRING               1
176            /var/feature_types                       codes H5I_DATASET  INTEGER           18085
177                          /var                    gene_ids H5I_DATASET   STRING           18085
178                          /var                      genome   H5I_GROUP                         
179                   /var/genome                  categories H5I_DATASET   STRING               1
180                   /var/genome                       codes H5I_DATASET  INTEGER           18085
181                          /var             highly_variable H5I_DATASET     ENUM           18085
182                          /var           log1p_mean_counts H5I_DATASET    FLOAT           18085
183                          /var          log1p_total_counts H5I_DATASET    FLOAT           18085
184                          /var                        mean H5I_DATASET    FLOAT           18085
185                          /var                 mean_counts H5I_DATASET    FLOAT           18085
186                          /var                       means H5I_DATASET    FLOAT           18085
187                          /var                          mt H5I_DATASET     ENUM           18085
188                          /var           n_cells_by_counts H5I_DATASET  INTEGER           18085
189                          /var       pct_dropout_by_counts H5I_DATASET    FLOAT           18085
190                          /var                         std H5I_DATASET    FLOAT           18085
191                          /var                total_counts H5I_DATASET    FLOAT           18085
192                             /                        varm   H5I_GROUP                         
193                         /varm                         PCs H5I_DATASET    FLOAT      50 x 18085
194                             /                        varp   H5I_GROUP                         
> 

thanks!

kueckelj commented 2 months ago

Thanks for mentioning that. We'll look into that and come back to you.

simonmfr commented 2 months ago

Hi @GUOYF0412, thanks for reporting. This is an error from the anndata package (https://github.com/scverse/anndataR), stating that it isn't compatible with some part of the object. It could have to do with the COMPOUND data in uns, see here, therefore I recommend to delete these from the anndata object in python, then export the new file, and load again in SPATA2. You can do this in python with del adata_sp.uns, or more specifically del adata_sp.uns["rank_genes_groups"].