From 35a7588a61b879b8bd05f6792be81dcf859ee424 Mon Sep 17 00:00:00 2001
From: Nico Maillet <nicolas.maillet@pasteur.fr>
Date: Tue, 11 Jun 2024 14:47:31 +0200
Subject: [PATCH] Adaptive precision for masses

---
 CHANGELOG.rst                 | 5 +++++
 docs/conf.py                  | 2 +-
 docs/userguide.rst            | 6 +++---
 rpg/RapidPeptidesGenerator.py | 4 ++--
 rpg/sequence.py               | 2 +-
 setup.py                      | 2 +-
 6 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/CHANGELOG.rst b/CHANGELOG.rst
index c6d894f..eabe21a 100644
--- a/CHANGELOG.rst
+++ b/CHANGELOG.rst
@@ -1,6 +1,11 @@
 =========
 CHANGELOG
 =========
+- `2.0.4 <https://gitlab.pasteur.fr/nmaillet/rpg/-/releases/2.0.4>`_
+    Modify precision of masses:
+    - 4 digits precision with average masses (default)
+    - 9 digits precision with monoisotopic masses
+
 - `2.0.3 <https://gitlab.pasteur.fr/nmaillet/rpg/-/releases/2.0.3>`_
     Tested on Python 3.12
 
diff --git a/docs/conf.py b/docs/conf.py
index ca44c9b..7485b6d 100644
--- a/docs/conf.py
+++ b/docs/conf.py
@@ -26,7 +26,7 @@ author = 'Nicolas Maillet'
 # The short X.Y version
 version = ''
 # The full version, including alpha/beta/rc tags
-release = '2.0.3'
+release = '2.0.4'
 
 
 # -- General configuration ---------------------------------------------------
diff --git a/docs/userguide.rst b/docs/userguide.rst
index 3a759d8..bffed92 100644
--- a/docs/userguide.rst
+++ b/docs/userguide.rst
@@ -333,7 +333,7 @@ Then, on the next line:
 
     - Peptide sequence
 
-Peptide molecular weight approximation is computed as the addition of average isotopic masses of each amino acid present in the peptide. Then the average isotopic mass of one water molecule is added to it. Molecular weight values are given in Dalton (Da). It does not take into consideration any digestion-induced modifications.
+Peptide molecular weight approximation is computed as the addition of average isotopic masses of each amino acid present in the peptide. Then the average isotopic mass of one water molecule is added to it. Molecular weight values are given in Dalton (Da). It does not take into consideration any digestion-induced modifications. Masses are either 4 digits precision (average masses) or 9 digits precision (monoisotopic masses).
 
 The isoelectric point is computed by solving Henderson–Hasselbalch equation using binary search. It is based on Lukasz P. Kozlowski work (http://isoelectric.org/index.html).
 
@@ -341,9 +341,9 @@ The default output is in multi-fasta format. The header then summarizes all this
 
 .. code-block:: shell
 
-    >Input_0_Asp-N_3_3_419.43738_5.54
+    >Input_0_Asp-N_3_3_419.4373_5.54
     QWS
-    >Input_1_Asp-N_8_5_742.78688_4.16
+    >Input_1_Asp-N_8_5_742.7868_4.16
     ...
 
 we can see that a sequence was directly inputed in **RPG** `(Input)`, the first peptide `(0)` was obtained with `Asp-N` and this enzyme cleaved after the `3rd` amino acid in the original sequence. The peptide has a size of `3` amino acids, a molecular weight estimated at `419.43738` Da and a theoretical isoelectric point of `5.54`. The full sequence is then written `(QWS)`. The output of the remaining peptides follows in the same format.
diff --git a/rpg/RapidPeptidesGenerator.py b/rpg/RapidPeptidesGenerator.py
index cb22ec6..4609153 100644
--- a/rpg/RapidPeptidesGenerator.py
+++ b/rpg/RapidPeptidesGenerator.py
@@ -29,9 +29,9 @@
 necessary functions
 """
 
-__version_info__ = ('2', '0', '3')
+__version_info__ = ('2', '0', '4')
 __version__ = '.'.join(__version_info__)
-__revision_date__ = "2023-12-18"
+__revision_date__ = "2024-06-11"
 __author__ = "Nicolas Maillet"
 
 import argparse
diff --git a/rpg/sequence.py b/rpg/sequence.py
index 3231134..374445c 100644
--- a/rpg/sequence.py
+++ b/rpg/sequence.py
@@ -69,7 +69,7 @@ class Peptide:
         tmp_mass = water_mass
         for i in sequence:
             tmp_mass += aa_mass[i]
-        self.mass = round(tmp_mass, 5)  # mass of the peptide
+        self.mass = round(tmp_mass, len(str(aa_mass["A"]).split(".")[1])) # mass of the peptide
         self.p_i = self.get_isoelectric_point()
 
     # self representation for print
diff --git a/setup.py b/setup.py
index d68354b..421933a 100644
--- a/setup.py
+++ b/setup.py
@@ -36,7 +36,7 @@ setup(
     # For a discussion on single-sourcing the version across setup.py and the
     # project code, see
     # https://packaging.python.org/en/latest/single_source_version.html
-    version='2.0.3',  # Required
+    version='2.0.4',  # Required
 
     # This is a one-line description or tagline of what your project does. This
     # corresponds to the "Summary" metadata field:
-- 
GitLab