From 3252eb6b6985e15fb789a7b1e7f0240723c88f45 Mon Sep 17 00:00:00 2001
From: Olivier Langella <olivier.langella@u-psud.fr>
Date: Thu, 13 Dec 2018 09:36:48 +0100
Subject: [PATCH] accept empty labels for unmodified peptides

---
 src/core/labeling/label.cpp          | 11 ++++++++++-
 src/core/labeling/label.h            |  1 +
 src/core/labeling/labelingmethod.cpp | 19 ++++++++++++++++++-
 src/core/labeling/labelingmethod.h   |  4 +++-
 src/core/peptidextp.cpp              |  2 +-
 src/core/peptidextp.h                |  2 +-
 src/resources/catalog_label.xml      |  2 ++
 7 files changed, 36 insertions(+), 5 deletions(-)

diff --git a/src/core/labeling/label.cpp b/src/core/labeling/label.cpp
index 4eb7b7b2..85b89639 100644
--- a/src/core/labeling/label.cpp
+++ b/src/core/labeling/label.cpp
@@ -85,7 +85,8 @@ Label::containsAaModificationP(
 {
   for(LabelModification label_modification : _modification_list)
     {
-      if(std::find(modification_set.begin(), modification_set.end(),
+      if(std::find(modification_set.begin(),
+                   modification_set.end(),
                    label_modification.modification) != modification_set.end())
         {
           return true;
@@ -142,3 +143,11 @@ Label::writeMassChroqMl(QXmlStreamWriter *output_stream) const
   //	</isotope_label>
   output_stream->writeEndElement();
 }
+
+bool
+Label::isEmpty() const
+{
+  if(_modification_list.size() == 0)
+    return true;
+  return false;
+}
diff --git a/src/core/labeling/label.h b/src/core/labeling/label.h
index ed21b41c..3adec8ca 100644
--- a/src/core/labeling/label.h
+++ b/src/core/labeling/label.h
@@ -57,6 +57,7 @@ class Label
   const QString &getXmlId() const;
 
   const std::vector<LabelModification> &getLabelModifictionList() const;
+  bool isEmpty() const;
 
   private:
   QString _xml_id;
diff --git a/src/core/labeling/labelingmethod.cpp b/src/core/labeling/labelingmethod.cpp
index aed64bb8..aa0bb6ec 100644
--- a/src/core/labeling/labelingmethod.cpp
+++ b/src/core/labeling/labelingmethod.cpp
@@ -70,17 +70,23 @@ LabelingMethod::LabelingMethod(const QString &method_id) : _xml_id(method_id)
 }
 
 
-Label *
+const Label *
 LabelingMethod::getLabel(
   const std::list<pappso::AaModificationP> &modification_set) const
 {
   for(Label *p_label : _label_list)
     {
+
       if(p_label->containsAaModificationP(modification_set))
         {
           return p_label;
         }
     }
+  auto p_empty_label = getEmptyLabel();
+  if(p_empty_label != nullptr)
+    {
+      return p_empty_label;
+    }
   return nullptr;
 }
 
@@ -152,3 +158,14 @@ LabelingMethod::getLabelList() const
 {
   return _label_list;
 }
+
+const Label *
+LabelingMethod::getEmptyLabel() const
+{
+  for(const Label *p_label : _label_list)
+    {
+      if(p_label->isEmpty())
+        return p_label;
+    }
+  return nullptr;
+}
diff --git a/src/core/labeling/labelingmethod.h b/src/core/labeling/labelingmethod.h
index e0b03080..abd8f4c6 100644
--- a/src/core/labeling/labelingmethod.h
+++ b/src/core/labeling/labelingmethod.h
@@ -47,12 +47,14 @@ class LabelingMethod
   LabelingMethod(const LabelingMethod &other);
   ~LabelingMethod();
   LabelingMethodSp makeLabelingMethodSp() const;
-  Label *
+  const Label *
   getLabel(const std::list<pappso::AaModificationP> &modification_set) const;
   const QString &getXmlId() const;
   void writeMassChroqMl(QXmlStreamWriter *output_stream) const;
   const std::vector<Label *> &getLabelList() const;
 
+  const Label *getEmptyLabel() const;
+
   private:
   void parseMethod(QDomNode &method_node);
   void parseLabel(QDomNode &method_node);
diff --git a/src/core/peptidextp.cpp b/src/core/peptidextp.cpp
index d4dd5d93..598a1222 100644
--- a/src/core/peptidextp.cpp
+++ b/src/core/peptidextp.cpp
@@ -127,7 +127,7 @@ PeptideXtp::applyLabelingMethod(LabelingMethodSp labeling_method_sp)
   modification_set.unique();
 
   _p_label       = nullptr;
-  Label *p_label = labeling_method_sp.get()->getLabel(modification_set);
+  const Label *p_label = labeling_method_sp.get()->getLabel(modification_set);
   if(p_label != nullptr)
     {
       _p_label           = p_label;
diff --git a/src/core/peptidextp.h b/src/core/peptidextp.h
index a1539d67..dc545559 100644
--- a/src/core/peptidextp.h
+++ b/src/core/peptidextp.h
@@ -77,7 +77,7 @@ class PeptideXtp : public pappso::Peptide
    */
   pappso::PeptideSp _sp_native_peptide = nullptr;
 
-  Label *_p_label = nullptr;
+  const Label *_p_label = nullptr;
 };
 
 #endif // PEPTIDEXTP_H
diff --git a/src/resources/catalog_label.xml b/src/resources/catalog_label.xml
index 99efc420..7adf2ad3 100644
--- a/src/resources/catalog_label.xml
+++ b/src/resources/catalog_label.xml
@@ -22,5 +22,7 @@
     		<mod at="R" value="6.02" acc="MOD:01331"/>
     		<mod at="K" value="4.01" acc="MOD:00942"/>
     	</isotope_label>
+        <isotope_label id="light">
+    	</isotope_label>
     </isotope_label_list>
 </catalog>
-- 
GitLab