libpappsomspp
Library for mass spectrometry
pappso::TandemWrapperRun Class Reference

#include <tandemwrapperrun.h>

Inheritance diagram for pappso::TandemWrapperRun:

Public Member Functions

 TandemWrapperRun (const QString &tandem_binary, const QString &tmp_dir)
 prepare a tandem run More...
 
void run (const QString &tandem_input_file, QTextStream &output_stream, QTextStream &error_stream)
 run a tandem job More...
 
void readTandemPresetFile (const QString &tandem_preset_file)
 
QString getMs2FilterSuiteString () const
 gets the list of filters used on MS2 spectrum More...
 
 ~TandemWrapperRun ()
 

Private Slots

void readyReadStandardOutput ()
 
void readyReadStandardError ()
 

Private Member Functions

void setTandemBinaryPath (const QString &tandem_binary_path)
 
bool shouldIstop ()
 
const QString checkXtandemVersion (const QString &tandem_bin_path)
 
void wrapTandemInputFile (const QString &tandem_input_file)
 
void convertOrginalMsData2mzXmlData (const QString &origin, const QString &target) const
 
void runTandem (const QString &tandem_input_file)
 run a tandem job More...
 
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 centroidization parameters More...
 

Private Attributes

QString m_tandemBinary
 
QString m_tandemVersion
 
QString m_tmpDir
 
int m_maxTandemRunTimeMs = (60000 * 60 * 24)
 
QProcess * m_xtProcess = nullptr
 
std::shared_ptr< FilterSuiteStringmsp_ms2FilterSuiteString = nullptr
 
QTextStream * mp_outputStream = nullptr
 
QTextStream * mp_errorStream = nullptr
 
QTemporaryDir * mpa_temporaryDirectory = nullptr
 

Detailed Description

Definition at line 43 of file tandemwrapperrun.h.

Constructor & Destructor Documentation

◆ TandemWrapperRun()

pappso::TandemWrapperRun::TandemWrapperRun ( const QString &  tandem_binary,
const QString &  tmp_dir 
)

prepare a tandem run

Parameters
tandem_binaryfile path to tandem.exe if not set, a default value is given in QSettings
tmp_dirtemporary directory, where to write mzXML file conversion if not set, a default value is given in QSettings

Definition at line 47 of file tandemwrapperrun.cpp.

49 {
50 
51  setTandemBinaryPath(tandem_binary);
52 
53  if(!tmp_dir.isEmpty())
54  {
55  mpa_temporaryDirectory = new QTemporaryDir(tmp_dir + "/xtpwrp");
56  }
57  else
58  {
59  mpa_temporaryDirectory = new QTemporaryDir(QDir::tempPath() + "/xtpwrp");
60  }
61  mpa_temporaryDirectory->setAutoRemove(true);
62  if(!mpa_temporaryDirectory->isValid())
63  {
65  QObject::tr("ERROR: unable to create temporary directory %1\n Please "
66  "check file system permissions")
67  .arg(mpa_temporaryDirectory->path()));
68  }
69 }
QTemporaryDir * mpa_temporaryDirectory
void setTandemBinaryPath(const QString &tandem_binary_path)

References mpa_temporaryDirectory, and setTandemBinaryPath().

◆ ~TandemWrapperRun()

pappso::TandemWrapperRun::~TandemWrapperRun ( )

Destructor

Definition at line 71 of file tandemwrapperrun.cpp.

72 {
73  if(mpa_temporaryDirectory != nullptr)
74  {
76  }
77 
78  if(m_xtProcess != nullptr)
79  {
80  m_xtProcess->deleteLater();
81  }
82 }

References m_xtProcess, and mpa_temporaryDirectory.

Member Function Documentation

◆ checkXtandemVersion()

const QString pappso::TandemWrapperRun::checkXtandemVersion ( const QString &  tandem_bin_path)
private

Definition at line 105 of file tandemwrapperrun.cpp.

