From cd76de95cd7483c2872fa511acbfee6e41425d70 Mon Sep 17 00:00:00 2001
From: Olivier Langella <Olivier.Langella@moulon.inra.fr>
Date: Sun, 23 Apr 2017 23:08:51 +0200
Subject: [PATCH] new peptide counting method : peptide+mass+sample

---
 src/core/identificationgroup.cpp       | 35 ++++++++++++++++----
 src/core/identificationgroup.h         | 46 +++++++++++++++-----------
 src/core/peptidematch.cpp              |  4 +++
 src/core/peptidematch.h                |  1 +
 src/core/proteinmatch.cpp              |  9 +++++
 src/core/proteinmatch.h                |  4 +++
 src/gui/project_view/project_view.ui   |  5 ++-
 src/gui/project_view/projectwindow.cpp |  8 +++--
 8 files changed, 82 insertions(+), 30 deletions(-)

diff --git a/src/core/identificationgroup.cpp b/src/core/identificationgroup.cpp
index d0334bb28..3e98431bd 100644
--- a/src/core/identificationgroup.cpp
+++ b/src/core/identificationgroup.cpp
@@ -42,17 +42,40 @@ IdentificationGroup::~IdentificationGroup()
 }
 
 
-    const GroupStore & IdentificationGroup::getGroupStore() const {
-        return _group_store;
+const GroupStore & IdentificationGroup::getGroupStore() const {
+    return _group_store;
+}
+
+unsigned int IdentificationGroup::countPeptideMassSample(ValidationState state) const {
+    std::vector<std::size_t> count_peptide_mass_sample;
+    for (auto & p_protein_match : _protein_match_list) {
+        p_protein_match->countPeptideMassSample(count_peptide_mass_sample, state);
+    }
+    std::sort(count_peptide_mass_sample.begin(), count_peptide_mass_sample.end());
+    auto last = std::unique(count_peptide_mass_sample.begin(),count_peptide_mass_sample.end());
+    return std::distance(count_peptide_mass_sample.begin(),last);
+}
+
+unsigned int IdentificationGroup::countDecoyPeptideMassSample(ValidationState state) const {
+    std::vector<std::size_t> count_peptide_mass_sample;
+    for (auto & p_protein_match : _protein_match_list) {
+        if (p_protein_match->getProteinXtpSp().get()->isDecoy()) {
+            p_protein_match->countPeptideMassSample(count_peptide_mass_sample, state);
+        }
     }
+    std::sort(count_peptide_mass_sample.begin(), count_peptide_mass_sample.end());
+    auto last = std::unique(count_peptide_mass_sample.begin(),count_peptide_mass_sample.end());
+    return std::distance(count_peptide_mass_sample.begin(),last);
+}
+
 
 unsigned int IdentificationGroup::countDecoyPeptideMatch(ValidationState state) const {
     unsigned int i=0;
     for (auto & p_protein_match : _protein_match_list) {
         //if (p_protein_match->getValidationState() == state) {
-            if (p_protein_match->getProteinXtpSp().get()->isDecoy()) {
-                i+=p_protein_match->countPeptideMatch(state);
-            }
+        if (p_protein_match->getProteinXtpSp().get()->isDecoy()) {
+            i+=p_protein_match->countPeptideMatch(state);
+        }
         //}
     }
     return i;
@@ -72,7 +95,7 @@ unsigned int IdentificationGroup::countPeptideMatch(ValidationState state) const
     unsigned int i=0;
     for (auto & p_protein_match : _protein_match_list) {
         //if (p_protein_match->getValidationState() >= state) {
-            i+=p_protein_match->countPeptideMatch(state);
+        i+=p_protein_match->countPeptideMatch(state);
         //}
     }
     return i;
diff --git a/src/core/identificationgroup.h b/src/core/identificationgroup.h
index ee430508a..e8393d41d 100644
--- a/src/core/identificationgroup.h
+++ b/src/core/identificationgroup.h
@@ -50,54 +50,60 @@ public:
     std::vector<ProteinMatch *> & getProteinMatchList();
     void addMsRunSp(MsRunSp ms_run_sp);
 
-       /** @brief count groups
-     * */    
+    /** @brief count groups
+    * */
     std::size_t countGroup()const;
 
-       /** @brief count subgroups
-     * */    
+    /** @brief count subgroups
+    * */
     std::size_t countSubGroup()const;
-    
+
     /** @brief count proteins
-     * */    
+     * */
     unsigned int countProteinMatch(ValidationState state) const;
     /** @brief count decoy proteins
-     * */    
-    unsigned int countDecoyProteinMatch(ValidationState state) const;   
-    /** @brief count peptide match
-     * */    
+     * */
+    unsigned int countDecoyProteinMatch(ValidationState state) const;
+    /** @brief count peptide match (peptide spectrum match + protein match)
+     * */
     unsigned int countPeptideMatch(ValidationState state) const;
     /** @brief count decoy peptide match
-     * */    
+     * */
     unsigned int countDecoyPeptideMatch(ValidationState state) const;
+    /** @brief count peptide (peptide+mass+sample)
+     * */
+    unsigned int countPeptideMassSample(ValidationState state) const;
+    /** @brief count peptide (peptide+mass+sample) included by decoy proteins
+     * */
+    unsigned int countDecoyPeptideMassSample(ValidationState state) const;
 
 
     /** @brief validate or invalidate peptides and proteins based automatic filters and manual checks
      * */
     void updateAutomaticFilters(const AutomaticFilterParameters & automatic_filter_parameters);
-    
+
     void startGrouping (const GroupingType & grouping_type);
-    
-    const std::vector<MsRunSp> & getMsRunSpList() const; 
-    
+
+    const std::vector<MsRunSp> & getMsRunSpList() const;
+
     /** @brief get tab name for qtabwidget
-     * */   
+     * */
     const QString getTabName() const;
-    
+
     bool contains (const MsRun * p_msrun) const;
-    
+
     void collectMhDelta(std::vector< pappso::pappso_double> & delta_list, pappso::PrecisionUnit unit, ValidationState state) const;
 private :
     GroupingExperiment * _p_grp_experiment= nullptr;
 
     Project * _p_project;
-    
+
     GroupStore _group_store;
 
     std::vector<ProteinMatch *> _protein_match_list;
 
     std::vector<MsRunSp> _ms_run_list;
-    
+
     std::map<QString, ProteinMatch *> _cache_accession_protein_match;
 };
 
diff --git a/src/core/peptidematch.cpp b/src/core/peptidematch.cpp
index 5761314c3..05085bd33 100644
--- a/src/core/peptidematch.cpp
+++ b/src/core/peptidematch.cpp
@@ -47,6 +47,10 @@ void PeptideMatch::setEvalue(pappso::pappso_double evalue) {
 }
 
 
+std::size_t PeptideMatch::getHashPeptideMassSample() const {
+    return PeptideMatch::_hash_fn (QString("%1 %2").arg(_peptide_sp.get()->getLiAbsoluteString()).arg(_msrunid_sp->getXmlId()).toStdString());
+}
+
 std::size_t PeptideMatch::getHashSampleScan() const {
     return _hash_sample_scan;
 }
diff --git a/src/core/peptidematch.h b/src/core/peptidematch.h
index 6d885f715..42bcbabfe 100644
--- a/src/core/peptidematch.h
+++ b/src/core/peptidematch.h
@@ -36,6 +36,7 @@ class PeptideMatch
 public :
     PeptideMatch(MsRun * msrunid_sp, unsigned int scan);
     std::size_t getHashSampleScan() const;
+    std::size_t getHashPeptideMassSample() const;
 
     void setRetentionTime(pappso::pappso_double rt);
     void setEvalue(pappso::pappso_double evalue);
diff --git a/src/core/proteinmatch.cpp b/src/core/proteinmatch.cpp
index d44f1fe72..07c97cf88 100644
--- a/src/core/proteinmatch.cpp
+++ b/src/core/proteinmatch.cpp
@@ -176,6 +176,15 @@ const pappso::GrpProteinSp & ProteinMatch::getGrpProteinSp() const {
 }
 
 
+void ProteinMatch::countPeptideMassSample(std::vector<size_t> & count_peptide_mass_sample, ValidationState state) const {
+    for (auto & p_peptide_match : _peptide_match_list) {
+        if (p_peptide_match->getValidationState() >= state) {
+            count_peptide_mass_sample.push_back(p_peptide_match->getHashPeptideMassSample());
+        }
+    }
+}
+
+
 unsigned int ProteinMatch::countPeptideMatch(ValidationState state) const {
     return std::count_if (_peptide_match_list.begin(), _peptide_match_list.end(), [state](const PeptideMatch * p_peptide_match) {
         if (p_peptide_match->getValidationState() >= state) {
diff --git a/src/core/proteinmatch.h b/src/core/proteinmatch.h
index fb125d15d..c1cf06876 100644
--- a/src/core/proteinmatch.h
+++ b/src/core/proteinmatch.h
@@ -77,6 +77,10 @@ public:
 
     ValidationState getValidationState() const;
     unsigned int countPeptideMatch(ValidationState state) const;
+    
+    /** @brief count peptide (peptide+mass+sample)
+     */
+    void countPeptideMassSample(std::vector<size_t> & count_peptide_mass_sample, ValidationState state) const;
 
     /** @brief count unique identified sequences (from valid and cheked spectrums)
      * */
diff --git a/src/gui/project_view/project_view.ui b/src/gui/project_view/project_view.ui
index f45e0bde2..9313cbdae 100644
--- a/src/gui/project_view/project_view.ui
+++ b/src/gui/project_view/project_view.ui
@@ -24,7 +24,7 @@
        <string/>
       </property>
       <property name="currentIndex">
-       <number>2</number>
+       <number>0</number>
       </property>
       <widget class="QWidget" name="identifications">
        <attribute name="title">
@@ -52,6 +52,9 @@
              <string>Contaminants</string>
             </property>
             <layout class="QVBoxLayout" name="verticalLayout_6">
+             <item>
+              <widget class="QListView" name="contaminant_database_listview"/>
+             </item>
              <item>
               <widget class="QLineEdit" name="contaminant_protein_regexp_line_edit">
                <property name="placeholderText">
diff --git a/src/gui/project_view/projectwindow.cpp b/src/gui/project_view/projectwindow.cpp
index 780eaa948..29e125688 100644
--- a/src/gui/project_view/projectwindow.cpp
+++ b/src/gui/project_view/projectwindow.cpp
@@ -45,6 +45,7 @@ ProjectWindow::ProjectWindow(MainWindow *parent):
 
     _p_fasta_str_li = new QStandardItemModel();
     ui->decoy_database_listview->setModel(_p_fasta_str_li);
+    ui->contaminant_database_listview->setModel(_p_fasta_str_li);
 
     _p_automatic_filter_widget = new AutomaticFilterWidget(this);
     ui->filter_parameter_layout->addWidget(_p_automatic_filter_widget);
@@ -153,8 +154,10 @@ void ProjectWindow::computeFdr() {
     for (IdentificationGroup * identification_group : _project_sp.get()->getIdentificationGroupList()) {
         total_prot += identification_group->countProteinMatch(state);
         false_prot += identification_group->countDecoyProteinMatch(state);
-        total_peptide += identification_group->countPeptideMatch(state);
-        false_peptide += identification_group->countDecoyPeptideMatch(state);
+        //total_peptide += identification_group->countPeptideMatch(state);
+        //false_peptide += identification_group->countDecoyPeptideMatch(state);
+        total_peptide += identification_group->countPeptideMassSample(state);
+        false_peptide += identification_group->countDecoyPeptideMassSample(state);
     }
     ui->protein_fdr_label->setText(QString("%1 %").arg(QString::number((false_prot/total_prot)*100.0,'f',10)));
     ui->peptide_fdr_label->setText(QString("%1 %").arg(QString::number((false_peptide/total_peptide)*100.0,'f',10)));
@@ -353,7 +356,6 @@ void ProjectWindow::setProjectSp(ProjectSp project_sp) {
     qDebug() << "ProjectWindow::setProjectSp begin " << _project_sp.get()->getFastaFileStore().getFastaFileList().size() ;
     _fastafile_list = _project_sp.get()->getFastaFileStore().getFastaFileList();
     
-    
     for (FastaFileSp fasta_file : _fastafile_list ) {
 
         QStandardItem *item;
-- 
GitLab