Newer
Older
/**
* \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 "tandemcondorprocess.h"
#include <QDebug>
#include <pappsomspp/pappsoexception.h>
#include <QSettings>
#include <QProcess>
TandemCondorProcess::TandemCondorProcess(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
*/
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
QSettings settings;
QString condor_tmp_dir = QString("%1/xtpcpp").arg(settings.value("condor/tmp_dir", "/gorgone/pappso/temp").toString());
_p_tmp_dir = new QTemporaryDir(condor_tmp_dir);
_condor_submit_command = settings.value("condor/submit", "/usr/bin/condor_submit").toString();
if (!_p_tmp_dir->isValid()) {
// dir.path() returns the unique directory path
throw pappso::PappsoException(QObject::tr("problem creating condor temporary directory in %1\n").arg(condor_tmp_dir));
}
}
TandemCondorProcess::~TandemCondorProcess () {
delete _p_tmp_dir;
}
void TandemCondorProcess::prepareXmlDatabaseFile() {
QFile xml_database_file(QString("%1/database.xml").arg(_p_tmp_dir->path()));
if (xml_database_file.open(QIODevice::WriteOnly))
{
_xml_database_file = QFileInfo( xml_database_file.fileName()).absoluteFilePath();
QXmlStreamWriter * p_out = new QXmlStreamWriter();
p_out->setDevice(&xml_database_file);
writeXmlDatabaseFile(p_out);
xml_database_file.close();
delete p_out;
} else
{
throw pappso::PappsoException(QObject::tr("error : cannot open the XML database file : %1\n").arg(xml_database_file.fileName()));
}
qDebug() << "TandeCondorProcess::run begin ";
QFileInfo preset_info(_tandem_run_batch._preset_file);
_preset_file = QString("%1/%2").arg(_p_tmp_dir->path()).arg(preset_info.fileName());
QFile::copy(_tandem_run_batch._preset_file, _preset_file);
_preset_file = _tandem_run_batch._preset_file;
prepareXmlDatabaseFile();
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
//condor submit file :
QFile submit_file(QString("%1/submit.txt").arg(_p_tmp_dir->path()));
QTextStream * p_out = nullptr;
if (submit_file.open(QIODevice::WriteOnly))
{
p_out = new QTextStream();
p_out->setDevice(&submit_file);
*p_out << "Universe = vanilla" << endl;
*p_out << "notification = Error" << endl;
*p_out << "Rank = Mips" << endl;
*p_out << "request_memory= 50000" << endl;
*p_out << "request_cpus = 1" << endl;
*p_out << "Executable = " << _tandem_run_batch._tandem_bin_path << endl;
*p_out << "Log = \"" << _p_tmp_dir->path() << "/condor.log\"" << endl;
*p_out << "Output = \"" << _p_tmp_dir->path() << "/tandem.$(Process).out\"" << endl;
*p_out << "Error = \"" << _p_tmp_dir->path() << "/tandem.$(Process).error\"" << endl;
/*
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
*/
} else
{
throw pappso::PappsoException(QObject::tr("error : cannot open condor submit file : %1\n").arg(submit_file.fileName()));
}
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(_p_tmp_dir->path());
input_file_list.push_back(p_xml_input_file);
p_xml_input_file->setAutoRemove(false);
if (p_xml_input_file->open())
{
QXmlStreamWriter * p_xml_out = new QXmlStreamWriter();
p_xml_out->setDevice(p_xml_input_file);
delete p_xml_out;
*p_out << "Arguments = \"" << QFileInfo( p_xml_input_file->fileName()).absolutePath() << "\"" << endl;
*p_out << "Queue" << endl;
} 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;
}
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
if (p_out != nullptr) {
submit_file.close();
delete p_out;
}
//now run condor job on submit_file
QStringList arguments;
arguments << QFileInfo( submit_file.fileName()).absoluteFilePath();
QProcess * condor_process = new QProcess();
//hk_process->setWorkingDirectory(QFileInfo(_hardklor_exe).absolutePath());
condor_process->start(_condor_submit_command, arguments);
if (!condor_process->waitForStarted()) {
throw pappso::PappsoException(QObject::tr("HTCondor X!Tandem process failed to start"));
}
while(condor_process->waitForReadyRead(_max_xt_time_ms)) {
_p_monitor->appendText( condor_process->readAll().data());
//data.append(xt_process->readAll());
}
/*
if (!xt_process->waitForFinished(_max_xt_time_ms)) {
throw pappso::PappsoException(QObject::tr("can't wait for X!Tandem process to finish : timeout at %1").arg(_max_xt_time_ms));
}
*/
QByteArray result = condor_process->readAll();
QProcess::ExitStatus Status = condor_process->exitStatus();
if (Status != 0)
{
// != QProcess::NormalExit
throw pappso::PappsoException(QObject::tr("error executing HTCondor Status != 0 : %1 %2\n%3").arg(_tandem_run_batch._tandem_bin_path).arg(arguments.join(" ").arg(result.data())));
}
delete condor_process;
qDebug() << "TandeCondorProcess::run end" ;
}