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

Fix compatibility issue regarding non-character version specification #30

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

pormr
Copy link

@pormr pormr commented Feb 25, 2025

Description: supercell_2_Seurat will always fail on the latest R version (4.4.x, specifically) with an error message, no matter what the value of output.assay.version is.

Error in .make_numeric_version(x, strict, .standard_regexps()$valid_numeric_version) : 
  invalid non-character version specification 'x' (type: double)

Detailed traceback:

6: stop(msg, domain = NA)
5: .make_numeric_version(x, strict, .standard_regexps()$valid_numeric_version)
4: numeric_version(x)
3: as.numeric_version(e2)
2: Ops.numeric_version(packageVersion("Seurat"), 5)
1: supercell_2_Seurat(SC.GE, SC, fields = c("ident"))

It is likely caused by a change in the mechanics for comparing version numbers, as indicated in a similar issue here, which makes direct comparison between numeric_version and numeric type invalid.

Change: The right operand was changed to character type. For example:

  if(packageVersion("Seurat") >= "5"){
    ...
  }

This modification should be compatible with both older and newer versions of R, as indicated in the archived manual for R 3.1.0. I have tested the comparison logic on older versions of R, ranging from R 3.6.0 to R 4.4.0.

@pormr
Copy link
Author

pormr commented Feb 25, 2025

There is another compatibility issue to consider:

When using the latest version of Seurat (v5.1.0), supercell_2_Seurat will fail if the Seurat.object.assay.version option is unset or is set to v5. The error message says:

Error in .subset2(x, i, exact = exact) : subscript out of bounds
In addition: Warning messages:
1: Layer ‘data’ is empty 
2: Layer ‘scale.data’ is empty 

The issue is located between line 95-99 in supercell_2_Seurat.R:

m.seurat <- Seurat::CreateSeuratObject(counts = SC.GE, meta.data = meta)
if(packageVersion("Seurat") >= 5){
m.seurat[["RNA"]] <- as(object = m.seurat[["RNA"]], Class = "Assay")
}

The error can be prevented by setting Seurat.object.assay.version to v3 before running supercell_2_Seurat

options(Seurat.object.assay.version = "v3")

I have no idea what is going wrong in line 98. However, it might be appropriate to change the value of Seurat.object.assay.version temporarily to v3 before creating Seurat object, and then change it back afterwards. One neat solution is to use the withr package, which is implicitly required by many packages, including Seurat.

m.seurat <- withr::with_options(list(Seurat.object.assay.version = "v3"), {
  Seurat::CreateSeuratObject(counts = SC.GE, meta.data = meta)
})

Since this option was introduced in Seurat v5, prior versions will not be affected then.

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

Successfully merging this pull request may close these issues.

1 participant