Skip to content

Commit

Permalink
Bar graphs: add sort_samples: false config option, also do not sort…
Browse files Browse the repository at this point in the history
… `OrderedDict` data (#2210)

* Remove sorting of bar graph data

* When trying indexing lists/dicts, catch TypeError as well

* [automated] Update CHANGELOG.md

* Revert "When trying indexing lists/dicts, catch TypeError as well"

This reverts commit d234f97.

* Add sort_samples: false, do not sort OrderedDict

* Changelog

---------

Co-authored-by: MultiQC Bot <multiqc-bot@seqera.io>
  • Loading branch information
vladsavelyev and multiqc-bot committed Dec 12, 2023
1 parent 9d00f14 commit 2be5617
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
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

0 comments on commit 2be5617

Please sign in to comment.