From d83084c7b65608ccd33a046f2e987589287951f5 Mon Sep 17 00:00:00 2001
From: Blaise Li <blaise.li__git@nsup.org>
Date: Mon, 18 Sep 2023 15:20:01 +0200
Subject: [PATCH] Added computing of R4 (sensu Suzuki et al 2005).

This consists in dividing counts by the maximum across synonymous codons
for a given amino-acid, and is supposed to avoid certain biases in PCA.
---
 libcodonusage/__init__.py      | 2 +-
 libcodonusage/libcodonusage.py | 9 ++++++++-
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/libcodonusage/__init__.py b/libcodonusage/__init__.py
index fcfc26c..bcdaab8 100644
--- a/libcodonusage/__init__.py
+++ b/libcodonusage/__init__.py
@@ -1,6 +1,6 @@
 __copyright__ = "Copyright (C) 2022-2023 Blaise Li"
 __licence__ = "GNU GPLv3"
-__version__ = "0.27.3"
+__version__ = "0.27.4"
 from .libcodonusage import (
     aa2colour,
     aa_usage,
diff --git a/libcodonusage/libcodonusage.py b/libcodonusage/libcodonusage.py
index cf50fbf..2408e4a 100644
--- a/libcodonusage/libcodonusage.py
+++ b/libcodonusage/libcodonusage.py
@@ -541,7 +541,7 @@ def check_aa_codon_columns(table):
 
 def compute_rscu(codon_proportions_by_aa):
     """
-    Compute Relative Syninymous Codon Usage from proportions in genes.
+    Compute Relative Synonymous Codon Usage from proportions in genes.
 
     *codon_proportions_by_aa* should be a pandas DataFrame where
     rows correspond to genes, and columns to codons. It contains
@@ -641,6 +641,12 @@ for that amino-acid.
 (This corresponds to R3 in {SUZUKI_LINK})
 """)
         rscu = compute_rscu(codon_proportions)
+        render_md(f"""
+We will also compute R4 ({SUZUKI_LINK}) by computing codon counts relative
+to the maxium across synonymous codons of the counts for that amino-acid.
+""")
+        r4_table = codon_counts.div(
+            codon_counts.T.groupby("aa").max().T)
     if ref_filter_dict is None:
         counts_for_global = codon_counts
     else:
@@ -688,6 +694,7 @@ across genes) so that they are more comparable between codons.
             "biases": standardized_codon_usage_biases,
             "proportions": codon_proportions,
             "rscu": rscu,
+            "r4_table": r4_table,
             "global_proportions": global_proportions}
     return standardized_codon_usage_biases
 
-- 
GitLab