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

seuratUMAP fails, can't find reductions #774

Open
mcsimenc opened this issue Nov 4, 2024 · 1 comment
Open

seuratUMAP fails, can't find reductions #774

mcsimenc opened this issue Nov 4, 2024 · 1 comment

Comments

@mcsimenc
Copy link

mcsimenc commented Nov 4, 2024

Hi, I am getting this result. Setting method to "scaterUMAP" works.

sceObj = runNormalization(
  inSCE = sceObj,
  useAssay = "counts",
  outAssayName = "logcounts",
  normalizationMethod = "LogNormalize",
  scale = F,
  verbose = T
)

sceObj = runSeuratFindHVG(
  inSCE = sceObj,
  useAssay = "logcounts", 
  method = "vst",
  hvgNumber = 2000, 
  createFeatureSubset = "hvf"
)
s
sceObj = runDimReduce(
  inSCE = sceObj,
  method = "seuratPCA",
  reducedDimName = "PCA",
  useAssay = "logcounts",
  scale = T,
  seed = 789,
  nComponents = 30
)

# runSeuratFindClusters
sceObj = runScranSNN(
  inSCE = sceObj,
  useReducedDim = "PCA",
  clusterName = "cluster",
  k = 14,
  nComp = 30,
  algorithm = "louvain",
  seed = 789
)

sceObj = runDimReduce(
  inSCE = sceObj,
  method = "seuratUMAP",
  useReducedDim = "PCA",
  useFeatureSubset = "hvf",
  reducedDimName = "UMAP",
  scale = F,
  seed = 789,
  nComponents = 2
)

Sun Nov  3 23:41:09 2024 ... Computing Seurat UMAP.
Warning: Layer ‘var.features’ is empty
Error in `x[[i, drop = TRUE]]`:
! ‘reductions’ not found in this Seurat object
 
Backtrace:
 1. singleCellTK::runDimReduce(...)
 2. singleCellTK::runSeuratUMAP(...)
 3. singleCellTK::convertSCEToSeurat(inSCE)
 5. SeuratObject:::`$.Seurat`(inSCE@metadata$seurat$obj, "reductions")
 7. SeuratObject:::`[[.Seurat`(x, i, drop = TRUE)
@mingl1997
Copy link
Collaborator

mingl1997 commented Dec 11, 2024

Hello,

I ran the following code loading in the PBMC3K dataset that I use as testing:

library(singleCellTK)
library(Seurat)
library(TENxPBMCData)

# Load pbmc3k data 
sceObj <- TENxPBMCData(dataset = "pbmc3k")

# Run QC
sceObj <- runCellQC(sceObj)

sceObj = runNormalization(
    inSCE = sceObj,
    useAssay = "counts",
    outAssayName = "logcounts",
    normalizationMethod = "LogNormalize",
    scale = F,
    verbose = T
)

sceObj = runSeuratFindHVG(
    inSCE = sceObj,
    useAssay = "logcounts", 
    method = "vst",
    hvgNumber = 2000, 
    createFeatureSubset = "hvf"
)

sceObj = runDimReduce(
    inSCE = sceObj,
    method = "seuratPCA",
    reducedDimName = "PCA",
    useAssay = "logcounts",
    scale = T,
    seed = 789,
    nComponents = 30
)

# runSeuratFindClusters
sceObj = runScranSNN(
    inSCE = sceObj,
    useReducedDim = "PCA",
    clusterName = "cluster",
    k = 14,
    nComp = 30,
    algorithm = "louvain",
    seed = 789
)

sceObj = runDimReduce(
    inSCE = sceObj,
    method = "seuratUMAP",
    useReducedDim = "PCA",
    useFeatureSubset = "hvf",
    reducedDimName = "UMAP",
    scale = F,
    seed = 789,
    nComponents = 2
)

I receive the following result:

> library(singleCellTK)
> library(Seurat)
> 
> # Load pbmc3k data
> sceObj <- TENxPBMCData(dataset = "pbmc3k")
> 
> # Run QC
> sceObj <- runCellQC(sceObj)
>
> {...}
>
> sceObj = runNormalization(
+     inSCE = sceObj,
+     useAssay = "counts",
+     outAssayName = "logcounts",
+     normalizationMethod = "LogNormalize",
+     scale = F,
+     verbose = T
+ )
Normalizing layer: counts
Performing log-normalization
0%   10   20   30   40   50   60   70   80   90   100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
Normalization performed using LogNormalize method.
> 
> sceObj = runSeuratFindHVG(
+     inSCE = sceObj,
+     useAssay = "logcounts", 
+     method = "vst",
+     hvgNumber = 2000, 
+     createFeatureSubset = "hvf"
+ )
Finding variable features for layer counts
Calculating gene variances
0%   10   20   30   40   50   60   70   80   90   100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
Calculating feature variances of standardized and clipped values
0%   10   20   30   40   50   60   70   80   90   100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
Wed Dec 11 12:04:14 2024 ... Feature subset variable 'hvf' created.
> 
> sceObj = runDimReduce(
+     inSCE = sceObj,
+     method = "seuratPCA",
+     reducedDimName = "PCA",
+     useAssay = "logcounts",
+     scale = T,
+     seed = 789,
+     nComponents = 30
+ )
Wed Dec 11 12:04:14 2024 ... Computing Seurat PCA.
Centering and scaling data matrix
  |================================================================================| 100%
