mock_matrix <- function(ngenes, ncells) {
cell.means <- 2^stats::runif(ngenes, 2, 10)
cell.disp <- 100 / cell.means + 0.5
cell.data <- matrix(stats::rnbinom(ngenes * ncells,
mu = cell.means,
size = 1 / cell.disp
), ncol = ncells)
rownames(cell.data) <- sprintf("Gene_%s", formatC(seq_len(ngenes),
width = 4, flag = 0
))
colnames(cell.data) <- sprintf("Cell_%s", formatC(seq_len(ncells),
width = 3, flag = 0
))
cell.data
}
mat1 <- mock_matrix(30, 20)
mat2 <- mock_matrix(30, 20)
path <- normalizePath(c(tempfile(), tempfile()), mustWork = FALSE)
mat <- rbind(mat1, mat2)
mat1 <- BPCells::write_matrix_dir(as(mat1, "dgCMatrix"), dir = path[1L])
#> Warning: Matrix compression performs poorly with non-integers.
#> • Consider calling convert_matrix_type if a compressed integer matrix is intended.
#> This message is displayed once every 8 hours.
mat2 <- BPCells::write_matrix_dir(as(mat2, "dgCMatrix"), dir = path[2L])
obj <- rbind(mat1, mat2)
# if we omit this line, it'll work fine
obj <- BPCells::convert_matrix_type(obj, "uint32_t")
values <- matrix(sample(mat, length(mat)), nrow = nrow(mat))
# this'll be okay
# obj[1:10, ] <- values[1:10, ]
# this'll be okay
# obj[, 1:10] <- values[, 1:10]
obj[1:10, 1:10] <- values[1:10, 1:10]
#> Warning: Converting input matrix type to match destination
#> • input type: double
#> • destination type: uint32_t
as.matrix(obj)
#> Warning: Converting to a dense matrix may use excessive memory
#> This message is displayed once every 8 hours.
#> Error in h(simpleError(msg, call)): error in evaluating the argument 'x' in selecting a method for function 'as.matrix': invalid class "dgTMatrix" object: length of Dimnames[[2]] (10) is not equal to Dim[2] (20)
Created on 2024-07-04 with reprex v2.1.0
~
~
~
~
~
~
~
~
~
~
Created on 2024-07-04 with reprex v2.1.0 ~
~
~
~
~
~
~
~
~
~