diff --git a/libcodonusage/__init__.py b/libcodonusage/__init__.py index 81a2d1f8cac8eb9d1d2e7527a3bc63151c620ea4..dc6f97f98c2c936887781eee456fdbeabeb2b9c4 100644 --- a/libcodonusage/__init__.py +++ b/libcodonusage/__init__.py @@ -1,6 +1,6 @@ __copyright__ = "Copyright (C) 2022-2023 Blaise Li, Marie Anselmet" __licence__ = "GNU GPLv3" -__version__ = "0.28.4" +__version__ = "0.28.5" from .libcodonusage import ( aa2colour, aa_usage, diff --git a/libcodonusage/libcodonusage.py b/libcodonusage/libcodonusage.py index a1d4894b140d2b0f10187d7ee3109cf6b05e5beb..69aca04ae256558a5bb4758ef7fa19c13f41583e 100644 --- a/libcodonusage/libcodonusage.py +++ b/libcodonusage/libcodonusage.py @@ -442,7 +442,7 @@ SUZUKI_DOI = "10.1016/j.febslet.2005.10.032" SUZUKI_LINK = f"[Suzuki et al (2005)](https://doi.org/{SUZUKI_DOI})" -def remove_codons(codon_counts, codon_list): +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). @@ -451,6 +451,14 @@ def remove_codons(codon_counts, codon_list): return codon_counts +def remove_codons(codon_counts, codon_list): + """ + Filter out codons in a table *codon_counts* based on codons + present in the list *codon_list* (like stop codons). + """ + return codon_counts.drop(columns=codon_list) + + def sum_codon_counts(row, codons): """ Perform the row-wise sum of codon counts for the codons @@ -477,46 +485,6 @@ def max_codon_counts(row, codons): return max(counts_codons) -def group_codons_by_class_old( - codon_counts, group_name, dict_classes, - mode="max", keep_only_groups=False): - """ - Group codons given specific classes in *codon_counts* table. - - *group_name* contains the name of the grouping, and plays the role - of aa names in the original codon counts table. - *dict_classes* contains the different classes under this grouping - as keys and the associated list of codons as values. - *mode* defines the way grouping is computed. - If mode is "max", the maximum value of counts of codons belonging - to the same class is used for the grouped class. - Otherwise, the sum of counts values for all codons 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 - other codons than the ones specified in dict_classes. - If set to False (default), the original codon_counts table - is returned with additional columns for the grouped_classes. - """ - list_classes_names = [] - # pylint issues the following warning: - # "W0640: Cell variable value defined in loop (cell-var-from-loop)" - # Since the lambda function is used immediately, - # this should not be an actual issue - # (see https://stackoverflow.com/q/25314547/1878788 and answers) - for key, value in dict_classes.items(): - if mode == "max": - codon_counts[group_name, key] = codon_counts.apply( - lambda row: max_codon_counts(row, value), axis=1) - else: - codon_counts[group_name, key] = codon_counts.apply( - lambda row: sum_codon_counts(row, value), axis=1) - list_classes_names.append(key) - if keep_only_groups: - return codon_counts.loc[:, ([group_name], list_classes_names)] - else: - return codon_counts - - def group_codons_by_class( codon_counts, group_name, dict_classes, mode="max", keep_only_groups=False):