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
faf04a84
Commit
faf04a84
authored
1 year ago
by
Blaise Li
Browse files
Options
Downloads
Patches
Plain Diff
Add checks on column formats.
parent
d6bf5caf
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
+17
-0
17 additions, 0 deletions
libcodonusage/libcodonusage.py
with
17 additions
and
0 deletions
libcodonusage/libcodonusage.py
+
17
−
0
View file @
faf04a84
...
...
@@ -502,6 +502,19 @@ across genes) so that they are more comparable between codons.
return
standardized_codon_usage_biases
def
check_aa_codon_columns
(
table
):
"""
Check that the columns of *table* correspond to (aa, codon) pairs.
"""
msg
=
"
Codon proportions table should have two levels:
'
aa
'
and
'
codon
'"
if
codon_proportions_by_aa
.
columns
.
nlevels
!=
2
:
raise
ValueError
(
msg
)
if
codon_proportions_by_aa
.
columns
.
names
[
0
]
!=
"
aa
"
:
raise
ValueError
(
msg
)
if
codon_proportions_by_aa
.
columns
.
names
[
1
]
!=
"
codon
"
:
raise
ValueError
(
msg
)
def
compute_rscu
(
codon_proportions_by_aa
):
"""
Compute Relative Syninymous Codon Usage from proportions in genes.
...
...
@@ -513,6 +526,7 @@ def compute_rscu(codon_proportions_by_aa):
where the first level is the amino-acid name, and the second level
the codon.
"""
check_aa_codon_columns
(
codon_proportions_by_aa
)
degeneracy
=
pd
.
Series
(
# concat "flattens" the list of iterables given as arguments
# (list of tuples of repeated degeneracy values)
...
...
@@ -558,6 +572,7 @@ def by_aa_codon_usage(
restricted to the genes where the *index_level* has the *index_value*
for all those pairs.
"""
check_aa_codon_columns
(
codon_counts
)
render_md
(
f
"""
We will compute codon usage
"
by amino-acid
"
, by looking at the
proportion of codons for each amino-acid within a gene
'
s CDS.
...
...
@@ -667,6 +682,7 @@ def aa_usage(
restricted to the genes where the *index_level* has the *index_value*
for all those pairs.
"""
check_aa_codon_columns
(
codon_counts
)
render_md
(
"""
We will compute amino-acid usage, by looking at the
proportions of amino-acids within a gene
'
s CDS.
...
...
@@ -892,6 +908,7 @@ def centroid_usage(codon_counts, all_nan_cols):
For each amino-acid, there is one centroid per codon, where the
proportion for this codon is set to 1.0, and 0.0 for the other codons.
"""
check_aa_codon_columns
(
codon_counts
)
summed_by_aa
=
codon_counts
.
groupby
(
level
=
0
,
axis
=
1
).
sum
()
global_usage
=
codon_counts
.
sum
(
axis
=
0
)
global_summed_by_aa
=
global_usage
.
groupby
(
level
=
0
).
sum
()
...
...
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