From 4391a47c305d105bdeef9e47352caf8b68f2c86d Mon Sep 17 00:00:00 2001
From: Olivier Langella <Olivier.Langella@moulon.inra.fr>
Date: Thu, 6 Apr 2017 22:42:47 +0200
Subject: [PATCH] get protein match instance

---
 src/CMakeLists.txt               |  4 ++--
 src/core/identificationgroup.cpp | 24 ++++++------------------
 src/core/identificationgroup.h   |  3 +--
 src/core/peptidematch.cpp        |  2 +-
 src/core/peptidematch.h          |  2 +-
 src/input/xtandemsaxhandler.cpp  | 14 ++++----------
 6 files changed, 15 insertions(+), 34 deletions(-)

diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 42d4fb8f..9d83c283 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -29,8 +29,8 @@ SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt5Xml_EXECUTABLE_COMPILE_FLAGS} ${Qt5
 
 #sudo apt-get install libpappsomspp-dev
 #FIND_PACKAGE( Pappsomspp REQUIRED )
-# SET (PAPPSOMSPP_DIR  "/home/olivier/eclipse/git/pappsomspp")
- SET (PAPPSOMSPP_DIR  "/home/langella/developpement/git/pappsomspp")
+ SET (PAPPSOMSPP_DIR  "/home/olivier/eclipse/git/pappsomspp")
+# SET (PAPPSOMSPP_DIR  "/home/langella/developpement/git/pappsomspp")
  SET (PAPPSOMSPP_INCLUDE_DIR "${PAPPSOMSPP_DIR}/src")
  SET (PAPPSOMSPP_QT4_LIBRARY "${PAPPSOMSPP_DIR}/cbuild/src/libpappsomspp-qt4.so")
 
diff --git a/src/core/identificationgroup.cpp b/src/core/identificationgroup.cpp
index dcbf38ed..a56976d9 100644
--- a/src/core/identificationgroup.cpp
+++ b/src/core/identificationgroup.cpp
@@ -50,19 +50,17 @@ void IdentificationGroup::updateAutomaticFilters(const AutomaticFilterParameters
     }
 
 }
