Skip to content

Commit

Permalink
ENH: set BUSCO bars to constant height (#80)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sann5 authored Oct 17, 2023
1 parent 89ca6e2 commit ca9f5bb
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 17 deletions.
16 changes: 11 additions & 5 deletions q2_moshpit/busco/tests/data/plot_as_dict.json
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,7 @@
"y": "independent"
}
},
"spacing": 20,
"spec": {
"encoding": {
"color": {
Expand Down Expand Up @@ -546,11 +547,13 @@
"type": "nominal"
}
},
"height": 162,
"height": {
"step": 30
},
"mark": {
"type": "bar"
},
"width": 600
"width": 500
}
},
{
Expand All @@ -572,6 +575,7 @@
"y": "independent"
}
},
"spacing": 20,
"spec": {
"encoding": {
"opacity": {
Expand All @@ -595,7 +599,9 @@
"type": "nominal"
}
},
"height": 162,
"height": {
"step": 30
},
"mark": {
"type": "bar"
},
Expand All @@ -605,15 +611,15 @@
"calculate": "datum[param_i]"
}
],
"width": 600
"width": 500
}
}
],
"params": [
{
"bind": {
"input": "select",
"name": "Assambly Statistics: ",
"name": "Assembly Statistics: ",
"options": [
"scaffold_n50",
"contigs_n50",
Expand Down
5 changes: 3 additions & 2 deletions q2_moshpit/busco/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 19 additions & 10 deletions q2_moshpit/busco/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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")
)

Expand All @@ -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(
Expand All @@ -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"
)
Expand Down Expand Up @@ -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
),
}

Expand Down

0 comments on commit ca9f5bb

Please sign in to comment.