Mercurial > repos > devteam > basecoverage
comparison gops_basecoverage.py @ 0:3755ee8a74d7
Imported from capsule None
| author | devteam |
|---|---|
| date | Tue, 01 Apr 2014 09:13:19 -0400 |
| parents | |
| children | c929b6540d07 |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:3755ee8a74d7 |
|---|---|
| 1 #!/usr/bin/env python | |
| 2 """ | |
| 3 Count total base coverage. | |
| 4 | |
| 5 usage: %prog in_file out_file | |
| 6 -1, --cols1=N,N,N,N: Columns for start, end, strand in first file | |
| 7 """ | |
| 8 | |
| 9 import sys, traceback, fileinput | |
| 10 from warnings import warn | |
| 11 from bx.intervals import * | |
| 12 from bx.intervals.io import * | |
| 13 from bx.intervals.operations.base_coverage import * | |
| 14 from bx.cookbook import doc_optparse | |
| 15 from galaxy.tools.util.galaxyops import * | |
| 16 | |
| 17 assert sys.version_info[:2] >= ( 2, 4 ) | |
| 18 | |
| 19 def main(): | |
| 20 upstream_pad = 0 | |
| 21 downstream_pad = 0 | |
| 22 | |
| 23 options, args = doc_optparse.parse( __doc__ ) | |
| 24 try: | |
| 25 chr_col_1, start_col_1, end_col_1, strand_col_1 = parse_cols_arg( options.cols1 ) | |
| 26 in_fname, out_fname = args | |
| 27 except: | |
| 28 doc_optparse.exception() | |
| 29 | |
| 30 g1 = NiceReaderWrapper( fileinput.FileInput( in_fname ), | |
| 31 chrom_col=chr_col_1, | |
| 32 start_col=start_col_1, | |
| 33 end_col=end_col_1, | |
| 34 strand_col = strand_col_1, | |
| 35 fix_strand=True ) | |
| 36 | |
| 37 try: | |
| 38 bases = base_coverage(g1) | |
| 39 except ParseError, exc: | |
| 40 fail( "Invalid file format: %s" % str( exc ) ) | |
| 41 out_file = open( out_fname, "w" ) | |
| 42 out_file.write( "%s\n" % str( bases ) ) | |
| 43 out_file.close() | |
| 44 if g1.skipped > 0: | |
| 45 print skipped( g1, filedesc="" ) | |
| 46 | |
| 47 if __name__ == "__main__": | |
| 48 main() |
