Hi everyone:
Is there any way to coerce simple list-like object "list" to S4 "List" object? Apparently, I used nested-lapply on my functions, and I checked its return type as "list". I want "List" like objects instead. Is that possible to do such coercion in R? if answer is yes, how can I do that ? Thanks
Here is the reproducible example to understand the problem that I stated :
foo <- GRanges( seqnames=Rle(c("chr1", "chr2", "chr3", "chr4"), c(3, 2, 1, 2)), ranges=IRanges(seq(1, by=9, len=8), seq(7, by=9, len=8)), rangeName=letters[seq(1:8)], score=sample(1:20, 8, replace = FALSE)) bar <- GRanges( seqnames=Rle(c("chr1", "chr2", "chr3","chr4"), c(4, 3, 1, 1)), ranges=IRanges(seq(2, by=5, len=9), seq(4, by=5, len=9)), rangeName=letters[seq(1:9)], score=sample(1:20, 9, replace = FALSE)) moo <- GRanges( seqnames=Rle(c("chr1", "chr2", "chr3","chr4"), c(3, 4, 2,1)), ranges=IRanges(seq(5, by=7, len=10), seq(8, by=7, len=10)), rangeName=letters[seq(1:10)], score=sample(1:20, 10, replace = FALSE))
# hitIndex;
grl <- GRangesList(bar, moo) res <- lapply(grl, function(ele_) { tmp <- as(findOverlaps(foo, ele_), "List") })
#
obj.ov <- lapply(res, function(ele_) { re <- lapply(grl, function(obj) { id0 <- as(which.max(extractList(obj$score, ele_)), "List") id0 <- id0[!is.na(id0)] }) re <- re[!duplicated(re)] })
I want to coerce obj.ov
to S4 "List" ?. Any way to do this in R? Any possible approach, ideas, are appreciated.
Best regards;
Jurat
Same question on Biostars: https://www.biostars.org/p/200238/