Skip to content

Commit

Permalink
Beeswarm plot: Save data to multiqc_data
Browse files Browse the repository at this point in the history
Fixes #1861
  • Loading branch information
ewels committed Feb 8, 2023
1 parent be99c67 commit bd976bb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### MultiQC updates

- Table code now tolerates lambda function calls with bad data ([#1739](https://github.com/ewels/MultiQC/issues/1739))
- Beeswarm plot now saves data to `multiqc_data`, same as tables ([#1861](https://github.com/ewels/MultiQC/issues/1861))

### New Modules

Expand Down
11 changes: 10 additions & 1 deletion multiqc/plots/beeswarm.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@

import logging
import random
from collections import defaultdict

from multiqc.plots import table_object
from multiqc.utils import config, report
from multiqc.utils import config, report, util_functions

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -46,6 +47,7 @@ def make_plot(dt):
categories = []
s_names = []
data = []
dt.raw_vals = defaultdict(lambda: dict())
for idx, hs in enumerate(dt.headers):
for k, header in hs.items():
bcol = "rgb({})".format(header.get("colour", "204,204,204"))
Expand All @@ -69,6 +71,7 @@ def make_plot(dt):
for s_name, samp in dt.data[idx].items():
if k in samp:
val = samp[k]
dt.raw_vals[s_name][k] = val

if "modify" in header and callable(header["modify"]):
val = header["modify"](val)
Expand All @@ -95,4 +98,10 @@ def make_plot(dt):

report.plot_data[bs_id] = {"plot_type": "beeswarm", "samples": s_names, "datasets": data, "categories": categories}

# Save the raw values to a file if requested
if dt.pconfig.get("save_file") is True:
fn = dt.pconfig.get("raw_data_fn", "multiqc_{}".format(bs_id))
util_functions.write_data_file(dt.raw_vals, fn)
report.saved_raw_data[fn] = dt.raw_vals

return html

0 comments on commit bd976bb

Please sign in to comment.