From cc48fd86b31e7fa4c7424dd0967fe2fd7c0ffca3 Mon Sep 17 00:00:00 2001
From: Olivier Langella <olivier.langella@u-psud.fr>
Date: Sun, 13 Aug 2017 15:58:05 +0200
Subject: [PATCH] WIP: show several peptide match if needed in ptm islands

---
 src/grouping/ptm/ptmsamplescan.cpp            | 62 ++++++++-------
 src/grouping/ptm/ptmsamplescan.h              |  1 +
 .../ptmpeptidelistwindow.cpp                  |  3 +
 .../ptmpeptidelistwindow.h                    |  3 +
 .../ptmpeptidetableproxymodel.cpp             | 76 +++++++++++++++----
 .../ptmpeptidetableproxymodel.h               | 16 ++++
 6 files changed, 116 insertions(+), 45 deletions(-)

diff --git a/src/grouping/ptm/ptmsamplescan.cpp b/src/grouping/ptm/ptmsamplescan.cpp
index 2d9de0a7d..bf8cdce78 100644
--- a/src/grouping/ptm/ptmsamplescan.cpp
+++ b/src/grouping/ptm/ptmsamplescan.cpp
@@ -40,7 +40,7 @@ PtmSampleScan::PtmSampleScan(const PeptideMatch * p_peptide_match) {
     _peptide_match_list.push_back(p_peptide_match);
 }
 
