[2] | 1 | """Utility functions for galaxyops""" |
---|
| 2 | import sys |
---|
| 3 | from bx.bitset import * |
---|
| 4 | from bx.intervals.io import * |
---|
| 5 | |
---|
| 6 | def warn( msg ): |
---|
| 7 | # TODO: since everything printed to stderr results in job.state = error, we |
---|
| 8 | # don't need both a warn and a fail... |
---|
| 9 | print >> sys.stderr, msg |
---|
| 10 | sys.exit( 1 ) |
---|
| 11 | |
---|
| 12 | def fail( msg ): |
---|
| 13 | print >> sys.stderr, msg |
---|
| 14 | sys.exit( 1 ) |
---|
| 15 | |
---|
| 16 | # Default chrom, start, end, strand cols for a bed file |
---|
| 17 | BED_DEFAULT_COLS = 0, 1, 2, 5 |
---|
| 18 | |
---|
| 19 | def parse_cols_arg( cols ): |
---|
| 20 | """Parse a columns command line argument into a four-tuple""" |
---|
| 21 | if cols: |
---|
| 22 | # Handle case where no strand column included - in this case, cols |
---|
| 23 | # looks something like 1,2,3, |
---|
| 24 | if cols.endswith( ',' ): |
---|
| 25 | cols += '0' |
---|
| 26 | col_list = map( lambda x: int( x ) - 1, cols.split(",") ) |
---|
| 27 | return col_list |
---|
| 28 | else: |
---|
| 29 | return BED_DEFAULT_COLS |
---|
| 30 | |
---|
| 31 | def default_printer( stream, exc, obj ): |
---|
| 32 | print >> stream, "%d: %s" % ( obj.linenum, obj.current_line ) |
---|
| 33 | print >> stream, "\tError: %s" % ( str(exc) ) |
---|
| 34 | |
---|
| 35 | def skipped( reader, filedesc="" ): |
---|
| 36 | first_line, line_contents, problem = reader.skipped_lines[0] |
---|
| 37 | return 'Skipped %d invalid lines%s, 1st line #%d: "%s", problem: %s' % ( reader.skipped, filedesc, first_line, line_contents, problem ) |
---|