diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ade8d7f8ff6358cefc73f955f75856bd65a4404a..21b70805f3b5b588efffde1cef92db591f9ea050 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 f251e0bb20ddd54a44550d65372740ceb3a3ea5c..3a7cea893b81bef77c8cd6a5419024b7a3f55357 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 71d5912864e05898ae54a7b0dc80b6708b7fafbf..dc448a6d71aed0e76a1a5e3dda17834349d9b1c3 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 75c753f69a5b32549bcb465a5a8728459ad25149..718d2e02591040041d1af213b7871797f1956a15 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 92b42b92d86d5bfa1576d9df8e0817b686791362..8d8f2664116bbb55f8d06be217ee6c0e14334531 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 4cdc329c1af94e35beae0f78ece2305f84721597..3e6a0955d343d0727f0090e5b5ab9f2f3398270e 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 b97e74130c9fd981aca292a8c2e8938753649b62..b5ddcdf6a2c58074dc43fb3ba5d9b9f4e74a2cda 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 fb14cd1b40da1db3951cc5c1c4cb94e7c4594f39..f72acb9d2e541bc225a47ed49b62d1197bc0ac68 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 a0a0f5999d34e6839c125ff26cba3c77656b580d..6fba08333efa79ab0a566d411baba1005a3c8d77 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 3096830a85debce124ce42832fa23b923e511294..f5e88e48c77b5d10e465053453f3ff3042c28b06 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 bd7b21d8226a922e574a0afdc47991ba0040dc3b..5ceaa2609ed249bf866e8b9a5c77d98ba480263c 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 2cb9a30c1a227dcfb190ef350f73b5df23c85e05..ca567de05ea9f401c0c249d43c2527c18b9f5e30 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 ae9e8ff1241f7e9c25c7afd204567e9b13377661..7a6e471f186c2ce994b06126bbc789ae30aace8f 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;