Convert Seurat object to anndata
0
1
Entering edit mode
13 months ago
nadammagdy ▴ 10

Hi all,

I am trying to save my Seurat object to h5ad to use it as Anndata, I did it before using MuDataSeurat, with Seurat_4.3.0.1.

`seurat_object = CreateSeuratObject(counts = out, project = 'sample_name')

str(seurat_object)

1st str:

Formal class 'Seurat' [package "SeuratObject"] with 13 slots
  ..@ assays      :List of 1
  .. ..$ RNA:Formal class 'Assay' [package "SeuratObject"] with 8 slots
  .. .. .. ..@ counts       :Formal class 'dgCMatrix' [package "Matrix"] with 6 slots
  .. .. .. .. .. ..@ i       : int [1:5253276] 14 29 38 91 115 124 137 156 197 226 ...
  .. .. .. .. .. ..@ p       : int [1:4587] 0 1412 2343 3385 4580 5000 5850 7137 8320 9391 ...
  .. .. .. .. .. ..@ Dim     : int [1:2] 20420 4586
  .. .. .. .. .. ..@ Dimnames:List of 2
  .. .. .. .. .. .. ..$ : chr [1:20420] "AL627309.1" "AL669831.5" "LINC00115" "FAM41C" ...
  .. .. .. .. .. .. ..$ : chr [1:4586] "AAACAGCCACTTAGGC-1" "AAACATGCAACCCTAA-1" "AAACATGCAAGACTCC-1" "AAACATGCACTAAATC-1" ...
  .. .. .. .. .. ..@ x       : num [1:5253276] 0.934 0.818 0.881 0.798 0.802 ...
  .. .. .. .. .. ..@ factors : list()
  .. .. .. ..@ data         :Formal class 'dgCMatrix' [package "Matrix"] with 6 slots
  .. .. .. .. .. ..@ i       : int [1:5253276] 14 29 38 91 115 124 137 156 197 226 ...
  .. .. .. .. .. ..@ p       : int [1:4587] 0 1412 2343 3385 4580 5000 5850 7137 8320 9391 ...
  .. .. .. .. .. ..@ Dim     : int [1:2] 20420 4586
  .. .. .. .. .. ..@ Dimnames:List of 2
  .. .. .. .. .. .. ..$ : chr [1:20420] "AL627309.1" "AL669831.5" "LINC00115" "FAM41C" ...
  .. .. .. .. .. .. ..$ : chr [1:4586] "AAACAGCCACTTAGGC-1" "AAACATGCAACCCTAA-1" "AAACATGCAAGACTCC-1" "AAACATGCACTAAATC-1" ...
  .. .. .. .. .. ..@ x       : num [1:5253276] 0.934 0.818 0.881 0.798 0.802 ...
  .. .. .. .. .. ..@ factors : list()
  .. .. .. ..@ scale.data   : num[0 , 0 ] 
  .. .. .. ..@ key          : chr "rna_"
  .. .. .. ..@ assay.orig   : NULL
  .. .. .. ..@ var.features : logi(0) 
  .. .. .. ..@ meta.features:'data.frame':  20420 obs. of  0 variables
  .. .. .. ..@ misc         : list()
  ..@ meta.data   :'data.frame':    4586 obs. of  3 variables:
  .. ..$ orig.ident  : Factor w/ 1 level "CS23_F": 1 1 1 1 1 1 1 1 1 1 ...
  .. ..$ nCount_RNA  : num [1:4586] 2192 1357 1536 1792 751 ...
  .. ..$ nFeature_RNA: int [1:4586] 1412 930 1040 1193 420 847 1287 1178 1066 651 ...
  ..@ active.assay: chr "RNA"
  ..@ active.ident: Factor w/ 1 level "CS23_F": 1 1 1 1 1 1 1 1 1 1 ...
  .. ..- attr(*, "names")= chr [1:4586] "AAACAGCCACTTAGGC-1" "AAACATGCAACCCTAA-1" "AAACATGCAAGACTCC-1" "AAACATGCACTAAATC-1" ...
  ..@ graphs      : list()
  ..@ neighbors   : list()
  ..@ reductions  : list()
  ..@ images      : list()
  ..@ project.name: chr "CS23_F"
  ..@ misc        : list()
  ..@ version     :Classes 'package_version', 'numeric_version'  hidden list of 1
  .. ..$ : int [1:3] 4 1 3
  ..@ commands    : list()
  ..@ tools       : list()
'Seurat' 

Then with MuDataSeurat::WriteH5AD(seurat_object, "path/seuratobject.h5ad")` I never had problem.

Now when I am using Seurat V5 I get this error with MuDataSeurat.

