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)
 
void setMs2FilterSuite (const std::shared_ptr< FilterSuite > ms2filter)
 sets optional filters to use on MS2 spectrum More...
 
std::shared_ptr< FilterSuitegetMs2FilterSuite () 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< FilterSuitemsp_ms2FilterSuite
 
QTextStream * mp_outputStream = nullptr
 
QTextStream * mp_errorStream = nullptr
 
QTemporaryDir * mpa_temporaryDirectory = nullptr
 

Detailed Description

Definition at line 61 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 65 of file tandemwrapperrun.cpp.

65  : unable to create temporary directory %1\n Please "
66  "check file system permissions")
67  .arg(mpa_temporaryDirectory->path()));
68  }
69 }
70 
71 TandemWrapperRun::~TandemWrapperRun()
72 {
73  if(mpa_temporaryDirectory != nullptr)
74  {
75  delete mpa_temporaryDirectory;
76  }
77 }
78 
79 void
80 TandemWrapperRun::setTandemBinaryPath(const QString &tandem_binary_path)
81 {
82 
83 
84  m_tandemBinary = tandem_binary_path;
85  QSettings settings;
86  if(m_tandemBinary.isEmpty())
87  {

◆ ~TandemWrapperRun()

pappso::TandemWrapperRun::~TandemWrapperRun ( )

Destructor

Definition at line 89 of file tandemwrapperrun.cpp.

Member Function Documentation

◆ checkXtandemVersion()

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

Definition at line 118 of file tandemwrapperrun.cpp.

123  {
124  // dir.path() returns the unique directory path
126  QObject::tr("Please check permissions on X!Tandem software found at %1 "
127  "(file not executable).")
128  .arg(tandem_exe.absoluteFilePath()));
129  }
130 
131 
132  QString version_return;
133  QStringList arguments;
134 
135  arguments << "-v";
136 
137  QProcess *xt_process = new QProcess();
138  // hk_process->setWorkingDirectory(QFileInfo(_hardklor_exe).absolutePath());
139 
140  xt_process->start(tandem_bin_path, arguments);
141 
142  if(!xt_process->waitForStarted())
143  {
145  QObject::tr("X!Tandem %1 process failed to start")
146  .arg(m_tandemVersion));
147  }
148 
149  while(xt_process->waitForReadyRead(1000))
150  {
151  }
152  /*
153  if (!xt_process->waitForFinished(_max_xt_time_ms)) {
154  throw pappso::PappsoException(QObject::tr("can't wait for X!Tandem process
155  to finish : timeout at %1").arg(_max_xt_time_ms));
156  }
157  */
158  QByteArray result = xt_process->readAll();
159 
160 
161  qDebug() << result.constData();
162 
163  // X! TANDEM Jackhammer TPP (2013.06.15.1 - LabKey, Insilicos, ISB)
164 
165  QRegExp parse_version("(.*) TANDEM ([A-Z,a-z, ]+) \\(([^ ,^\\)]*)(.*)");
166  qDebug() << parse_version;
167  // Pattern patt = Pattern.compile("X! TANDEM [A-Z]+ \\‍((.*)\\‍)",
168  // Pattern.CASE_INSENSITIVE);
169 
170  if(parse_version.exactMatch(result.constData()))
171  {
172  version_return = QString("X!Tandem %1 %2")
173  .arg(parse_version.capturedTexts()[2])
174  .arg(parse_version.capturedTexts()[3]); //.join(" ");
175  }
176  else
177  {
179  QObject::tr("This executable %1 may not be a valid X!Tandem software. "
180  "Please check your X!Tandem installation.")
181  .arg(tandem_bin_path));
182  }
183 
184  QProcess::ExitStatus Status = xt_process->exitStatus();
185  delete xt_process;
186  if(Status != 0)
187  {
188  // != QProcess::NormalExit
190  QObject::tr("error executing X!Tandem Status != 0 : %1 %2\n%3")
191  .arg(tandem_bin_path)
192  .arg(arguments.join(" ").arg(result.data())));
193  }
194  qDebug();
195  return version_return;
196 }
197 
198 
199 bool
201 {
202  return false;
203 }
204 
205 
206 void
208 {
209  *mp_outputStream << m_xtProcess->readAllStandardOutput();
210  mp_outputStream->flush();
211 }
212 
213 void

