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

ProjectUMAP- 3D projection lacks accuracy #9501

Open
andynkili opened this issue Nov 21, 2024 · 0 comments
Open

ProjectUMAP- 3D projection lacks accuracy #9501

andynkili opened this issue Nov 21, 2024 · 0 comments

Comments

@andynkili
Copy link

andynkili commented Nov 21, 2024

Dear developpers,

Thanks for the constant support and developing new tools to make single-cell data analysis easier.

I am trying to project query onto a reference using 3 UMAP components, instead of 2.
To assess the results, the current query is just a subset of the reference.
Essentially, I project query cells to the reference PCA space before projecting to UMAP (based on https://github.com/satijalab/seurat/issues/5199)
Here is the code:

library(plotly)
library(data.table)
options(future.globals.maxSize = 1000 * 1024^3)
set.seed(1234)
ref <- readRDS('SR.rds')
query = subset(ref, cells = sample(Cells(ref), 5000))


ref <- SCTransform(ref, variable.features.n = 3000, verbose = F)
ref <- RunPCA(ref, features=VariableFeatures(ref), npcs = 50, verbose = F)
ref <- FindNeighbors(ref, dims = 1:30, verbose = F)
ref <- RunUMAP(ref, dims = 1:30, n.components = 3,return.model = T)

  
set.seed(1234)
pca.features <- rownames(ref[['pca']]@feature.loadings)
query <- SCTransform(query,   residual.features = pca.features,  verbose = F)
#pca.feature have to match the features in query 'scale.data'
pca.features <- intersect(rownames(ref[['pca']]@feature.loadings),rownames(query@assays$SCT$scale.data))
query.pca.embeddings <- t(query@assays$SCT$scale.data[pca.features,]) %*% ref[['pca']]@feature.loadings[pca.features,]
query[['pca']] <- CreateDimReducObject(embeddings = query.pca.embeddings, key = "PC_", assay = "SCT"  )
query <- ProjectUMAP(query = query, query.reduction = "pca",
                     reference = ref, reference.reduction = "pca",
                     reduction.model = "umap", verbose=T)

Then I use plotly to visualize query and reference cells:
image

The picture is showing only NK.cells (reference is grey and query is dark greeen).
I don't understand the 2 cells in opposite coordinates. I was expecting the reference and query (subset of reference) to be more aligned.
And that effect is happening for every cell types: most of the query cells are grouped with corresponding ref cells in the 3D-UMAP but some query cells are far away from the reference.

Could you point me what am I missing there?

Best,
Andy

@andynkili andynkili changed the title ProjectUMAP results lacks accuracy ProjectUMAP- 3D projection lacks accuracy Nov 25, 2024
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

1 participant