Mercurial > repos > iuc > bigwig_outlier_bed
comparison 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 |
comparison
equal
deleted
inserted
replaced
2:61946b8bd43b | 3:00b3da7776a0 |
---|---|
144 if isTop: | 144 if isTop: |
145 bwex = np.r_[False, bw >= self.bwtop, False] # extend with 0s | 145 bwex = np.r_[False, bw >= self.bwtop, False] # extend with 0s |
146 else: | 146 else: |
147 bwex = np.r_[False, bw <= self.bwbot, False] | 147 bwex = np.r_[False, bw <= self.bwbot, False] |
148 bwexd = np.diff(bwex) | 148 bwexd = np.diff(bwex) |
149 bwexdnz = bwexd.nonzero()[0] | 149 bwexdnz = bwexd.nonzero()[0] # start and end transition of each segment - nice! |
150 bwregions = np.reshape(bwexdnz, (-1, 2)) | 150 bwregions = np.reshape(bwexdnz, (-1, 2)) |
151 return bwregions | 151 return bwregions |
152 | 152 |
153 def writeBed(self, bed, bedfname): | 153 def writeBed(self, bed, bedfname): |
154 """ | 154 """ |
155 potentially multiple | 155 potentially multiple |
156 """ | 156 """ |
157 bed.sort() | 157 bed.sort() |
158 beds = ["%s\t%d\t%d\t%s\t%d" % x for x in bed] | |
159 with open(bedfname, "w") as bedf: | 158 with open(bedfname, "w") as bedf: |
160 bedf.write("\n".join(beds)) | 159 for b in bed: |
161 bedf.write("\n") | 160 bedf.write("%s\t%d\t%d\t%s\t%d\n" % b) |
162 | 161 |
163 def makeTableRow(self, bw, bwlabel, chr): | 162 def makeTableRow(self, bw, bwlabel, chr): |
164 """ | 163 """ |
165 called for every contig, but messy inline | 164 called for every contig, but messy inline |
166 """ | 165 """ |
192 bedhi = [] | 191 bedhi = [] |
193 bedlo = [] | 192 bedlo = [] |
194 restab = [] | 193 restab = [] |
195 bwlabels = self.bwlabels | 194 bwlabels = self.bwlabels |
196 bwnames = self.bwnames | 195 bwnames = self.bwnames |
197 bwnames.sort() | |
198 reshead = "bigwig\tcontig\tn\tmean\tstd\tmin\tmax\tqtop\tqbot" | 196 reshead = "bigwig\tcontig\tn\tmean\tstd\tmin\tmax\tqtop\tqbot" |
199 for i, bwname in enumerate(bwnames): | 197 for i, bwname in enumerate(bwnames): |
200 bwlabel = bwlabels[i].replace(" ", "") | 198 bwlabel = bwlabels[i].replace(" ", "") |
201 fakepath = "in%d.bw" % i | 199 fakepath = "in%d.bw" % i |
202 if os.path.isfile(fakepath): | 200 if os.path.isfile(fakepath): |
249 ) | 247 ) |
250 if self.qlo is not None: | 248 if self.qlo is not None: |
251 self.bwbot = np.quantile(bw, self.qlo) | 249 self.bwbot = np.quantile(bw, self.qlo) |
252 bwlo = self.processVals(bw, isTop=False) | 250 bwlo = self.processVals(bw, isTop=False) |
253 for j, seg in enumerate(bwlo): | 251 for j, seg in enumerate(bwlo): |
252 seglen = seg[1] - seg[0] | |
254 if seg[1] - seg[0] >= self.bedwin: | 253 if seg[1] - seg[0] >= self.bedwin: |
255 score = -1 * np.sum(bw[seg[0]:seg[1]]) / float(seglen) | 254 score = ( |
255 -1 * np.sum(bw[seg[0]:seg[1]]) / float(seglen) | |
256 ) | |
256 bedlo.append( | 257 bedlo.append( |
257 ( | 258 ( |
258 chr, | 259 chr, |
259 seg[0], | 260 seg[0], |
260 seg[1], | 261 seg[1], |