Skip to content

Commit

Permalink
fix bigwig_outlier_bed handling of qlo (#6164)
Browse files Browse the repository at this point in the history
* adding new tool bigwig_outlier_bed

* remove redundant script

* replace test.bw with test-data/1.bigwig to decrease test outputs below 1MB maximum for linter.

* added bigtools to bio.tools for this new entry
added edam

* Add a proper version command by importing pybedtools

* fix doi for pybigtools

* Incorporate Bjoern's ideas.

Single select to configure 3 possible outputs.

Upper quantile now required. Chide if no low quantile and no output because low not in the choice.

Help vastly expanded.

* Added the bigwig metadata name as the label for bed feature name so no need for the user to supply one.

* Clearing out old test data. Passes tests here but diffs in CI. Something odd.

* readding fixed test outputs again again.

* Ah. was overwriting a bed with the two bigwig test.

* remove print leftovers

* Separated python script to enable access for linting in CI

* fix flake8 complaints with black on the new separate python script

* fix imports

* Do not make the output contig statistics table if there's no table output needed.

* make the table calculations optional and mostly as a separate function since they may not be needed.

* Clean up some comments.
makeTableRow renamed

* Update tools/bigwig_outlier_bed/.shed.yml

Co-authored-by: Björn Grüning <[email protected]>

* Update tools/bigwig_outlier_bed/.shed.yml

Co-authored-by: Björn Grüning <[email protected]>

* Clean up all field prompt text and consolidate the help text into chunks.

* remove test for both qhi/qlo because qhi is not optional

* fix broken qlo parameter passing and tests - add test for no qlo.

* Flake fix

* update to 0.2.0 pybigtools
test outputs are different :(

---------

Co-authored-by: Björn Grüning <[email protected]>
  • Loading branch information
fubar2 and bgruening authored Jul 21, 2024
1 parent 275acb7 commit 92ffe42
Show file tree
Hide file tree
Showing 14 changed files with 4,754 additions and 630 deletions.
42 changes: 32 additions & 10 deletions tools/bigwig_outlier_bed/bigwig_outlier_bed.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,20 @@ def __init__(self, args):
self.bwnames = args.bigwig
self.bwlabels = args.bigwiglabels
self.bedwin = args.minwin
self.qlo = args.qlo
self.qhi = args.qhi
self.outbeds = args.outbeds
self.bedouthi = args.bedouthi
self.bedoutlo = args.bedoutlo
self.bedouthilo = args.bedouthilo
self.tableoutfile = args.tableoutfile
self.bedwin = args.minwin
self.qhi = args.qhi
self.qlo = args.qlo
self.qlo = None
try:
f = float(args.qlo)
self.qlo = f
except Exception as e:
s = str(e)
print(s, ' qlo=', args.qlo)
nbw = len(args.bigwig)
nlab = len(args.bigwiglabels)
if nlab < nbw:
Expand Down Expand Up @@ -90,13 +94,13 @@ def makeTableRow(self, bw, bwlabel, chr):
bwmax,
)
if self.qhi is not None:
row += "\t%f" % self.bwtop
row += "\t%.2f" % self.bwtop
else:
row += "\t"
row += "\tnoqhi"
if self.qlo is not None:
row += "\t%f" % self.bwbot
row += "\t%.2f" % self.bwbot
else:
row += "\t"
row += "\tnoqlo"
return row

def makeBed(self):
Expand Down Expand Up @@ -125,13 +129,31 @@ def makeBed(self):
bwhi = self.processVals(bw, isTop=True)
for j, seg in enumerate(bwhi):
if seg[1] - seg[0] >= self.bedwin:
bedhi.append((chr, seg[0], seg[1], "%s_hi" % (bwlabel), 1))
score = np.sum(bw[seg[0]:seg[1]])
bedhi.append(
(
chr,
seg[0],
seg[1],
"%s_%d" % (bwlabel, score),
score,
)
)
if self.qlo is not None:
self.bwbot = np.quantile(bw, self.qlo)
bwlo = self.processVals(bw, isTop=False)
for j, seg in enumerate(bwlo):
if seg[1] - seg[0] >= self.bedwin:
bedlo.append((chr, seg[0], seg[1], "%s_lo" % (bwlabel), -1))
score = -1 * np.sum(bw[seg[0]:seg[1]])
bedlo.append(
(
chr,
seg[0],
seg[1],
"%s_%d" % (bwlabel, score),
score,
)
)
if self.tableoutfile:
row = self.makeTableRow(bw, bwlabel, chr)
restab.append(copy.copy(row))
Expand Down Expand Up @@ -164,7 +186,7 @@ def makeBed(self):
parser = argparse.ArgumentParser()
a = parser.add_argument
a("-m", "--minwin", default=10, type=int)
a("-l", "--qlo", default=None, type=float)
a("-l", "--qlo", default=None)
a("-i", "--qhi", default=None, type=float)
a("--bedouthi", default=None)
a("--bedoutlo", default=None)
Expand Down
37 changes: 26 additions & 11 deletions tools/bigwig_outlier_bed/bigwig_outlier_bed.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
<tool name="Bigwig extremes to bed features" id="bigwig_outlier_bed" version="0.1.4" profile="22.05">
<tool name="Bigwig extremes to bed features" id="bigwig_outlier_bed" version="@TOOL_VERSION@" profile="22.05">
<description>Writes high and low bigwig runs as features in a bed file</description>
<macros>
<token name="@TOOL_VERSION@">0.2.0</token>
<token name="@NUMPY_VERSION@">2.0.0</token>
<token name="@PYTHON_VERSION@">3.12.3</token>
</macros>
<edam_topics>
<edam_topic>topic_0157</edam_topic>
<edam_topic>topic_0092</edam_topic>
Expand All @@ -11,9 +16,9 @@
<xref type="bio.tools">bigtools</xref>
</xrefs>
<requirements>
<requirement type="package" version="3.12.3">python</requirement>
<requirement type="package" version="2.0.0">numpy</requirement>
<requirement type="package" version="0.1.4">pybigtools</requirement>
<requirement type="package" version="@PYTHON_VERSION@">python</requirement>
<requirement type="package" version="@NUMPY_VERSION@">numpy</requirement>
<requirement type="package" version="@TOOL_VERSION@">pybigtools</requirement>
</requirements>
<required_files>
<include path="bigwig_outlier_bed.py"/>
Expand Down Expand Up @@ -102,15 +107,25 @@
<param name="qlo" value="0.01"/>
<param name="tableout" value="create"/>
</test>
<test expect_num_outputs="2">
<output name="bedouthi" value="bedouthi_qlo_notset_sample" compare="diff" lines_diff="0"/>
<output name="tableoutfile" value="table_qlo_notset_sample" compare="diff" lines_diff="0"/>
<param name="outbeds" value="outhi"/>
<param name="bigwig" value="bigwig_sample"/>
<param name="minwin" value="10"/>
<param name="qhi" value="0.99"/>
<param name="qlo" value=""/>
<param name="tableout" value="create"/>
</test>
<test expect_num_outputs="3">
<output name="bedouthi" value="bedouthi_sample" compare="diff" lines_diff="0"/>
<output name="bedoutlo" value="bedoutlo_sample" compare="diff" lines_diff="0"/>
<output name="tableoutfile" value="table_sample" compare="diff" lines_diff="0"/>
<output name="tableoutfile" value="table3_sample" compare="diff" lines_diff="0"/>
<param name="outbeds" value="outlohi"/>
<param name="bigwig" value="bigwig_sample"/>
<param name="minwin" value="10"/>
<param name="qhi" value="0.99"/>
<param name="qlo" value="0.01"/>
<param name="minwin" value="1"/>
<param name="qhi" value="0.9"/>
<param name="qlo" value="0.1"/>
<param name="tableout" value="create"/>
</test>
<test expect_num_outputs="4">
Expand All @@ -120,9 +135,9 @@
<output name="tableoutfile" value="table2_sample" compare="diff" lines_diff="0"/>
<param name="outbeds" value="outall"/>
<param name="bigwig" value="bigwig_sample,1.bigwig"/>
<param name="minwin" value="10"/>
<param name="qhi" value="0.99"/>
<param name="qlo" value="0.01"/>
<param name="minwin" value="1"/>
<param name="qhi" value="0.9"/>
<param name="qlo" value="0.1"/>
<param name="tableout" value="create"/>
</test>
</tests>
Expand Down
Loading

0 comments on commit 92ffe42

Please sign in to comment.