From 14a62e114a5edfc61f6c602884639c86945dd956 Mon Sep 17 00:00:00 2001
From: Olivier Langella <olivier.langella@u-psud.fr>
Date: Thu, 8 Feb 2018 22:28:34 +0100
Subject: [PATCH] new ui to select contaminants

---
 src/CMakeLists.txt                     |   4 +-
 src/gui/project_view/project_view.ui   | 153 +++++++++++++++++--------
 src/gui/project_view/projectwindow.cpp |  47 ++++++--
 src/gui/project_view/projectwindow.h   |   1 +
 4 files changed, 146 insertions(+), 59 deletions(-)

diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 159b03b3f..71bd578d3 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -28,8 +28,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_QT5_LIBRARY "${PAPPSOMSPP_DIR}/cbuild/src/libpappsomspp-qt5.so")
  SET (PAPPSOMSPP_WIDGET_QT5_LIBRARY "${PAPPSOMSPP_DIR}/cbuild/src/pappsomspp/widget/libpappsomspp-widget-qt5.so")
diff --git a/src/gui/project_view/project_view.ui b/src/gui/project_view/project_view.ui
index 358663a03..674a4dd86 100644
--- a/src/gui/project_view/project_view.ui
+++ b/src/gui/project_view/project_view.ui
@@ -6,7 +6,7 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>465</width>
+    <width>471</width>
     <height>533</height>
    </rect>
   </property>
@@ -24,7 +24,7 @@
        <string/>
       </property>
       <property name="currentIndex">
-       <number>2</number>
+       <number>0</number>
       </property>
       <widget class="QWidget" name="identifications">
        <attribute name="title">
@@ -59,21 +59,68 @@
              <string>Contaminants</string>
             </property>
             <layout class="QVBoxLayout" name="verticalLayout_6">
+             <item>
+              <layout class="QHBoxLayout" name="horizontalLayout_4">
+               <item>
+                <widget class="QRadioButton" name="contaminant_file_radiobutton">
+                 <property name="toolTip">
+                  <string>select contaminants from fasta files</string>
+                 </property>
+                 <property name="text">
+                  <string>contaminant file</string>
+                 </property>
+                 <attribute name="buttonGroup">
+                  <string notr="true">contaminant_source_buttongroup</string>
+                 </attribute>
+                </widget>
+               </item>
+               <item>
+                <widget class="QRadioButton" name="contaminant_regexp_radiobutton">
+                 <property name="toolTip">
+                  <string>select contaminants using a regular expression</string>
+                 </property>
+                 <property name="text">
+                  <string>contaminant regular expression</string>
+                 </property>
+                 <attribute name="buttonGroup">
+                  <string notr="true">contaminant_source_buttongroup</string>
+                 </attribute>
+                </widget>
+               </item>
+              </layout>
+             </item>
              <item>
               <widget class="QListView" name="contaminant_database_listview"/>
              </item>
              <item>
-              <widget class="QLineEdit" name="contaminant_protein_regexp_line_edit">
-               <property name="placeholderText">
-                <string>^conta\\|</string>
-               </property>
-              </widget>
+              <layout class="QVBoxLayout" name="verticalLayout_8">
+               <item>
+                <widget class="QLineEdit" name="contaminant_protein_regexp_line_edit">
+                 <property name="placeholderText">
+                  <string>^conta\\|</string>
+                 </property>
+                </widget>
+               </item>
+              </layout>
              </item>
             </layout>
            </widget>
           </item>
          </layout>
         </item>
+        <item row="1" column="0">
+         <spacer name="verticalSpacer_2">
+          <property name="orientation">
+           <enum>Qt::Vertical</enum>
+          </property>
+          <property name="sizeHint" stdset="0">
+           <size>
+            <width>20</width>
+            <height>40</height>
+           </size>
+          </property>
+         </spacer>
+        </item>
        </layout>
       </widget>
       <widget class="QWidget" name="fdr">
@@ -140,7 +187,7 @@
                <string>select decoy sequences from fasta files</string>
               </property>
               <property name="text">
-               <string>database files</string>
+               <string>data&amp;base files</string>
               </property>
               <attribute name="buttonGroup">
                <string notr="true">decoy_source_buttongroup</string>
@@ -153,7 +200,7 @@
                <string>select decoy sequences based on a regular expression</string>
               </property>
               <property name="text">
