lilab-bcb/cirrocumulus

support change the selected ids to new category and add a new cluster to anndata.obs

ditannan opened this issue · 5 comments

when I selected ids, I can Download Selected IDs, would it possiable I can change the category name of selected ids and update the clusters to a new cluster name. The anndata should be updated and can be downloaded.

kind of:

def change_cluster(adata, old_cluster, new_category_ids, new_category_name=None, new_cluster_name=None):
    adata.obs[new_cluster_name] = adata.obs[old_cluster]
    adata.obs[new_cluster_name] = adata.obs[new_cluster_name].cat.add_categories(new_category_name)
    adata.obs.loc[new_category_ids, new_cluster_name] = new_category_name
    return adata

Please see the attached gif for annotating clusters. When using cirro launch, the renamed clusters are available in a JSON file stored next to the input h5ad. Does this work?

annotate

Please see the attached gif for annotating clusters. When using cirro launch, the renamed clusters are available in a JSON file stored next to the input h5ad. Does this work?

annotate

Thank you for your quick reply. Annotating the cluster seems to change the category name for a whole cluster, what I want is changing some samples (selected ids) of one category or two categories to another new category.

You can download the selected ids for each group and then add a new field in anndata.obs. Does this work?

import pandas as pd
ids1 = pd.read_csv('selection.txt', header=None, index_col=0).index
ids2 = pd.read_csv('selection (1).txt', header=None, index_col=0).index
obs_field = 'my_group'
adata.obs.loc[ids1, obs_field] = 'A'
adata.obs.loc[ids2, obs_field] = 'B'
adata.obs[obs_field] = adata.obs[obs_field].astype('category')

You can download the selected ids for each group and then add a new field in anndata.obs. Does this work?

import pandas as pd
ids1 = pd.read_csv('selection.txt', header=None, index_col=0).index
ids2 = pd.read_csv('selection (1).txt', header=None, index_col=0).index
obs_field = 'my_group'
adata.obs.loc[ids1, obs_field] = 'A'
adata.obs.loc[ids2, obs_field] = 'B'
adata.obs[obs_field] = adata.obs[obs_field].astype('category')

Thank you, it works. If this feature can be added to the cirrocumulus?