1 | """ |
---|
2 | High level operations on genomic intervals. Most accept and produce iterables |
---|
3 | of `bx.io.inervals.io.GenomicInterval` objects. |
---|
4 | """ |
---|
5 | |
---|
6 | from bx.bitset import * |
---|
7 | from bx.filter import * |
---|
8 | |
---|
9 | def warn( msg ): |
---|
10 | print >> sys.stderr, msg |
---|
11 | |
---|
12 | def fail( msg ): |
---|
13 | print >> sys.stderr, msg |
---|
14 | sys.exit(1) |
---|
15 | |
---|
16 | BED_DEFAULT_COLS = 0, 1, 2, 5 |
---|
17 | MAX_END = 512*1024*1024 |
---|
18 | |
---|
19 | def bits_set_in_range( bits, range_start, range_end ): |
---|
20 | """ |
---|
21 | Yield start,end tuples for each span of set bits in [range_start,range_end) |
---|
22 | """ |
---|
23 | end = range_start |
---|
24 | while 1: |
---|
25 | start = bits.next_set( end ) |
---|
26 | end = min( bits.next_clear( start ), range_end ) |
---|
27 | if start >= end: break |
---|
28 | yield start, end |
---|
29 | |
---|
30 | def bits_clear_in_range( bits, range_start, range_end ): |
---|
31 | """ |
---|
32 | Yield start,end tuples for each span of clear bits in [range_start,range_end) |
---|
33 | """ |
---|
34 | end = range_start |
---|
35 | while 1: |
---|
36 | start = bits.next_clear( end ) |
---|
37 | if start >= range_end: break |
---|
38 | end = min( bits.next_set( start ), range_end ) |
---|
39 | yield start, end |
---|