From ffe4369166c84682f344a63e1a7171680befb7d6 Mon Sep 17 00:00:00 2001
From: Olivier Langella <olivier.langella@u-psud.fr>
Date: Mon, 6 Nov 2017 21:53:01 +0100
Subject: [PATCH] fastafile object has an xml id

---
 src/core/project.cpp         |  4 ++++
 src/core/project.h           |  1 +
 src/files/fastafile.cpp      | 12 ++++++++----
 src/files/fastafile.h        |  5 +++++
 src/output/ods/infosheet.cpp | 17 +++++++++--------
 src/output/xpip.cpp          |  2 +-
 src/utils/fastafilestore.cpp | 11 +++++++----
 src/utils/proteinstore.cpp   | 20 ++++++++++----------
 src/utils/proteinstore.h     | 12 ++++++------
 9 files changed, 51 insertions(+), 33 deletions(-)

diff --git a/src/core/project.cpp b/src/core/project.cpp
index 834e30e3..4a370017 100644
--- a/src/core/project.cpp
+++ b/src/core/project.cpp
@@ -70,6 +70,10 @@ const GroupingType Project::getGroupingType() const {
 FastaFileStore & Project::getFastaFileStore() {
     return _fasta_file_store;
 }
+
+const FastaFileStore & Project::getFastaFileStore() const {
+    return _fasta_file_store;
+}
 MsRunStore & Project::getMsRunStore() {
     return _msrun_store;
 }
diff --git a/src/core/project.h b/src/core/project.h
index 78c0067a..b7cbebe5 100644
--- a/src/core/project.h
+++ b/src/core/project.h
@@ -53,6 +53,7 @@ public:
     MsRunStore & getMsRunStore();
     const MsRunStore & getMsRunStore() const;
     FastaFileStore & getFastaFileStore();
+    const FastaFileStore & getFastaFileStore() const;
     IdentificationDataSourceStore & getIdentificationDataSourceStore();
     const IdentificationDataSourceStore & getIdentificationDataSourceStore() const;
     void readXpipFile(WorkMonitorInterface * p_monitor, QFileInfo xpip_source);
diff --git a/src/files/fastafile.cpp b/src/files/fastafile.cpp
index e075c7ab..a4bbdef0 100644
--- a/src/files/fastafile.cpp
+++ b/src/files/fastafile.cpp
@@ -76,6 +76,12 @@ FastaFile::~FastaFile()
 
 }
 
+void FastaFile::setXmlId(const QString xmlid) {
+    _xml_id = xmlid;
+}
+const QString & FastaFile::getXmlId() const {
+    return _xml_id;
+}
 const QString FastaFile::getFilename() const {
     return _fasta_source.fileName();
 }
