diff --git a/src/output/proticdbml.cpp b/src/output/proticdbml.cpp index 92052431759edcdf03d0562e57637af27132d8b9..eb1a5923bbdcf98ebb80e0c6b2c16b5b44d75237 100644 --- a/src/output/proticdbml.cpp +++ b/src/output/proticdbml.cpp @@ -68,7 +68,7 @@ ProticdbMl::~ProticdbMl() void ProticdbMl::close() { _output_stream->writeEndDocument(); _output_file->close(); - + qDebug() << "ProticdbMl::close end duration = " << _duracel.elapsed() << "ms"; } @@ -563,91 +563,121 @@ void ProticdbMl::writeMatchs(IdentificationGroup * p_identification) { _output_stream->writeEndElement();// "matchs"); } - -void ProticdbMl::writeMatch(std::vector<const ProteinMatch *> & protein_match_sg_list) { - - if (protein_match_sg_list.size() == 0) return; - //for (SubGroup sg : group.getSubGroupSet().getSubGroupList()) { - _output_stream->writeStartElement("match"); - - // samples - QStringList sample_name_list; - for (const PeptideMatch * p_peptide_match: protein_match_sg_list[0]->getPeptideMatchList(ValidationState::grouped)) { - sample_name_list << p_peptide_match->getMsRunP()->getSampleName(); - } - sample_name_list = sample_name_list.toSet().toList(); - for (QString sample_name :sample_name_list) { - _output_stream->writeStartElement("matchSample"); - _output_stream->writeAttribute( - "sample_id",_sample_to_id[sample_name]); - _output_stream->writeAttribute("name", sample_name); - _output_stream->writeEndElement();// "matchSample"); +const QString & ProticdbMl::getPeptideXmlId(const PeptideMatch* p_peptide_match) const { + QString peptide_key = getProticPeptideHitKey(p_peptide_match); + auto it = _peptidekey_to_id.find(peptide_key); + if (it == _peptidekey_to_id.end()) { + throw pappso::PappsoException(QObject::tr("Error peptide key %1 not found for peptide match %2 sample=%3 scan=%4 start=%5").arg(peptide_key) + .arg(p_peptide_match->getPeptideXtpSp().get()->toString()) + .arg(p_peptide_match->getMsRunP()->getXmlId()) + .arg(p_peptide_match->getScan()) + .arg(p_peptide_match->getStart()) + ); } + return it->second; - // proteins - for (const ProteinMatch * p_protein_match: protein_match_sg_list) { - _output_stream->writeStartElement("proteinHit"); - _output_stream->writeAttribute("sequence_id",QString("%1 %2").arg(p_protein_match->getProteinXtpSp().get()->getAccession()).arg(p_protein_match->getProteinXtpSp().get()->getDescription())); - // proteinHit.setAttribute("score", ""); - _output_stream->writeAttribute("rank", QString("%1").arg(p_protein_match->getGrpProteinSp().get()->getRank())); - - // //cvparam - writeCvParam("PROTICdbO:0000284",QString("%1").arg(p_protein_match->getProteinXtpSp().get()->getMass()), - "MW computation"); - // evalue - writeCvParam("PROTICdbO:0000291", Utils::getXmlDouble(p_protein_match->getLogEvalue()) - , "Xtandem log evalue"); - - // coverage - writeCvParam( - "PROTICdbO:0000285", Utils::getXmlDouble(p_protein_match->getCoverage()), - "protein coverage"); - - // [Term] - // id: PROTICdbO:0000335 - // name: X!TandemPipeline PAI - writeCvParam("PROTICdbO:0000335",Utils::getXmlDouble(p_protein_match->getPAI()), "PAI"); - - // [Term] - // id: PROTICdbO:0000337 - // name: protein group number - writeCvParam("PROTICdbO:0000337",p_protein_match->getGrpProteinSp().get()->getGroupingId(), "grouping number"); - - _output_stream->writeEndElement();// "proteinHit"); +} +const QString & ProticdbMl::getProteinXmlId(const ProteinMatch* p_protein_match) const { + auto it = _map_accession2xmlid.find(p_protein_match->getProteinXtpSp().get()->getAccession()); + if (it == _map_accession2xmlid.end()) { + throw pappso::PappsoException(QObject::tr("Error protein accession %1 not found for protein %2") + .arg(p_protein_match->getProteinXtpSp().get()->getAccession()) + .arg(p_protein_match->getProteinXtpSp().get()->getAccession())); } + return it->second; +} +void ProticdbMl::writeMatch(std::vector<const ProteinMatch *> & protein_match_sg_list) { + try { + if (protein_match_sg_list.size() == 0) return; + //for (SubGroup sg : group.getSubGroupSet().getSubGroupList()) { + _output_stream->writeStartElement("match"); + + // samples + QStringList sample_name_list; + for (const PeptideMatch * p_peptide_match: protein_match_sg_list[0]->getPeptideMatchList(ValidationState::grouped)) { + sample_name_list << p_peptide_match->getMsRunP()->getSampleName(); + } + sample_name_list = sample_name_list.toSet().toList(); + for (QString sample_name :sample_name_list) { + _output_stream->writeStartElement("matchSample"); + _output_stream->writeAttribute( + "sample_id",_sample_to_id[sample_name]); + _output_stream->writeAttribute("name", sample_name); + _output_stream->writeEndElement();// "matchSample"); + } - for (const ProteinMatch * p_protein_match: protein_match_sg_list) { - //peptides - for (const PeptideMatch * p_peptide_match: p_protein_match->getPeptideMatchList(ValidationState::grouped)) { - // peptidesHitRef - QString peptide_key = getProticPeptideHitKey(p_peptide_match); - QString peptide_xml_id = _peptidekey_to_id.at(peptide_key); + // proteins + for (const ProteinMatch * p_protein_match: protein_match_sg_list) { + _output_stream->writeStartElement("proteinHit"); + _output_stream->writeAttribute("sequence_id",QString("%1 %2").arg(p_protein_match->getProteinXtpSp().get()->getAccession()).arg(p_protein_match->getProteinXtpSp().get()->getDescription())); + // proteinHit.setAttribute("score", ""); + _output_stream->writeAttribute("rank", QString("%1").arg(p_protein_match->getGrpProteinSp().get()->getRank())); + + // //cvparam + writeCvParam("PROTICdbO:0000284",QString("%1").arg(p_protein_match->getProteinXtpSp().get()->getMass()), + "MW computation"); + // evalue + writeCvParam("PROTICdbO:0000291", Utils::getXmlDouble(p_protein_match->getLogEvalue()) + , "Xtandem log evalue"); + + // coverage + writeCvParam( + "PROTICdbO:0000285", Utils::getXmlDouble(p_protein_match->getCoverage()), + "protein coverage"); + + // [Term] + // id: PROTICdbO:0000335 + // name: X!TandemPipeline PAI + writeCvParam("PROTICdbO:0000335",Utils::getXmlDouble(p_protein_match->getPAI()), "PAI"); + + // [Term] + // id: PROTICdbO:0000337 + // name: protein group number + writeCvParam("PROTICdbO:0000337",p_protein_match->getGrpProteinSp().get()->getGroupingId(), "grouping number"); + + _output_stream->writeEndElement();// "proteinHit"); + } - _output_stream->writeStartElement("peptideHitRef"); - _output_stream->writeAttribute("peptide_hit_id", peptide_xml_id); + for (const ProteinMatch * p_protein_match: protein_match_sg_list) { + //peptides + for (const PeptideMatch * p_peptide_match: p_protein_match->getPeptideMatchList(ValidationState::grouped)) { + // peptidesHitRef + QString peptide_xml_id = getPeptideXmlId(p_peptide_match); + + _output_stream->writeStartElement("peptideHitRef"); + _output_stream->writeAttribute("peptide_hit_id", peptide_xml_id); + + _output_stream->writeStartElement("fromSeq"); + _output_stream->writeAttribute( + "seq_id", getProteinXmlId(p_protein_match)); + _output_stream->writeAttribute("start", QString("%1").arg(p_peptide_match->getStart()+1)); + _output_stream->writeAttribute("stop", QString("%1").arg(p_peptide_match->getStop()+1)); + QString residue_before_nter = "-"; + if (p_peptide_match->getStart() > 0) { + residue_before_nter = p_protein_match->getProteinXtpSp().get()->getSequence().mid(p_peptide_match->getStart()-1,1); + } + _output_stream->writeAttribute("residue_before_nter", residue_before_nter); + QString residue_after_cter = "-"; + if (p_peptide_match->getStop() < (p_protein_match->getProteinXtpSp().get()->getSequence().size()-1)) { + residue_after_cter = p_protein_match->getProteinXtpSp().get()->getSequence().mid(p_peptide_match->getStop(),1); + } + _output_stream->writeAttribute("residue_after_cter", residue_after_cter); - _output_stream->writeStartElement("fromSeq"); - _output_stream->writeAttribute( - "seq_id",_map_accession2xmlid.at(p_protein_match->getProteinXtpSp().get()->getAccession())); - _output_stream->writeAttribute("start", QString("%1").arg(p_peptide_match->getStart()+1)); - _output_stream->writeAttribute("stop", QString("%1").arg(p_peptide_match->getStop()+1)); - QString residue_before_nter = "-"; - if (p_peptide_match->getStart() > 0) { - residue_before_nter = p_protein_match->getProteinXtpSp().get()->getSequence().mid(p_peptide_match->getStart()-1,1); - } - _output_stream->writeAttribute("residue_before_nter", residue_before_nter); - QString residue_after_cter = "-"; - if (p_peptide_match->getStop() < (p_protein_match->getProteinXtpSp().get()->getSequence().size()-1)) { - residue_after_cter = p_protein_match->getProteinXtpSp().get()->getSequence().mid(p_peptide_match->getStop(),1); + _output_stream->writeEndElement();// fromSeq + _output_stream->writeEndElement();// peptideHitRef } - _output_stream->writeAttribute("residue_after_cter", residue_after_cter); - _output_stream->writeEndElement();// fromSeq - _output_stream->writeEndElement();// peptideHitRef } - + _output_stream->writeEndElement();// "match"); + } + catch (pappso::PappsoException &error) + { + throw pappso::PappsoException(QObject::tr("Error in ProticdbMl::writeMatch :\n%1").arg(error.qwhat())); + } + catch (std::exception &error) + { + throw pappso::PappsoException(QObject::tr("Error in ProticdbMl::writeMatch stdex :\n%1").arg(error.what())); } - _output_stream->writeEndElement();// "match"); } void ProticdbMl::writeOboModif(pappso::AaModificationP mod) { _output_stream->writeStartElement("cvParam"); diff --git a/src/output/proticdbml.h b/src/output/proticdbml.h index 65f6bbb06159dab8bdb8747ba58549d3de6a389c..df91fcb066716e9b917ae34249b4e16e98585b00 100644 --- a/src/output/proticdbml.h +++ b/src/output/proticdbml.h @@ -66,6 +66,9 @@ private : void writeMatchs(IdentificationGroup * p_identification); void writeMatch(std::vector<const ProteinMatch *> & protein_match_sg_list); + const QString & getPeptideXmlId(const PeptideMatch* p_peptide_match) const; + const QString & getProteinXmlId(const ProteinMatch* p_protein_match) const; + private : QFile * _output_file; QXmlStreamWriter * _output_stream; diff --git a/src/resources/catalog_label.xml b/src/resources/catalog_label.xml index 0da0a47b47dcc5088974790c38226fa2e18b6295..c3cdb178ce9ce0021a27e98a497aabeaed74a521 100644 --- a/src/resources/catalog_label.xml +++ b/src/resources/catalog_label.xml @@ -12,5 +12,4 @@ <mod at="Nter" value="36.0" acc="MOD:00638"/> <mod at="K" value="36.0" acc="MOD:00638"/> </isotope_label> - </isotope_label_list> </catalog>