-               <string>regular expression</string>
+               <string>&amp;regular expression</string>
               </property>
               <attribute name="buttonGroup">
                <string notr="true">decoy_source_buttongroup</string>
@@ -171,30 +218,6 @@
              <item>
               <widget class="QListView" name="decoy_database_listview"/>
              </item>
-             <item>
-              <layout class="QHBoxLayout" name="horizontalLayout">
-               <item>
-                <spacer name="horizontalSpacer">
-                 <property name="orientation">
-                  <enum>Qt::Horizontal</enum>
-                 </property>
-                 <property name="sizeHint" stdset="0">
-                  <size>
-                   <width>40</width>
-                   <height>20</height>
-                  </size>
-                 </property>
-                </spacer>
-               </item>
-               <item>
-                <widget class="QPushButton" name="pushButton">
-                 <property name="text">
-                  <string>add</string>
-                 </property>
-                </widget>
-               </item>
-              </layout>
-             </item>
             </layout>
            </widget>
           </item>
@@ -211,19 +234,6 @@
                </property>
               </widget>
              </item>
-             <item>
-              <spacer name="verticalSpacer">
-               <property name="orientation">
-                <enum>Qt::Vertical</enum>
-               </property>
-               <property name="sizeHint" stdset="0">
-                <size>
-                 <width>20</width>
-                 <height>40</height>
-                </size>
-               </property>
-              </spacer>
-             </item>
             </layout>
            </widget>
           </item>
@@ -253,6 +263,19 @@
           </item>
          </layout>
         </item>
+        <item row="1" column="0">
+         <spacer name="verticalSpacer">
+          <property name="orientation">
+           <enum>Qt::Vertical</enum>
+          </property>
+          <property name="sizeHint" stdset="0">
+           <size>
+            <width>20</width>
+            <height>40</height>
+           </size>
+          </property>
+         </spacer>
+        </item>
        </layout>
       </widget>
       <widget class="QWidget" name="mass_precision">
@@ -366,7 +389,7 @@
     <rect>
      <x>0</x>
      <y>0</y>
-     <width>465</width>
+     <width>471</width>
      <height>25</height>
     </rect>
    </property>
@@ -391,7 +414,7 @@
    <hints>
     <hint type="sourcelabel">
      <x>442</x>
-     <y>430</y>
+     <y>485</y>
     </hint>
     <hint type="destinationlabel">
      <x>484</x>
@@ -463,14 +486,48 @@
     </hint>
    </hints>
   </connection>
+  <connection>
+   <sender>contaminant_file_radiobutton</sender>
+   <signal>clicked()</signal>
+   <receiver>ProjectView</receiver>
+   <slot>doSelectContaminantSource()</slot>
+   <hints>
+    <hint type="sourcelabel">
+     <x>159</x>
+     <y>127</y>
+    </hint>
+    <hint type="destinationlabel">
+     <x>581</x>
+     <y>113</y>
+    </hint>
+   </hints>
+  </connection>
+  <connection>
+   <sender>contaminant_regexp_radiobutton</sender>
+   <signal>clicked()</signal>
+   <receiver>ProjectView</receiver>
+   <slot>doSelectContaminantSource()</slot>
+   <hints>
+    <hint type="sourcelabel">
+     <x>408</x>
+     <y>129</y>
+    </hint>
+    <hint type="destinationlabel">
+     <x>578</x>
+     <y>62</y>
+    </hint>
+   </hints>
+  </connection>
  </connections>
  <slots>
   <slot>doFdrChanged()</slot>
   <slot>doMassPrecisionUnitChanged(QString)</slot>
   <slot>doIdentificationsComboboxChanged(int)</slot>
   <slot>doSelectDecoySource()</slot>
+  <slot>doSelectContaminantSource()</slot>
  </slots>
  <buttongroups>
   <buttongroup name="decoy_source_buttongroup"/>
+  <buttongroup name="contaminant_source_buttongroup"/>
  </buttongroups>
 </ui>