◆ convertOrginalMsData2mzXmlData()

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

Definition at line 366 of file tandemwrapperrun.cpp.

367  {
368  tims2_reader->setMs2FilterCstSPtr(msp_ms2FilterSuite);
369  }
370  else
371  {
372  std::shared_ptr<FilterSuite> ms2filter =
373  std::make_shared<FilterSuite>();
374 
375  ms2filter.get()->push_back(
376  std::make_shared<FilterChargeDeconvolution>(
378 
379  tims2_reader->setMs2FilterCstSPtr(ms2filter);
380  }
381  qDebug();
382  }
383 
384 
385  pappso::MzxmlOutput *p_mzxml_output;
386  QFile output_file(target);
387  // qDebug() << " TsvDirectoryWriter::writeSheet " <<
388  // QFileInfo(*_p_ofile).absoluteFilePath();
389  if(output_file.open(QIODevice::WriteOnly))
390  {
391  p_mzxml_output =
392  new pappso::MzxmlOutput(QTextStream(&output_file).device());
393 
394  p_mzxml_output->maskMs1(true);
395 
396  p_mzxml_output->setReadAhead(true);
397 
398  p_mzxml_output->write(p_reader.get());
399 
400  p_mzxml_output->close();
401  }
402  else
403  {
405  tr("unable to write into %1 mzXML output file").arg(target));
406  }
407 
408  qDebug();
409 }
410 
411 void
412 TandemWrapperRun::run(const QString &tandem_input_file,
413  QTextStream &output_stream,
414  QTextStream &error_stream)
415 {
416  mp_outputStream = &output_stream;
417  mp_errorStream = &error_stream;
418 
419  wrapTandemInputFile(tandem_input_file);
420  mp_outputStream = nullptr;
421  mp_errorStream = nullptr;
422 }
423 void
424 TandemWrapperRun::runTandem(const QString &tandem_input_file)
425 {
426 
427  m_xtProcess = new QProcess();

References msp_ms2FilterSuite, and pappso::TimsMsRunReaderMs2::setMs2FilterCstSPtr().

◆ getMs2FilterSuite()

std::shared_ptr< FilterSuite > pappso::TandemWrapperRun::getMs2FilterSuite ( ) const

gets the list of filters used on MS2 spectrum

Returns
vector of filters applied on MS2 spectrums

Definition at line 511 of file tandemwrapperrun.cpp.

◆ readTandemPresetFile()

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

Definition at line 267 of file tandemwrapperrun.cpp.

269  {
270  cpu_number = ideal_number_of_thread;
271  }
272  else
273  {
274  if(cpu_number > 0)
275  {
276  QThreadPool::globalInstance()->setMaxThreadCount(cpu_number);
277 
278  qDebug() << " maxThreadCount="
279  << QThreadPool::globalInstance()->maxThreadCount();
280  }
281  }
282  }
283  else
284  {
286  QObject::tr("Error reading %1 X!Tandem preset file :\n %2")
287  .arg(tandem_preset_file)
288  .arg(preset_handler.errorString()));
289  }
290 }
291 
292 
293 void
294 TandemWrapperRun::wrapTandemInputFile(const QString &tandem_input_file)
295 {
296  // read original tandem input file
297  // store original ms data file name
298  // create new mzXML data file in temporary directory
299  // create new tandem input file based on new mzXML file
300  QString mzxml_data_file_name =
301  mpa_temporaryDirectory->filePath("msdata.mzxml");
302  QString wrapped_tandem_input =
303  mpa_temporaryDirectory->filePath("input_tandem.xml");
304  QString wrapped_tandem_output =
305  mpa_temporaryDirectory->filePath("output_tandem.xml");
306  XtandemInputSaxHandler wrap_input(
307  mzxml_data_file_name, wrapped_tandem_input, wrapped_tandem_output);
308 

◆ readyReadStandardError

void pappso::TandemWrapperRun::readyReadStandardError ( )
privateslot

Definition at line 232 of file tandemwrapperrun.cpp.

237  {

◆ readyReadStandardOutput

void pappso::TandemWrapperRun::readyReadStandardOutput ( )
privateslot

Definition at line 225 of file tandemwrapperrun.cpp.

225 {
226 
227  XtandemOutputSaxHandler wrap_output(final_tandem_output,
228  original_msdata_file_name);
229 

◆ run()

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

run a tandem job

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 430 of file tandemwrapperrun.cpp.

◆ 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 442 of file tandemwrapperrun.cpp.

451  {
453  QObject::tr("X!Tandem process failed to start"));
454  }
455 
456  qDebug() << m_tandemBinary << " " << m_xtProcess->arguments();
457 
458  while(m_xtProcess->waitForFinished(m_maxTandemRunTimeMs))
459  {
460  //_p_monitor->appendText(xt_process->readAll().data());
461  // data.append(xt_process->readAll());
462  if(shouldIstop())
463  {
464  m_xtProcess->kill();
465  delete m_xtProcess;
467  QObject::tr("X!Tandem stopped by the user processing on file %1")
468  .arg(tandem_input_file));
469  }
470  }
471 
472  QProcess::ExitStatus Status = m_xtProcess->exitStatus();
473 
474  delete m_xtProcess;
475  if(Status != 0)
476  {
477  // != QProcess::NormalExit
479  QObject::tr("error executing X!Tandem Status != 0 : %1")
480  .arg(m_tandemBinary));
481  }
482  m_xtProcess = nullptr;
483 }
484 
485 void
487  const std::shared_ptr<FilterSuite> ms2filter)
488 {
489  msp_ms2FilterSuite = ms2filter;
490 }
491 
492 std::shared_ptr<FilterSuite>
494 {
495  return msp_ms2FilterSuite;
496 }
497 
498 } // namespace pappso

