annotate bigwigtobed.python.txt @ 0:c71db540eb38 draft

planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
author fubar
date Mon, 01 Jul 2024 02:48:46 +0000
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
1 #raw
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
2 """
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
3 Ross Lazarus June 2024 for VGP
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
4 Bigwigs are great, but hard to reliably "see" small low coverage or small very high coverage regions.
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
5 Colouring in JB2 tracks will need a new plugin, so this code will find bigwig regions above and below a chosen percentile point.
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
6 0.99 and 0.01 work well in testing with a minimum span of 10 bp.
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
7 Multiple bigwigs **with the same reference** can be combined - bed segments will be named appropriately
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
8 Combining multiple references works but is silly because only display will rely on one reference so others will not be shown...
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
9 Tricksy numpy method from http://gregoryzynda.com/python/numpy/contiguous/interval/2019/11/29/contiguous-regions.html
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
10 takes about 95 seconds for a 17MB test wiggle
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
11 JBrowse2 bed normally displays ignore the score, so could provide separate low/high bed file outputs as an option.
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
12 Update june 30 2024: wrote a 'no-build' plugin for beds to display red/blue if >0/<0 so those are used for scores
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
13 Bed interval naming must be short for JB2 but needs input bigwig name and (lo or hi).
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
14 """
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
15 import argparse
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
16 import numpy as np
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
17 import pybigtools
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
18 import sys
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
19 from pathlib import Path
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
20 class findOut():
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
21 def __init__(self, args):
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
22 self.bwnames=args.bigwig
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
23 self.bwlabels=args.bigwiglabels
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
24 self.bedwin=args.minwin
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
25 self.qlo=args.qlo
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
26 self.qhi=args.qhi
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
27 self.bedouthilo=args.bedouthilo
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
28 self.bedouthi=args.bedouthi
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
29 self.bedoutlo=args.bedoutlo
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
30 self.tableout = args.tableout
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
31 self.bedwin = args.minwin
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
32 self.qhi = args.qhi
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
33 self.qlo = args.qlo
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
34 self.makeBed()
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
35 def processVals(self, bw, isTop):
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
36 # http://gregoryzynda.com/python/numpy/contiguous/interval/2019/11/29/contiguous-regions.html
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
37 if isTop:
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
38 bwex = np.r_[False, bw >= self.bwtop, False] # extend with 0s
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
39 else:
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
40 bwex = np.r_[False, bw <= self.bwbot, False]
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
41 bwexd = np.diff(bwex)
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
42 bwexdnz = bwexd.nonzero()[0]
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
43 bwregions = np.reshape(bwexdnz, (-1,2))
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
44 return bwregions
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
45 def writeBed(self, bed, bedfname):
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
46 """
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
47 potentially multiple
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
48 """
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
49 bed.sort()
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
50 beds = ['%s\t%d\t%d\t%s\t%d' % x for x in bed]
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
51 with open(bedfname, "w") as bedf:
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
52 bedf.write('\n'.join(beds))
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
53 bedf.write('\n')
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
54 print('Wrote %d bed regions to %s' % (len(bed), bedfname))
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
55 def makeBed(self):
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
56 bedhi = []
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
57 bedlo = []
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
58 bwlabels = self.bwlabels
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
59 bwnames = self.bwnames
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
60 print('bwnames=', bwnames, "bwlabs=", bwlabels)
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
61 for i, bwname in enumerate(bwnames):
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
62 bwlabel = bwlabels[i].replace(" ",'')
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
63 p = Path('in.bw')
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
64 p.symlink_to( bwname ) # required by pybigtools (!)
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
65 bwf = pybigtools.open('in.bw')
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
66 chrlist = bwf.chroms()
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
67 chrs = list(chrlist.keys())
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
68 chrs.sort()
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
69 restab = ["contig\tn\tmean\tstd\tmin\tmax\tqtop\tqbot"]
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
70 for chr in chrs:
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
71 bw = bwf.values(chr)
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
72 bw = bw[~np.isnan(bw)] # some have NaN if parts of a contig not covered
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
73 if self.qhi is not None:
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
74 self.bwtop = np.quantile(bw, self.qhi)
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
75 bwhi = self.processVals(bw, isTop=True)
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
76 for i, seg in enumerate(bwhi):
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
77 if seg[1] - seg[0] >= self.bedwin:
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
78 bedhi.append((chr, seg[0], seg[1], '%s_hi' % (bwlabel), 1))
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
79 if self.qlo is not None:
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
80 self.bwbot = np.quantile(bw, self.qlo)
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
81 bwlo = self.processVals(bw, isTop=False)
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
82 for i, seg in enumerate(bwlo):
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
83 if seg[1] - seg[0] >= self.bedwin:
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
84 bedlo.append((chr, seg[0], seg[1], '%s_lo' % (bwlabel), -1))
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
85 bwmean = np.mean(bw)
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
86 bwstd = np.std(bw)
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
87 bwmax = np.max(bw)
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
88 nrow = np.size(bw)
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
89 bwmin = np.min(bw)
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
90 restab.append('%s\t%d\t%f\t%f\t%f\t%f\t%f\t%f' % (chr,nrow,bwmean,bwstd,bwmin,bwmax,self.bwtop,self.bwbot))
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
91 print('\n'.join(restab), '\n')
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
92 if self.tableout:
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
93 with open(self.tableout) as t:
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
94 t.write('\n'.join(restab))
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
95 t.write('\n')
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
96 if self.bedoutlo:
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
97 if self.qlo:
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
98 self.writeBed(bedlo, self.bedoutlo)
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
99 if self.bedouthi:
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
100 if self.qhi:
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
101 self.writeBed(bedhi, self.bedouthi)
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
102 if self.bedouthilo:
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
103 allbed = bedlo + bedhi
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
104 self.writeBed(allbed, self.bedouthilo)
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
105 return restab
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
106 if __name__ == "__main__":
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
107 parser = argparse.ArgumentParser()
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
108 a = parser.add_argument
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
109 a('-m', '--minwin',default=10, type=int)
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
110 a('-l', '--qlo',default=None, type=float)
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
111 a('-i', '--qhi',default=None, type=float)
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
112 a('-w', '--bigwig', nargs='+')
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
113 a('-n', '--bigwiglabels', nargs='+')
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
114 a('-o', '--bedouthilo', default=None, help="optional high and low combined bed")
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
115 a('-u', '--bedouthi', default=None, help="optional high only bed")
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
116 a('-b', '--bedoutlo', default=None, help="optional low only bed")
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
117 a('-t', '--tableout', default=None)
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
118 args = parser.parse_args()
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
119 print('args=', args)
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
120 if not (args.bedouthilo or args.bedouthi or args.bedoutlo):
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
121 sys.stderr.write("bigwig_outlier_bed.py cannot usefully run - need a bed output choice - must be one of low only, high only or both combined")
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
122 sys.exit(2)
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
123 if not (args.qlo or args.qhi):
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
124 sys.stderr.write("bigwig_outlier_bed.py cannot usefully run - need one or both of quantile cutpoints qhi and qlo")
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
125 sys.exit(2)
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
126 restab = findOut(args)
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
127 if args.tableout:
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
128 with open(args.tableout, 'w') as tout:
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
129 tout.write('\n'.join(restab))
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
130 tout.write('\n')
c71db540eb38 planemo upload for repository https://github.com/jackh726/bigtools commit ce6b9f638ebcebcad5a5b10219f252962f30e5cc-dirty
fubar
parents:
diff changeset
131 #end raw