From b530a62bcf8009004a65b337254072cbc859d234 Mon Sep 17 00:00:00 2001
From: Olivier Langella <Olivier.Langella@moulon.inra.fr>
Date: Tue, 28 Mar 2017 15:07:59 +0200
Subject: [PATCH] PAI computation

---
 src/core/proteinmatch.cpp                     | 32 ++++++++++++++++++-
 src/core/proteinmatch.h                       | 12 +++++++
 src/core/proteinxtp.cpp                       | 30 +++++++++++++++++
 src/core/proteinxtp.h                         |  1 +
 src/gui/project_view/projectwindow.cpp        | 10 +++---
 .../protein_list_view/proteintablemodel.cpp   |  7 +++-
 6 files changed, 85 insertions(+), 7 deletions(-)

diff --git a/src/core/proteinmatch.cpp b/src/core/proteinmatch.cpp
index ae009c04..9df85654 100644
--- a/src/core/proteinmatch.cpp
+++ b/src/core/proteinmatch.cpp
@@ -162,6 +162,36 @@ size_t ProteinMatch::countUniqueSequence()const {
     return sequence_list.size();
 }
 
+unsigned int ProteinMatch::countValidAndCheckedPeptideMassCharge(const pappso::MsRunIdSp & sp_msrun_id) const {
+    std::set<QString> sequence_list;
+    for (auto & p_peptide_match : _peptide_match_list) {
+        if (p_peptide_match->isValidAndChecked()) {
+            if(sp_msrun_id.get() != nullptr) {
+                //within sample
+                if (p_peptide_match->getMsRunIdSp().get() == sp_msrun_id.get()) {
+                    sequence_list.insert(QString("%1-%2").arg(p_peptide_match->getPeptideXtpSp().get()->toAbsoluteString()).arg(p_peptide_match->getCharge()));
+                }
+            }
+            else {
+                //overall samples
+                sequence_list.insert(QString("%1-%2").arg(p_peptide_match->getPeptideXtpSp().get()->toAbsoluteString()).arg(p_peptide_match->getCharge()));
+            }
+        }
+    }
+    return sequence_list.size();
+}
+
+
+pappso::pappso_double ProteinMatch::getPAI() const {
+    pappso::MsRunIdSp sp_msrun_id;
+    return getPAI(sp_msrun_id);
+}
+
+pappso::pappso_double ProteinMatch::getPAI(const pappso::MsRunIdSp & sp_msrun_id) const {
+    pappso::pappso_double PAI =  (pappso::pappso_double) countValidAndCheckedPeptideMassCharge(sp_msrun_id) / (pappso::pappso_double) _protein_sp.get()->countTrypticPeptidesForPAI();
+    return PAI;
+}
+
 pappso::pappso_double ProteinMatch::getCoverage() const {
     size_t prot_size = _protein_sp.get()->size();
     //qDebug() << "ProteinMatch::getCoverage begin prot_size=" << prot_size << " " << _protein_sp.get()-//>getSequence();
@@ -186,7 +216,7 @@ pappso::pappso_double ProteinMatch::getCoverage() const {
     return (((pappso::pappso_double)count)/ ((pappso::pappso_double)prot_size));
 }
 const GroupingGroupSp & ProteinMatch::getGroupingGroupSp() const {
-  return _sp_group;
+    return _sp_group;
 }
 
 void ProteinMatch::setGroupInstance(GroupStore & group_store) {
diff --git a/src/core/proteinmatch.h b/src/core/proteinmatch.h
index b473d43e..d649e355 100644
--- a/src/core/proteinmatch.h
+++ b/src/core/proteinmatch.h
@@ -46,6 +46,17 @@ public:
     void setEvalue(pappso::pappso_double evalue);
     pappso::pappso_double getEvalue() const;
     pappso::pappso_double getCoverage() const;
+    
+   /** @brief compute Protein Abundance Index (PAI)
+     * overall sample PAI computation (Rappsilber et al. 2002)
+     * */
+    pappso::pappso_double getPAI() const;
+
+    /** @brief compute Protein Abundance Index (PAI) within sample
+     * PAI computation (Rappsilber et al. 2002)
+     * */
+    pappso::pappso_double getPAI(const pappso::MsRunIdSp & sp_msrun_id) const;
+    
     void setProteinXtpSp(ProteinXtpSp protein_sp);
     void addPeptideMatch(PeptideMatch * peptide_match);
     std::vector<PeptideMatch *> & getPeptideMatchList();
@@ -95,6 +106,7 @@ private:
     /** @brief automatic filter result (false by default)
      */
     bool _proxy_valid = false;
+    unsigned int countValidAndCheckedPeptideMassCharge(const pappso::MsRunIdSp & sp_msrun_id) const;
 
 };
 
diff --git a/src/core/proteinxtp.cpp b/src/core/proteinxtp.cpp
index 432318eb..f08e97e2 100644
--- a/src/core/proteinxtp.cpp
+++ b/src/core/proteinxtp.cpp
@@ -22,6 +22,7 @@
 ******************************************************************************/
 
 #include "proteinxtp.h"
+#include <pappsomspp/protein/enzyme.h>
 
 ProteinXtp::ProteinXtp():pappso::Protein()
 {
@@ -62,3 +63,32 @@ bool ProteinXtp::isContaminant() const {
 bool ProteinXtp::isDecoy() const {
     return _is_decoy;
 }
+
+class DigestionHandler: public pappso::EnzymeProductInterface {
+public:
+    void setPeptide(std::int8_t sequence_database_id, const pappso::ProteinSp & protein_sp, bool is_decoy, const QString& peptide, unsigned int start, bool is_nter, unsigned int missed_cleavage_number, bool semi_enzyme) override {
+        _peptide_list.append(peptide);
+    };
+
+    QStringList _peptide_list;
+};
+
+unsigned int ProteinXtp::countTrypticPeptidesForPAI() const {
+    qDebug() << "ProteinXtp::countTrypticPeptidesForPAI begin";
+    pappso::Enzyme kinase;
+    kinase.setMiscleavage(0);
+    DigestionHandler digestion;
+    kinase.eat(0,this->makeProteinSp(),false,digestion);
+
+    unsigned int count = 0;
+    for (const QString & peptide_str: digestion._peptide_list) {
+        pappso::Peptide peptide(peptide_str);
+        pappso::mz mass= peptide.getMass();
+        if ((mass > 800) && (mass < 2500)) {
+            count ++;
+        }
+    }
+
+    return count;
+    qDebug() << "ProteinXtp::countTrypticPeptidesForPAI end";
+}
diff --git a/src/core/proteinxtp.h b/src/core/proteinxtp.h
index 764266d3..0dfa8ff7 100644
--- a/src/core/proteinxtp.h
+++ b/src/core/proteinxtp.h
@@ -48,6 +48,7 @@ public:
     void setIsDecoy(bool conta);
     bool isContaminant() const;
     bool isDecoy() const;
+    unsigned int countTrypticPeptidesForPAI() const;
 
 private:
     SequenceDatabase * _p_sequence_database;
diff --git a/src/gui/project_view/projectwindow.cpp b/src/gui/project_view/projectwindow.cpp
index 96f0793d..c5700f62 100644
--- a/src/gui/project_view/projectwindow.cpp
+++ b/src/gui/project_view/projectwindow.cpp
@@ -167,17 +167,17 @@ void ProjectWindow::doViewProteinList(IdentificationGroup* p_identification_grou
 void ProjectWindow::setProjectSp(ProjectSp project_sp) {
 
     for (auto && p_window :_peptide_list_window_collection) {
-      delete p_window;
+        delete p_window;
     }
     _peptide_list_window_collection.clear();
     _p_current_peptide_list_window = nullptr;
-    
-     for (auto && p_window :_protein_list_window_collection) {
-      delete p_window;
+
+    for (auto && p_window :_protein_list_window_collection) {
+        delete p_window;
     }
     _protein_list_window_collection.clear();
     _p_current_protein_list_window = nullptr;
-   
+
     _project_sp = project_sp;
     vector< MsRunIdSp > ms_run_list = _project_sp.get()->getCurrentIdentificationGroupP()->getMsRunIdSpList();
     ui->sample_number_display->setText(QString("%1").arg(ms_run_list.size()));
diff --git a/src/gui/protein_list_view/proteintablemodel.cpp b/src/gui/protein_list_view/proteintablemodel.cpp
index eb74f3cd..3a64371f 100644
--- a/src/gui/protein_list_view/proteintablemodel.cpp
+++ b/src/gui/protein_list_view/proteintablemodel.cpp
@@ -147,7 +147,7 @@ int ProteinTableModel::rowCount(const QModelIndex &parent ) const {
     return 0;
 }
 int ProteinTableModel::columnCount(const QModelIndex &parent ) const {
-    return 10;
+    return 11;
 }
 QVariant ProteinTableModel::headerData(int section, Qt::Orientation orientation, int role) const
 {
@@ -176,6 +176,8 @@ QVariant ProteinTableModel::headerData(int section, Qt::Orientation orientation,
                 return QString("specific sequence");
             case 9:
                 return QString("coverage");
+            case 10:
+                return QString("PAI");
             }
         }
     }
@@ -264,6 +266,9 @@ QVariant ProteinTableModel::data(const QModelIndex &index, int role ) const {
         if (col == 9) {
             return QVariant ((qreal)_p_identification_group->getProteinMatchList().at(row)->getCoverage());
         }
+        if (col == 10) {
+            return QVariant ((qreal)_p_identification_group->getProteinMatchList().at(row)->getPAI());
+        }
 
         return QVariant();
     }
-- 
GitLab