diff --git a/src/gui/project_view/projectwindow.cpp b/src/gui/project_view/projectwindow.cpp
index 06ddc310a..870001f64 100644
--- a/src/gui/project_view/projectwindow.cpp
+++ b/src/gui/project_view/projectwindow.cpp
@@ -392,16 +392,18 @@ void ProjectWindow::doAutomaticFilterParametersChanged(AutomaticFilterParameters
         showWaitingMessage(tr("Updating filters"));
 
         doDisplayLoadingMessage(tr("tagging contaminant proteins"));
-        QModelIndexList index_list = ui->contaminant_database_listview->selectionModel()->selectedIndexes();
-        if (index_list.size() > 0) {
+        if (ui->contaminant_file_radiobutton->isChecked()) {
+            QModelIndexList index_list = ui->contaminant_database_listview->selectionModel()->selectedIndexes();
             _project_sp.get()->getProteinStore().clearContaminants();
-            for (QModelIndex index :index_list) {
-                if (index.data(Qt::UserRole).canConvert<FastaFile *>()) {
-                    FastaFile * p_fasta_file = index.data(Qt::UserRole).value<FastaFile *>();
-                    p_fasta_file->setContaminants(_project_sp.get()->getProteinStore());
-                }
-                else {
-                    throw pappso::PappsoException(QObject::tr("can not convert to FastaFile index.data().canConvert<FastaFile *>()"));
+            if (index_list.size() > 0) {
+                for (QModelIndex index :index_list) {
+                    if (index.data(Qt::UserRole).canConvert<FastaFile *>()) {
+                        FastaFile * p_fasta_file = index.data(Qt::UserRole).value<FastaFile *>();
+                        p_fasta_file->setContaminants(_project_sp.get()->getProteinStore());
+                    }
+                    else {
+                        throw pappso::PappsoException(QObject::tr("can not convert to FastaFile index.data().canConvert<FastaFile *>()"));
+                    }
                 }
             }
         }
@@ -591,6 +593,20 @@ void ProjectWindow::setProjectSp(ProjectSp project_sp) {
     _project_sp = project_sp;
     ui->decoy_regexp_radiobutton->setChecked(true);
     ui->decoy_database_groupbox->setVisible(false);
+    if (_project_sp.get()->getProteinStore().getDecoyFastaFileList().size() > 0) {
+        ui->decoy_database_files_radiobutton->setChecked(true);
+        ui->decoy_regexp_groupbox->setVisible(false);
+        ui->decoy_database_groupbox->setVisible(true);
+    }
+
+    ui->contaminant_regexp_radiobutton->setChecked(true);
+    ui->contaminant_database_listview->setVisible(false);
+    if (_project_sp.get()->getProteinStore().getContaminantFastaFileList().size() > 0) {
+        ui->contaminant_file_radiobutton->setChecked(true);
+        ui->contaminant_protein_regexp_line_edit->setVisible(false);
+        ui->contaminant_database_listview->setVisible(true);
+    }
+
 
     qDebug() << "ProjectWindow::setProjectSp begin " << _project_sp.get()->getFastaFileStore().getFastaFileList().size() ;
     _fastafile_list = _project_sp.get()->getFastaFileStore().getFastaFileList();
@@ -800,3 +816,16 @@ void ProjectWindow::doSelectDecoySource() {
     }
     qDebug() << "ProjectWindow::doSelectDecoySource end";
 }
+
+void ProjectWindow::doSelectContaminantSource() {
+    qDebug() << "ProjectWindow::doSelectContaminantSource begin";
+    ui->contaminant_database_listview->setVisible(false);
+    ui->contaminant_protein_regexp_line_edit->setVisible(false);
+    if (ui->contaminant_file_radiobutton->isChecked()) {
+        ui->contaminant_database_listview->setVisible(true);
+    }
+    else {
+        ui->contaminant_protein_regexp_line_edit->setVisible(true);
+    }
+    qDebug() << "ProjectWindow::doSelectContaminantSource end";
+}
diff --git a/src/gui/project_view/projectwindow.h b/src/gui/project_view/projectwindow.h
index a0701fd86..ff2a4111e 100644
--- a/src/gui/project_view/projectwindow.h
+++ b/src/gui/project_view/projectwindow.h
@@ -70,6 +70,7 @@ public slots:
     void doAutomaticFilterParametersChanged(AutomaticFilterParameters parameters);
     void doFdrChanged();
     void doSelectDecoySource();
+    void doSelectContaminantSource();
     void doMassPrecisionUnitChanged(QString combo_value);
     void doOperationFailed(QString);
     void doOperationFinished();
-- 
GitLab