From 7c3309b2cf6fc4c9d89a8cbc14e23beb7c2399f4 Mon Sep 17 00:00:00 2001
From: Olivier Langella <Olivier.Langella@moulon.inra.fr>
Date: Mon, 3 Apr 2017 11:25:38 +0200
Subject: [PATCH] highlight peptide is OK

---
 src/CMakeLists.txt                     |  4 +--
 src/core/proteinmatch.cpp              | 49 +++++++++++++++++++++++---
 src/core/proteinmatch.h                | 17 ++++++---
 src/gui/project_view/projectwindow.cpp |  2 ++
 src/gui/project_view/projectwindow.h   |  1 +
 src/gui/protein_view/proteinwindow.cpp |  8 +++++
 src/gui/protein_view/proteinwindow.h   |  1 +
 7 files changed, 72 insertions(+), 10 deletions(-)

diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index ced3b3bd..a40d8a47 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -29,8 +29,8 @@ SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt5Xml_EXECUTABLE_COMPILE_FLAGS} ${Qt5
 
 #sudo apt-get install libpappsomspp-dev
 #FIND_PACKAGE( Pappsomspp REQUIRED )
- SET (PAPPSOMSPP_DIR  "/home/olivier/eclipse/git/pappsomspp")
-# SET (PAPPSOMSPP_DIR  "/home/langella/developpement/git/pappsomspp")
+# SET (PAPPSOMSPP_DIR  "/home/olivier/eclipse/git/pappsomspp")
+ SET (PAPPSOMSPP_DIR  "/home/langella/developpement/git/pappsomspp")
  SET (PAPPSOMSPP_INCLUDE_DIR "${PAPPSOMSPP_DIR}/src")
  SET (PAPPSOMSPP_QT4_LIBRARY "${PAPPSOMSPP_DIR}/cbuild/src/libpappsomspp-qt4.so")
 
diff --git a/src/core/proteinmatch.cpp b/src/core/proteinmatch.cpp
index 013d1968..091f7ac5 100644
--- a/src/core/proteinmatch.cpp
+++ b/src/core/proteinmatch.cpp
@@ -27,6 +27,10 @@
 #include <set>
 
 
+QColor ProteinMatch::_color_peptide_background = QColor("yellow");
+QColor ProteinMatch::_color_highlighted_peptide_background = QColor("#ff7878");
+
+
 ProteinMatch::ProteinMatch()
 {
 
@@ -41,6 +45,14 @@ ProteinMatch::~ProteinMatch()
     }
 }
 
