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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Blaise LI
libcodonusage
Commits
e6f55702
Commit
e6f55702
authored
3 years ago
by
Blaise Li
Browse files
Options
Downloads
Patches
Plain Diff
More easy to choose fig formats.
parent
64894825
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
libcodonusage/__init__.py
+1
-1
1 addition, 1 deletion
libcodonusage/__init__.py
libcodonusage/libcodonusage.py
+23
-11
23 additions, 11 deletions
libcodonusage/libcodonusage.py
with
24 additions
and
12 deletions
libcodonusage/__init__.py
+
1
−
1
View file @
e6f55702
__copyright__
=
"
Copyright (C) 2022 Blaise Li
"
__licence__
=
"
GNU GPLv3
"
__version__
=
"
0.2
4
"
__version__
=
"
0.2
5
"
from
.libcodonusage
import
(
aa2colour
,
aa_usage
,
...
...
This diff is collapsed.
Click to expand it.
libcodonusage/libcodonusage.py
+
23
−
11
View file @
e6f55702
...
...
@@ -60,6 +60,13 @@ from sklearn.preprocessing import normalize
from
upsetplot
import
from_indicators
,
UpSet
fmt_metadata
=
{
"
png
"
:
{
"
creationDate
"
:
None
},
"
svg
"
:
{
"
Creator
"
:
None
,
"
Date
"
:
None
,
"
Title
"
:
"
Distribution of standardized codon usages biases (by aa), by chromosome
"
}
}
def
render_md
(
md_str
):
"""
Render a markdown string *md_str* in a Jupyter notebook.
...
...
@@ -669,7 +676,8 @@ methionine (M) and tryptophan (W).
def
codon_usage_pca
(
usage_data
,
figs_dir
=
None
,
hue
=
"
chrom
"
,
exclude_cols
=
None
):
figs_dir
=
None
,
hue
=
"
chrom
"
,
exclude_cols
=
None
,
formats
=
None
):
"""
Perform Principal Component Analysis on *usage_data*.
...
...
@@ -691,6 +699,8 @@ def codon_usage_pca(
in the first four principal components (0 vs. 1 and 2 vs. 3)
as well as graphics representing the influence of each data column
on the first four principal components.
*formats* should be a list of formats in which the figures should
be saved, such as
"
svg
"
or
"
png
"
.
If *exclude_cols* is not None, the columns with the names contained
in the iterable *exclude_cols* will not be included in the PCA analysis.
...
...
@@ -713,10 +723,11 @@ def codon_usage_pca(
sns
.
scatterplot
(
data
=
transformed_data
,
x
=
2
,
y
=
3
,
hue
=
hue
,
marker
=
"
.
"
,
ax
=
axes
[
1
])
if
figs_dir
is
not
None
:
if
figs_dir
is
not
None
and
formats
is
not
None
:
for
ext
in
formats
:
plt
.
savefig
(
figs_dir
.
joinpath
(
"
PCA_projections.
png
"
),
metadata
=
{
'
creationDate
'
:
None
}
)
figs_dir
.
joinpath
(
f
"
PCA_projections.
{
ext
}
"
),
metadata
=
fmt_metadata
[
ext
]
)
display
(
fig
)
plt
.
close
(
fig
)
render_md
(
...
...
@@ -734,10 +745,11 @@ def codon_usage_pca(
axis
.
set_ylabel
(
f
"
weight in component
{
component
}
"
)
# axis.set_xticklabels(axis.get_xticklabels(), rotation=90)
fig
.
subplots_adjust
(
hspace
=
.
5
)
if
figs_dir
is
not
None
:
if
figs_dir
is
not
None
and
formats
is
not
None
:
for
ext
in
formats
:
plt
.
savefig
(
figs_dir
.
joinpath
(
"
PCA_components.
png
"
),
metadata
=
{
'
creationDate
'
:
None
}
)
figs_dir
.
joinpath
(
f
"
PCA_components.
{
ext
}
"
),
metadata
=
fmt_metadata
[
ext
]
)
display
(
fig
)
plt
.
close
(
fig
)
return
(
pca
,
transformed_data
)
...
...
@@ -994,7 +1006,7 @@ def write_cluster_lists(
vertical
=
True
)
path_to_fig
=
aa_dir
.
joinpath
(
star2stop
(
f
"
usage_biases_violin_plots_by_cluster_for_
{
aa
}
.png
"
))
plt
.
savefig
(
path_to_fig
,
metadata
=
{
'
creationDate
'
:
None
}
)
plt
.
savefig
(
path_to_fig
,
metadata
=
fmt_metadata
[
"
png
"
]
)
plt
.
close
()
relpath_to_fig
=
str
(
path_to_fig
.
relative_to
(
'
.
'
))
md_report
+=
(
...
...
@@ -1202,7 +1214,7 @@ def plot_codon_usage_for_gene_list(
aa_dir
.
mkdir
(
parents
=
True
,
exist_ok
=
True
)
path_to_fig
=
aa_dir
.
joinpath
(
star2stop
(
f
"
usage_biases_violin_plot_
{
aa
}
_
{
codon
}
.png
"
))
plt
.
savefig
(
path_to_fig
,
metadata
=
{
'
creationDate
'
:
None
}
)
plt
.
savefig
(
path_to_fig
,
metadata
=
fmt_metadata
[
"
png
"
]
)
plt
.
close
()
# Save the list of the top genes
# path_to_top = aa_dir.joinpath(star2stop(f"{aa}_{codon}_top.txt"))
...
...
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