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

Removing metadata columns #31

Open
dennishamrick opened this issue Oct 8, 2024 · 2 comments
Open

Removing metadata columns #31

dennishamrick opened this issue Oct 8, 2024 · 2 comments

Comments

@dennishamrick
Copy link

dennishamrick commented Oct 8, 2024

Hello!

I have a large h5ad file, named asbrain2.h5ad. I downloaded this from the website CellxGene, can be found here:
https://datasets.cellxgene.cziscience.com/427090ae-5e21-421f-b178-e66a930ca63c.h5ad

I load it into R using the anndata package (full list of each metadata column has been truncated by me):
> brain2 AnnData object with n_obs × n_vars = 1915592 × 1122 obs: 'organism_ontology_term_id', 'donor_id', 'development_stage_ontology_term_id', 'sex_ontology_term_id', 'major_brain_region', 'cell_type'... (29 obs_keys in total) var: 'gene_name', 'feature_is_filtered', 'feature_name'... (6 var_keys in total) uns: 'citation', 'schema_reference'... (4 uns_keys in total) obsm: 'X_CCF', 'X_spatial_coords', 'X_umap'

Now, my question is: Is there a method in R using the anndata package to delete the metadata columns I don't need en masse or at once?
brain2$obs$organism_ontology_term_id <- NULL will delete that column or whichever I specify. I could probably figure out something with a for loop, but I feel like there must be a way for me to just specify the column names I want to keep and save those while preserving the cell counts. Several methods I have tried have resulted in python errors.

This may be due to me missing something w/r/t syntax for subsetting in R, of course.

Thanks for any assistance.

@rcannood
Copy link
Member

Hi @dennishamrick !

You could use:

ad$obs <- ad$obs[,c("columns", "you", "want", "to", "keep")]

Does that work for you?

@dennishamrick
Copy link
Author

Hi @dennishamrick !

You could use:

ad$obs <- ad$obs[,c("columns", "you", "want", "to", "keep")]

Does that work for you?

Hi!

This works swimmingly. Thank you so much.

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