From 7e5372d2b776ea8469581b617efce23ff6456f10 Mon Sep 17 00:00:00 2001
From: Olivier Langella <Olivier.Langella@moulon.inra.fr>
Date: Fri, 7 Apr 2017 21:30:24 +0200
Subject: [PATCH] count factorisation

---
 src/core/identificationgroup.cpp              | 34 ++-----------------
 src/core/identificationgroup.h                | 16 ++-------
 src/core/proteinmatch.cpp                     | 15 ++------
 src/core/proteinmatch.h                       |  9 +----
 src/grouping/groupinggroup.cpp                |  4 +--
 .../identificationgroupwidget.cpp             |  2 +-
 src/gui/project_view/projectwindow.cpp        |  4 +--
 .../protein_list_view/proteinlistwindow.cpp   |  2 +-
 .../protein_list_view/proteintablemodel.cpp   |  4 +--
 9 files changed, 15 insertions(+), 75 deletions(-)

diff --git a/src/core/identificationgroup.cpp b/src/core/identificationgroup.cpp
index 602d9cf0..40646661 100644
--- a/src/core/identificationgroup.cpp
+++ b/src/core/identificationgroup.cpp
@@ -53,7 +53,7 @@ unsigned int IdentificationGroup::countDecoyPeptideMatch(ValidationState state)
     }
     return i;
 }
