1 | #!/usr/bin/python2.6 |
---|
2 | |
---|
3 | """ |
---|
4 | Read data in UCSC wiggle format and write it to an "array tree" file. |
---|
5 | |
---|
6 | usage: %prog array_length output.array_tree < input.wig |
---|
7 | """ |
---|
8 | |
---|
9 | from __future__ import division |
---|
10 | |
---|
11 | import sys |
---|
12 | |
---|
13 | from bx.arrays.array_tree import * |
---|
14 | from bx.arrays.wiggle import WiggleReader |
---|
15 | |
---|
16 | def main(): |
---|
17 | |
---|
18 | sizes_fname = sys.argv[1] |
---|
19 | out_fname = sys.argv[2] |
---|
20 | |
---|
21 | sizes = {} |
---|
22 | for line in open( sizes_fname ): |
---|
23 | fields = line.split() |
---|
24 | sizes[ fields[0] ] = int( fields[1] ) |
---|
25 | |
---|
26 | # Fill array from wiggle |
---|
27 | d = array_tree_dict_from_reader( WiggleReader( sys.stdin ), sizes ) |
---|
28 | |
---|
29 | for value in d.itervalues(): |
---|
30 | value.root.build_summary() |
---|
31 | |
---|
32 | f = open( out_fname, "w" ) |
---|
33 | FileArrayTreeDict.dict_to_file( d, f ) |
---|
34 | f.close() |
---|
35 | |
---|
36 | if __name__ == "__main__": |
---|
37 | main() |
---|