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
28b03b1e
Commit
28b03b1e
authored
1 year ago
by
Blaise Li
Browse files
Options
Downloads
Patches
Plain Diff
Change default output of group_codons_by_class.
The codons belonging to the classes are not present in the output.
parent
de4b5e81
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide 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
+18
-16
18 additions, 16 deletions
libcodonusage/libcodonusage.py
with
19 additions
and
17 deletions
libcodonusage/__init__.py
+
1
−
1
View file @
28b03b1e
__copyright__
=
"
Copyright (C) 2022-2023 Blaise Li, Marie Anselmet
"
__copyright__
=
"
Copyright (C) 2022-2023 Blaise Li, Marie Anselmet
"
__licence__
=
"
GNU GPLv3
"
__licence__
=
"
GNU GPLv3
"
__version__
=
"
0.2
8.5
"
__version__
=
"
0.2
9.0
"
from
.libcodonusage
import
(
from
.libcodonusage
import
(
aa2colour
,
aa2colour
,
aa_usage
,
aa_usage
,
...
...
This diff is collapsed.
Click to expand it.
libcodonusage/libcodonusage.py
+
18
−
16
View file @
28b03b1e
...
@@ -14,7 +14,7 @@
...
@@ -14,7 +14,7 @@
# You should have received a copy of the GNU General Public License
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
# along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
Functions used in Jupyter notebooks.
"""
"""
Functions used in Jupyter notebooks.
"""
from
itertools
import
combinations
from
itertools
import
chain
,
combinations
import
json
import
json
from
operator
import
attrgetter
,
itemgetter
from
operator
import
attrgetter
,
itemgetter
from
pathlib
import
Path
from
pathlib
import
Path
...
@@ -442,19 +442,13 @@ SUZUKI_DOI = "10.1016/j.febslet.2005.10.032"
...
@@ -442,19 +442,13 @@ SUZUKI_DOI = "10.1016/j.febslet.2005.10.032"
SUZUKI_LINK
=
f
"
[Suzuki et al (2005)](https://doi.org/
{
SUZUKI_DOI
}
)
"
SUZUKI_LINK
=
f
"
[Suzuki et al (2005)](https://doi.org/
{
SUZUKI_DOI
}
)
"
def
remove_codons_old
(
codon_counts
,
codon_list
):
"""
Filter out codons in a table *codon_counts* based on codons
present in the list *codon_list* (like stop codons).
"""
codon_counts
.
drop
(
columns
=
codon_list
,
inplace
=
True
)
return
codon_counts
def
remove_codons
(
codon_counts
,
codon_list
):
def
remove_codons
(
codon_counts
,
codon_list
):
"""
"""
Filter out codons in a table *codon_counts* based on codons
Filter out codons in a table *codon_counts* based on codons
present in the list *codon_list* (like stop codons).
present in the list *codon_list* (like stop codons).
When the columns of *codon_counts* are a MultiIndex with a first
level corresponding to the amino-acid and the second to the codon,
the codons should be specified as (aa, codon) tuples.
"""
"""
return
codon_counts
.
drop
(
columns
=
codon_list
)
return
codon_counts
.
drop
(
columns
=
codon_list
)
...
@@ -486,14 +480,14 @@ def max_codon_counts(row, codons):
...
@@ -486,14 +480,14 @@ def max_codon_counts(row, codons):
def
group_codons_by_class
(
def
group_codons_by_class
(
codon_counts
,
group_name
,
dict
_classes
,
codon_counts
,
group_name
,
codon
_classes
,
mode
=
"
max
"
,
keep_only_groups
=
False
):
mode
=
"
max
"
,
keep_only_groups
=
False
,
replace_groups
=
True
):
"""
"""
Group codons given specific classes in *codon_counts* table.
Group codons given specific classes in *codon_counts* table.
*group_name* contains the name of the grouping, and plays the role
*group_name* contains the name of the grouping, and plays the role
of aa names in the original codon counts table.
of aa names in the original codon counts table.
*
dict
_classes* contains the different classes under this grouping
*
codon
_classes* contains the different classes under this grouping
as keys and the associated list of codons as values.
as keys and the associated list of codons as values.
*mode* defines the way grouping is computed. It should be the name of
*mode* defines the way grouping is computed. It should be the name of
a method of the `GroupBy` object, like
"
sum
"
or
"
max
"
.
a method of the `GroupBy` object, like
"
sum
"
or
"
max
"
.
...
@@ -502,14 +496,18 @@ def group_codons_by_class(
...
@@ -502,14 +496,18 @@ def group_codons_by_class(
If *mode* is
"
sum
"
, the sum of counts values for all codons
If *mode* is
"
sum
"
, the sum of counts values for all codons
belonging to the same class is used for the grouped class.
belonging to the same class is used for the grouped class.
*keep_only_groups* is a boolean set to True if you want to filter out
*keep_only_groups* is a boolean set to True if you want to filter out
other codons than the ones specified in
dict
_classes.
other codons than the ones specified in
codon
_classes.
If set to False (default), the original codon_counts table
If set to False (default), the original codon_counts table
is returned with additional columns for the grouped_classes.
is returned with additional columns for the grouped_classes.
If the boolean *replace_groups* is set to True (default), the full
count table will be returned, except the columns used to compute the
grouped values. This option is ignored if *keep_only_groups* has been
set to True.
"""
"""
col_renames
=
{
col_renames
=
{
(
aa
,
codon
):
(
class_name
,
group_name
,
codon
)
(
aa
,
codon
):
(
class_name
,
group_name
,
codon
)
for
class_name
in
dict
_classes
for
class_name
in
codon
_classes
for
(
aa
,
codon
)
in
dict
_classes
[
class_name
]}
for
(
aa
,
codon
)
in
codon
_classes
[
class_name
]}
codon_counts_pre_group
=
codon_counts
[
col_renames
.
keys
()]
codon_counts_pre_group
=
codon_counts
[
col_renames
.
keys
()]
# We add a level to the column names,
# We add a level to the column names,
# "codon", becoming "sub_codon", will disappear
# "codon", becoming "sub_codon", will disappear
...
@@ -524,6 +522,10 @@ def group_codons_by_class(
...
@@ -524,6 +522,10 @@ def group_codons_by_class(
mode
)()
mode
)()
if
keep_only_groups
:
if
keep_only_groups
:
return
codon_counts_grouped
return
codon_counts_grouped
if
replace_groups
:
return
remove_codons
(
pd
.
concat
([
codon_counts
,
codon_counts_grouped
],
axis
=
1
),
chain
.
from_iterable
(
codon_classes
.
values
()))
return
pd
.
concat
([
codon_counts
,
codon_counts_grouped
],
axis
=
1
)
return
pd
.
concat
([
codon_counts
,
codon_counts_grouped
],
axis
=
1
)
...
...
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