From 6530db566b1eb8454f95ac28f0ae766b80cee93e Mon Sep 17 00:00:00 2001 From: Blaise Li <blaise.li__git@nsup.org> Date: Thu, 28 Apr 2022 16:13:40 +0200 Subject: [PATCH] Start fixing aa usage violin plots. --- libcodonusage/__init__.py | 2 +- libcodonusage/libcodonusage.py | 22 +++++++++------------- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/libcodonusage/__init__.py b/libcodonusage/__init__.py index 4241c50..8d68210 100644 --- a/libcodonusage/__init__.py +++ b/libcodonusage/__init__.py @@ -1,6 +1,6 @@ __copyright__ = "Copyright (C) 2022 Blaise Li" __licence__ = "GNU GPLv3" -__version__ = "0.23" +__version__ = "0.24" from .libcodonusage import ( aa2colour, aa_usage, diff --git a/libcodonusage/libcodonusage.py b/libcodonusage/libcodonusage.py index c675e92..70da58f 100644 --- a/libcodonusage/libcodonusage.py +++ b/libcodonusage/libcodonusage.py @@ -1333,16 +1333,13 @@ def violin_usage( "data": long_form, "ax": axis, "orient": "v", "scale": "count"} kwargs.update(violin_kwargs) axis = sns.violinplot(**kwargs) - # sns.violinplot(x=variable, y=ylabel, order=variable2order(variable), - # hue=hue, palette=palette, dodge=dodge, - # data=long_form, ax=axis, orient="v", scale="count", - # **violin_kwargs) if do_legend: plt.legend(bbox_to_anchor=(1.01, 1), borderaxespad=0) if variable == "codon": ticklabels = format_codon_labels(axis.get_xticklabels()) else: ticklabels = axis.get_xticklabels() + # TODO: Expect issues when variable == "aa" axis.set_xticklabels(ticklabels, rotation=90) return axis @@ -1365,7 +1362,13 @@ def violin_usage_vertical( nb_violins = len(usage_table.index.get_level_values(hue).unique()) long_form = to_long_form(usage_table, ylabel, others=[hue]) if axis is None: - _, axis = plt.subplots(figsize=(6, 44 * nb_violins)) + if variable == "codon": + base_height = 44 + elif variable == "aa": + base_height = 18 + else: + raise NotImplementedError(f"Unsupported variable: {variable}.") + _, axis = plt.subplots(figsize=(6, base_height * nb_violins)) if hue == "aa": palette = aa2colour else: @@ -1377,16 +1380,9 @@ def violin_usage_vertical( "data": long_form, "ax": axis, "orient": "h", "scale": "count"} kwargs.update(violin_kwargs) axis = sns.violinplot(**kwargs) - # sns.violinplot( - # y=variable, x=ylabel, order=variable2order(variable), - # hue=hue, palette=palette, dodge=dodge, - # data=long_form, ax=axis, orient="h", scale="count", - # **violin_kwargs) if variable == "codon": ticklabels = format_codon_labels(axis.get_yticklabels()) - else: - ticklabels = axis.get_xticklabels() - axis.set_yticklabels(ticklabels) + axis.set_yticklabels(ticklabels) return axis -- GitLab