1 | #!/usr/bin/python2.6 |
---|
2 | |
---|
3 | """ |
---|
4 | Writes compressed data from a wiggle file by chromosome. |
---|
5 | |
---|
6 | usage: %prog score_file < wiggle_data |
---|
7 | """ |
---|
8 | |
---|
9 | from __future__ import division |
---|
10 | |
---|
11 | import sys |
---|
12 | import psyco_full |
---|
13 | import bx.wiggle |
---|
14 | from bx.binned_array import BinnedArray |
---|
15 | from fpconst import isNaN |
---|
16 | from bx.cookbook import doc_optparse |
---|
17 | from bx import misc |
---|
18 | |
---|
19 | |
---|
20 | def main(): |
---|
21 | |
---|
22 | # Parse command line |
---|
23 | options, args = doc_optparse.parse( __doc__ ) |
---|
24 | try: |
---|
25 | score_fname = args[0] |
---|
26 | except: |
---|
27 | doc_optparse.exit() |
---|
28 | |
---|
29 | scores = {} |
---|
30 | for i, ( chrom, pos, val ) in enumerate( bx.wiggle.Reader( open(sys.argv[1]) ) ): |
---|
31 | if not chrom in scores: scores[ chrom ] = BinnedArray() |
---|
32 | scores[chrom][pos] = val |
---|
33 | |
---|
34 | # Status |
---|
35 | if i % 10000 == 0: print i, "scores processed" |
---|
36 | |
---|
37 | for chr in scores.keys(): |
---|
38 | out = open( chr, "w" ) |
---|
39 | scores[chr].to_file( out ) |
---|
40 | out.close() |
---|
41 | |
---|
42 | if __name__ == "__main__": main() |
---|