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

SCTransform vars.to.regress Contrasts can be applied only to factors with 2 or more levels #193

Open
UKECat opened this issue May 8, 2024 · 0 comments

Comments

@UKECat
Copy link

UKECat commented May 8, 2024

Hi there,
I encountered an error while attempting to run SCTransform() in the Seurat package. The error message suggests a problem with the second non-regularized linear regression step. The error only occurs, when I add the parameter "batch" to vars.to.regress. Here are the details:
Running this code:

merged_seurat_b <- SCTransform(
     merged_seurat,
     vars.to.regress = c("percent.mt", "nFeature_RNA", "nCount_RNA", "batch"), 
     do.scale=FALSE, 
     do.center=TRUE,
     verbose=TRUE)

Produces this error:

Running SCTransform on layer: counts.C1
vst.flavor='v2' set. Using model with fixed slope and excluding poisson genes.
Variance stabilizing transformation of count matrix of size 14474 by 4786
Model formula is y ~ log_umi
Get Negative Binomial regression parameters per gene
Using 2000 genes, 4786 cells
Found 42 outliers - those will be ignored in fitting/regularization step

Second step: Get residuals using fitted parameters for 14474 genes
Computing corrected count matrix for 14474 genes
Calculating gene attributes
Wall clock passed: Time difference of 39.14677 secs
Determine variable features
Regressing out percent.mt, nFeature_RNA, nCount_RNA, batch
Error in `contrasts<-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]) : 
  Contrasts can be applied only to factors with 2 or more levels

Every sample has been assigned to a batch using this code beforehand:

merged_seurat <- RenameIdents(merged_seurat,
                              'C1' = '01',
                              'C2' = '01',
                              'C3' = '01',
                              'C4' = '02',
                              'C5' = '02')
merged_seurat$batch <- Idents(merged_seurat)

I am using the Seurat Package Version 5.0.2

Does anybody have an idea how to solve this? I appreciate any help! Cheers!

@UKECat UKECat changed the title SCTransform vars.to.regress SCTransform vars.to.regress Contrasts can be applied only to factors with 2 or more levels May 8, 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