From 1dd2746f2037a2db1f8f3a573cbfc28bd2b1398f Mon Sep 17 00:00:00 2001
From: Olivier Langella <olivier.langella@u-psud.fr>
Date: Mon, 6 Nov 2017 16:29:30 +0100
Subject: [PATCH] handle decoy and contaminant filter status, more information
 in ODS output

---
 src/core/project.cpp         |  4 ++++
 src/core/project.h           |  1 +
 src/files/fastafile.cpp      |  2 ++
 src/output/ods/infosheet.cpp | 30 ++++++++++++++++++++++++++++++
 src/utils/proteinstore.cpp   | 18 ++++++++++++++++++
 src/utils/proteinstore.h     | 16 ++++++++++++++++
 6 files changed, 71 insertions(+)

diff --git a/src/core/project.cpp b/src/core/project.cpp
index 743a3ceb5..834e30e30 100644
--- a/src/core/project.cpp
+++ b/src/core/project.cpp
@@ -84,6 +84,10 @@ ProteinStore & Project::getProteinStore() {
     return _protein_store;
 }
 
+const ProteinStore & Project::getProteinStore() const {
+    return _protein_store;
+}
+
 IdentificationDataSourceStore & Project::getIdentificationDataSourceStore() {
     return _identification_data_source_store;
 }
diff --git a/src/core/project.h b/src/core/project.h
index 52c8077be..78c0067a5 100644
--- a/src/core/project.h
+++ b/src/core/project.h
@@ -49,6 +49,7 @@ public:
     ProjectSp makeProjectSp() const;
     ProteinStore & getProteinStore();
     PeptideStore & getPeptideStore();
+    const ProteinStore & getProteinStore() const;
     MsRunStore & getMsRunStore();
     const MsRunStore & getMsRunStore() const;
     FastaFileStore & getFastaFileStore();
diff --git a/src/files/fastafile.cpp b/src/files/fastafile.cpp
index f4eb6876d..e075c7ab0 100644
--- a/src/files/fastafile.cpp
+++ b/src/files/fastafile.cpp
@@ -92,6 +92,7 @@ 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";
@@ -113,6 +114,7 @@ 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/output/ods/infosheet.cpp b/src/output/ods/infosheet.cpp
index 038e9b62a..ce22bd2c2 100644
--- a/src/output/ods/infosheet.cpp
+++ b/src/output/ods/infosheet.cpp
@@ -67,5 +67,35 @@ InfoSheet::InfoSheet (OdsExport * p_ods_export, CalcWriterInterface * p_writer,
     p_writer->writeCell("Maximum protein Evalue");
     p_writer->writeCell(filter_param.getFilterProteinEvalue());
     p_writer->writeLine();
+
+
+    p_writer->writeLine();
+    p_writer->writeLine();
+
+    std::vector<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());
+        }
+
+    }
+    std::vector<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());
+        }
+
+    }
+
 }
 
diff --git a/src/utils/proteinstore.cpp b/src/utils/proteinstore.cpp
index 6a6a9666c..733835e0c 100644
--- a/src/utils/proteinstore.cpp
+++ b/src/utils/proteinstore.cpp
@@ -28,6 +28,7 @@
 ******************************************************************************/
 
 #include "proteinstore.h"
+#include "../files/fastafile.h"
 #include <QDebug>
 #include <QSettings>
 
@@ -46,6 +47,13 @@ ProteinStore::~ProteinStore()
 {
 
 }
+
+    const std::vector<FastaFile> & ProteinStore::getContaminantFastaFileList() const {
+        return _fasta_contaminant_list;
+    }
+    const std::vector<FastaFile> & ProteinStore::getDecoyFastaFileList() const {
+        return _fasta_decoy_list;
+    }
 QRegExp ProteinStore::getRegexpContaminant() const {
     return (_regexp_contaminant);
 }
@@ -73,16 +81,26 @@ void ProteinStore::setRegexpDecoyPattern(const QString & pattern) {
 }
 
 void ProteinStore::clearDecoys() {
+    _fasta_decoy_list.clear();
     for  (std::pair<const QString, ProteinXtpSp> & acc_protein :_map_accession_protein_list) {
         acc_protein.second.get()->setIsDecoy(false);
     }
 }
 void ProteinStore::clearContaminants() {
+    _fasta_contaminant_list.clear();
     for  (std::pair<const QString, ProteinXtpSp> & acc_protein :_map_accession_protein_list) {
         acc_protein.second.get()->setIsContaminant(false);
     }
 }
 
+void ProteinStore::addContaminantFastaFile(const FastaFile & fasta_file) {
+    _fasta_contaminant_list.push_back(fasta_file);
+}
+void ProteinStore::addDecoyFastaFile(const FastaFile & fasta_file) {
+    _fasta_decoy_list.push_back(fasta_file);
+}
+
+
 void ProteinStore::setDecoyAccession(QString accession) {
     std::map<QString, ProteinXtpSp>::iterator it =  _map_accession_protein_list.find(accession);
     if (it != _map_accession_protein_list.end()) {
diff --git a/src/utils/proteinstore.h b/src/utils/proteinstore.h
index f0c50fb82..454904b4e 100644
--- a/src/utils/proteinstore.h
+++ b/src/utils/proteinstore.h
@@ -37,6 +37,9 @@
 #include <QString>
 #include <QRegExp>
 #include <map>
+#include <vector>
+
+class FastaFile;
 
 class ProteinStore
 {
@@ -54,6 +57,13 @@ public:
     
     QRegExp getRegexpContaminant() const;
     
+    void addContaminantFastaFile(const FastaFile & fasta_file);
+    void addDecoyFastaFile(const FastaFile & fasta_file);
+    
+    const std::vector<FastaFile> & getContaminantFastaFileList() const;
+    const std::vector<FastaFile> & getDecoyFastaFileList() const;
+    
+    
     void clearContaminants();
     void clearDecoys();
     
@@ -65,6 +75,12 @@ private :
 private :
   
     std::map<QString, ProteinXtpSp> _map_accession_protein_list;
+    
+    /** \brief decoy Fasta file liste */
+    std::vector<FastaFile> _fasta_decoy_list;
+    /** \brief contaminant Fasta file liste */
+    std::vector<FastaFile> _fasta_contaminant_list;
+    
     /** \brief recognize decoy accession */
     QRegExp _regexp_decoy;
     /** \brief recognize contaminant accession */
-- 
GitLab