SuperCell icon indicating copy to clipboard operation
SuperCell copied to clipboard

Fix compatibility issue regarding non-character version specification

Open pormr opened this issue 11 months ago • 1 comments

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 avatar Feb 25 '25 08:02 pormr

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: https://github.com/GfellerLab/SuperCell/blob/5de820e93ba4991b532ed2ac7ac7a09820bb0164/R/supercell_2_Seurat.R#L95-L99

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.

pormr avatar Feb 25 '25 13:02 pormr