From 38988efcb66ba08330823f18baebcdebfbbced57 Mon Sep 17 00:00:00 2001
From: Olivier Langella <Olivier.Langella@moulon.inra.fr>
Date: Sat, 20 May 2017 23:38:07 +0200
Subject: [PATCH] new labeling method object

---
 src/CMakeLists.txt                            |  2 +
 src/core/labeling/label.cpp                   | 64 ++++++++++++++
 src/core/labeling/label.h                     | 54 ++++++++++++
 src/core/labeling/labelingmethod.cpp          | 86 +++++++++++++++++++
 src/core/labeling/labelingmethod.h            | 56 ++++++++++++
 .../edit_label_methods/editlabelmethods.cpp   |  3 +
 src/resources/catalog_label.xml               |  8 +-
 7 files changed, 269 insertions(+), 4 deletions(-)
 create mode 100644 src/core/labeling/label.cpp
 create mode 100644 src/core/labeling/label.h
 create mode 100644 src/core/labeling/labelingmethod.cpp
 create mode 100644 src/core/labeling/labelingmethod.h

diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index b406d160a..8a859d1ee 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -54,6 +54,8 @@ SET(CPP_FILES
   core/identificationgroup.cpp
   core/identification_sources/identificationdatasource.cpp
   core/identification_sources/identificationxtandemfile.cpp
+  core/labeling/label.cpp
+  core/labeling/labelingmethod.cpp
   core/msrun.cpp
   core/peptidematch.cpp
   core/peptidextp.cpp
diff --git a/src/core/labeling/label.cpp b/src/core/labeling/label.cpp
new file mode 100644
index 000000000..f050050e3
--- /dev/null
+++ b/src/core/labeling/label.cpp
@@ -0,0 +1,64 @@
+/**
+ * \file core/label.cpp
+ * \date 20/5/2017
+ * \author Olivier Langella
+ * \brief description of a label
+ */
+
+/*******************************************************************************
+* Copyright (c) 2017 Olivier Langella <olivier.langella@u-psud.fr>.
+*
+* This file is part of XTPcpp.
+*
+*     XTPcpp is free software: you can redistribute it and/or modify
+*     it under the terms of the GNU General Public License as published by
+*     the Free Software Foundation, either version 3 of the License, or
+*     (at your option) any later version.
+*
+*     XTPcpp is distributed in the hope that it will be useful,
+*     but WITHOUT ANY WARRANTY; without even the implied warranty of
+*     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+*     GNU General Public License for more details.
+*
+*     You should have received a copy of the GNU General Public License
+*     along with XTPcpp.  If not, see <http://www.gnu.org/licenses/>.
+*
+* Contributors:
+*     Olivier Langella <olivier.langella@u-psud.fr> - initial API and implementation
+******************************************************************************/
+
+#include "label.h"
+#include <pappsomspp/amino_acid/aamodification.h>
+#include <pappsomspp/pappsoexception.h>
+#include <QDebug>
+
+Label::Label(QDomNode & label_node) {
+    //<isotope_label id="light">
+    _xml_id =label_node.toElement().attribute("id");
+    qDebug() <<"Label::Label begin "<<_xml_id;
+    try {
+        //<mod at="Nter" value="28.0" acc="MOD:00429"/>
+        //<mod at="K" value="28.0" acc="MOD:00429"/>
+        QDomNode child = label_node.firstChild();
+        while (!child.isNull()) {
+            if (child.toElement().tagName() == "mod") {
+                if (child.toElement().attribute("acc").isEmpty()) {
+                    throw pappso::PappsoException(QObject::tr("acc attribute is empty : PSIMOD accession required"));
+                }
+                qDebug() <<"Label::Label mod at="<<child.toElement().attribute("at") << " mod="<< child.toElement().attribute("acc");
+                LabelModification label_modification = {child.toElement().attribute("at"), pappso::AaModification::getInstance( child.toElement().attribute("acc"))};
+                _modification_list.push_back (label_modification);
+            }
+            child = child.nextSibling();
+        }
+    }
+    catch (pappso::PappsoException error) {
+        throw pappso::PappsoException(QObject::tr("error creating Label : %1").arg(error.qwhat()));
+    }
+}
+
+
+Label::Label( const Label & other) {
+    _xml_id = other._xml_id;
+    _modification_list = other._modification_list;
+}
diff --git a/src/core/labeling/label.h b/src/core/labeling/label.h
new file mode 100644
index 000000000..c4b017005
--- /dev/null
+++ b/src/core/labeling/label.h
@@ -0,0 +1,54 @@
+/**
+ * \file core/label.h
+ * \date 20/5/2017
+ * \author Olivier Langella
+ * \brief description of a label
+ */
+
+/*******************************************************************************
+* Copyright (c) 2017 Olivier Langella <olivier.langella@u-psud.fr>.
+*
+* This file is part of XTPcpp.
+*
+*     XTPcpp is free software: you can redistribute it and/or modify
+*     it under the terms of the GNU General Public License as published by
+*     the Free Software Foundation, either version 3 of the License, or
+*     (at your option) any later version.
+*
+*     XTPcpp is distributed in the hope that it will be useful,
+*     but WITHOUT ANY WARRANTY; without even the implied warranty of
+*     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+*     GNU General Public License for more details.
+*
+*     You should have received a copy of the GNU General Public License
+*     along with XTPcpp.  If not, see <http://www.gnu.org/licenses/>.
+*
+* Contributors:
+*     Olivier Langella <olivier.langella@u-psud.fr> - initial API and implementation
+******************************************************************************/
+
+#ifndef LABEL_H
+#define LABEL_H
+#include <QString>
+#include <vector>
+#include <QDomNode>
+#include <pappsomspp/amino_acid/aamodification.h>
+
+
+struct LabelModification {
+    QString at;
+    pappso::AaModificationP modification;
+};
+
+
+class Label
+{
+public:
+    Label(QDomNode & method_node);
+    Label( const Label & other);
+private:
+    QString _xml_id;
+    std::vector<LabelModification> _modification_list;
+};
+
+#endif // LABEL_H
diff --git a/src/core/labeling/labelingmethod.cpp b/src/core/labeling/labelingmethod.cpp
new file mode 100644
index 000000000..7dbd0afdc
--- /dev/null
+++ b/src/core/labeling/labelingmethod.cpp
@@ -0,0 +1,86 @@
+/**
+ * \file core/labelingmethod.cpp
+ * \date 20/5/2017
+ * \author Olivier Langella
+ * \brief labeling method
+ */
+
+/*******************************************************************************
+* Copyright (c) 2017 Olivier Langella <olivier.langella@u-psud.fr>.
+*
+* This file is part of XTPcpp.
+*
+*     XTPcpp is free software: you can redistribute it and/or modify
+*     it under the terms of the GNU General Public License as published by
+*     the Free Software Foundation, either version 3 of the License, or
+*     (at your option) any later version.
+*
+*     XTPcpp is distributed in the hope that it will be useful,
+*     but WITHOUT ANY WARRANTY; without even the implied warranty of
+*     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+*     GNU General Public License for more details.
+*
+*     You should have received a copy of the GNU General Public License
+*     along with XTPcpp.  If not, see <http://www.gnu.org/licenses/>.
+*
+* Contributors:
+*     Olivier Langella <olivier.langella@u-psud.fr> - initial API and implementation
+******************************************************************************/
+
+#include "labelingmethod.h"
+#include <pappsomspp/pappsoexception.h>
+#include <QFile>
+#include <QDomDocument>
+
+LabelingMethod::LabelingMethod(const QString & method_id):_xml_id(method_id) {
+
+    qDebug() <<"LabelingMethod::LabelingMethod begin "<<_xml_id;
+    QDomDocument *dom = new QDomDocument("labeling_methods");
+    QFile xml_doc(":/labeling/resources/catalog_label.xml");
+    if(!xml_doc.open(QIODevice::ReadOnly))
+    {
+        //error
+        throw pappso::PappsoException(QObject::tr("error opening catalog_label resource file"));
+    }
+    if (!dom->setContent(&xml_doc)) {
+        xml_doc.close();
+        throw pappso::PappsoException(QObject::tr("error opening catalog_label xml content"));
+    }
+
+    QDomNode child = dom->documentElement().firstChild();
+    while (!child.isNull()) {
+        if (child.toElement().tagName() == "isotope_label_list") {
+            if (child.toElement().attribute("id")== _xml_id) {
+                parseMethod(child);
+            }
+        }
+        child = child.nextSibling();
+    }
+
+    xml_doc.close();
+    delete dom;
+}
+
+LabelingMethod::LabelingMethod( const LabelingMethod & other):_xml_id(other._xml_id) {
+    for (Label * p_label: other._label_list) {
+        _label_list.push_back( new Label(*p_label));
+    }
+}
+LabelingMethod::~LabelingMethod() {
+    for (Label * p_label: _label_list) {
+        delete p_label;
+    }
+}
+
+LabelingMethodSp LabelingMethod::makeLabelingMethodSp() const {
+    return std::make_shared<LabelingMethod>(*this);
+}
+void LabelingMethod::parseMethod(QDomNode & method_node) {
+    QDomNode child = method_node.firstChild();
+    while (!child.isNull()) {
+        if (child.toElement().tagName() == "isotope_label") {
+            _label_list.push_back( new Label(child));
+        }
+        child = child.nextSibling();
+    }
+}
diff --git a/src/core/labeling/labelingmethod.h b/src/core/labeling/labelingmethod.h
new file mode 100644
index 000000000..909ccd5cc
--- /dev/null
+++ b/src/core/labeling/labelingmethod.h
@@ -0,0 +1,56 @@
+/**
+ * \file core/labelingmethod.h
+ * \date 20/5/2017
+ * \author Olivier Langella
+ * \brief labeling method
+ */
+
+/*******************************************************************************
+* Copyright (c) 2017 Olivier Langella <olivier.langella@u-psud.fr>.
+*
+* This file is part of XTPcpp.
+*
+*     XTPcpp is free software: you can redistribute it and/or modify
+*     it under the terms of the GNU General Public License as published by
+*     the Free Software Foundation, either version 3 of the License, or
+*     (at your option) any later version.
+*
+*     XTPcpp is distributed in the hope that it will be useful,
+*     but WITHOUT ANY WARRANTY; without even the implied warranty of
+*     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+*     GNU General Public License for more details.
+*
+*     You should have received a copy of the GNU General Public License
+*     along with XTPcpp.  If not, see <http://www.gnu.org/licenses/>.
+*
+* Contributors:
+*     Olivier Langella <olivier.langella@u-psud.fr> - initial API and implementation
+******************************************************************************/
+
+#ifndef LABELINGMETHOD_H
+#define LABELINGMETHOD_H
+#include <QString>
+#include <QDomNode>
+#include <vector>
+#include <memory>
+#include "label.h"
+
+class LabelingMethod;
+typedef std::shared_ptr<LabelingMethod> LabelingMethodSp;
+
+class LabelingMethod
+{
+    public:
+    LabelingMethod(const QString & method_id);
+    LabelingMethod( const LabelingMethod & other);
+    ~LabelingMethod();
+    LabelingMethodSp makeLabelingMethodSp() const;
+private :
+    void parseMethod(QDomNode & method_node);
+    void parseLabel(QDomNode & method_node);
+private:
+    const QString _xml_id;
+    std::vector<Label *> _label_list;
+};
+
+#endif // LABELINGMETHOD_H
diff --git a/src/gui/edit_label_methods/editlabelmethods.cpp b/src/gui/edit_label_methods/editlabelmethods.cpp
index 8dfe8a9a5..bbc94d652 100644
--- a/src/gui/edit_label_methods/editlabelmethods.cpp
+++ b/src/gui/edit_label_methods/editlabelmethods.cpp
@@ -27,6 +27,7 @@
 #include <QFile>
 #include <QDomDocument>
 #include <QMessageBox>
+#include "../../core/labeling/labelingmethod.h"
 
 EditLabelMethods::EditLabelMethods(ProjectWindow *parent):
     QDialog(parent),
@@ -97,6 +98,8 @@ void EditLabelMethods::ItemClicked (QModelIndex index )
 {
     qDebug() << "EditLabelMethods::ItemClicked begin" << index.data().toString();
     ui->ok_button->setDisabled(false);
+    
+    LabelingMethod method(index.data().toString());
 }
 
 
diff --git a/src/resources/catalog_label.xml b/src/resources/catalog_label.xml
index dff26d517..0da0a47b4 100644
--- a/src/resources/catalog_label.xml
+++ b/src/resources/catalog_label.xml
@@ -5,12 +5,12 @@
     		<mod at="K" value="28.0" acc="MOD:00429"/>
     	</isotope_label>
     	<isotope_label id="inter">
-    		<mod at="Nter" value="32.0" />
-    		<mod at="K" value="32.0" />
+    		<mod at="Nter" value="32.0" acc="MOD:00552"/>
+    		<mod at="K" value="32.0" acc="MOD:00552"/>
     	</isotope_label>
         <isotope_label id="heavy">
-    		<mod at="Nter" value="36.0" />
-    		<mod at="K" value="36.0" />
+    		<mod at="Nter" value="36.0" acc="MOD:00638"/>
+    		<mod at="K" value="36.0" acc="MOD:00638"/>
     	</isotope_label>
     </isotope_label_list>
 </catalog>
-- 
GitLab