From 7c319cbbd289c3f1798f33bcbddd725a25ca3268 Mon Sep 17 00:00:00 2001
From: Olivier Langella <Olivier.Langella@moulon.inra.fr>
Date: Sun, 23 Apr 2017 00:09:57 +0200
Subject: [PATCH] problem with fastafile

---
 src/CMakeLists.txt                            |  3 +-
 .../identificationdatasource.cpp              |  8 ++-
 .../identificationdatasource.h                |  7 ++-
 src/core/project.h                            |  1 +
 src/files/fastafile.cpp                       | 18 ++++--
 src/files/fastafile.h                         | 13 +++-
 .../choosemodificationdialog.cpp              | 48 +++++++-------
 src/gui/project_view/project_view.ui          | 25 +++++++-
 src/gui/project_view/projectwindow.cpp        | 23 +++++--
 src/gui/project_view/projectwindow.h          |  4 ++
 src/utils/fastafilestore.cpp                  | 63 +++++++++++++++++++
 src/utils/fastafilestore.h                    | 52 +++++++++++++++
 src/utils/identificationdatasourcestore.cpp   | 17 ++++-
 src/utils/identificationdatasourcestore.h     |  4 ++
 14 files changed, 243 insertions(+), 43 deletions(-)
 create mode 100644 src/utils/fastafilestore.cpp
 create mode 100644 src/utils/fastafilestore.h

diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index b18681860..885ed02d1 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -72,6 +72,7 @@ SET(CPP_FILES
   output/masschroqml.cpp
   output/ods/odsexport.cpp
   output/ods/simplesheet.cpp
+  utils/fastafilestore.cpp
   utils/identificationdatasourcestore.cpp
   utils/groupstore.cpp
   utils/msrunstore.cpp
@@ -109,7 +110,7 @@ SET(XTPCPP_SRCS
 )
 
 SET (GUI_UIS
-  ./gui/choose_modification_dialog/choose_modification_dialog.uicpp
+  ./gui/choose_modification_dialog/choose_modification_dialog.ui
   ./gui/edit_label_methods/edit_label_methods.ui
   ./gui/edit_modifications/edit_modifications.ui
   ./gui/export_spreadsheet_dialog/export_spreadsheet_dialog.ui
diff --git a/src/core/identification_sources/identificationdatasource.cpp b/src/core/identification_sources/identificationdatasource.cpp
index dd06ce03a..4e377f01d 100644
--- a/src/core/identification_sources/identificationdatasource.cpp
+++ b/src/core/identification_sources/identificationdatasource.cpp
@@ -26,6 +26,8 @@
 #include <QFileInfo>
 #include "../../utils/readspectrum.h"
 
+FastaFileStore IdentificationDataSource::_fasta_file_store;
+
 IdentificationDataSource::IdentificationDataSource(const QString resource_name)
 {
     _resource_name = resource_name;
@@ -82,5 +84,9 @@ pappso::SpectrumSp IdentificationDataSource::getSpectrumSp(unsigned int scan_num
 }
 
 void IdentificationDataSource::addFastaFile (FastaFile file) {
-    _fastafile_list.push_back(file);
+    _fastafile_list.push_back(IdentificationDataSource::_fasta_file_store.getInstance(file));
+}
+const std::vector<FastaFileSp> & IdentificationDataSource::getFastaFileList() const {
+    qDebug()<<  "IdentificationDataSource::getFastaFileList begin" << _fastafile_list.size();
+    return _fastafile_list;
 }
diff --git a/src/core/identification_sources/identificationdatasource.h b/src/core/identification_sources/identificationdatasource.h
index 3d4b51f2b..f5a7d0e88 100644
--- a/src/core/identification_sources/identificationdatasource.h
+++ b/src/core/identification_sources/identificationdatasource.h
@@ -27,7 +27,7 @@
 #include <pappsomspp/spectrum/spectrum.h>
 #include <memory>
 #include "../msrun.h"
-#include "../../files/fastafile.h"
+#include "../../utils/fastafilestore.h"
 
 class Project;
 
@@ -74,16 +74,19 @@ public:
     /** \brief add Fastafile used by the identification engine
      */
     void addFastaFile (FastaFile file);
+    
+    const std::vector<FastaFileSp> & getFastaFileList() const;
 
 protected :
     QString _resource_name;
     IdentificationEngine _engine = IdentificationEngine::unknown;
 private :
     //static std::map<QString, pappso::MsRunIdSp> _map_msrunidsp;
+    static FastaFileStore _fasta_file_store;
     QString _version;
     MsRunSp _ms_run_sp = nullptr;
     std::map<IdentificationEngineParam, QString> _params;
-    std::vector<FastaFile> _fastafile_list;
+    std::vector<FastaFileSp> _fastafile_list;
 };
 
 #endif // IDENTIFICATIONDATASOURCE_H
diff --git a/src/core/project.h b/src/core/project.h
index 544de7dc9..5f454f404 100644
--- a/src/core/project.h
+++ b/src/core/project.h
@@ -83,6 +83,7 @@ private :
     PeptideStore _peptide_store;
     IdentificationDataSourceStore _identification_data_source_store;
     MsRunStore _msrun_store;
+    
 };
 
 #endif // PROJECT_H
diff --git a/src/files/fastafile.cpp b/src/files/fastafile.cpp
index 26d4c8358..aa6694508 100644
--- a/src/files/fastafile.cpp
+++ b/src/files/fastafile.cpp
@@ -26,11 +26,6 @@
 FastaFile::FastaFile(const QString & fasta_source) : _fasta_source(fasta_source)
 {
 
-}
-
-FastaFile::FastaFile(const QUrl & fasta_source) : _fasta_source(fasta_source)
-{
-
 }
 FastaFile::FastaFile(const QFileInfo & fasta_source): _fasta_source(fasta_source.absoluteFilePath())
 {
@@ -43,3 +38,16 @@ FastaFile::~FastaFile()
 {
 
 }
+
+bool FastaFile::operator<( const FastaFile& other ) const
+{
+    return (_fasta_source.absoluteFilePath() < other._fasta_source.absoluteFilePath());
+}
+bool FastaFile::operator==( const FastaFile& other ) const
+{
+    return (_fasta_source == other._fasta_source);
+}
+
+const QString FastaFile::getFilename() const {
+    return _fasta_source.fileName();
+}
diff --git a/src/files/fastafile.h b/src/files/fastafile.h
index 3e3c90a39..263bf587d 100644
--- a/src/files/fastafile.h
+++ b/src/files/fastafile.h
@@ -24,19 +24,26 @@
 #ifndef FASTAFILE_H
 #define FASTAFILE_H
 
-#include <QUrl>
 #include <QFileInfo>
+#include <memory>
+
+class FastaFile;
+typedef std::shared_ptr<FastaFile> FastaFileSp;
+
 class FastaFile
 {
 public:
     FastaFile(const QString & fasta_source);
-    FastaFile(const QUrl & fasta_source);
     FastaFile(const QFileInfo & fasta_source);
     FastaFile(const FastaFile & other);
     ~FastaFile();
 
+    bool operator<( const FastaFile& other ) const;
+    bool operator==( const FastaFile& other ) const;
+    
+    const QString getFilename() const;
 private :
-    const QUrl _fasta_source;
+    const QFileInfo _fasta_source;
 
 };
 
diff --git a/src/gui/choose_modification_dialog/choosemodificationdialog.cpp b/src/gui/choose_modification_dialog/choosemodificationdialog.cpp
index fc0c9bc5a..e8a889206 100644
--- a/src/gui/choose_modification_dialog/choosemodificationdialog.cpp
+++ b/src/gui/choose_modification_dialog/choosemodificationdialog.cpp
@@ -44,7 +44,7 @@ ChooseModificationDialog::ChooseModificationDialog(QWidget * parent):
     _p_modification_str_li = new QStandardItemModel();
     ui->modification_listview->setModel(_p_modification_str_li);
     //param.setFilterCrossSamplePeptideNumber(settings.value("automatic_filter/cross_sample", "true").toBool());
-    
+
 #if QT_VERSION >= 0x050000
     // Qt5 code
     /*
@@ -68,27 +68,27 @@ ChooseModificationDialog::~ChooseModificationDialog()
 }
 
 void ChooseModificationDialog::setMassRange(const pappso::MassRange & massrange) {
-    
-            qDebug() << "ChooseModificationDialog::setMassRange " << massrange.toString();
-            _selected_modification = nullptr;
+
+    qDebug() << "ChooseModificationDialog::setMassRange " << massrange.toString();
+    _selected_modification = nullptr;
     _p_modification_str_li->removeRows(0,_p_modification_str_li->rowCount());
-        pappso::FilterOboPsiModSink term_list;
-
-        pappso::OboPsiModHandlerInterface * last_men_standing = &term_list;
-        pappso::FilterOboPsiModTermDiffMono * p_filter_mass = nullptr;
-        //FilterOboPsiModTermLabel * p_filter_label = nullptr;
-	//FilterOboPsiModTermName * p_filter_name = nullptr;
-
-            p_filter_mass = new pappso::FilterOboPsiModTermDiffMono(*last_men_standing, massrange);
-            pappso::OboPsiMod psimodb(*p_filter_mass);
-        for (pappso::OboPsiModTerm term : term_list.getOboPsiModTermList() ) {
-            
-            QStandardItem *item;
-            item = new QStandardItem(QString("[%1] %2").arg(term._accession).arg(term._name));
-            item->setEditable(false);
-            _p_modification_str_li->appendRow(item);
-            item->setData(QVariant(QString("%1").arg(term._accession)),Qt::UserRole);
-        }
+    pappso::FilterOboPsiModSink term_list;
+
+    pappso::OboPsiModHandlerInterface * last_men_standing = &term_list;
+    pappso::FilterOboPsiModTermDiffMono * p_filter_mass = nullptr;
+    //FilterOboPsiModTermLabel * p_filter_label = nullptr;
+    //FilterOboPsiModTermName * p_filter_name = nullptr;
+
+    p_filter_mass = new pappso::FilterOboPsiModTermDiffMono(*last_men_standing, massrange);
+    pappso::OboPsiMod psimodb(*p_filter_mass);
+    for (pappso::OboPsiModTerm term : term_list.getOboPsiModTermList() ) {
+
+        QStandardItem *item;
+        item = new QStandardItem(QString("[%1] %2").arg(term._accession).arg(term._name));
+        item->setEditable(false);
+        _p_modification_str_li->appendRow(item);
+        item->setData(QVariant(QString("%1").arg(term._accession)),Qt::UserRole);
+    }
 }
 
 
@@ -108,6 +108,6 @@ void ChooseModificationDialog::ItemClicked (QModelIndex index )
     _selected_modification = modification;
 }
 
- pappso::AaModificationP ChooseModificationDialog::getSelectedModification()const {
-        return _selected_modification;
-    }
+pappso::AaModificationP ChooseModificationDialog::getSelectedModification()const {
+    return _selected_modification;
+}
diff --git a/src/gui/project_view/project_view.ui b/src/gui/project_view/project_view.ui
index bcff87cae..f45e0bde2 100644
--- a/src/gui/project_view/project_view.ui
+++ b/src/gui/project_view/project_view.ui
@@ -20,8 +20,11 @@
       <property name="enabled">
        <bool>true</bool>
       </property>
+      <property name="toolTip">
+       <string/>
+      </property>
       <property name="currentIndex">
-       <number>0</number>
+       <number>2</number>
       </property>
       <widget class="QWidget" name="identifications">
        <attribute name="title">
@@ -64,6 +67,9 @@
        </layout>
       </widget>
       <widget class="QWidget" name="fdr">
+       <property name="toolTip">
+        <string/>
+       </property>
        <attribute name="title">
         <string>FDR</string>
        </attribute>
@@ -72,6 +78,9 @@
          <layout class="QVBoxLayout" name="verticalLayout_2">
           <item>
            <widget class="QGroupBox" name="groupBox_3">
+            <property name="toolTip">
+             <string/>
+            </property>
             <property name="title">
              <string>FDR</string>
             </property>
@@ -85,6 +94,9 @@
              </item>
              <item row="0" column="1">
               <widget class="QLabel" name="peptide_fdr_label">
+               <property name="toolTip">
+                <string>FDR is computed using peptides tagged as &quot;decoy&quot; on all valid peptides (check filter parameters)</string>
+               </property>
                <property name="text">
                 <string>0 %</string>
                </property>
@@ -99,6 +111,9 @@
              </item>
              <item row="1" column="1">
               <widget class="QLabel" name="protein_fdr_label">
+               <property name="toolTip">
+                <string>FDR is computed using proteins tagged as &quot;decoy&quot; on all valid proteins (check filter parameters)</string>
+               </property>
                <property name="text">
                 <string>0 %</string>
                </property>
@@ -114,7 +129,7 @@
             </property>
             <layout class="QVBoxLayout" name="verticalLayout_3">
              <item>
-              <widget class="QListWidget" name="decoy_database_list_widget"/>
+              <widget class="QListView" name="decoy_database_listview"/>
              </item>
              <item>
               <layout class="QHBoxLayout" name="horizontalLayout">
@@ -188,6 +203,9 @@
        </layout>
       </widget>
       <widget class="QWidget" name="mass_precision">
+       <property name="toolTip">
+        <string/>
+       </property>
        <attribute name="title">
         <string>Mass precision</string>
        </attribute>
@@ -250,6 +268,9 @@
             </item>
             <item row="3" column="1">
              <widget class="QLabel" name="mass_precision_sd_label">
+              <property name="toolTip">
+               <string>Mass deviation is computed on all valid and checked proteins but not decoy</string>
+              </property>
               <property name="text">
                <string>0</string>
               </property>
diff --git a/src/gui/project_view/projectwindow.cpp b/src/gui/project_view/projectwindow.cpp
index 92fc2c536..48254de5c 100644
--- a/src/gui/project_view/projectwindow.cpp
+++ b/src/gui/project_view/projectwindow.cpp
@@ -43,6 +43,9 @@ ProjectWindow::ProjectWindow(MainWindow *parent):
     main_window = parent;
     ui->setupUi(this);
 
+    _p_fasta_str_li = new QStandardItemModel();
+    ui->decoy_database_listview->setModel(_p_fasta_str_li);
+
     _p_automatic_filter_widget = new AutomaticFilterWidget(this);
     ui->filter_parameter_layout->addWidget(_p_automatic_filter_widget);
 
@@ -206,7 +209,7 @@ void ProjectWindow::refresh() {
     computeFdr(ValidationState::valid);
     computeMassPrecision(ValidationState::validAndChecked);
     qDebug() << "ProjectWindow::refresh end ";
-    
+
 }
 void ProjectWindow::doAutomaticFilterParametersChanged(AutomaticFilterParameters parameters) {
     qDebug() << "ProjectWindow::doAutomaticFilterParametersChanged begin ";
@@ -341,7 +344,20 @@ void ProjectWindow::doViewProteinList(IdentificationGroup* p_identification_grou
 }
 
 void ProjectWindow::setProjectSp(ProjectSp project_sp) {
+    
+    _fastafile_list = _project_sp.get()->getIdentificationDataSourceStore().getFastaFileList();
+    
+    /*
+    for (FastaFileSp fasta_file : _fastafile_list ) {
 
+        QStandardItem *item;
+        item = new QStandardItem(QString("%1").arg(fasta_file.get()->getFilename()));
+        item->setEditable(false);
+        _p_fasta_str_li->appendRow(item);
+        item->setData(QVariant(QString("%1").arg(fasta_file.get()->getFilename())),Qt::UserRole);
+    }
+    */
+    
     for (auto && p_window :_peptide_list_window_collection) {
         delete p_window;
     }
@@ -402,9 +418,8 @@ void ProjectWindow::setProjectSp(ProjectSp project_sp) {
 
     ui->decoy_protein_regexp_line_edit->setText(_project_sp.get()->getProteinStore().getRegexpDecoy().pattern());
     ui->contaminant_protein_regexp_line_edit->setText(_project_sp.get()->getProteinStore().getRegexpContaminant().pattern());
-    computeFdr(ValidationState::grouped);
-
-    computeMassPrecision(ValidationState::validAndChecked);
+    
+    refresh();
     this->setEnabled(true);
 }
 
diff --git a/src/gui/project_view/projectwindow.h b/src/gui/project_view/projectwindow.h
index a2c680802..02144ec1d 100644
--- a/src/gui/project_view/projectwindow.h
+++ b/src/gui/project_view/projectwindow.h
@@ -25,6 +25,7 @@
 #define PROJECTWINDOW_H
 
 #include <QMainWindow>
+#include <set>
 #include "../../core/project.h"
 #include "../edit_label_methods/editlabelmethods.h"
 #include "../edit_modifications/editmodifications.h"
@@ -102,6 +103,9 @@ private:
     EditLabelMethods * _p_edit_label_methods = nullptr;
     
     ProjectSp _project_sp;
+    
+    QStandardItemModel * _p_fasta_str_li;
+    std::set<FastaFileSp> _fastafile_list;
 
 
 };
diff --git a/src/utils/fastafilestore.cpp b/src/utils/fastafilestore.cpp
new file mode 100644
index 000000000..d07b8ba6b
--- /dev/null
+++ b/src/utils/fastafilestore.cpp
@@ -0,0 +1,63 @@
+/**
+ * \file utils/fastafiletore.cpp
+ * \date 22/4/2017
+ * \author Olivier Langella
+ * \brief store unique version of fastafile
+ */
+
+
+/*******************************************************************************
+* 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 "fastafilestore.h"
+FastaFileStore::FastaFileStore()
+{
+
+}
+
+FastaFileStore::~FastaFileStore()
+{
+
+}
+
+FastaFileSp FastaFileStore::getInstance(const FastaFile & location) {
+
+    std::map< FastaFile, FastaFileSp >::iterator it = _map_fastafile.find(location);
+    if (it != _map_fastafile.end()) {
+        return it->second;
+    }
+    else {
+        FastaFileSp p_xtfile = std::make_shared<FastaFile>(location);
+        _map_fastafile.insert(std::pair< FastaFile, FastaFileSp >(location, p_xtfile));
+        return p_xtfile;
+
+    }
+}
+
+
+std::vector<FastaFileSp> FastaFileStore::getFastaFileList() const {
+    std::vector<FastaFileSp> msrun_list;
+    for (auto & msrun_pair :_map_fastafile) {
+        msrun_list.push_back(msrun_pair.second);
+    }
+    return msrun_list;
+}
diff --git a/src/utils/fastafilestore.h b/src/utils/fastafilestore.h
new file mode 100644
index 000000000..a5cca3cc0
--- /dev/null
+++ b/src/utils/fastafilestore.h
@@ -0,0 +1,52 @@
+/**
+ * \file utils/fastafiletore.h
+ * \date 22/4/2017
+ * \author Olivier Langella
+ * \brief store unique version of fastafile
+ */
+
+
+/*******************************************************************************
+* 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 FASTAFILESTORE_H
+#define FASTAFILESTORE_H
+
+#include <map>
+#include <vector>
+#include "../files/fastafile.h"
+
+class FastaFileStore
+{
+public:
+    FastaFileStore();
+    ~FastaFileStore();
+
+    FastaFileSp getInstance(const FastaFile & fastafile);
+    
+    std::vector<FastaFileSp> getFastaFileList() const;
+private:
+    std::map<FastaFile, FastaFileSp> _map_fastafile;
+};
+
+
+#endif // FASTAFILESTORE_H
diff --git a/src/utils/identificationdatasourcestore.cpp b/src/utils/identificationdatasourcestore.cpp
index 04e37584f..003800f78 100644
--- a/src/utils/identificationdatasourcestore.cpp
+++ b/src/utils/identificationdatasourcestore.cpp
@@ -43,7 +43,8 @@ IdentificationDataSourceStore::~IdentificationDataSourceStore()
 }
 
 IdentificationDataSourceSp IdentificationDataSourceStore::getInstance(const QString & location) {
-
+qDebug() << "IdentificationDataSourceStore::getInstance begin " << location;
+qDebug() << " " << _map_identification_data_sources.size();
     std::map< QString, IdentificationDataSourceSp >::iterator it = _map_identification_data_sources.find(location);
     if (it != _map_identification_data_sources.end()) {
         return it->second;
@@ -62,3 +63,17 @@ IdentificationDataSourceSp IdentificationDataSourceStore::getInstance(const QStr
     }
     throw pappso::PappsoException(QObject::tr("Identification resource %1 not recognized").arg(location));
 }
+
+std::set<FastaFileSp> IdentificationDataSourceStore::getFastaFileList() const {
+    qDebug()<<  "IdentificationDataSourceStore::getFastaFileList begin ";
+    std::set<FastaFileSp> list_fasta_set;
+    /*
+    for (auto pair_ident:_map_identification_data_sources) {
+        qDebug()<<  "IdentificationDataSourceStore::getFastaFileList 1";
+        std::vector<FastaFileSp> idfastalist = pair_ident.second.get()->getFastaFileList();
+        list_fasta_set.insert(idfastalist.begin(), idfastalist.end()); 
+    }
+    */
+    qDebug()<<  "IdentificationDataSourceStore::getFastaFileList end";
+    return list_fasta_set;
+}
diff --git a/src/utils/identificationdatasourcestore.h b/src/utils/identificationdatasourcestore.h
index cfef38ee8..3262a49eb 100644
--- a/src/utils/identificationdatasourcestore.h
+++ b/src/utils/identificationdatasourcestore.h
@@ -32,7 +32,9 @@
 #define IDENTIFICATIONDATASOURCESTORE_H
 
 #include <map>
+#include <set>
 #include "../core/identification_sources/identificationdatasource.h"
+#include "../files/fastafile.h"
 
 class IdentificationDataSourceStore
 {
@@ -40,6 +42,8 @@ public:
     IdentificationDataSourceStore();
     ~IdentificationDataSourceStore();
     IdentificationDataSourceSp getInstance(const QString & location);
+    
+    std::set<FastaFileSp> getFastaFileList() const;
 private :
     std::map<QString, IdentificationDataSourceSp> _map_identification_data_sources;
 };
-- 
GitLab