STOmics / Stereopy

A toolkit of spatial transcriptomic analysis.
MIT License
197 stars 65 forks source link

How to add metadata to stereopy object #142

Closed GokceOGUZ closed 1 year ago

GokceOGUZ commented 1 year ago

I have few questions related to cluster annotation

  1. I performed basic processing in stereopy and clustered the data. We want to annotate the clusters and in the process merge any clusters that are similar. However, I am getting the error message "Categorical categories must be unique" (see screenshot and brief code below):
annotation_dict = {
    '1':'a',
    '2':'b',
    '3':'c',
    '4':'c',
    '5':'c',
    }

data.tl.annotation(
        annotation_information=annotation_dict, 
        cluster_res_key='louvain', 
        res_key='anno_louvain'
  )

image

  1. I exported the data to R and performed subclustering there. I created a mapping file that contains the bin id and my desired grouping. How can I read and add this to the metadata of the stereopy object?

  2. I want to annotate some bins as a cell type manually if their expression levels for a gene is high. i.e. not using/overriding the cluster information.

Any advice is much appreciated.

tanliwei-coder commented 1 year ago

Hi!

  1. data.tl.annotation only can support one to one.
  2. you can save the data as an anndata format file(h5ad) and save the groups into obs, then read it by data = st.io.read_h5ad('xxx.h5ad'), after reading, you can get the groups from data.cells[obs_key], the obs_key is the key of groups stored in anndata.obs.
  3. about annotation, you can refer to here.