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

ENH: Busco main plot. Bars with constant height. #80

Merged
merged 1 commit into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -473,6 +473,7 @@
"y": "independent"
}
},
"spacing": 20,
"spec": {
"encoding": {
"color": {
Expand Down Expand Up @@ -547,11 +548,13 @@
"type": "nominal"
}
},
"height": 162,
"height": {
"step": 30
},
"mark": {
"type": "bar"
},
"width": 600
"width": 500
}
},
{
Expand All @@ -573,6 +576,7 @@
"y": "independent"
}
},
"spacing": 20,
"spec": {
"encoding": {
"opacity": {
Expand All @@ -596,7 +600,9 @@
"type": "nominal"
}
},
"height": 162,
"height": {
"step": 30
},
"mark": {
"type": "bar"
},
Expand All @@ -606,15 +612,15 @@
"calculate": "datum[param_2]"
}
],
"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 @@ -152,10 +152,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
)

# Load expected data
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