-unsigned int IdentificationGroup::countDecoyProtein(ValidationState state) const {
+unsigned int IdentificationGroup::countDecoyProteinMatch(ValidationState state) const {
     return std::count_if (_protein_match_list.begin(), _protein_match_list.end(), [state](const ProteinMatch * p_protein_match) {
         if ((p_protein_match->getProteinXtpSp().get()->isDecoy()) && (p_protein_match->getValidationState() >= state)) {
             return true;
@@ -74,7 +74,7 @@ unsigned int IdentificationGroup::countPeptideMatch(ValidationState state) const
     return i;
 }
 
-unsigned int IdentificationGroup::countProtein(ValidationState state) const {
+unsigned int IdentificationGroup::countProteinMatch(ValidationState state) const {
     return std::count_if (_protein_match_list.begin(), _protein_match_list.end(), [state](const ProteinMatch * p_protein_match) {
         if (p_protein_match->getValidationState() >= state) {
             return true;
@@ -134,36 +134,6 @@ std::vector<ProteinMatch *> & IdentificationGroup::getProteinMatchList() {
     return _protein_match_list;
 }
 
-size_t IdentificationGroup::countGrouped()const {
-    size_t i=0;
-    for (auto & p_protein_match : _protein_match_list) {
-        if (p_protein_match->isGrouped()) {
-            i++;
-        }
-    }
-    return i;
-}
-
-size_t IdentificationGroup::countValidAndChecked()const {
-    size_t i=0;
-    for (auto & p_protein_match : _protein_match_list) {
-        if (p_protein_match->isValidAndChecked()) {
-            i++;
-        }
-    }
-    return i;
-}
-
-size_t IdentificationGroup::countValid()const {
-    size_t i=0;
-    for (auto & p_protein_match : _protein_match_list) {
-        if (p_protein_match->isValid()) {
-            i++;
-        }
-    }
-    return i;
-}
-
 std::size_t IdentificationGroup::countGroup()const {
     return _group_store.countGroup();
 }
diff --git a/src/core/identificationgroup.h b/src/core/identificationgroup.h
index 3eaf8565..9726a01b 100644
--- a/src/core/identificationgroup.h
+++ b/src/core/identificationgroup.h
@@ -48,18 +48,6 @@ public:
     void addProteinMatch(ProteinMatch * protein_match);
     std::vector<ProteinMatch *> & getProteinMatchList();
     void addMsRunSp(MsRunSp ms_run_sp);
-    
-    /** @brief count valid proteins
-     * */    
-    std::size_t countValid()const;
-    
-    /** @brief count valid and manually checked proteins
-     * */    
-    std::size_t countValidAndChecked()const;
-
-        /** @brief count grouped proteins
-     * */    
-    std::size_t countGrouped()const;
 
        /** @brief count groups
      * */    
@@ -71,10 +59,10 @@ public:
     
     /** @brief count proteins
      * */    
-    unsigned int countProtein(ValidationState state) const;
+    unsigned int countProteinMatch(ValidationState state) const;
     /** @brief count decoy proteins
      * */    
-    unsigned int countDecoyProtein(ValidationState state) const;   
+    unsigned int countDecoyProteinMatch(ValidationState state) const;   
     /** @brief count peptide match
      * */    
     unsigned int countPeptideMatch(ValidationState state) const;
diff --git a/src/core/proteinmatch.cpp b/src/core/proteinmatch.cpp
index 799f6cec..9f097e0f 100644
--- a/src/core/proteinmatch.cpp
+++ b/src/core/proteinmatch.cpp
@@ -187,21 +187,10 @@ unsigned int ProteinMatch::countPeptideMatch(ValidationState state) const {
     });
 }
 
-size_t ProteinMatch::countValidSpectrum()const {
-    return std::count_if (_peptide_match_list.begin(), _peptide_match_list.end(), [](const PeptideMatch * p_peptide_match) {
-        return (p_peptide_match->isValid());
-    });
-}
-
-size_t ProteinMatch::countValidAndCheckedSpectrum()const {
-    return std::count_if (_peptide_match_list.begin(), _peptide_match_list.end(), [](const PeptideMatch * p_peptide_match) {
-        return (p_peptide_match->isValidAndChecked());
-    });
-}
-size_t ProteinMatch::countUniqueSequence()const {
+size_t ProteinMatch::countUniqueSequence(ValidationState state)const {
     std::set<QString> sequence_list;
     for (auto & p_peptide_match : _peptide_match_list) {
-        if (p_peptide_match->isValidAndChecked()) {
+        if (p_peptide_match->getValidationState() >= state) {
             sequence_list.insert(p_peptide_match->getPeptideXtpSp().get()->getSequence());
         }
     }
diff --git a/src/core/proteinmatch.h b/src/core/proteinmatch.h
index b2501074..35685e99 100644
--- a/src/core/proteinmatch.h
+++ b/src/core/proteinmatch.h
@@ -78,16 +78,9 @@ public:
     ValidationState getValidationState() const;
     unsigned int countPeptideMatch(ValidationState state) const;
 
-    /** @brief count valid spectrums
-     * */
-    size_t countValidSpectrum()const;
-
-    /** @brief count valid and manually checked spectrums
-     * */
-    size_t countValidAndCheckedSpectrum()const;
     /** @brief count unique identified sequences (from valid and cheked spectrums)
      * */
-    size_t countUniqueSequence()const;
+    size_t countUniqueSequence(ValidationState state)const;
 
 
     const pappso::GrpProteinSp & getGrpProteinSp() const;
diff --git a/src/grouping/groupinggroup.cpp b/src/grouping/groupinggroup.cpp
index 7dd05b0a..b27c2570 100644
--- a/src/grouping/groupinggroup.cpp
+++ b/src/grouping/groupinggroup.cpp
@@ -83,7 +83,7 @@ unsigned int GroupingGroup::countSubgroupPresence(const PeptideMatch * p_peptide
 
 std::size_t GroupingGroup::countSpecificSpectrum(const ProteinMatch * p_protein_match) const {
     if (_number_of_subgroup == 1) {
-        return p_protein_match->countValidAndCheckedSpectrum();
+        return p_protein_match->countPeptideMatch(ValidationState::validAndChecked);
     }
     std::set<QString> spectrum_list_in;
     for (auto && p_peptide_match :p_protein_match->getPeptideMatchList()) {
@@ -111,7 +111,7 @@ std::size_t GroupingGroup::countSpecificSpectrum(const ProteinMatch * p_protein_
 
 std::size_t GroupingGroup::countSpecificSequence(const ProteinMatch * p_protein_match) const {
     if (_number_of_subgroup == 1) {
-        return p_protein_match->countUniqueSequence();
+        return p_protein_match->countUniqueSequence(ValidationState::validAndChecked);
     }
     std::set<QString> sequence_list_in;
     for (auto && p_peptide_match :p_protein_match->getPeptideMatchList()) {
diff --git a/src/gui/project_view/identification_group_widget/identificationgroupwidget.cpp b/src/gui/project_view/identification_group_widget/identificationgroupwidget.cpp
index 8fb21db1..df8ff2f8 100644
--- a/src/gui/project_view/identification_group_widget/identificationgroupwidget.cpp
+++ b/src/gui/project_view/identification_group_widget/identificationgroupwidget.cpp
@@ -68,6 +68,6 @@ void IdentificationGroupWidget::doIdentificationGroupGrouped(IdentificationGroup
 
         ui->group_number_display->setText(QString("%1").arg(_p_identification_group->countGroup()));
         ui->subgroup_number_display->setText(QString("%1").arg(_p_identification_group->countSubGroup()));
-        ui->protein_number_display->setText(QString("%1").arg(_p_identification_group->countGrouped()));
+        ui->protein_number_display->setText(QString("%1").arg(_p_identification_group->countProteinMatch(ValidationState::grouped)));
     }
 }
diff --git a/src/gui/project_view/projectwindow.cpp b/src/gui/project_view/projectwindow.cpp
index f9c63fed..5311738f 100644
--- a/src/gui/project_view/projectwindow.cpp
+++ b/src/gui/project_view/projectwindow.cpp
@@ -142,8 +142,8 @@ void ProjectWindow::computeFdr(ValidationState state) {
     pappso::pappso_double total_prot=0;
     pappso::pappso_double false_prot=0;
     for (IdentificationGroup * identification_group : _project_sp.get()->getIdentificationGroupList()) {
-        total_prot += identification_group->countProtein(state);
-        false_prot += identification_group->countDecoyProtein(state);
+        total_prot += identification_group->countProteinMatch(state);
+        false_prot += identification_group->countDecoyProteinMatch(state);
     }
     ui->protein_fdr_label->setText(QString("%1 %").arg(false_prot/total_prot));
     
diff --git a/src/gui/protein_list_view/proteinlistwindow.cpp b/src/gui/protein_list_view/proteinlistwindow.cpp
index 0392a929..8515a4d9 100644
--- a/src/gui/protein_list_view/proteinlistwindow.cpp
+++ b/src/gui/protein_list_view/proteinlistwindow.cpp
@@ -227,7 +227,7 @@ void ProteinListWindow::updateStatusBar() {
     if (_p_identification_group == nullptr) {
     }
     else {
-        ui->statusbar->showMessage(tr("proteins %1 valid, %2 checked, %3 displayed").arg(_p_identification_group->countValid()).arg(_p_identification_group->countValidAndChecked()).arg(_p_proxy_model->rowCount()));
+        ui->statusbar->showMessage(tr("proteins %1 valid, %2 checked, %3 displayed").arg(_p_identification_group->countProteinMatch(ValidationState::valid)).arg(_p_identification_group->countProteinMatch(ValidationState::validAndChecked)).arg(_p_proxy_model->rowCount()));
     }
 }
 
diff --git a/src/gui/protein_list_view/proteintablemodel.cpp b/src/gui/protein_list_view/proteintablemodel.cpp
index 85b9831b..904fa910 100644
--- a/src/gui/protein_list_view/proteintablemodel.cpp
+++ b/src/gui/protein_list_view/proteintablemodel.cpp
@@ -170,7 +170,7 @@ QVariant ProteinTableModel::data(const QModelIndex &index, int role ) const {
             return QVariant ((qreal)_p_identification_group->getProteinMatchList().at(row)->getEvalue());
         }
         if (_column_assignment[col] == (std::int8_t) ProteinListColumn::spectrum ) {
-            return QVariant ((qreal) _p_identification_group->getProteinMatchList().at(row)->countValidAndCheckedSpectrum());
+            return QVariant ((qreal) _p_identification_group->getProteinMatchList().at(row)->countPeptideMatch(ValidationState::validAndChecked));
         }
 
         if (_column_assignment[col] == (std::int8_t) ProteinListColumn::specific_spectrum ) {
@@ -181,7 +181,7 @@ QVariant ProteinTableModel::data(const QModelIndex &index, int role ) const {
         }
 
         if (_column_assignment[col] == (std::int8_t) ProteinListColumn::sequence ) {
-            return QVariant ((qreal) _p_identification_group->getProteinMatchList().at(row)->countUniqueSequence());
+            return QVariant ((qreal) _p_identification_group->getProteinMatchList().at(row)->countUniqueSequence(ValidationState::validAndChecked));
         }
         if (_column_assignment[col] == (std::int8_t) ProteinListColumn::specific_sequence ) {
             GroupingGroup * p_groupin_group = _p_identification_group->getProteinMatchList().at(row)->getGroupingGroupSp().get();
-- 
GitLab