From a2f9fbf06ac8b93107f2ddffe0fd931e4a216a4c Mon Sep 17 00:00:00 2001
From: Olivier Langella <olivier.langella@u-psud.fr>
Date: Mon, 15 Oct 2018 08:42:45 +0200
Subject: [PATCH] WIP: replacing decoy selection with new widget

---
 src/gui/project_view/project_view.ui   | 122 +++++++------------------
 src/gui/project_view/projectwindow.cpp | 112 ++++++++++++++++-------
 src/gui/project_view/projectwindow.h   |  11 +--
 3 files changed, 113 insertions(+), 132 deletions(-)

diff --git a/src/gui/project_view/project_view.ui b/src/gui/project_view/project_view.ui
index 773a39e2f..b89a7c5dd 100644
--- a/src/gui/project_view/project_view.ui
+++ b/src/gui/project_view/project_view.ui
@@ -174,61 +174,13 @@
            </widget>
           </item>
           <item>
-           <layout class="QHBoxLayout" name="horizontalLayout_3">
-            <item>
-             <widget class="QRadioButton" name="decoy_database_files_radiobutton">
-              <property name="toolTip">
-               <string>select decoy sequences from fasta files</string>
-              </property>
-              <property name="text">
-               <string>data&amp;base files</string>
-              </property>
-              <attribute name="buttonGroup">
-               <string notr="true">decoy_source_buttongroup</string>
-              </attribute>
-             </widget>
-            </item>
-            <item>
-             <widget class="QRadioButton" name="decoy_regexp_radiobutton">
-              <property name="toolTip">
-               <string>select decoy sequences based on a regular expression</string>
-              </property>
-              <property name="text">
-               <string>&amp;regular expression</string>
-              </property>
-              <attribute name="buttonGroup">
-               <string notr="true">decoy_source_buttongroup</string>
-              </attribute>
-             </widget>
-            </item>
-           </layout>
-          </item>
-          <item>
-           <widget class="QGroupBox" name="decoy_database_groupbox">
-            <property name="title">
-             <string>Choose decoy database files</string>
-            </property>
-            <layout class="QVBoxLayout" name="verticalLayout_3">
-             <item>
-              <widget class="QListView" name="decoy_database_listview"/>
-             </item>
-            </layout>
-           </widget>
-          </item>
-          <item>
-           <widget class="QGroupBox" name="decoy_regexp_groupbox">
-            <property name="title">
-             <string>Set regular expression to select decoy proteins</string>
+           <widget class="DecoyWidget" name="decoy_widget" native="true">
+            <property name="minimumSize">
+             <size>
+              <width>10</width>
+              <height>10</height>
+             </size>
             </property>
-            <layout class="QVBoxLayout" name="verticalLayout_4">
-             <item>
-              <widget class="QLineEdit" name="decoy_protein_regexp_line_edit">
-               <property name="placeholderText">
-                <string>.*\\|reversed$</string>
-               </property>
-              </widget>
-             </item>
-            </layout>
            </widget>
           </item>
           <item>
@@ -412,6 +364,15 @@
     <signal>changed()</signal>
    </slots>
   </customwidget>
+  <customwidget>
+   <class>DecoyWidget</class>
+   <extends>QWidget</extends>
+   <header>gui/widgets/decoy_widget/decoywidget.h</header>
+   <container>1</container>
+   <slots>
+    <signal>changed()</signal>
+   </slots>
+  </customwidget>
  </customwidgets>
  <resources/>
  <connections>
@@ -422,8 +383,8 @@
    <slot>doFdrChanged()</slot>
    <hints>
     <hint type="sourcelabel">
-     <x>119</x>
-     <y>104</y>
+     <x>448</x>
+     <y>219</y>
     </hint>
     <hint type="destinationlabel">
      <x>484</x>
@@ -464,66 +425,50 @@
    </hints>
   </connection>
   <connection>
-   <sender>decoy_database_files_radiobutton</sender>
-   <signal>clicked()</signal>
+   <sender>contaminant_widget</sender>
+   <signal>changed()</signal>
    <receiver>ProjectView</receiver>
-   <slot>doSelectDecoySource()</slot>
+   <slot>doFilterChanged()</slot>
    <hints>
     <hint type="sourcelabel">
