comparison tools/new_operations/gops_basecoverage.py @ 0:9071e359b9a3

Uploaded
author xuebing
date Fri, 09 Mar 2012 19:37:19 -0500
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:9071e359b9a3
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 from galaxy import eggs
9 import pkg_resources
10 pkg_resources.require( "bx-python" )
11 import sys, traceback, fileinput
12 from warnings import warn
13 from bx.intervals import *
14 from bx.intervals.io import *
15 from bx.intervals.operations.base_coverage import *
16 from bx.cookbook import doc_optparse
17 from galaxy.tools.util.galaxyops import *
18
19 assert sys.version_info[:2] >= ( 2, 4 )
20
21 def main():
22 upstream_pad = 0
23 downstream_pad = 0
24
25 options, args = doc_optparse.parse( __doc__ )
26 try:
27 chr_col_1, start_col_1, end_col_1, strand_col_1 = parse_cols_arg( options.cols1 )
28 in_fname, out_fname = args
29 except:
30 doc_optparse.exception()
31
32 g1 = NiceReaderWrapper( fileinput.FileInput( in_fname ),
33 chrom_col=chr_col_1,
34 start_col=start_col_1,
35 end_col=end_col_1,
36 strand_col = strand_col_1,
37 fix_strand=True )
38
39 try:
40 bases = base_coverage(g1)
41 except ParseError, exc:
42 fail( "Invalid file format: %s" % str( exc ) )
43 out_file = open( out_fname, "w" )
44 out_file.write( "%s\n" % str( bases ) )
45 out_file.close()
46 if g1.skipped > 0:
47 print skipped( g1, filedesc="" )
48
49 if __name__ == "__main__":
50 main()