From d73fcb8b9c157f45fe361391750436141a24f84d Mon Sep 17 00:00:00 2001 From: Olivier Langella <Olivier.Langella@moulon.inra.fr> Date: Fri, 19 Aug 2016 18:19:43 +0200 Subject: [PATCH] sax parser for xpip file --- src/CMakeLists.txt | 9 +- src/core/project.cpp | 45 +++++- src/core/project.h | 5 + src/files/xpipfile.cpp | 7 +- .../protein_list_view/proteintablemodel.cpp | 6 +- src/input/xpipsaxhandler.cpp | 136 ++++++++++++++++++ src/input/xpipsaxhandler.h | 60 ++++++++ 7 files changed, 258 insertions(+), 10 deletions(-) create mode 100644 src/input/xpipsaxhandler.cpp create mode 100644 src/input/xpipsaxhandler.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e39188a50..67d010994 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -12,7 +12,7 @@ #FIND_PACKAGE(Boost REQUIRED) #INCLUDE_DIRECTORIES( ${Boost_INCLUDE_DIRS}) -FIND_PACKAGE( Qt4 COMPONENTS QTCORE QTGUI QTSVG REQUIRED ) +FIND_PACKAGE( Qt4 COMPONENTS QTCORE QTGUI QTSVG QTXML REQUIRED ) FIND_PACKAGE( Odsstream REQUIRED ) #ODSSTREAM_INCLUDE_DIR AND ODSSTREAM_LIBRARY @@ -54,6 +54,7 @@ SET(CPP_FILES utils/readspectrum.cpp core/project.cpp files/xpipfile.cpp + input/xpipsaxhandler.cpp ) set(QTLIBS ${Qt5Xml_LIBRARIES} ${Qt5Gui_LIBRARIES} ${Qt5Svg_LIBRARIES}) @@ -92,15 +93,17 @@ MESSAGE("XTPCPP_SRCS: ${XTPCPP_SRCS}") ADD_EXECUTABLE(xtpcpp main.cpp ${CPP_FILES} ${XTPCPP_SRCS} ${GUI_UI_HDRS} ${XTPCPP_MOC_SRCS}) -target_include_directories (xtpcpp PUBLIC ${QT_INCLUDE_DIR} ${QT_QTCORE_INCLUDE_DIR} ${QT_QTGUI_INCLUDE_DIR} ${QT_QTSVG_INCLUDE_DIR}) +target_include_directories (xtpcpp PUBLIC ${QT_INCLUDE_DIR} ${QT_QTCORE_INCLUDE_DIR} ${QT_QTGUI_INCLUDE_DIR} ${QT_QTSVG_INCLUDE_DIR} ${QT_QTXML_INCLUDE_DIR}) SET_TARGET_PROPERTIES(xtpcpp PROPERTIES OUTPUT_NAME xtpcpp CLEAN_DIRECT_OUTPUT 1 COMPILE_DEFINITIONS "${QT_DEFINITIONS}" #INCLUDE_DIRECTORIES "${QT_INCLUDE_DIR} ${QT_QTCORE_INCLUDE_DIR}" ) -TARGET_LINK_LIBRARIES(xtpcpp ${PAPPSOMSPP_QT4_LIBRARY} ${Pwiz_LIBRARY} ${ODSSTREAM_QT4_LIBRARY} ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY} ${QT_QTSVG_LIBRARY}) +TARGET_LINK_LIBRARIES(xtpcpp ${PAPPSOMSPP_QT4_LIBRARY} ${Pwiz_LIBRARY} ${ODSSTREAM_QT4_LIBRARY} ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY} ${QT_QTSVG_LIBRARY} ${QT_QTXML_LIBRARY}) INSTALL(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/xtpcpp DESTINATION bin) #configure_file (${CMAKE_SOURCE_DIR}/templates/share/applications/pt-peptideviewer.desktop.cmake ${CMAKE_BINARY_DIR}/templates/share/applications/pt-peptideviewer.desktop) + +add_subdirectory(input) \ No newline at end of file diff --git a/src/core/project.cpp b/src/core/project.cpp index 7a92c3fb5..4f51f107c 100644 --- a/src/core/project.cpp +++ b/src/core/project.cpp @@ -21,6 +21,7 @@ * Olivier Langella <Olivier.Langella@moulon.inra.fr> - initial API and implementation ******************************************************************************/ #include "project.h" +#include "../input/xpipsaxhandler.h" Project::Project() { @@ -33,5 +34,45 @@ Project::~Project() } ProjectSp Project::makeProjectSp() const { - return std::make_shared<Project>(*this); -} \ No newline at end of file + return std::make_shared<Project>(*this); +} + + +void Project::readXpipFile(QFileInfo xpip_fileinfo) { + + + XpipSaxHandler * parser = new XpipSaxHandler(); + + QXmlSimpleReader simplereader; + simplereader.setContentHandler(parser); + simplereader.setErrorHandler(parser); + + qDebug() << "Read XPIP XML result file '" << xpip_fileinfo.absoluteFilePath() << "'"; + + QFile qfile(xpip_fileinfo.absoluteFilePath()); + QXmlInputSource xmlInputSource(&qfile); + + if (simplereader.parse(xmlInputSource)) { + } else { + qDebug() << parser->errorString(); + // throw PappsoException( + // QObject::tr("error reading tandem XML result file :\n").append( + // parser->errorString())); + } + qfile.close(); + +/* + GrpGroupingMonitor monitor; + GrpExperiment grpExperiment(monitor); + PeptideReader peptideReader(grpExperiment); + FastaReader reader(peptideReader); + reader.parse(&fastaFile); + fastaFile.close(); + grpExperiment.startGrouping(); + + + std::list<GrpProteinSp> protein_list; + grpExperiment.getGroupedProteinSpList(protein_list); + */ + +} diff --git a/src/core/project.h b/src/core/project.h index 31ff6dc68..d5d72c686 100644 --- a/src/core/project.h +++ b/src/core/project.h @@ -24,6 +24,8 @@ #define PROJECT_H #include<memory> +#include <pappsomspp/grouping/grpexperiment.h> +#include <QFileInfo> class Project; typedef std::shared_ptr<Project> ProjectSp; @@ -35,6 +37,9 @@ public: ~Project(); ProjectSp makeProjectSp() const; + void readXpipFile(QFileInfo xpip_source); + + pappso::GrpExperiment * _p_grp_experiment= nullptr; }; #endif // PROJECT_H diff --git a/src/files/xpipfile.cpp b/src/files/xpipfile.cpp index 4d13bf011..e5e55f04a 100644 --- a/src/files/xpipfile.cpp +++ b/src/files/xpipfile.cpp @@ -30,9 +30,12 @@ XpipFile::~XpipFile() { } + ProjectSp XpipFile::getProjectSp() const { - Project project; + ProjectSp project_sp = Project().makeProjectSp(); + + project_sp.get()->readXpipFile(QFileInfo(_xpip_source.toLocalFile())); - return (project.makeProjectSp()); + return (project_sp); } \ No newline at end of file diff --git a/src/gui/protein_list_view/proteintablemodel.cpp b/src/gui/protein_list_view/proteintablemodel.cpp index 24a87a25d..7ef7e8e9a 100644 --- a/src/gui/protein_list_view/proteintablemodel.cpp +++ b/src/gui/protein_list_view/proteintablemodel.cpp @@ -49,11 +49,11 @@ QVariant ProteinTableModel::headerData(int section, Qt::Orientation orientation, switch (section) { case 0: - return QString("first"); + return QString("group"); case 1: - return QString("second"); + return QString("subgroup"); case 2: - return QString("third"); + return QString("protein description"); } } } diff --git a/src/input/xpipsaxhandler.cpp b/src/input/xpipsaxhandler.cpp new file mode 100644 index 000000000..804b5a009 --- /dev/null +++ b/src/input/xpipsaxhandler.cpp @@ -0,0 +1,136 @@ +/******************************************************************************* +* Copyright (c) 2016 Olivier Langella <Olivier.Langella@moulon.inra.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@moulon.inra.fr> - initial API and implementation +******************************************************************************/ + +#include "xpipsaxhandler.h" + +XpipSaxHandler::XpipSaxHandler() +{ + +} + +XpipSaxHandler::~XpipSaxHandler() +{ + +} + + +bool XpipSaxHandler::startElement(const QString & namespaceURI, const QString & localName, + const QString & qName, const QXmlAttributes & attributes) { + // qDebug() << namespaceURI << " " << localName << " " << qName ; + _tag_stack.push_back(qName); + bool is_ok = true; + + try { + //startElement_group + if (qName == "group") + { + //is_ok = startElement_group(attributes); + } + _current_text.clear(); + } + catch (PappsoException exception_pappso) { + _errorStr = QObject::tr("ERROR in XtandemResultsHandler::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 XtandemResultsHandler::startElement tag %1, std exception:\n%2").arg(qName).arg(exception_std.what()); + return false; + } + return is_ok; +} + +bool XpipSaxHandler::endElement(const QString & namespaceURI, const QString & localName, + const QString & qName) { + + bool is_ok = true; + // endElement_peptide_list + try { + if (qName == "group") + { + //is_ok = endElement_group(); + } + + // end of detection_moulon + // else if ((_tag_stack.size() > 1) && + // (_tag_stack[_tag_stack.size() - 2] == "detection_moulon")) + } + catch (PappsoException exception_pappso) { + _errorStr = QObject::tr("ERROR in XtandemResultsHandler::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 XtandemResultsHandler::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 XpipSaxHandler::endElement_group() { + if ((_tag_stack.size() > 1) && (_tag_stack[_tag_stack.size() - 2] == "group")) { + } + else { + // XtandemHyperscore hyperscore(_curent_spectrum, _current_peptide_sp, _precision, _ion_list, _max_charge,_refine_spectrum_synthesis); + } + return true; +} +*/ + + +bool XpipSaxHandler::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 XpipSaxHandler::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 XpipSaxHandler::errorString() const { + return _errorStr; +} + + +bool XpipSaxHandler::endDocument() { + return true; +} + +bool XpipSaxHandler::startDocument() { + return true; +} + +bool XpipSaxHandler::characters(const QString &str) { + _current_text += str; + return true; +} + diff --git a/src/input/xpipsaxhandler.h b/src/input/xpipsaxhandler.h new file mode 100644 index 000000000..55ca5e4cb --- /dev/null +++ b/src/input/xpipsaxhandler.h @@ -0,0 +1,60 @@ +/******************************************************************************* +* Copyright (c) 2016 Olivier Langella <Olivier.Langella@moulon.inra.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@moulon.inra.fr> - initial API and implementation +******************************************************************************/ + +#ifndef XPIPSAXHANDLER_H +#define XPIPSAXHANDLER_H + +#include <QXmlDefaultHandler> +#include <pappsomspp/pappsoexception.h> + +using namespace pappso; + +class XpipSaxHandler: public QXmlDefaultHandler +{ +public: + XpipSaxHandler(); + ~XpipSaxHandler(); + + 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: + std::vector<QString> _tag_stack; + QString _errorStr; + QString _current_text; +}; + +#endif // XTANDEMRESULTSHANDLER_H -- GitLab