From 77693a1a2ec81ebe9e368aca4e2a923bd31ab819 Mon Sep 17 00:00:00 2001 From: Olivier Langella <Olivier.Langella@moulon.inra.fr> Date: Tue, 21 Mar 2017 12:06:58 +0100 Subject: [PATCH] valid and checked design --- src/CMakeLists.txt | 3 +- src/core/identificationgroup.cpp | 7 ++-- src/core/identificationgroup.h | 6 +-- src/core/peptidematch.cpp | 17 ++++++++ src/core/peptidematch.h | 8 ++++ src/core/project.cpp | 21 +++------- src/core/project.h | 16 +------- src/core/proteinmatch.cpp | 41 +++++++++++++++++++ src/core/proteinmatch.h | 9 ++++ .../peptide_list_view/peptidetablemodel.cpp | 2 +- .../protein_list_view/proteintablemodel.cpp | 2 +- src/input/xpipsaxhandler.cpp | 11 ++--- src/input/xpipsaxhandler.h | 1 + 13 files changed, 101 insertions(+), 43 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ade8d7f8f..21b70805f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -53,9 +53,10 @@ configure_file (${CMAKE_SOURCE_DIR}/src/config.h.cmake ${CMAKE_SOURCE_DIR}/src/c # File list SET(CPP_FILES + core/automaticfilterparameters.cpp core/identificationgroup.cpp core/peptidematch.cpp - core/project.cpp + ./core/project.cpp core/proteinmatch.cpp core/identification_sources/identificationdatasource.cpp core/identification_sources/identificationxtandemfile.cpp diff --git a/src/core/identificationgroup.cpp b/src/core/identificationgroup.cpp index f251e0bb2..3a7cea893 100644 --- a/src/core/identificationgroup.cpp +++ b/src/core/identificationgroup.cpp @@ -38,11 +38,12 @@ IdentificationGroup::~IdentificationGroup() } } -bool IdentificationGroup::isValid(ProteinMatch* p_protein_match) const { - return _p_project->isValid(p_protein_match); +void IdentificationGroup::updateAutomaticFilters(const AutomaticFilterParameters & automatic_filter_parameters) { + for (auto & p_protein_match : _protein_match_list) { + p_protein_match->updateAutomaticFilters(automatic_filter_parameters); + } } - void IdentificationGroup::addProteinMatch(ProteinMatch * protein_match) { _protein_match_list.push_back(protein_match); } diff --git a/src/core/identificationgroup.h b/src/core/identificationgroup.h index 71d591286..dc448a6d7 100644 --- a/src/core/identificationgroup.h +++ b/src/core/identificationgroup.h @@ -47,9 +47,9 @@ public: void addMsRunIdSp(pappso::MsRunIdSp ms_run_sp); - /** @brief is it valid regarding threshold and project rules - */ - bool isValid(ProteinMatch* p_protein_match) const; + /** @brief validate or invalidate peptides and proteins based automatic filters and manual checks + * */ + void updateAutomaticFilters(const AutomaticFilterParameters & automatic_filter_parameters); pappso::GrpExperiment * _p_grp_experiment= nullptr; private : diff --git a/src/core/peptidematch.cpp b/src/core/peptidematch.cpp index 75c753f69..718d2e025 100644 --- a/src/core/peptidematch.cpp +++ b/src/core/peptidematch.cpp @@ -28,6 +28,13 @@ PeptideMatch::PeptideMatch(pappso::MsRunIdSp msrunid_sp, unsigned int scan) { _scan = scan; } +void PeptideMatch::updateAutomaticFilters(const AutomaticFilterParameters & automatic_filter_parameters) { + _proxy_valid = false; + + if (_evalue <= automatic_filter_parameters.getFilterPeptideEvalue()) { + _proxy_valid = true; + } +} void PeptideMatch::setRetentionTime(pappso::pappso_double rt) { _rt = rt; } @@ -56,10 +63,16 @@ void PeptideMatch::setChecked(bool arg1) { _checked = arg1; } +bool PeptideMatch::isValid() const { + return _proxy_valid; +} bool PeptideMatch::isChecked() const { return _checked; } +bool PeptideMatch::isValidAndChecked() const{ + return _proxy_valid && _checked; +} void PeptideMatch::setIdentificationDataSource(IdentificationDataSource* identification_source) { _p_identification_source = identification_source; } @@ -79,3 +92,7 @@ unsigned int PeptideMatch::getCharge() const { pappso::PeptideSp PeptideMatch::getPeptideSp() const { return _peptide_sp; } + +const pappso::MsRunIdSp & PeptideMatch::getMsRunIdSp() const { + return _msrunid_sp; +} \ No newline at end of file diff --git a/src/core/peptidematch.h b/src/core/peptidematch.h index 92b42b92d..8d8f26641 100644 --- a/src/core/peptidematch.h +++ b/src/core/peptidematch.h @@ -27,6 +27,7 @@ #include <pappsomspp/types.h> #include <pappsomspp/peptide/peptide.h> #include "identification_sources/identificationdatasource.h" +#include "automaticfilterparameters.h" class PeptideMatch { @@ -42,7 +43,10 @@ public : void setIdentificationDataSource(IdentificationDataSource* identification_source); void setChecked(bool arg1); bool isChecked() const; + bool isValid() const; + bool isValidAndChecked() const; + const pappso::MsRunIdSp & getMsRunIdSp() const; IdentificationDataSource* getIdentificationDataSource () const; unsigned int getScan() const; pappso::pappso_double getRetentionTime() const; @@ -50,6 +54,10 @@ public : pappso::PeptideSp getPeptideSp() const; pappso::pappso_double getEvalue() const; + /** @brief validate or invalidate peptides and proteins based automatic filters and manual checks + * */ + void updateAutomaticFilters(const AutomaticFilterParameters & automatic_filter_parameters); + private : pappso::MsRunIdSp _msrunid_sp; unsigned int _scan; diff --git a/src/core/project.cpp b/src/core/project.cpp index 4cdc329c1..3e6a0955d 100644 --- a/src/core/project.cpp +++ b/src/core/project.cpp @@ -39,7 +39,12 @@ Project::~Project() } } -void Project::updateAutomaticFilters() { +void Project::updateAutomaticFilters(const AutomaticFilterParameters & automatic_filter_parameters) { + _automatic_filter_parameters = automatic_filter_parameters; + for (auto & p_id_group : _identification_goup_list) { + p_id_group->updateAutomaticFilters(_automatic_filter_parameters); + } + } ProjectSp Project::makeProjectSp() const { return std::make_shared<Project>(*this); @@ -83,17 +88,3 @@ void Project::readXpipFile(QFileInfo xpip_fileinfo) { IdentificationGroup* Project::getCurrentIdentificationGroupP() const { return _p_current_identification_group; } - -bool Project::isValid(PeptideMatch* p_peptide_match) const { - if (p_peptide_match->getEvalue() > _filter_minimum_peptide_evalue) { - return false; - } - return true; -} - -bool Project::isValid(ProteinMatch* p_protein_match) const { - if (p_protein_match->getEvalue() > _filter_minimum_protein_evalue) { - return false; - } - return true; -} diff --git a/src/core/project.h b/src/core/project.h index b97e74130..b5ddcdf6a 100644 --- a/src/core/project.h +++ b/src/core/project.h @@ -33,9 +33,8 @@ typedef std::shared_ptr<Project> ProjectSp; class PeptideMatch; class ProteinMatch; -class Project : public QObject +class Project { - Q_OBJECT public: Project(); ~Project(); @@ -44,22 +43,11 @@ public: void readXpipFile(QFileInfo xpip_source); IdentificationGroup* newIdentificationGroup(); IdentificationGroup* getCurrentIdentificationGroupP() const; - /** @brief is it valid regarding threshold and project rules - */ - bool isValid(PeptideMatch* p_peptide_match) const; - /** @brief is it valid regarding threshold and project rules - */ - bool isValid(ProteinMatch* p_protein_match) const; /** @brief validate or invalidate peptides and proteins based automatic filters and manual checks * */ void updateAutomaticFilters(const AutomaticFilterParameters & automatic_filter_parameters); - - signals: - /** @brief signal when automatic filters are applied and project is ready - * */ - void projectReady(); - + private : std::vector<IdentificationGroup *> _identification_goup_list; diff --git a/src/core/proteinmatch.cpp b/src/core/proteinmatch.cpp index fb14cd1b4..f72acb9d2 100644 --- a/src/core/proteinmatch.cpp +++ b/src/core/proteinmatch.cpp @@ -22,6 +22,7 @@ ******************************************************************************/ #include "proteinmatch.h" +#include <pappsomspp/msrun/msrunid.h> ProteinMatch::ProteinMatch() @@ -38,6 +39,37 @@ ProteinMatch::~ProteinMatch() } } +void ProteinMatch::updateAutomaticFilters(const AutomaticFilterParameters & automatic_filter_parameters) { + _proxy_valid = false; + unsigned int _number_of_valid_peptides =0; + std::map<const pappso::MsRunId*, unsigned int> _count_per_msrun; + bool cross_sample = automatic_filter_parameters.getFilterCrossSamplePeptideNumber(); + + for (auto & p_peptide_match : _peptide_match_list) { + p_peptide_match->updateAutomaticFilters(automatic_filter_parameters); + //count valid and checked peptides : + if (p_peptide_match->isValidAndChecked()) { + if (cross_sample) { + _number_of_valid_peptides++; + } + else { + std::pair<std::map<const pappso::MsRunId*, unsigned int>::iterator,bool> ret = _count_per_msrun.insert(std::pair<const pappso::MsRunId*, unsigned int>(p_peptide_match->getMsRunIdSp().get(),0)); + ret.first->second +=1; + if (ret.first->second > _number_of_valid_peptides) { + _number_of_valid_peptides = ret.first->second; + } + } + } + } + + + if (_number_of_valid_peptides >= automatic_filter_parameters.getFilterMinimumPeptidePerMatch()) { + if (_evalue <= automatic_filter_parameters.getFilterProteinEvalue()) { + _proxy_valid = true; + } + } +} + const pappso::ProteinSp & ProteinMatch::getProteinSp() const { return _protein_sp; } @@ -52,9 +84,18 @@ void ProteinMatch::setProteinSp(pappso::ProteinSp protein_sp) { _protein_sp = protein_sp; } + +bool ProteinMatch::isValid() const { + return _proxy_valid; +} bool ProteinMatch::isChecked() const { return _checked; } + +bool ProteinMatch::isValidAndChecked() const{ + return _proxy_valid && _checked; +} + void ProteinMatch::setChecked(bool arg1) { _checked = arg1; } diff --git a/src/core/proteinmatch.h b/src/core/proteinmatch.h index a0a0f5999..6fba08333 100644 --- a/src/core/proteinmatch.h +++ b/src/core/proteinmatch.h @@ -28,6 +28,7 @@ #include <pappsomspp/types.h> #include <pappsomspp/protein/protein.h> #include "peptidematch.h" +#include "automaticfilterparameters.h" class ProteinMatch { @@ -42,7 +43,15 @@ public: void addPeptideMatch(PeptideMatch * peptide_match); std::vector<PeptideMatch *> & getPeptideMatchList(); void setChecked(bool arg1); + bool isChecked() const; + bool isValid() const; + bool isValidAndChecked() const; + + /** @brief validate or invalidate peptides and proteins based automatic filters and manual checks + * */ + void updateAutomaticFilters(const AutomaticFilterParameters & automatic_filter_parameters); + private: std::vector<PeptideMatch *> _peptide_match_list; pappso::ProteinSp _protein_sp = nullptr; diff --git a/src/gui/peptide_list_view/peptidetablemodel.cpp b/src/gui/peptide_list_view/peptidetablemodel.cpp index 3096830a8..f5e88e48c 100644 --- a/src/gui/peptide_list_view/peptidetablemodel.cpp +++ b/src/gui/peptide_list_view/peptidetablemodel.cpp @@ -191,7 +191,7 @@ void PeptideTableModel::onTableClicked(const QModelIndex &index) } bool PeptideTableModel::acceptRow(int source_row) { - if (_p_project->isValid(_p_protein_match->getPeptideMatchList().at(source_row))) { + if (_p_protein_match->getPeptideMatchList().at(source_row)->isValid()) { return true; } return false; diff --git a/src/gui/protein_list_view/proteintablemodel.cpp b/src/gui/protein_list_view/proteintablemodel.cpp index bd7b21d82..5ceaa2609 100644 --- a/src/gui/protein_list_view/proteintablemodel.cpp +++ b/src/gui/protein_list_view/proteintablemodel.cpp @@ -223,7 +223,7 @@ bool ProteinTableModel::acceptRow(int source_row) { return false; } } - if (_p_identification_group->isValid(protein_match)) { + if (protein_match->isValid()) { return true; } return false; diff --git a/src/input/xpipsaxhandler.cpp b/src/input/xpipsaxhandler.cpp index 2cb9a30c1..ca567de05 100644 --- a/src/input/xpipsaxhandler.cpp +++ b/src/input/xpipsaxhandler.cpp @@ -134,12 +134,12 @@ bool XpipSaxHandler::startElement_filter_params(QXmlAttributes attributes) { //<filter_params pep_evalue="0.01" prot_evalue="-2.0" pep_number="1" filter_to_all="false" database_filter="contaminants_standarts.fasta"/> qDebug() << "startElement_filter_params "; - _p_project->setFilterPeptideEvalue( attributes.value("pep_evalue").simplified().toDouble()); - _p_project->setFilterProteinEvalue( std::pow ((double) 10.0,attributes.value("prot_evalue").simplified().toDouble())); - _p_project->setFilterMinimumPeptidePerMatch( attributes.value("pep_number").simplified().toUInt()); - _p_project->setFilterCrossSamplePeptideNumber(false); + _automatic_filter_parameters.setFilterPeptideEvalue( attributes.value("pep_evalue").simplified().toDouble()); + _automatic_filter_parameters.setFilterProteinEvalue( std::pow ((double) 10.0,attributes.value("prot_evalue").simplified().toDouble())); + _automatic_filter_parameters.setFilterMinimumPeptidePerMatch( attributes.value("pep_number").simplified().toUInt()); + _automatic_filter_parameters.setFilterCrossSamplePeptideNumber(false); if (attributes.value("filter_to_all").simplified() == "true") { - _p_project->setFilterCrossSamplePeptideNumber(true); + _automatic_filter_parameters.setFilterCrossSamplePeptideNumber(true); } qDebug() << "startElement_filter_params end" ; return true; @@ -331,6 +331,7 @@ QString XpipSaxHandler::errorString() const { bool XpipSaxHandler::endDocument() { + _p_project->updateAutomaticFilters(_automatic_filter_parameters); return true; } diff --git a/src/input/xpipsaxhandler.h b/src/input/xpipsaxhandler.h index ae9e8ff12..7a6e471f1 100644 --- a/src/input/xpipsaxhandler.h +++ b/src/input/xpipsaxhandler.h @@ -78,6 +78,7 @@ private: std::vector<QString> _tag_stack; QString _errorStr; QString _current_text; + AutomaticFilterParameters _automatic_filter_parameters; Project * _p_project; ProteinMatch * _p_protein_match; -- GitLab