From 83e75fdc835bbabc32e468170a60130abd5000e2 Mon Sep 17 00:00:00 2001
From: Olivier Langella <olivier.langella@u-psud.fr>
Date: Mon, 10 Jun 2019 07:49:43 +0200
Subject: [PATCH] WIP: finding best msrun for alignment reference

---
 src/core/project.cpp                          | 78 +++++++++++++++----
 src/core/project.h                            |  6 +-
 .../exportmasschroqdialog.cpp                 | 39 +++-------
 3 files changed, 80 insertions(+), 43 deletions(-)

diff --git a/src/core/project.cpp b/src/core/project.cpp
index effd7a3af..534f40989 100644
--- a/src/core/project.cpp
+++ b/src/core/project.cpp
@@ -27,6 +27,7 @@
 #include "peptidematch.h"
 #include "proteinmatch.h"
 #include <QDebug>
+#include <pappsomspp/exception/exceptionnotfound.h>
 
 Project::Project()
 {
@@ -54,7 +55,7 @@ Project::readResultFile(QString filename)
     _identification_data_source_store.getInstance(filename);
 
   ident_source.get()->parseTo(this);
-  qDebug() << "Project::readResultFile end";
+  qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__;
 }
 
 const ProjectMode
@@ -143,14 +144,13 @@ Project::updateAutomaticFilters(
   const AutomaticFilterParameters &automatic_filter_parameters)
 {
 
-  qDebug() << "Project::updateAutomaticFilters begin";
+  qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__;
   _automatic_filter_parameters = automatic_filter_parameters;
   for(auto &p_id_group : _identification_goup_list)
     {
       p_id_group->updateAutomaticFilters(_automatic_filter_parameters);
     }
-
-  qDebug() << "Project::updateAutomaticFilters end";
+  qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__;
 }
 ProjectSp
 Project::makeProjectSp() const
