def select_groups(adata, groups='<STR_LIT:all>', key='<STR_LIT>'):
strings_to_categoricals(adata)<EOL>if isinstance(groups, list) and isinstance(groups[<NUM_LIT:0>], int): groups = [str(n) for n in groups]<EOL>categories = adata.obs[key].cat.categories<EOL>groups_masks = np.array([categories[i] == adata.obs[key].values for i, name in enumerate(categories)])<EOL>if groups == '<STR_LIT:all>':<EOL><INDENT>groups = categories.values<EOL><DEDENT>else:<EOL><INDENT>groups_ids = [np.where(categories.values == name)[<NUM_LIT:0>][<NUM_LIT:0>] for name in groups]<EOL>groups_masks = groups_masks[groups_ids]<EOL>groups = categories[groups_ids].values<EOL><DEDENT>return groups, groups_masks<EOL>
Get subset of groups in adata.obs[key].