aertslab / SCopeLoomR

R package (compatible with SCope) to create generic .loom files and extend them with other data e.g.: SCENIC regulons, Seurat clusters and markers, ...
MIT License
38 stars 15 forks source link

How to get metadata? #8

Closed Sophia409 closed 5 years ago

Sophia409 commented 5 years ago

I want to get metadata from a loom file,but I'm getting an error with the function: get.attribute.df.Can anyone help me?

> lfile
Class: loom
Filename: /home/yuhong/snap/firefox/common/Downloads/l1_thalamus.loom
Access type: H5F_ACC_RDWR
Attributes: CreationDate, version
Listing:
       name    obj_type  dataset.dims dataset.type_class
  col_attrs   H5I_GROUP          <NA>               <NA>
 col_graphs   H5I_GROUP          <NA>               <NA>
     layers   H5I_GROUP          <NA>               <NA>
     matrix H5I_DATASET 36681 x 27998          H5T_FLOAT
  row_attrs   H5I_GROUP          <NA>               <NA>
 row_graphs   H5I_GROUP          <NA>               <NA>
> lfile[["col_attrs/"]]
Class: H5Group
Filename: /home/yuhong/snap/firefox/common/Downloads/l1_thalamus.loom
Group: /col_attrs
Listing:
                                name    obj_type dataset.dims dataset.type_class
                                 Age H5I_DATASET        36681         H5T_STRING
                              CellID H5I_DATASET        36681         H5T_STRING
                               Class H5I_DATASET        36681         H5T_STRING
          ClassProbability_Astrocyte H5I_DATASET        36681          H5T_FLOAT
   ClassProbability_Astrocyte,Immune H5I_DATASET        36681          H5T_FLOAT
  ClassProbability_Astrocyte,Neurons H5I_DATASET        36681          H5T_FLOAT
   ClassProbability_Astrocyte,Oligos H5I_DATASET        36681          H5T_FLOAT
 ClassProbability_Astrocyte,Vascular H5I_DATASET        36681          H5T_FLOAT
      ClassProbability_Bergmann-glia H5I_DATASET        36681          H5T_FLOAT
              ClassProbability_Blood H5I_DATASET        36681          H5T_FLOAT
< Printed 10, out of 46>

> attrs <- names(lfile$col.attrs)
> tha.meatdata <- lfile$get.attribute.df(MARGIN = 2, attribute.names = attrs)
Error in `[[.H5File`(self, paste0(attribute.layer, "/", col.names)) : 
  An object with name col_attrs/cell_names does not exist in this group
> df = lfile$get.attribute.df(MARGIN = 2, attribute.names = c("CellID", "Clusters"), col.names = "CellID")
Error in `.rowNamesDF<-`(x, value = value) : 
  duplicate 'row.names' are not allowed
此外: Warning message:
non-unique values when setting 'row.names': ‘10X50_5_AAGTGACCAAGT-’, ‘10X50_5_ACCGGACTCGCT-’, ‘10X50_5_ACCTTGTCTCTA-’, ‘10X50_5_ACGTCTGGCATT-’, ‘10X50_5_ACTCTGTTACCT-’, ‘10X50_5_ACTTCTGCTCCT-’, ‘10X50_5_CAGTTGCCCTTG-’, ‘10X50_5_CGGAACCTGAGT-’, ‘10X50_5_CTCACTGCCATA-’, ‘10X50_5_CTGAGACATGGT-’, ‘10X50_5_GAAACTTAACGC-’, ‘10X50_5_GAAGACACACAC-’, ‘10X50_5_GACCCTTGGGAG-’, ‘10X50_5_GATAGACAACTG-’, ‘10X50_5_GATATGTAGAAG-’, ‘10X50_5_GCACACAGAGAT-’, ‘10X50_5_GCCATGTCCGTC-’, ‘10X50_5_TCGAACTGCTGA-’, ‘10X50_6_AACACTGAGCAG-’, ‘10X50_6_ACGAACGTGTCA-’, ‘10X50_6_ACTTTGGTTTCT-’, ‘10X50_6_AGAACTTAAGCC-’, ‘10X50_6_AGGATGTTCCGC-’, ‘10X50_6_ATACTGAGGTCT-’, ‘10X50_6_CCAGCTTCCGTC-’, ‘10X50_6_TAGAGAATCTCT-’, ‘10X50_6_TCAACTGCCATA-’, ‘10X50_6_TCAGGAGAAGGC-’, ‘10X50_6_TCCAGAGGTACT-’, ‘10X50_6_TCGAACATCACG-’, ‘10X50_6_TGGATGACCTCC-’, ‘10X50_6_TTAAGAGGGACA-’, ‘10X50_7_AACAGATCAAGC-’, [... truncated] 

@tropfenameimer @ghuls @KrisDavie @cflerin @sedjro 
dweemx commented 5 years ago

Hi @Sophia409, If you want to get the meta data from any loom using loomR R package please visit https://github.com/mojaveazure/loomR.

dweemx commented 5 years ago

However, it's possible also to get it using SCopeLoomR by means of the get_col_attr_by_key function. For instance, if you want to get the Clusters from the column attributes of the loom you can run:

library(SCopeLoomR)
loom<-open_loom(file.path="/home/yuhong/snap/firefox/common/Downloads/l1_thalamus.loom")
clusters<-get_col_attr_by_key(loom = loom, key = "Clusters")
dweemx commented 5 years ago

I'm closing this issue since it has been inactive for more than 1 month.