1

I have problem with looping over the GRanges list.

my feature contains a list of objects:

feature file:

...

$Pol3
GRanges object with 205 ranges and 0 metadata columns:
      seqnames                 ranges strand
         <Rle>              <IRanges>  <Rle>
    1     chr1 [ 16545569,  16546385]      *
    2     chr1 [ 16678151,  16678447]      *
    3     chr1 [ 93847201,  93848017]      *
    4     chr1 [146039330, 146039547]      *
    5     chr1 [146038406, 146038434]      *
  ...      ...                    ...    ...
  180     chr8 [ 66112999,  66114487]      *
  181     chr8 [ 95269339,  95270155]      *
  182     chr8 [123157081, 123157461]      *
  183     chrX [ 18674543,  18675359]      *
  184     chrX [137437934, 137438750]      *
  -------
  seqinfo: 17 sequences from an unspecified genome; no seqlengths

$FOS
GRanges object with 14383 ranges and 0 metadata columns:
          seqnames                 ranges strand
             <Rle>              <IRanges>  <Rle>
      [1]     chr1     [ 778602,  778872]      *
      [2]     chr1     [ 966089,  966373]      *
      [3]     chr1     [1000738, 1001022]      *
      [4]     chr1     [1064238, 1064508]      *
      [5]     chr1     [1080197, 1080467]      *
      ...      ...                    ...    ...
  [14379]     chrX [155026485, 155026769]      *
  [14380]     chrX [155068168, 155068452]      *
  [14381]     chrX [155216229, 155216464]      *
  [14382]     chrX [155881129, 155881399]      *
  [14383]     chrX [155888227, 155888497]      *
  -------
  seqinfo: 23 sequences from an unspecified genome; no seqlengths

...

and my interval is like:

GRanges object with 6 ranges and 1 metadata column:
      seqnames               ranges strand |          id
         <Rle>            <IRanges>  <Rle> | <character>
  [1]     chr1 [ 8409137,  8409637]      * |   region1
  [2]     chr1 [ 8789220,  8789720]      * |   region1
  [3]     chr1 [ 9615503,  9616003]      * |   region1
  [4]     chr1 [10960926, 10961426]      * |   region1
  [5]     chr1 [11797718, 11798218]      * |   region1
  [6]     chr1 [12434198, 12434698]      * |   region1
  -------
  seqinfo: 23 sequences from an unspecified genome; no seqlengths

For each object in feature file (e.g. $FOS) I am able to do

mtch = findOverlaps(interval, feature$FOS)
myRanges = ranges(mtch,ranges(interval),ranges(feature$FOS))

everything is fine for each object one by one but when I try to use lapply , the second step does not work

mtch <- lapply(feature, function(x) findOverlaps(x, interval)) 

myRanges = ranges(mtch,ranges(currmySegm),ranges(feature))

I get :

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

OR

   myRanges = ranges(mtch,ranges(interval),lapply(feature, function(x) ranges(x)))
Error in (function (classes, fdef, mtable)  : 
  unable to find an inherited method for function 'ranges' for signature '"list"'

Thank so much for helping me

  • You need to use `lapply` in `myRanges = ranges(mtch, ranges(currmySegm), ranges(feature))` since this is a list now – emilliman5 Dec 01 '16 at 19:14
  • @emilliman5, thanks for your reply. would you please let me know how to use lapply in this case? I tried many ways but did not work – user6013305 Dec 01 '16 at 19:51
  • If you can make a minimal example, using `dput` we can do more to help. But as I see it `mtch` is a list and `features` is a list that need to be looped through. It is also unclear where `currmySegm` is coming from. I assume you want something like `ranges(mtch[[i]], ranges(interval), ranges(features[[i]]))`. – emilliman5 Dec 01 '16 at 19:51

1 Answers1

0

Step two should be something like this assuming you want to get ranges from the matches and the original GRange objects:

lapply(seq_along(mtch), function(i){ 
    ranges(mtch[[i]], ranges(interval), ranges(features[[i]]))
})
emilliman5
  • 5,816
  • 3
  • 27
  • 37
  • is there anyway to share my files with you? I get a new error Error in .local(x, ...) : 'query' must be a Ranges of length equal to number of queries – user6013305 Dec 01 '16 at 20:19
  • Maybe you could start by explaining what you are trying to do. I understand the `findOverlaps` call but not the `range` of `ranges` – emilliman5 Dec 01 '16 at 20:27