0

I am trying to combine several grange objects in R using the reduce() function. I already have the grange objects stored in a list, but I can't figure out how to pass the list onto the reduce function.

I have tried

reduce(x = granges))
reduce(x = unlist(granges))
reduce(x = c(unlist(granges)))

but all of these output:

Error in (function (classes, fdef, mtable) : unable to find an inherited method for function 'reduce' for signature '"list"'

So it seems the object still remains a list. So far only

reduce(x = c(granges[[1]],granges[[2]],granges[[3]])))

works. I suspect that there should be a simpler way that I'm just unfamiliar with. Thanks for any help.

zx8754
  • 52,746
  • 12
  • 114
  • 209
rdv
  • 41
  • 4
  • What is the output for `class(c(granges[[1]], granges[[2]], granges[[3]]))`? – Hieu Nguyen May 24 '23 at 12:50
  • It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. – MrFlick May 24 '23 at 13:16
  • ```> class(c(granges[[1]], granges[[2]], granges[[3]])) [1] "GRanges" attr(,"package") [1] "GenomicRanges" Warning message: In .Seqinfo.mergexy(x, y) : Each of the 2 combined objects has sequence levels not in the other: - in 'x': scaffold228, scaffold450 - in 'y': scaffold137, scaffold242, scaffold53 Make sure to always combine/compare objects based on the same reference genome (use suppressWarnings() to suppress this warning).``` – rdv May 24 '23 at 13:20
  • 1
    @rdv Try `lapply(granges, reduce)` – Hieu Nguyen May 24 '23 at 14:21
  • `lapply` produces a new list, and `reduce` ran on the individual grange objects without combining them. What I am supposed to get is a new object with the original grange objects condensed into a single object. – rdv May 25 '23 at 06:36

0 Answers0