Skip to content

Conversation

@ycl6
Copy link

@ycl6 ycl6 commented Jan 24, 2025

This PR addresses the issue when offset is a DelayedArray object, and the check enters else and get stopped at Line 91.

if(is.matrix(offset)){
stopifnot(dim(offset) == c(n_genes, n_samples))
offset_matrix <- offset
}else if(is(offset, "HDF5Matrix")){
stopifnot(dim(offset) == c(n_genes, n_samples))
stopifnot(make_offset_hdf5_mat)
offset_matrix <- offset
}else{
stopifnot(length(offset) == 1 || length(offset) == n_samples)

My use case is following DESeq2's LRT workflow with a sparse matrix input and on_disk = TRUE. We use glmGamPoi::glm_gp to perform fitting and then glmGamPoi::test_de to test for DE.

While running glm_gp, the offset_matrix is converted into a DelayedArray object at one stage.
While running test_de, it calls glm_gp again when fitting the reduced model. At this point, the fit$Offset is a DelayedArray object and will failed with following error message

Error in combine_size_factors_and_offset(offset, size_factors, Y, verbose = verbose): 
  length(offset) == 1 || length(offset) == n_samples is not TRUE

@const-ae
Copy link
Owner

Thanks. I hope that I will be able to take a look next week, but things are pretty busy for me, so there might be a delay. I was anyways recently investigating what it would take to make glmGamPoi support sparse matrices now that the backend was switched from beachmat to tatami.

@const-ae
Copy link
Owner

Quick question: are there objects that are HDF5Matrix but not DelayedArrays? If not, you could simplify the if statement

@ycl6
Copy link
Author

ycl6 commented Jan 24, 2025

Hi @const-ae

I kinda simplified a little of my use case. I am using DESeq2 to run DE analysis on scRNA-seq data. My starting count matrix input is a dgCMatrix (but I will like it to be DelayedArray eventually, and glm_gp supports it too), but there are some issues with its support on sparse matrix and I am optimising it right now. But basically I am following its LRT workflow and run the whole analysis with DESeq(). When fitting the full model (glm_gp), the offset is converted into a DelayedArray object as my input isn't not a dense matrix nor HDF5Matrix. And the error shows up when fitting with a reduced model (test_de).

I suppose it is possible there will be cases where users uses glmGamPoi as it is (not within DESeq), and therefore the supplied offset could have been a HDF5Matrix. Or, it can also be a DelayedArray as glm_gp also supports it (I think).

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.

2 participants