PC_ 1 
Positive:  ENSG00000143947, ENSG00000213402, ENSG00000145425, ENSG00000227507, ENSG00000168028, ENSG00000167286, ENSG00000008517, ENSG00000198851, ENSG00000213741, ENSG00000111716 
	   ENSG00000121966, ENSG00000205246, ENSG00000168685, ENSG00000173762, ENSG00000182866, ENSG00000104964, ENSG00000133639, ENSG00000089157, ENSG00000181163, ENSG00000116824 
	   ENSG00000108654, ENSG00000156976, ENSG00000105373, ENSG00000110848, ENSG00000172183, ENSG00000147168, ENSG00000114942, ENSG00000196405, ENSG00000101608, ENSG00000147604 
Negative:  ENSG00000101439, ENSG00000011600, ENSG00000163220, ENSG00000204482, ENSG00000087086, ENSG00000090382, ENSG00000204472, ENSG00000085265, ENSG00000167996, ENSG00000158869 
	   ENSG00000025708, ENSG00000100097, ENSG00000197766, ENSG00000143546, ENSG00000100079, ENSG00000129226, ENSG00000163131, ENSG00000197249, ENSG00000130066, ENSG00000066336 
	   ENSG00000197746, ENSG00000126759, ENSG00000142089, ENSG00000163191, ENSG00000216490, ENSG00000119655, ENSG00000103187, ENSG00000030582, ENSG00000131981, ENSG00000182287 
PC_ 2 
Positive:  ENSG00000105374, ENSG00000145649, ENSG00000077984, ENSG00000180644, ENSG00000100453, ENSG00000172543, ENSG00000137441, ENSG00000115523, ENSG00000161570, ENSG00000197540 
	   ENSG00000159674, ENSG00000100450, ENSG00000126264, ENSG00000129277, ENSG00000198821, ENSG00000196154, ENSG00000008517, ENSG00000134539, ENSG00000122862, ENSG00000143185 
	   ENSG00000135046, ENSG00000169583, ENSG00000133321, ENSG00000203747, ENSG00000108518, ENSG00000173762, ENSG00000196139, ENSG00000160255, ENSG00000171476, ENSG00000180739 
Negative:  ENSG00000105369, ENSG00000156738, ENSG00000196735, ENSG00000179344, ENSG00000100721, ENSG00000007312, ENSG00000204287, ENSG00000247982, ENSG00000128218, ENSG00000019582 
	   ENSG00000196126, ENSG00000223865, ENSG00000237541, ENSG00000231389, ENSG00000198502, ENSG00000104921, ENSG00000204257, ENSG00000153064, ENSG00000104894, ENSG00000242574 
	   ENSG00000106537, ENSG00000132185, ENSG00000122986, ENSG00000241106, ENSG00000168734, ENSG00000176533, ENSG00000145088, ENSG00000137101, ENSG00000269404, ENSG00000112799 
PC_ 3 
Positive:  ENSG00000100453, ENSG00000137441, ENSG00000180644, ENSG00000105374, ENSG00000115523, ENSG00000077984, ENSG00000159674, ENSG00000145649, ENSG00000007312, ENSG00000105369 
	   ENSG00000129277, ENSG00000196735, ENSG00000156738, ENSG00000100450, ENSG00000019582, ENSG00000169583, ENSG00000223865, ENSG00000134539, ENSG00000100721, ENSG00000179344 
	   ENSG00000143185, ENSG00000196139, ENSG00000231389, ENSG00000075234, ENSG00000203747, ENSG00000150687, ENSG00000196126, ENSG00000247982, ENSG00000172543, ENSG00000180739 
Negative:  ENSG00000111716, ENSG00000167286, ENSG00000026025, ENSG00000168685, ENSG00000171223, ENSG00000241343, ENSG00000170345, ENSG00000142546, ENSG00000198851, ENSG00000213741 
	   ENSG00000089157, ENSG00000172809, ENSG00000102760, ENSG00000152518, ENSG00000172005, ENSG00000165272, ENSG00000126353, ENSG00000129824, ENSG00000082074, ENSG00000133872 
	   ENSG00000227507, ENSG00000008517, ENSG00000116251, ENSG00000148908, ENSG00000196683, ENSG00000171858, ENSG00000147604, ENSG00000116824, ENSG00000204387, ENSG00000181163 
