Mercurial > repos > fubar > microsatbed
comparison find_str.py @ 26:26e9575c2c83 draft
planemo upload for repository https://github.com/fubar2/microsatbed commit d952bc313f408735456747c3d33e09a3170c8f59-dirty
author | fubar |
---|---|
date | Fri, 19 Jul 2024 22:20:43 +0000 |
parents | 8d0b8a75350f |
children | efc775ab30fe |
comparison
equal
deleted
inserted
replaced
25:8d0b8a75350f | 26:26e9575c2c83 |
---|---|
1 import argparse | 1 import argparse |
2 import shutil | 2 import shutil |
3 import subprocess | |
3 | 4 |
4 import pybigtools | 5 import pybigtools |
5 import pytrf # 1.3.0 | 6 import pytrf # 1.3.0 |
6 from pyfastx import Fastx # 0.5.2 | 7 from pyfastx import Fastx # 0.5.2 |
7 | 8 |
17 for b in bed: | 18 for b in bed: |
18 nt = b[5] | 19 nt = b[5] |
19 bin = int(b[1] / winwidth) | 20 bin = int(b[1] / winwidth) |
20 d[bin] += nt | 21 d[bin] += nt |
21 dw = [ | 22 dw = [ |
22 (name, (x * winwidth)+1, (x + 1) * winwidth, float(d[x])) | 23 (name, (x * winwidth), ((x + 1) * winwidth) - 1, float(d[x])) |
23 for x in range(nwin + 1) | 24 for x in range(nwin + 1) |
24 if (x + 1) * winwidth <= chrlen - 1 | 25 if (x + 1) * winwidth <= chrlen |
25 ] | 26 ] |
26 return dw | 27 return dw |
27 | 28 |
28 | 29 |
29 def write_ssrs(args): | 30 def write_ssrs(args): |
76 cbed.append(row) | 77 cbed.append(row) |
77 elif args.penta and len(ssr.motif) == 5: | 78 elif args.penta and len(ssr.motif) == 5: |
78 cbed.append(row) | 79 cbed.append(row) |
79 elif args.hexa and len(ssr.motif) == 6: | 80 elif args.hexa and len(ssr.motif) == 6: |
80 cbed.append(row) | 81 cbed.append(row) |
81 bed += cbed | |
82 if args.bigwig: | 82 if args.bigwig: |
83 w = getDensity(name, cbed, chrlen, args.winwidth) | 83 w = getDensity(name, cbed, chrlen, args.winwidth) |
84 wig += w | 84 wig += w |
85 bed += cbed | |
85 if args.bigwig: | 86 if args.bigwig: |
86 wig.sort() | 87 wig.sort() |
87 bw = pybigtools.open("temp.bw", "w") | 88 bedg = ['%s %d %d %.3f' % x for x in wig] |
88 bw.write(chrlens, wig) | 89 # bedg.insert(0,'track type=bedGraph') https://genomebrowser.wustl.edu/goldenPath/help/bigWig.html |
90 with open("temp.bedg", "w") as bw: | |
91 bw.write('\n'.join(bedg)) | |
92 chroms = ["%s\t%s" % (x, chrlens[x]) for x in chrlens.keys()] | |
93 with open("temp.chromlen", "w") as cl: | |
94 cl.write('\n'.join(chroms)) | |
95 cmd = ["bedGraphToBigWig", "temp.bedg", "temp.chromlen", "temp.bw" ] | |
96 subprocess.run(cmd) | |
97 #bw = pybigtools.open("temp.bw", "w") | |
98 #bw.write(chrlens, wig) | |
89 shutil.move("temp.bw", args.bed) | 99 shutil.move("temp.bw", args.bed) |
90 else: | 100 else: |
91 bed.sort() | 101 bed.sort() |
92 obed = ["%s\t%d\t%d\t%s_%d\t%d" % x for x in bed] | 102 obed = ["%s\t%d\t%d\t%s_%d\t%d" % x for x in bed] |
93 with open(args.bed, "w") as outbed: | 103 with open(args.bed, "w") as outbed: |