From ee09dcc411581af643a48e69a7273dc2e38507a1 Mon Sep 17 00:00:00 2001 From: Olivier Langella <olivier.langella@u-psud.fr> Date: Thu, 18 Oct 2018 21:36:02 +0200 Subject: [PATCH] NSAF indice handles labeling methods --- src/core/identificationgroup.cpp | 26 ++++++++------ src/core/identificationgroup.h | 10 ++++-- src/core/proteinmatch.cpp | 21 ++++++----- src/core/proteinmatch.h | 9 +++-- src/output/ods/comparspectrasheet.cpp | 50 ++++++++++++++++++++------- src/output/ods/comparspectrasheet.h | 2 +- 6 files changed, 80 insertions(+), 38 deletions(-) diff --git a/src/core/identificationgroup.cpp b/src/core/identificationgroup.cpp index 1f805b5e6..5063f0bfb 100644 --- a/src/core/identificationgroup.cpp +++ b/src/core/identificationgroup.cpp @@ -55,14 +55,15 @@ IdentificationGroup::getGroupStore() const } pappso::pappso_double -IdentificationGroup::computeProtoNsafSum(const MsRun *p_msrun_id) const +IdentificationGroup::computeProtoNsafSum(const MsRun *p_msrun_id, + const Label *p_label) const { pappso::pappso_double nsaf_sum = 0; for(auto &p_protein_match : _protein_match_list) { if(p_protein_match->getValidationState() >= ValidationState::grouped) { - nsaf_sum += p_protein_match->getProtoNsaf(p_msrun_id); + nsaf_sum += p_protein_match->getProtoNsaf(p_msrun_id, p_label); } } return nsaf_sum; @@ -130,7 +131,8 @@ unsigned int IdentificationGroup::countDecoyProteinMatch(ValidationState state) const { return std::count_if( - _protein_match_list.begin(), _protein_match_list.end(), + _protein_match_list.begin(), + _protein_match_list.end(), [state](const ProteinMatch *p_protein_match) { if((p_protein_match->getProteinXtpSp().get()->isDecoy()) && (p_protein_match->getValidationState() >= state)) @@ -209,7 +211,8 @@ IdentificationGroup::countDecoyPeptideMatch(ValidationState state) const unsigned int IdentificationGroup::countProteinMatch(ValidationState state) const { - return std::count_if(_protein_match_list.begin(), _protein_match_list.end(), + return std::count_if(_protein_match_list.begin(), + _protein_match_list.end(), [state](const ProteinMatch *p_protein_match) { if(p_protein_match->getValidationState() >= state) { @@ -302,8 +305,8 @@ IdentificationGroup::addIdentificationDataSourceP( IdentificationDataSource *p_identification_source) { addMsRunSp(p_identification_source->getMsRunSp()); - auto it = std::find(_id_source_list.begin(), _id_source_list.end(), - p_identification_source); + auto it = std::find( + _id_source_list.begin(), _id_source_list.end(), p_identification_source); if(it == _id_source_list.end()) { _id_source_list.push_back(p_identification_source); @@ -353,7 +356,8 @@ IdentificationGroup::countSubGroup() const void IdentificationGroup::collectMhDelta( - std::vector<pappso::pappso_double> &delta_list, pappso::PrecisionUnit unit, + std::vector<pappso::pappso_double> &delta_list, + pappso::PrecisionUnit unit, ValidationState state) const { std::set<const PeptideEvidence *> peptide_evidence_list; @@ -466,7 +470,9 @@ IdentificationGroup::getProteinFdr(ValidationState state) const void IdentificationGroup::getSameXicPeptideEvidenceList( std::vector<const PeptideEvidence *> &peptide_evidence_list, - const MsRun *p_msrun, const PeptideXtp *p_peptide, unsigned int charge) const + const MsRun *p_msrun, + const PeptideXtp *p_peptide, + unsigned int charge) const { if(!contains(p_msrun)) return; @@ -475,8 +481,8 @@ IdentificationGroup::getSameXicPeptideEvidenceList( if(p_msrun == p_identification_source->getMsRunSp().get()) { p_identification_source->getPeptideEvidenceStore() - .getSameXicPeptideEvidenceList(peptide_evidence_list, p_msrun, - p_peptide, charge); + .getSameXicPeptideEvidenceList( + peptide_evidence_list, p_msrun, p_peptide, charge); } } } diff --git a/src/core/identificationgroup.h b/src/core/identificationgroup.h index 43e03e2bd..7ec739ac5 100644 --- a/src/core/identificationgroup.h +++ b/src/core/identificationgroup.h @@ -62,7 +62,9 @@ class IdentificationGroup * Warning: this is not NSAF, just a part * @param p_msrun_id pointer on the msrun to get NSAF. * */ - pappso::pappso_double computeProtoNsafSum(const MsRun *p_msrun_id) const; + pappso::pappso_double + computeProtoNsafSum(const MsRun *p_msrun_id, + const Label *p_label = nullptr) const; /** @brief count groups * */ @@ -152,7 +154,8 @@ class IdentificationGroup * each peptide evidence is only counted once */ void collectMhDelta(std::vector<pappso::pappso_double> &delta_list, - pappso::PrecisionUnit unit, ValidationState state) const; + pappso::PrecisionUnit unit, + ValidationState state) const; /** @brief look for a peptide in the same XIC @@ -163,7 +166,8 @@ class IdentificationGroup */ void getSameXicPeptideEvidenceList( std::vector<const PeptideEvidence *> &peptide_evidence_list, - const MsRun *p_msrun, const PeptideXtp *p_peptide, + const MsRun *p_msrun, + const PeptideXtp *p_peptide, unsigned int charge) const; private: diff --git a/src/core/proteinmatch.cpp b/src/core/proteinmatch.cpp index 343155ed6..64149784c 100644 --- a/src/core/proteinmatch.cpp +++ b/src/core/proteinmatch.cpp @@ -434,8 +434,10 @@ ProteinMatch::countPeptideMassCharge(ValidationState state, { if(p_label != nullptr) { - if(peptide_match.getPeptideEvidence()->getPeptideXtpSp().get()->getLabel() == - p_label) + if(peptide_match.getPeptideEvidence() + ->getPeptideXtpSp() + .get() + ->getLabel() == p_label) { sequence_list.insert( QString("%1-%2-%3") @@ -559,7 +561,8 @@ ProteinMatch::getLogEvalue(const MsRun *sp_msrun_id) const } pappso::pappso_double ProteinMatch::getNsaf(pappso::pappso_double proto_nsaf_sum, - const MsRun *p_msrun_id) const + const MsRun *p_msrun_id, + const Label *p_label) const { if(proto_nsaf_sum == 0) { @@ -568,11 +571,11 @@ ProteinMatch::getNsaf(pappso::pappso_double proto_nsaf_sum, "Error computing NSAF for protein %1 :\nproto_nsaf_sum is null") .arg(this->getProteinXtpSp().get()->getAccession())); } - return (getProtoNsaf(p_msrun_id) / proto_nsaf_sum); + return (getProtoNsaf(p_msrun_id, p_label) / proto_nsaf_sum); } pappso::pappso_double -ProteinMatch::getProtoNsaf(const MsRun *sp_msrun_id) const +ProteinMatch::getProtoNsaf(const MsRun *sp_msrun_id, const Label *p_label) const { try { @@ -582,8 +585,8 @@ ProteinMatch::getProtoNsaf(const MsRun *sp_msrun_id) const QObject::tr("protein has no amino acid sequence")); } pappso::pappso_double proto_nsaf = - (pappso::pappso_double)countSampleScan(ValidationState::validAndChecked, - sp_msrun_id) / + (pappso::pappso_double)countSampleScan( + ValidationState::validAndChecked, sp_msrun_id, p_label) / (pappso::pappso_double)_protein_sp.get()->size(); return proto_nsaf; } @@ -617,11 +620,11 @@ ProteinMatch::getPAI(const MsRun *sp_msrun_id, const Label *p_label) const } pappso::pappso_double -ProteinMatch::getEmPAI(const MsRun *sp_msrun_id) const +ProteinMatch::getEmPAI(const MsRun *sp_msrun_id, const Label *p_label) const { // compute emPAI, Ishihama 2005 pappso::pappso_double value = - std::pow(10.0, getPAI(sp_msrun_id)) - (pappso::pappso_double)1.0; + std::pow(10.0, getPAI(sp_msrun_id, p_label)) - (pappso::pappso_double)1.0; return value; } diff --git a/src/core/proteinmatch.h b/src/core/proteinmatch.h index e99e2ef5f..33ff923c7 100644 --- a/src/core/proteinmatch.h +++ b/src/core/proteinmatch.h @@ -72,7 +72,8 @@ class ProteinMatch * Warning: this is not NSAF, just a part * @param p_msrun_id pointer on the msrun to get NSAF. * */ - pappso::pappso_double getProtoNsaf(const MsRun *p_msrun_id) const; + pappso::pappso_double getProtoNsaf(const MsRun *p_msrun_id, + const Label *p_label = nullptr) const; /** @brief compute NSAF within msrun : normalized spectral abundance factor * (NSAF) Florens L., Carozza M. J. C., Swanson S. K., et al. Analyzing @@ -84,7 +85,8 @@ class ProteinMatch * @param p_msrun_id pointer on the msrun to get NSAF * */ pappso::pappso_double getNsaf(pappso::pappso_double proto_nsaf_sum, - const MsRun *p_msrun_id) const; + const MsRun *p_msrun_id, + const Label *p_label = nullptr) const; /** @brief compute Protein Abundance Index (PAI) within sample * PAI computation (Rappsilber et al. 2002) @@ -95,7 +97,8 @@ class ProteinMatch /** @brief compute emPAI within sample * Ishihama 2005 * */ - pappso::pappso_double getEmPAI(const MsRun *sp_msrun_id = nullptr) const; + pappso::pappso_double getEmPAI(const MsRun *sp_msrun_id = nullptr, + const Label *p_label = nullptr) const; void setProteinXtpSp(ProteinXtpSp protein_sp); void addPeptideMatch(const PeptideMatch &peptide_match); diff --git a/src/output/ods/comparspectrasheet.cpp b/src/output/ods/comparspectrasheet.cpp index b2fe6ae6f..b9ee4cc32 100644 --- a/src/output/ods/comparspectrasheet.cpp +++ b/src/output/ods/comparspectrasheet.cpp @@ -110,7 +110,7 @@ ComparEmpaiSheet::writeComparValue(const ProteinMatch *p_protein_match, const Label *p_label) { qDebug() << "ComparEmpaiSheet::writeComparValue begin"; - _p_writer->writeCell(p_protein_match->getEmPAI(p_msrun)); + _p_writer->writeCell(p_protein_match->getEmPAI(p_msrun, p_label)); qDebug() << "ComparEmpaiSheet::writeComparValue end"; } @@ -130,21 +130,47 @@ ComparNsafSheet::writeComparValue(const ProteinMatch *p_protein_match, { qDebug() << "ComparNsafSheet::writeComparValue begin"; pappso::pappso_double proto_nsaf_sum = 0; - std::pair<std::map<const MsRun *, pappso::pappso_double>::iterator, bool> - ret = _map_proto_nsaf_sum_by_msrun.insert( - std::pair<const MsRun *, pappso::pappso_double>(p_msrun, 0)); - if(ret.second == false) + + if(_label_list.size() > 0) { - //"element 'z' already existed"; - proto_nsaf_sum = ret.first->second; + std::pair<std::map<QString, pappso::pappso_double>::iterator, bool> ret = + _map_proto_nsaf_sum_by_msrun.insert( + std::pair<QString, pappso::pappso_double>( + QString("%1--%2").arg(p_msrun->getXmlId()).arg(p_label->getXmlId()), + 0)); + if(ret.second == false) + { + //"element 'z' already existed"; + proto_nsaf_sum = ret.first->second; + } + else + { + proto_nsaf_sum = _p_current_identification_group->computeProtoNsafSum( + p_msrun, p_label); + ret.first->second = proto_nsaf_sum; + } + + _p_writer->writeCell( + p_protein_match->getNsaf(proto_nsaf_sum, p_msrun, p_label)); } else { - proto_nsaf_sum = - _p_current_identification_group->computeProtoNsafSum(p_msrun); - ret.first->second = proto_nsaf_sum; + std::pair<std::map<QString, pappso::pappso_double>::iterator, bool> ret = + _map_proto_nsaf_sum_by_msrun.insert( + std::pair<QString, pappso::pappso_double>(p_msrun->getXmlId(), 0)); + if(ret.second == false) + { + //"element 'z' already existed"; + proto_nsaf_sum = ret.first->second; + } + else + { + proto_nsaf_sum = + _p_current_identification_group->computeProtoNsafSum(p_msrun); + ret.first->second = proto_nsaf_sum; + } + + _p_writer->writeCell(p_protein_match->getNsaf(proto_nsaf_sum, p_msrun)); } - - _p_writer->writeCell(p_protein_match->getNsaf(proto_nsaf_sum, p_msrun)); qDebug() << "ComparNsafSheet::writeComparValue end"; } diff --git a/src/output/ods/comparspectrasheet.h b/src/output/ods/comparspectrasheet.h index 737af6c1e..d129f71f7 100644 --- a/src/output/ods/comparspectrasheet.h +++ b/src/output/ods/comparspectrasheet.h @@ -104,7 +104,7 @@ class ComparNsafSheet : public ComparBaseSheet const Label *p_label = nullptr) override; private: - std::map<const MsRun *, pappso::pappso_double> _map_proto_nsaf_sum_by_msrun; + std::map<QString, pappso::pappso_double> _map_proto_nsaf_sum_by_msrun; }; #endif // COMPARSPECTRASHEET_H -- GitLab