Commit 46abe4e8 authored by Langella Olivier's avatar Langella Olivier
Browse files

tandem parameters file and handlers

parent 625b7cea
......@@ -60,6 +60,7 @@ SET(CPP_FILES
core/labeling/labelingmethod.cpp
core/tandem_run/tandembatchprocess.cpp
core/tandem_run/tandemcondorprocess.cpp
core/tandem_run/tandemparameters.cpp
core/msrun.cpp
core/peptidematch.cpp
core/peptidextp.cpp
......@@ -68,6 +69,7 @@ SET(CPP_FILES
core/proteinxtp.cpp
core/sequencedatabase.cpp
files/fastafile.cpp
files/tandemparametersfile.cpp
files/xpipfile.cpp
grouping/groupingexperiment.cpp
grouping/groupinggroup.cpp
......@@ -81,6 +83,7 @@ SET(CPP_FILES
input/condorqxmlsaxhandler.cpp
input/identificationpwizreader.cpp
input/xpipsaxhandler.cpp
input/xtandemparamsaxhandler.cpp
input/xtandemsaxhandler.cpp
output/masschroqml.cpp
output/proticdbml.cpp
......
......@@ -35,6 +35,7 @@
#include <QXmlSimpleReader>
#include <QThread>
#include "../../input/condorqxmlsaxhandler.h"
#include "../../files/tandemparametersfile.h"
TandemCondorProcess::TandemCondorProcess(MainWindow * p_main_window, WorkMonitorInterface * p_monitor, const TandemRunBatch & tandem_run_batch) : TandemBatchProcess(p_main_window,p_monitor, tandem_run_batch) {
/*
......@@ -98,10 +99,14 @@ void TandemCondorProcess::prepareXmlDatabaseFile() {
void TandemCondorProcess::run() {
qDebug() << "TandemCondorProcess::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;
TandemParametersFile orig_parameter_file(_tandem_run_batch._preset_file);
_preset_file = QString("%1/%2").arg(_p_tmp_dir->path()).arg(orig_parameter_file.getFilename());
TandemParametersFile new_parameter_file(_preset_file);
TandemParameters new_param = orig_parameter_file.getTandemParameters();
// <note type="input" label="spectrum, threads">1</note>
new_param.setParamLabel("spectrum, threads",QString("%1").arg(_tandem_run_batch._number_of_threads));
new_parameter_file.setTandemParameters(new_param);
prepareXmlDatabaseFile();
......
/**
* \file /core/tandem_run/tandemparameters.cpp
* \date 19/9/2017
* \author Olivier Langella
* \brief handles X!Tandem parameters
*/
/*******************************************************************************
* 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 "tandemparameters.h"
TandemParameters::TandemParameters() {
}
TandemParameters::~TandemParameters() {
}
TandemParameters::TandemParameters(const TandemParameters & other) {
_map_label_value = other._map_label_value;
_method_name = other._method_name;
}
void TandemParameters::setParamLabel(const QString & label, const QString & value) {
_map_label_value.insert(label, value);
}
void TandemParameters::setMethodName(const QString & method) {
_method_name = method;
}
const QMap<QString, QString> & TandemParameters::getMapLabelValue() const {
return _map_label_value;
}
/**
* \file /core/tandem_run/tandemparameters.h
* \date 19/9/2017
* \author Olivier Langella
* \brief handles X!Tandem parameters
*/
/*******************************************************************************
* 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 TANDEMPARAMETERS_H
#define TANDEMPARAMETERS_H
#include <QString>
#include <QMap>
class TandemParameters
{
public:
TandemParameters();
TandemParameters(const TandemParameters & other);
virtual ~TandemParameters();
void setMethodName(const QString & method);
void setParamLabel(const QString & label, const QString & value);
const QMap<QString, QString> & getMapLabelValue() const;
private:
QString _method_name;
QMap<QString, QString> _map_label_value;
};
#endif // TANDEMPARAMETERS_H
......@@ -39,6 +39,7 @@ struct TandemRunBatch
QString _preset_file;
QStringList _fasta_file_list;
QString _output_directory;
unsigned int _number_of_threads=1;
};
//Q_DECLARE_METATYPE(TandemRunBatch)
#endif // TANDEMRUNBATCH_H
/**
* \file /files/tandemparametersfile.cpp
* \date 19/9/2017
* \author Olivier Langella
* \brief handles X!Tandem parameters file (presets)
*/
/*******************************************************************************
* 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 "tandemparametersfile.h"
#include <QXmlSimpleReader>
#include <QXmlStreamWriter>
#include <pappsomspp/pappsoexception.h>
#include "../input/xtandemparamsaxhandler.h"
TandemParametersFile::TandemParametersFile(const QString & fasta_source) : _param_source(fasta_source)
{
qDebug() << "TandemParametersFile::TandemParametersFile "<< fasta_source;
}
TandemParametersFile::TandemParametersFile(const QFileInfo & fasta_source): _param_source(fasta_source)
{
}
TandemParametersFile::TandemParametersFile(const TandemParametersFile & other) : _param_source(other._param_source)
{
}
TandemParametersFile::~TandemParametersFile()
{
}
const QString TandemParametersFile::getMethodName() const {
return _param_source.baseName();
}
const QString TandemParametersFile::getFilename() const {
return _param_source.fileName();
}
const QString TandemParametersFile::getAbsoluteFilePath() const {
return _param_source.absoluteFilePath();
}
void TandemParametersFile::setTandemParameters(const TandemParameters & parameters) const {
QFile xml_file(_param_source.absoluteFilePath());
QXmlStreamWriter * p_out;
if (xml_file.open(QIODevice::WriteOnly)) {
p_out = new QXmlStreamWriter();
p_out->setDevice(&xml_file);
writeXmlParametersFile(p_out, parameters);
xml_file.close();
delete p_out;
} else
{
throw pappso::PappsoException(QObject::tr("error : cannot open the XML X!Tandem parameter file : %1\n").arg(xml_file.fileName()));
}
}
TandemParameters TandemParametersFile::getTandemParameters() const {
qDebug() << "TandemParametersFile::getTandemParameters begin";
TandemParameters parameters;
XtandemParamSaxHandler * parser = new XtandemParamSaxHandler(&parameters);
QXmlSimpleReader simplereader;
simplereader.setContentHandler(parser);
simplereader.setErrorHandler(parser);
qDebug() << "TandemParametersFile::getTandemParameters '" << _param_source.absoluteFilePath() << "'";
parameters.setMethodName(getMethodName());
QFile qfile(_param_source.absoluteFilePath());
QXmlInputSource xmlInputSource(&qfile);
if (simplereader.parse(xmlInputSource)) {
qfile.close();
} else {
qfile.close();
delete parser;
throw pappso::PappsoException(QObject::tr("Error reading %1 X!Tandem preset file :\n %2").arg(_param_source.absoluteFilePath()).arg(parser->errorString()));
}
delete parser;
return parameters;
}
void TandemParametersFile::writeXmlParametersFile (QXmlStreamWriter * p_out, const TandemParameters & parameters) const {
p_out->setAutoFormatting(true);
p_out->writeStartDocument("1.0");
//<?xml version="1.0" encoding="UTF-8"?>
//<bioml label="example api document">
//<note type="input" label="spectrum, parent monoisotopic mass error units">ppm</note>
//<note type="input" label="spectrum, parent monoisotopic mass error minus">10</note>
p_out->writeStartElement("bioml");
p_out->writeAttribute("label","example api document");
for (const QString & label :parameters.getMapLabelValue().keys()) {
p_out->writeStartElement("note");
p_out->writeAttribute("type","input");
p_out->writeAttribute("label",label);
p_out->writeCharacters(parameters.getMapLabelValue().value(label));
p_out->writeEndElement();
}
//</bioml>
p_out->writeEndElement();
p_out->writeEndDocument();
}
/**
* \file /files/tandemparametersfile.h
* \date 19/9/2017
* \author Olivier Langella
* \brief handles X!Tandem parameters file (presets)
*/
/*******************************************************************************
* 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 TANDEMPARAMETERSFILE_H
#define TANDEMPARAMETERSFILE_H
#include <QFileInfo>
#include <QXmlStreamWriter>
#include "../core/tandem_run/tandemparameters.h"
class TandemParametersFile
{
public:
TandemParametersFile(const QString & param_file);
TandemParametersFile(const QFileInfo & param_file);
TandemParametersFile(const TandemParametersFile & other);
~TandemParametersFile();
const QString getMethodName() const;
const QString getFilename() const;
const QString getAbsoluteFilePath() const;
/** @brief read tandem parameters from XML file
*/
TandemParameters getTandemParameters() const;
/** @brief write tandem parameters to XML file
*/
void setTandemParameters(const TandemParameters & parameters) const;
private :
void writeXmlParametersFile (QXmlStreamWriter * p_out, const TandemParameters & parameters) const;
private :
const QFileInfo _param_source;
};
#endif // TANDEMPARAMETERSFILE_H
......@@ -206,6 +206,20 @@
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>number of threads</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="thread_spin_box">
<property name="minimum">
<number>1</number>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
......
......@@ -195,5 +195,6 @@ TandemRunBatch TandemRunDialog::getTandemRunBatch() const {
//tandem_run_batch._preset_file = ui->preset_combobox->itemData(ui->preset_combobox->currentIndex()).value<QFileInfo>().absoluteFilePath();
tandem_run_batch._preset_file = ui->preset_combobox->itemData(ui->preset_combobox->currentIndex()).value<QString>();
tandem_run_batch._output_directory = ui->output_directory_label->text();
tandem_run_batch._number_of_threads = ui->thread_spin_box->value();
return tandem_run_batch;
}
/**
* \file /input/xtandemparamsaxhandler.cpp
* \date 19/9/2017
* \author Olivier Langella
* \brief XML handler for X!Tandem parameters file (presets)
*/
/*******************************************************************************
* 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 "xtandemparamsaxhandler.h"
#include <pappsomspp/pappsoexception.h>
XtandemParamSaxHandler::XtandemParamSaxHandler(TandemParameters * p_tandem_parameters) {
_p_tandem_parameters = p_tandem_parameters;
}
XtandemParamSaxHandler::~XtandemParamSaxHandler() {
}
bool XtandemParamSaxHandler::startElement(const QString & namespaceURI, const QString & localName,
const QString & qName, const QXmlAttributes & attributes) {
qDebug()<< "XtandemParamSaxHandler::startElement begin" << namespaceURI << " " << localName << " " << qName ;
_tag_stack.push_back(qName);
bool is_ok = true;
try {
//startElement_group
if (qName == "c") {
is_ok = startElement_note(attributes);
}
_current_text.clear();
}
catch (pappso::PappsoException exception_pappso) {
_errorStr = QObject::tr("ERROR in XtandemParamSaxHandler::startElement tag %1, PAPPSO exception:\n%2").arg(qName).arg(exception_pappso.qwhat());
return false;
}
catch (std::exception exception_std) {
_errorStr = QObject::tr("ERROR in XtandemParamSaxHandler::startElement tag %1, std exception:\n%2").arg(qName).arg(exception_std.what());
return false;
}
return is_ok;
}
bool XtandemParamSaxHandler::endElement(const QString & namespaceURI, const QString & localName,
const QString & qName) {
bool is_ok = true;
// endElement_peptide_list
try {
if (qName == "note")
{
is_ok = endElement_note();
}
}
catch (pappso::PappsoException exception_pappso) {
_errorStr = QObject::tr("ERROR in XtandemParamSaxHandler::endElement tag %1, PAPPSO exception:\n%2").arg(qName).arg(exception_pappso.qwhat());
return false;
}
catch (std::exception exception_std) {
_errorStr = QObject::tr("ERROR in XtandemParamSaxHandler::endElement tag %1, std exception:\n%2").arg(qName).arg(exception_std.what());
return false;
}
_current_text.clear();
_tag_stack.pop_back();
return is_ok;
}
bool XtandemParamSaxHandler::error(const QXmlParseException &exception) {
_errorStr = QObject::tr("Parse error at line %1, column %2 :\n"
"%3").arg(exception.lineNumber()).arg(exception.columnNumber()).arg(
exception.message());
return false;
}
bool XtandemParamSaxHandler::fatalError(const QXmlParseException &exception) {
_errorStr = QObject::tr("Parse error at line %1, column %2 :\n"
"%3").arg(exception.lineNumber()).arg(exception.columnNumber()).arg(
exception.message());
return false;
}
QString XtandemParamSaxHandler::errorString() const {
return _errorStr;
}
bool XtandemParamSaxHandler::endDocument() {
return true;
}
bool XtandemParamSaxHandler::startDocument() {
/*<?xml version="1.0" encoding="UTF-8"?>
<bioml label="example api document">
<note type="input" label="spectrum, parent monoisotopic mass error units">ppm</note>
<note type="input" label="spectrum, parent monoisotopic mass error minus">10</note>
*/
return true;
}
bool XtandemParamSaxHandler::characters(const QString &str) {
_current_text += str;
return true;
}
bool XtandemParamSaxHandler::startElement_note(QXmlAttributes attributes) {
// logger.debug("startElementgroup begin");
_current_label = "";
if (attributes.value("type") == "input") {
_current_label = attributes.value("label");
}
return true;
}
bool XtandemParamSaxHandler::endElement_note() {
if (!_current_label.isEmpty()) {
_p_tandem_parameters->setParamLabel( _current_label, _current_text.simplified());
}
return true;
}
/**
* \file /input/xtandemparamsaxhandler.h
* \date 19/9/2017
* \author Olivier Langella
* \brief XML handler for X!Tandem parameters file (presets)
*/
/*******************************************************************************
* 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 XTANDEMPARAMSAXHANDLER_H
#define XTANDEMPARAMSAXHANDLER_H
#include <QXmlDefaultHandler>
#include <vector>
#include "../core/tandem_run/tandemparameters.h"
class XtandemParamSaxHandler: public QXmlDefaultHandler
{
public:
XtandemParamSaxHandler(TandemParameters * p_tandem_parameters);
~XtandemParamSaxHandler();
bool startElement(const QString & namespaceURI, const QString & localName,
const QString & qName, const QXmlAttributes & attributes);
bool endElement(const QString & namespaceURI, const QString & localName,
const QString & qName);
bool startDocument();
bool endDocument();
bool characters(const QString &str);
bool fatalError(const QXmlParseException &exception);
bool error(const QXmlParseException &exception);
QString errorString() const;
private:
bool startElement_note(QXmlAttributes attributes);
bool endElement_note();
private:
TandemParameters * _p_tandem_parameters;
std::vector<QString> _tag_stack;
QString _errorStr;
QString _current_text;
QString _current_label;
};