106 {
107  qDebug();
108  // check tandem path
109  QFileInfo tandem_exe(tandem_bin_path);
110  if(!tandem_exe.exists())
111  {
112  // dir.path() returns the unique directory path
114  QObject::tr(
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()));
118  }
119  if(!tandem_exe.isReadable())
120  {
121  // dir.path() returns the unique directory path
123  QObject::tr("Please check permissions on X!Tandem software found at %1 "
124  "(file not readable).")
125  .arg(tandem_exe.absoluteFilePath()));
126  }
127  if(!tandem_exe.isExecutable())
128  {
129  // dir.path() returns the unique directory path
131  QObject::tr("Please check permissions on X!Tandem software found at %1 "
132  "(file not executable).")
133  .arg(tandem_exe.absoluteFilePath()));
134  }
135 
136 
137  QString version_return;
138  QStringList arguments;
139 
140  arguments << "-v";
141 
142  QProcess *xt_process = new QProcess();
143  // hk_process->setWorkingDirectory(QFileInfo(_hardklor_exe).absolutePath());
144 
145  xt_process->start(tandem_bin_path, arguments);
146 
147  if(!xt_process->waitForStarted())
148  {
150  QObject::tr("X!Tandem %1 process failed to start")
151  .arg(m_tandemVersion));
152  }
153 
154  while(xt_process->waitForReadyRead(1000))
155  {
156  }
157  /*
158  if (!xt_process->waitForFinished(_max_xt_time_ms)) {
159  throw pappso::PappsoException(QObject::tr("can't wait for X!Tandem process
160  to finish : timeout at %1").arg(_max_xt_time_ms));
161  }
162  */
163  QByteArray result = xt_process->readAll();
164 
165 
166  qDebug() << result.constData();
167 
168  // X! TANDEM Jackhammer TPP (2013.06.15.1 - LabKey, Insilicos, ISB)
169 
170  QRegExp parse_version("(.*) TANDEM ([A-Z,a-z, ]+) \\(([^ ,^\\)]*)(.*)");
171  qDebug() << parse_version;
172  // Pattern patt = Pattern.compile("X! TANDEM [A-Z]+ \\‍((.*)\\‍)",
173  // Pattern.CASE_INSENSITIVE);
174 
175  if(parse_version.exactMatch(result.constData()))
176  {
177  version_return = QString("X!Tandem %1 %2")
178  .arg(parse_version.capturedTexts()[2])
179  .arg(parse_version.capturedTexts()[3]); //.join(" ");
180  }
181  else
182  {
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));
187  }
188 
189  QProcess::ExitStatus Status = xt_process->exitStatus();
190  delete xt_process;
191  if(Status != 0)
192  {
193  // != QProcess::NormalExit
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())));
198  }
199  qDebug();
200  return version_return;
201 }

References m_tandemVersion.

Referenced by setTandemBinaryPath().

◆ convertOrginalMsData2mzXmlData()

void pappso::TandemWrapperRun::convertOrginalMsData2mzXmlData ( const QString &  origin,
const QString &  target 
) const
private

Definition at line 373 of file tandemwrapperrun.cpp.

