I have 2 genomic ranges
g1<-GRanges(c("chr1:0-14","chr1:15-29"), score=c(20.2,10.4));g1
GRanges object with 2 ranges and 1 metadata column:
seqnames ranges strand | score
<Rle> <IRanges> <Rle> | <numeric>
[1] chr1 0-14 * | 20.2
[2] chr1 15-29 * | 10.4
g2<-GRanges(c("chr1:0-9","chr1:10-19","chr1:20-29"), state=c('E1','E2','E1'));g2
GRanges object with 3 ranges and 1 metadata column:
seqnames ranges strand | state
<Rle> <IRanges> <Rle> | <character>
[1] chr1 0-9 * | E1
[2] chr1 10-19 * | E2
[3] chr1 20-29 * | E1
I would like to make them comparable. First I combined them and then I used disjoin:
g3<-(c(g1,g2)); g3
GRanges object with 5 ranges and 2 metadata columns:
seqnames ranges strand | score state
<Rle> <IRanges> <Rle> | <numeric> <character>
[1] chr1 0-14 * | 20.2 <NA>
[2] chr1 15-29 * | 10.4 <NA>
[3] chr1 0-9 * | <NA> E1
[4] chr1 10-19 * | <NA> E2
[5] chr1 20-29 * | <NA> E1
disjoin(g3)
GRanges object with 4 ranges and 0 metadata columns:
seqnames ranges strand
<Rle> <IRanges> <Rle>
[1] chr1 0-9 *
[2] chr1 10-14 *
[3] chr1 15-19 *
[4] chr1 20-29 *
So, disjoin is doing the split I want, but unfortunately does not keep the metadata. Is there a way to keep metadata and obtain GRanges like this?
GRanges object with 5 ranges and 2 metadata columns:
seqnames ranges strand | score state
<Rle> <IRanges> <Rle> | <numeric> <character>
[1] chr1 0-9 *| 20.2 E1
[2] chr1 10-14 *| 20.2 E2
[3] chr1 15-19 *| 10.4 E2
[4] chr1 20-29 *| 10.4 E1
Thanks