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 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
|
#!/usr/bin/python3
"""
Convert wiggle data to a binned array. This assumes the input data is on a
single chromosome and does no sanity checks!
usage: %prog score_file out_file < wiggle_data
-c, --comp=type: compression type (none, zlib, lzo)
"""
import bx.wiggle
from bx import misc
from bx.binned_array import BinnedArray
from bx.cookbook import doc_optparse
def main():
# Parse command line
options, args = doc_optparse.parse(__doc__)
try:
if options.comp:
comp_type = options.comp
else:
comp_type = None
score_fname = args[0]
out_fname = args[1]
except Exception:
doc_optparse.exit()
scores = BinnedArray()
for i, (chrom, pos, val) in enumerate(bx.wiggle.Reader(misc.open_compressed(score_fname))):
# if last_chrom is None:
# last_chrom = chrom
# else:
# assert chrom == last_chrom, "This script expects a 'wiggle' input on only one chromosome"
scores[pos] = val
# Status
if i % 10000 == 0:
print(i, "scores processed")
out = open(out_fname, "w")
if comp_type:
scores.to_file(out, comp_type=comp_type)
else:
scores.to_file(out)
out.close()
if __name__ == "__main__":
main()
|