Skip to content
Snippets Groups Projects
Commit 974f4bc0 authored by Olivier Langella's avatar Olivier Langella
Browse files

WIP: begin compar spectra

parent 67728c7a
No related branches found
No related tags found
No related merge requests found
......@@ -70,6 +70,7 @@ SET(CPP_FILES
input/xpipsaxhandler.cpp
input/xtandemsaxhandler.cpp
output/masschroqml.cpp
output/ods/comparspectrasheet.cpp
output/ods/infosheet.cpp
output/ods/odsexport.cpp
output/ods/peptidepossheet.cpp
......
/**
* \file output/ods/comparspectrasheet.cpp
* \date 30/4/2017
* \author Olivier Langella
* \brief ODS compar spectra sheet
*/
/*******************************************************************************
* Copyright (c) 2017 Olivier Langella <olivier.langella@u-psud.fr>.
*
* This file is part of XTPcpp.
*
* XTPcpp is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* XTPcpp is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with XTPcpp. If not, see <http://www.gnu.org/licenses/>.
*
* Contributors:
* Olivier Langella <olivier.langella@u-psud.fr> - initial API and implementation
******************************************************************************/
#include "comparspectrasheet.h"
#include <tuple>
#include <pappsomspp/utils.h>
#include <QDebug>
ComparSpectraSheet::ComparSpectraSheet (OdsExport * p_ods_export, CalcWriterInterface * p_writer, const Project * p_project): _p_project(p_project) {
_p_ods_export = p_ods_export;
_p_writer = p_writer;
p_writer->writeSheet("compar spectra");
std::vector<IdentificationGroup *> identification_list = p_project->getIdentificationGroupList();
for (IdentificationGroup * p_ident:identification_list) {
//writeHeaders(p_ident);
writeIdentificationGroup(p_ident);
}
}
void ComparSpectraSheet::writeHeaders(IdentificationGroup * p_ident) {
// Peptide ID Protein ID accession description Sequence Modifs Start Stop MH+ theo
//MS Sample : 20120906_balliau_extract_1_A01_urnb-1
_msrun_list = p_ident->getMsRunSpList();
if (_msrun_list.size() == 1) {
_p_writer->writeCell("sample");
_p_writer->writeLine();
_p_writer->writeCell(_msrun_list[0].get()->getSampleName());
_p_writer->writeLine();
}
std::sort(_msrun_list.begin(), _msrun_list.end(),
[](MsRunSp & a, MsRunSp & b)
{
return a.get()->getXmlId() < b.get()->getXmlId();
});
_p_writer->writeLine();
_p_writer->writeCell("Group ID");
_p_writer->writeCell("Subgroup ID");
//_p_writer->setCellAnnotation("MS sample name (MS run)");
_p_writer->writeCell("Protein ID");
_p_writer->writeCell("accession");
_p_writer->writeCell("description");
_p_writer->writeCell("Number of proteins");
for (MsRunSp & msrun_sp: _msrun_list) {
_p_writer->writeCell(msrun_sp.get()->getSampleName());
}
}
void ComparSpectraSheet::writeBestPeptideMatch(const ProteinMatch * p_protein_match,const PeptideMatch * p_peptide_match) {
_p_writer->writeLine();
unsigned int group_number = p_protein_match->getGrpProteinSp().get()->getGroupNumber();
unsigned int subgroup_number = p_protein_match->getGrpProteinSp().get()->getSubGroupNumber();
unsigned int rank_number = p_protein_match->getGrpProteinSp().get()->getRank();
_p_ods_export->setEvenOrOddStyle(group_number, _p_writer);
_p_writer->writeCell(pappso::Utils::getLexicalOrderedString(group_number));
_p_ods_export->setEvenOrOddStyle(subgroup_number, _p_writer);
_p_writer->writeCell(pappso::Utils::getLexicalOrderedString(subgroup_number));
_p_ods_export->setEvenOrOddStyle(rank_number, _p_writer);
_p_writer->writeCell(p_protein_match->getGrpProteinSp().get()->getGroupingId());
_p_writer->clearTableCellStyleRef();
_p_writer->writeCell(p_protein_match->getProteinXtpSp().get()->getAccession());
_p_writer->writeCell(p_protein_match->getProteinXtpSp().get()->getDescription());
_p_writer->writeCell(p_protein_match->getGroupingGroupSp().get()->countProteinInSubgroup(subgroup_number));
for (MsRunSp & msrun_sp: _msrun_list) {
_p_writer->writeCell(msrun_sp.get()->getSampleName());
}
}
void ComparSpectraSheet::writeIdentificationGroup(IdentificationGroup * p_ident) {
qDebug() << "ComparSpectraSheet::writeIdentificationGroup begin";
writeHeaders(p_ident);
std::vector<ProteinMatch *> protein_match_list;
for (ProteinMatch * p_protein_match: p_ident->getProteinMatchList()) {
if (p_protein_match->getValidationState() < ValidationState::grouped) continue;
if (p_protein_match->getGrpProteinSp().get()->getRank() == 1) {
protein_match_list.push_back(p_protein_match);
}
}
std::sort(protein_match_list.begin(), protein_match_list.end(),
[](const ProteinMatch * a, const ProteinMatch * b)
{
unsigned int agroup = a->getGrpProteinSp().get()->getGroupNumber();
unsigned int asubgroup = a->getGrpProteinSp().get()->getSubGroupNumber();
unsigned int arank = a->getGrpProteinSp().get()->getRank();
unsigned int bgroup = b->getGrpProteinSp().get()->getGroupNumber();
unsigned int bsubgroup = b->getGrpProteinSp().get()->getSubGroupNumber();
unsigned int brank = b->getGrpProteinSp().get()->getRank();
return std::tie(agroup, asubgroup, arank) < std::tie(bgroup, bsubgroup, brank);
});
for (ProteinMatch * p_protein_match : protein_match_list) {
std::vector<PeptideMatch *> peptide_match_list;
for (auto & peptide_match: p_protein_match->getPeptideMatchList()) {
if (peptide_match->getValidationState() < ValidationState::grouped) continue;
peptide_match_list.push_back(peptide_match);
}
std::sort(peptide_match_list.begin(), peptide_match_list.end(),
[](const PeptideMatch * a, const PeptideMatch * b)
{
unsigned int arank = a->getGrpPeptideSp().get()->getRank();
unsigned int aposition = a->getStart();
unsigned int brank = b->getGrpPeptideSp().get()->getRank();
unsigned int bposition = b->getStart();
return std::tie(arank, aposition) < std::tie(brank, bposition);
});
const PeptideMatch * p_best_peptide_match = nullptr;
for (auto & peptide_match:peptide_match_list) {
if (p_best_peptide_match == nullptr) {
p_best_peptide_match = peptide_match;
}
//change spectra :
unsigned int arank = p_best_peptide_match->getGrpPeptideSp().get()->getRank();
unsigned int aposition = p_best_peptide_match->getStart();
unsigned int brank = peptide_match->getGrpPeptideSp().get()->getRank();
unsigned int bposition = peptide_match->getStart();
if (std::tie(arank, aposition) != std::tie(brank, bposition)) {
//write p_best_peptide_match
writeBestPeptideMatch(p_protein_match, p_best_peptide_match);
p_best_peptide_match = peptide_match;
}
else {
if (p_best_peptide_match->getEvalue()> peptide_match->getEvalue()) {
p_best_peptide_match = peptide_match;
}
}
}
if (p_best_peptide_match != nullptr) {
writeBestPeptideMatch(p_protein_match, p_best_peptide_match);
}
}
_p_writer->writeLine();
_p_writer->writeLine();
qDebug() << "PeptidePosSheet::writeIdentificationGroup end";
}
/**
* \file output/ods/comparspectrasheet.h
* \date 30/4/2017
* \author Olivier Langella
* \brief ODS compar spectra sheet
*/
/*******************************************************************************
* Copyright (c) 2017 Olivier Langella <olivier.langella@u-psud.fr>.
*
* This file is part of XTPcpp.
*
* XTPcpp is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* XTPcpp is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with XTPcpp. If not, see <http://www.gnu.org/licenses/>.
*
* Contributors:
* Olivier Langella <olivier.langella@u-psud.fr> - initial API and implementation
******************************************************************************/
#ifndef COMPARSPECTRASHEET_H
#define COMPARSPECTRASHEET_H
#include "../../core/project.h"
#include <odsstream/calcwriterinterface.h>
#include "../../core/proteinmatch.h"
#include "odsexport.h"
class ComparSpectraSheet
{
public :
ComparSpectraSheet (OdsExport * p_ods_export, CalcWriterInterface * p_writer, const Project * p_project);
private :
void writeIdentificationGroup(IdentificationGroup * p_ident);
void writeHeaders(IdentificationGroup * p_ident);
void writeBestPeptideMatch(const ProteinMatch * p_protein_match, const PeptideMatch * p_peptide_match);
private :
OdsExport * _p_ods_export;
const Project * _p_project;
CalcWriterInterface * _p_writer;
std::vector<MsRunSp> _msrun_list;
};
#endif // COMPARSPECTRASHEET_H
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment