From dd5989d8037d325ba394fd49f59a4ed2494b4c40 Mon Sep 17 00:00:00 2001
From: Olivier Langella <olivier.langella@u-psud.fr>
Date: Thu, 3 May 2018 15:33:50 +0200
Subject: [PATCH] first NSAF version

---
 src/core/identificationgroup.cpp                | 10 ++++++++++
 src/core/identificationgroup.h                  |  6 ++++++
 src/core/proteinmatch.cpp                       |  3 +++
 src/core/proteinmatch.h                         | 12 ++++++++++--
 src/gui/protein_list_view/proteinlistwindow.cpp | 11 +++++++++++
 src/gui/protein_list_view/proteinlistwindow.h   |  3 +++
 src/gui/protein_list_view/proteintablemodel.cpp | 11 ++++++++++-
 src/gui/protein_list_view/proteintablemodel.h   |  1 +
 8 files changed, 54 insertions(+), 3 deletions(-)

diff --git a/src/core/identificationgroup.cpp b/src/core/identificationgroup.cpp
index 82ab9dd3..666e75c8 100644
--- a/src/core/identificationgroup.cpp
+++ b/src/core/identificationgroup.cpp
@@ -48,6 +48,16 @@ const GroupStore & IdentificationGroup::getGroupStore() const {
     return _group_store;
 }
 
+pappso::pappso_double IdentificationGroup::computeProtoNsafSum(const MsRun * p_msrun_id ) const {
+    pappso::pappso_double nsaf_sum = 0;
+    for (auto & p_protein_match : _protein_match_list) {
+        if (p_protein_match->getValidationState() >= ValidationState::grouped) {
+            nsaf_sum += p_protein_match->getProtoNsaf(p_msrun_id);
+        }
+    }
+    return nsaf_sum;
+}
+
 unsigned int IdentificationGroup::countPeptideMass(ValidationState state) const {
 
     std::vector<pappso::GrpPeptide *> count_peptide_mass;
diff --git a/src/core/identificationgroup.h b/src/core/identificationgroup.h
index 110d7d9a..2e162785 100644
--- a/src/core/identificationgroup.h
+++ b/src/core/identificationgroup.h
@@ -54,6 +54,12 @@ public:
     void addIdentificationDataSourceP(IdentificationDataSource *  p_identification_source);
 
     const PtmGroupingExperiment * getPtmGroupingExperiment() const;
+    
+            /** @brief compute proto NSAF sum within msrun
+     * Warning: this is not NSAF, just a part
+     * @param p_msrun_id pointer on the msrun to get NSAF. if not defined, NSAF is computed overall msruns
+     * */
+    pappso::pappso_double computeProtoNsafSum(const MsRun * p_msrun_id = nullptr) const;
 
     /** @brief count groups
     * */
diff --git a/src/core/proteinmatch.cpp b/src/core/proteinmatch.cpp
index 093d6585..cf3ba339 100644
--- a/src/core/proteinmatch.cpp
+++ b/src/core/proteinmatch.cpp
@@ -325,6 +325,9 @@ pappso::pappso_double ProteinMatch::getLogEvalue(const MsRun * sp_msrun_id) cons
     return (evalue_prot);
 
 }