Error in (function (cl, name, valueClass)  : 
  ‘meta.features’ is not a slot in class “Seurat”

I checked the Seurat str and slots are different in the updated version, there is no meta.feature.

2nd str:

Formal class 'Seurat' [package "SeuratObject"] with 13 slots
  ..@ assays      :List of 1
  .. ..$ RNA:Formal class 'Assay5' [package "SeuratObject"] with 8 slots
  .. .. .. ..@ layers    :List of 1
  .. .. .. .. ..$ counts:Formal class 'dgCMatrix' [package "Matrix"] with 6 slots
  .. .. .. .. .. .. ..@ i       : int [1:14994601] 154 240 493 541 546 567 624 675 684 693 ...
  .. .. .. .. .. .. ..@ p       : int [1:6975] 0 425 1244 1680 5294 7829 10590 13797 15113 15752 ...
  .. .. .. .. .. .. ..@ Dim     : int [1:2] 33538 6974
  .. .. .. .. .. .. ..@ Dimnames:List of 2
  .. .. .. .. .. .. .. ..$ : NULL
  .. .. .. .. .. .. .. ..$ : NULL
  .. .. .. .. .. .. ..@ x       : num [1:14994601] 0.936 0.985 1.899 0.979 0.973 ...
  .. .. .. .. .. .. ..@ factors : list()
  .. .. .. ..@ cells     :Formal class 'LogMap' [package "SeuratObject"] with 1 slot
  .. .. .. .. .. ..@ .Data: logi [1:6974, 1] TRUE TRUE TRUE TRUE TRUE TRUE ...
  .. .. .. .. .. .. ..- attr(*, "dimnames")=List of 2
  .. .. .. .. .. .. .. ..$ : chr [1:6974] "AAACAGCCAACTGGGA-1" "AAACAGCCAAGGTGGC-1" "AAACAGCCACAATGTT-1" "AAACAGCCACTTAGGC-1" ...
  .. .. .. .. .. .. .. ..$ : chr "counts"
  .. .. .. .. .. ..$ dim     : int [1:2] 6974 1
  .. .. .. .. .. ..$ dimnames:List of 2
  .. .. .. .. .. .. ..$ : chr [1:6974] "AAACAGCCAACTGGGA-1" "AAACAGCCAAGGTGGC-1" "AAACAGCCACAATGTT-1" "AAACAGCCACTTAGGC-1" ...
  .. .. .. .. .. .. ..$ : chr "counts"
  .. .. .. ..@ features  :Formal class 'LogMap' [package "SeuratObject"] with 1 slot
  .. .. .. .. .. ..@ .Data: logi [1:33538, 1] TRUE TRUE TRUE TRUE TRUE TRUE ...
  .. .. .. .. .. .. ..- attr(*, "dimnames")=List of 2
  .. .. .. .. .. .. .. ..$ : chr [1:33538] "MIR1302-2HG" "FAM138A" "OR4F5" "AL627309.1" ...
  .. .. .. .. .. .. .. ..$ : chr "counts"
  .. .. .. .. .. ..$ dim     : int [1:2] 33538 1
  .. .. .. .. .. ..$ dimnames:List of 2
  .. .. .. .. .. .. ..$ : chr [1:33538] "MIR1302-2HG" "FAM138A" "OR4F5" "AL627309.1" ...
  .. .. .. .. .. .. ..$ : chr "counts"
  .. .. .. ..@ default   : int 1
  .. .. .. ..@ assay.orig: chr(0) 
  .. .. .. ..@ meta.data :'data.frame':   33538 obs. of  0 variables
  .. .. .. ..@ misc      :List of 1
  .. .. .. .. ..$ calcN: logi TRUE
  .. .. .. ..@ key       : chr "rna_"
  ..@ meta.data   :'data.frame':  6974 obs. of  3 variables:
  .. ..$ orig.ident  : Factor w/ 1 level "CS23LV": 1 1 1 1 1 1 1 1 1 1 ...
  .. ..$ nCount_RNA  : num [1:6974] 746 1539 535 8631 5633 ...
  .. ..$ nFeature_RNA: int [1:6974] 425 818 435 3612 2532 2752 3179 1316 639 2267 ...
  ..@ active.assay: chr "RNA"
  ..@ active.ident: Factor w/ 1 level "CS23LV": 1 1 1 1 1 1 1 1 1 1 ...
  .. ..- attr(*, "names")= chr [1:6974] "AAACAGCCAACTGGGA-1" "AAACAGCCAAGGTGGC-1" "AAACAGCCACAATGTT-1" "AAACAGCCACTTAGGC-1" ...
  ..@ graphs      : list()
  ..@ neighbors   : list()
  ..@ reductions  : list()
  ..@ images      : list()
  ..@ project.name: chr "CS23LV"
  ..@ misc        : list()
  ..@ version     :Classes 'package_version', 'numeric_version'  hidden list of 1
  .. ..$ : int [1:3] 5 0 0
  ..@ commands    : list()
  ..@ tools       : list()

I tried to get the older version again, but I also get the second str of Seurat object each time.

Does anyone know how can I get the first str of Seurat object back or know another way to save it to h5ad?

Thanks

anndata h5ad Seurat • 1.6k views
ADD COMMENT

Login before adding your answer.

Traffic: 1739 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6