375 {
376  qDebug();
377  pappso::MsFileAccessor origin_access(origin, "runa1");
378  origin_access.setPreferedFileReaderType(pappso::MzFormat::brukerTims,
380  origin_access.getMsRunIds();
381 
382  pappso::MsRunReaderSPtr p_reader;
383  p_reader = origin_access.msRunReaderSp(origin_access.getMsRunIds().front());
384 
385  pappso::TimsMsRunReaderMs2 *tims2_reader =
386  dynamic_cast<pappso::TimsMsRunReaderMs2 *>(p_reader.get());
387  if(tims2_reader != nullptr)
388  {
389  qDebug();
390  tims2_reader->setMs2BuiltinCentroid(true);
391 
392  if(msp_ms2FilterSuiteString != nullptr)
393  {
395  }
396  qDebug();
397  }
398 
399 
400  pappso::MzxmlOutput *p_mzxml_output;
401  QFile output_file(target);
402  // qDebug() << " TsvDirectoryWriter::writeSheet " <<
403  // QFileInfo(*_p_ofile).absoluteFilePath();
404  if(output_file.open(QIODevice::WriteOnly))
405  {
406  p_mzxml_output =
407  new pappso::MzxmlOutput(QTextStream(&output_file).device());
408 
409  p_mzxml_output->maskMs1(true);
410 
411  p_mzxml_output->setReadAhead(true);
412 
413  p_mzxml_output->write(p_reader.get());
414 
415  p_mzxml_output->close();
416 
417  delete p_mzxml_output;
418  }
419  else
420  {
422  tr("unable to write into %1 mzXML output file").arg(target));
423  }
424 
425  qDebug();
426 }
void setReadAhead(bool read_ahead)
Definition: mzxmloutput.cpp:90
void write(MsRunReader *p_msrunreader)
Definition: mzxmloutput.cpp:95
void maskMs1(bool mask_ms1)
std::shared_ptr< FilterSuiteString > msp_ms2FilterSuiteString
void setMs2FilterCstSPtr(pappso::FilterInterfaceCstSPtr filter)
void setMs2BuiltinCentroid(bool centroid)
enable or disable simple centroid filter on raw tims data for MS2
std::shared_ptr< MsRunReader > MsRunReaderSPtr
Definition: msrunreader.h:151

References pappso::brukerTims, pappso::MzxmlOutput::close(), pappso::MsFileAccessor::getMsRunIds(), pappso::MzxmlOutput::maskMs1(), msp_ms2FilterSuiteString, pappso::MsFileAccessor::msRunReaderSp(), pappso::TimsMsRunReaderMs2::setMs2BuiltinCentroid(), pappso::TimsMsRunReaderMs2::setMs2FilterCstSPtr(), pappso::MsFileAccessor::setPreferedFileReaderType(), pappso::MzxmlOutput::setReadAhead(), pappso::tims_ms2, and pappso::MzxmlOutput::write().

Referenced by wrapTandemInputFile().

◆ getMs2FilterSuiteString()

QString pappso::TandemWrapperRun::getMs2FilterSuiteString ( ) const

gets the list of filters used on MS2 spectrum

Returns
string describing filters and associated parameters

Definition at line 503 of file tandemwrapperrun.cpp.

504 {
505  if(msp_ms2FilterSuiteString == nullptr)
506  return "";
507  return msp_ms2FilterSuiteString.get()->toString();
508 }

References msp_ms2FilterSuiteString.

Referenced by writeFinalTandemOutput().

◆ readTandemPresetFile()

void pappso::TandemWrapperRun::readTandemPresetFile ( const QString &  tandem_preset_file)

Definition at line 257 of file tandemwrapperrun.cpp.

258 {
259  // get number of threads and centroid parameters from tandem preset
260 
261  XtandemPresetSaxHandler preset_handler;
262 
263  QFile qfile(tandem_preset_file);
264  QXmlInputSource xmlInputSource(&qfile);
265  QXmlSimpleReader simplereader;
266  simplereader.setContentHandler(&preset_handler);
267  simplereader.setErrorHandler(&preset_handler);
268 
269  if(simplereader.parse(xmlInputSource))
270  {
271 
272  int ideal_number_of_thread = QThread::idealThreadCount();
273  int cpu_number = preset_handler.getNumberOfThreads();
274  qDebug() << " cpu_number=" << cpu_number;
275  // QThreadPool::globalInstance()->setMaxThreadCount(1);
276  if(cpu_number > ideal_number_of_thread)
277  {
278  cpu_number = ideal_number_of_thread;
279  }
280  else
281  {
282  if(cpu_number > 0)
283  {
284  QThreadPool::globalInstance()->setMaxThreadCount(cpu_number);
285 
286  qDebug() << " maxThreadCount="
287  << QThreadPool::globalInstance()->maxThreadCount();
288  }
289  }
290 
291  QString ms2_filters_str = preset_handler.getMs2FiltersOptions();
292  if(!ms2_filters_str.isEmpty())
293  {
295  std::make_shared<pappso::FilterSuiteString>(ms2_filters_str);
296  }
297  else
298  {
300  std::make_shared<pappso::FilterSuiteString>(
301  "chargeDeconvolution|0.02dalton mzExclusion|0.01dalton");
302  }
303  }
304  else
305  {
307  QObject::tr("Error reading %1 X!Tandem preset file :\n %2")
308  .arg(tandem_preset_file)
309  .arg(preset_handler.errorString()));
310  }
311 }

