From acb5d43688011389e09a3d78c2e17410225ca022 Mon Sep 17 00:00:00 2001 From: Olivier Langella <olivier.langella@u-psud.fr> Date: Sat, 18 Nov 2017 11:21:43 +0100 Subject: [PATCH] WIP: new peptide match store object --- src/CMakeLists.txt | 1 + .../identificationdatasource.cpp | 5 ++- .../identificationdatasource.h | 5 +++ src/core/peptidematch.cpp | 4 ++ src/core/peptidematch.h | 6 ++- src/core/proteinmatch.cpp | 10 ++--- src/core/proteinmatch.h | 2 +- src/input/identificationpwizreader.cpp | 5 ++- src/input/xpipsaxhandler.cpp | 4 +- src/input/xtandemsaxhandler.cpp | 6 ++- src/utils/peptidematchstore.cpp | 36 +++++++++++++++ src/utils/peptidematchstore.h | 44 +++++++++++++++++++ 12 files changed, 113 insertions(+), 15 deletions(-) create mode 100644 src/utils/peptidematchstore.cpp create mode 100644 src/utils/peptidematchstore.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f7b3c632b..7a1be53fa 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -106,6 +106,7 @@ SET(CPP_FILES utils/identificationdatasourcestore.cpp utils/groupstore.cpp utils/msrunstore.cpp + utils/peptidematchstore.cpp utils/peptidestore.cpp utils/proteinstore.cpp utils/readspectrum.cpp diff --git a/src/core/identification_sources/identificationdatasource.cpp b/src/core/identification_sources/identificationdatasource.cpp index ca74c0739..d300871d2 100644 --- a/src/core/identification_sources/identificationdatasource.cpp +++ b/src/core/identification_sources/identificationdatasource.cpp @@ -27,7 +27,6 @@ #include <QFileInfo> #include "../../utils/readspectrum.h" - IdentificationDataSource::IdentificationDataSource(const QString resource_name) { _resource_name = resource_name; @@ -45,6 +44,10 @@ IdentificationDataSource::~IdentificationDataSource() } +PeptideMatchStore & IdentificationDataSource::getPeptideMatchStore() { + return _peptide_match_store; +} + void IdentificationDataSource::setXmlId(const QString xmlid) { _xml_id = xmlid; } diff --git a/src/core/identification_sources/identificationdatasource.h b/src/core/identification_sources/identificationdatasource.h index 7d23ac482..de98f146b 100644 --- a/src/core/identification_sources/identificationdatasource.h +++ b/src/core/identification_sources/identificationdatasource.h @@ -29,12 +29,14 @@ #include <QVariant> #include "../msrun.h" #include "../../utils/fastafilestore.h" +#include "../../utils/peptidematchstore.h" class Project; class IdentificationDataSource; typedef std::shared_ptr<IdentificationDataSource> IdentificationDataSourceSp; + class IdentificationDataSource { public: @@ -44,6 +46,7 @@ public: ~IdentificationDataSource(); bool operator==(const IdentificationDataSource& other) const; + PeptideMatchStore & getPeptideMatchStore(); void setXmlId(const QString xmlid); const QString & getXmlId() const; @@ -118,6 +121,8 @@ private : std::map<IdentificationEngineParam, QVariant> _params; std::map<IdentificationEngineStatistics, QVariant> _param_stats; std::vector<FastaFileSp> _fastafile_list; + + PeptideMatchStore _peptide_match_store; }; #endif // IDENTIFICATIONDATASOURCE_H diff --git a/src/core/peptidematch.cpp b/src/core/peptidematch.cpp index 4e51d36a7..ad0938af0 100644 --- a/src/core/peptidematch.cpp +++ b/src/core/peptidematch.cpp @@ -49,6 +49,10 @@ PeptideMatch::PeptideMatch(const PeptideMatch & other): PeptideMatch(other._msru } +PeptideMatchSp PeptideMatch::makePeptideMatchSp() const { + return std::make_shared<PeptideMatch>(*this); +} + void PeptideMatch::updateAutomaticFilters(const AutomaticFilterParameters & automatic_filter_parameters) { _proxy_valid = false; diff --git a/src/core/peptidematch.h b/src/core/peptidematch.h index 2ae750d44..2f28bfe01 100644 --- a/src/core/peptidematch.h +++ b/src/core/peptidematch.h @@ -45,6 +45,8 @@ public : std::size_t getHashSampleScan() const; std::size_t getHashPeptideMassSample() const; + PeptideMatchSp makePeptideMatchSp() const; + void setRetentionTime(pappso::pappso_double rt); void setEvalue(pappso::pappso_double evalue); @@ -72,7 +74,7 @@ public : /** \brief get specific parameter value */ virtual const QVariant getParam(PeptideMatchParam param) const; - + const std::map<PeptideMatchParam, QVariant> & getParamList() const; @@ -118,7 +120,7 @@ public : pappso::mz getDeltaMass() const; ValidationState getValidationState() const; - + /** @brief tells if this peptide contains a protein position * the position is the amino acid position on the protein sequence (starts from 0) * */ diff --git a/src/core/proteinmatch.cpp b/src/core/proteinmatch.cpp index 4400d062c..37795b3f7 100644 --- a/src/core/proteinmatch.cpp +++ b/src/core/proteinmatch.cpp @@ -39,12 +39,8 @@ ProteinMatch::ProteinMatch() ProteinMatch::~ProteinMatch() { - auto it = _peptide_match_list.begin(); - while (it != _peptide_match_list.end()) { - delete (*it); - it++; - } } + ValidationState ProteinMatch::getValidationState() const { if (isGrouped()) { return ValidationState::grouped; @@ -141,8 +137,8 @@ bool ProteinMatch::isGrouped() const { void ProteinMatch::setChecked(bool arg1) { _checked = arg1; } -void ProteinMatch::addPeptideMatch(PeptideMatch * peptide_match) { - _peptide_match_list.push_back(peptide_match); +void ProteinMatch::addPeptideMatchSp(PeptideMatchSp peptide_match) { + _peptide_match_list.push_back(peptide_match.get()); } diff --git a/src/core/proteinmatch.h b/src/core/proteinmatch.h index 01717dd4e..e4d0c6606 100644 --- a/src/core/proteinmatch.h +++ b/src/core/proteinmatch.h @@ -74,7 +74,7 @@ public: pappso::pappso_double getEmPAI(const MsRun * sp_msrun_id = nullptr) const; void setProteinXtpSp(ProteinXtpSp protein_sp); - void addPeptideMatch(PeptideMatch * peptide_match); + void addPeptideMatchSp(PeptideMatchSp peptide_match); std::vector<PeptideMatch *> & getPeptideMatchList(); const std::vector<PeptideMatch *> & getPeptideMatchList() const; diff --git a/src/input/identificationpwizreader.cpp b/src/input/identificationpwizreader.cpp index 3f271316b..bfa3a3097 100644 --- a/src/input/identificationpwizreader.cpp +++ b/src/input/identificationpwizreader.cpp @@ -278,7 +278,10 @@ void IdentificationPwizReader::read( } ProteinMatch * protein_match_p = it->second; - protein_match_p->addPeptideMatch(p_peptide_match_from_evidence); + protein_match_p->addPeptideMatchSp(p_peptide_match_from_evidence->getIdentificationDataSource()->getPeptideMatchStore().getInstance(p_peptide_match_from_evidence)); + + delete p_peptide_match_from_evidence; + //protein_match_p->addPeptideMatch(p_peptide_match_from_evidence); } delete p_peptide_match; } diff --git a/src/input/xpipsaxhandler.cpp b/src/input/xpipsaxhandler.cpp index a5b4cd840..9c580c962 100644 --- a/src/input/xpipsaxhandler.cpp +++ b/src/input/xpipsaxhandler.cpp @@ -279,7 +279,6 @@ bool XpipSaxHandler::startElement_peptide(QXmlAttributes attributes) { if (attributes.value("validate").simplified().toLower() == "true") { _p_peptide_match->setChecked(true); } - _p_protein_match->addPeptideMatch(_p_peptide_match); qDebug() << "startElement_peptide end" ; return true; } @@ -296,10 +295,11 @@ bool XpipSaxHandler::startElement_modif(QXmlAttributes attributes) { } bool XpipSaxHandler::endElement_peptide() { qDebug() << "endElement_peptide "; - PeptideXtpSp peptide_const = PeptideXtp(*(_current_peptide_sp.get())).makePeptideXtpSp(); peptide_const = _p_project->getPeptideStore().getInstance(peptide_const); _p_peptide_match->setPeptideXtpSp(peptide_const); + _p_protein_match->addPeptideMatchSp(_p_peptide_match->getIdentificationDataSource()->getPeptideMatchStore().getInstance(_p_peptide_match)); + delete _p_peptide_match; return true; } diff --git a/src/input/xtandemsaxhandler.cpp b/src/input/xtandemsaxhandler.cpp index 396dba158..d1cdd2fcd 100644 --- a/src/input/xtandemsaxhandler.cpp +++ b/src/input/xtandemsaxhandler.cpp @@ -303,7 +303,6 @@ bool XtandemSaxHandler::startElement_domain(QXmlAttributes attributes) { _p_peptide_match->setIdentificationDataSource( _p_identification_data_source); _p_peptide_match->setChecked(true); - _p_protein_match->addPeptideMatch(_p_peptide_match); @@ -331,6 +330,11 @@ bool XtandemSaxHandler::endElement_domain() { _current_peptide_sp = _p_project->getPeptideStore().getInstance(_current_peptide_sp); _p_peptide_match->setPeptideXtpSp(_current_peptide_sp); + + + _p_protein_match->addPeptideMatchSp(_p_peptide_match->getIdentificationDataSource()->getPeptideMatchStore().getInstance(_p_peptide_match)); + + delete _p_peptide_match; return is_ok; } bool XtandemSaxHandler::endElement_note() { diff --git a/src/utils/peptidematchstore.cpp b/src/utils/peptidematchstore.cpp new file mode 100644 index 000000000..f2fbef9d2 --- /dev/null +++ b/src/utils/peptidematchstore.cpp @@ -0,0 +1,36 @@ +/** + * \file utils/peptidematchstore.cpp + * \date 18/11/2017 + * \author Olivier Langella + * \brief store unique instances of peptide match + */ + + +/******************************************************************************* +* 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 "peptidematchstore.h" + +#include "../core/peptidematch.h" + +std::shared_ptr<PeptideMatch> & PeptideMatchStore::getInstance(const PeptideMatch * p_peptide_match) { +} diff --git a/src/utils/peptidematchstore.h b/src/utils/peptidematchstore.h new file mode 100644 index 000000000..912f17382 --- /dev/null +++ b/src/utils/peptidematchstore.h @@ -0,0 +1,44 @@ +/** + * \file utils/peptidematchstore.h + * \date 18/11/2017 + * \author Olivier Langella + * \brief store unique instances of peptide match + */ + + +/******************************************************************************* +* 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 PEPTIDEMATCHSTORE_H +#define PEPTIDEMATCHSTORE_H + +#include <memory> + +class PeptideMatch; + +class PeptideMatchStore +{ +public: + std::shared_ptr<PeptideMatch> & getInstance(const PeptideMatch * p_peptide_match); +}; + +#endif // PEPTIDEMATCHSTORE_H -- GitLab