◆ setMs2FilterSuite()

void pappso::TandemWrapperRun::setMs2FilterSuite ( const std::shared_ptr< FilterSuite ms2filter)

sets optional filters to use on MS2 spectrum

Parameters
ms2filtervector of filters applied on MS2 spectrums

Definition at line 504 of file tandemwrapperrun.cpp.

◆ setTandemBinaryPath()

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

Definition at line 98 of file tandemwrapperrun.cpp.

101 {
102  qDebug();
103  // check tandem path
104  QFileInfo tandem_exe(tandem_bin_path);
105  if(!tandem_exe.exists())
106  {
107  // dir.path() returns the unique directory path
109  QObject::tr(
110  "X!Tandem software not found at %1.\nPlease check the X!Tandem "
111  "installation on your computer and set tandem.exe path.")
112  .arg(tandem_exe.absoluteFilePath()));
113  }
114  if(!tandem_exe.isReadable())

◆ shouldIstop()

bool pappso::TandemWrapperRun::shouldIstop ( )
private

Definition at line 218 of file tandemwrapperrun.cpp.

225 {

◆ wrapTandemInputFile()

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

Definition at line 312 of file tandemwrapperrun.cpp.

316  {
317  }
318  else
319  {
321  QObject::tr("Error reading %1 X!Tandem input file :\n %2")
322  .arg(tandem_input_file)
323  .arg(wrap_input.errorString()));
324  }
325 
326  // get number of threads and centroid parameters from tandem preset
327  readTandemPresetFile(wrap_input.getOriginalTandemPresetFileName());
328 
329 
330  // convert to mzXML
331  QString original_msdata_file_name = wrap_input.getOriginalMsDataFileName();
332  qDebug() << "DDDDDDDDDDD" << original_msdata_file_name
333  << wrap_input.getOriginalTandemOutputFileName();
334  convertOrginalMsData2mzXmlData(original_msdata_file_name,
335  mzxml_data_file_name);
336 
337 
338  // launch tandem
339  runTandem(wrapped_tandem_input);
340 
341  // rewrite tandem result file
342  writeFinalTandemOutput(wrapped_tandem_output,
343  wrap_input.getOriginalTandemOutputFileName(),
344  original_msdata_file_name);
345 }
346 
347 void
349  const QString &target) const
350 {
351  qDebug();
352  pappso::MsFileAccessor origin_access(origin, "runa1");
353  origin_access.setPreferedFileReaderType(pappso::MzFormat::brukerTims,
355  origin_access.getMsRunIds();
356 
357  pappso::MsRunReaderSPtr p_reader;
358  p_reader = origin_access.msRunReaderSp(origin_access.getMsRunIds().front());
359 
360  pappso::TimsMsRunReaderMs2 *tims2_reader =
361  dynamic_cast<pappso::TimsMsRunReaderMs2 *>(p_reader.get());
362  if(tims2_reader != nullptr)
363  {

◆ 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 239 of file tandemwrapperrun.cpp.

240  {
242  QObject::tr("Error reading %1 X!Tandem output file :\n %2")
243  .arg(tmp_tandem_output)
244  .arg(wrap_output.errorString()));
245  }
246 }
247 
248 void
249 TandemWrapperRun::readTandemPresetFile(const QString &tandem_preset_file)
250 {
251  // get number of threads and centroid parameters from tandem preset
252 
253  XtandemPresetSaxHandler preset_handler;
254 
255  QFile qfile(tandem_preset_file);
256  QXmlInputSource xmlInputSource(&qfile);
257  QXmlSimpleReader simplereader;
258  simplereader.setContentHandler(&preset_handler);
259  simplereader.setErrorHandler(&preset_handler);
260 
261  if(simplereader.parse(xmlInputSource))
262  {
263 
264  int ideal_number_of_thread = QThread::idealThreadCount();

References pappso::XtandemOutputSaxHandler::errorString().

Member Data Documentation

◆ m_maxTandemRunTimeMs

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

Definition at line 155 of file tandemwrapperrun.h.

◆ m_tandemBinary

QString pappso::TandemWrapperRun::m_tandemBinary
private

Definition at line 152 of file tandemwrapperrun.h.

◆ m_tandemVersion

QString pappso::TandemWrapperRun::m_tandemVersion
private

Definition at line 153 of file tandemwrapperrun.h.

◆ m_tmpDir

QString pappso::TandemWrapperRun::m_tmpDir
private

Definition at line 154 of file tandemwrapperrun.h.

◆ m_xtProcess

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

Definition at line 156 of file tandemwrapperrun.h.

◆ mp_errorStream

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

Definition at line 162 of file tandemwrapperrun.h.

◆ mp_outputStream

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

Definition at line 161 of file tandemwrapperrun.h.

◆ mpa_temporaryDirectory

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

Definition at line 164 of file tandemwrapperrun.h.

◆ msp_ms2FilterSuite

std::shared_ptr<FilterSuite> pappso::TandemWrapperRun::msp_ms2FilterSuite
private
Initial value:
=
std::make_shared<FilterSuite>()

Definition at line 158 of file tandemwrapperrun.h.

Referenced by convertOrginalMsData2mzXmlData().


The documentation for this class was generated from the following files:
pappso::TandemWrapperRun::shouldIstop
bool shouldIstop()
Definition: tandemwrapperrun.cpp:218
pappso::TandemWrapperRun::m_maxTandemRunTimeMs
int m_maxTandemRunTimeMs
Definition: tandemwrapperrun.h:155
pappso::MzFormat::brukerTims
@ brukerTims
pappso::MzxmlOutput
Definition: mzxmloutput.h:64
pappso::MsRunReaderSPtr
std::shared_ptr< MsRunReader > MsRunReaderSPtr
Definition: msrunreader.h:172
pappso::TandemWrapperRun::m_tandemVersion
QString m_tandemVersion
Definition: tandemwrapperrun.h:153
pappso::TandemWrapperRun::setMs2FilterSuite
void setMs2FilterSuite(const std::shared_ptr< FilterSuite > ms2filter)
sets optional filters to use on MS2 spectrum
Definition: tandemwrapperrun.cpp:504
pappso::MzxmlOutput::write
void write(MsRunReader *p_msrunreader)
Definition: mzxmloutput.cpp:95
pappso::TandemWrapperRun::writeFinalTandemOutput
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...
Definition: tandemwrapperrun.cpp:239
pappso::TandemWrapperRun::readyReadStandardOutput
void readyReadStandardOutput()
Definition: tandemwrapperrun.cpp:225
pappso::TandemWrapperRun::runTandem
void runTandem(const QString &tandem_input_file)
run a tandem job
Definition: tandemwrapperrun.cpp:442
pappso::MsFileAccessor
Definition: msfileaccessor.h:35
pappso::PrecisionFactory::getDaltonInstance
static PrecisionPtr getDaltonInstance(pappso_double value)
Definition: precision.cpp:150
pappso::TandemWrapperRun::mp_errorStream
QTextStream * mp_errorStream
Definition: tandemwrapperrun.h:162
pappso::TandemWrapperRun::mpa_temporaryDirectory
QTemporaryDir * mpa_temporaryDirectory
Definition: tandemwrapperrun.h:164
pappso::TandemWrapperRun::readyReadStandardError
void readyReadStandardError()
Definition: tandemwrapperrun.cpp:232
pappso::FileReaderType::tims_ms2
@ tims_ms2
pappso::TandemWrapperRun::m_xtProcess
QProcess * m_xtProcess
Definition: tandemwrapperrun.h:156
pappso::TandemWrapperRun::msp_ms2FilterSuite
std::shared_ptr< FilterSuite > msp_ms2FilterSuite
Definition: tandemwrapperrun.h:158
pappso::TimsMsRunReaderMs2
Definition: timsmsrunreaderms2.h:59
pappso::TandemWrapperRun::m_tandemBinary
QString m_tandemBinary
Definition: tandemwrapperrun.h:152
pappso::TandemWrapperRun::readTandemPresetFile
void readTandemPresetFile(const QString &tandem_preset_file)
Definition: tandemwrapperrun.cpp:267
pappso::MzxmlOutput::setReadAhead
void setReadAhead(bool read_ahead)
Definition: mzxmloutput.cpp:90
pappso::TandemWrapperRun::run
void run(const QString &tandem_input_file, QTextStream &output_stream, QTextStream &error_stream)
run a tandem job
Definition: tandemwrapperrun.cpp:430
pappso::MzxmlOutput::maskMs1
void maskMs1(bool mask_ms1)
Definition: mzxmloutput.cpp:382
pappso::MzxmlOutput::close
void close()
Definition: mzxmloutput.cpp:215
pappso::TandemWrapperRun::mp_outputStream
QTextStream * mp_outputStream
Definition: tandemwrapperrun.h:161
pappso::TandemWrapperRun::convertOrginalMsData2mzXmlData
void convertOrginalMsData2mzXmlData(const QString &origin, const QString &target) const
Definition: tandemwrapperrun.cpp:366
pappso::TandemWrapperRun::wrapTandemInputFile
void wrapTandemInputFile(const QString &tandem_input_file)
Definition: tandemwrapperrun.cpp:312
pappso::TandemWrapperRun::getMs2FilterSuite
std::shared_ptr< FilterSuite > getMs2FilterSuite() const
gets the list of filters used on MS2 spectrum
Definition: tandemwrapperrun.cpp:511
pappso::PappsoException
Definition: pappsoexception.h:63