References pappso::XtandemPresetSaxHandler::errorString(), pappso::XtandemPresetSaxHandler::getMs2FiltersOptions(), pappso::XtandemPresetSaxHandler::getNumberOfThreads(), and msp_ms2FilterSuiteString.

Referenced by wrapTandemInputFile().

◆ readyReadStandardError

void pappso::TandemWrapperRun::readyReadStandardError ( )
privateslot

Definition at line 219 of file tandemwrapperrun.cpp.

220 {
221  *mp_errorStream << m_xtProcess->readAllStandardError();
222  mp_errorStream->flush();
223 }

References m_xtProcess, and mp_errorStream.

Referenced by runTandem().

◆ readyReadStandardOutput

void pappso::TandemWrapperRun::readyReadStandardOutput ( )
privateslot

Definition at line 212 of file tandemwrapperrun.cpp.

213 {
214  *mp_outputStream << m_xtProcess->readAllStandardOutput();
215  mp_outputStream->flush();
216 }

References m_xtProcess, and mp_outputStream.

Referenced by runTandem().

◆ run()

void pappso::TandemWrapperRun::run ( const QString &  tandem_input_file,
QTextStream &  output_stream,
QTextStream &  error_stream 
)

run a tandem job

The tandem input file should contain an additional input parameter called "spectrum, timstof MS2 filters". The value of this parameters must contain a string describing the FilterSuiteString to apply on TimsTOF MS2. A default value of "chargeDeconvolution|0.02dalton" is recommended for this additional tandem input parameter

Parameters
tandem_input_filetandem xml input file
output_streamstandard output where to write tandem stdout
error_streamstandard error where to write tandem stderr

Definition at line 429 of file tandemwrapperrun.cpp.

432 {
433  mp_outputStream = &output_stream;
434  mp_errorStream = &error_stream;
435 
436  wrapTandemInputFile(tandem_input_file);
437  mp_outputStream = nullptr;
438  mp_errorStream = nullptr;
439 }
void wrapTandemInputFile(const QString &tandem_input_file)

References mp_errorStream, mp_outputStream, and wrapTandemInputFile().

◆ runTandem()

void pappso::TandemWrapperRun::runTandem ( const QString &  tandem_input_file)
private

run a tandem job

Parameters
tandem_input_filetandem xml input file

Definition at line 441 of file tandemwrapperrun.cpp.

442 {
443 
444  m_xtProcess = new QProcess();
445  QStringList arguments;
446 
447  qDebug() << m_tandemBinary << " " << m_xtProcess->arguments();
448 
449  arguments << tandem_input_file;
450  // hk_process->setWorkingDirectory(QFileInfo(_hardklor_exe).absolutePath());
451  m_xtProcess->start(m_tandemBinary, arguments);
452 
453  qDebug() << m_tandemBinary << " " << m_xtProcess->arguments();
454 
455  connect(m_xtProcess,
456  &QProcess::readyReadStandardOutput,
457  this,
459  connect(m_xtProcess,
460  &QProcess::readyReadStandardError,
461  this,
463 
464 
465  qDebug() << m_tandemBinary << " " << m_xtProcess->arguments();
466 
467  if(!m_xtProcess->waitForStarted())
468  {
470  QObject::tr("X!Tandem process failed to start"));
471  }
472 
473  qDebug() << m_tandemBinary << " " << m_xtProcess->arguments();
474 
475  while(m_xtProcess->waitForFinished(m_maxTandemRunTimeMs))
476  {
477  //_p_monitor->appendText(xt_process->readAll().data());
478  // data.append(xt_process->readAll());
479  if(shouldIstop())
480  {
481  m_xtProcess->kill();
482  delete m_xtProcess;
484  QObject::tr("X!Tandem stopped by the user processing on file %1")
485  .arg(tandem_input_file));
486  }
487  }
488 
489  QProcess::ExitStatus Status = m_xtProcess->exitStatus();
490 
491  delete m_xtProcess;
492  if(Status != 0)
493  {
494  // != QProcess::NormalExit
496  QObject::tr("error executing X!Tandem Status != 0 : %1")
497  .arg(m_tandemBinary));
498  }
499  m_xtProcess = nullptr;
500 }

