I've looked around and it doesn't seem like there were any questions posted before regarding this. I have two GRanges object with some coordinates, and I would like to subtract the intervals of one from the other. This is different from finding overlaps with findOverlaps() or using intersect().
For instance:
granges.in
seqnames ranges$start ranges$end
chr01 1100 2000
chr01 2100 3000
chr02 1000 4000
chr03 1500 3500
granges.out
seqnames ranges$start ranges$end
chr01 1000 1200
chr02 2500 3000
chr03 1500 2000
chr03 3000 3500
and I want:
granges.ref
seqnames ranges$start ranges$end
chr01 1200 2000
chr01 2100 3000
chr02 1000 2500
chr02 3000 4000
chr03 2000 3000
The following works, but it's pretty clumsy and I would have to do it chromosome by chromosome as the number of intervals per chromosome does not match between the two objects.
setdiff(ranges(genome.ref[seqnames(granges.in) == "chr01"]),
ranges(interval[seqnames(granges.out)== "chr01"]))
Is there a quicker, more effective way to do using the two GRanges object as a whole?