@@ -84,7 +90,7 @@ const QString FastaFile::getAbsoluteFilePath() const {
     return _fasta_source.absoluteFilePath();
 }
 void FastaFile::setContaminants(ProteinStore & protein_store) const {
-
+    protein_store.addContaminantFastaFile(this);
     if (_fasta_source.exists()) {
         AccessionContaminantReader accession_reader(protein_store);
         pappso::FastaReader reader(accession_reader);
@@ -92,7 +98,6 @@ void FastaFile::setContaminants(ProteinStore & protein_store) const {
         if (fasta_file.open(QIODevice::ReadOnly)) {
             reader.parse(&fasta_file);
             fasta_file.close();
-            protein_store.addContaminantFastaFile(*this);
         }
         else {
             qDebug() << "FastaFile::setContaminants "<< _fasta_source.absoluteFilePath() << " not open";
@@ -106,7 +111,7 @@ void FastaFile::setContaminants(ProteinStore & protein_store) const {
 }
 
 void FastaFile::setDecoys(ProteinStore & protein_store) const {
-
+    protein_store.addDecoyFastaFile(this);
     if (_fasta_source.exists()) {
         AccessionDecoyReader accession_reader(protein_store);
         pappso::FastaReader reader(accession_reader);
@@ -114,7 +119,6 @@ void FastaFile::setDecoys(ProteinStore & protein_store) const {
         if (fasta_file.open(QIODevice::ReadOnly)) {
             reader.parse(&fasta_file);
             fasta_file.close();
-            protein_store.addDecoyFastaFile(*this);
         }
         else {
             qDebug() << "FastaFile::setDecoys "<< _fasta_source.absoluteFilePath() << " not open";
diff --git a/src/files/fastafile.h b/src/files/fastafile.h
index 243f9dcb..59213a2f 100644
--- a/src/files/fastafile.h
+++ b/src/files/fastafile.h
@@ -50,9 +50,14 @@ public:
     /** @brief read fasta file and set accessions as decoys
      * */
     void setDecoys(ProteinStore & protein_store) const;
+    
+    
+    void setXmlId(const QString xmlid);
+    const QString & getXmlId() const;
 
 private :
     const QFileInfo _fasta_source;
+    QString _xml_id;
 
 };
 
diff --git a/src/output/ods/infosheet.cpp b/src/output/ods/infosheet.cpp
index ce22bd2c..ff5761fa 100644
--- a/src/output/ods/infosheet.cpp
+++ b/src/output/ods/infosheet.cpp
@@ -72,30 +72,31 @@ InfoSheet::InfoSheet (OdsExport * p_ods_export, CalcWriterInterface * p_writer,
     p_writer->writeLine();
     p_writer->writeLine();
 
-    std::vector<FastaFile> conta_file_list = p_project->getProteinStore().getContaminantFastaFileList();
+    std::vector<const FastaFile *> conta_file_list = p_project->getProteinStore().getContaminantFastaFileList();
     if (conta_file_list.size() == 0) {
         p_writer->writeCell("contaminant pattern");
         p_writer->writeCell(p_project->getProteinStore().getRegexpContaminant().pattern());
     }
     else {
         p_writer->writeCell("contaminant fasta files");
-        for (FastaFile & fasta_file : conta_file_list) {
-            p_writer->writeCell(fasta_file.getAbsoluteFilePath());
+        for (const FastaFile * fasta_file : conta_file_list) {
+            p_writer->writeCell(fasta_file->getAbsoluteFilePath());
         }
-
     }
-    std::vector<FastaFile> decoy_file_list = p_project->getProteinStore().getDecoyFastaFileList();
+    p_writer->writeLine();
+    
+    std::vector<const FastaFile *> decoy_file_list = p_project->getProteinStore().getDecoyFastaFileList();
     if (conta_file_list.size() == 0) {
         p_writer->writeCell("decoy pattern");
         p_writer->writeCell(p_project->getProteinStore().getRegexpDecoy().pattern());
     }
     else {
         p_writer->writeCell("decoy fasta files");
-        for (FastaFile & fasta_file : decoy_file_list) {
-            p_writer->writeCell(fasta_file.getAbsoluteFilePath());
+        for (const FastaFile * fasta_file : decoy_file_list) {
+            p_writer->writeCell(fasta_file->getAbsoluteFilePath());
         }
-
     }
+    p_writer->writeLine();
 
 }
 
diff --git a/src/output/xpip.cpp b/src/output/xpip.cpp
index 733b6556..16a9e64d 100644
--- a/src/output/xpip.cpp
+++ b/src/output/xpip.cpp
@@ -189,7 +189,7 @@ void Xpip::writeMsrunList(const MsRunStore & msrun_store) {
         _output_stream->writeStartElement("fasta_file_list");
     for (FastaFileSp fasta_file_sp : fasta_store.getFastaFileList()) {
         _output_stream->writeStartElement("fasta_file");
-        //_output_stream->writeAttribute("id",fasta_file_sp.get()->getXmlId());
+        _output_stream->writeAttribute("id",fasta_file_sp.get()->getXmlId());
         _output_stream->writeAttribute("path",fasta_file_sp.get()->getAbsoluteFilePath());
 
         _output_stream->writeEndElement();
diff --git a/src/utils/fastafilestore.cpp b/src/utils/fastafilestore.cpp
index ddafcd3c..617b2998 100644
--- a/src/utils/fastafilestore.cpp
+++ b/src/utils/fastafilestore.cpp
@@ -29,6 +29,7 @@
 ******************************************************************************/
 
 #include "fastafilestore.h"
+#include <pappsomspp/utils.h>
 #include <QDebug>
 FastaFileStore::FastaFileStore()
 {
@@ -41,19 +42,21 @@ FastaFileStore::~FastaFileStore()
 }
 
 FastaFileSp FastaFileStore::getInstance(const FastaFile & location) {
-qDebug() << "FastaFileStore::getInstance() begin ";
-qDebug() << "FastaFileStore::getInstance() begin "<< location.getAbsoluteFilePath();
+    qDebug() << "FastaFileStore::getInstance() begin ";
+    qDebug() << "FastaFileStore::getInstance() begin "<< location.getAbsoluteFilePath();
     std::vector<FastaFileSp>::iterator it = _map_fastafile.begin();
     std::vector<FastaFileSp>::iterator itend = _map_fastafile.end();
     while (it != itend) {
         if (it->get()->getFilename() == location.getFilename()) {
-            
-qDebug() << "FastaFileStore::getInstance() end b "<< it->get()->getFilename();
+
+            qDebug() << "FastaFileStore::getInstance() end b "<< it->get()->getFilename();
             return *it;
         }
         it++;
     }
     FastaFileSp fastafile_sp = std::make_shared<FastaFile>(location);
+
+    fastafile_sp.get()->setXmlId(QString("fasta%1").arg(pappso::Utils::getLexicalOrderedString(_map_fastafile.size())));
     _map_fastafile.push_back(fastafile_sp);
     qDebug() << "FastaFileStore::getFastaFileList() end a "  << _map_fastafile.size();
     return fastafile_sp;
diff --git a/src/utils/proteinstore.cpp b/src/utils/proteinstore.cpp
index 733835e0..7a864097 100644
--- a/src/utils/proteinstore.cpp
+++ b/src/utils/proteinstore.cpp
@@ -48,12 +48,12 @@ ProteinStore::~ProteinStore()
 
 }
 
-    const std::vector<FastaFile> & ProteinStore::getContaminantFastaFileList() const {
-        return _fasta_contaminant_list;
-    }
-    const std::vector<FastaFile> & ProteinStore::getDecoyFastaFileList() const {
-        return _fasta_decoy_list;
-    }
+const std::vector<const FastaFile *> & ProteinStore::getContaminantFastaFileList() const {
+    return _fasta_contaminant_list;
+}
+const std::vector<const FastaFile *> & ProteinStore::getDecoyFastaFileList() const {
+    return _fasta_decoy_list;
+}
 QRegExp ProteinStore::getRegexpContaminant() const {
     return (_regexp_contaminant);
 }
@@ -93,11 +93,11 @@ void ProteinStore::clearContaminants() {
     }
 }
 
-void ProteinStore::addContaminantFastaFile(const FastaFile & fasta_file) {
-    _fasta_contaminant_list.push_back(fasta_file);
+void ProteinStore::addContaminantFastaFile(const FastaFile * p_fasta_file) {
+    _fasta_contaminant_list.push_back(p_fasta_file);
 }
-void ProteinStore::addDecoyFastaFile(const FastaFile & fasta_file) {
-    _fasta_decoy_list.push_back(fasta_file);
+void ProteinStore::addDecoyFastaFile(const FastaFile * p_fasta_file) {
+    _fasta_decoy_list.push_back(p_fasta_file);
 }
 
 
diff --git a/src/utils/proteinstore.h b/src/utils/proteinstore.h
index 454904b4..fa06e130 100644
--- a/src/utils/proteinstore.h
+++ b/src/utils/proteinstore.h
@@ -57,11 +57,11 @@ public:
     
     QRegExp getRegexpContaminant() const;
     
-    void addContaminantFastaFile(const FastaFile & fasta_file);
-    void addDecoyFastaFile(const FastaFile & fasta_file);
+    void addContaminantFastaFile(const FastaFile * p_fasta_file);
+    void addDecoyFastaFile(const FastaFile * p_fasta_file);
     
-    const std::vector<FastaFile> & getContaminantFastaFileList() const;
-    const std::vector<FastaFile> & getDecoyFastaFileList() const;
+    const std::vector<const FastaFile *> & getContaminantFastaFileList() const;
+    const std::vector<const FastaFile *> & getDecoyFastaFileList() const;
     
     
     void clearContaminants();
@@ -77,9 +77,9 @@ private :
     std::map<QString, ProteinXtpSp> _map_accession_protein_list;
     
     /** \brief decoy Fasta file liste */
-    std::vector<FastaFile> _fasta_decoy_list;
+    std::vector<const FastaFile *> _fasta_decoy_list;
     /** \brief contaminant Fasta file liste */
-    std::vector<FastaFile> _fasta_contaminant_list;
+    std::vector<const FastaFile *> _fasta_contaminant_list;
     
     /** \brief recognize decoy accession */
     QRegExp _regexp_decoy;
-- 
GitLab