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

Adding modality to MuData.mod #46

Open
racng opened this issue Aug 1, 2023 · 1 comment · May be fixed by #53
Open

Adding modality to MuData.mod #46

racng opened this issue Aug 1, 2023 · 1 comment · May be fixed by #53
Labels
enhancement New feature or request
Milestone

Comments

@racng
Copy link

racng commented Aug 1, 2023

Is your feature request related to a problem? Please describe.
After loading a CITE-seq 10x h5 file with muon and 10x vdj file with scirpy, I tried adding the AIRR modality to the existing mdata by adding it to mdata.mod. It seemed to work, since mdata shows that it has 3 modalities. However, when I tried to write the mdata, I get an error:

SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

However, there is no error if i initialize a new mdata object with all three modalities and save that.

Describe the solution you'd like
Would be nice if we can add a modality with mdata.mod['airr'] = adata.copy() without causing warnings.

Describe alternatives you've considered
We currently need to create a new object whenever we want to add a new modality

new_mdata = mu.MuData({
	'rna': mdata.mod['rna'].copy(),
	'new': adata.copy(),
	'prot': mdata.mod['prot'].copy()
})

Additional context

mdata = mu.read_10x_h5(gex_path)
adata = ir.io.read_10x_vdj(vdj_path)
mdata.mod['airr'] = adata.copy()
mdata.write('test.h5mu')

Full error message when saving the mdata after adding adata to mdata.mod

/users/rng/mambaforge/envs/compbio/lib/python3.10/site-packages/anndata/_core/anndata.py:1230: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  df[key] = c
/users/rng/mambaforge/envs/compbio/lib/python3.10/site-packages/anndata/_core/anndata.py:1230: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  df[key] = c
/users/rng/mambaforge/envs/compbio/lib/python3.10/site-packages/anndata/_core/anndata.py:1230: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  df[key] = c
@racng racng added the enhancement New feature or request label Aug 1, 2023
@gtca
Copy link
Collaborator

gtca commented Sep 11, 2023

Thank you, @racng!

As this seems to be a warning, it shouldn't generally stand in the way of adding modalities.

So far I see that this warning might be related to a scenario when the feature names are duplicated across modalities. In that case .varmap also looks fragmented (e.g. array([1, 0, 2, 0, 3, 0, ...]) and array([0, 1, 0, 2, 0, 3, ...]) for two modalities with the same var_names). This is not the case when creating a MuData object from modalities with these duplicated feature names straight away.

With no name duplicates, there should be no problem like this and no warning!


Version 0.3 of mudata will come with a fix to this warning — together with improved name duplicates handling so that varmap looks better and the behaviour is more intuitive when adding modalities. 🎉

gtca added a commit that referenced this issue Sep 11, 2023
avoid name (pandas index) sorting
when adding new modalities.

Resolves #46.
@gtca gtca added this to the v0.3.0 milestone Sep 11, 2023
@gtca gtca linked a pull request Sep 11, 2023 that will close this issue
5 tasks
@gtca gtca linked a pull request Sep 11, 2023 that will close this issue
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants