Hi, everyone:
I have used extractROWS method for expanding intersected regions from hitlist, and it works fine. However, for 3 GRanges objects (third GRanges can be manually produced ), I have applied my R function for each of them, then wants to apply chisq.test, but I have trouble to coerce list objects (that contain intersected genomic interval) into GRanges objects, and I ran into this problem:
as(res_b, "GRanges")
Error in as(res_b, "GRanges") :
no method or default for coercing “list” to “GRanges”
For the feasibility of my problem, I have this reproducible example :
# set up data
a <- 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))
a$pvalue <- 10^(score(a)/-1) ; a$score <- NULL
b <- 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))
b$pvalue <- 10^(score(b)/-1) ; b$score <- NULL
# overlap
ov_ab <- as(findOverlaps(a, b), "List")
# purify
res_b <- lapply(ov_ab, function(x) {
idx0 <- which.min(extractROWS(b$pvalue, x))
idx1 <- extractROWS(seq_along(b), x)[idx0]
b[idx1]
})
Objective: how can I coerce res_b to GRanges objects ? Is there any way to get out this issue ? Any recommendation, possible solution is highly appreciated. Thanks a lot.
All the best:
Jurat

I have to admit I didn't know that was possible, but you could just unlist:
Ah, that's much nicer. I was sure there was a way to flatten the GRangeList, but looked under 'Coercion' rather than 'Combining' in the man page.
Hi Mike:
Thanks a lot for this quick respond. I have tried your solution, that could help me out.
All the best:
Jurat