You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Reference handling with .obsm causing trouble with umap.transform (maybe?) #138
Edit: I've now managed to completely factor AnnData out of this bug. It turns out it's an issue with passing views of recarrays to UMAP. See this #138 (comment) for a minimal example without AnnData.
Alright, this is a bit of a weird one. I'm trying to project simulated doublets into a UMAP of the real data. The initial embedding is being modified when I try to transform the simulated doublets. This only seems to occur if there are the same amount of simulated doublets as initial cells. I spent the last day thinking was a problem with UMAP, until I couldn't replicate without using Scanpy and AnnData, so my current theory is it has to do with getters and setters for .obsm. I could also be doing something dumb and just not seeing it.
I've put everything needed to reproduce in this gist (sorry about the length, I'm having trouble cutting it down). Basically, this code gives weird looking results and throws an error:
Doesn't your last example suggest that the umap instance does some changes to pbmc.obsm["X_pca"] (which gives a view on .obsm by virtue of how numpy structured arrays work) via fit_transform if you can resolve it via .copy()?
After some blood, sweat, and tears I've managed to factor out AnnData entirely:
Using a umap fit on a view of a recarray to transform any other array of the same size will modify the umap object internally. Any time you get some values from .obsm like adata.obsm["X_pca"] it is a view of a recarray, which is not obvious from how it's printed (thanks for pointing that out Alex!). Here's a little example:
Activity
ivirshup commentedon Apr 14, 2019
Managed to cut down the example by a lot:
Looks like it has something to do with the pca update function, if I just pass the copy to
umap.transformthere is no error.Edit: 😕
Edit 2: Closer
If I pass a copy of the original cell loadings to the
fit_transformthere is no error.falexwolf commentedon Apr 15, 2019
Doesn't your last example suggest that the
umapinstance does some changes topbmc.obsm["X_pca"](which gives a view on.obsmby virtue of how numpy structured arrays work) viafit_transformif you can resolve it via.copy()?ivirshup commentedon Apr 15, 2019
It doesn't look like it changes the values:
It definitely could have something to do with being a view though, but I'm not particularly familiar with recarrays
ivirshup commentedon Apr 15, 2019
I can finally get this to (not) work with random data:
Slightly different, less cut down version
Edit: Cut down slightly more:
ivirshup commentedon Apr 15, 2019
After some blood, sweat, and tears I've managed to factor out AnnData entirely:
Using a umap fit on a view of a recarray to transform any other array of the same size will modify the umap object internally. Any time you get some values from
.obsmlikeadata.obsm["X_pca"]it is a view of a recarray, which is not obvious from how it's printed (thanks for pointing that out Alex!). Here's a little example:I'll go open an issue for UMAP now.
falexwolf commentedon Apr 16, 2019
I can imagine that this was a lot of blood, sweat, and tears...