-     <x>68</x>
+     <x>119</x>
      <y>104</y>
     </hint>
     <hint type="destinationlabel">
-     <x>682</x>
-     <y>256</y>
+     <x>815</x>
+     <y>196</y>
     </hint>
    </hints>
   </connection>
   <connection>
-   <sender>decoy_regexp_radiobutton</sender>
+   <sender>apply_filter_button</sender>
    <signal>clicked()</signal>
    <receiver>ProjectView</receiver>
-   <slot>doSelectDecoySource()</slot>
+   <slot>doApplyFilter()</slot>
    <hints>
     <hint type="sourcelabel">
      <x>119</x>
      <y>104</y>
     </hint>
     <hint type="destinationlabel">
-     <x>693</x>
-     <y>239</y>
+     <x>689</x>
+     <y>147</y>
     </hint>
    </hints>
   </connection>
   <connection>
-   <sender>contaminant_widget</sender>
+   <sender>decoy_widget</sender>
    <signal>changed()</signal>
    <receiver>ProjectView</receiver>
    <slot>doFilterChanged()</slot>
    <hints>
     <hint type="sourcelabel">
-     <x>368</x>
-     <y>99</y>
+     <x>180</x>
+     <y>182</y>
     </hint>
     <hint type="destinationlabel">
-     <x>815</x>
-     <y>196</y>
-    </hint>
-   </hints>
-  </connection>
-  <connection>
-   <sender>apply_filter_button</sender>
-   <signal>clicked()</signal>
-   <receiver>ProjectView</receiver>
-   <slot>doApplyFilter()</slot>
-   <hints>
-    <hint type="sourcelabel">
-     <x>412</x>
-     <y>120</y>
-    </hint>
-    <hint type="destinationlabel">
-     <x>689</x>
-     <y>147</y>
+     <x>763</x>
+     <y>179</y>
     </hint>
    </hints>
   </connection>
@@ -537,7 +482,4 @@
   <slot>doFilterChanged()</slot>
   <slot>doApplyFilter()</slot>
  </slots>
- <buttongroups>
-  <buttongroup name="decoy_source_buttongroup"/>
- </buttongroups>
 </ui>
diff --git a/src/gui/project_view/projectwindow.cpp b/src/gui/project_view/projectwindow.cpp
index b270acd28..8ee7b7e54 100644
--- a/src/gui/project_view/projectwindow.cpp
+++ b/src/gui/project_view/projectwindow.cpp
@@ -50,11 +50,6 @@ ProjectWindow::ProjectWindow(MainWindow *parent)
   p_worker->moveToThread(&_worker_thread);
   _worker_thread.start();
 
-  _p_fasta_str_li = new QStandardItemModel();
-  ui->decoy_database_listview->setModel(_p_fasta_str_li);
-  ui->decoy_database_listview->setSelectionMode(
-    QAbstractItemView::MultiSelection);
-
 
   _p_edit_modifications     = new EditModifications(this);
   _p_edit_label_methods     = new EditLabelMethods(this);
@@ -89,12 +84,21 @@ ProjectWindow::ProjectWindow(MainWindow *parent)
 #if QT_VERSION >= 0x050000
   // Qt5 code
   connect(ui->filter_parameter_widget,
-          &AutomaticFilterWidget::automaticFilterParametersChanged, this,
+          &AutomaticFilterWidget::automaticFilterParametersChanged,
+          this,
           &ProjectWindow::doAutomaticFilterParametersChanged);