+pappso::pappso_double  ProteinMatch::getNsaf(pappso::pappso_double proto_nsaf_sum, const MsRun * p_msrun_id) const {
+    return (getProtoNsaf(p_msrun_id)/proto_nsaf_sum);
+}
 
 pappso::pappso_double ProteinMatch::getProtoNsaf(const MsRun * sp_msrun_id) const {
     try {
diff --git a/src/core/proteinmatch.h b/src/core/proteinmatch.h
index a9e41967..4b1bcebb 100644
--- a/src/core/proteinmatch.h
+++ b/src/core/proteinmatch.h
@@ -64,10 +64,18 @@ public:
      **/
     const QString getHtmlSequence(PeptideEvidence * peptide_evidence_to_locate = nullptr) const;
 
-        /** @brief compute proto NSAF within sample
+        /** @brief compute proto NSAF within msrun
      * Warning: this is not NSAF, just a part
+     * @param p_msrun_id pointer on the msrun to get NSAF. if not defined, NSAF is computed overall msruns
      * */
-    pappso::pappso_double getProtoNsaf(const MsRun * sp_msrun_id = nullptr) const;
+    pappso::pappso_double getProtoNsaf(const MsRun * p_msrun_id = nullptr) const;
+
+            /** @brief compute NSAF within msrun
+     * Warning: this is not NSAF, just a part
+     * @param proto_nsaf_sum the sum of proto nsaf of all proteins within the msrun
+     * @param p_msrun_id pointer on the msrun to get NSAF. if not defined, NSAF is computed overall msruns
+     * */
+    pappso::pappso_double getNsaf(pappso::pappso_double proto_nsaf_sum, const MsRun * p_msrun_id = nullptr) const;
 
     /** @brief compute Protein Abundance Index (PAI) within sample
      * PAI computation (Rappsilber et al. 2002)
diff --git a/src/gui/protein_list_view/proteinlistwindow.cpp b/src/gui/protein_list_view/proteinlistwindow.cpp
index e71b9ecd..d7c02cf4 100644
--- a/src/gui/protein_list_view/proteinlistwindow.cpp
+++ b/src/gui/protein_list_view/proteinlistwindow.cpp
@@ -272,6 +272,9 @@ void ProteinListWindow::doIdentificationGroupGrouped(IdentificationGroup * p_ide
     if (_p_identification_group == p_identification_group) {
         //_protein_table_model_p->setIdentificationGroup(p_identification_group);
         //_p_proxy_model->setSourceModel(_protein_table_model_p);
+        //if(getProteinListColumnDisplay) {
+            sumProtoNsaf();
+        //}
         emit proteinDataChanged();
     }
 
@@ -347,3 +350,11 @@ void ProteinListWindow::resizeColumnsToContents() {
 ProjectWindow * ProteinListWindow::getProjectWindow() {
     return _project_window;
 }
+
+
+    pappso::pappso_double ProteinListWindow::getProtoNsafSum() const {
+        return _sum_proto_nsaf;
+    }
+    void ProteinListWindow::sumProtoNsaf() {
+        _sum_proto_nsaf = _p_identification_group->computeProtoNsafSum();
+    }
diff --git a/src/gui/protein_list_view/proteinlistwindow.h b/src/gui/protein_list_view/proteinlistwindow.h
index e5d1d9d7..98a3e632 100644
--- a/src/gui/protein_list_view/proteinlistwindow.h
+++ b/src/gui/protein_list_view/proteinlistwindow.h
@@ -98,6 +98,8 @@ protected :
     void askProteinDetailView(ProteinMatch * p_protein_match);
     void askPeptideListView(ProteinMatch * p_protein_match);
     ProjectWindow * getProjectWindow();
+    pappso::pappso_double getProtoNsafSum() const;
+    void sumProtoNsaf();
 
 
 
@@ -110,6 +112,7 @@ private:
     QMenu * _p_context_menu = nullptr;
     bool _display_evalue = true;
     bool _display_accession = true;
+    pappso::pappso_double _sum_proto_nsaf;
 
 };
 
diff --git a/src/gui/protein_list_view/proteintablemodel.cpp b/src/gui/protein_list_view/proteintablemodel.cpp
index a6e3cd24..ee1dbfc6 100644
--- a/src/gui/protein_list_view/proteintablemodel.cpp
+++ b/src/gui/protein_list_view/proteintablemodel.cpp
@@ -65,7 +65,7 @@ int ProteinTableModel::rowCount(const QModelIndex &parent ) const {
 int ProteinTableModel::columnCount(const QModelIndex &parent ) const {
     //qDebug() << "ProteinTableModel::columnCount begin ";
     if (_p_identification_group != nullptr) {
-        return 14;
+        return 15;
     }
     return 0;
 }
@@ -127,6 +127,10 @@ const QString ProteinTableModel::getTitle(std::int8_t column) {
     case (std::int8_t) ProteinListColumn::molecular_weight:
         return "MW";
         break;
+        
+    case (std::int8_t) ProteinListColumn::nsaf:
+        return "NSAF";
+        break;
 
     }
     return "";
@@ -180,6 +184,8 @@ const QString ProteinTableModel::getDescription(std::int8_t column) {
     case (std::int8_t) ProteinListColumn::molecular_weight:
         return "protein molecular weight in Dalton";
 
+    case (std::int8_t) ProteinListColumn::nsaf:
+        return "NSAF";
     }
     return "";
 }
@@ -331,6 +337,9 @@ QVariant ProteinTableModel::data(const QModelIndex &index, int role ) const {
         if (col == (std::int8_t) ProteinListColumn::molecular_weight ) {
             return QVariant ((qreal)_p_identification_group->getProteinMatchList().at(row)->getProteinXtpSp().get()->getMass());
         }
+        if (col == (std::int8_t) ProteinListColumn::nsaf ) {
+            return QVariant ((qreal)_p_identification_group->getProteinMatchList().at(row)->getNsaf(_p_protein_list_window->getProtoNsafSum()));
+        }
         return QVariant();
     }
     return QVariant();
diff --git a/src/gui/protein_list_view/proteintablemodel.h b/src/gui/protein_list_view/proteintablemodel.h
index a3f10326..04f37015 100644
--- a/src/gui/protein_list_view/proteintablemodel.h
+++ b/src/gui/protein_list_view/proteintablemodel.h
@@ -47,6 +47,7 @@ enum class ProteinListColumn: std::int8_t {
     molecular_weight=11, ///< protein molecular weight in Dalton
     pai=12, ///< PAI
     empai=13, ///< emPAI
+    nsaf=14, ///< NSAF
 };
 
 class ProteinListWindow;
-- 
GitLab