/tools/new_operations/gops_basecoverage.py

https://bitbucket.org/cistrome/cistrome-harvard/ · Python · 50 lines · 37 code · 6 blank · 7 comment · 5 complexity · 7ea5e5903f2d98a20a72d25e3e5a2576 MD5 · raw file

  1. #!/usr/bin/env python
  2. """
  3. Count total base coverage.
  4. usage: %prog in_file out_file
  5. -1, --cols1=N,N,N,N: Columns for start, end, strand in first file
  6. """
  7. from galaxy import eggs
  8. import pkg_resources
  9. pkg_resources.require( "bx-python" )
  10. import sys, traceback, fileinput
  11. from warnings import warn
  12. from bx.intervals import *
  13. from bx.intervals.io import *
  14. from bx.intervals.operations.base_coverage import *
  15. from bx.cookbook import doc_optparse
  16. from galaxy.tools.util.galaxyops import *
  17. assert sys.version_info[:2] >= ( 2, 4 )
  18. def main():
  19. upstream_pad = 0
  20. downstream_pad = 0
  21. options, args = doc_optparse.parse( __doc__ )
  22. try:
  23. chr_col_1, start_col_1, end_col_1, strand_col_1 = parse_cols_arg( options.cols1 )
  24. in_fname, out_fname = args
  25. except:
  26. doc_optparse.exception()
  27. g1 = NiceReaderWrapper( fileinput.FileInput( in_fname ),
  28. chrom_col=chr_col_1,
  29. start_col=start_col_1,
  30. end_col=end_col_1,
  31. strand_col = strand_col_1,
  32. fix_strand=True )
  33. try:
  34. bases = base_coverage(g1)
  35. except ParseError, exc:
  36. fail( "Invalid file format: %s" % str( exc ) )
  37. out_file = open( out_fname, "w" )
  38. out_file.write( "%s\n" % str( bases ) )
  39. out_file.close()
  40. if g1.skipped > 0:
  41. print skipped( g1, filedesc="" )
  42. if __name__ == "__main__":
  43. main()