From 727603c100f52f16aa3929bb55c312fd727fd78e Mon Sep 17 00:00:00 2001 From: Olivier Langella <Olivier.Langella@moulon.inra.fr> Date: Thu, 6 Apr 2017 17:39:11 +0200 Subject: [PATCH] reading Xtandem files seems to work! --- src/core/identificationgroup.cpp | 31 ++++++++++++++++--------------- src/core/identificationgroup.h | 4 ++++ 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/src/core/identificationgroup.cpp b/src/core/identificationgroup.cpp index 6b332d4e5..dcbf38ed7 100644 --- a/src/core/identificationgroup.cpp +++ b/src/core/identificationgroup.cpp @@ -54,11 +54,19 @@ ProteinMatch * IdentificationGroup::getProteinMatch(const QString accession) { if (accession.isEmpty()) { throw pappso::PappsoException(QObject::tr("Error protein match not found : accession is empty")); } - for (ProteinMatch * p_protein_match : _protein_match_list) { - if (p_protein_match->getProteinXtpSp().get()->getAccession() == accession) { - return p_protein_match; + auto it_cache = _cache_accession_protein_match.find(accession); + if (it_cache == _cache_accession_protein_match.end()) { + //accession not found in cache + for (ProteinMatch * p_protein_match : _protein_match_list) { + if (p_protein_match->getProteinXtpSp().get()->getAccession() == accession) { + _cache_accession_protein_match.insert(std::pair<QString, ProteinMatch *>(accession, p_protein_match)); + return p_protein_match; + } } } + else { + return it_cache->second; + } return nullptr; } void IdentificationGroup::addProteinMatch(ProteinMatch * protein_match) { @@ -66,20 +74,13 @@ void IdentificationGroup::addProteinMatch(ProteinMatch * protein_match) { if (accession.isEmpty()) { throw pappso::PappsoException(QObject::tr("Error adding protein match : accession is empty")); } - bool push = true; - for (ProteinMatch * p_protein_match : _protein_match_list) { - if (p_protein_match == protein_match) { - push = false; - } - else { - if(p_protein_match->getProteinXtpSp().get()->getAccession() == accession) { - throw pappso::PappsoException(QObject::tr("Error adding protein match : accession %1 already registered").arg(accession)); - } - } - } - if (push) { + auto it_cache = _cache_already_added_protein_match.find(protein_match); + if (it_cache == _cache_already_added_protein_match.end()) { + //accession not found in cache + _cache_already_added_protein_match.insert(protein_match); _protein_match_list.push_back(protein_match); } + } bool IdentificationGroup::contains (const MsRun * p_msrun) const { diff --git a/src/core/identificationgroup.h b/src/core/identificationgroup.h index e71793757..279b7a8b7 100644 --- a/src/core/identificationgroup.h +++ b/src/core/identificationgroup.h @@ -31,6 +31,7 @@ #ifndef IDENTIFICATIONGROUP_H #define IDENTIFICATIONGROUP_H +#include <set> class Project; @@ -92,6 +93,9 @@ private : std::vector<ProteinMatch *> _protein_match_list; std::vector<MsRunSp> _ms_run_list; + + std::map<QString, ProteinMatch *> _cache_accession_protein_match; + std::set<ProteinMatch *> _cache_already_added_protein_match; }; #endif // IDENTIFICATIONGROUP_H -- GitLab