@@ -168,16 +168,16 @@ Project::newIdentificationGroup()
 void
 Project::readXpipFile(WorkMonitorInterface *p_monitor, QFileInfo xpip_fileinfo)
 {
-  qDebug() << "Project::readXpipFile begin";
+  qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__;
 
   XpipSaxHandler *parser_java_xpip = new XpipSaxHandler(p_monitor, this);
 
   QXmlSimpleReader simplereader;
   simplereader.setContentHandler(parser_java_xpip);
   simplereader.setErrorHandler(parser_java_xpip);
-
-  qDebug() << "Project::readXpipFile Read XPIP XML result file '"
-           << xpip_fileinfo.absoluteFilePath() << "'";
+  qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__
+           << " Read XPIP XML result file '" << xpip_fileinfo.absoluteFilePath()
+           << "'";
 
   QFile qfile(xpip_fileinfo.absoluteFilePath());
   QXmlInputSource xmlInputSource(&qfile);
@@ -189,7 +189,8 @@ Project::readXpipFile(WorkMonitorInterface *p_monitor, QFileInfo xpip_fileinfo)
     }
   else
     {
-      qDebug() << parser_java_xpip->errorString();
+      qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__
+               << parser_java_xpip->errorString();
       // throw PappsoException(
       //    QObject::tr("error reading tandem XML result file :\n").append(
       //         parser->errorString()));
@@ -213,7 +214,8 @@ Project::readXpipFile(WorkMonitorInterface *p_monitor, QFileInfo xpip_fileinfo)
           simplereaderb.setContentHandler(parser_xtp_xpip);
           simplereaderb.setErrorHandler(parser_xtp_xpip);
 
-          qDebug() << "Project::readXpipFile Read XPIP XML result file '"
+          qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__
+                   << " Read XPIP XML result file '"
                    << xpip_fileinfo.absoluteFilePath() << "'";
 
           QFile qfileb(xpip_fileinfo.absoluteFilePath());
@@ -235,7 +237,8 @@ Project::readXpipFile(WorkMonitorInterface *p_monitor, QFileInfo xpip_fileinfo)
                 }
               else
                 {
-                  qDebug() << parser_xtp_xpip->errorString();
+                  qDebug() << __FILE__ << " " << __FUNCTION__ << " "
+                           << __LINE__;
                   throw pappso::PappsoException(
                     QObject::tr(
                       "Error reading %1 XPIP file :\n it is not an XPIP file")
@@ -281,11 +284,58 @@ Project::hasPtmExperiment() const
 void
 Project::getSameXicPeptideEvidenceList(
   std::vector<const PeptideEvidence *> &peptide_evidence_list,
-  const MsRun *p_msrun, const PeptideXtp *p_peptide, unsigned int charge) const
+  const MsRun *p_msrun,
+  const PeptideXtp *p_peptide,
+  unsigned int charge) const
 {
   for(const IdentificationGroup *p_ident_group : _identification_goup_list)
     {
-      p_ident_group->getSameXicPeptideEvidenceList(peptide_evidence_list,
-                                                   p_msrun, p_peptide, charge);
+      p_ident_group->getSameXicPeptideEvidenceList(
+        peptide_evidence_list, p_msrun, p_peptide, charge);
+    }
+}
+
+void
+Project::prepareMsrunRetentionTimesForAlignment() const
+{
+  qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__;
+  bool is_ok = true;
+  for(IdentificationDataSourceSp p_ident_data_source :
+      this->getIdentificationDataSourceStore()
+        .getIdentificationDataSourceList())
+    {
+      MsRunSp msrun_sp = p_ident_data_source->getMsRunSp();
+
+      if(msrun_sp->findMsRunFile())
+        {
+          // msrun_sp->checkMsRunStatistics();
+          msrun_sp->buildMsRunRetentionTime(
+            p_ident_data_source->getPeptideEvidenceStore());
+        }
+      else
+        {
+          is_ok = false;
+
+          throw pappso::ExceptionNotFound(
+            QObject::tr("MS run file %1 not found.")
+              .arg(msrun_sp.get()->getFileName()));
+          break;
+        }
+    }
+  if(is_ok)
+    {
+      for(auto &msrun_sp : this->getMsRunStore().getMsRunList())
+        {
+          msrun_sp->computeMsRunRetentionTime();
+        }
+      // find the best reference
+    }
+  else
+    {
+      for(auto &msrun_sp : this->getMsRunStore().getMsRunList())
+        {
+          msrun_sp->clearMsRunRetentionTime();
+        }
     }
+  qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__;
 }
diff --git a/src/core/project.h b/src/core/project.h
index e79d02b91..5f0120f21 100644
--- a/src/core/project.h
+++ b/src/core/project.h
@@ -97,9 +97,13 @@ class Project
    */
   void getSameXicPeptideEvidenceList(
     std::vector<const PeptideEvidence *> &peptide_evidence_list,
-    const MsRun *p_msrun, const PeptideXtp *p_peptide,
+    const MsRun *p_msrun,
+    const PeptideXtp *p_peptide,
     unsigned int charge) const;
 
+
+  void prepareMsrunRetentionTimesForAlignment() const;
+
   private:
   LabelingMethodSp _labeling_method_sp;
   ProjectMode _project_mode = ProjectMode::combined;
diff --git a/src/gui/export/export_masschroq_dialog/exportmasschroqdialog.cpp b/src/gui/export/export_masschroq_dialog/exportmasschroqdialog.cpp
index 6d615df0b..dd20c7972 100644
--- a/src/gui/export/export_masschroq_dialog/exportmasschroqdialog.cpp
+++ b/src/gui/export/export_masschroq_dialog/exportmasschroqdialog.cpp
@@ -38,6 +38,7 @@
 #include <QFileDialog>
 #include <pappsomspp/msrun/alignment/msrunretentiontime.h>
 #include <pappsomspp/msfile/msfileaccessor.h>
+#include <pappsomspp/pappsoexception.h>
 
 ExportMasschroqDialog::ExportMasschroqDialog(QWidget *parent)
   : QDialog(parent), ui(new Ui::ExportMasschroqDialog)
@@ -268,27 +269,11 @@ ExportMasschroqDialog::doBrowseMsrunDirectory()
 void
 ExportMasschroqDialog::doFindBestMsrunForAlignment()
 {
-  IdentificationGroup *p_identification_group = nullptr;
-  if(mp_project->getIdentificationGroupList().size() != 1)
-    {
-    }
-  else
-    {
-      // p_identification_group =
-      // mp_project->getIdentificationGroupList()[0]->get
-    }
   bool is_ok = true;
-  for(IdentificationDataSourceSp p_ident_data_source :
-      mp_project->getIdentificationDataSourceStore()
-        .getIdentificationDataSourceList())
+  for(auto &msrun_sp : mp_project->getMsRunStore().getMsRunList())
     {
-      MsRunSp msrun_sp = p_ident_data_source->getMsRunSp();
-
       if(msrun_sp->findMsRunFile())
         {
-          // msrun_sp->checkMsRunStatistics();
-          msrun_sp->buildMsRunRetentionTime(
-            p_ident_data_source->getPeptideEvidenceStore());
         }
       else
         {
@@ -301,19 +286,17 @@ ExportMasschroqDialog::doFindBestMsrunForAlignment()
           break;
         }
     }
-  if(is_ok)
+  try
     {
-      for(auto &msrun_sp : mp_project->getMsRunStore().getMsRunList())
-        {
-          msrun_sp->computeMsRunRetentionTime();
-        }
-        //find the best reference
+      mp_project->prepareMsrunRetentionTimesForAlignment();
     }
-  else
+  catch(pappso::PappsoException &error)
     {
-      for(auto &msrun_sp : mp_project->getMsRunStore().getMsRunList())
-        {
-          msrun_sp->clearMsRunRetentionTime();
-        }
+      QMessageBox msgBox;
+      msgBox.setWindowTitle("Error");
+      msgBox.setText(
+        tr("Error preparing MS run retention times: %1").arg(error.qwhat()));
+      msgBox.setIcon(QMessageBox::Critical);
+      msgBox.exec();
     }
 }
-- 
GitLab