Mercurial > repos > iuc > bigwig_outlier_bed
annotate bigwig_outlier_bed.py @ 2:61946b8bd43b draft
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
| author | iuc |
|---|---|
| date | Thu, 25 Jul 2024 14:38:34 +0000 |
| parents | 8377a6abb4da |
| children | 00b3da7776a0 |
| rev | line source |
|---|---|
|
0
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
1 """ |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
2 Ross Lazarus June 2024 for VGP |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
3 Bigwigs are great, but hard to reliably "see" small low coverage or small very high coverage regions. |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
4 Colouring in JB2 tracks will need a new plugin, so this code will find bigwig regions above and below a chosen percentile point. |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
5 0.99 and 0.01 work well in testing with a minimum span of 10 bp. |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
6 Multiple bigwigs **with the same reference** can be combined - bed segments will be named appropriately |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
7 Combining multiple references works but is silly because only display will rely on one reference so others will not be shown... |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
8 Tricksy numpy method from http://gregoryzynda.com/python/numpy/contiguous/interval/2019/11/29/contiguous-regions.html |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
9 takes about 95 seconds for a 17MB test wiggle |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
10 JBrowse2 bed normally displays ignore the score, so could provide separate low/high bed file outputs as an option. |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
11 Update june 30 2024: wrote a 'no-build' plugin for beds to display red/blue if >0/<0 so those are used for scores |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
12 Bed interval naming must be short for JB2 but needs input bigwig name and (lo or hi). |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
13 """ |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
14 |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
15 import argparse |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
16 import os |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
17 import sys |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
18 from pathlib import Path |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
19 |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
20 import numpy as np |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
21 import pybigtools |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
22 |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
23 |
|
2
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
24 class asciihist: |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
25 |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
26 def __init__( |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
27 self, |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
28 data, |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
29 bins=10, |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
30 minmax=None, |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
31 str_tag="", |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
32 scale_output=80, |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
33 generate_only=True, |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
34 ): |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
35 """ |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
36 https://gist.github.com/bgbg/608d9ef4fd75032731651257fe67fc81 |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
37 Create an ASCII histogram from an interable of numbers. |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
38 Author: Boris Gorelik boris@gorelik.net. based on http://econpy.googlecode.com/svn/trunk/pytrix/pytrix.py |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
39 License: MIT |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
40 """ |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
41 self.data = data |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
42 self.minmax = minmax |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
43 self.str_tag = str_tag |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
44 self.bins = bins |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
45 self.generate_only = generate_only |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
46 self.scale_output = scale_output |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
47 self.itarray = np.asanyarray(self.data) |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
48 if self.minmax == "auto": |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
49 self.minmax = np.percentile(data, [5, 95]) |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
50 if self.minmax[0] == self.minmax[1]: |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
51 # for very ugly distributions |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
52 self.minmax = None |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
53 if self.minmax is not None: |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
54 # discard values that are outside minmax range |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
55 mn = self.minmax[0] |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
56 mx = self.minmax[1] |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
57 self.itarray = self.itarray[self.itarray >= mn] |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
58 self.itarray = self.itarray[self.itarray <= mx] |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
59 |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
60 def draw(self): |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
61 values, counts = np.unique(self.data, return_counts=True) |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
62 if len(values) <= 20: |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
63 self.bins = len(values) |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
64 ret = [] |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
65 if self.itarray.size: |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
66 total = len(self.itarray) |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
67 counts, cutoffs = np.histogram(self.itarray, bins=self.bins) |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
68 cutoffs = cutoffs[1:] |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
69 if self.str_tag: |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
70 self.str_tag = "%s " % self.str_tag |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
71 else: |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
72 self.str_tag = "" |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
73 if self.scale_output is not None: |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
74 scaled_counts = counts.astype(float) / counts.sum() * self.scale_output |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
75 else: |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
76 scaled_counts = counts |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
77 footerbar = "{:s}{:s} |{:s} |".format( |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
78 self.str_tag, |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
79 "-" * 12, |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
80 "-" * 12, |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
81 ) |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
82 if self.minmax is not None: |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
83 ret.append( |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
84 "Trimmed to range (%s - %s)" |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
85 % (str(self.minmax[0]), str(self.minmax[1])) |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
86 ) |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
87 for cutoff, original_count, scaled_count in zip( |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
88 cutoffs, counts, scaled_counts |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
89 ): |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
90 ret.append( |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
91 "{:s}{:>12.2f} |{:>12,d} | {:s}".format( |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
92 self.str_tag, cutoff, original_count, "*" * int(scaled_count) |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
93 ) |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
94 ) |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
95 ret.append(footerbar) |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
96 ret.append("{:s}{:>12s} |{:>12,d} |".format(self.str_tag, "N=", total)) |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
97 ret.append(footerbar) |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
98 ret.append("") |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
99 else: |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
100 ret = [] |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
101 if not self.generate_only: |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
102 for line in ret: |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
103 print(line) |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
104 ret = "\n".join(ret) |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
105 return ret |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
106 |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
107 |
|
0
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
108 class findOut: |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
109 |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
110 def __init__(self, args): |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
111 self.bwnames = args.bigwig |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
112 self.bwlabels = args.bigwiglabels |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
113 self.bedwin = args.minwin |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
114 self.outbeds = args.outbeds |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
115 self.bedouthi = args.bedouthi |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
116 self.bedoutlo = args.bedoutlo |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
117 self.bedouthilo = args.bedouthilo |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
118 self.tableoutfile = args.tableoutfile |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
119 self.bedwin = args.minwin |
|
1
8377a6abb4da
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 92ffe42a6ad6e81f3f157bbc9b942c000d450416
iuc
parents:
0
diff
changeset
|
120 self.qlo = None |
|
2
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
121 self.qhi = None |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
122 if args.outbeds != "outtab": |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
123 self.qhi = args.qhi |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
124 if args.qlo: |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
125 try: |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
126 f = float(args.qlo) |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
127 self.qlo = f |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
128 except Exception: |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
129 print("qlo not provided") |
|
0
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
130 nbw = len(args.bigwig) |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
131 nlab = len(args.bigwiglabels) |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
132 if nlab < nbw: |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
133 self.bwlabels += ["Nolabel"] * (nbw - nlab) |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
134 self.makeBed() |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
135 |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
136 def processVals(self, bw, isTop): |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
137 """ |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
138 idea from http://gregoryzynda.com/python/numpy/contiguous/interval/2019/11/29/contiguous-regions.html |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
139 Fast segmentation into regions by taking np.diff on the boolean array of over (under) cutpoint indicators in bwex. |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
140 This only gives non-zero values at the segment boundaries where there's a change, so those zeros are all removed in bwexdnz |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
141 leaving an array of segment start/end positions. That's twisted around into an array of start/end coordinates. |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
142 Magical. Fast. Could do the same for means or medians over windows for sparse bigwigs like repeat regions. |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
143 """ |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
144 if isTop: |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
145 bwex = np.r_[False, bw >= self.bwtop, False] # extend with 0s |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
146 else: |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
147 bwex = np.r_[False, bw <= self.bwbot, False] |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
148 bwexd = np.diff(bwex) |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
149 bwexdnz = bwexd.nonzero()[0] |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
150 bwregions = np.reshape(bwexdnz, (-1, 2)) |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
151 return bwregions |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
152 |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
153 def writeBed(self, bed, bedfname): |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
154 """ |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
155 potentially multiple |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
156 """ |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
157 bed.sort() |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
158 beds = ["%s\t%d\t%d\t%s\t%d" % x for x in bed] |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
159 with open(bedfname, "w") as bedf: |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
160 bedf.write("\n".join(beds)) |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
161 bedf.write("\n") |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
162 |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
163 def makeTableRow(self, bw, bwlabel, chr): |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
164 """ |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
165 called for every contig, but messy inline |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
166 """ |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
167 bwmean = np.mean(bw) |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
168 bwstd = np.std(bw) |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
169 bwmax = np.max(bw) |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
170 nrow = np.size(bw) |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
171 bwmin = np.min(bw) |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
172 row = "%s\t%s\t%d\t%f\t%f\t%f\t%f" % ( |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
173 bwlabel, |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
174 chr, |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
175 nrow, |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
176 bwmean, |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
177 bwstd, |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
178 bwmin, |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
179 bwmax, |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
180 ) |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
181 if self.qhi is not None: |
|
1
8377a6abb4da
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 92ffe42a6ad6e81f3f157bbc9b942c000d450416
iuc
parents:
0
diff
changeset
|
182 row += "\t%.2f" % self.bwtop |
|
0
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
183 else: |
|
1
8377a6abb4da
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 92ffe42a6ad6e81f3f157bbc9b942c000d450416
iuc
parents:
0
diff
changeset
|
184 row += "\tnoqhi" |
|
0
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
185 if self.qlo is not None: |
|
1
8377a6abb4da
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 92ffe42a6ad6e81f3f157bbc9b942c000d450416
iuc
parents:
0
diff
changeset
|
186 row += "\t%.2f" % self.bwbot |
|
0
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
187 else: |
|
1
8377a6abb4da
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 92ffe42a6ad6e81f3f157bbc9b942c000d450416
iuc
parents:
0
diff
changeset
|
188 row += "\tnoqlo" |
|
0
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
189 return row |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
190 |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
191 def makeBed(self): |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
192 bedhi = [] |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
193 bedlo = [] |
|
2
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
194 restab = [] |
|
0
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
195 bwlabels = self.bwlabels |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
196 bwnames = self.bwnames |
|
2
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
197 bwnames.sort() |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
198 reshead = "bigwig\tcontig\tn\tmean\tstd\tmin\tmax\tqtop\tqbot" |
|
0
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
199 for i, bwname in enumerate(bwnames): |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
200 bwlabel = bwlabels[i].replace(" ", "") |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
201 fakepath = "in%d.bw" % i |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
202 if os.path.isfile(fakepath): |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
203 os.remove(fakepath) |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
204 p = Path(fakepath) |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
205 p.symlink_to(bwname) # required by pybigtools (!) |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
206 bwf = pybigtools.open(fakepath) |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
207 chrlist = bwf.chroms() |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
208 chrs = list(chrlist.keys()) |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
209 for chr in chrs: |
|
2
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
210 first_few = None |
|
0
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
211 bw = bwf.values(chr) |
|
2
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
212 values, counts = np.unique(bw, return_counts=True) |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
213 nvalues = len(values) |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
214 if nvalues <= 20: |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
215 histo = "\n".join( |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
216 [ |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
217 "%s: %f occurs %d times" % (chr, values[x], counts[x]) |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
218 for x in range(len(values)) |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
219 ] |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
220 ) |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
221 else: |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
222 last10 = range(nvalues - 10, nvalues) |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
223 first_few = ["%.2f\t%d" % (values[x], counts[x]) for x in range(10)] |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
224 first_few += ["%.2f\t%d" % (values[x], counts[x]) for x in last10] |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
225 first_few.insert(0, "First/Last 10 value counts\nValue\tCount") |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
226 ha = asciihist(data=bw, bins=20, str_tag="%s_%s" % (bwlabel, chr)) |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
227 histo = ha.draw() |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
228 histo = ( |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
229 "\n".join(first_few) |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
230 + "\nHistogram of %s bigwig values\n" % bwlabel |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
231 + histo |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
232 ) |
|
0
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
233 bw = bw[~np.isnan(bw)] # some have NaN if parts of a contig not covered |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
234 if self.qhi is not None: |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
235 self.bwtop = np.quantile(bw, self.qhi) |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
236 bwhi = self.processVals(bw, isTop=True) |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
237 for j, seg in enumerate(bwhi): |
|
2
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
238 seglen = seg[1] - seg[0] |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
239 if seglen >= self.bedwin: |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
240 score = np.sum(bw[seg[0]:seg[1]]) / float(seglen) |
|
1
8377a6abb4da
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 92ffe42a6ad6e81f3f157bbc9b942c000d450416
iuc
parents:
0
diff
changeset
|
241 bedhi.append( |
|
8377a6abb4da
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 92ffe42a6ad6e81f3f157bbc9b942c000d450416
iuc
parents:
0
diff
changeset
|
242 ( |
|
8377a6abb4da
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 92ffe42a6ad6e81f3f157bbc9b942c000d450416
iuc
parents:
0
diff
changeset
|
243 chr, |
|
8377a6abb4da
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 92ffe42a6ad6e81f3f157bbc9b942c000d450416
iuc
parents:
0
diff
changeset
|
244 seg[0], |
|
8377a6abb4da
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 92ffe42a6ad6e81f3f157bbc9b942c000d450416
iuc
parents:
0
diff
changeset
|
245 seg[1], |
|
8377a6abb4da
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 92ffe42a6ad6e81f3f157bbc9b942c000d450416
iuc
parents:
0
diff
changeset
|
246 "%s_%d" % (bwlabel, score), |
|
8377a6abb4da
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 92ffe42a6ad6e81f3f157bbc9b942c000d450416
iuc
parents:
0
diff
changeset
|
247 score, |
|
8377a6abb4da
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 92ffe42a6ad6e81f3f157bbc9b942c000d450416
iuc
parents:
0
diff
changeset
|
248 ) |
|
8377a6abb4da
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 92ffe42a6ad6e81f3f157bbc9b942c000d450416
iuc
parents:
0
diff
changeset
|
249 ) |
|
0
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
250 if self.qlo is not None: |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
251 self.bwbot = np.quantile(bw, self.qlo) |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
252 bwlo = self.processVals(bw, isTop=False) |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
253 for j, seg in enumerate(bwlo): |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
254 if seg[1] - seg[0] >= self.bedwin: |
|
2
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
255 score = -1 * np.sum(bw[seg[0]:seg[1]]) / float(seglen) |
|
1
8377a6abb4da
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 92ffe42a6ad6e81f3f157bbc9b942c000d450416
iuc
parents:
0
diff
changeset
|
256 bedlo.append( |
|
8377a6abb4da
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 92ffe42a6ad6e81f3f157bbc9b942c000d450416
iuc
parents:
0
diff
changeset
|
257 ( |
|
8377a6abb4da
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 92ffe42a6ad6e81f3f157bbc9b942c000d450416
iuc
parents:
0
diff
changeset
|
258 chr, |
|
8377a6abb4da
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 92ffe42a6ad6e81f3f157bbc9b942c000d450416
iuc
parents:
0
diff
changeset
|
259 seg[0], |
|
8377a6abb4da
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 92ffe42a6ad6e81f3f157bbc9b942c000d450416
iuc
parents:
0
diff
changeset
|
260 seg[1], |
|
8377a6abb4da
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 92ffe42a6ad6e81f3f157bbc9b942c000d450416
iuc
parents:
0
diff
changeset
|
261 "%s_%d" % (bwlabel, score), |
|
8377a6abb4da
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 92ffe42a6ad6e81f3f157bbc9b942c000d450416
iuc
parents:
0
diff
changeset
|
262 score, |
|
8377a6abb4da
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 92ffe42a6ad6e81f3f157bbc9b942c000d450416
iuc
parents:
0
diff
changeset
|
263 ) |
|
8377a6abb4da
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 92ffe42a6ad6e81f3f157bbc9b942c000d450416
iuc
parents:
0
diff
changeset
|
264 ) |
|
0
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
265 if self.tableoutfile: |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
266 row = self.makeTableRow(bw, bwlabel, chr) |
|
2
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
267 resheadl = reshead.split("\t") |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
268 rowl = row.split() |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
269 desc = ["%s\t%s" % (resheadl[x], rowl[x]) for x in range(len(rowl))] |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
270 desc.insert(0, "Descriptive measures") |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
271 descn = "\n".join(desc) |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
272 restab.append(descn) |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
273 restab.append(histo) |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
274 if os.path.isfile(fakepath): |
|
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
275 os.remove(fakepath) |
|
0
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
276 if self.tableoutfile: |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
277 stable = "\n".join(restab) |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
278 with open(self.tableoutfile, "w") as t: |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
279 t.write(stable) |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
280 t.write("\n") |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
281 some = False |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
282 if self.qlo: |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
283 if self.outbeds in ["outall", "outlo", "outlohi"]: |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
284 self.writeBed(bedlo, self.bedoutlo) |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
285 some = True |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
286 if self.qhi: |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
287 if self.outbeds in ["outall", "outlohi", "outhi"]: |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
288 self.writeBed(bedhi, self.bedouthi) |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
289 some = True |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
290 if self.outbeds in ["outall", "outhilo"]: |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
291 allbed = bedlo + bedhi |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
292 self.writeBed(allbed, self.bedouthilo) |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
293 some = True |
|
2
61946b8bd43b
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 3cce4c76a60b9353298fdcf759e893b8fcdfaa77
iuc
parents:
1
diff
changeset
|
294 if not ((self.outbeds == "outtab") or some): |
|
0
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
295 sys.stderr.write( |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
296 "Invalid configuration - no output could be created. Was qlo missing and only low output requested for example?" |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
297 ) |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
298 sys.exit(2) |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
299 |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
300 |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
301 if __name__ == "__main__": |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
302 parser = argparse.ArgumentParser() |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
303 a = parser.add_argument |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
304 a("-m", "--minwin", default=10, type=int) |
|
1
8377a6abb4da
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 92ffe42a6ad6e81f3f157bbc9b942c000d450416
iuc
parents:
0
diff
changeset
|
305 a("-l", "--qlo", default=None) |
|
0
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
306 a("-i", "--qhi", default=None, type=float) |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
307 a("--bedouthi", default=None) |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
308 a("--bedoutlo", default=None) |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
309 a("--bedouthilo", default=None) |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
310 a("-w", "--bigwig", nargs="+") |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
311 a("-n", "--bigwiglabels", nargs="+") |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
312 a("-o", "--outbeds", default="outhilo", help="optional high and low combined bed") |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
313 a("-t", "--tableoutfile", default=None) |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
314 args = parser.parse_args() |
|
ebcd48f183b3
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/bigwig_outlier_bed commit 091caba3c5b066b293745ccee5cd31132fec3b4b
iuc
parents:
diff
changeset
|
315 findOut(args) |
