root/galaxy-central/tools/stats/wiggle_to_simple.py @ 3

リビジョン 2, 1.2 KB (コミッタ: hatakeyama, 14 年 前)

import galaxy-central

  • 属性 svn:executable の設定値 *
行番号 
1#!/usr/bin/env python
2
3"""
4Read a wiggle track and print out a series of lines containing
5"chrom position score". Ignores track lines, handles bed, variableStep
6and fixedStep wiggle lines.
7"""
8import sys
9from galaxy import eggs
10import pkg_resources; pkg_resources.require( "bx-python" )
11import bx.wiggle
12from galaxy.tools.exception_handling import *
13
14def stop_err( msg ):
15    sys.stderr.write( msg )
16    sys.exit()
17
18def 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
43if __name__ == "__main__": main()
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。