changeset 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 63c7d7ba4d52
files find_str.py microsatbed.xml
diffstat 2 files changed, 17 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/find_str.py	Fri Jul 19 06:41:18 2024 +0000
+++ b/find_str.py	Fri Jul 19 22:20:43 2024 +0000
@@ -1,5 +1,6 @@
 import argparse
 import shutil
+import subprocess
 
 import pybigtools
 import pytrf  # 1.3.0
@@ -19,9 +20,9 @@
         bin = int(b[1] / winwidth)
         d[bin] += nt
     dw = [
-        (name, (x * winwidth)+1, (x + 1) * winwidth, float(d[x]))
+        (name, (x * winwidth), ((x + 1) * winwidth) - 1, float(d[x]))
         for x in range(nwin + 1)
-        if  (x + 1) * winwidth <= chrlen - 1
+        if (x + 1) * winwidth <= chrlen
     ]
     return dw
 
@@ -78,14 +79,23 @@
                 cbed.append(row)
             elif args.hexa and len(ssr.motif) == 6:
                 cbed.append(row)
-        bed += cbed
         if args.bigwig:
             w = getDensity(name, cbed, chrlen, args.winwidth)
             wig += w
+        bed += cbed
     if args.bigwig:
         wig.sort()
-        bw = pybigtools.open("temp.bw", "w")
-        bw.write(chrlens, wig)
+        bedg = ['%s %d %d %.3f' % x for x in wig]
+        # bedg.insert(0,'track type=bedGraph') https://genomebrowser.wustl.edu/goldenPath/help/bigWig.html
+        with open("temp.bedg", "w") as bw:
+            bw.write('\n'.join(bedg))
+        chroms = ["%s\t%s" % (x, chrlens[x]) for x in chrlens.keys()]
+        with open("temp.chromlen", "w") as cl:
+            cl.write('\n'.join(chroms))
+        cmd = ["bedGraphToBigWig", "temp.bedg", "temp.chromlen", "temp.bw" ]
+        subprocess.run(cmd)
+        #bw = pybigtools.open("temp.bw", "w")
+        #bw.write(chrlens, wig)
         shutil.move("temp.bw", args.bed)
     else:
         bed.sort()
--- a/microsatbed.xml	Fri Jul 19 06:41:18 2024 +0000
+++ b/microsatbed.xml	Fri Jul 19 22:20:43 2024 +0000
@@ -5,6 +5,8 @@
     <requirement version="2.1.0" type="package">pyfastx</requirement>
     <requirement version="1.3.2" type="package">pytrf</requirement>
     <requirement version="0.2.0" type="package">pybigtools</requirement>
+    <requirement version="455" type="package">ucsc-bedgraphtobigwig</requirement>
+     
   </requirements>
    <required_files>
       <include path="find_str.py"/>