Closed yli110-stat697 closed 1 year ago
Hi @yli110-stat697 Rosemary,
Thank you for reporting. This seems to be an issue with DataFrame
sub-assignment.
I have asked Hervé about it here https://github.com/Bioconductor/S4Vectors/issues/117
-Marcel
dimnames<-
seems broken when the RaggedExperiment object carries colData:
library(RaggedExperiment)
sample1 <- GRanges(c("chr1:1-10", "chr1:11-18"), score=1:2)
sample2 <- GRanges(c("chr1:1-10", "chr2:11-18"), score=3:4)
re <- RaggedExperiment(sample1, sample2)
colData(re) <- DataFrame(sampleID=c("ID1", "ID2"))
dimnames(re) <- dimnames(re)
# Error in .subassign_columns(x, nsbs, value) :
# provided 1 variables to replace 0 variables
Here's another issue with the current implementation of dimnames<-
:
re2 <- RaggedExperiment(sample1, sample2)[4:1]
rownames(re2) <- letters[1:4]
rownames(re2)
# [1] "d" "c" "b" "a" <-- not the expected rownames
FWIW it looks like the current implementation of the dimnames<-
method is unnecessarily complicated and could be made slightly simpler by doing something like this:
.set_RaggedExperiment_dimnames <- function(x, value)
{
new_rownames <- value[[1L]]
new_colnames <- value[[2L]]
x_assays <- .assays(x)
if (is.null(new_colnames)) {
names(x_assays) <- NULL
} else {
names(x_assays)[.colidx(x)] <- new_colnames
}
unlisted_assays <- unlist(x_assays, use.names=FALSE)
if (is.null(new_rownames)) {
names(unlisted_assays) <- NULL
} else {
names(unlisted_assays)[.rowidx(x)] <- new_rownames
}
new_assays <- relist(unlisted_assays, x_assays)
mcols(new_assays) <- mcols(x_assays)
BiocGenerics:::replaceSlots(x, assays=new_assays, check=FALSE)
}
Hope this helps,
H.
I just edited my .set_RaggedExperiment_dimnames
proposal above to make sure that setting the dimnames to NULL actually drops the dimnames. Note that the current dimnames<-
method also fails to handle this case:
re <- RaggedExperiment(sample1, sample2)
dimnames(re) <- list(letters[1:4], LETTERS[1:2])
dimnames(re) <- NULL
dimnames(re)
# [[1]]
# [1] "a" "b" "c" "d"
#
# [[2]]
# [1] "A" "B"
The unit tests for dimnames<-
would need to be expanded to cover all these situations.
Thank you. This should be fixed in the latest version of RaggedExperiment (1.24.2 or 1.25.3).
Hi, I have a RaggedExperiment and I want to change its
colnames(x)
or row names of itscolData(x)
to a different sample id from its colData, and found that thedimnames()
setter was not working as it claimed from the documentation.Example RaggedExperiment
Currently the colnames are
sample1, sample2
, but I want to change to the New_id from colDat. I was trying the dimnames and fount that