-ProteinMatch * IdentificationGroup::getProteinMatch(const QString accession) {
+ProteinMatch * IdentificationGroup::getProteinMatchInstance(const QString accession) {
     if (accession.isEmpty()) {
         throw pappso::PappsoException(QObject::tr("Error protein match not found : accession is empty"));
     }
     auto it_cache = _cache_accession_protein_match.find(accession);
     if (it_cache == _cache_accession_protein_match.end()) {
         //accession not found in cache
-        for (ProteinMatch * p_protein_match : _protein_match_list) {
-            if (p_protein_match->getProteinXtpSp().get()->getAccession() == accession) {
-                _cache_accession_protein_match.insert(std::pair<QString, ProteinMatch *>(accession, p_protein_match));
-                return p_protein_match;
-            }
-        }
+        ProteinMatch * p_protein_match = new ProteinMatch();
+        _cache_accession_protein_match.insert(std::pair<QString, ProteinMatch *>(accession, p_protein_match));
+        _protein_match_list.push_back(p_protein_match);
+        return p_protein_match;
     }
     else {
         return it_cache->second;
@@ -70,17 +68,7 @@ ProteinMatch * IdentificationGroup::getProteinMatch(const QString accession) {
     return nullptr;
 }
 void IdentificationGroup::addProteinMatch(ProteinMatch * protein_match) {
-    QString accession = protein_match->getProteinXtpSp().get()->getAccession();
-    if (accession.isEmpty()) {
-        throw pappso::PappsoException(QObject::tr("Error adding protein match : accession is empty"));
-    }
-    auto it_cache = _cache_already_added_protein_match.find(protein_match);
-    if (it_cache == _cache_already_added_protein_match.end()) {
-        //accession not found in cache
-        _cache_already_added_protein_match.insert(protein_match);
-        _protein_match_list.push_back(protein_match);
-    }
-
+    _protein_match_list.push_back(protein_match);
 }
 
 bool IdentificationGroup::contains (const MsRun * p_msrun) const {
diff --git a/src/core/identificationgroup.h b/src/core/identificationgroup.h
index 279b7a8b..27986627 100644
--- a/src/core/identificationgroup.h
+++ b/src/core/identificationgroup.h
@@ -44,7 +44,7 @@ public:
     IdentificationGroup(Project * project);
     ~IdentificationGroup();
 
-    ProteinMatch * getProteinMatch(const QString accession);
+    ProteinMatch * getProteinMatchInstance(const QString accession);
     void addProteinMatch(ProteinMatch * protein_match);
     std::vector<ProteinMatch *> & getProteinMatchList();
     void addMsRunSp(MsRunSp ms_run_sp);
@@ -95,7 +95,6 @@ private :
     std::vector<MsRunSp> _ms_run_list;
     
     std::map<QString, ProteinMatch *> _cache_accession_protein_match;
-    std::set<ProteinMatch *> _cache_already_added_protein_match;
 };
 
 #endif // IDENTIFICATIONGROUP_H
diff --git a/src/core/peptidematch.cpp b/src/core/peptidematch.cpp
index faba2b9a..c95a4d48 100644
--- a/src/core/peptidematch.cpp
+++ b/src/core/peptidematch.cpp
@@ -52,7 +52,7 @@ void PeptideMatch::setStart(unsigned int start) {
     _start =start;
 }
 pappso::mz PeptideMatch::getDeltaMass() const {
-    return (_exp_mass - _peptide_sp.get()->getMass());
+    return ((_exp_mass+pappso::MHPLUS) - _peptide_sp.get()->getMz(1));
 }
 unsigned int PeptideMatch::getStart() const {
     return _start;
diff --git a/src/core/peptidematch.h b/src/core/peptidematch.h
index 49c58b63..bd150ed5 100644
--- a/src/core/peptidematch.h
+++ b/src/core/peptidematch.h
@@ -72,7 +72,7 @@ public :
      * */
     void updateAutomaticFilters(const AutomaticFilterParameters & automatic_filter_parameters);
     
-    /** @brief get delta between theoretical mass and experimental mass
+    /** @brief get delta between theoretical mhplus mass and mhplus experimental mass
       */
     pappso::mz getDeltaMass() const;
 
diff --git a/src/input/xtandemsaxhandler.cpp b/src/input/xtandemsaxhandler.cpp
index 0f63fe24..001cb943 100644
--- a/src/input/xtandemsaxhandler.cpp
+++ b/src/input/xtandemsaxhandler.cpp
@@ -132,7 +132,7 @@ bool XtandemSaxHandler::startElement_group(QXmlAttributes attrs) {
         _scan = attrs.value("id").toUInt();
         _mhplus_obser = attrs.value("mh").toDouble();
         _charge = attrs.value("z").toUInt();
-        //_retention_time = attrs.value("rt");
+        _retention_time = attrs.value("rt").replace("PT","").replace("S","").toDouble();
     }
     return is_ok;
 }
@@ -156,22 +156,16 @@ bool XtandemSaxHandler::startElement_protein(QXmlAttributes attributes) {
     //qDebug() << "startElement_protein begin";
     QString accession = attributes.value("label").simplified().split(" ", QString::SkipEmptyParts).at(0);
     //qDebug() << "startElement_protein accession" << accession;
-    _p_protein_match = _p_identification_group->getProteinMatch(accession);
+    _p_protein_match = _p_identification_group->getProteinMatchInstance(accession);
 
     //qDebug() << "startElement_protein p_protein_match 1 " << _p_protein_match;
     _current_protein.setAccession(accession);
-    if (_p_protein_match == nullptr) {
-        _p_protein_match = new ProteinMatch();
-        //qDebug() << "startElement_protein p_protein_match 2 " << _p_protein_match;
-        _p_protein_match->setChecked(false);
-
-    }
+    _p_protein_match->setChecked(false);
     //qDebug() << "startElement_protein p_protein_match 3 " << _p_protein_match;
     ProteinXtpSp sp_xtp_protein = _current_protein.makeProteinXtpSp();
     _p_protein_match->setProteinXtpSp(_p_project->getProteinStore().getInstance(sp_xtp_protein));
     _p_protein_match->setChecked(true);
 
-    _p_identification_group->addProteinMatch(_p_protein_match);
     //qDebug() << "startElement_protein end" ;
     return is_ok;
 }
@@ -247,7 +241,7 @@ bool XtandemSaxHandler::startElement_aa(QXmlAttributes attributes) {
 }
 
 bool XtandemSaxHandler::endElement_domain() {
-   bool is_ok = true;
+    bool is_ok = true;
     _current_peptide_sp = _p_project->getPeptideStore().getInstance(_current_peptide_sp);
 
     _p_peptide_match->setPeptideXtpSp(_current_peptide_sp);
-- 
GitLab