File: wiggle_to_chr_binned_array.py

package info (click to toggle)
python-bx 0.13.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 5,000 kB
  • sloc: python: 17,136; ansic: 2,326; makefile: 24; sh: 8
file content (36 lines) | stat: -rwxr-xr-x 736 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/python3

"""
Writes compressed data from a wiggle file by chromosome.

usage: %prog score_file < wiggle_data
"""

import sys

import bx.wiggle
from bx.binned_array import BinnedArray
from bx.cookbook import doc_optparse


def main():
    options, args = doc_optparse.parse(__doc__)

    scores = {}
    for i, (chrom, pos, val) in enumerate(bx.wiggle.Reader(open(sys.argv[1]))):
        if chrom not in scores:
            scores[chrom] = BinnedArray()
        scores[chrom][pos] = val

        # Status
        if i % 10000 == 0:
            print(i, "scores processed")

    for chr in scores.keys():
        out = open(chr, "w")
        scores[chr].to_file(out)
        out.close()


if __name__ == "__main__":
    main()