comparison bigwig_outlier_bed.py @ 1:8377a6abb4da draft

planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 92ffe42a6ad6e81f3f157bbc9b942c000d450416
author iuc
date Sun, 21 Jul 2024 11:03:36 +0000
parents ebcd48f183b3
children 61946b8bd43b
comparison
equal deleted inserted replaced
0:ebcd48f183b3 1:8377a6abb4da
26 26
27 def __init__(self, args): 27 def __init__(self, args):
28 self.bwnames = args.bigwig 28 self.bwnames = args.bigwig
29 self.bwlabels = args.bigwiglabels 29 self.bwlabels = args.bigwiglabels
30 self.bedwin = args.minwin 30 self.bedwin = args.minwin
31 self.qlo = args.qlo
32 self.qhi = args.qhi
33 self.outbeds = args.outbeds 31 self.outbeds = args.outbeds
34 self.bedouthi = args.bedouthi 32 self.bedouthi = args.bedouthi
35 self.bedoutlo = args.bedoutlo 33 self.bedoutlo = args.bedoutlo
36 self.bedouthilo = args.bedouthilo 34 self.bedouthilo = args.bedouthilo
37 self.tableoutfile = args.tableoutfile 35 self.tableoutfile = args.tableoutfile
38 self.bedwin = args.minwin 36 self.bedwin = args.minwin
39 self.qhi = args.qhi 37 self.qhi = args.qhi
40 self.qlo = args.qlo 38 self.qlo = None
39 try:
40 f = float(args.qlo)
41 self.qlo = f
42 except Exception as e:
43 s = str(e)
44 print(s, ' qlo=', args.qlo)
41 nbw = len(args.bigwig) 45 nbw = len(args.bigwig)
42 nlab = len(args.bigwiglabels) 46 nlab = len(args.bigwiglabels)
43 if nlab < nbw: 47 if nlab < nbw:
44 self.bwlabels += ["Nolabel"] * (nbw - nlab) 48 self.bwlabels += ["Nolabel"] * (nbw - nlab)
45 self.makeBed() 49 self.makeBed()
88 bwstd, 92 bwstd,
89 bwmin, 93 bwmin,
90 bwmax, 94 bwmax,
91 ) 95 )
92 if self.qhi is not None: 96 if self.qhi is not None:
93 row += "\t%f" % self.bwtop 97 row += "\t%.2f" % self.bwtop
94 else: 98 else:
95 row += "\t" 99 row += "\tnoqhi"
96 if self.qlo is not None: 100 if self.qlo is not None:
97 row += "\t%f" % self.bwbot 101 row += "\t%.2f" % self.bwbot
98 else: 102 else:
99 row += "\t" 103 row += "\tnoqlo"
100 return row 104 return row
101 105
102 def makeBed(self): 106 def makeBed(self):
103 bedhi = [] 107 bedhi = []
104 bedlo = [] 108 bedlo = []
123 if self.qhi is not None: 127 if self.qhi is not None:
124 self.bwtop = np.quantile(bw, self.qhi) 128 self.bwtop = np.quantile(bw, self.qhi)
125 bwhi = self.processVals(bw, isTop=True) 129 bwhi = self.processVals(bw, isTop=True)
126 for j, seg in enumerate(bwhi): 130 for j, seg in enumerate(bwhi):
127 if seg[1] - seg[0] >= self.bedwin: 131 if seg[1] - seg[0] >= self.bedwin:
128 bedhi.append((chr, seg[0], seg[1], "%s_hi" % (bwlabel), 1)) 132 score = np.sum(bw[seg[0]:seg[1]])
133 bedhi.append(
134 (
135 chr,
136 seg[0],
137 seg[1],
138 "%s_%d" % (bwlabel, score),
139 score,
140 )
141 )
129 if self.qlo is not None: 142 if self.qlo is not None:
130 self.bwbot = np.quantile(bw, self.qlo) 143 self.bwbot = np.quantile(bw, self.qlo)
131 bwlo = self.processVals(bw, isTop=False) 144 bwlo = self.processVals(bw, isTop=False)
132 for j, seg in enumerate(bwlo): 145 for j, seg in enumerate(bwlo):
133 if seg[1] - seg[0] >= self.bedwin: 146 if seg[1] - seg[0] >= self.bedwin:
134 bedlo.append((chr, seg[0], seg[1], "%s_lo" % (bwlabel), -1)) 147 score = -1 * np.sum(bw[seg[0]:seg[1]])
148 bedlo.append(
149 (
150 chr,
151 seg[0],
152 seg[1],
153 "%s_%d" % (bwlabel, score),
154 score,
155 )
156 )
135 if self.tableoutfile: 157 if self.tableoutfile:
136 row = self.makeTableRow(bw, bwlabel, chr) 158 row = self.makeTableRow(bw, bwlabel, chr)
137 restab.append(copy.copy(row)) 159 restab.append(copy.copy(row))
138 if self.tableoutfile: 160 if self.tableoutfile:
139 stable = "\n".join(restab) 161 stable = "\n".join(restab)
162 184
163 if __name__ == "__main__": 185 if __name__ == "__main__":
164 parser = argparse.ArgumentParser() 186 parser = argparse.ArgumentParser()
165 a = parser.add_argument 187 a = parser.add_argument
166 a("-m", "--minwin", default=10, type=int) 188 a("-m", "--minwin", default=10, type=int)
167 a("-l", "--qlo", default=None, type=float) 189 a("-l", "--qlo", default=None)
168 a("-i", "--qhi", default=None, type=float) 190 a("-i", "--qhi", default=None, type=float)
169 a("--bedouthi", default=None) 191 a("--bedouthi", default=None)
170 a("--bedoutlo", default=None) 192 a("--bedoutlo", default=None)
171 a("--bedouthilo", default=None) 193 a("--bedouthilo", default=None)
172 a("-w", "--bigwig", nargs="+") 194 a("-w", "--bigwig", nargs="+")