-  connect(ui->contaminant_widget, &ContaminantWidget::changed, this,
+  connect(ui->contaminant_widget,
+          &ContaminantWidget::changed,
+          this,
           &ProjectWindow::doContaminantSelectionChanged);
+  connect(ui->decoy_widget,
+          &DecoyWidget::changed,
+          this,
+          &ProjectWindow::doDecoySelectionChanged);
 
-  connect(_p_edit_label_methods, &EditLabelMethods::accepted, this,
+  connect(_p_edit_label_methods,
+          &EditLabelMethods::accepted,
+          this,
           &ProjectWindow::doAcceptedLabelingMethod);
 
 #else
@@ -106,7 +110,9 @@ ProjectWindow::ProjectWindow(MainWindow *parent)
           this,
           SLOT(doAutomaticFilterParametersChanged(AutomaticFilterParameters)));
 
-  connect(_p_edit_label_methods, SIGNAL(accepted()), this,
+  connect(_p_edit_label_methods,
+          SIGNAL(accepted()),
+          this,
           SLOT(doAcceptedLabelingMethod()));
 
   // connect(this, SIGNAL(operateGrouping(ProjectSp)),
@@ -217,13 +223,13 @@ ProjectWindow::refreshPtmGroup(IdentificationGroup *p_ident_group)
         }
       catch(pappso::PappsoException exception_pappso)
         {
-          QMessageBox::warning(this, tr("Unable to display project :"),
-                               exception_pappso.qwhat());
+          QMessageBox::warning(
+            this, tr("Unable to display project :"), exception_pappso.qwhat());
         }
       catch(std::exception exception_std)
         {
-          QMessageBox::warning(this, tr("Unable to display project :"),
-                               exception_std.what());
+          QMessageBox::warning(
+            this, tr("Unable to display project :"), exception_std.what());
         }
     }
   qDebug() << "ProjectWindow::refreshPtmGroup end";
@@ -245,13 +251,13 @@ ProjectWindow::refreshGroup(IdentificationGroup *p_ident_group)
         }
       catch(pappso::PappsoException exception_pappso)
         {
-          QMessageBox::warning(this, tr("Unable to display project :"),
-                               exception_pappso.qwhat());
+          QMessageBox::warning(
+            this, tr("Unable to display project :"), exception_pappso.qwhat());
         }
       catch(std::exception exception_std)
         {
-          QMessageBox::warning(this, tr("Unable to display project :"),
-                               exception_std.what());
+          QMessageBox::warning(
+            this, tr("Unable to display project :"), exception_std.what());
         }
     }
   qDebug() << "ProjectWindow::refreshGroup end";
@@ -284,13 +290,13 @@ ProjectWindow::computeFdr()
     }
   catch(pappso::PappsoException exception_pappso)
     {
-      QMessageBox::warning(this, tr("Unable to compute FDR :"),
-                           exception_pappso.qwhat());
+      QMessageBox::warning(
+        this, tr("Unable to compute FDR :"), exception_pappso.qwhat());
     }
   catch(std::exception exception_std)
     {
-      QMessageBox::warning(this, tr("Unable to compute FDR :"),
-                           exception_std.what());
+      QMessageBox::warning(
+        this, tr("Unable to compute FDR :"), exception_std.what());
     }
   qDebug() << "ProjectWindow::computeFdr end";
 }
@@ -375,7 +381,8 @@ ProjectWindow::computeMassPrecision()
       ui->mass_precision_mean_label->setText("0");
       ui->mass_precision_median_label->setText("0");
       ui->mass_precision_sd_label->setText("0");
-      QMessageBox::warning(this, tr("Unable to compute mass precision :"),
+      QMessageBox::warning(this,
+                           tr("Unable to compute mass precision :"),
                            exception_pappso.qwhat());
     }
   catch(std::exception exception_std)
@@ -383,8 +390,8 @@ ProjectWindow::computeMassPrecision()
       ui->mass_precision_mean_label->setText("0");
       ui->mass_precision_median_label->setText("0");
       ui->mass_precision_sd_label->setText("0");
-      QMessageBox::warning(this, tr("Unable to compute mass precision :"),
-                           exception_std.what());
+      QMessageBox::warning(
+        this, tr("Unable to compute mass precision :"), exception_std.what());
     }
   qDebug() << "ProjectWindow::computeMassPrecision end";
 }
@@ -439,14 +446,14 @@ ProjectWindow::doFdrChanged()
   catch(pappso::PappsoException exception_pappso)
     {
       hideWaitingMessage();
-      QMessageBox::warning(this, tr("Unable to compute FDR :"),
-                           exception_pappso.qwhat());
+      QMessageBox::warning(
+        this, tr("Unable to compute FDR :"), exception_pappso.qwhat());
     }
   catch(std::exception exception_std)
     {
       hideWaitingMessage();
-      QMessageBox::warning(this, tr("Unable to compute FDR :"),
-                           exception_std.what());
+      QMessageBox::warning(
+        this, tr("Unable to compute FDR :"), exception_std.what());
     }
 
   qDebug() << "ProjectWindow::doFdrChanged end ";
