diff bigwig_outlier_bed.py @ 3:00b3da7776a0 draft

planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 06c54e8066ecbc6292167e7c5bdfb8af945a41ba
author iuc
date Sun, 15 Sep 2024 17:08:45 +0000
parents 61946b8bd43b
children 2488bcddaf14
line wrap: on
line diff
--- a/bigwig_outlier_bed.py	Thu Jul 25 14:38:34 2024 +0000
+++ b/bigwig_outlier_bed.py	Sun Sep 15 17:08:45 2024 +0000
@@ -146,7 +146,7 @@
         else:
             bwex = np.r_[False, bw <= self.bwbot, False]
         bwexd = np.diff(bwex)
-        bwexdnz = bwexd.nonzero()[0]
+        bwexdnz = bwexd.nonzero()[0]  # start and end transition of each segment - nice!
         bwregions = np.reshape(bwexdnz, (-1, 2))
         return bwregions
 
@@ -155,10 +155,9 @@
         potentially multiple
         """
         bed.sort()
-        beds = ["%s\t%d\t%d\t%s\t%d" % x for x in bed]
         with open(bedfname, "w") as bedf:
-            bedf.write("\n".join(beds))
-            bedf.write("\n")
+            for b in bed:
+                bedf.write("%s\t%d\t%d\t%s\t%d\n" % b)
 
     def makeTableRow(self, bw, bwlabel, chr):
         """
@@ -194,7 +193,6 @@
         restab = []
         bwlabels = self.bwlabels
         bwnames = self.bwnames
-        bwnames.sort()
         reshead = "bigwig\tcontig\tn\tmean\tstd\tmin\tmax\tqtop\tqbot"
         for i, bwname in enumerate(bwnames):
             bwlabel = bwlabels[i].replace(" ", "")
@@ -251,8 +249,11 @@
                     self.bwbot = np.quantile(bw, self.qlo)
                     bwlo = self.processVals(bw, isTop=False)
                     for j, seg in enumerate(bwlo):
+                        seglen = seg[1] - seg[0]
                         if seg[1] - seg[0] >= self.bedwin:
-                            score = -1 * np.sum(bw[seg[0]:seg[1]]) / float(seglen)
+                            score = (
+                                -1 * np.sum(bw[seg[0]:seg[1]]) / float(seglen)
+                            )
                             bedlo.append(
                                 (
                                     chr,