PageRenderTime 31ms CodeModel.GetById 14ms app.highlight 11ms RepoModel.GetById 1ms app.codeStats 1ms

/tools/new_operations/gops_basecoverage.py

https://bitbucket.org/cistrome/cistrome-harvard/
Python | 50 lines | 38 code | 5 blank | 7 comment | 1 complexity | 7ea5e5903f2d98a20a72d25e3e5a2576 MD5 | raw file
 1#!/usr/bin/env python
 2"""
 3Count total base coverage.
 4
 5usage: %prog in_file out_file
 6    -1, --cols1=N,N,N,N: Columns for start, end, strand in first file
 7"""
 8from galaxy import eggs
 9import pkg_resources
10pkg_resources.require( "bx-python" )
11import sys, traceback, fileinput
12from warnings import warn
13from bx.intervals import *
14from bx.intervals.io import *
15from bx.intervals.operations.base_coverage import *
16from bx.cookbook import doc_optparse
17from galaxy.tools.util.galaxyops import *
18
19assert sys.version_info[:2] >= ( 2, 4 )
20
21def 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
49if __name__ == "__main__":
50    main()