From c3af4de4098356bc696adbe545a3de29384f6005 Mon Sep 17 00:00:00 2001
From: Olivier Langella <Olivier.Langella@moulon.inra.fr>
Date: Sun, 19 Mar 2017 08:02:31 +0100
Subject: [PATCH] first evalue filter

---
 src/core/identificationgroup.cpp |  4 +++-
 src/core/peptidematch.cpp        |  3 +++
 src/core/peptidematch.h          |  1 +
 src/core/project.cpp             | 24 ++++++++++++++++++++++++
 src/core/project.h               | 15 +++++++++++++++
 src/input/xpipsaxhandler.cpp     | 14 +++++++++++---
 6 files changed, 57 insertions(+), 4 deletions(-)

diff --git a/src/core/identificationgroup.cpp b/src/core/identificationgroup.cpp
index 0345b1f62..f251e0bb2 100644
--- a/src/core/identificationgroup.cpp
+++ b/src/core/identificationgroup.cpp
@@ -22,6 +22,7 @@
 ******************************************************************************/
 
 #include "identificationgroup.h"
+#include "project.h"
 
 IdentificationGroup::IdentificationGroup(Project * project)
 {
@@ -38,7 +39,8 @@ IdentificationGroup::~IdentificationGroup()
 }
 
 bool IdentificationGroup::isValid(ProteinMatch* p_protein_match) const {
-    return true;
+    return _p_project->isValid(p_protein_match);
+
 }
 
 void IdentificationGroup::addProteinMatch(ProteinMatch * protein_match) {
diff --git a/src/core/peptidematch.cpp b/src/core/peptidematch.cpp
index d150c5ab5..75c753f69 100644
--- a/src/core/peptidematch.cpp
+++ b/src/core/peptidematch.cpp
@@ -35,6 +35,9 @@ void PeptideMatch::setEvalue(pappso::pappso_double evalue) {
     _evalue = evalue;
 }
 
+pappso::pappso_double PeptideMatch::getEvalue() const {
+    return _evalue;
+}
 void PeptideMatch::setExperimentalMass(pappso::pappso_double exp_mass) {
     _exp_mass =exp_mass;
 }
diff --git a/src/core/peptidematch.h b/src/core/peptidematch.h
index 6f2672feb..92b42b92d 100644
--- a/src/core/peptidematch.h
+++ b/src/core/peptidematch.h
@@ -48,6 +48,7 @@ public :
     pappso::pappso_double getRetentionTime() const;
     unsigned int getCharge() const;
     pappso::PeptideSp getPeptideSp() const;
+    pappso::pappso_double getEvalue() const;
 
 private :
     pappso::MsRunIdSp _msrunid_sp;
diff --git a/src/core/project.cpp b/src/core/project.cpp
index 26c906674..255d23ee2 100644
--- a/src/core/project.cpp
+++ b/src/core/project.cpp
@@ -23,6 +23,7 @@
 #include "project.h"
 #include "../input/xpipsaxhandler.h"
 #include "peptidematch.h"
+#include "proteinmatch.h"
 
 Project::Project()
 {
@@ -42,6 +43,19 @@ ProjectSp Project::makeProjectSp() const {
     return std::make_shared<Project>(*this);
 }
 
+void Project::setFilterPeptideEvalue( pappso::pappso_double evalue) {
+    _filter_minimum_peptide_evalue = evalue;
+}
+
+void Project::setFilterProteinEvalue( pappso::pappso_double evalue) {
+    _filter_minimum_protein_evalue = evalue;
+}
+void Project::setFilterMinimumPeptidePerMatch(unsigned int number) {
+    _filter_minimum_peptide_per_match = number;
+}
+void Project::setFilterCrossSamplePeptideNumber(bool cross) {
+    _filter_is_cross_sample_peptide_number = cross;
+}
 
 IdentificationGroup* Project::newIdentificationGroup() {
     _p_current_identification_group =  new IdentificationGroup(this);
@@ -83,5 +97,15 @@ IdentificationGroup* Project::getCurrentIdentificationGroupP() const {
 }
 
 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 2bc65e7e0..8f60fcf8b 100644
--- a/src/core/project.h
+++ b/src/core/project.h
@@ -25,11 +25,13 @@
 
 #include<memory>
 #include "identificationgroup.h"
+#include <pappsomspp/types.h>
 
 class Project;
 typedef std::shared_ptr<Project> ProjectSp;
 
 class PeptideMatch;
+class ProteinMatch;
 
 class Project
 {
@@ -44,10 +46,23 @@ public:
     /** @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;
+    
+    void setFilterPeptideEvalue( pappso::pappso_double evalue);
+    void setFilterProteinEvalue( pappso::pappso_double evalue);
+    void setFilterMinimumPeptidePerMatch(unsigned int number);
+    void setFilterCrossSamplePeptideNumber(bool cross);
 
 private :
     std::vector<IdentificationGroup *> _identification_goup_list;
     IdentificationGroup* _p_current_identification_group = nullptr;
+    
+    pappso::pappso_double _filter_minimum_peptide_evalue=1;
+    pappso::pappso_double _filter_minimum_protein_evalue=1;
+    unsigned int _filter_minimum_peptide_per_match=1;
+    bool _filter_is_cross_sample_peptide_number=false;
 };
 
 #endif // PROJECT_H
diff --git a/src/input/xpipsaxhandler.cpp b/src/input/xpipsaxhandler.cpp
index 1afa8677c..2cb9a30c1 100644
--- a/src/input/xpipsaxhandler.cpp
+++ b/src/input/xpipsaxhandler.cpp
@@ -23,6 +23,7 @@
 #include "xpipsaxhandler.h"
 #include <pappsomspp/msrun/msrunid.h>
 #include <pappsomspp/exception/exceptionnotfound.h>
+#include <cmath>
 
 XpipSaxHandler::XpipSaxHandler(Project * p_project):_p_project(p_project)
 {
@@ -133,6 +134,13 @@ 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);
+    if (attributes.value("filter_to_all").simplified() == "true") {
+        _p_project->setFilterCrossSamplePeptideNumber(true);
+    }
     qDebug() << "startElement_filter_params end" ;
     return true;
 }
@@ -201,15 +209,15 @@ bool XpipSaxHandler::startElement_protein(QXmlAttributes attributes) {
 
     qDebug() << "startElement_protein ";
     /*
-     * <protein peptide_number="268" evalue="-432.77353" URL="Genome_Z_mays_5a.fasta" 
-     * description="GRMZM2G083841_P01 P04711 Phosphoenolpyruvate carboxylase 1 (PEPCase 1)(PEPC 1)(EC 4.1.1.31) 
+     * <protein peptide_number="268" evalue="-432.77353" URL="Genome_Z_mays_5a.fasta"
+     * description="GRMZM2G083841_P01 P04711 Phosphoenolpyruvate carboxylase 1 (PEPCase 1)(PEPC 1)(EC 4.1.1.31)
      * seq=translation; coord=9:61296279..61301686:1; parent_transcript=GRMZM2G083841_T01; parent_gene=GRMZM2G083841">
                 <protein_evalue evalue="-399.36093" sample="20120906_balliau_extract_1_A02_urzb-1"/>
                 <protein_evalue evalue="-384.54382" sample="20120906_balliau_extract_1_A01_urnb-1"/>
                 <sequence>MASTKAPGPGEKHHSIDAQLRQLVPGKVSEDDKLIEYDALLVDRFLNILQDLHGPSLREFVQECYEVSADYEGKGDTTKLGELGAKLTGLAPADAILVASSILHMLNLANLAEEVQIAHRRRNSKLKKGGFADEGSATTESDIEETLKRLVSEVGKSPEEVFEALKNQTVDLVFTAHPTQSARRSLLQKNARIRNCLTQLNAKDITDDDKQELDEALQREIQAAFRTDEIRRAQPTPQDEMRYGMSYIHETVWKGVPKFLRRVDTALKNIGINERLPYNVSLIRFSSWMGGDRDGNPRVTPEVTRDVCLLARMMAANLYIDQIEELMFELSMWRCNDELRVRAEELHSSSGSKVTKYYIEFWKQIPPNEPYRVILGHVRDKLYNTRERARHLLASGVSEISAESSFTSIEEFLEPLELCYKSLCDCGDKAIADGSLLDLLRQVFTFGLSLVKLDIRQESERHTDVIDAITTHLGIGSYREWPEDKRQEWLLSELRGKRPLLPPDLPQTDEIADVIGAFHVLAELPPDSFGPYIISMATAPSDVLAVELLQRECGVRQPLPVVPLFERLADLQSAPASVERLFSVDWYMDRIKGKQQVMVGYSDSGKDAGRLSAAWQLYRAQEEMAQVAKRYGVKLTLFHGRGGTVGRGGGPTHLAILSQPPDTINGSIRVTVQGEVIEFCFGEEHLCFQTLQRFTAATLEHGMHPPVSPKPEWRKLMDEMAVVATEEYRSVVVKEARFVEYFRSATPETEYGRMNIGSRPAKRRPGGGITTLRAIPWIFSWTQTRFHLPVWLGVGAAFKFAIDKDVRNFQVLKEMYNEWPFFRVTLDLLEMVFAKGDPGIAGLYDELLVAEELKPFGKQLRDKYVETQQLLLQIAGHKDILEGDPFLKQGLVLRNPYITTLNVFQAYTLKRIRDPNFKVTPQPPLSKEFADENKPAGLVKLNPASEYPPGLEDTLILTMKGIAAGMQNTG</sequence>
               </protein>
               */
-    _p_protein_match->setEvalue(attributes.value("evalue").toDouble());
+    _p_protein_match->setEvalue(std::pow ((double) 10.0, attributes.value("evalue").toDouble()));
     _current_protein.setDescription(attributes.value("description").simplified());
     _current_protein.setAccession(_current_protein.getDescription().split(" ").at(0));
     qDebug() << "startElement_protein end" ;
-- 
GitLab