From 05666e515a81e52bcbc36e2e261be020f9fa9770 Mon Sep 17 00:00:00 2001
From: Olivier Langella <Olivier.Langella@moulon.inra.fr>
Date: Fri, 19 Aug 2016 18:51:46 +0200
Subject: [PATCH] WIP parsing XPIP

---
 src/CMakeLists.txt           |  8 ++++----
 src/core/project.cpp         | 32 ++++++++++++++++++--------------
 src/core/project.h           |  2 ++
 src/input/xpipsaxhandler.cpp | 29 +++++++++++++++++++++++++----
 src/input/xpipsaxhandler.h   | 13 ++++++++++++-
 5 files changed, 61 insertions(+), 23 deletions(-)

diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 67d010994..31f62f99d 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -26,11 +26,11 @@ SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt5Xml_EXECUTABLE_COMPILE_FLAGS} ${Qt5
 
 
 #sudo apt-get install libpappsomspp-dev
-FIND_PACKAGE( Pappsomspp REQUIRED )
-#SET (PAPPSOMSPP_DIR  "/home/olivier/eclipse/git/pappsomspp")
+#FIND_PACKAGE( Pappsomspp REQUIRED )
+SET (PAPPSOMSPP_DIR  "/home/olivier/eclipse/git/pappsomspp")
 # SET (PAPPSOMSPP_DIR  "/home/langella/developpement/git/pappsomspp")
-# SET (PAPPSOMSPP_INCLUDE_DIR "${PAPPSOMSPP_DIR}/src")
-# SET (PAPPSOMSPP_QT4_LIBRARY "${PAPPSOMSPP_DIR}/build/src/libpappsomspp-qt4.so")
+ SET (PAPPSOMSPP_INCLUDE_DIR "${PAPPSOMSPP_DIR}/src")
+ SET (PAPPSOMSPP_QT4_LIBRARY "${PAPPSOMSPP_DIR}/build/src/libpappsomspp-qt4.so")
 
 INCLUDE_DIRECTORIES( ${PAPPSOMSPP_INCLUDE_DIR} )
 
diff --git a/src/core/project.cpp b/src/core/project.cpp
index 4f51f107c..2d848022c 100644
--- a/src/core/project.cpp
+++ b/src/core/project.cpp
@@ -39,9 +39,9 @@ ProjectSp Project::makeProjectSp() const {
 
 
 void Project::readXpipFile(QFileInfo xpip_fileinfo) {
-    
-    
-    XpipSaxHandler * parser = new XpipSaxHandler();
+
+
+    XpipSaxHandler * parser = new XpipSaxHandler(this);
 
     QXmlSimpleReader simplereader;
     simplereader.setContentHandler(parser);
@@ -61,18 +61,22 @@ void Project::readXpipFile(QFileInfo xpip_fileinfo) {
     }
     qfile.close();
 
-/*
-    GrpGroupingMonitor monitor;
-    GrpExperiment grpExperiment(monitor);
-    PeptideReader peptideReader(grpExperiment);
-    FastaReader reader(peptideReader);
-    reader.parse(&fastaFile);
-    fastaFile.close();
-    grpExperiment.startGrouping();
+    /*
+        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);
+        */
+
+}
 
-    std::list<GrpProteinSp> protein_list;
-    grpExperiment.getGroupedProteinSpList(protein_list);
-    */
 
+void Project::addProteinSp(pappso::ProteinSp makeProteinSp) {
 }
diff --git a/src/core/project.h b/src/core/project.h
index d5d72c686..49338ace7 100644
--- a/src/core/project.h
+++ b/src/core/project.h
@@ -26,6 +26,7 @@
 #include<memory>
 #include <pappsomspp/grouping/grpexperiment.h>
 #include <QFileInfo>
+#include <pappsomspp/protein/protein.h>
 
 class Project;
 typedef std::shared_ptr<Project> ProjectSp;
@@ -38,6 +39,7 @@ public:
     
     ProjectSp makeProjectSp() const;
     void readXpipFile(QFileInfo xpip_source);
+    void addProteinSp(pappso::ProteinSp makeProteinSp);
     
     pappso::GrpExperiment * _p_grp_experiment= nullptr; 
 };
diff --git a/src/input/xpipsaxhandler.cpp b/src/input/xpipsaxhandler.cpp
index 804b5a009..38d82c6d3 100644
--- a/src/input/xpipsaxhandler.cpp
+++ b/src/input/xpipsaxhandler.cpp
@@ -22,7 +22,7 @@
 
 #include "xpipsaxhandler.h"
 
-XpipSaxHandler::XpipSaxHandler()
+XpipSaxHandler::XpipSaxHandler(Project * p_project):_p_project(p_project)
 {
 
 }
@@ -89,15 +89,36 @@ bool XpipSaxHandler::endElement(const QString & namespaceURI, const QString & lo
 }
 
 /*
-bool XpipSaxHandler::endElement_group() {
-    if ((_tag_stack.size() > 1) && (_tag_stack[_tag_stack.size() - 2] == "group")) {
+ * <protein peptide_number="268" evalue="-432.77353" URL="Genome_Z_mays_5a.fasta" description="GRMZM2G083841_P01 P04711 Phosphoenolpyruvate carboxylase 1 (PEPCase 1)(PEPC 1)(EC 4.1.1.31) seq=translation; coord=9:61296279..61301686:1; parent_transcript=GRMZM2G083841_T01; parent_gene=GRMZM2G083841">
+            <protein_evalue evalue="-399.36093" sample="20120906_balliau_extract_1_A02_urzb-1"/>
+            <protein_evalue evalue="-384.54382" sample="20120906_balliau_extract_1_A01_urnb-1"/>
+            <sequence>MASTKAPGPGEKHHSIDAQLRQLVPGKVSEDDKLIEYDALLVDRFLNILQDLHGPSLREFVQECYEVSADYEGKGDTTKLGELGAKLTGLAPADAILVASSILHMLNLANLAEEVQIAHRRRNSKLKKGGFADEGSATTESDIEETLKRLVSEVGKSPEEVFEALKNQTVDLVFTAHPTQSARRSLLQKNARIRNCLTQLNAKDITDDDKQELDEALQREIQAAFRTDEIRRAQPTPQDEMRYGMSYIHETVWKGVPKFLRRVDTALKNIGINERLPYNVSLIRFSSWMGGDRDGNPRVTPEVTRDVCLLARMMAANLYIDQIEELMFELSMWRCNDELRVRAEELHSSSGSKVTKYYIEFWKQIPPNEPYRVILGHVRDKLYNTRERARHLLASGVSEISAESSFTSIEEFLEPLELCYKSLCDCGDKAIADGSLLDLLRQVFTFGLSLVKLDIRQESERHTDVIDAITTHLGIGSYREWPEDKRQEWLLSELRGKRPLLPPDLPQTDEIADVIGAFHVLAELPPDSFGPYIISMATAPSDVLAVELLQRECGVRQPLPVVPLFERLADLQSAPASVERLFSVDWYMDRIKGKQQVMVGYSDSGKDAGRLSAAWQLYRAQEEMAQVAKRYGVKLTLFHGRGGTVGRGGGPTHLAILSQPPDTINGSIRVTVQGEVIEFCFGEEHLCFQTLQRFTAATLEHGMHPPVSPKPEWRKLMDEMAVVATEEYRSVVVKEARFVEYFRSATPETEYGRMNIGSRPAKRRPGGGITTLRAIPWIFSWTQTRFHLPVWLGVGAAFKFAIDKDVRNFQVLKEMYNEWPFFRVTLDLLEMVFAKGDPGIAGLYDELLVAEELKPFGKQLRDKYVETQQLLLQIAGHKDILEGDPFLKQGLVLRNPYITTLNVFQAYTLKRIRDPNFKVTPQPPLSKEFADENKPAGLVKLNPASEYPPGLEDTLILTMKGIAAGMQNTG</sequence>
+          </protein>
+          */
+
+bool XpipSaxHandler::startElement_protein(QXmlAttributes attributes) {
+
+    qDebug() << "startElement_protein ";
+    _current_protein.setDescription(attributes.value("description").simplified());
+    _current_protein.setAccession(_current_protein.getDescription().split(" ").at(0));
+    qDebug() << "startElement_protein end" ;
+    return true;
+}
+
+bool XpipSaxHandler::endElement_sequence() {
+    if ((_tag_stack.size() > 1) && (_tag_stack[_tag_stack.size() - 1] == "protein")) {
+      _current_protein.setSequence(_current_text);
     }
     else {
         // XtandemHyperscore hyperscore(_curent_spectrum, _current_peptide_sp, _precision, _ion_list, _max_charge,_refine_spectrum_synthesis);
     }
     return true;
 }
-*/
+bool XpipSaxHandler::endElement_protein() {
+    _p_project->addProteinSp(_current_protein.makeProteinSp());
+    return true;
+}
+
 
 
 bool XpipSaxHandler::error(const QXmlParseException &exception) {
diff --git a/src/input/xpipsaxhandler.h b/src/input/xpipsaxhandler.h
index 55ca5e4cb..860584e06 100644
--- a/src/input/xpipsaxhandler.h
+++ b/src/input/xpipsaxhandler.h
@@ -25,13 +25,15 @@
 
 #include <QXmlDefaultHandler>
 #include <pappsomspp/pappsoexception.h>
+#include <pappsomspp/protein/protein.h>
+#include "../core/project.h"
 
 using namespace pappso;
 
 class XpipSaxHandler: public QXmlDefaultHandler
 {
 public:
-    XpipSaxHandler();
+    XpipSaxHandler(Project * p_project);
     ~XpipSaxHandler();
 
     bool startElement(const QString & namespaceURI, const QString & localName,
@@ -51,10 +53,19 @@ public:
 
     QString errorString() const;
 
+    
+private:
+  bool startElement_protein(QXmlAttributes attributes);
+  bool endElement_sequence();
+  bool endElement_protein();
+
 private:
     std::vector<QString> _tag_stack;
     QString _errorStr;
     QString _current_text;
+    
+    Project * _p_project;
+    Protein _current_protein;
 };
 
 #endif // XTANDEMRESULTSHANDLER_H
-- 
GitLab