References m_maxTandemRunTimeMs, m_tandemBinary, m_xtProcess, readyReadStandardError(), readyReadStandardOutput(), and shouldIstop().

Referenced by wrapTandemInputFile().

◆ setTandemBinaryPath()

void pappso::TandemWrapperRun::setTandemBinaryPath ( const QString &  tandem_binary_path)
private

Definition at line 85 of file tandemwrapperrun.cpp.

86 {
87 
88 
89  m_tandemBinary = tandem_binary_path;
90  QSettings settings;
91  if(m_tandemBinary.isEmpty())
92  {
94  settings.value("path/tandem_binary", "/usr/bin/tandem").toString();
95  }
96  // check for tandem executable
98 
99  qDebug() << m_tandemVersion;
100  settings.setValue("path/tandem_binary", m_tandemBinary);
101 }
const QString checkXtandemVersion(const QString &tandem_bin_path)

References checkXtandemVersion(), m_tandemBinary, and m_tandemVersion.

Referenced by TandemWrapperRun().

◆ shouldIstop()

bool pappso::TandemWrapperRun::shouldIstop ( )
private

Definition at line 205 of file tandemwrapperrun.cpp.

206 {
207  return false;
208 }

Referenced by runTandem().

◆ wrapTandemInputFile()

void pappso::TandemWrapperRun::wrapTandemInputFile ( const QString &  tandem_input_file)
private

Definition at line 315 of file tandemwrapperrun.cpp.

