Question: do.call error "second argument must be a list" with GRanges object [closed]
0
gravatar for Jurat Shahidin
2.7 years ago by
Chicago, IL, USA
Jurat Shahidin70 wrote:

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)),
                 score=c(48,7,10,8)),
    cat = GRanges(seqnames = Rle("chr1",4),
                  IRanges( c(6,15,20,44), c(10,17,34,51)),
                  score=c(54,21,14,12)),
    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),
                 IRanges(c(53,8,6,15,11,44,43,44,43), 
                         c(61,14,10,17,36,51,49,51,49)),
                 score=c(8,48,54,21,49,12,13,12,13))

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[do.call(paste, resGR) %in% do.call(paste, x),])

I have this error:

Error in do.call(paste, 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:

Jurat

 

 

R error handling • 2.3k views
ADD COMMENTlink modified 2.7 years ago • written 2.7 years ago by Jurat Shahidin70

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?

ADD REPLYlink written 2.7 years ago by Mike Smith4.0k

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:

Jurat

ADD REPLYlink modified 2.7 years ago • written 2.7 years ago by Jurat Shahidin70
Answer: do.call error "second argument must be a list" with GRanges object
1
gravatar for Mike Smith
2.7 years ago by
Mike Smith4.0k
EMBL Heidelberg / de.NBI
Mike Smith4.0k wrote:

How about this?

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

reList <- lapply(matches, function(x, res) {
  x <- na.omit(x)
  res[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:
$bar 
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

$cat 
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

$foo 
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.

ADD COMMENTlink modified 2.7 years ago • written 2.7 years ago by Mike Smith4.0k

Dear Mike:

Thanks for your effort. I figured out the problem.

Best regards:

Jurat

ADD REPLYlink modified 2.7 years ago • written 2.7 years ago by Jurat Shahidin70
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 16.09
Traffic: 181 users visited in the last hour