Skip to content

vst() fails when using custom latent variable with vst.flavor = "v2" #208

@blasks

Description

@blasks

When calling sctransform::vst() with a user-defined latent variable and vst.flavor = "v2", the function errors with:

Error in fit_glmGamPoi_offset(...): !is.null(log10_umi) is not TRUE

This happens even when a the column in cell_attr is a valid numeric column.

Minimal Example

library(sctransform)
library(Matrix)

# fake count data
set.seed(1)
data <- Matrix(
  rpois(50, lambda = 5), 
  nrow = 10, 
  ncol = 5,
  dimnames = list(paste0("gene", 1:10), paste0("cell", 1:5)), 
  sparse = TRUE
)

# fake cell attributes
cell_attr <- data.frame(
  user_var = runif(5, 100, 1000),
  row.names = colnames(data)
)

# works fine
result_ok <- vst(data, cell_attr = cell_attr, vst.flavor = "v2", verbosity = 2)

# fails
result_fail <- vst(data, cell_attr = cell_attr, latent_var = "user_var", vst.flavor = "v2", verbosity = 2)

# works, but with a different result from the first call
cell_attr$log_umi <- log10(cell_attr$user_var)
result_different <- vst(data, cell_attr = cell_attr, latent_var = "log_umi", vst.flavor = "v2", verbosity = 2)

I'm running sctransform version 0.4.2, and R version 4.5.1 on a macOS system.

Thanks for looking into this!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions