From abeb33e9acd43d9f75ab0b677d13091d4ccc7a29 Mon Sep 17 00:00:00 2001 From: Olivier Langella <Olivier.Langella@moulon.inra.fr> Date: Sun, 23 Apr 2017 14:36:26 +0200 Subject: [PATCH] better assign pointer first... --- .../identificationdatasource.cpp | 5 ++- .../identificationdatasource.h | 3 +- src/core/project.cpp | 3 ++ src/core/project.h | 2 ++ src/core/proteinmatch.cpp | 6 ++-- src/files/fastafile.cpp | 15 +++----- src/files/fastafile.h | 4 +-- src/gui/mainwindow.cpp | 3 ++ src/gui/project_view/projectwindow.cpp | 8 +++-- src/gui/project_view/projectwindow.h | 2 +- src/input/xpipsaxhandler.cpp | 2 ++ src/input/xpipsaxhandler.h | 1 + src/input/xtandemsaxhandler.cpp | 4 +-- src/utils/fastafilestore.cpp | 36 ++++++++++--------- src/utils/fastafilestore.h | 5 ++- src/utils/identificationdatasourcestore.cpp | 14 -------- src/utils/identificationdatasourcestore.h | 2 -- 17 files changed, 54 insertions(+), 61 deletions(-) diff --git a/src/core/identification_sources/identificationdatasource.cpp b/src/core/identification_sources/identificationdatasource.cpp index 4e377f01d..0e0780733 100644 --- a/src/core/identification_sources/identificationdatasource.cpp +++ b/src/core/identification_sources/identificationdatasource.cpp @@ -26,7 +26,6 @@ #include <QFileInfo> #include "../../utils/readspectrum.h" -FastaFileStore IdentificationDataSource::_fasta_file_store; IdentificationDataSource::IdentificationDataSource(const QString resource_name) { @@ -83,8 +82,8 @@ pappso::SpectrumSp IdentificationDataSource::getSpectrumSp(unsigned int scan_num return spectrum_sp; } -void IdentificationDataSource::addFastaFile (FastaFile file) { - _fastafile_list.push_back(IdentificationDataSource::_fasta_file_store.getInstance(file)); +void IdentificationDataSource::addFastaFile (FastaFileSp file) { + _fastafile_list.push_back(file); } const std::vector<FastaFileSp> & IdentificationDataSource::getFastaFileList() const { qDebug()<< "IdentificationDataSource::getFastaFileList begin" << _fastafile_list.size(); diff --git a/src/core/identification_sources/identificationdatasource.h b/src/core/identification_sources/identificationdatasource.h index f5a7d0e88..efb09f341 100644 --- a/src/core/identification_sources/identificationdatasource.h +++ b/src/core/identification_sources/identificationdatasource.h @@ -73,7 +73,7 @@ public: /** \brief add Fastafile used by the identification engine */ - void addFastaFile (FastaFile file); + void addFastaFile (FastaFileSp file); const std::vector<FastaFileSp> & getFastaFileList() const; @@ -82,7 +82,6 @@ protected : 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; diff --git a/src/core/project.cpp b/src/core/project.cpp index be9f6dde3..e4d78b800 100644 --- a/src/core/project.cpp +++ b/src/core/project.cpp @@ -65,6 +65,9 @@ const GroupingType Project::getGroupingType() const { return _grouping_type; } +FastaFileStore & Project::getFastaFileStore() { + return _fasta_file_store; +} MsRunStore & Project::getMsRunStore() { return _msrun_store; } diff --git a/src/core/project.h b/src/core/project.h index 5f454f404..73a8b06b8 100644 --- a/src/core/project.h +++ b/src/core/project.h @@ -48,6 +48,7 @@ public: ProteinStore & getProteinStore(); PeptideStore & getPeptideStore(); MsRunStore & getMsRunStore(); + FastaFileStore & getFastaFileStore(); IdentificationDataSourceStore & getIdentificationDataSourceStore(); void readXpipFile(QFileInfo xpip_source); IdentificationGroup* newIdentificationGroup(); @@ -83,6 +84,7 @@ private : PeptideStore _peptide_store; IdentificationDataSourceStore _identification_data_source_store; MsRunStore _msrun_store; + FastaFileStore _fasta_file_store; }; diff --git a/src/core/proteinmatch.cpp b/src/core/proteinmatch.cpp index 9265c6292..d44f1fe72 100644 --- a/src/core/proteinmatch.cpp +++ b/src/core/proteinmatch.cpp @@ -62,7 +62,7 @@ bool ProteinMatch::contains(PeptideMatch * peptide_match) const { } void ProteinMatch::updateAutomaticFilters(const AutomaticFilterParameters & automatic_filter_parameters) { - qDebug() <<"ProteinMatch::updateAutomaticFilters begin " ; + //qDebug() <<"ProteinMatch::updateAutomaticFilters begin " ; _proxy_valid = false; unsigned int number_of_valid_peptides =0; bool cross_sample = automatic_filter_parameters.getFilterCrossSamplePeptideNumber(); @@ -102,7 +102,7 @@ void ProteinMatch::updateAutomaticFilters(const AutomaticFilterParameters & auto } } } - qDebug() <<"ProteinMatch::updateAutomaticFilters end " << number_of_valid_peptides ; + //qDebug() <<"ProteinMatch::updateAutomaticFilters end " << number_of_valid_peptides ; } const ProteinXtpSp & ProteinMatch::getProteinXtpSp() const { @@ -213,7 +213,7 @@ unsigned int ProteinMatch::countSequenceLi(ValidationState state, const MsRun * } } } - qDebug() <<"ProteinMatch::countValidAndCheckedPeptide end " << sequence_list.size(); + //qDebug() <<"ProteinMatch::countValidAndCheckedPeptide end " << sequence_list.size(); return sequence_list.size(); } diff --git a/src/files/fastafile.cpp b/src/files/fastafile.cpp index aa6694508..2ac6b0dac 100644 --- a/src/files/fastafile.cpp +++ b/src/files/fastafile.cpp @@ -27,7 +27,7 @@ FastaFile::FastaFile(const QString & fasta_source) : _fasta_source(fasta_source) { } -FastaFile::FastaFile(const QFileInfo & fasta_source): _fasta_source(fasta_source.absoluteFilePath()) +FastaFile::FastaFile(const QFileInfo & fasta_source): _fasta_source(fasta_source) { } FastaFile::FastaFile(const FastaFile & other) : _fasta_source(other._fasta_source) @@ -39,15 +39,10 @@ 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(); } + +const QString FastaFile::getAbsoluteFilePath() const { + return _fasta_source.absoluteFilePath(); +} diff --git a/src/files/fastafile.h b/src/files/fastafile.h index 263bf587d..1ba908272 100644 --- a/src/files/fastafile.h +++ b/src/files/fastafile.h @@ -38,10 +38,10 @@ public: FastaFile(const FastaFile & other); ~FastaFile(); - bool operator<( const FastaFile& other ) const; - bool operator==( const FastaFile& other ) const; const QString getFilename() const; + const QString getAbsoluteFilePath() const; + private : const QFileInfo _fasta_source; diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp index b6b27e378..496fb71d9 100644 --- a/src/gui/mainwindow.cpp +++ b/src/gui/mainwindow.cpp @@ -219,7 +219,10 @@ void MainWindow::doProjectReady(ProjectSp project_sp) { qDebug() << "MainWindow::doProjectReady begin"; try { + qDebug() << "MainWindow::doProjectReady begin a " << project_sp.get()->getFastaFileStore().getFastaFileList().size() ; _project_sp = project_sp; + + qDebug() << "MainWindow::doProjectReady begin b " << _project_sp.get()->getFastaFileStore().getFastaFileList().size() ; doDisplayLoadingMessage(tr("grouping proteins")); project_sp.get()->startGrouping(); doDisplayLoadingMessage(tr("grouping proteins finished")); diff --git a/src/gui/project_view/projectwindow.cpp b/src/gui/project_view/projectwindow.cpp index 7e6294f1b..780eaa948 100644 --- a/src/gui/project_view/projectwindow.cpp +++ b/src/gui/project_view/projectwindow.cpp @@ -346,8 +346,12 @@ void ProjectWindow::doViewProteinList(IdentificationGroup* p_identification_grou } void ProjectWindow::setProjectSp(ProjectSp project_sp) { + qDebug() << "ProjectWindow::setProjectSp begin" ; - _fastafile_list = _project_sp.get()->getIdentificationDataSourceStore().getFastaFileList(); + _project_sp = project_sp; + + qDebug() << "ProjectWindow::setProjectSp begin " << _project_sp.get()->getFastaFileStore().getFastaFileList().size() ; + _fastafile_list = _project_sp.get()->getFastaFileStore().getFastaFileList(); for (FastaFileSp fasta_file : _fastafile_list ) { @@ -384,8 +388,6 @@ void ProjectWindow::setProjectSp(ProjectSp project_sp) { _peptide_detail_window_collection.clear(); _p_current_peptide_detail_window = nullptr; - _project_sp = project_sp; - if (_p_identification_widget != nullptr) { delete _p_identification_widget; } diff --git a/src/gui/project_view/projectwindow.h b/src/gui/project_view/projectwindow.h index 5d3882f18..daae90f48 100644 --- a/src/gui/project_view/projectwindow.h +++ b/src/gui/project_view/projectwindow.h @@ -105,7 +105,7 @@ private: ProjectSp _project_sp; QStandardItemModel * _p_fasta_str_li; - std::set<FastaFileSp> _fastafile_list; + std::vector<FastaFileSp> _fastafile_list; }; diff --git a/src/input/xpipsaxhandler.cpp b/src/input/xpipsaxhandler.cpp index e925bd943..a8f9b20c5 100644 --- a/src/input/xpipsaxhandler.cpp +++ b/src/input/xpipsaxhandler.cpp @@ -215,6 +215,7 @@ bool XpipSaxHandler::startElement_protein(QXmlAttributes attributes) { </protein> */ _current_protein.setCompleteDescription(attributes.value("description")); + _current_fasta_file_sp = _p_project->getFastaFileStore().getInstance(FastaFile(attributes.value("URL"))); qDebug() << "startElement_protein end" ; return true; } @@ -247,6 +248,7 @@ bool XpipSaxHandler::startElement_peptide(QXmlAttributes attributes) { if (p_identification_data_source->getMsRunSp().get() != ms_run_id.get()) { throw pappso::PappsoException(QObject::tr("p_identification_data_source->getMsRunSp().get() != ms_run_id.get()")); } + p_identification_data_source->addFastaFile(_current_fasta_file_sp); _p_peptide_match->setChecked(false); if (attributes.value("validate").simplified().toLower() == "true") { _p_peptide_match->setChecked(true); diff --git a/src/input/xpipsaxhandler.h b/src/input/xpipsaxhandler.h index dc172caa0..f7f3feeb8 100644 --- a/src/input/xpipsaxhandler.h +++ b/src/input/xpipsaxhandler.h @@ -85,6 +85,7 @@ private: ProteinXtp _current_protein; PeptideXtpSp _current_peptide_sp; IdentificationGroup * _current_identification_group_p; + FastaFileSp _current_fasta_file_sp; QMap<QString, pappso::AaModificationP> _map_massstr_aamod; }; diff --git a/src/input/xtandemsaxhandler.cpp b/src/input/xtandemsaxhandler.cpp index e1649cf2f..58c59468c 100644 --- a/src/input/xtandemsaxhandler.cpp +++ b/src/input/xtandemsaxhandler.cpp @@ -449,8 +449,8 @@ bool XtandemSaxHandler::endElement_note() { //<note label="list path, sequence source #1">/gorgone/pappso/formation/TD/Database/Genome_Z_mays_5a.fasta</note> //<note label="list path, sequence source #2">/gorgone/pappso/formation/TD/Database/contaminants_standarts.fasta</note> - if (_current_note_label.startsWith("list path, sequence source")) { - _p_identification_data_source->addFastaFile(FastaFile(_current_text)); + if (_current_note_label.startsWith("list path, sequence source #")) { + _p_identification_data_source->addFastaFile(_p_project->getFastaFileStore().getInstance( FastaFile(_current_text))); } /* diff --git a/src/utils/fastafilestore.cpp b/src/utils/fastafilestore.cpp index d07b8ba6b..ab5a58b4a 100644 --- a/src/utils/fastafilestore.cpp +++ b/src/utils/fastafilestore.cpp @@ -29,6 +29,7 @@ ******************************************************************************/ #include "fastafilestore.h" +#include <QDebug> FastaFileStore::FastaFileStore() { @@ -40,24 +41,27 @@ 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; - +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()->getAbsoluteFilePath() == location.getAbsoluteFilePath()) { + +qDebug() << "FastaFileStore::getInstance() end b "<< it->get()->getAbsoluteFilePath(); + return *it; + } + it++; } + FastaFileSp fastafile_sp = std::make_shared<FastaFile>(location); + _map_fastafile.push_back(fastafile_sp); + qDebug() << "FastaFileStore::getFastaFileList() end a " << _map_fastafile.size(); + return fastafile_sp; } -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; +const std::vector<FastaFileSp> & FastaFileStore::getFastaFileList() const { + qDebug() << "FastaFileStore::getFastaFileList() begin" ; + qDebug() << "FastaFileStore::getFastaFileList() begin" << _map_fastafile.size(); + return _map_fastafile; } diff --git a/src/utils/fastafilestore.h b/src/utils/fastafilestore.h index a5cca3cc0..af3e877b3 100644 --- a/src/utils/fastafilestore.h +++ b/src/utils/fastafilestore.h @@ -31,7 +31,6 @@ #ifndef FASTAFILESTORE_H #define FASTAFILESTORE_H -#include <map> #include <vector> #include "../files/fastafile.h" @@ -43,9 +42,9 @@ public: FastaFileSp getInstance(const FastaFile & fastafile); - std::vector<FastaFileSp> getFastaFileList() const; + const std::vector<FastaFileSp> & getFastaFileList() const; private: - std::map<FastaFile, FastaFileSp> _map_fastafile; + std::vector<FastaFileSp> _map_fastafile; }; diff --git a/src/utils/identificationdatasourcestore.cpp b/src/utils/identificationdatasourcestore.cpp index 003800f78..012e65c8c 100644 --- a/src/utils/identificationdatasourcestore.cpp +++ b/src/utils/identificationdatasourcestore.cpp @@ -63,17 +63,3 @@ qDebug() << " " << _map_identification_data_sources.size(); } 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 3262a49eb..e634800fb 100644 --- a/src/utils/identificationdatasourcestore.h +++ b/src/utils/identificationdatasourcestore.h @@ -42,8 +42,6 @@ public: IdentificationDataSourceStore(); ~IdentificationDataSourceStore(); IdentificationDataSourceSp getInstance(const QString & location); - - std::set<FastaFileSp> getFastaFileList() const; private : std::map<QString, IdentificationDataSourceSp> _map_identification_data_sources; }; -- GitLab