From 69f3124c93a5ed87b94154e28ff4dabadf9739e5 Mon Sep 17 00:00:00 2001
From: Olivier Langella <olivier.langella@u-psud.fr>
Date: Wed, 22 Nov 2017 16:26:51 +0100
Subject: [PATCH] xtpcpp (0.2.1-1) stretch

---
 CMakeLists.txt                                |  4 +-
 debian/changelog                              |  8 ++
 .../identificationdatasource.cpp              |  4 +-
 .../identificationdatasource.h                |  1 +
 src/core/proteinmatch.cpp                     |  2 +-
 src/output/xpip.cpp                           | 92 ++++++++++---------
 src/output/xpip.h                             |  5 +-
 src/utils/peptideevidencestore.cpp            |  9 +-
 src/utils/peptideevidencestore.h              |  2 +
 9 files changed, 78 insertions(+), 49 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 3065fb150..d1392e063 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -40,8 +40,8 @@ configure_file (${CMAKE_SOURCE_DIR}/debian/control.cmake ${CMAKE_SOURCE_DIR}/deb
 SET(SOFTWARE_NAME "XTPcpp")
 
 SET(XTPCPP_VERSION_MAJOR "0")
-SET(XTPCPP_VERSION_MINOR "1")
-SET(XTPCPP_VERSION_PATCH "23")
+SET(XTPCPP_VERSION_MINOR "2")
+SET(XTPCPP_VERSION_PATCH "1")
 SET(XTPCPP_VERSION "${XTPCPP_VERSION_MAJOR}.${XTPCPP_VERSION_MINOR}.${XTPCPP_VERSION_PATCH}")
 
 # Set the CMAKE_PREFIX_PATH for the find_library fonction when using non
diff --git a/debian/changelog b/debian/changelog
index 0943b2310..467b8764a 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,11 @@
+xtpcpp (0.2.1-1) stretch; urgency=medium
+
+  * huge refactoring
+  * new xpip output file
+  * clear mz file list in tandem run dialog
+
+ -- Olivier Langella <olivier.langella@u-psud.fr>  Wed, 22 Nov 2017 15:56:02 +0100
+
 xtpcpp (0.1.23-1) stretch; urgency=medium
 
   * better ODS and XPIP file
diff --git a/src/core/identification_sources/identificationdatasource.cpp b/src/core/identification_sources/identificationdatasource.cpp
index b06ae4d94..3736af228 100644
--- a/src/core/identification_sources/identificationdatasource.cpp
+++ b/src/core/identification_sources/identificationdatasource.cpp
@@ -43,7 +43,9 @@ IdentificationDataSource::~IdentificationDataSource()
 {
 
 }
-
+const PeptideEvidenceStore & IdentificationDataSource::getPeptideEvidenceStore() const {
+    return _peptide_evidence_store;
+}
 PeptideEvidenceStore & IdentificationDataSource::getPeptideEvidenceStore() {
     return _peptide_evidence_store;
 }
diff --git a/src/core/identification_sources/identificationdatasource.h b/src/core/identification_sources/identificationdatasource.h
index f83588031..30ca866e0 100644
--- a/src/core/identification_sources/identificationdatasource.h
+++ b/src/core/identification_sources/identificationdatasource.h
@@ -47,6 +47,7 @@ public:
     bool operator==(const IdentificationDataSource& other) const;
     
     PeptideEvidenceStore & getPeptideEvidenceStore();
+    const PeptideEvidenceStore & getPeptideEvidenceStore() const;
     
     void setXmlId(const QString xmlid);
     const QString & getXmlId() const;
diff --git a/src/core/proteinmatch.cpp b/src/core/proteinmatch.cpp
index e79fdfc1b..392ef2885 100644
--- a/src/core/proteinmatch.cpp
+++ b/src/core/proteinmatch.cpp
@@ -128,7 +128,7 @@ void ProteinMatch::setChecked(bool arg1) {
 }
 
 void ProteinMatch::addPeptideMatch(const PeptideMatch & peptide_match) {
-    qDebug() << "ProteinMatch::addPeptideMatch begin " << peptide_match.getPeptideEvidence()->getPeptideXtpSp().get()->toAbsoluteString(); 
+    //qDebug() << "ProteinMatch::addPeptideMatch begin " << peptide_match.getPeptideEvidence()->getPeptideXtpSp().get()->toAbsoluteString(); 
     _peptide_match_list.push_back(peptide_match);
 }
 
diff --git a/src/output/xpip.cpp b/src/output/xpip.cpp
index 1d1edf391..43d56b1ff 100644
--- a/src/output/xpip.cpp
+++ b/src/output/xpip.cpp
@@ -365,26 +365,63 @@ void Xpip::writeIdentificationGroupList() {
     qDebug() << "Xpip::writeIdentificationGroupList end";
 }
 
-void Xpip::dedupPeptideMatch(const IdentificationGroup * p_identification_group) {
-    qDebug() << "Xpip::dedupPeptideMatch begin";
-    
-    qDebug() << "Xpip::dedupPeptideMatch end";
+void Xpip::writePeptideEvidence(const PeptideEvidence * p_peptide_evidence) {
+    qDebug() << "Xpip::writePeptideEvidence begin";
+
+    _output_stream->writeStartElement("peptide_evidence");
+    QString idp = QString("pe%1").arg(pappso::Utils::getLexicalOrderedString(_map_peptide_evidences.size()+1));
+    _map_peptide_evidences.insert(std::pair<const PeptideEvidence *, QString>(p_peptide_evidence, idp));
+    _output_stream->writeAttribute("id",idp);
+
+    _output_stream->writeAttribute("source_id",p_peptide_evidence->getIdentificationDataSource()->getXmlId());
+    //_output_stream->writeAttribute("ms_id",p_peptide_match->getMsRunP()->getXmlId());
+    _output_stream->writeAttribute("peptide_id",_map_peptides.at( p_peptide_evidence->getPeptideXtpSp().get()));
+    _output_stream->writeAttribute("scan",QString("%1").arg(p_peptide_evidence->getScan()));
+    writeDoubleAttribute("rt",p_peptide_evidence->getRetentionTime());
+    writeDoubleAttribute("evalue",p_peptide_evidence->getEvalue());
+    writeDoubleAttribute("exp_mass",p_peptide_evidence->getExperimentalMass());
+    _output_stream->writeAttribute("charge",QString("%1").arg(p_peptide_evidence->getCharge()));
+
+    if (p_peptide_evidence->isChecked()) {
+        _output_stream->writeAttribute("checked","true");
+    }
+    else {
+        _output_stream->writeAttribute("checked","false");
+    }
+
+    const std::map<PeptideMatchParam, QVariant> & params = p_peptide_evidence->getParamList();
+
+    //if (params.size() > 0) {
+    //   _output_stream->writeStartElement("stats");
+    for (const std::pair<PeptideMatchParam, QVariant> param_pair: params) {
+        _output_stream->writeStartElement("param");
+        _output_stream->writeAttribute("key",QString("%1").arg(static_cast<std::int8_t>(param_pair.first)));
+        _output_stream->writeAttribute("value",param_pair.second.toString());
+        _output_stream->writeEndElement();
+    }
+    //   _output_stream->writeEndElement();
+    _output_stream->writeEndElement(); //peptide_evidence
+    qDebug() << "Xpip::writePeptideEvidence end";
 }
 
-void Xpip::writeUniquePeptideMatch(const IdentificationGroup * p_identification_group) {
-    qDebug() << "Xpip::writeUniquePeptideMatch begin";
-    
-    dedupPeptideMatch(p_identification_group);
-    
-    _output_stream->writeStartElement("peptide_match_list");
-    _output_stream->writeEndElement(); //peptide_match_list
-    qDebug() << "Xpip::writeUniquePeptideMatch end";
+void Xpip::writePeptideEvidenceList(const IdentificationGroup * p_identification_group) {
+    qDebug() << "Xpip::writePeptideEvidenceList begin";
+
+    _output_stream->writeStartElement("peptide_evidence_list");
+    for (const IdentificationDataSource * p_ident_source : p_identification_group->getIdentificationDataSourceList()) {
+        for (const PeptideEvidenceSp & sp_peptide_evidence:p_ident_source->getPeptideEvidenceStore().getPeptideEvidenceList()) {
+            writePeptideEvidence(sp_peptide_evidence.get());
+        }
+    }
+
+    _output_stream->writeEndElement(); //peptide_evidence_list
+    qDebug() << "Xpip::writePeptideEvidenceList end";
 }
 
 void Xpip::writeIdentificationGroup(const IdentificationGroup * p_identification_group) {
     qDebug() << "Xpip::writeIdentificationGroup begin";
     _output_stream->writeStartElement("identification_group");
-    writeUniquePeptideMatch(p_identification_group);
+    writePeptideEvidenceList(p_identification_group);
     _output_stream->writeStartElement("protein_match_list");
     for (const ProteinMatch * p_protein_match : p_identification_group->getProteinMatchList()) {
         //std::vector<ProteinMatch *> & getProteinMatchList()
@@ -409,35 +446,8 @@ void Xpip::writeIdentificationGroup(const IdentificationGroup * p_identification
 void Xpip::writePeptideMatch(const PeptideMatch & peptide_match) {
     qDebug() << "Xpip::writePeptideMatch begin";
     _output_stream->writeStartElement("peptide_match");
-    _output_stream->writeAttribute("source_id",peptide_match.getPeptideEvidence()->getIdentificationDataSource()->getXmlId());
-    //_output_stream->writeAttribute("ms_id",p_peptide_match->getMsRunP()->getXmlId());
-    _output_stream->writeAttribute("peptide_id",_map_peptides.at( peptide_match.getPeptideEvidence()->getPeptideXtpSp().get()));
-    _output_stream->writeAttribute("scan",QString("%1").arg(peptide_match.getPeptideEvidence()->getScan()));
-    writeDoubleAttribute("rt",peptide_match.getPeptideEvidence()->getRetentionTime());
-    writeDoubleAttribute("evalue",peptide_match.getPeptideEvidence()->getEvalue());
-    writeDoubleAttribute("exp_mass",peptide_match.getPeptideEvidence()->getExperimentalMass());
+    _output_stream->writeAttribute("peptide_evidence_id",_map_peptide_evidences.at( peptide_match.getPeptideEvidence()));
     _output_stream->writeAttribute("start",QString("%1").arg(peptide_match.getStart()));
-    _output_stream->writeAttribute("charge",QString("%1").arg(peptide_match.getPeptideEvidence()->getCharge()));
-
-    if (peptide_match.getPeptideEvidence()->isChecked()) {
-        _output_stream->writeAttribute("checked","true");
-    }
-    else {
-        _output_stream->writeAttribute("checked","false");
-    }
-
-    const std::map<PeptideMatchParam, QVariant> & params = peptide_match.getPeptideEvidence()->getParamList();
-
-    //if (params.size() > 0) {
-    //   _output_stream->writeStartElement("stats");
-    for (const std::pair<PeptideMatchParam, QVariant> param_pair: params) {
-        _output_stream->writeStartElement("param");
-        _output_stream->writeAttribute("key",QString("%1").arg(static_cast<std::int8_t>(param_pair.first)));
-        _output_stream->writeAttribute("value",param_pair.second.toString());
-        _output_stream->writeEndElement();
-    }
-    //   _output_stream->writeEndElement();
-    //}
 
     _output_stream->writeEndElement(); //protein_match_list
     qDebug() << "Xpip::writePeptideMatch end";
diff --git a/src/output/xpip.h b/src/output/xpip.h
index 169719c9b..55924037e 100644
--- a/src/output/xpip.h
+++ b/src/output/xpip.h
@@ -59,9 +59,9 @@ private :
     void writeLabelingMethod();
     void writeIdentificationGroupList();
     void writeIdentificationGroup(const IdentificationGroup * p_identification_group);
-    void dedupPeptideMatch(const IdentificationGroup * p_identification_group);
-    void writeUniquePeptideMatch(const IdentificationGroup * p_identification_group);
+    void writePeptideEvidenceList(const IdentificationGroup * p_identification_group);
     void writePeptideMatch(const PeptideMatch & peptide_match);
+    void writePeptideEvidence(const PeptideEvidence * p_peptide_evidence);
 
     QString getPeptideId(std::size_t crc_peptide) const;
 
@@ -72,6 +72,7 @@ private :
     
     std::map<pappso::AaModificationP, QString> _map_modifications;
     std::map<const PeptideXtp *, QString> _map_peptides;
+    std::map<const PeptideEvidence *, QString> _map_peptide_evidences;
 
 };
 
diff --git a/src/utils/peptideevidencestore.cpp b/src/utils/peptideevidencestore.cpp
index 34384227a..e43b819d1 100644
--- a/src/utils/peptideevidencestore.cpp
+++ b/src/utils/peptideevidencestore.cpp
@@ -36,7 +36,7 @@
 
 std::shared_ptr<PeptideEvidence> & PeptideEvidenceStore::getInstance(const PeptideEvidence * p_peptide_evidence) {
 
-    qDebug() << "PeptideEvidenceStore::getInstance begin" ;
+    //qDebug() << "PeptideEvidenceStore::getInstance begin" ;
     std::multimap<unsigned int ,PeptideEvidenceSp>::iterator it = _multimap_scan_evidence.find(p_peptide_evidence->getScan());
     std::multimap<unsigned int ,PeptideEvidenceSp>::iterator find_it = _multimap_scan_evidence.end();
 
@@ -54,16 +54,21 @@ std::shared_ptr<PeptideEvidence> & PeptideEvidenceStore::getInstance(const Pepti
         find_it = _multimap_scan_evidence.insert(std::pair<unsigned int , PeptideEvidenceSp>(p_peptide_evidence->getScan(), p_peptide_evidence->makePeptideEvidenceSp()));
         _peptide_evidence_list.push_back(find_it->second);
     }
-    qDebug() << "PeptideEvidenceStore::getInstance end " << find_it->second.get()->getScan() << " size=" << _multimap_scan_evidence.size();
+    //qDebug() << "PeptideEvidenceStore::getInstance end " << find_it->second.get()->getScan() << " size=" << _multimap_scan_evidence.size();
     return find_it->second;
 
 }
 
 void PeptideEvidenceStore::updateAutomaticFilters(const AutomaticFilterParameters & automatic_filter_parameters) {
     qDebug() << "PeptideEvidenceStore::updateAutomaticFilters begin" ;
+    _multimap_scan_evidence.clear();
     for (PeptideEvidenceSp & peptide_evidence_sp:_peptide_evidence_list) {
         peptide_evidence_sp.get()->updateAutomaticFilters(automatic_filter_parameters);
     }
     qDebug() << "PeptideEvidenceStore::updateAutomaticFilters end" ;
 
 }
+
+const std::vector<std::shared_ptr<PeptideEvidence>> & PeptideEvidenceStore::getPeptideEvidenceList() const {
+    return _peptide_evidence_list;
+}
diff --git a/src/utils/peptideevidencestore.h b/src/utils/peptideevidencestore.h
index 49338ec65..e51fda1b4 100644
--- a/src/utils/peptideevidencestore.h
+++ b/src/utils/peptideevidencestore.h
@@ -43,6 +43,8 @@ class PeptideEvidenceStore
 public:
     std::shared_ptr<PeptideEvidence> & getInstance(const PeptideEvidence * p_peptide_evidence);
     void updateAutomaticFilters(const AutomaticFilterParameters & automatic_filter_parameters);
+    
+    const std::vector<std::shared_ptr<PeptideEvidence>> & getPeptideEvidenceList() const;
 private:
     std::vector<std::shared_ptr<PeptideEvidence>> _peptide_evidence_list;
     
-- 
GitLab