From 35f50c953a41201e072f87cd33e36a24f582896d Mon Sep 17 00:00:00 2001
From: Olivier Langella <Olivier.Langella@moulon.inra.fr>
Date: Sun, 9 Apr 2017 07:42:05 +0200
Subject: [PATCH] new group functions

---
 src/core/identificationgroup.cpp |  4 ++++
 src/core/identificationgroup.h   |  1 +
 src/grouping/groupinggroup.cpp   |  5 +++++
 src/grouping/groupinggroup.h     |  5 +++++
 src/output/masschroqml.cpp       | 22 ++++++++++++++++------
 src/output/masschroqml.h         |  2 ++
 src/utils/groupstore.cpp         |  3 +++
 src/utils/groupstore.h           |  2 ++
 8 files changed, 38 insertions(+), 6 deletions(-)

diff --git a/src/core/identificationgroup.cpp b/src/core/identificationgroup.cpp
index 2bb1162f6..c66ab899c 100644
--- a/src/core/identificationgroup.cpp
+++ b/src/core/identificationgroup.cpp
@@ -42,6 +42,10 @@ IdentificationGroup::~IdentificationGroup()
 }
 
 
+    const GroupStore & IdentificationGroup::getGroupStore() const {
+        return _group_store;
+    }
+
 unsigned int IdentificationGroup::countDecoyPeptideMatch(ValidationState state) const {
     unsigned int i=0;
     for (auto & p_protein_match : _protein_match_list) {
diff --git a/src/core/identificationgroup.h b/src/core/identificationgroup.h
index 74ba6ab90..ee430508a 100644
--- a/src/core/identificationgroup.h
+++ b/src/core/identificationgroup.h
@@ -45,6 +45,7 @@ public:
     ~IdentificationGroup();
 
     ProteinMatch * getProteinMatchInstance(const QString accession);
+    const GroupStore & getGroupStore() const;
     void addProteinMatch(ProteinMatch * protein_match);
     std::vector<ProteinMatch *> & getProteinMatchList();
     void addMsRunSp(MsRunSp ms_run_sp);
diff --git a/src/grouping/groupinggroup.cpp b/src/grouping/groupinggroup.cpp
index f5da520f6..8c13cad3d 100644
--- a/src/grouping/groupinggroup.cpp
+++ b/src/grouping/groupinggroup.cpp
@@ -137,6 +137,11 @@ std::size_t GroupingGroup::countSpecificSequence(const ProteinMatch * p_protein_
     return count;
 }
 
+
+    QString GroupingGroup::getProteinGroupingIdOfSubgroup(unsigned int subgroup_number) const {
+        return QString("%1%2a1").arg(pappso::Utils::getLexicalOrderedString(_group_number)).arg(pappso::Utils::getLexicalOrderedString(subgroup_number));
+    }
+
 void GroupingGroup::add(const ProteinMatch * p_protein_match) {
     _group_number = p_protein_match->getGrpProteinSp().get()->getGroupNumber();
     if (p_protein_match->getGrpProteinSp().get()->getRank() == 1) {
diff --git a/src/grouping/groupinggroup.h b/src/grouping/groupinggroup.h
index 5d740da7e..a84980b9a 100644
--- a/src/grouping/groupinggroup.h
+++ b/src/grouping/groupinggroup.h
@@ -57,6 +57,11 @@ public:
      * */
     const QStringList getSubgroupIdList(const PeptideMatch * p_peptide_match) const;
     
+        /** @brief give the protein group id of the representant of a subgroup
+     * */
+    QString getProteinGroupingIdOfSubgroup(unsigned int subgroup_number) const;
+
+    
     
     const std::vector<std::pair<unsigned int, const PeptideMatch *>> & getPairSgNumberPeptideMatchList() const;
 
diff --git a/src/output/masschroqml.cpp b/src/output/masschroqml.cpp
index b60f05983..49f5186d9 100644
--- a/src/output/masschroqml.cpp
+++ b/src/output/masschroqml.cpp
@@ -339,23 +339,33 @@ void MassChroQml::writeIsotopeLabelList() {
 void MassChroQml::writePeptideList() {
 //<peptide_list>
     _output_stream->writeStartElement("peptide_list");
+    const std::map<unsigned int, GroupingGroupSp> & group_store = _p_identification_group->getGroupStore().getGroupMap();
+    
+    for (auto & group_pair :group_store) {
+        writePeptideListInGroup(group_pair.second.get());
+    }
+} 
+    
+void MassChroQml::writePeptideListInGroup(const GroupingGroup * p_group) {
+    
+    const std::vector<std::pair<unsigned int, const PeptideMatch *>> & sg_peptide_match_list =  p_group->getPairSgNumberPeptideMatchList();
     std::vector<McqPeptide> mcq_peptide_list;
-    for (ProteinMatch * p_protein_match :_p_identification_group->getProteinMatchList()) {
-        if (!p_protein_match->isGrouped()) continue;
-        for (PeptideMatch * peptide_match :p_protein_match->getPeptideMatchList()) {
-            if (!peptide_match->isGrouped()) continue;
+    
+    for (auto & sg_peptide_pair :sg_peptide_match_list) {
+        unsigned int sg_number = sg_peptide_pair.first;
+        const PeptideMatch * peptide_match = sg_peptide_pair.second;
 
             McqPeptide mcq_peptide;
             mcq_peptide.id = peptide_match->getGrpPeptideSp().get()->getGroupingId();
             mcq_peptide.mods << peptide_match->getPeptideXtpSp().get()->getModifString();
-            mcq_peptide.prot_ids << p_protein_match->getGrpProteinSp().get()->getGroupingId();
+            mcq_peptide.prot_ids << p_group->getProteinGroupingIdOfSubgroup(sg_number);
             mcq_peptide.seq = peptide_match->getPeptideXtpSp().get()->getSequence();
             mcq_peptide.native_peptide = peptide_match->getPeptideXtpSp().get()->getNativePeptideP();
             mcq_peptide.data.push_back(peptide_match->getMsRunP()->getXmlId());
             mcq_peptide.scan.push_back(peptide_match->getScan());
             mcq_peptide.charge.push_back(peptide_match->getCharge());
             mcq_peptide_list.push_back(mcq_peptide);
-        }
+        
 
     }
 
diff --git a/src/output/masschroqml.h b/src/output/masschroqml.h
index ff291ffc0..8eeeb559f 100644
--- a/src/output/masschroqml.h
+++ b/src/output/masschroqml.h
@@ -48,12 +48,14 @@ private:
     void writeGroups();
     void writeProteinList();
     void writePeptideList();
+    void writePeptideListInGroup(const GroupingGroup * p_group);
     void writeIsotopeLabelList();
     void writeAlignments();
     void writeQuantificationMethods();
     void writeQuantificationResults();
     void writeQuantificationTraces();
     void writeQuantify();
+    
 private :
     QFile * _output_file;
     QXmlStreamWriter * _output_stream;
diff --git a/src/utils/groupstore.cpp b/src/utils/groupstore.cpp
index 17c46e71f..6371c5fc2 100644
--- a/src/utils/groupstore.cpp
+++ b/src/utils/groupstore.cpp
@@ -57,6 +57,9 @@ std::size_t GroupStore::countSubGroup() const {
     return  count;
 }
 
+    const std::map<unsigned int, GroupingGroupSp> & GroupStore::getGroupMap() const {
+        return _map_group;
+    }
 
 GroupingGroupSp GroupStore::getInstance(unsigned int group_number) {
 
diff --git a/src/utils/groupstore.h b/src/utils/groupstore.h
index 7ed6182cf..98db1ce54 100644
--- a/src/utils/groupstore.h
+++ b/src/utils/groupstore.h
@@ -41,6 +41,8 @@ public:
     GroupStore();
     ~GroupStore();
     GroupingGroupSp getInstance(unsigned int group_number);
+    const std::map<unsigned int, GroupingGroupSp> & getGroupMap() const;
+    
     void clear();
     std::size_t countGroup() const;
     std::size_t countSubGroup() const;
-- 
GitLab