root/galaxy-central/eggs/bx_python-0.5.0_dev_f74aec067563-py2.6-macosx-10.6-universal-ucs2.egg/EGG-INFO/scripts/wiggle_to_binned_array.py @ 3

リビジョン 3, 1.4 KB (コミッタ: kohda, 14 年 前)

Install Unix tools  http://hannonlab.cshl.edu/galaxy_unix_tools/galaxy.html

行番号 
1#!/usr/bin/python2.6
2
3"""
4Convert wiggle data to a binned array. This assumes the input data is on a
5single chromosome and does no sanity checks!
6
7usage: %prog score_file out_file < wiggle_data
8    -c, --comp=type: compression type (none, zlib, lzo)
9"""
10
11from __future__ import division
12
13import sys
14import psyco_full
15import bx.wiggle
16from bx.binned_array import BinnedArray
17from bx_extras.fpconst import isNaN
18from bx.cookbook import doc_optparse
19from bx import misc
20
21def main():
22   
23    # Parse command line
24    options, args = doc_optparse.parse( __doc__ )
25    try:
26        if options.comp:
27            comp_type = options.comp
28        else:
29            comp_type = None
30        score_fname = args[0]
31        out_fname = args[1]
32    except:
33        doc_optparse.exit()
34
35    scores = BinnedArray()
36
37    ## last_chrom = None
38    for i, ( chrom, pos, val ) in enumerate( bx.wiggle.Reader( misc.open_compressed( score_fname ) ) ):
39        #if last_chrom is None:
40        #    last_chrom = chrom
41        #else:
42        #    assert chrom == last_chrom, "This script expects a 'wiggle' input on only one chromosome"
43        scores[pos] = val
44        # Status
45        if i % 10000 == 0: print i, "scores processed"
46
47    out = open( out_fname, "w" )
48    if comp_type:
49        scores.to_file( out, comp_type=comp_type )
50    else:   
51        scores.to_file( out )
52    out.close()
53
54if __name__ == "__main__": main()
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。