error "second argument must be a list" with GRanges object [closed]
Entering edit mode
Last seen 2.4 years ago
Chicago, IL, USA

Hi :

I have GRangesList grs to find overlap and other meta-analyses, after several workflows, I obtained resGR, which needed to be relisted. However, I come up with the solution to relist `resGR` as GRangesList, but I got an error. My solution works fine with data.frame, but can't work with the S4 class. Can anyone point me out how to fix this error? Is there any simplest way to relist GRanges respect to GRangesList?

Here is input GRangesList :

grs <- GRangesList(
    bar= GRanges(seqnames = Rle("chr1",4),
                 IRanges(c(8,18,33,53), c(14,21,39,61)),
    cat = GRanges(seqnames = Rle("chr1",4),
                  IRanges( c(6,15,20,44), c(10,17,34,51)),
    foo= GRanges(seqnames = Rle("chr1",2),
                 IRanges(c(11,43), c(36,49)), score=c(49,13))

After several workflows, I obtained resGR:

resGR <- GRanges(seqnames = Rle("chr1",9),

I want to relist resGR respect to grs, so I come up with this solution (my attempt might not be desired, perhaps there is  might have a more straightforward way to do this); Here is my solution:

lapply(grs, function(x) resGR[, resGR) %in%, x),])

I have this error:

Error in, resGR) : second argument must be a list

Perhaps my attempt is not feasible, but it works well if use data.frame. Is there any simple and vectorized approach to get this done?  Any idea? Thanks a lot.

Best regards:




r error handling • 3.9k views
Entering edit mode

I'm not sure I totally follow what you're trying to do, but does resGR now contain a subset of the ranges in your original GRangesList, but in a different order?  Any you're trying to match them back to the original?  Is it intentional that you have one fewer range in resGR?

Entering edit mode

Dear Mike:

Yes, resGR was generated as GRanges which contains a subset of ranges in grs (where the order of ranges was different). Yes, I want back resGR as GRangesList. resGR has fewer ranges because some of the ranges were filtered out by a threshold. Why my solution won't work with S4 class? Is there any straightforward, simplest way to do this? Thank you

Best regards:


Entering edit mode
Mike Smith ★ 5.7k
Last seen 10 hours ago
EMBL Heidelberg / de.NBI

How about this?

​matches <- lapply(grs, match, resGR)

reList <- lapply(matches, function(x, res) {
  x <- na.omit(x)
}, resGR)

reList <- as(reList, "GRangesList")

The first line takes the input GRangesList, and for each entry finds any matches in your output GRanges object.

The second part then takes the resulting list of matches, and gets the appropriate entries from resGR and returns it as a normal list of GRanges objects.  

Finally we convert that to a true GRangesList

The output I get is:

GRangesList object of length 3:
GRanges object with 2 ranges and 1 metadata column:
      seqnames    ranges strand |     score
         <Rle> <IRanges>  <Rle> | <numeric>
  [1]     chr1  [ 8, 14]      * |        48
  [2]     chr1  [53, 61]      * |         8

GRanges object with 3 ranges and 1 metadata column:
      seqnames   ranges strand | score
  [1]     chr1 [ 6, 10]      * |    54
  [2]     chr1 [15, 17]      * |    21
  [3]     chr1 [44, 51]      * |    12

GRanges object with 2 ranges and 1 metadata column:
      seqnames   ranges strand | score
  [1]     chr1 [11, 36]      * |    49
  [2]     chr1 [43, 49]      * |    13

seqinfo: 1 sequence from an unspecified genome; no seqlengths

One obvious caveat is that this throws away anything in your resGR object that can't be found in the start data, but it's not clear to me what you'd want to do with it anyway.

Entering edit mode

Dear Mike:

Thanks for your effort. I figured out the problem.

Best regards:



Login before adding your answer.

Traffic: 282 users visited in the last hour
Help About
Access RSS

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6