seurat icon indicating copy to clipboard operation
seurat copied to clipboard

Issue with Running Seurat(v5.0.3) on Correlation Matrix Data

Open adesalegn opened this issue 9 months ago • 1 comments

Hi,

I've been using Seurat (v4.0.0) along with PCAtools to analyze correlation networks derived from gene expression data. Previously, I had success with the following code snippet:

library(PCAtools)
library(Seurat)

#  gene expression data
set.seed(123) 
num_genes <- 100  # number of genes
num_samples <- 50  # number of samples

# Generate random gene expression data
gene_expr <- matrix(rnorm(num_genes * num_samples), nrow = num_genes, ncol = num_samples)

# Correlation matrix
coreg <- cor(t(gene_expr), use = 'pairwise.complete.obs', method = 'pearson')
coreg_seurat <- CreateSeuratObject(counts = coreg)
coreg_seurat <- ScaleData(coreg_seurat)
coreg_seurat <- RunPCA(coreg_seurat)

# ElbowPlot(coreg_seurat, ndims = 50)
pca_std <- Stdev(object = coreg_seurat, reduction = 'pca')
chosen <- findElbowPoint(pca_std)
coreg_seurat <- RunUMAP(coreg_seurat, dims = 1:8, n.neighbors = k, min.dist = l)

However, after updating to the latest version of Seurat, I encountered issues when running this code. Specifically, I received the following errors:

Warning: Data is of class matrix. Coercing to dgCMatrix.
Warning: No layers found matching search pattern provided
Error in `ScaleData()`:
! No layer matching pattern 'data' found. Please run NormalizeData and retry
Run `rlang::last_trace()` to see where the error occurred.
Warning: No layers found matching search pattern provided
Error in `PrepDR5()`:
! No layer matching pattern 'scale.data' not found. Please run ScaleData and retry
Run `rlang::last_trace()` to see where the error occurred.

thank you Ad

adesalegn avatar May 05 '24 22:05 adesalegn

I think your layer of your Seurat is called "counts" and not "data"

See

> str(coreg_seurat)
Formal class 'Seurat' [package "SeuratObject"] with 13 slots
  ..@ assays      :List of 1
  .. ..$ RNA:Formal class 'Assay5' [package "SeuratObject"] with 8 slots
  .. .. .. ..@ layers    :List of 1
  .. .. .. .. ..$ counts:Formal class 'dgCMatrix' [package "Matrix"] with 6 slots

Follow your CreateSeurat with:

coreg_seurat <- ScaleData(coreg_seurat, layer = "counts")
coreg_seurat <- FindVariableFeatures(coreg_seurat)

Then it works for me.

roanvanscheppingen avatar May 06 '24 14:05 roanvanscheppingen

Thank you @roanvanscheppingen for your help here. But I think this issue is related to users switching to V5 from V4. PCAtools() might not support the new data structure in V5 so it failed to find the correct "assay" ("assay" is no longer supported in Seurat v5). Please consider down-grading the Seurat back to V4 or check with the developers in PCAtools() to see if there is any update for Seurat V5.

longmanz avatar Jun 24 '24 15:06 longmanz