-PtmSampleScan::PtmSampleScan(const PtmSampleScan& other){
+PtmSampleScan::PtmSampleScan(const PtmSampleScan& other) {
 }
 
 PtmSampleScan::~PtmSampleScan() {
@@ -59,8 +59,8 @@ bool PtmSampleScan::add(const PeptideMatch * p_peptide_match) {
         return false;
     }
     _peptide_match_list.push_back(p_peptide_match);
-    
-        //sort list
+
+    //sort list
     std::sort(_peptide_match_list.begin(),_peptide_match_list.end(),[](const PeptideMatch * first, const PeptideMatch * second) {
         return (first->getEvalue() < second->getEvalue()) ;
     });
@@ -68,24 +68,24 @@ bool PtmSampleScan::add(const PeptideMatch * p_peptide_match) {
     return true;
 }
 
-    std::vector<unsigned int> PtmSampleScan::getBestPtmPositionList(const PtmGroupingExperiment * p_ptm_grouping_experiment) const {
-        return p_ptm_grouping_experiment->getPtmPositions(getRepresentativePeptideMatch());
-    }
+std::vector<unsigned int> PtmSampleScan::getBestPtmPositionList(const PtmGroupingExperiment * p_ptm_grouping_experiment) const {
+    return p_ptm_grouping_experiment->getPtmPositions(getRepresentativePeptideMatch());
+}
 
-    std::vector<unsigned int> PtmSampleScan::getObservedPtmPositionList(const PtmGroupingExperiment * p_ptm_grouping_experiment) const {
-        std::vector<unsigned int> position_list;
+std::vector<unsigned int> PtmSampleScan::getObservedPtmPositionList(const PtmGroupingExperiment * p_ptm_grouping_experiment) const {
+    std::vector<unsigned int> position_list;
 
-        for (const PeptideMatch * p_peptide_match: _peptide_match_list) {
-            std::vector<unsigned int> positionb_list = p_ptm_grouping_experiment->getPtmPositions(p_peptide_match);
-            for (unsigned int position: positionb_list) {
-                position_list.push_back(position);
-            }
+    for (const PeptideMatch * p_peptide_match: _peptide_match_list) {
+        std::vector<unsigned int> positionb_list = p_ptm_grouping_experiment->getPtmPositions(p_peptide_match);
+        for (unsigned int position: positionb_list) {
+            position_list.push_back(position);
         }
-        std::sort(position_list.begin(), position_list.end());
-        auto last = std::unique(position_list.begin(), position_list.end());
-        position_list.erase(last, position_list.end());
-        return position_list;
     }
+    std::sort(position_list.begin(), position_list.end());
+    auto last = std::unique(position_list.begin(), position_list.end());
+    position_list.erase(last, position_list.end());
+    return position_list;
+}
 
 const QString PtmSampleScan::getHtmlSequence(const PtmGroupingExperiment * p_ptm_grouping_experiment) const
 {
@@ -98,7 +98,7 @@ const QString PtmSampleScan::getHtmlSequence(const PtmGroupingExperiment * p_ptm
     bool nobest_bool[pep_size] = {false};
     double best_evalue = p_representative_peptide->getEvalue();
 
-    
+
     for (auto & p_peptide_match : _peptide_match_list) {
         bool is_best= false;
         if (p_peptide_match->getEvalue() == best_evalue) {
@@ -121,17 +121,21 @@ const QString PtmSampleScan::getHtmlSequence(const PtmGroupingExperiment * p_ptm
     QString sequence_html;
     for (unsigned int i=0; i < pep_size; i++) {
         if (best_bool[i]) {
-                sequence_html.append(QString("<span style=\"color:%2;\">%1</span>").arg(sequence[i]).arg(_color_best.name()));
-            }
-            else if (other_best_bool[i]) {
-                sequence_html.append(QString("<span style=\"color:%2;\">%1</span>").arg(sequence[i]).arg(_color_other_best.name()));
-            }
-            else if (nobest_bool[i]){
-                sequence_html.append(QString("<span style=\"color:%2;\">%1</span>").arg(sequence[i]).arg(_color_no_best.name()));
-            }
-            else {
-                sequence_html.append(sequence[i]);
-            }
+            sequence_html.append(QString("<span style=\"color:%2;\">%1</span>").arg(sequence[i]).arg(_color_best.name()));
+        }
+        else if (other_best_bool[i]) {
+            sequence_html.append(QString("<span style=\"color:%2;\">%1</span>").arg(sequence[i]).arg(_color_other_best.name()));
+        }
+        else if (nobest_bool[i]) {
+            sequence_html.append(QString("<span style=\"color:%2;\">%1</span>").arg(sequence[i]).arg(_color_no_best.name()));
+        }
+        else {
+            sequence_html.append(sequence[i]);
+        }
     }
     return sequence_html;
 }
+
+const std::vector<const PeptideMatch *> & PtmSampleScan::getPeptideMatchList() const {
+    return _peptide_match_list;
+}
diff --git a/src/grouping/ptm/ptmsamplescan.h b/src/grouping/ptm/ptmsamplescan.h
index a6fa35f5e..5ae26bc05 100644
--- a/src/grouping/ptm/ptmsamplescan.h
+++ b/src/grouping/ptm/ptmsamplescan.h
@@ -53,6 +53,7 @@ public:
     std::vector<unsigned int> getBestPtmPositionList(const PtmGroupingExperiment * p_ptm_grouping_experiment) const;
     std::vector<unsigned int> getObservedPtmPositionList(const PtmGroupingExperiment * p_ptm_grouping_experiment) const;
     const QString getHtmlSequence(const PtmGroupingExperiment * p_ptm_grouping_experiment) const;
+    const std::vector<const PeptideMatch *> & getPeptideMatchList() const;
     
 private:
     std::vector<const PeptideMatch *> _peptide_match_list;
diff --git a/src/gui/ptm_peptide_list_view/ptmpeptidelistwindow.cpp b/src/gui/ptm_peptide_list_view/ptmpeptidelistwindow.cpp
index 9724b410d..32cd36467 100644
--- a/src/gui/ptm_peptide_list_view/ptmpeptidelistwindow.cpp
+++ b/src/gui/ptm_peptide_list_view/ptmpeptidelistwindow.cpp
@@ -34,6 +34,9 @@
 
 #include "ui_ptm_peptide_list_view.h"
 
+
+
+
 PtmPeptideListWindow::PtmPeptideListWindow(PtmIslandListWindow * parent):QMainWindow(parent),
     ui(new Ui::PtmPeptideListWindow) {
     _p_ptm_island_list_window = parent;
diff --git a/src/gui/ptm_peptide_list_view/ptmpeptidelistwindow.h b/src/gui/ptm_peptide_list_view/ptmpeptidelistwindow.h
index 5a6af5cf6..26bbcc747 100644
--- a/src/gui/ptm_peptide_list_view/ptmpeptidelistwindow.h
+++ b/src/gui/ptm_peptide_list_view/ptmpeptidelistwindow.h
@@ -41,6 +41,7 @@ namespace Ui {
 class PtmPeptideListWindow;
 }
 
+
 class PtmPeptideListWindow: public QMainWindow {
     Q_OBJECT
 public:
@@ -49,12 +50,14 @@ public:
     ~PtmPeptideListWindow();
     void setPtmIsland(PtmIsland * p_ptm_island);
 
+    
 private:
     PtmIsland * _p_ptm_island=nullptr;
     Ui::PtmPeptideListWindow *ui;
     PtmPeptideTableModel * _ptm_table_model_p = nullptr;
     PtmPeptideTableProxyModel * _ptm_proxy_model_p = nullptr;
     PtmIslandListWindow * _p_ptm_island_list_window;
+    QMenu * _p_context_menu = nullptr;
 
 };
 
diff --git a/src/gui/ptm_peptide_list_view/ptmpeptidetableproxymodel.cpp b/src/gui/ptm_peptide_list_view/ptmpeptidetableproxymodel.cpp
index fb0a15811..608b4e8b8 100644
--- a/src/gui/ptm_peptide_list_view/ptmpeptidetableproxymodel.cpp
+++ b/src/gui/ptm_peptide_list_view/ptmpeptidetableproxymodel.cpp
@@ -30,10 +30,35 @@
 #include "ptmpeptidetablemodel.h"
 #include "ptmpeptidelistwindow.h"
 
+PtmPeptideMenuQaction::PtmPeptideMenuQaction(PtmPeptideTableProxyModel * parent, const PtmSampleScan * p_ptm_sample, const PeptideMatch * p_peptide_match):QAction(parent) {
+
+    this->setText(p_peptide_match->getPeptideXtpSp().get()->getSequence());
+    //evalue_action.setChecked(_display_evalue);
+    //connect(p_action, SIGNAL(toggled(bool)), this, SLOT(showEvalueColumn(bool)));
+
+#if QT_VERSION >= 0x050000
+    // Qt5 code
+    /*
+    connect(&workerThread, &QThread::finished, worker, &QObject::deleteLater);
+    connect(this, &PtSpectrumViewer::operateMsDataFile, worker, &PwizLoaderThread::doMsDataFileLoad);
+    connect(worker, &PwizLoaderThread::msDataReady, this, &PtSpectrumViewer::handleMsDataFile);
+    */
+#else
+// Qt4 code
+    connect (this, SIGNAL(toggled(bool)), this,SLOT(doToggled(bool)));
+#endif
+}
+
+PtmPeptideMenuQaction::~PtmPeptideMenuQaction()
+{
+    //if (_p_ms_data_file != nullptr) delete _p_ms_data_file;
+    qDebug() << "PtmPeptideMenuQaction::~PtmPeptideMenuQaction begin ";
+
+}
 PtmPeptideTableProxyModel::PtmPeptideTableProxyModel(PtmPeptideListWindow * p_ptm_peptide_list_window, PtmPeptideTableModel* ptm_table_model_p)
 {
-  _p_ptm_peptide_list_window = p_ptm_peptide_list_window;
-  _p_ptm_table_model = ptm_table_model_p;
+    _p_ptm_peptide_list_window = p_ptm_peptide_list_window;
+    _p_ptm_table_model = ptm_table_model_p;
 }
 
 PtmPeptideTableProxyModel::~PtmPeptideTableProxyModel()
@@ -41,17 +66,36 @@ PtmPeptideTableProxyModel::~PtmPeptideTableProxyModel()
 
 }
 
- bool PtmPeptideTableProxyModel::lessThan(const QModelIndex &left,
-                                       const QModelIndex &right) const
- {
-     QVariant leftData = sourceModel()->data(left);
-     QVariant rightData = sourceModel()->data(right);
-
-     if (leftData.canConvert<PtmSampleScan *>()) {
-         PtmSampleScan * p_ptm_sample_scan_left = qvariant_cast<PtmSampleScan *>(leftData);
-         PtmSampleScan * p_ptm_sample_scan_right = qvariant_cast<PtmSampleScan *>(rightData);
-         return p_ptm_sample_scan_left->getRepresentativePeptideMatch()->getPeptideXtpSp().get()->toAbsoluteString() < p_ptm_sample_scan_right->getRepresentativePeptideMatch()->getPeptideXtpSp().get()->toAbsoluteString();
-     } else {
-         return QSortFilterProxyModel::lessThan(left, right);
-     }
- }
+bool PtmPeptideTableProxyModel::lessThan(const QModelIndex &left,
+        const QModelIndex &right) const
+{
+    QVariant leftData = sourceModel()->data(left);
+    QVariant rightData = sourceModel()->data(right);
+
+    if (leftData.canConvert<PtmSampleScan *>()) {
+        PtmSampleScan * p_ptm_sample_scan_left = qvariant_cast<PtmSampleScan *>(leftData);
+        PtmSampleScan * p_ptm_sample_scan_right = qvariant_cast<PtmSampleScan *>(rightData);
+        return p_ptm_sample_scan_left->getRepresentativePeptideMatch()->getPeptideXtpSp().get()->toAbsoluteString() < p_ptm_sample_scan_right->getRepresentativePeptideMatch()->getPeptideXtpSp().get()->toAbsoluteString();
+    } else {
+        return QSortFilterProxyModel::lessThan(left, right);
+    }
+}
+
+void PtmPeptideTableProxyModel::showContextMenu(const QModelIndex &index) {
+    if (_p_context_menu == nullptr) {
+        _p_context_menu = new QMenu(tr("Context menu"));
+
+    QVariant index_data = sourceModel()->data(index);
+
+    if (index_data.canConvert<PtmSampleScan *>()) {
+         PtmSampleScan * p_ptm_sample = qvariant_cast<PtmSampleScan *>(index_data);
+        PtmPeptideMenuQaction * p_action;
+        for (auto p_peptide_match : p_ptm_sample->getPeptideMatchList()) {
+            p_action = new PtmPeptideMenuQaction(this, p_ptm_sample, p_peptide_match);
+            _p_context_menu->addAction(p_action);
+        }
+    }
+        //_p_context_menu->exec(mapToGlobal(pos));
+    }
+    _p_context_menu->show();
+}
diff --git a/src/gui/ptm_peptide_list_view/ptmpeptidetableproxymodel.h b/src/gui/ptm_peptide_list_view/ptmpeptidetableproxymodel.h
index 95efc6f00..f20a6d2f7 100644
--- a/src/gui/ptm_peptide_list_view/ptmpeptidetableproxymodel.h
+++ b/src/gui/ptm_peptide_list_view/ptmpeptidetableproxymodel.h
@@ -31,11 +31,25 @@
 
 #include <QAbstractTableModel>
 #include <QSortFilterProxyModel>
+#include <QMenu>
+#include "../../grouping/ptm/ptmsamplescan.h"
 
 
 class PtmPeptideListWindow;
 class PtmPeptideTableModel;
 
+class PtmPeptideTableProxyModel;
+class PtmPeptideMenuQaction: public QAction {
+    Q_OBJECT
+public:
+
+    explicit PtmPeptideMenuQaction(PtmPeptideTableProxyModel * parent, const PtmSampleScan * p_ptm_sample, const PeptideMatch * p_peptide_match);
+    ~PtmPeptideMenuQaction();
+
+private:
+};
+
+
 class PtmPeptideTableProxyModel: public QSortFilterProxyModel
 {
     Q_OBJECT
@@ -45,9 +59,11 @@ public:
 
 protected:
      bool lessThan(const QModelIndex &left, const QModelIndex &right) const override;
+    void showContextMenu(const QModelIndex &index);
 private:
     PtmPeptideListWindow * _p_ptm_peptide_list_window;
     PtmPeptideTableModel* _p_ptm_table_model;
+    QMenu * _p_context_menu = nullptr;
 };
 
 #endif // PTMPEPTIDETABLEPROXYMODEL_H
-- 
GitLab