Skip to content
Snippets Groups Projects
Commit 6530db56 authored by Blaise Li's avatar Blaise Li
Browse files

Start fixing aa usage violin plots.

parent b37e7ce5
No related branches found
No related tags found
No related merge requests found
__copyright__ = "Copyright (C) 2022 Blaise Li" __copyright__ = "Copyright (C) 2022 Blaise Li"
__licence__ = "GNU GPLv3" __licence__ = "GNU GPLv3"
__version__ = "0.23" __version__ = "0.24"
from .libcodonusage import ( from .libcodonusage import (
aa2colour, aa2colour,
aa_usage, aa_usage,
......
...@@ -1333,16 +1333,13 @@ def violin_usage( ...@@ -1333,16 +1333,13 @@ def violin_usage(
"data": long_form, "ax": axis, "orient": "v", "scale": "count"} "data": long_form, "ax": axis, "orient": "v", "scale": "count"}
kwargs.update(violin_kwargs) kwargs.update(violin_kwargs)
axis = sns.violinplot(**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: if do_legend:
plt.legend(bbox_to_anchor=(1.01, 1), borderaxespad=0) plt.legend(bbox_to_anchor=(1.01, 1), borderaxespad=0)
if variable == "codon": if variable == "codon":
ticklabels = format_codon_labels(axis.get_xticklabels()) ticklabels = format_codon_labels(axis.get_xticklabels())
else: else:
ticklabels = axis.get_xticklabels() ticklabels = axis.get_xticklabels()
# TODO: Expect issues when variable == "aa"
axis.set_xticklabels(ticklabels, rotation=90) axis.set_xticklabels(ticklabels, rotation=90)
return axis return axis
...@@ -1365,7 +1362,13 @@ def violin_usage_vertical( ...@@ -1365,7 +1362,13 @@ def violin_usage_vertical(
nb_violins = len(usage_table.index.get_level_values(hue).unique()) nb_violins = len(usage_table.index.get_level_values(hue).unique())
long_form = to_long_form(usage_table, ylabel, others=[hue]) long_form = to_long_form(usage_table, ylabel, others=[hue])
if axis is None: 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": if hue == "aa":
palette = aa2colour palette = aa2colour
else: else:
...@@ -1377,16 +1380,9 @@ def violin_usage_vertical( ...@@ -1377,16 +1380,9 @@ def violin_usage_vertical(
"data": long_form, "ax": axis, "orient": "h", "scale": "count"} "data": long_form, "ax": axis, "orient": "h", "scale": "count"}
kwargs.update(violin_kwargs) kwargs.update(violin_kwargs)
axis = sns.violinplot(**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": if variable == "codon":
ticklabels = format_codon_labels(axis.get_yticklabels()) ticklabels = format_codon_labels(axis.get_yticklabels())
else: axis.set_yticklabels(ticklabels)
ticklabels = axis.get_xticklabels()
axis.set_yticklabels(ticklabels)
return axis return axis
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment