0
|
1 #!/usr/bin/env python
|
|
2
|
|
3 """
|
|
4 Read a wiggle track and print out a series of lines containing
|
|
5 "chrom position score". Ignores track lines, handles bed, variableStep
|
|
6 and fixedStep wiggle lines.
|
|
7 """
|
|
8 import sys
|
|
9 from galaxy import eggs
|
|
10 import pkg_resources; pkg_resources.require( "bx-python" )
|
|
11 import bx.wiggle
|
|
12 from galaxy.tools.exception_handling import *
|
|
13
|
|
14 def stop_err( msg ):
|
|
15 sys.stderr.write( msg )
|
|
16 sys.exit()
|
|
17
|
|
18 def main():
|
|
19 if len( sys.argv ) > 1:
|
|
20 in_file = open( sys.argv[1] )
|
|
21 else:
|
|
22 in_file = open( sys.stdin )
|
|
23
|
|
24 if len( sys.argv ) > 2:
|
|
25 out_file = open( sys.argv[2], "w" )
|
|
26 else:
|
|
27 out_file = sys.stdout
|
|
28
|
|
29 try:
|
|
30 for fields in bx.wiggle.IntervalReader( UCSCOutWrapper( in_file ) ):
|
|
31 out_file.write( "%s\n" % "\t".join( map( str, fields ) ) )
|
|
32 except UCSCLimitException:
|
|
33 # Wiggle data was truncated, at the very least need to warn the user.
|
|
34 print 'Encountered message from UCSC: "Reached output limit of 100000 data values", so be aware your data was truncated.'
|
|
35 except ValueError, e:
|
|
36 in_file.close()
|
|
37 out_file.close()
|
|
38 stop_err( str( e ) )
|
|
39
|
|
40 in_file.close()
|
|
41 out_file.close()
|
|
42
|
|
43 if __name__ == "__main__": main()
|