From fd70b054cca8189f469223d8fbd13bb041375435 Mon Sep 17 00:00:00 2001
From: Olivier Langella <olivier.langella@u-psud.fr>
Date: Fri, 29 Sep 2017 21:43:14 +0200
Subject: [PATCH] error if fasta file is not found

---
 src/core/proteinmatch.cpp              |   6 +-
 src/files/fastafile.cpp                |   5 ++
 src/gui/project_view/projectwindow.cpp | 104 +++++++++++++++----------
 3 files changed, 73 insertions(+), 42 deletions(-)

diff --git a/src/core/proteinmatch.cpp b/src/core/proteinmatch.cpp
index 6866522fe..4400d062c 100644
--- a/src/core/proteinmatch.cpp
+++ b/src/core/proteinmatch.cpp
@@ -64,7 +64,7 @@ bool ProteinMatch::contains(PeptideMatch * peptide_match) const {
 }
 
 void ProteinMatch::updateAutomaticFilters(const AutomaticFilterParameters & automatic_filter_parameters) {
-    qDebug() <<"ProteinMatch::updateAutomaticFilters begin " ;
+    //qDebug() <<"ProteinMatch::updateAutomaticFilters begin " ;
     _proxy_valid = false;
     unsigned int number_of_valid_peptides =0;
     bool cross_sample = automatic_filter_parameters.getFilterCrossSamplePeptideNumber();
@@ -91,7 +91,7 @@ void ProteinMatch::updateAutomaticFilters(const AutomaticFilterParameters & auto
         }
     }
 
-    qDebug() <<"ProteinMatch::updateAutomaticFilters begin 2" ;
+    // qDebug() <<"ProteinMatch::updateAutomaticFilters begin 2" ;
     if (number_of_valid_peptides == 0) {
 
         _proxy_valid = false;
@@ -105,7 +105,7 @@ void ProteinMatch::updateAutomaticFilters(const AutomaticFilterParameters & auto
             }
         }
     }
-    qDebug() <<"ProteinMatch::updateAutomaticFilters end " << number_of_valid_peptides ;
+    // qDebug() <<"ProteinMatch::updateAutomaticFilters end " << number_of_valid_peptides ;
 }
 
 const ProteinXtpSp & ProteinMatch::getProteinXtpSp() const {
diff --git a/src/files/fastafile.cpp b/src/files/fastafile.cpp
index cc1bf229e..f4eb6876d 100644
--- a/src/files/fastafile.cpp
+++ b/src/files/fastafile.cpp
@@ -25,6 +25,7 @@
 #include <pappsomspp/fasta/fastareader.h>
 #include <QStringList>
 #include <QDebug>
+#include <pappsomspp/exception/exceptionnotfound.h>
 
 class AccessionContaminantReader: public pappso::FastaHandlerInterface {
 public:
@@ -94,10 +95,12 @@ void FastaFile::setContaminants(ProteinStore & protein_store) const {
         }
         else {
             qDebug() << "FastaFile::setContaminants "<< _fasta_source.absoluteFilePath() << " not open";
+            throw pappso::ExceptionNotFound(QObject::tr("unable to open contaminant fasta file \"%1\"").arg(_fasta_source.absoluteFilePath()));
         }
     }
     else {
         qDebug() << "FastaFile::setContaminants "<< _fasta_source.absoluteFilePath() << " does not exists";
+        throw pappso::ExceptionNotFound(QObject::tr("contaminant fasta file \"%1\" not found").arg(_fasta_source.absoluteFilePath()));
     }
 }
 
@@ -113,9 +116,11 @@ void FastaFile::setDecoys(ProteinStore & protein_store) const {
         }
         else {
             qDebug() << "FastaFile::setDecoys "<< _fasta_source.absoluteFilePath() << " not open";
+            throw pappso::ExceptionNotFound(QObject::tr("unable to open decoy fasta file \"%1\"").arg(_fasta_source.absoluteFilePath()));
         }
     }
     else {
         qDebug() << "FastaFile::setDecoys "<< _fasta_source.absoluteFilePath() << " does not exists";
+        throw pappso::ExceptionNotFound(QObject::tr("decoy fasta file \"%1\" not found").arg(_fasta_source.absoluteFilePath()));
     }
 }