PC_ 4 
Positive:  ENSG00000163736, ENSG00000163737, ENSG00000168497, ENSG00000127920, ENSG00000113140, ENSG00000154146, ENSG00000180573, ENSG00000169704, ENSG00000150681, ENSG00000101162 
	   ENSG00000120885, ENSG00000236304, ENSG00000010278, ENSG00000005961, ENSG00000171611, ENSG00000104267, ENSG00000088726, ENSG00000111644, ENSG00000108960, ENSG00000161911 
	   ENSG00000124491, ENSG00000184702, ENSG00000101856, ENSG00000176783, ENSG00000101335, ENSG00000145335, ENSG00000095303, ENSG00000102804, ENSG00000166091, ENSG00000204424 
Negative:  ENSG00000168028, ENSG00000051523, ENSG00000147604, ENSG00000231389, ENSG00000143947, ENSG00000223865, ENSG00000089157, ENSG00000143119, ENSG00000198502, ENSG00000196126 
	   ENSG00000145287, ENSG00000019582, ENSG00000104894, ENSG00000145425, ENSG00000128340, ENSG00000137441, ENSG00000106153, ENSG00000196735, ENSG00000105374, ENSG00000115523 
	   ENSG00000169442, ENSG00000179344, ENSG00000169100, ENSG00000180644, ENSG00000185201, ENSG00000135390, ENSG00000114942, ENSG00000007312, ENSG00000102879, ENSG00000077984 
PC_ 5 
Positive:  ENSG00000143546, ENSG00000162444, ENSG00000163221, ENSG00000163220, ENSG00000110203, ENSG00000170458, ENSG00000100079, ENSG00000110077, ENSG00000119535, ENSG00000166523 
	   ENSG00000090382, ENSG00000169429, ENSG00000183019, ENSG00000221869, ENSG00000130522, ENSG00000085265, ENSG00000006075, ENSG00000150337, ENSG00000141505, ENSG00000011600 
	   ENSG00000126883, ENSG00000090013, ENSG00000104918, ENSG00000124731, ENSG00000084207, ENSG00000226091, ENSG00000129277, ENSG00000169413, ENSG00000135929, ENSG00000213903 
Negative:  ENSG00000185201, ENSG00000026297, ENSG00000143933, ENSG00000184009, ENSG00000150991, ENSG00000070756, ENSG00000133872, ENSG00000143119, ENSG00000109971, ENSG00000169442 
	   ENSG00000155366, ENSG00000101608, ENSG00000123416, ENSG00000134333, ENSG00000171223, ENSG00000065978, ENSG00000102879, ENSG00000181163, ENSG00000168028, ENSG00000136156 
	   ENSG00000118680, ENSG00000187109, ENSG00000172757, ENSG00000203747, ENSG00000143549, ENSG00000122566, ENSG00000089327, ENSG00000142168, ENSG00000189043, ENSG00000125534
> 
> # runSeuratFindClusters
> sceObj = runScranSNN(
+     inSCE = sceObj,
+     useReducedDim = "PCA",
+     clusterName = "cluster",
+     k = 14,
+     nComp = 30,
+     algorithm = "louvain",
+     seed = 789
+ )
Wed Dec 11 12:04:17 2024 ... Running 'scran SNN clustering' with 'louvain' algorithm
Wed Dec 11 12:04:18 2024 ...   Identified 9 clusters
> 
> sceObj = runDimReduce(
+     inSCE = sceObj,
+     method = "seuratUMAP",
+     useReducedDim = "PCA",
+     useFeatureSubset = "hvf",
+     reducedDimName = "UMAP",
+     scale = F,
+     seed = 789,
+     nComponents = 2
+ )
Wed Dec 11 12:04:19 2024 ... Computing Seurat UMAP.
Warning: The default method for RunUMAP has changed from calling Python UMAP via reticulate to the R-native UWOT using the cosine metric
To use Python UMAP via reticulate, set umap.method to 'umap-learn' and metric to 'correlation'
This message will be shown once per session
12:04:20 UMAP embedding parameters a = 0.9922 b = 1.112
12:04:20 Read 2700 rows and found 10 numeric columns
12:04:20 Using Annoy for neighbor search, n_neighbors = 30
12:04:20 Building Annoy index with metric = cosine, n_trees = 50
0%   10   20   30   40   50   60   70   80   90   100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
12:04:20 Writing NN index file to temp file C:\Users\Cortana\AppData\Local\Temp\Rtmpu4piOF\file1f6c05ad71814
12:04:20 Searching Annoy index using 1 thread, search_k = 3000
12:04:21 Annoy recall = 100%
12:04:21 Commencing smooth kNN distance calibration using 1 thread with target n_neighbors = 30
12:04:23 Initializing from normalized Laplacian + noise (using RSpectra)
12:04:23 Commencing optimization for 500 epochs, with 107660 positive edges
Using method 'umap'
0%   10   20   30   40   50   60   70   80   90   100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
12:04:29 Optimization finished

Could you supply the data that you used and which versions of sctk and Seurat?

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

2 participants