【发布时间】:2016-12-01 18:46:13
【问题描述】:
我在遍历 GRanges 列表时遇到问题。
我的feature 包含一个对象列表:
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
...
而我的interval 是这样的:
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
对于功能文件中的每个对象(例如 $FOS)我都能做到
mtch = findOverlaps(interval, feature$FOS)
myRanges = ranges(mtch,ranges(interval),ranges(feature$FOS))
每个对象的一切都很好,但是当我尝试使用 lapply 时,第二步不起作用
mtch <- lapply(feature, function(x) findOverlaps(x, interval))
myRanges = ranges(mtch,ranges(currmySegm),ranges(feature))
我明白了:
Error in (function (classes, fdef, mtable) :
unable to find an inherited method for function 'ranges' for signature '"list"'
或
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"'
非常感谢你帮助我
【问题讨论】:
-
您需要在
myRanges = ranges(mtch, ranges(currmySegm), ranges(feature))中使用lapply,因为这是一个列表 -
@emilliman5,感谢您的回复。你能告诉我在这种情况下如何使用 lapply 吗?我尝试了很多方法,但没有奏效
-
如果你能做一个最小的例子,使用
dput我们可以做更多的帮助。但正如我所见,mtch是一个列表,features是一个需要循环遍历的列表。还不清楚currmySegm的来源。我假设你想要像ranges(mtch[[i]], ranges(interval), ranges(features[[i]]))这样的东西。