diff --git a/src/core/identificationgroup.cpp b/src/core/identificationgroup.cpp index 2403b432b69c08e6250936f8dc2f3b0455db40ea..4b3c3e3b7fec64f60a5c26a96e8c74261aa7b4f5 100644 --- a/src/core/identificationgroup.cpp +++ b/src/core/identificationgroup.cpp @@ -184,6 +184,9 @@ const std::vector<MsRunSp> & IdentificationGroup::getMsRunSpList() const { const std::vector<IdentificationDataSource *> & IdentificationGroup::getIdentificationDataSourceList() const { return _id_source_list; } +const std::vector<ProteinMatch *> & IdentificationGroup::getProteinMatchList() const { + return _protein_match_list; +} std::vector<ProteinMatch *> & IdentificationGroup::getProteinMatchList() { return _protein_match_list; } diff --git a/src/core/identificationgroup.h b/src/core/identificationgroup.h index 01dbafba4159aa9d22ce0fc55ffb07deb85a827e..243f77811c8cbe52fa210f526f65e130125ed704 100644 --- a/src/core/identificationgroup.h +++ b/src/core/identificationgroup.h @@ -50,6 +50,7 @@ public: const GroupStore & getGroupStore() const; void addProteinMatch(ProteinMatch * protein_match); std::vector<ProteinMatch *> & getProteinMatchList(); + const std::vector<ProteinMatch *> & getProteinMatchList() const; void addIdentificationDataSourceP(IdentificationDataSource * p_identification_source); const PtmGroupingExperiment * getPtmGroupingExperiment() const; diff --git a/src/core/labeling/label.cpp b/src/core/labeling/label.cpp index e3093ea61f9e09705e3b49f57bae7bc93dc25333..c0a50b11eace2add49ea370a4b796497887dfbfc 100644 --- a/src/core/labeling/label.cpp +++ b/src/core/labeling/label.cpp @@ -85,6 +85,10 @@ const QString & Label::getXmlId() const { return _xml_id; } +const std::vector<LabelModification> & Label::getLabelModifictionList() const { + return _modification_list; +} + void Label::writeMassChroqMl(QXmlStreamWriter* output_stream) const { @@ -95,11 +99,11 @@ void Label::writeMassChroqMl(QXmlStreamWriter* output_stream) const { // <mod at="K" value="28.0" acc="MOD:00429"/> for (const LabelModification label_modification: _modification_list) { output_stream->writeStartElement("mod"); - output_stream->writeAttribute("at",label_modification.at); + output_stream->writeAttribute("at",label_modification.at); output_stream->writeAttribute("value",Utils::getXmlDouble(label_modification.modification->getMass())); output_stream->writeAttribute("acc",label_modification.modification->getAccession()); - output_stream->writeEndElement(); - output_stream->writeComment(label_modification.modification->getName()); + output_stream->writeEndElement(); + output_stream->writeComment(label_modification.modification->getName()); } // </isotope_label> output_stream->writeEndElement(); diff --git a/src/core/labeling/label.h b/src/core/labeling/label.h index ba941181b6f58f67b326f38fe180a1641897c64e..00140c1d8de0197ceaea7bb1c4f5b9a312eebe36 100644 --- a/src/core/labeling/label.h +++ b/src/core/labeling/label.h @@ -52,6 +52,9 @@ public: pappso::PeptideSp getLabeledPeptideSp(const pappso::Peptide * p_peptide) const; void writeMassChroqMl(QXmlStreamWriter* output_stream) const; const QString & getXmlId() const; + + const std::vector<LabelModification> & getLabelModifictionList() const; + private: QString _xml_id; std::vector<LabelModification> _modification_list; diff --git a/src/core/peptidextp.h b/src/core/peptidextp.h index 4701e551fc1d33529289681c1817c0e5126376b4..8353eb854dd3362ee511341fea786989e5fdc0be 100644 --- a/src/core/peptidextp.h +++ b/src/core/peptidextp.h @@ -42,7 +42,7 @@ public: PeptideXtpSp makePeptideXtpSp() const; - /** \brief get the tehoretical mass to use for grouping + /** \brief get the theoretical mass to use for grouping * This mass might be different than the true peptide mass to recognize that a tagged * peptide with taget modification is a light, inter or heavy version of the same peptide */ diff --git a/src/output/xpip.cpp b/src/output/xpip.cpp index cc2f478ee56a0650ac83d02a74e02cb7f03475ff..20f9077c2a24162bd56628e3bf7f3a804b588180 100644 --- a/src/output/xpip.cpp +++ b/src/output/xpip.cpp @@ -31,6 +31,8 @@ #include "../config.h" #include <QDateTime> #include <pappsomspp/pappsoexception.h> +#include <pappsomspp/utils.h> +#include <QDebug> Xpip::Xpip(const QString & out_filename) { @@ -117,8 +119,10 @@ void Xpip::write(ProjectSp sp_project) { writeMsrunList(_sp_project.get()->getMsRunStore()); writeIdentificationDataSourceList(_sp_project.get()->getIdentificationDataSourceStore()); + writeProteinList(); + writePeptideList(); - + writeIdentificationGroupList(); _output_stream->writeEndDocument(); } void Xpip::writeDoubleAttribute(const QString & attribute, pappso::pappso_double value) { @@ -135,13 +139,14 @@ void Xpip::writeBooleanAttribute(const QString & attribute, bool value) { } void Xpip::writeFilterParameters(const AutomaticFilterParameters & filters) { - + qDebug() << "Xpip::writeFilterParameters begin"; _output_stream->writeStartElement("filter_params"); writeDoubleAttribute("pep_evalue",filters.getFilterPeptideEvalue()); writeDoubleAttribute("prot_evalue",filters.getFilterProteinEvalue()); _output_stream->writeAttribute("pep_number",QString("%1").arg(filters.getFilterMinimumPeptidePerMatch())); writeBooleanAttribute("cross_sample",filters.getFilterCrossSamplePeptideNumber()); _output_stream->writeEndElement(); + qDebug() << "Xpip::writeFilterParameters end"; } void Xpip::writeDescription() { @@ -206,6 +211,7 @@ void Xpip::writeMsrunList(const MsRunStore & msrun_store) { } void Xpip::writeFastaFileList(const FastaFileStore & fasta_store) { + qDebug() << "Xpip::writeFastaFileList begin"; _output_stream->writeStartElement("fasta_file_list"); for (FastaFileSp fasta_file_sp : fasta_store.getFastaFileList()) { _output_stream->writeStartElement("fasta_file"); @@ -215,4 +221,149 @@ void Xpip::writeFastaFileList(const FastaFileStore & fasta_store) { _output_stream->writeEndElement(); } _output_stream->writeEndElement(); + qDebug() << "Xpip::writeFastaFileList end"; +} + +void Xpip::writeProteinList() { + qDebug() << "Xpip::writeProteinList begin"; + _output_stream->writeStartElement("protein_list"); + const ProteinStore & protein_store = _sp_project.get()->getProteinStore(); + for (std::pair<QString, ProteinXtpSp> protein_pair : protein_store.getProteinMap()) { + const ProteinXtp * p_protein = protein_pair.second.get(); + _output_stream->writeStartElement("protein"); + _output_stream->writeAttribute("acc",p_protein->getAccession()); + _output_stream->writeAttribute("description",p_protein->getDescription()); + _output_stream->writeAttribute("is_decoy","false"); + if (p_protein->isDecoy()) { + _output_stream->writeAttribute("is_decoy","true"); + } + _output_stream->writeAttribute("is_contaminant","false"); + if (p_protein->isContaminant()) { + _output_stream->writeAttribute("is_contaminant","true"); + } + + _output_stream->writeStartElement("sequence"); + _output_stream->writeCharacters(p_protein->getSequence()); + _output_stream->writeEndElement(); + + for (DbXref db_xref : p_protein->getDbxrefList()) { + _output_stream->writeStartElement("dbxref"); + _output_stream->writeAttribute("acc",db_xref.accession); + _output_stream->writeAttribute("database",QString("%1").arg(static_cast<std::int8_t>(db_xref.database))); + _output_stream->writeEndElement(); + } + _output_stream->writeEndElement(); + } + _output_stream->writeEndElement(); + qDebug() << "Xpip::writeProteinList end"; +} + +QString Xpip::getPeptideId(std::size_t crc_peptide) const { + return QString("p%1").arg(pappso::Utils::getLexicalOrderedString(crc_peptide)); +} + +void Xpip::writeLabelingMethod() { + qDebug() << "Xpip::writeLabelingMethod begin"; + + LabelingMethod * p_labeling_method = _sp_project.get()->getLabelingMethodSp().get(); + if (p_labeling_method == nullptr) return; + _output_stream->writeStartElement("label_method"); + _output_stream->writeAttribute("id",p_labeling_method->getXmlId()); + + _output_stream->writeStartElement("label_list"); + for (const Label * p_label : p_labeling_method->getLabelList()) { + _output_stream->writeStartElement("label"); + _output_stream->writeAttribute("id", p_label->getXmlId()); + for (const LabelModification label_modification : p_label->getLabelModifictionList()) { + _output_stream->writeStartElement("label_modification"); + _output_stream->writeAttribute("at", label_modification.at); + _output_stream->writeAttribute("mod", label_modification.modification->getAccession()); + _output_stream->writeEndElement();// label_modification + } + _output_stream->writeEndElement();// label + } + _output_stream->writeEndElement();// label_list + + _output_stream->writeEndElement();// label_method + qDebug() << "Xpip::writeLabelingMethod end"; +} + +void Xpip::writePeptideList() { + qDebug() << "Xpip::writePeptideList begin"; + _output_stream->writeStartElement("peptide_list"); + + writeLabelingMethod(); + + const PeptideStore & peptide_store = _sp_project.get()->getPeptideStore(); + _output_stream->writeStartElement("modification_list"); + for (pappso::AaModificationP mod_p : peptide_store.getModificationCollection()) { + QString id = QString("mod%1").arg(pappso::Utils::getLexicalOrderedString(_map_modifications.size()+1)); + _map_modifications.insert(std::pair<pappso::AaModificationP, QString>(mod_p, id)); + _output_stream->writeStartElement("modification"); + _output_stream->writeAttribute("id", id); + _output_stream->writeAttribute("mod", mod_p->getAccession()); + _output_stream->writeEndElement();// modification + } + _output_stream->writeEndElement();// modification_list + + for (std::pair<std::size_t, PeptideXtpSp> peptide_pair : peptide_store.getPeptideMap()) { + const PeptideXtp * p_peptide = peptide_pair.second.get(); + _output_stream->writeStartElement("peptide"); + QString idp = QString("p%1").arg(pappso::Utils::getLexicalOrderedString(_map_peptides.size()+1)); + _map_peptides.insert(std::pair<const PeptideXtp *, QString>(p_peptide, idp)); + _output_stream->writeAttribute("id",idp); + _output_stream->writeAttribute("seq",p_peptide->getSequence()); + + const Label * p_label = p_peptide->getLabel(); + if (p_label != nullptr) { + _output_stream->writeAttribute("label_id",p_label->getXmlId()); + } + + + unsigned int i=1; + for (const pappso::Aa & amino_acid: *p_peptide) { + + std::list<pappso::AaModificationP> aa_modif_list = amino_acid.getModificationList(); + + + for (auto && aa_modif : aa_modif_list) { + if (!aa_modif->isInternal()) { + _output_stream->writeStartElement("mod"); + _output_stream->writeAttribute("ref", _map_modifications.at(aa_modif)); + _output_stream->writeAttribute("position", QString ("%1").arg(i)); + _output_stream->writeAttribute("aa", QString(amino_acid.getLetter())); + _output_stream->writeEndElement();// mod + } + } + i++; + } + + _output_stream->writeEndElement();// peptide + } + _output_stream->writeEndElement(); //peptide_list + qDebug() << "Xpip::writePeptideList end"; +} + +void Xpip::writeIdentificationGroupList() { + qDebug() << "Xpip::writeIdentificationGroupList begin"; + _output_stream->writeStartElement("identification_group_list"); + for (const IdentificationGroup * p_identification_group : _sp_project.get()->getIdentificationGroupList()) { + //std::vector<ProteinMatch *> & getProteinMatchList() + writeIdentificationGroup(p_identification_group); + } + _output_stream->writeEndElement(); //identification_group_list + qDebug() << "Xpip::writeIdentificationGroupList end"; +} + +void Xpip::writeIdentificationGroup(const IdentificationGroup * p_identification_group) { + qDebug() << "Xpip::writeIdentificationGroup begin"; + _output_stream->writeStartElement("protein_match_list"); + for (const ProteinMatch * p_protein_match : p_identification_group->getProteinMatchList()) { + //std::vector<ProteinMatch *> & getProteinMatchList() + _output_stream->writeStartElement("protein_match"); + _output_stream->writeAttribute("acc", p_protein_match->getProteinXtpSp().get()->getAccession()); + _output_stream->writeEndElement();// protein_match + } + _output_stream->writeEndElement(); //protein_match_list + qDebug() << "Xpip::writeIdentificationGroup end"; } diff --git a/src/output/xpip.h b/src/output/xpip.h index 595eae0ea2b83f415ce14709170dd47d25773561..2775fb89b2a5a5b393e52061cab7039304e41ae1 100644 --- a/src/output/xpip.h +++ b/src/output/xpip.h @@ -53,12 +53,22 @@ private : void writeFastaFileList(const FastaFileStore & fasta_store); void writeDoubleAttribute(const QString & attribute, pappso::pappso_double value); void writeBooleanAttribute(const QString & attribute, bool value); + + void writeProteinList(); + void writePeptideList(); + void writeLabelingMethod(); + void writeIdentificationGroupList(); + void writeIdentificationGroup(const IdentificationGroup * p_identification_group); + QString getPeptideId(std::size_t crc_peptide) const; private : QFile * _output_file; QXmlStreamWriter * _output_stream; ProjectSp _sp_project; + + std::map<pappso::AaModificationP, QString> _map_modifications; + std::map<const PeptideXtp *, QString> _map_peptides; }; diff --git a/src/utils/peptidestore.cpp b/src/utils/peptidestore.cpp index aeba5eedd6f53146e250348c82308dbf5fa697e8..0e3ce9405e4ae24492321d032770b052802954da 100644 --- a/src/utils/peptidestore.cpp +++ b/src/utils/peptidestore.cpp @@ -103,3 +103,7 @@ void PeptideStore::setLabelingMethodSp(LabelingMethodSp labeling_method_sp) { peptide_xtp.get()->applyLabelingMethod(labeling_method_sp); } } + +const std::unordered_map<std::size_t, PeptideXtpSp> & PeptideStore::getPeptideMap() const { + return _map_crc_peptide_list; +} diff --git a/src/utils/peptidestore.h b/src/utils/peptidestore.h index 81dc770b32214dadfd6ae23942e9a5a0d88ad5b0..cb2099c163fe31b035e793d03539d2ccb6e4104f 100644 --- a/src/utils/peptidestore.h +++ b/src/utils/peptidestore.h @@ -56,6 +56,8 @@ public: /** @brief apply labeling method to all peptide match * */ void setLabelingMethodSp(LabelingMethodSp labeling_method_sp); + + const std::unordered_map<std::size_t, PeptideXtpSp> & getPeptideMap() const; private: /** @brief reset labeling method * */ diff --git a/src/utils/proteinstore.cpp b/src/utils/proteinstore.cpp index 7a86409776226d96fe7d5ec848ab1b39592decb0..9a23471dc221c6eb52e8cee0dff04790f03af6ac 100644 --- a/src/utils/proteinstore.cpp +++ b/src/utils/proteinstore.cpp @@ -69,6 +69,11 @@ void ProteinStore::setRegexpContaminantPattern(const QString & pattern) { QRegExp ProteinStore::getRegexpDecoy() const { return (_regexp_decoy); } + +const std::map<QString, ProteinXtpSp> & ProteinStore::getProteinMap() const { + return _map_accession_protein_list; +} + void ProteinStore::setRegexpDecoyPattern(const QString & pattern) { _regexp_decoy.setPattern(pattern); diff --git a/src/utils/proteinstore.h b/src/utils/proteinstore.h index fa06e1304bda2ee61eab255bb1f45fe70899fe63..14c5ef5fc82e29a3d8040839af6c0a71375d650c 100644 --- a/src/utils/proteinstore.h +++ b/src/utils/proteinstore.h @@ -69,6 +69,8 @@ public: void setContaminantAccession(QString accession); void setDecoyAccession(QString accession); + + const std::map<QString, ProteinXtpSp> & getProteinMap() const; private : void setProteinInformations(ProteinXtpSp & protein_in);