316 {
317  // read original tandem input file
318  // store original ms data file name
319  // create new mzXML data file in temporary directory
320  // create new tandem input file based on new mzXML file
321  QString mzxml_data_file_name =
322  mpa_temporaryDirectory->filePath("msdata.mzxml");
323  QString wrapped_tandem_input =
324  mpa_temporaryDirectory->filePath("input_tandem.xml");
325  QString wrapped_tandem_output =
326  mpa_temporaryDirectory->filePath("output_tandem.xml");
327  XtandemInputSaxHandler wrap_input(
328  mzxml_data_file_name, wrapped_tandem_input, wrapped_tandem_output);
329 
330  QFile qfile(tandem_input_file);
331  if(!qfile.exists())
332  {
334  QObject::tr("Tandem input file %1 does not exists")
335  .arg(QFileInfo(tandem_input_file).absoluteFilePath()));
336  }
337  QXmlInputSource xmlInputSource(&qfile);
338  QXmlSimpleReader simplereader;
339  simplereader.setContentHandler(&wrap_input);
340  simplereader.setErrorHandler(&wrap_input);
341 
342  if(simplereader.parse(xmlInputSource))
343  {
344  }
345  else
346  {
348  QObject::tr("Error reading %1 X!Tandem input file :\n %2")
349  .arg(tandem_input_file)
350  .arg(wrap_input.errorString()));
351  }
352 
353  // get number of threads and centroid parameters from tandem preset
354  readTandemPresetFile(wrap_input.getOriginalTandemPresetFileName());
355 
356 
357  // convert to mzXML
358  QString original_msdata_file_name = wrap_input.getOriginalMsDataFileName();
359  convertOrginalMsData2mzXmlData(original_msdata_file_name,
360  mzxml_data_file_name);
361 
362 
363  // launch tandem
364  runTandem(wrapped_tandem_input);
365 
366  // rewrite tandem result file
367  writeFinalTandemOutput(wrapped_tandem_output,
368  wrap_input.getOriginalTandemOutputFileName(),
369  original_msdata_file_name);
370 }
void readTandemPresetFile(const QString &tandem_preset_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...
void runTandem(const QString &tandem_input_file)
run a tandem job

References convertOrginalMsData2mzXmlData(), pappso::XtandemInputSaxHandler::errorString(), pappso::XtandemInputSaxHandler::getOriginalMsDataFileName(), pappso::XtandemInputSaxHandler::getOriginalTandemOutputFileName(), pappso::XtandemInputSaxHandler::getOriginalTandemPresetFileName(), mpa_temporaryDirectory, readTandemPresetFile(), runTandem(), and writeFinalTandemOutput().

Referenced by run().

◆ writeFinalTandemOutput()

void pappso::TandemWrapperRun::writeFinalTandemOutput ( const QString &  tmp_tandem_output,
const QString &  final_tandem_output,
const QString &  original_msdata_file_name 
)
private

tandem output modification tandem output is modified to contain the Bruker's file as input and centroidization parameters

Parameters
tmp_tandem_outputraw tandem output filename
final_tandem_outputfinal destination file for modified tandem output

Definition at line 226 of file tandemwrapperrun.cpp.

230 {
231 
232  XtandemOutputSaxHandler wrap_output(final_tandem_output,
233  original_msdata_file_name);
234 
235  wrap_output.setInputParameters("spectrum, timstof MS2 filters",
237 
238  QFile qfile(tmp_tandem_output);
239  QXmlInputSource xmlInputSource(&qfile);
240  QXmlSimpleReader simplereader;
241  simplereader.setContentHandler(&wrap_output);
242  simplereader.setErrorHandler(&wrap_output);
243 
244  if(simplereader.parse(xmlInputSource))
245  {
246  }
247  else
248  {
250  QObject::tr("Error reading %1 X!Tandem output file :\n %2")
251  .arg(tmp_tandem_output)
252  .arg(wrap_output.errorString()));
253  }
254 }
QString getMs2FilterSuiteString() const
gets the list of filters used on MS2 spectrum

References pappso::XtandemOutputSaxHandler::errorString(), getMs2FilterSuiteString(), and pappso::XtandemOutputSaxHandler::setInputParameters().

Referenced by wrapTandemInputFile().

Member Data Documentation

◆ m_maxTandemRunTimeMs

int pappso::TandemWrapperRun::m_maxTandemRunTimeMs = (60000 * 60 * 24)
private

Definition at line 119 of file tandemwrapperrun.h.

Referenced by runTandem().

◆ m_tandemBinary

QString pappso::TandemWrapperRun::m_tandemBinary
private

Definition at line 116 of file tandemwrapperrun.h.

Referenced by runTandem(), and setTandemBinaryPath().

◆ m_tandemVersion

QString pappso::TandemWrapperRun::m_tandemVersion
private

Definition at line 117 of file tandemwrapperrun.h.

Referenced by checkXtandemVersion(), and setTandemBinaryPath().

◆ m_tmpDir

QString pappso::TandemWrapperRun::m_tmpDir
private

Definition at line 118 of file tandemwrapperrun.h.

◆ m_xtProcess

QProcess* pappso::TandemWrapperRun::m_xtProcess = nullptr
private

◆ mp_errorStream

QTextStream* pappso::TandemWrapperRun::mp_errorStream = nullptr
private

Definition at line 125 of file tandemwrapperrun.h.

Referenced by readyReadStandardError(), and run().

◆ mp_outputStream

QTextStream* pappso::TandemWrapperRun::mp_outputStream = nullptr
private

Definition at line 124 of file tandemwrapperrun.h.

Referenced by readyReadStandardOutput(), and run().

◆ mpa_temporaryDirectory

QTemporaryDir* pappso::TandemWrapperRun::mpa_temporaryDirectory = nullptr
private

Definition at line 127 of file tandemwrapperrun.h.

Referenced by TandemWrapperRun(), ~TandemWrapperRun(), and wrapTandemInputFile().

◆ msp_ms2FilterSuiteString

std::shared_ptr<FilterSuiteString> pappso::TandemWrapperRun::msp_ms2FilterSuiteString = nullptr
private

The documentation for this class was generated from the following files: