lapply for GRanges
1
0
Entering edit mode
@dadbfbf7
Last seen 2.3 years ago
United States

When I use the 'lapply' function for data in the format of 'GRanges', the system prompts an error, so what are the good solutions? (((Thank you!


data(IlluminaHumanMethylationEPICanno.ilm10b4.hg19)
data(Locations)
locs<-Locations
locs.ranges<-GRanges(Locations$chr,IRanges(Locations$pos,Locations$pos))
names(locs.ranges)<-rownames(Locations)
DMR.IDs<-lapply(results.ranges,function(x) names(locs.ranges[locs.ranges %over% x]))

GRanges objects don't support [[, as.list(), lapply(), or unlist() at the
  moment 

sessionInfo( )
lapply GRanges • 1.1k views
ADD COMMENT
1
Entering edit mode
@herve-pages-1542
Last seen 15 hours ago
Seattle, WA, United States

You can loop on a GRanges object, if you really want to, by doing something like this:

DMR.IDs <- lapply(seq_along(results.ranges), function(i) names(locs.ranges[locs.ranges %over% results.ranges[i]]))

However, keep in mind that lapply-based solutions tend to be quite inefficient so should be avoided whenever possible. In your case a much better way is to do:

hits <- findOverlaps(results.ranges, locs.ranges)
DMR.IDs <- extractList(names(locs.ranges), as(hits, "IntegerList"))

This will be thousands times more efficient ;-)

Cheers,

H.

ADD COMMENT

Login before adding your answer.

Traffic: 659 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

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

Powered by the version 2.3.6