STOmics / Stereopy

A toolkit of spatial transcriptomic analysis.
MIT License
184 stars 64 forks source link

Adding one column metadata into the Stereoseq Object #189

Closed GokceOGUZ closed 9 months ago

GokceOGUZ commented 11 months ago

I have an excel file with 118,443 rows & 2 columns. 1st column is the BinID, 2nd column is the cell type annotation. Here is an example: image

I would like to add this metadata to my Stereopy object which has 118,443 bins & 37 clusters.

StereoExpData object with n_cells X n_genes = 118443 X 23162 bin_type: bins bin_size: 20 offset_x = None offset_y = None cells: ['cell_name', 'total_counts', 'pct_counts_mt', 'n_genes_by_counts', 'louvain'] genes: ['gene_name', 'n_cells', 'n_counts'] cells_matrix = ['pca', 'umap'] cells_pairwise = ['neighbors'] key_record: {'hvg': ['highly_variable_genes'], 'pca': ['pca'], 'neighbors': ['neighbors'], 'umap': ['umap'], 'cluster': ['louvain'], 'gene_exp_cluster': ['gene_exp_louvain']}

I would be really glad if you could suggest me a solution.

tanliwei-coder commented 10 months ago

Hi, you can do this like below:

anno = reading from the excel you mentioned as a dataframe anno.rename({'ID': 'bins', 'CellType': 'group'}, inplace=True) data.tl.result['anno'] = anno data.tl.reset_key_record('cluster', 'anno')