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

https://bitbucket.org/cistrome/cistrome-harvard/ · Python · 37 lines · 24 code · 6 blank · 7 comment · 3 complexity · 9b0d9416d22c339a79f6caa308c7910e MD5 · raw file

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