Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ditannan opened this issue Nov 12, 2021 · 5 comments

Comments

@ditannan
Copy link

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.

@ditannan
Copy link
Author

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

@joshua-gould
Copy link
Contributor

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

@ditannan
Copy link
Author

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.

@joshua-gould
Copy link
Contributor

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')

@ditannan
Copy link
Author

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants