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

Ability to index by label along one axis into obsp, varp arrays #358

Open
wrosko opened this issue Apr 28, 2020 · 2 comments
Open

Ability to index by label along one axis into obsp, varp arrays #358

wrosko opened this issue Apr 28, 2020 · 2 comments

Comments

@wrosko
Copy link

wrosko commented Apr 28, 2020

So I've run into an issue when slicing my anndata object to get a vector.

My anndata is structured like:

  • X: obs x var
  • obs: iterable of observation names
  • var: iterable of variable names
  • obsp: connectivity matrices defined by my different obsp keys and having a shape of obs x obs
  • varp: connectivity matrices defined by my different varp keys and having a shape of var x var

I initiate the object with (note that all X's are sparse matrices):

adata = anndata.AnnData(adata_X, obs=pd.DataFrame(index=obs_keys))

adata.obsp['obsp_1'] = obsp_1_X
adata.obsp['obsp_2'] = obsp_2_X

adata.varp['varp_1'] = varp_1_X
adata.varp['varp_2'] = varp_2_X

I would like to slice with: adata[key].obsp[obsp_1_X] but this returns a 1x1 matrix whereas I would like a 1 x n_obs

To get around this I am having to do: adata.obsp['obsp_1_X'][adata.obs.index.get_loc('key')]

I assume similar behavior with .varm and .obsm

@falexwolf
Copy link
Member

Maybe empower obs_vector to allow accessing obsp? That could be easy, @ivirshup?

Or adding a .loc accessor to the obsp attribute.

@ivirshup ivirshup changed the title Inability to slice to get a row vector from .varp,.obsp Ability to index by label along one axis into obsp, varp arrays Apr 29, 2020
@ivirshup
Copy link
Member

Maybe empower obs_vector to allow accessing obsp?

That's the plan! One of the last remaining things to do in #342 (@flying-sheep). IIRC we were going to leave the ability to select which axis of the pairwise array is being subset and default to rows for now.

Right now I do what @wrosko is doing:

adata.obsp['obsp_1_X'][adata.obs.index.get_loc('key')]

I do think it would be nice to make adata.obs.index.get_loc('key') more concise.

Or adding a .loc accessor to the obsp attribute.

This could be interesting. Right now the idea of a subset of one of the aligned mappings is pretty tightly coupled to a view of an AnnData object, so this could take some doing.

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

No branches or pull requests

3 participants