seurat icon indicating copy to clipboard operation
seurat copied to clipboard

Error when converting SCE object to Seurat despite counts and logcounts present in assays

Open sagrikachugh opened this issue 10 months ago • 8 comments

I am using Seurat v5.0.2 , SeuratObject v5.0.1 and SingleCellExperiment v1.22.0 trying to convert a SCE object to Seurat using the following code

so <- as.Seurat(sce, counts = "counts", data = "logcounts")

This results in error:

Error: No data in provided assay - logcounts

Here is how my SCE looks like:

sce
class: SingleCellExperiment 
dim: 28421 111867 
metadata(1): Samples
assays(2): counts logcounts
rownames(28421): Xkr4 Gm1992 ... CAAA01147332.1 AC149090.1
rowData names(4): ID Symbol Type CHR
colnames(111867): 1_AAACCCACAAGTGACG-1 1_AAACCCACACTCACTC-1
  ... 15_TTTGTTGGTTAGTCGT-1 15_TTTGTTGGTTTGGGAG-1
colData names(29): Sample Barcode ... cluster cluster_colours
reducedDimNames(2): PCA UMAP
mainExpName: RNA

sagrikachugh avatar Apr 19 '24 11:04 sagrikachugh

Can you share a small example file where this is occurring?

Gesmira avatar Apr 23 '24 15:04 Gesmira

@Gesmira Thanks for looking into this. Here's a reproducible example using the scater package

Creating a sce object first

test_sce <- scater::mockSCE()
test_sce
class: SingleCellExperiment 
dim: 2000 200 
metadata(0):
assays(1): counts
rownames(2000): Gene_0001 Gene_0002 ... Gene_1999 Gene_2000
rowData names(0):
colnames(200): Cell_001 Cell_002 ... Cell_199 Cell_200
colData names(3): Mutation_Status Cell_Cycle Treatment
reducedDimNames(0):
mainExpName: NULL
altExpNames(1): Spikes

Now, we add logcounts to the test_sce object as as.Seurat function needs both "counts" and "logcounts" in the assay slot

test_sce <- scater::logNormCounts(test_sce)

Now we have "logcounts" in our assays as shown below

test_sce
class: SingleCellExperiment 
dim: 2000 200 
metadata(0):
assays(2): counts logcounts
rownames(2000): Gene_0001 Gene_0002 ... Gene_1999 Gene_2000
rowData names(0):
colnames(200): Cell_001 Cell_002 ... Cell_199 Cell_200
colData names(4): Mutation_Status Cell_Cycle Treatment sizeFactor
reducedDimNames(0):
mainExpName: NULL
altExpNames(1): Spikes

Converting test_sce to seurat object

test_so <- as.Seurat(test_sce, counts = "counts", data = "logcounts")

This results in error -

Warning: Feature names cannot have underscores ('_'), replacing with dashes ('-')
Warning: Feature names cannot have underscores ('_'), replacing with dashes ('-')
Warning: Feature names cannot have underscores ('_'), replacing with dashes ('-')
Error: No data in provided assay - logcounts

sagrikachugh avatar Apr 24 '24 00:04 sagrikachugh

@Gesmira Could you please have a look at the above example with mockSCE. It seems like a bug now.

sagrikachugh avatar May 01 '24 09:05 sagrikachugh

I am having a similar issue. I'm trying to create an object that just has raw counts:

> SCPCL000001.seurat <- as.Seurat(SCPCL000001_unfiltered, counts = "counts")
Error: No data in provided assay - logcounts

wudustan avatar May 14 '24 12:05 wudustan

Hi @sagrikachugh, Thank you for the reproducible example. I am able to confirm the bug which occurs because the "alternative Experiment" Spikes does not have the logcounts stored. We try to make an assay from each experiment (including the alternative Experiment) which then fails when we get to that. To fix this in the example, you can simply normalize the alternate experiments as well:

test_sce <- applySCE(test_sce, logNormCounts)
test_so <- as.Seurat(test_sce, counts = "counts", data = "logcounts")
> test_so
An object of class Seurat 
2100 features across 200 samples within 2 assays 
Active assay: Spikes (100 features, 0 variable features)
 2 layers present: counts, data
 1 other assay present: originalexp

However, I am curious if this helps you with your original issue.

Gesmira avatar May 14 '24 19:05 Gesmira

Hi @Gesmira

Thank you for your suggestion based on the reproducible example. However, this does not help with my original issue as my data is a cite-seq data and my alternate experiments are HTOs and ADTs

When I run the following code on my sce object

sce <- applySCE(sce, logNormCounts)

I get this error

Error in value[[3L]](cond) : 
  'FUN' failed on alternative Experiment 'ADTs':
  size factors should be positive

Here is my SCE for context

sce
class: SingleCellExperiment 
dim: 28421 111963 
metadata(1): Samples
assays(3): counts logcounts reconstructed
rownames(28421): Xkr4 Gm1992 ... CAAA01147332.1 AC149090.1
rowData names(4): ID Symbol Type CHR
colnames(111963): 1_AAACCCACAAGTGACG-1 1_AAACCCACACTCACTC-1
  ... 15_TTTGTTGGTTAGTCGT-1 15_TTTGTTGGTTTGGGAG-1
colData names(29): Sample Barcode ... cluster cluster_colours
reducedDimNames(3): PCA UMAP corrected
mainExpName: Gene Expression
altExpNames(2): HTOs ADTs

Could you please suggest how can I solve this error?

sagrikachugh avatar Jun 05 '24 06:06 sagrikachugh

Hi @Gesmira was wondering if you had a chance to look at this and if there is something else I can try for this issue?

sagrikachugh avatar Jun 18 '24 05:06 sagrikachugh