Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bar graphs: add sort_samples: false config option, also do not sort OrderedDict data #2210

Merged
merged 8 commits into from
Dec 12, 2023
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
- When trying indexing lists/dicts while accessing config parameters, catch TypeError as well ([#2211](https://github.com/ewels/MultiQC/pull/2211))
- Fix running `--no-report` ([#2212](https://github.com/ewels/MultiQC/pull/2212))
- Add `.cram` to sample name cleaning defaults ([#2209](https://github.com/ewels/MultiQC/pull/2209))
- Fastp: search pattern: look at content instead of file name ([#2213](https://github.com/ewels/MultiQC/pull/2213))
- Custom content plot: do not assume first row are samples ([#2208](https://github.com/ewels/MultiQC/pull/2208))
- Fastp: search pattern: look at content instead of file name ([#2213](https://github.com/ewels/MultiQC/pull/2213))
- Bar graphs: add `sort_samples: false` config option, also do not sort `OrderedDict` data ([#2210](https://github.com/ewels/MultiQC/pull/2210))

### New Modules

Expand Down
5 changes: 3 additions & 2 deletions docs/core/development/plots.md
Original file line number Diff line number Diff line change
Expand Up @@ -857,7 +857,7 @@ Data and configuration must be added to the document level
`mqc_plots` variable on page load, using the target as the key.
The variables used are as follows:

```javascript
```js
mqc_plots[target]["plot_type"] = "bar_graph";
mqc_plots[target]["config"];
mqc_plots[target]["datasets"];
Expand All @@ -866,7 +866,7 @@ mqc_plots[target]["samples"];

All available config options with default vars:

```javascript
```js
config = {
title: undefined, // Plot title
xlab: undefined, // X axis label
Expand All @@ -882,6 +882,7 @@ config = {
cursor: undefined, // CSS mouse cursor type. Defaults to pointer when 'click_func' specified
tt_percentages: true, // Show the percentages of each count in the tooltip
reversedStacks: false, // Reverse the order of the categories in the stack.
sort_samples: true, // Sort samples alphanumerically
};
```

Expand Down
10 changes: 9 additions & 1 deletion multiqc/plots/bargraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import inspect
import io
import logging
from collections import OrderedDict

import math
import os
import random
Expand Down Expand Up @@ -135,7 +137,13 @@ def plot(data, cats=None, pconfig=None):
plotsamples = list()
plotdata = list()
for idx, d in enumerate(data):
hc_samples = sorted(list(d.keys()))
hc_samples = list(d.keys())
if isinstance(d, OrderedDict):
# Legacy: users assumed that passing an OrderedDict indicates that we
# want to keep the sample order https://github.com/ewels/MultiQC/issues/2204
pass
elif pconfig.get("sort_samples", True):
hc_samples = sorted(list(d.keys()))
hc_data = list()
sample_dcount = dict()
for c in cats[idx].keys():
Expand Down