7 Overlapping Ranges

PyRanges objects can be overlapped with other PyRanges to report the intervals in self that overlap with those in other.

import pyranges as pr
gr = pr.load_dataset("aorta")
gr2 = pr.load_dataset("aorta2")
print(gr.overlap(gr2))
## +--------------+-----------+-----------+------------+-----------+--------------+
## | Chromosome   | Start     | End       | Name       | Score     | Strand       |
## | (category)   | (int64)   | (int64)   | (object)   | (int64)   | (category)   |
## |--------------+-----------+-----------+------------+-----------+--------------|
## | chr1         | 9916      | 10115     | H3K27me3   | 5         | -            |
## | chr1         | 9939      | 10138     | H3K27me3   | 7         | +            |
## | chr1         | 9951      | 10150     | H3K27me3   | 8         | -            |
## | ...          | ...       | ...       | ...        | ...       | ...          |
## | chr1         | 10127     | 10326     | H3K27me3   | 1         | -            |
## | chr1         | 10241     | 10440     | H3K27me3   | 6         | -            |
## | chr1         | 10246     | 10445     | H3K27me3   | 4         | +            |
## +--------------+-----------+-----------+------------+-----------+--------------+
## PyRanges object has 10 sequences from 1 chromosomes.

Both methods also take a strandedness option, which can either be "same", "opposite" or False/None

print(gr.overlap(gr2, strandedness="opposite"))
## +--------------+-----------+-----------+------------+-----------+--------------+
## | Chromosome   | Start     | End       | Name       | Score     | Strand       |
## | (category)   | (int64)   | (int64)   | (object)   | (int64)   | (category)   |
## |--------------+-----------+-----------+------------+-----------+--------------|
## | chr1         | 9939      | 10138     | H3K27me3   | 7         | +            |
## | chr1         | 9953      | 10152     | H3K27me3   | 5         | +            |
## | chr1         | 10024     | 10223     | H3K27me3   | 1         | +            |
## | ...          | ...       | ...       | ...        | ...       | ...          |
## | chr1         | 10001     | 10200     | H3K27me3   | 5         | -            |
## | chr1         | 10127     | 10326     | H3K27me3   | 1         | -            |
## | chr1         | 10241     | 10440     | H3K27me3   | 6         | -            |
## +--------------+-----------+-----------+------------+-----------+--------------+
## PyRanges object has 10 sequences from 1 chromosomes.