jlmelville / uwot

An R package implementing the UMAP dimensionality reduction method.
https://jlmelville.github.io/uwot/
GNU General Public License v3.0
322 stars 31 forks source link

umap_transform with seurat umap coordinate #113

Closed TuoCai2000 closed 8 months ago

TuoCai2000 commented 1 year ago

Hi! Thank you for developing uwot! I have a reference named"seurat",and it is a large seurat object.

seurat An object of class Seurat 18637 features across 1216 samples within 1 assay Active assay: RNA (18637 features, 2000 variable features) 1 dimensional reduction calculated: umap

And I would like to project my own data on the reference dataset.I have finished the PCA reduction and extracted the first 25 principal components as a matrix.I run the code as follows:

umapManifold=seurat@reductions$umap umapProjection <- uwot::umap_transform(g.pca[,1:25],umapManifold, verbose = TRUE) error: $ operator not defined for this S4 class

Then,I rerun the code with the modification:

umapManifold=list(seurat@reductions$umap) umapProjection <- uwot::umap_transform(g.pca[,1:25],umapManifold, verbose = TRUE) Error in all_nn_indices_are_loaded(model) : Invalid model: has no 'nn_index'

So i wonder if i can directly use the umap coordinate of my reference in the seurat object to run the umap_transform function! Thank you so much ! I am looking forward to your reply!

jlmelville commented 1 year ago

Unfortunately, I don't know anything about seurat, so I don't know what the seurat@reductions$umap object is. Is it the output coordinates of running UMAP on your RNA data (presumably a 2D matrix)? If so, that's not enough information for umap_transform. You need the object returned from running uwot::umap(ret_model = TRUE). But I don't think mixing low-level uwot functions with higher-level seurat data is a good way forward, when clearly neither of us know much about how seurat's internals interact with uwot.

I wish I could be more helpful but I would recommend going to the seurat repo and asking how to transform new data. A similar error message was reported at https://github.com/satijalab/seurat/issues/7378 -- maybe following the responses there can help?

jlmelville commented 8 months ago

Closing as not reproducible. Please reopen if there is more info and this is not an issue better dealt with at the Seurat repo.