Hello - I expect GenomicRanges:disjoin is your friend for this operation. Look:
# editted for tightness and clarity, and to add a final split
> g<-GRangesList(GeneA.1 = GRanges(seqnames="x", ranges=IRanges(1, 10), strand="+")
+ ,GeneA.2 = GRanges(seqnames="x", ranges=IRanges(c(1, 8), c(3,10)), strand='+')
+ ,GeneA.3 = GRanges(seqnames="x", ranges=IRanges(c(1, 7), c(3,15)), strand='+'))
> u<-unlist(g)
> d <- disjoin(u, with.revmap=TRUE)
> d$source<-lapply(d$revmap,function(i)names(u)[i])
> d1<-d[1==lengths(d$revmap)]
> s<-split(d1,unlist(d1$source))
> d1
GRanges object with 2 ranges and 2 metadata columns:
seqnames ranges strand | revmap source
<Rle> <IRanges> <Rle> | <IntegerList> <list>
[1] x [ 4, 6] + | 1 GeneA.1
[2] x [11, 15] + | 5 GeneA.3
-------
seqinfo: 1 sequence from an unspecified genome; no seqlengths
> s
GRangesList object of length 2:
$GeneA.1
GRanges object with 1 range and 2 metadata columns:
seqnames ranges strand | revmap source
<Rle> <IRanges> <Rle> | <IntegerList> <list>
[1] x [4, 6] + | 1 GeneA.1
$GeneA.3
GRanges object with 1 range and 2 metadata columns:
seqnames ranges strand | revmap source
[1] x [11, 15] + | 5 GeneA.3
-------
seqinfo: 1 sequence from an unspecified genome; no seqlengths
>
Could also do
Yes, except that it does not provide the info present in the revmap, being the association of each range with the to which it is unique isoform which I am assuming (perhaps incorrectly?) is desired result
Malcolm Cook, thank you so much for the complete example. Michael Lawrence, thanks for your help, too. I really appreciate it.
@hwu12 - Glad to help! The best thanks would be to accept my answer!
Malcolm, how can I accept your answer? I want to do it but I cannot find a way to do it. It is not similar to StackOverflow. Sorry I did not see your reply until now. Please let me know and I will accept your answer. Thanks again!
To the left of every response to your question you should have the opportunity to click on a "thumb" to give the response +1 points and I think also a check-mark in a circle, which will turn green, which indicates that you have "accepted" the response as an answer. I could not find documentation on this for you. I wonder where it is. Here is an example of a response of mine which was accepted as an answer: A: Importing a .txt file with multiple headers into R - you should be able to see the gree check mark
The problem is in my Safari browser. I cannot/never see the green circle there. I switched to Firefox and can see it now. Thanks again.
Thanks. I reported your experience as an issue here: checkbox to accept response as answer does not appear in Safari browser #439
Thanks! I uploaded an image to issue #439 from the two browsers to show the problem. Hopefully, they can fix it soon. In any case, I will use the Firefox to vote in the future.