+bool ProteinMatch::contains(PeptideMatch * peptide_match) const {
+    if (peptide_match == nullptr) return false;
+    for (auto & p_peptide_match : _peptide_match_list) {
+        if (p_peptide_match == peptide_match) return true;
+    }
+    return false;
+}
+
 void ProteinMatch::updateAutomaticFilters(const AutomaticFilterParameters & automatic_filter_parameters) {
     qDebug() <<"ProteinMatch::updateAutomaticFilters begin " ;
     _proxy_valid = false;
@@ -273,12 +285,23 @@ pappso::pappso_double ProteinMatch::getPAI(const pappso::MsRunIdSp & sp_msrun_id
 }
 
 
-const QString ProteinMatch::getHtmlSequence() const
+const QString ProteinMatch::getHtmlSequence(PeptideMatch * peptide_match_to_locate) const
 {
     size_t prot_size = _protein_sp.get()->size();
     //qDebug() << "ProteinMatch::getCoverage begin prot_size=" << prot_size << " " << _protein_sp.get()-//>getSequence();
     if (prot_size == 0) return 0;
     bool cover_bool[prot_size] = {false};
+    bool highlight_bool[prot_size] = {false};
+    if (this->contains(peptide_match_to_locate)) {
+        size_t size = peptide_match_to_locate->getPeptideXtpSp().get()->size();
+        size_t offset = peptide_match_to_locate->getStart();
+        if (offset >= 0) {
+            for (size_t i=0; (i < size) && (offset < prot_size) ; i++,offset++) {
+                highlight_bool[offset] = true;
+            }
+        }
+    }
+
     for (auto & p_peptide_match : _peptide_match_list) {
         if (p_peptide_match->isValidAndChecked()) {
             size_t size = p_peptide_match->getPeptideXtpSp().get()->size();
@@ -293,11 +316,29 @@ const QString ProteinMatch::getHtmlSequence() const
     QString sequence = getProteinXtpSp().get()->getSequence();
     QString sequence_html;
     for (unsigned int i=0; i < prot_size; i++) {
-
-        if(cover_bool[i]) {
-            sequence_html.append(QString("<span style=\"background-color:yellow;\">%1").arg(sequence[i]));
+        if(highlight_bool[i]) {
+            sequence_html.append(QString("<span style=\"background-color:%2;\">%1").arg(sequence[i]).arg(_color_highlighted_peptide_background.name()));
+            i++;
+            for (; i < prot_size; i++) {
+                if(highlight_bool[i]) {
+                    sequence_html.append(sequence[i]);
+                }
+                else {
+                    sequence_html.append(QString("</span>"));
+		    i--;
+                    break;
+                }
+            }
+            sequence_html.append(QString("</span>"));
+        }
+        else if(cover_bool[i]) {
+            sequence_html.append(QString("<span style=\"background-color:%2;\">%1").arg(sequence[i]).arg(_color_peptide_background.name()));
             i++;
             for (; i < prot_size; i++) {
+                if (highlight_bool[i]) {
+		  i--;
+		  break;
+		}
                 if(cover_bool[i]) {
                     sequence_html.append(sequence[i]);
                 }
diff --git a/src/core/proteinmatch.h b/src/core/proteinmatch.h
index 49cc8fca..c2693248 100644
--- a/src/core/proteinmatch.h
+++ b/src/core/proteinmatch.h
@@ -21,6 +21,7 @@
 *     Olivier Langella <olivier.langella@u-psud.fr> - initial API and implementation
 ******************************************************************************/
 
+#include <QColor>
 #include <vector>
 #include <pappsomspp/types.h>
 #include "proteinxtp.h"
@@ -48,7 +49,7 @@ public:
     /** @brief compute protein Evalue overall samples
       * */
     pappso::pappso_double getEvalue() const;
-    
+
     /** @brief compute protein Evalue within samples
       * */
     pappso::pappso_double getEvalue(const pappso::MsRunIdSp & sp_msrun_id) const;
@@ -58,9 +59,10 @@ public:
       * */
     pappso::pappso_double getCoverage() const;
 
-/** @brief get coverage sequence (html representation) 
- **/    
-    const QString getHtmlSequence() const;
+    /** @brief get coverage sequence (html representation)
+     * @param peptide_match_to_locate pointer to optional peptide match to locate on protein sequence
+     **/
+    const QString getHtmlSequence(PeptideMatch * peptide_match_to_locate = nullptr) const;
 
     /** @brief compute Protein Abundance Index (PAI)
       * overall sample PAI computation (Rappsilber et al. 2002)
@@ -102,6 +104,9 @@ public:
     * */
     void updateAutomaticFilters(const AutomaticFilterParameters & automatic_filter_parameters);
 
+    /** @brief tells if this protein match contains this peptides
+     */
+    bool contains(PeptideMatch * peptide_match) const;
 protected :
 
     void setGroupingExperiment(GroupingExperiment * p_grp_experiment);
@@ -113,6 +118,10 @@ private :
     unsigned int countValidAndCheckedPeptideMassCharge(const pappso::MsRunIdSp & sp_msrun_id) const;
 
 private:
+  static QColor _color_peptide_background;
+  static QColor _color_highlighted_peptide_background;
+  
+  
     pappso::GrpProteinSp _sp_grp_protein;
     GroupingGroupSp _sp_group;
 
diff --git a/src/gui/project_view/projectwindow.cpp b/src/gui/project_view/projectwindow.cpp
index 57f6c18f..f631bb82 100644
--- a/src/gui/project_view/projectwindow.cpp
+++ b/src/gui/project_view/projectwindow.cpp
@@ -193,6 +193,8 @@ void ProjectWindow::doViewPeptideDetail(PeptideMatch * peptide_match) {
 
     _p_current_peptide_detail_window->setPeptideMatch(peptide_match);
     _p_current_peptide_detail_window->show();
+    
+    emit peptideMatchSelected(peptide_match);
     qDebug() << "ProjectWindow::doViewPeptideDetail end";
 }
 
diff --git a/src/gui/project_view/projectwindow.h b/src/gui/project_view/projectwindow.h
index daae3dc4..1926e13d 100644
--- a/src/gui/project_view/projectwindow.h
+++ b/src/gui/project_view/projectwindow.h
@@ -57,6 +57,7 @@ public slots:
     // void setShape(Shape shape);
 signals:
     void identificationGroupGrouped(IdentificationGroup * p_identification_group);
+    void peptideMatchSelected(PeptideMatch * peptide_match);
     //void peptideChanged(pappso::PeptideSp peptide);
     
 protected :
diff --git a/src/gui/protein_view/proteinwindow.cpp b/src/gui/protein_view/proteinwindow.cpp
index 1df41309..b683f168 100644
--- a/src/gui/protein_view/proteinwindow.cpp
+++ b/src/gui/protein_view/proteinwindow.cpp
@@ -48,6 +48,7 @@ ProteinWindow::ProteinWindow(ProjectWindow *parent):
 #else
 // Qt4 code
     connect (_p_project_window, SIGNAL(identificationGroupGrouped(IdentificationGroup *)), this,SLOT(doIdentificationGroupGrouped(IdentificationGroup *)));
+    connect (_p_project_window, SIGNAL(peptideMatchSelected(PeptideMatch*)), this,SLOT(doPeptideMatchSelected(PeptideMatch*)));
 
     //connect(_protein_table_model_p, SIGNAL(layoutChanged()), this, SLOT(updateStatusBar()));
 #endif
@@ -61,6 +62,13 @@ void ProteinWindow::doIdentificationGroupGrouped(IdentificationGroup * p_identif
     updateDisplay();
 }
 
+void ProteinWindow::doPeptideMatchSelected(PeptideMatch * peptide_match) {
+    if (_p_protein_match != nullptr) {
+            ui->sequenceTextEdit->setText(_p_protein_match->getHtmlSequence(peptide_match));
+
+    }
+}
+
 void ProteinWindow::updateDisplay() {
     try {
         ui->validCheckBox->setCheckState(Qt::Unchecked);
diff --git a/src/gui/protein_view/proteinwindow.h b/src/gui/protein_view/proteinwindow.h
index 3dfeeda5..a9a14708 100644
--- a/src/gui/protein_view/proteinwindow.h
+++ b/src/gui/protein_view/proteinwindow.h
@@ -45,6 +45,7 @@ public:
     
 public slots:
     void doIdentificationGroupGrouped(IdentificationGroup * p_identification_group);
+    void doPeptideMatchSelected(PeptideMatch * peptide_match);
     
 protected :
     void updateDisplay();
-- 
GitLab