Bioconductor / RaggedExperiment

Matrix-like representations of mutation and CN data
https://bioconductor.org/packages/RaggedExperiment
4 stars 3 forks source link

Different order of rows depending on the type of assay extraction #30

Closed csoneson closed 4 months ago

csoneson commented 4 months ago

Hello,

this is more of a curiosity, but it seems that the order of the rows is different depending on whether one sets sparse to TRUE or FALSE for compactAssay(). I couldn't see this mentioned in the documentation (sorry if I missed it somewhere!) and was wondering if it was intentional.

Example:

library(RaggedExperiment)
sample1 <- GRanges(
    c(a = "chr1:1-10:-", b = "chr1:11-18:+"),
    score = 1:2)
sample2 <- GRanges(
    c(c = "chr2:1-10:-", d = "chr2:11-18:+"),
    score = 3:4)
colDat <- DataFrame(id = 1:2)
re1 <- RaggedExperiment(sample1=sample1, sample2=sample2, colData = colDat)
re1
compactAssay(re1, sparse = FALSE)
compactAssay(re1, sparse = TRUE)
rowRanges(re1)

gives

> library(RaggedExperiment)
> sample1 <- GRanges(
+     c(a = "chr1:1-10:-", b = "chr1:11-18:+"),
+     score = 1:2)
> sample2 <- GRanges(
+     c(c = "chr2:1-10:-", d = "chr2:11-18:+"),
+     score = 3:4)
> colDat <- DataFrame(id = 1:2)
> re1 <- RaggedExperiment(sample1=sample1, sample2=sample2, colData = colDat)
> re1
class: RaggedExperiment 
dim: 4 2 
assays(1): score
rownames(4): a b c d
colnames(2): sample1 sample2
colData names(1): id
> compactAssay(re1, sparse = FALSE)
             sample1 sample2
chr1:11-18:+       2      NA
chr1:1-10:-        1      NA
chr2:11-18:+      NA       4
chr2:1-10:-       NA       3
> compactAssay(re1, sparse = TRUE)
4 x 2 sparse Matrix of class "dgCMatrix"
             sample1 sample2
chr1:1-10:-        1       .
chr1:11-18:+       2       .
chr2:1-10:-        .       3
chr2:11-18:+       .       4
> rowRanges(re1)
GRanges object with 4 ranges and 0 metadata columns:
    seqnames    ranges strand
       <Rle> <IRanges>  <Rle>
  a     chr1      1-10      -
  b     chr1     11-18      +
  c     chr2      1-10      -
  d     chr2     11-18      +
  -------
  seqinfo: 2 sequences from an unspecified genome; no seqlengths

I'm using Bioc 3.19, RaggedExperiment 1.28.0 Thanks!

LiNk-NY commented 4 months ago

Hi Charlotte, @csoneson Thanks for reporting! We were ordering by GRanges order only for one output type. This should be fixed.

Best regards, Marcel

csoneson commented 4 months ago

Thanks @LiNk-NY!