As part of a larger analysis, I need to evaluate pairs of genomic regions (regionsA and regionsB) and perform different calculations for each pair depending on whether:

  1. They're completely separate (no overlap)
  2. regionsB partially overlaps regionsA (start or end of regionsB does not overlap; both are handled separately)
  3. regionsB is fully contained in regionsA

At this time, regionsA and regionsB are represented as Pandas DataFrames. Likewise, I'm doing all possible combinations:

if (region_b.start < region_a.start and
    region_b.end < region_b.start):
elif (region_b.start < region_a.start and
     (region_b.end > region_a.start
     and region_b.end < region_a.end )):

Given that there are many conditions I check for, this makes the code long, a little hard to read, and too verbose. Is there anything I can use (without making the code harder to read) to make these checks simpler, something like PyRanges (or PyRanges itself, although I don't think there's API for it)?

If not, I'll just live with what I have.



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.