1 | """ |
---|
2 | Determine the number of bases covered by a set of intervals. |
---|
3 | """ |
---|
4 | |
---|
5 | import psyco_full |
---|
6 | |
---|
7 | import traceback |
---|
8 | import fileinput |
---|
9 | from warnings import warn |
---|
10 | |
---|
11 | from bx.intervals.io import * |
---|
12 | from bx.intervals.operations import * |
---|
13 | |
---|
14 | def base_coverage( reader ): |
---|
15 | # Handle any ValueError, IndexError and OverflowError exceptions that may be thrown when |
---|
16 | # the bitsets are being created by skipping the problem lines |
---|
17 | base_reader = BitsetSafeReaderWrapper( reader, lens={} ) |
---|
18 | bitsets = base_reader.binned_bitsets() |
---|
19 | coverage = 0 |
---|
20 | for chrom in bitsets: |
---|
21 | try: |
---|
22 | coverage += bitsets[chrom].count_range(0, MAX_END) |
---|
23 | except IndexError, e: |
---|
24 | base_reader.skipped += 1 |
---|
25 | # no reason to stuff an entire bad file into memmory |
---|
26 | if base_reader.skipped < 10: |
---|
27 | base_reader.skipped_lines.append( ( base_reader.linenum, base_reader.current_line, str( e ) ) ) |
---|
28 | continue |
---|
29 | return coverage |
---|