diff --git a/src/core/proteinmatch.cpp b/src/core/proteinmatch.cpp index 1bf326c9ee30a942169854df148eb4b21649e6c0..2ffadd6fd2072ec3f92668196895ca845595b18b 100644 --- a/src/core/proteinmatch.cpp +++ b/src/core/proteinmatch.cpp @@ -182,13 +182,21 @@ void ProteinMatch::countPeptideMassSample(std::vector<size_t> & count_peptide_ma } } } -std::vector<PeptideMatch> ProteinMatch::getPeptideMatchList(ValidationState state) const { +std::vector<PeptideMatch> ProteinMatch::getPeptideMatchList(ValidationState state, const MsRun * p_msrun_id) const { std::vector<PeptideMatch> peptide_match_list; for (auto & peptide_match : _peptide_match_list) { if (peptide_match.getPeptideEvidence()->getValidationState() >= state) { - peptide_match_list.push_back(peptide_match); + if (p_msrun_id == nullptr) { + peptide_match_list.push_back(peptide_match); + } + else { + if (peptide_match.getPeptideEvidence()->getMsRunP() == p_msrun_id) { + peptide_match_list.push_back(peptide_match); + } + } } } + //it should automatically use the move semantic : return peptide_match_list; } diff --git a/src/core/proteinmatch.h b/src/core/proteinmatch.h index 37ccefb7e4ac1e039c046f18c4a30e8368da2d89..2104a7120e82bc6dfa9864f67c0ab9e672edbbfb 100644 --- a/src/core/proteinmatch.h +++ b/src/core/proteinmatch.h @@ -80,8 +80,11 @@ public: const std::vector<PeptideMatch> & getPeptideMatchList() const; /** @brief get peptide match sublist with required validation state + * @param state the validation state to select + * @param sp_msrun_id the msrun to look for, if nullptr, then get peptide match overall MSruns * */ - std::vector<PeptideMatch> getPeptideMatchList(ValidationState state) const; + std::vector<PeptideMatch> getPeptideMatchList(ValidationState state, const MsRun * sp_msrun_id = nullptr) const; + void setChecked(bool arg1); bool isChecked() const; diff --git a/src/output/mcqr/mcqrscpeptide.cpp b/src/output/mcqr/mcqrscpeptide.cpp index e3331a745eb4f3e74260df2b9ef692fed05e95db..aac947d7aee3d7d801f8438f6e860b9a691555f3 100644 --- a/src/output/mcqr/mcqrscpeptide.cpp +++ b/src/output/mcqr/mcqrscpeptide.cpp @@ -57,7 +57,7 @@ void McqRscPeptide::writeHeaders(IdentificationGroup * p_ident) { _p_writer->writeCell("label"); _p_writer->writeCell("msrun"); _p_writer->writeCell("msrunfile"); - _p_writer->writeCell("sequence"); + //_p_writer->writeCell("sequence"); _p_writer->writeCell("sc"); //_p_writer->writeCell(p_protein_match->countSampleScan(state, p_msrun)); @@ -66,8 +66,9 @@ void McqRscPeptide::writeHeaders(IdentificationGroup * p_ident) { void McqRscPeptide::writeIdentificationGroup(IdentificationGroup * p_ident) { + ValidationState validation_state = ValidationState::grouped; - _ms_run_sp_list = p_ident->getMsRunSpList(); + std::vector<MsRunSp> ms_run_sp_list = p_ident->getMsRunSpList(); writeHeaders(p_ident); for (const std::pair<unsigned int, GroupingGroupSp> & group_pair : p_ident->getGroupStore().getGroupMap()) { @@ -80,7 +81,17 @@ void McqRscPeptide::writeIdentificationGroup(IdentificationGroup * p_ident) { }); for (auto & protein_match:protein_match_list) { - writeOneProtein(group_pair.second.get(), protein_match); + + //count number of scan fore each GrpPeptide + std::map<const pappso::GrpPeptide *, std::size_t> count_scan_zero; + for (const PeptideMatch & peptide_match:protein_match->getPeptideMatchList(validation_state) ) { + count_scan_zero.insert ( std::pair<const pappso::GrpPeptide *, std::size_t>(peptide_match.getPeptideEvidence()->getGrpPeptideSp().get(),0) ); + } + + for (auto & msrun_sp : ms_run_sp_list) { + std::vector<PeptideMatch> peptide_match_in_msrun = protein_match->getPeptideMatchList(validation_state, msrun_sp.get()); + writePeptidesInMsrun(msrun_sp.get(), peptide_match_in_msrun, count_scan_zero); + } } } @@ -88,33 +99,40 @@ void McqRscPeptide::writeIdentificationGroup(IdentificationGroup * p_ident) { } -void McqRscPeptide::writeOneProtein(const GroupingGroup * p_group, const ProteinMatch * p_protein_match) { +void McqRscPeptide::writePeptidesInMsrun(const MsRun * p_msrun,const std::vector<PeptideMatch> & peptide_match_in_msrun, const std::map<const pappso::GrpPeptide *, std::size_t> & count_scan_zero) { try { - qDebug() << "McqRscPeptide::writeOneProtein begin" ; - ValidationState validation_state = ValidationState::grouped; - - pappso::GrpProtein * p_grp_protein = p_protein_match->getGrpProteinSp().get(); - - ProteinXtp * p_protein = p_protein_match->getProteinXtpSp().get(); - - //for (MsRunSp & msrun_sp : _ms_run_sp_list) { - std::set<QString> peptide_list; - for (PeptideMatch & peptide_match : p_protein_match->getPeptideMatchList(validation_state)) { - peptide_list.insert( peptide_match.getPeptideEvidence()->getGrpPeptideSp().get()->getGroupingId()); + qDebug() << "McqRscPeptide::writePeptidesInMsrun begin" ; + //count number of scan fore each GrpPeptide + std::map<const pappso::GrpPeptide *, std::size_t> count_scan(count_scan_zero); + + + for (const PeptideMatch & peptide_match:peptide_match_in_msrun) { + std::pair<std::map<const pappso::GrpPeptide *, std::size_t>::iterator,bool> ret; + ret = count_scan.insert ( std::pair<const pappso::GrpPeptide *, std::size_t>(peptide_match.getPeptideEvidence()->getGrpPeptideSp().get(),0) ); + if (ret.second==false) { + //already exists + ret.first->second++; + } + else { + //error : it should exists + throw pappso::PappsoException(QObject::tr("error in %1 %2 %3").arg(__FILE__).arg(__FUNCTION__).arg(__LINE__)); + } } - - for (const QString & peptide_str :peptide_list) { + + for (const std::pair<const pappso::GrpPeptide *, std::size_t> & pair_count :count_scan) { _p_writer->writeLine(); - _p_writer->writeCell(peptide_str); - _p_writer->writeCell(p_grp_protein->getGroupingId()); - _p_writer->writeCell(p_protein->getAccession()); - _p_writer->writeCell(p_protein->getDescription()); + _p_writer->writeCell(pair_count.first->getGroupingId()); + _p_writer->writeCell(""); + _p_writer->writeCell(p_msrun->getXmlId()); + _p_writer->writeCell(p_msrun->getSampleName()); + //_p_writer->writeCell(pair.first->getSequence()); + _p_writer->writeCell((unsigned int) pair_count.second); } - qDebug() << "McqRscPeptide::writeOneProtein end" ; + qDebug() << "McqRscPeptide::writePeptidesInMsrun end" ; } catch (pappso::PappsoException error) { - throw pappso::PappsoException(QObject::tr("Error writing protein %1 :\n%2").arg(p_protein_match->getProteinXtpSp().get()->getAccession()).arg(error.qwhat())); + throw pappso::PappsoException(QObject::tr("Error writing scan count in msrun %1 :\n%2").arg(p_msrun->getXmlId()).arg(error.qwhat())); } } diff --git a/src/output/mcqr/mcqrscpeptide.h b/src/output/mcqr/mcqrscpeptide.h index 68641e21a1c7984c417db5fcce1852c3bade28d6..a2f2a80e91530ed0fa44ee70eb9e67fbc1f2139b 100644 --- a/src/output/mcqr/mcqrscpeptide.h +++ b/src/output/mcqr/mcqrscpeptide.h @@ -32,22 +32,22 @@ #include <odsstream/calcwriterinterface.h> #include "../../core/project.h" +#include <pappsomspp/grouping/grppeptide.h> class McqRscPeptide { public : McqRscPeptide (CalcWriterInterface * p_writer, const Project * p_project); - + void writeSheet(); private : void writeIdentificationGroup(IdentificationGroup * p_ident); void writeHeaders(IdentificationGroup * p_ident); - void writeOneProtein(const GroupingGroup * p_group, const ProteinMatch * p_protein_match); + void writePeptidesInMsrun(const MsRun * p_msrun,const std::vector<PeptideMatch> & peptide_match_in_msrun, const std::map<const pappso::GrpPeptide *, std::size_t> & count_scan_zero); private : const Project * _p_project; CalcWriterInterface * _p_writer; - std::vector<MsRunSp> _ms_run_sp_list; }; #endif // MCQRSCPEPTIDE_H