@@ -964,6 +971,44 @@ void
 ProjectWindow::doFilterChanged()
 {
   ui->apply_filter_button->setEnabled(true);
+  ui->fdr_button->setEnabled(true);
+}
+
+void
+ProjectWindow::doApplyDecoy()
+{
+  ui->fdr_button->setEnabled(false);
+  // doAutomaticFilterParametersChanged(automatic_filter);
+  try
+    {
+      showWaitingMessage(tr("Updating decoy sequences"));
+
+      doDisplayLoadingMessage(tr("tagging decoy proteins"));
+
+      ui->decoy_widget->setProjectDecoys(_project_sp.get());
+      // doDisplayLoadingMessage(tr("updating FDR"));
+      //_project_sp.get()->updateAutomaticFilters(automatic_filter);
+      doDisplayLoadingMessage(tr("updating filters"));
+      _project_sp.get()->updateAutomaticFilters(
+        _project_sp.get()->getAutomaticFilterParameters());
+      
+      
+
+      qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__;
+      emit operateGrouping(_project_sp);
+    }
+  catch(pappso::PappsoException exception_pappso)
+    {
+      hideWaitingMessage();
+      QMessageBox::warning(
+        this, tr("Error filtering results :"), exception_pappso.qwhat());
+    }
+  catch(std::exception exception_std)
+    {
+      hideWaitingMessage();
+      QMessageBox::warning(
+        this, tr("Error filtering results :"), exception_std.what());
+    }
 }
 
 void
@@ -983,20 +1028,19 @@ ProjectWindow::doApplyFilter()
       doDisplayLoadingMessage(tr("updating filters"));
       _project_sp.get()->updateAutomaticFilters(automatic_filter);
 
-      qDebug() << "ProjectWindow::doAutomaticFilterParametersChanged emit "
-                  "operateGrouping(_project_sp) ";
+      qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__;
       emit operateGrouping(_project_sp);
     }
   catch(pappso::PappsoException exception_pappso)
     {
       hideWaitingMessage();
-      QMessageBox::warning(this, tr("Error filtering results :"),
-                           exception_pappso.qwhat());
+      QMessageBox::warning(
+        this, tr("Error filtering results :"), exception_pappso.qwhat());
     }
   catch(std::exception exception_std)
     {
       hideWaitingMessage();
-      QMessageBox::warning(this, tr("Error filtering results :"),
-                           exception_std.what());
+      QMessageBox::warning(
+        this, tr("Error filtering results :"), exception_std.what());
     }
 }
diff --git a/src/gui/project_view/projectwindow.h b/src/gui/project_view/projectwindow.h
index 7855d705d..6ff7aa6cb 100644
--- a/src/gui/project_view/projectwindow.h
+++ b/src/gui/project_view/projectwindow.h
@@ -17,13 +17,9 @@
  *     You should have received a copy of the GNU General Public License
  *     along with XTPcpp.  If not, see <http://www.gnu.org/licenses/>.
  *
- * Contributors:
- *     Olivier Langella <olivier.langella@u-psud.fr> - initial API and
- *implementation
  ******************************************************************************/
 
-#ifndef PROJECTWINDOW_H
-#define PROJECTWINDOW_H
+#pragma once
 
 #include <QMainWindow>
 #include <QThread>
@@ -46,7 +42,7 @@ class MainWindow;
 // http://doc.qt.io/qt-4.8/qt-itemviews-chart-mainwindow-cpp.html
 namespace Ui
 {
-  class ProjectView;
+class ProjectView;
 }
 
 class ProjectWindow : public QMainWindow
@@ -107,6 +103,7 @@ class ProjectWindow : public QMainWindow
   void doViewProteinDetail(ProteinMatch *protein_match);
   void doIdentificationGroupEdited(IdentificationGroup *p_identification_group);
   void doContaminantSelectionChanged();
+  void doDecoySelectionChanged();
   void computeFdr();
   void computeMassPrecision();
 
@@ -150,5 +147,3 @@ class ProjectWindow : public QMainWindow
   // QCPBars *_p_bars;
 };
 
-
-#endif // PROJECTWINDOW_H
-- 
GitLab