33 #include <QThreadPool>
34 #include "../../pappsoexception.h"
35 #include "../../msfile/msfileaccessor.h"
36 #include "../../msrun/private/timsmsrunreaderms2.h"
37 #include "../../processing/filters/filterpseudocentroid.h"
38 #include "../../processing/filters/filtertriangle.h"
39 #include "../../processing/filters/filterchargedeconvolution.h"
40 #include "../../msrun/output/mzxmloutput.h"
48 const QString &tmp_dir)
53 if(!tmp_dir.isEmpty())
65 QObject::tr(
"ERROR: unable to create temporary directory %1\n Please "
66 "check file system permissions")
94 settings.value(
"path/tandem_binary",
"/usr/bin/tandem").toString();
109 QFileInfo tandem_exe(tandem_bin_path);
110 if(!tandem_exe.exists())
115 "X!Tandem software not found at %1.\nPlease check the X!Tandem "
116 "installation on your computer and set tandem.exe path.")
117 .arg(tandem_exe.absoluteFilePath()));
119 if(!tandem_exe.isReadable())
123 QObject::tr(
"Please check permissions on X!Tandem software found at %1 "
124 "(file not readable).")
125 .arg(tandem_exe.absoluteFilePath()));
127 if(!tandem_exe.isExecutable())
131 QObject::tr(
"Please check permissions on X!Tandem software found at %1 "
132 "(file not executable).")
133 .arg(tandem_exe.absoluteFilePath()));
137 QString version_return;
138 QStringList arguments;
142 QProcess *xt_process =
new QProcess();
145 xt_process->start(tandem_bin_path, arguments);
147 if(!xt_process->waitForStarted())
150 QObject::tr(
"X!Tandem %1 process failed to start")
154 while(xt_process->waitForReadyRead(1000))
163 QByteArray result = xt_process->readAll();
166 qDebug() << result.constData();
170 QRegExp parse_version(
"(.*) TANDEM ([A-Z,a-z, ]+) \\(([^ ,^\\)]*)(.*)");
171 qDebug() << parse_version;
175 if(parse_version.exactMatch(result.constData()))
177 version_return = QString(
"X!Tandem %1 %2")
178 .arg(parse_version.capturedTexts()[2])
179 .arg(parse_version.capturedTexts()[3]);
184 QObject::tr(
"This executable %1 may not be a valid X!Tandem software. "
185 "Please check your X!Tandem installation.")
186 .arg(tandem_bin_path));
189 QProcess::ExitStatus Status = xt_process->exitStatus();
195 QObject::tr(
"error executing X!Tandem Status != 0 : %1 %2\n%3")
196 .arg(tandem_bin_path)
197 .arg(arguments.join(
" ").arg(result.data())));
200 return version_return;
227 const QString &tmp_tandem_output,
228 const QString &final_tandem_output,
229 const QString &original_msdata_file_name)
233 original_msdata_file_name);
238 QFile qfile(tmp_tandem_output);
239 QXmlInputSource xmlInputSource(&qfile);
240 QXmlSimpleReader simplereader;
241 simplereader.setContentHandler(&wrap_output);
242 simplereader.setErrorHandler(&wrap_output);
244 if(simplereader.parse(xmlInputSource))
250 QObject::tr(
"Error reading %1 X!Tandem output file :\n %2")
251 .arg(tmp_tandem_output)
263 QFile qfile(tandem_preset_file);
264 QXmlInputSource xmlInputSource(&qfile);
265 QXmlSimpleReader simplereader;
266 simplereader.setContentHandler(&preset_handler);
267 simplereader.setErrorHandler(&preset_handler);
269 if(simplereader.parse(xmlInputSource))
272 int ideal_number_of_thread = QThread::idealThreadCount();
274 qDebug() <<
" cpu_number=" << cpu_number;
276 if(cpu_number > ideal_number_of_thread)
278 cpu_number = ideal_number_of_thread;
284 QThreadPool::globalInstance()->setMaxThreadCount(cpu_number);
286 qDebug() <<
" maxThreadCount="
287 << QThreadPool::globalInstance()->maxThreadCount();
292 if(!ms2_filters_str.isEmpty())
295 std::make_shared<pappso::FilterSuiteString>(ms2_filters_str);
300 std::make_shared<pappso::FilterSuiteString>(
301 "chargeDeconvolution|0.02dalton mzExclusion|0.01dalton");
307 QObject::tr(
"Error reading %1 X!Tandem preset file :\n %2")
308 .arg(tandem_preset_file)
321 QString mzxml_data_file_name =
323 QString wrapped_tandem_input =
325 QString wrapped_tandem_output =
328 mzxml_data_file_name, wrapped_tandem_input, wrapped_tandem_output);
330 QFile qfile(tandem_input_file);
334 QObject::tr(
"Tandem input file %1 does not exists")
335 .arg(QFileInfo(tandem_input_file).absoluteFilePath()));
337 QXmlInputSource xmlInputSource(&qfile);
338 QXmlSimpleReader simplereader;
339 simplereader.setContentHandler(&wrap_input);
340 simplereader.setErrorHandler(&wrap_input);
342 if(simplereader.parse(xmlInputSource))
348 QObject::tr(
"Error reading %1 X!Tandem input file :\n %2")
349 .arg(tandem_input_file)
360 mzxml_data_file_name);
369 original_msdata_file_name);
374 const QString &target)
const
387 if(tims2_reader !=
nullptr)
401 QFile output_file(target);
404 if(output_file.open(QIODevice::WriteOnly))
413 p_mzxml_output->
write(p_reader.get());
415 p_mzxml_output->
close();
417 delete p_mzxml_output;
422 tr(
"unable to write into %1 mzXML output file").arg(target));
430 QTextStream &output_stream,
431 QTextStream &error_stream)
445 QStringList arguments;
449 arguments << tandem_input_file;
456 &QProcess::readyReadStandardOutput,
460 &QProcess::readyReadStandardError,
470 QObject::tr(
"X!Tandem process failed to start"));
484 QObject::tr(
"X!Tandem stopped by the user processing on file %1")
485 .arg(tandem_input_file));
489 QProcess::ExitStatus Status =
m_xtProcess->exitStatus();
496 QObject::tr(
"error executing X!Tandem Status != 0 : %1")
MsRunReaderSPtr msRunReaderSp(MsRunIdCstSPtr ms_run_id)
void setPreferedFileReaderType(MzFormat format, FileReaderType reader_type)
given an mz format, explicitly set the prefered reader
std::vector< MsRunIdCstSPtr > getMsRunIds()
void setReadAhead(bool read_ahead)
void write(MsRunReader *p_msrunreader)
void maskMs1(bool mask_ms1)
QTemporaryDir * mpa_temporaryDirectory
QTextStream * mp_errorStream
void setTandemBinaryPath(const QString &tandem_binary_path)
void readyReadStandardError()
void readyReadStandardOutput()
QTextStream * mp_outputStream
void run(const QString &tandem_input_file, QTextStream &output_stream, QTextStream &error_stream)
run a tandem job
void readTandemPresetFile(const QString &tandem_preset_file)
std::shared_ptr< FilterSuiteString > msp_ms2FilterSuiteString
void wrapTandemInputFile(const QString &tandem_input_file)
void convertOrginalMsData2mzXmlData(const QString &origin, const QString &target) const
void writeFinalTandemOutput(const QString &tmp_tandem_output, const QString &final_tandem_output, const QString &original_msdata_file_name)
tandem output modification tandem output is modified to contain the Bruker's file as input and centro...
TandemWrapperRun(const QString &tandem_binary, const QString &tmp_dir)
prepare a tandem run
QString getMs2FilterSuiteString() const
gets the list of filters used on MS2 spectrum
void runTandem(const QString &tandem_input_file)
run a tandem job
const QString checkXtandemVersion(const QString &tandem_bin_path)
void setMs2FilterCstSPtr(pappso::FilterInterfaceCstSPtr filter)
void setMs2BuiltinCentroid(bool centroid)
enable or disable simple centroid filter on raw tims data for MS2
void setInputParameters(const QString &label_name_attribute, const QString &input_value)
QString errorString() const
QString errorString() const
int getNumberOfThreads() const
const QString getMs2FiltersOptions() const
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
std::shared_ptr< MsRunReader > MsRunReaderSPtr
actually does really run tandem directly on Bruker's data
rewrites tandem xml output file with temporary files
read tandem preset file to get centroid parameters and number of threads