diff --git a/src/gui/project_view/projectwindow.cpp b/src/gui/project_view/projectwindow.cpp
index 10723c89f..75f0e264c 100644
--- a/src/gui/project_view/projectwindow.cpp
+++ b/src/gui/project_view/projectwindow.cpp
@@ -282,29 +282,42 @@ void ProjectWindow::computeMassPrecision() {
 
 void ProjectWindow::doFdrChanged() {
     qDebug() << "ProjectWindow::doFdrChanged begin ";
-    showWaitingMessage(tr("FDR modifications"));
-    doDisplayLoadingMessage(tr("tagging decoy proteins"));
-    QModelIndexList index_list = ui->decoy_database_listview->selectionModel()->selectedIndexes();
-    if (index_list.size() > 0) {
-        _project_sp.get()->getProteinStore().clearDecoys();
-        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->setDecoys(_project_sp.get()->getProteinStore());
-            }
-            else {
-                throw pappso::PappsoException(QObject::tr("can not convert to FastaFile index.data().canConvert<FastaFile *>()"));
+    try {
+        showWaitingMessage(tr("FDR modifications"));
+        doDisplayLoadingMessage(tr("tagging decoy proteins"));
+        QModelIndexList index_list = ui->decoy_database_listview->selectionModel()->selectedIndexes();
+        if (index_list.size() > 0) {
+            qDebug() << "ProjectWindow::doFdrChanged index_list.size()=" << index_list.size();
+            _project_sp.get()->getProteinStore().clearDecoys();
+            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->setDecoys(_project_sp.get()->getProteinStore());
+                }
+                else {
+                    throw pappso::PappsoException(QObject::tr("can not convert to FastaFile index.data().canConvert<FastaFile *>()"));
+                }
             }
         }
+        else {
+            _project_sp.get()->getProteinStore().setRegexpDecoyPattern(ui->decoy_protein_regexp_line_edit->text());
+        }
+        doDisplayLoadingMessage(tr("updating filters"));
+        _project_sp.get()->updateAutomaticFilters(_project_sp.get()->getAutomaticFilterParameters());
+
+        //re group
+        emit operateGrouping(_project_sp);
     }
-    else {
-        _project_sp.get()->getProteinStore().setRegexpDecoyPattern(ui->decoy_protein_regexp_line_edit->text());
+    catch (pappso::PappsoException exception_pappso) {
+        hideWaitingMessage();
+        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());
     }
-    doDisplayLoadingMessage(tr("updating filters"));
-    _project_sp.get()->updateAutomaticFilters(_project_sp.get()->getAutomaticFilterParameters());
-
-    //re group
-    emit operateGrouping(_project_sp);
 
     qDebug() << "ProjectWindow::doFdrChanged end ";
 }
@@ -317,30 +330,42 @@ void ProjectWindow::refresh() {
 }
 void ProjectWindow::doAutomaticFilterParametersChanged(AutomaticFilterParameters parameters) {
     qDebug() << "ProjectWindow::doAutomaticFilterParametersChanged begin ";
-    showWaitingMessage(tr("Updating filters"));
-
-    doDisplayLoadingMessage(tr("tagging contaminant proteins"));
-    QModelIndexList index_list = ui->contaminant_database_listview->selectionModel()->selectedIndexes();
-    if (index_list.size() > 0) {
-        _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 *>()"));
+    try {
+        showWaitingMessage(tr("Updating filters"));
+
+        doDisplayLoadingMessage(tr("tagging contaminant proteins"));
+        QModelIndexList index_list = ui->contaminant_database_listview->selectionModel()->selectedIndexes();
+        if (index_list.size() > 0) {
+            _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 *>()"));
+                }
             }
         }
+        else {
+            _project_sp.get()->getProteinStore().setRegexpContaminantPattern(ui->contaminant_protein_regexp_line_edit->text());
+        }
+        doDisplayLoadingMessage(tr("updating filters"));
+        _project_sp.get()->updateAutomaticFilters(parameters);
+
+        qDebug() << "ProjectWindow::doAutomaticFilterParametersChanged emit operateGrouping(_project_sp) ";
+        emit operateGrouping(_project_sp);
     }
-    else {
-        _project_sp.get()->getProteinStore().setRegexpContaminantPattern(ui->contaminant_protein_regexp_line_edit->text());
+    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());
     }
-    doDisplayLoadingMessage(tr("updating filters"));
-    _project_sp.get()->updateAutomaticFilters(parameters);
-
-    qDebug() << "ProjectWindow::doAutomaticFilterParametersChanged emit operateGrouping(_project_sp) ";
-    emit operateGrouping(_project_sp);
     qDebug() << "ProjectWindow::doAutomaticFilterParametersChanged end ";
 }
 
@@ -653,3 +678,4 @@ void ProjectWindow::doAcceptedLabelingMethod() {
     emit operateGrouping(_project_sp);
 
 }
+
-- 
GitLab