Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
libcodonusage
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Blaise LI
libcodonusage
Commits
14de21d2
Commit
14de21d2
authored
3 years ago
by
Blaise Li
Browse files
Options
Downloads
Patches
Plain Diff
Forward arguments to violin plot.
parent
6b3bb11b
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
libcodonusage/libcodonusage.py
+41
-21
41 additions, 21 deletions
libcodonusage/libcodonusage.py
with
41 additions
and
21 deletions
libcodonusage/libcodonusage.py
+
41
−
21
View file @
14de21d2
...
...
@@ -1089,6 +1089,11 @@ def to_long_form(usage_table, ylabel, others=None):
See https://pandas.pydata.org/docs/user_guide/10min.html#stack
and https://seaborn.pydata.org/generated/seaborn.violinplot.html
*y_label* is the column header you want to set for the usage values.
*others* should be a list of extra information you want to extract
from the index (which is expected to be a pandas MultiIndex).
"""
col_nb_levels
=
usage_table
.
columns
.
nlevels
row_nb_levels
=
usage_table
.
index
.
nlevels
...
...
@@ -1141,7 +1146,9 @@ def format_codon_labels(codons):
for
(
x
,
y
,
codon
)
in
map
(
attrgetter
(
"
_x
"
,
"
_y
"
,
"
_text
"
),
codons
)]
def
violin_usage
(
usage_table
,
variable
,
ylabel
,
hue
=
"
aa
"
,
axis
=
None
):
def
violin_usage
(
usage_table
,
variable
,
ylabel
,
hue
=
"
aa
"
,
axis
=
None
,
**
violin_kwargs
):
"""
Plot violin plots of codon usage biases.
...
...
@@ -1157,15 +1164,20 @@ def violin_usage(usage_table, variable, ylabel, hue="aa", axis=None):
palette
=
aa2colour
else
:
palette
=
None
# if variable == "aa":
# order = list(columns_by_aa.keys())
# elif variable == "codon":
# order = [codon for (_, codon) in concat(columns_by_aa.values())]
# else:
# raise ValueError("variable can only be 'aa' or 'codon'.\n")
sns
.
violinplot
(
x
=
variable
,
y
=
ylabel
,
order
=
variable2order
(
variable
),
hue
=
hue
,
palette
=
palette
,
dodge
=
False
,
data
=
long_form
,
ax
=
axis
,
orient
=
"
v
"
,
scale
=
"
count
"
)
if
hue
in
{
"
aa
"
,
"
codon
"
}:
dodge
=
False
else
:
dodge
=
True
kwargs
=
{
"
x
"
:
variable
,
"
y
"
:
ylabel
,
"
order
"
:
variable2order
(
variable
),
"
hue
"
:
hue
,
"
palette
"
:
palette
,
"
dodge
"
:
dodge
,
"
data
"
:
long_form
,
"
ax
"
:
axis
,
"
orient
"
:
"
v
"
,
"
scale
"
:
"
count
"
}
kwargs
.
update
(
violin_kwargs
)
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
"
:
...
...
@@ -1176,7 +1188,9 @@ def violin_usage(usage_table, variable, ylabel, hue="aa", axis=None):
return
axis
def
violin_usage_vertical
(
usage_table
,
variable
,
ylabel
,
hue
=
"
aa
"
,
axis
=
None
):
def
violin_usage_vertical
(
usage_table
,
variable
,
ylabel
,
hue
=
"
aa
"
,
axis
=
None
,
**
violin_kwargs
):
"""
Plot vertically stacked violin plots of codon usage biases.
...
...
@@ -1189,16 +1203,22 @@ def violin_usage_vertical(usage_table, variable, ylabel, hue="aa", axis=None):
palette
=
aa2colour
else
:
palette
=
None
# if variable == "aa":
# order = list(columns_by_aa.keys())
# elif variable == "codon":
# order = [codon for (_, codon) in concat(columns_by_aa.values())]
# else:
# raise ValueError("variable can only be 'aa' or 'codon'.\n")
sns
.
violinplot
(
y
=
variable
,
x
=
ylabel
,
order
=
variable2order
(
variable
),
hue
=
hue
,
palette
=
palette
,
dodge
=
False
,
data
=
long_form
,
ax
=
axis
,
orient
=
"
h
"
,
scale
=
"
count
"
)
if
hue
in
{
"
aa
"
,
"
codon
"
}:
dodge
=
False
else
:
dodge
=
True
kwargs
=
{
"
y
"
:
variable
,
"
x
"
:
ylabel
,
"
order
"
:
variable2order
(
variable
),
"
hue
"
:
hue
,
"
palette
"
:
palette
,
"
dodge
"
:
dodge
,
"
data
"
:
long_form
,
"
ax
"
:
axis
,
"
orient
"
:
"
h
"
,
"
scale
"
:
"
count
"
}
kwargs
.
update
(
violin_kwargs
)
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
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment