Remove overlapping sequences with GenomicRanges
Hi everyone, I needed some help using GenomicRanges from R.
I have Two gr objects such as :
> genes_bacteria
GRanges object with 6 ranges and 0 metadata columns:
seqnames ranges strand
<Rle> <IRanges> <Rle>
[1] scaffold_1 1-50 -
[2] scaffold_1 60-100 -
[3] scaffold_1 200-350 -
[4] scaffold_2 1500-1700 +
[5] scaffold_2 1900-2300 -
[6] scaffold_5 250-255 +
-------
seqinfo: 3 sequences from an unspecified genome; no seqlengths
and
> genes_busco
GRanges object with 6 ranges and 0 metadata columns:
seqnames ranges strand
<Rle> <IRanges> <Rle>
[1] scaffold_1 1-50 +
[2] scaffold_1 70-120 +
[3] scaffold_2 1550-1650 +
[4] scaffold_3 3000-3815 +
[5] scaffold_4 6-251 +
[6] scaffold_5 6-251 -
-------
seqinfo: 5 sequences from an unspecified genome; no seqlengths
I found the overlapping sequences between them by using the following code:
hits <- findOverlaps(genes_bacteria, genes_busco)
overlaps <- pintersect(genes_bacteria[queryHits(hits)], genes_busco[subjectHits(hits)])
overlaps$with <- width(overlaps)
overlaps$with_bacteria<-width(genes_bacteria[queryHits(hits)])
overlaps$with_busco<-width(genes_busco[subjectHits(hits)])
overlaps$percentOverlap <- width(overlaps) / width(genes_bacteria[queryHits(hits)])
And I got something like:
> overlaps
GRanges object with 1 range and 5 metadata columns:
seqnames ranges strand | hit with with_bacteria with_busco percentOverlap
<Rle> <IRanges> <Rle> | <logical> <integer> <integer> <integer> <numeric>
[1] scaffold_2 1550-1650 + | TRUE 101 201 101 0.502487562189055
-------
seqinfo: 3 sequences from an unspecified genome; no seqlengths
And at the end the aim of my question should be to remove all the overlapping ranges in my genes_bacteria object so here to get:
> genes_bacteria
GRanges object with 30047 ranges and 0 metadata columns:
seqnames ranges strand
<Rle> <IRanges> <Rle>
[1] scaffold_1 1-50 +
[2] scaffold_1 60-100 +
[3] scaffold_1 200-350 +
[5] scaffold_2 1900-2300 +
[6] scaffold_5 250-255 -
-------
As you can see, Scaffold_2 has been deleted because it overlaps.
Thank you for your help.
• 353 views
•
link
0 answers
No answers yet.
Log in to answer this question.
I edited title and tags as the package is called
GenomicRanges, notGenomeRanges.Posted at SO and has answers: https://stackoverflow.com/q/54441312/680068