From ca9f5bb5dcb3a9d4b6ab54bef48c238918aff340 Mon Sep 17 00:00:00 2001 From: Santiago Castro Dau <54123712+Sann5@users.noreply.github.com> Date: Tue, 17 Oct 2023 16:19:58 +0200 Subject: [PATCH] ENH: set BUSCO bars to constant height (#80) --- q2_moshpit/busco/tests/data/plot_as_dict.json | 16 ++++++---- q2_moshpit/busco/tests/test_utils.py | 5 ++-- q2_moshpit/busco/utils.py | 29 ++++++++++++------- 3 files changed, 33 insertions(+), 17 deletions(-) diff --git a/q2_moshpit/busco/tests/data/plot_as_dict.json b/q2_moshpit/busco/tests/data/plot_as_dict.json index cfd80635..9103456a 100644 --- a/q2_moshpit/busco/tests/data/plot_as_dict.json +++ b/q2_moshpit/busco/tests/data/plot_as_dict.json @@ -472,6 +472,7 @@ "y": "independent" } }, + "spacing": 20, "spec": { "encoding": { "color": { @@ -546,11 +547,13 @@ "type": "nominal" } }, - "height": 162, + "height": { + "step": 30 + }, "mark": { "type": "bar" }, - "width": 600 + "width": 500 } }, { @@ -572,6 +575,7 @@ "y": "independent" } }, + "spacing": 20, "spec": { "encoding": { "opacity": { @@ -595,7 +599,9 @@ "type": "nominal" } }, - "height": 162, + "height": { + "step": 30 + }, "mark": { "type": "bar" }, @@ -605,7 +611,7 @@ "calculate": "datum[param_i]" } ], - "width": 600 + "width": 500 } } ], @@ -613,7 +619,7 @@ { "bind": { "input": "select", - "name": "Assambly Statistics: ", + "name": "Assembly Statistics: ", "options": [ "scaffold_n50", "contigs_n50", diff --git a/q2_moshpit/busco/tests/test_utils.py b/q2_moshpit/busco/tests/test_utils.py index a4b51512..73573edc 100644 --- a/q2_moshpit/busco/tests/test_utils.py +++ b/q2_moshpit/busco/tests/test_utils.py @@ -153,10 +153,11 @@ def test_draw_busco_plots_for_render(self): # Draw plot observed = _draw_busco_plots_for_render( all_summaries_df, - width=600, - height=18, + width=500, + height=30, titleFontSize=20, labelFontSize=17, + spacing=20 ) # Replace param value to make the dict altair version invariant diff --git a/q2_moshpit/busco/utils.py b/q2_moshpit/busco/utils.py index c3e1a394..a19ba694 100644 --- a/q2_moshpit/busco/utils.py +++ b/q2_moshpit/busco/utils.py @@ -50,6 +50,7 @@ def _draw_busco_plots_for_render( height: int = None, labelFontSize: int = None, titleFontSize: int = None, + spacing: int = None ) -> str: """ Draws a horizontal normalized bar plot for every sample for which BUSCO was @@ -71,9 +72,6 @@ def _draw_busco_plots_for_render( # Format data frame df = _parse_df_columns(df) - # Get number of samples - n_samples = len(df["mag_id"].unique()) - # Format data for plotting busco_plot_data = pd.melt( df, @@ -138,8 +136,17 @@ def _draw_busco_plots_for_render( ], opacity=alt.value(0.85), ) - .properties(width=width, height=height * n_samples) - .facet(row=alt.Row("sample_id", title="Sample ID")) + .properties( + width=width, + height={"step": height} + ) + .facet( + row=alt.Row( + "sample_id", + title="Sample ID" + ), + spacing=spacing + ) .resolve_scale(y="independent") ) @@ -152,7 +159,7 @@ def _draw_busco_plots_for_render( 'percent_gaps', 'number_of_scaffolds', ], - name="Assambly Statistics: " + name="Assembly Statistics: " ) xcol_param = alt.param( @@ -171,13 +178,14 @@ def _draw_busco_plots_for_render( xcol_param ).properties( width=width, - height=height * n_samples + height={"step": height} ).facet( row=alt.Row( "sample_id", title=None, - header=alt.Header(labelFontSize=0) - ) + header=alt.Header(labelFontSize=0), + ), + spacing=spacing ).resolve_scale( y="independent" ) @@ -417,9 +425,10 @@ def _render_html( "vega_plots_overview": _draw_busco_plots_for_render( all_summaries_df, width=600, - height=9, + height=30, titleFontSize=20, labelFontSize=17, + spacing=20 ), }