Skip to content

Commit

Permalink
Fix no_violin/no_beeswarm flag to table (#2376)
Browse files Browse the repository at this point in the history
* Fix `no_violin`/`no_beeswarm` flag to table

* [automated] Update CHANGELOG.md

* Fix docs

* Comment and reoder logic

---------

Co-authored-by: MultiQC Bot <multiqc-bot@seqera.io>
  • Loading branch information
vladsavelyev and multiqc-bot committed Feb 25, 2024
1 parent 9379f89 commit 981715c
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 21 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
- Fix: wrap `full_figure_for_development` in try to handle Kaleido error ([#2359](https://github.com/MultiQC/MultiQC/pull/2359))
- Generic font family for Plotly ([#2368](https://github.com/MultiQC/MultiQC/pull/2368))
- Violin plot: filter Inf values ([#2380](https://github.com/MultiQC/MultiQC/pull/2380))
- Fix use of the `no_violin`/`no_beeswarm` table config flag ([#2376](https://github.com/MultiQC/MultiQC/pull/2376))

### New modules

Expand Down
4 changes: 2 additions & 2 deletions docs/core/development/plots.md
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ single_header = {
"cond_formatting_colours": None, # Styles for conditional formatting of table cell values
"shared_key": None, # See below for description
"modify": None, # Lambda function to modify values
"hidden": False # Set to True to hide the column on page load
"hidden": False, # Set to True to hide the column on page load
}
```

Expand All @@ -481,7 +481,7 @@ table_config = {
"sortRows": True, # Whether to sort rows alphabetically
"only_defined_headers": True, # Only show columns that are defined in the headers config
"col1_header": "Sample Name", # The header used for the first column
"no_beeswarm": False, # Force a table to always be plotted (beeswarm by default if many rows)
"no_violin": False, # Force a table to always be plotted (beeswarm by default if many rows)
}
```

Expand Down
2 changes: 1 addition & 1 deletion multiqc/modules/bcl2fastq/bcl2fastq.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ def lane_stats_table(self):
"id": "bcl2fastq-lane-stats-table",
"table_title": "bcl2fastq Lane Statistics",
"col1_header": "Run ID - Lane",
"no_beeswarm": True,
"no_violin": True,
}
return table.plot(self.bcl2fastq_bylane, headers, table_config)

Expand Down
4 changes: 2 additions & 2 deletions multiqc/modules/bclconvert/bclconvert.py
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,7 @@ def sample_stats_table(self, bclconvert_data, bclconvert_by_sample):
"namespace": "bclconvert",
"id": "bclconvert-sample-stats-table",
"table_title": "bclconvert Sample Statistics",
"no_beeswarm": True,
"no_violin": True,
}

return table.plot(sample_stats_data, headers, table_config)
Expand Down Expand Up @@ -822,7 +822,7 @@ def lane_stats_table(self, bclconvert_by_lane):
"id": "bclconvert-lane-stats-table",
"table_title": "bclconvert Lane Statistics",
"col1_header": "Run ID - Lane",
"no_beeswarm": True,
"no_violin": True,
}

# new dict with matching keys for plotting (this avoids duplicate html id linting errors)
Expand Down
4 changes: 2 additions & 2 deletions multiqc/modules/clusterflow/clusterflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def clusterflow_commands_table(self):
"table_title": "Cluster Flow Commands",
"col1_header": "Tool",
"sortRows": False,
"no_beeswarm": True,
"no_violin": True,
}
self.add_section(
name="Commands",
Expand Down Expand Up @@ -336,7 +336,7 @@ def clusterflow_pipelines_section(self):
"id": "clusterflow-pipelines-table",
"table_title": "Cluster Flow Pipelines",
"col1_header": "Pipeline ID",
"no_beeswarm": True,
"no_violin": True,
"save_file": True,
}
self.add_section(
Expand Down
4 changes: 2 additions & 2 deletions multiqc/modules/dragen/coverage_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,13 +470,13 @@
"sortRows": True, # Whether to sort rows alphabetically
"only_defined_headers": True, # Only show columns that are defined in the headers config
"col1_header": None, # The header used for the first column with sample names.
"no_beeswarm": False, # Force a table to always be plotted (beeswarm by default if many rows)
"no_violin": False, # Force a table to always be plotted (beeswarm by default if many rows)
}
# Below are region-specific configs with higher priority.
REGION_TABLE_CONFIG = {
WGS: {
"table_title": "WGS",
# "no_beeswarm": True,
# "no_violin": True,
# "save_file": True,
# "raw_data_fn": "Genome_raw_file",
},
Expand Down
2 changes: 1 addition & 1 deletion multiqc/modules/picard/CrosscheckFingerprints.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def parse_reports(module):
"table_title": f"{module.name}: Crosscheck Fingerprints",
"save_file": True,
"col1_header": "ID",
"no_beeswarm": True,
"no_violin": True,
},
),
)
Expand Down
2 changes: 1 addition & 1 deletion multiqc/modules/somalier/somalier.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ def somalier_stats_table(self):
"id": "somalier_stats",
"namespace": "Somalier",
"title": "Somalier: Statistics",
"no_beeswarm": True,
"no_violin": True,
"raw_data_fn": "multiqc_somalier_stats",
}

Expand Down
33 changes: 23 additions & 10 deletions multiqc/plots/plotly/violin.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,8 +328,9 @@ def __init__(
assert len(list_of_values_by_sample_by_metric) > 0

self.dt = dt
self.show_table_by_default = dt is not None and show_table_by_default
self.no_violin = pconfig.get("no_violin", pconfig.get("no_beeswarm", False))
self.show_table = dt is not None
self.show_table_by_default = show_table_by_default or self.no_violin

super().__init__(
PlotType.VIOLIN,
Expand Down Expand Up @@ -381,7 +382,7 @@ def __init__(
# - plot a Violin in Python, and serialise the figure instead of the datasets
self.n_samples = max(len(ds.all_samples) for ds in self.datasets)
self.serialize_figure = False
if self.n_samples > config.max_table_rows:
if self.n_samples > config.max_table_rows and not self.no_violin:
self.show_table = False
if self.show_table_by_default:
logger.debug(
Expand Down Expand Up @@ -431,7 +432,10 @@ def tt_label() -> str:
return ": %{x}"

def add_to_report(self, report) -> str:
violin_html = super().add_to_report(report)
if not self.no_violin:
violin_html = super().add_to_report(report)
else:
violin_html = ""

warning = ""
if self.show_table_by_default and not self.show_table:
Expand All @@ -456,17 +460,26 @@ def add_to_report(self, report) -> str:
)

if not self.show_table:
# Show violin alone
# Show violin alone.
# Note that "no_violin" will be ignored here as we need to render _something_. The only case it can
# happen if violin.plot() is called directly, and "no_violin" is passed, which doesn't make sense.
html = warning + violin_html
elif self.no_violin:
# Show table alone
table_html, configuration_modal = make_table(self.dt)
html = warning + table_html + configuration_modal
else:
# Switch between table and violin
# Render both, add a switch between table and violin
table_html, configuration_modal = make_table(self.dt, violin_id=self.id)
visibility = "style='display: none;'" if self.show_table_by_default else ""
html = f"<div id='mqc_violintable_wrapper_{self.id}' {visibility}>{warning}{violin_html}</div>"
if self.show_table:
visibility = "style='display: none;'" if not self.show_table_by_default else ""
html += f"<div id='mqc_violintable_wrapper_{self.dt.id}' {visibility}>{table_html}</div>"

violin_visibility = "style='display: none;'" if self.show_table_by_default else ""
html = f"<div id='mqc_violintable_wrapper_{self.id}' {violin_visibility}>{warning}{violin_html}</div>"

table_visibility = "style='display: none;'" if not self.show_table_by_default else ""
html += f"<div id='mqc_violintable_wrapper_{self.dt.id}' {table_visibility}>{table_html}</div>"

html += configuration_modal

return html

def dump_for_javascript(self):
Expand Down

0 comments on commit 981715c

Please sign in to comment.