PageRenderTime 21ms CodeModel.GetById 6ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/galaxy/tools/util/galaxyops/__init__.py

https://bitbucket.org/cistrome/cistrome-harvard/
Python | 37 lines | 24 code | 6 blank | 7 comment | 2 complexity | 9b0d9416d22c339a79f6caa308c7910e MD5 | raw file
 1"""Utility functions for galaxyops"""
 2import sys
 3from bx.bitset import *
 4from bx.intervals.io import *
 5
 6def 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
12def fail( msg ):
13    print >> sys.stderr, msg
14    sys.exit( 1 )
15
16# Default chrom, start, end, strand cols for a bed file
17BED_DEFAULT_COLS = 0, 1, 2, 5
18
19def 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
31def default_printer( stream, exc, obj ):
32    print >> stream, "%d: %s" % ( obj.linenum, obj.current_line )
33    print >> stream, "\tError: %s" % ( str(exc) )
34
35def 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 )