From 296771b458f2c9c8d300d8497a8934b6a704f805 Mon Sep 17 00:00:00 2001
From: Olivier Langella <Olivier.Langella@moulon.inra.fr>
Date: Thu, 7 Sep 2017 21:29:41 +0200
Subject: [PATCH] new condor process class

---
 src/CMakeLists.txt                         |  1 +
 src/core/tandem_run/tandecondorprocess.cpp | 85 ++++++++++++++++++++++
 src/core/tandem_run/tandecondorprocess.h   | 44 +++++++++++
 src/core/tandem_run/tandembatchprocess.cpp | 51 +++++++------
 src/core/tandem_run/tandembatchprocess.h   | 17 +++--
 5 files changed, 167 insertions(+), 31 deletions(-)
 create mode 100644 src/core/tandem_run/tandecondorprocess.cpp
 create mode 100644 src/core/tandem_run/tandecondorprocess.h

diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 3f2859b8..e2e6453e 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -58,6 +58,7 @@ SET(CPP_FILES
   core/labeling/label.cpp
   core/labeling/labelingmethod.cpp
   core/tandem_run/tandembatchprocess.cpp
+  core/tandem_run/tandemcondorprocess.cpp
   core/msrun.cpp
   core/peptidematch.cpp
   core/peptidextp.cpp
diff --git a/src/core/tandem_run/tandecondorprocess.cpp b/src/core/tandem_run/tandecondorprocess.cpp
new file mode 100644
index 00000000..2354a061
--- /dev/null
+++ b/src/core/tandem_run/tandecondorprocess.cpp
@@ -0,0 +1,85 @@
+/**
+ * \file /core/tandem_run/tandemcondorprocess.cpp
+ * \date 5/9/2017
+ * \author Olivier Langella
+ * \brief handles execution of a bunch of X!Tandem process throught condor job
+ */
+
+/*******************************************************************************
+* Copyright (c) 2017 Olivier Langella <olivier.langella@u-psud.fr>.
+*
+* This file is part of XTPcpp.
+*
+*     XTPcpp is free software: you can redistribute it and/or modify
+*     it under the terms of the GNU General Public License as published by
+*     the Free Software Foundation, either version 3 of the License, or
+*     (at your option) any later version.
+*
+*     XTPcpp is distributed in the hope that it will be useful,
+*     but WITHOUT ANY WARRANTY; without even the implied warranty of
+*     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+*     GNU General Public License for more details.
+*
+*     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
+******************************************************************************/
+
+#include "tandecondorprocess.h"
+
+TandeCondorProcess(WorkMonitorInterface * p_monitor, const TandemRunBatch & tandem_run_batch) : TandemBatchProcess(p_monitor, tandem_run_batch) {
+    /*
+    Universe   = vanilla
+    notification   = Error
+    Rank       = Mips
+    request_memory= 50000
+    request_cpus = 1
+    Executable = /usr/bin/tandem
+    Log        = /gorgone/pappso/tmp/temp_condor_job93294001891239208719639434471283743/submit_condor.log
+    Output        = /gorgone/pappso/tmp/temp_condor_job93294001891239208719639434471283743/tandem.$(Process).out
+    Error        = /gorgone/pappso/tmp/temp_condor_job93294001891239208719639434471283743/tandem.$(Process).error
+
+    Arguments = /gorgone/pappso/tmp/temp_condor_job93294001891239208719639434471283743/xtandem_param2054956555872858570.xml
+    Queue
+    */
+}
+
+void TandeCondorProcess::run() {
+    qDebug() << "TandeCondorProcess::run begin " << _tandem_run_batch._preset_file;
+    _preset_file = _tandem_run_batch._preset_file;
+
+    prepareXmlDatabaseFile();
+
+    std::vector<QTemporaryFile *> input_file_list;
+
+    int i=0;
+    _p_monitor->setProgressMaximumValue(_tandem_run_batch._mz_file_list.size());
+    for (QString mz_file : _tandem_run_batch._mz_file_list) {
+
+
+        QTemporaryFile *  p_xml_input_file = new QTemporaryFile();
+
+        input_file_list.push_back(p_xml_input_file);
+        p_xml_input_file->setAutoRemove(false);
+        if (p_xml_input_file->open())
+        {
+            QXmlStreamWriter * p_out = new QXmlStreamWriter();
+            p_out->setDevice(p_xml_input_file);
+
+            writeXmlInputFile(p_out, mz_file);
+
+            p_xml_input_file->close();
+            delete p_out;
+        } else
+        {
+            throw pappso::PappsoException(QObject::tr("error : cannot open the XML X!Tandem input file : %1\n").arg(p_xml_input_file->fileName()));
+        }
+        i++;
+    }
+    for (QTemporaryFile *  p_xml_input_file: input_file_list) {
+        delete p_xml_input_file;
+    }
+    qDebug() << "TandeCondorProcess::run end" ;
+}
diff --git a/src/core/tandem_run/tandecondorprocess.h b/src/core/tandem_run/tandecondorprocess.h
new file mode 100644
index 00000000..57e85f6a
--- /dev/null
+++ b/src/core/tandem_run/tandecondorprocess.h
@@ -0,0 +1,44 @@
+/**
+ * \file /core/tandem_run/tandemcondorprocess.h
+ * \date 5/9/2017
+ * \author Olivier Langella
+ * \brief handles execution of a bunch of X!Tandem process throught condor job
+ */
+
+/*******************************************************************************
+* Copyright (c) 2017 Olivier Langella <olivier.langella@u-psud.fr>.
+*
+* This file is part of XTPcpp.
+*
+*     XTPcpp is free software: you can redistribute it and/or modify
+*     it under the terms of the GNU General Public License as published by
+*     the Free Software Foundation, either version 3 of the License, or
+*     (at your option) any later version.
+*
+*     XTPcpp is distributed in the hope that it will be useful,
+*     but WITHOUT ANY WARRANTY; without even the implied warranty of
+*     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+*     GNU General Public License for more details.
+*
+*     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 TANDECONDORPROCESS_H
+#define TANDECONDORPROCESS_H
+
+#include "tandembatchprocess.h"
+
+class TandeCondorProcess: public TandemBatchProcess
+{
+public:
+    TandeCondorProcess(WorkMonitorInterface * p_monitor, const TandemRunBatch & tandem_run_batch);
+
+    virtual void run();
+
+};
+
+#endif // TANDECONDORPROCESS_H
diff --git a/src/core/tandem_run/tandembatchprocess.cpp b/src/core/tandem_run/tandembatchprocess.cpp
index b8532fce..b6ecc7ed 100644
--- a/src/core/tandem_run/tandembatchprocess.cpp
+++ b/src/core/tandem_run/tandembatchprocess.cpp
@@ -38,6 +38,32 @@ TandemBatchProcess::TandemBatchProcess(WorkMonitorInterface * p_monitor, const T
     _p_monitor = p_monitor;
 }
 
+void TandemBatchProcess::writeXmlDatabaseFile (QXmlStreamWriter * p_out) {
+    p_out->setAutoFormatting(true);
+    p_out->writeStartDocument("1.0");
+
+    //<?xml version="1.0" encoding="UTF-8"?>
+    //<bioml label="x! taxon-to-file matching list">
+    p_out->writeStartElement("bioml");
+    p_out->writeAttribute("label","x! taxon-to-file matching list");
+    //<taxon label="usedefined">
+    p_out->writeStartElement("taxon");
+    p_out->writeAttribute("label","usedefined");
+    //<file format="peptide" URL="/gorgone/pappso/jouy/users/Didier/fasta/20170608_Delastours/contaminants_standards.fasta"></file>
+    //<file format="peptide" URL="/gorgone/pappso/jouy/users/Didier/fasta/20170608_Delastours/Escherichia coli 27J42_WGS_ECOLI_1.fasta"></file>
+    for (QString fasta_file:_tandem_run_batch._fasta_file_list) {
+        p_out->writeStartElement("file");
+        p_out->writeAttribute("format","peptide");
+        p_out->writeAttribute("URL",fasta_file);
+        p_out->writeEndElement();
+    }
+    //</taxon>
+    p_out->writeEndElement();
+    //</bioml>
+    p_out->writeEndElement();
+    p_out->writeEndDocument();
+}
+
 void TandemBatchProcess::prepareXmlDatabaseFile() {
     _xml_database_file.setAutoRemove(false);
 
@@ -45,30 +71,7 @@ void TandemBatchProcess::prepareXmlDatabaseFile() {
     {
         QXmlStreamWriter * p_out = new QXmlStreamWriter();
         p_out->setDevice(&_xml_database_file);
-
-        p_out->setAutoFormatting(true);
-        p_out->writeStartDocument("1.0");
-
-        //<?xml version="1.0" encoding="UTF-8"?>
-        //<bioml label="x! taxon-to-file matching list">
-        p_out->writeStartElement("bioml");
-        p_out->writeAttribute("label","x! taxon-to-file matching list");
-        //<taxon label="usedefined">
-        p_out->writeStartElement("taxon");
-        p_out->writeAttribute("label","usedefined");
-        //<file format="peptide" URL="/gorgone/pappso/jouy/users/Didier/fasta/20170608_Delastours/contaminants_standards.fasta"></file>
-        //<file format="peptide" URL="/gorgone/pappso/jouy/users/Didier/fasta/20170608_Delastours/Escherichia coli 27J42_WGS_ECOLI_1.fasta"></file>
-        for (QString fasta_file:_tandem_run_batch._fasta_file_list) {
-            p_out->writeStartElement("file");
-            p_out->writeAttribute("format","peptide");
-            p_out->writeAttribute("URL",fasta_file);
-            p_out->writeEndElement();
-        }
-        //</taxon>
-        p_out->writeEndElement();
-        //</bioml>
-        p_out->writeEndElement();
-        p_out->writeEndDocument();
+        writeXmlDatabaseFile(p_out);
         _xml_database_file.close();
         delete p_out;
     } else
diff --git a/src/core/tandem_run/tandembatchprocess.h b/src/core/tandem_run/tandembatchprocess.h
index cdc6397e..cda9bdc9 100644
--- a/src/core/tandem_run/tandembatchprocess.h
+++ b/src/core/tandem_run/tandembatchprocess.h
@@ -39,19 +39,22 @@ class TandemBatchProcess
 public:
     TandemBatchProcess(WorkMonitorInterface * p_monitor, const TandemRunBatch & tandem_run_batch);
 
-    void run();
+    virtual void run();
+protected:
+    void writeXmlDatabaseFile (QXmlStreamWriter * p_out);
+    void writeXmlInputFile (QXmlStreamWriter * p_out, const QString & mz_file);
+    void prepareXmlDatabaseFile();
 private:
     void runOne(const QString & mz_file);
-    void prepareXmlDatabaseFile();
-    void writeXmlInputFile (QXmlStreamWriter * p_out, const QString & mz_file);
 
-private:
+protected:
+    QString _preset_file;
     TandemRunBatch _tandem_run_batch;
     WorkMonitorInterface * _p_monitor;
-    QString _preset_file;
-    int _max_xt_time_ms = (60000 * 60 * 24); //1 day
-    
     QTemporaryFile _xml_database_file;
+    
+private:
+    int _max_xt_time_ms = (60000 * 60 * 24); //1 day
 };
 
 #endif // TANDEMBATCHPROCESS_H
-- 
GitLab