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

trying map reduce function

parent 4f64bee3
No related branches found
No related tags found
No related merge requests found
......@@ -31,6 +31,7 @@
#include "tidddataoutput.h"
#include <pappsomspp/psm/xtandem/xtandemhyperscore.h>
#include <cmath>
#include <QtConcurrent>
TiddDataOutput::TiddDataOutput(pappso::UiMonitorInterface *p_monitor,
CalcWriterInterface *p_writer,
......@@ -123,22 +124,145 @@ TiddDataOutput::TiddDataOutput(pappso::UiMonitorInterface *p_monitor,
"extracting %1 mass spectrum from raw data files and computing features")
.arg(m_peptideEvidenceList.size()));
for(auto &peptide_evidence : m_peptideEvidenceList)
{
mp_monitor->count();
writeFeatures(peptide_evidence, spectrum_process);
if(std::find(peptide_evidence_list_target.begin(),
peptide_evidence_list_target.end(),
peptide_evidence) != peptide_evidence_list_target.end())
{
mp_writer->writeCell("T");
}
else
auto self = this;
std::function<StructFeatures(const PeptideEvidence *)> extractFeatures =
[self, spectrum_process, ms2precision, minimumMz](
const PeptideEvidence *p_peptide_evidence) {
qDebug();
const PeptideEvidence *p_best_peptide_evidence = p_peptide_evidence;
pappso::MassSpectrum spectrum = spectrum_process.process(
*p_peptide_evidence->getMassSpectrumCstSPtr().get(),
p_peptide_evidence->getExperimentalMz(),
p_peptide_evidence->getCharge());
StructFeatures features_result;
features_result.p_best_hyperscore =
std::make_shared<pappso::XtandemHyperscore>(
spectrum,
p_peptide_evidence->getPeptideXtpSp(),
p_peptide_evidence->getCharge(),
self->m_ms2precision,
self->m_ionList,
true);
std::vector<pappso::XtandemHyperscore> resultable;
std::vector<std::shared_ptr<PeptideEvidence>>
peptide_evidence_solution_list =
self->generatePeptideEvidenceSolutions(p_peptide_evidence);
for(auto sp_peptide_evidence : peptide_evidence_solution_list)
{
mp_writer->writeCell("D");
qDebug();
std::shared_ptr<pappso::XtandemHyperscore> p_hyperscore(
std::make_shared<pappso::XtandemHyperscore>(
spectrum,
sp_peptide_evidence->getPeptideXtpSp(),
sp_peptide_evidence->getCharge(),
self->m_ms2precision,
self->m_ionList,
true));
if(p_hyperscore.get()->getHyperscore() >
features_result.p_best_hyperscore.get()->getHyperscore())
{
features_result.p_best_hyperscore = p_hyperscore;
p_best_peptide_evidence = sp_peptide_evidence.get();
}
qDebug();
}
mp_writer->writeLine();
}
pappso::PsmFeatures psm_features(ms2precision, minimumMz);
psm_features.setPeptideSpectrumCharge(
p_best_peptide_evidence->getPeptideXtpSp(),
p_best_peptide_evidence->getMassSpectrumCstSPtr().get(),
p_best_peptide_evidence->getCharge());
features_result.p_peptide_evidence = p_best_peptide_evidence;
features_result.total_intensity = psm_features.getTotalIntensity();
features_result.MaxIntALL =
p_best_peptide_evidence->getMassSpectrumCstSPtr()
.get()
->maxIntensityDataPoint()
.y;
features_result.MaxYionInt =
psm_features.getMaxIntensityPeakIonMatch(pappso::PeptideIon::y);
features_result.MaxBionInt =
psm_features.getMaxIntensityPeakIonMatch(pappso::PeptideIon::b);
features_result.SumYmatchInt =
psm_features.getIntensityOfMatchedIon(pappso::PeptideIon::y);
features_result.SumBmatchInt =
psm_features.getIntensityOfMatchedIon(pappso::PeptideIon::b);
features_result.NbAaCoverYion =
psm_features.getAaSequenceCoverage(pappso::PeptideIon::y);
features_result.NbAaCoverBion =
psm_features.getAaSequenceCoverage(pappso::PeptideIon::b);
features_result.MaxConsecutiveYion =
psm_features.getMaxConsecutiveIon(pappso::PeptideIon::y);
features_result.MaxConsecutiveBion =
psm_features.getMaxConsecutiveIon(pappso::PeptideIon::b);
features_result.MassErrMean = psm_features.getMatchedMzDiffMean();
// MassErrSD
features_result.MassErrSD = psm_features.getMatchedMzDiffSd();
// NumofAnnoPeaks
features_result.NumofAnnoPeaks = psm_features.getNumberOfMatchedIons();
features_result.NumofComplementPeaks =
psm_features.countMatchedIonComplementPairs();
// SumComplementPeaksInt
features_result.SumComplementPeaksInt =
psm_features.getTotalIntensityOfMatchedIonComplementPairs();
features_result.ComplementPairsAaSequenceCoverage =
psm_features.getComplementPairsAaSequenceCoverage();
qDebug();
return features_result;
};
std::function<void(std::size_t & result, const StructFeatures)>
reduceWriteFeatures =
[self, peptide_evidence_list_target](
std::size_t &result, const StructFeatures features_result) {
// write results
self->mp_monitor->count();
writeFeatures(self->mp_writer, features_result);
if(std::find(peptide_evidence_list_target.begin(),
peptide_evidence_list_target.end(),
features_result.p_peptide_evidence) !=
peptide_evidence_list_target.end())
{
self->mp_writer->writeCell("T");
}
else
{
self->mp_writer->writeCell("D");
}
self->mp_writer->writeLine();
result++;
};
QFuture<std::size_t> res =
QtConcurrent::mappedReduced<std::size_t>(m_peptideEvidenceList.begin(),
m_peptideEvidenceList.end(),
extractFeatures,
reduceWriteFeatures,
QtConcurrent::OrderedReduce);
// compute features
}
TiddDataOutput::~TiddDataOutput()
......@@ -213,200 +337,144 @@ TiddDataOutput::writeHeaders()
void
TiddDataOutput::writeFeatures(const PeptideEvidence *p_peptide_evidence,
pappso::XtandemSpectrumProcess &spectrum_process)
TiddDataOutput::writeFeatures(CalcWriterInterface *p_writer,
const StructFeatures &features_result)
{
qDebug();
const PeptideEvidence *p_best_peptide_evidence = p_peptide_evidence;
pappso::MassSpectrum spectrum = spectrum_process.process(
*p_peptide_evidence->getMassSpectrumCstSPtr().get(),
p_peptide_evidence->getExperimentalMz(),
p_peptide_evidence->getCharge());
std::shared_ptr<pappso::XtandemHyperscore> p_best_hyperscore(
std::make_shared<pappso::XtandemHyperscore>(
spectrum,
p_peptide_evidence->getPeptideXtpSp(),
p_peptide_evidence->getCharge(),
m_ms2precision,
m_ionList,
true));
std::vector<pappso::XtandemHyperscore> resultable;
std::vector<std::shared_ptr<PeptideEvidence>> peptide_evidence_solution_list =
generatePeptideEvidenceSolutions(p_peptide_evidence);
for(auto sp_peptide_evidence : peptide_evidence_solution_list)
{
qDebug();
std::shared_ptr<pappso::XtandemHyperscore> p_hyperscore(
std::make_shared<pappso::XtandemHyperscore>(
spectrum,
sp_peptide_evidence->getPeptideXtpSp(),
sp_peptide_evidence->getCharge(),
m_ms2precision,
m_ionList,
true));
if(p_hyperscore.get()->getHyperscore() >
p_best_hyperscore.get()->getHyperscore())
{
p_best_hyperscore = p_hyperscore;
p_best_peptide_evidence = sp_peptide_evidence.get();
}
qDebug();
}
qDebug();
mp_writer->writeCell(
p_peptide_evidence->getIdentificationDataSource()->getSampleName());
mp_writer->writeCell(p_peptide_evidence->getSpectrumIndexByScanNumber());
mp_writer->writeCell(
p_peptide_evidence->getPeptideXtpSp().get()->getSequence());
mp_writer->writeCell(
p_best_peptide_evidence->getPeptideXtpSp().get()->getSequence());
p_writer->writeCell(
features_result.p_peptide_evidence->getIdentificationDataSource()
->getSampleName());
p_writer->writeCell(
features_result.p_peptide_evidence->getSpectrumIndexByScanNumber());
p_writer->writeCell(
features_result.p_peptide_evidence->getPeptideXtpSp().get()->getSequence());
p_writer->writeCell(
features_result.p_peptide_evidence->getPeptideXtpSp().get()->getSequence());
// Charge
mp_writer->writeCell((std::size_t)p_best_peptide_evidence->getCharge());
p_writer->writeCell(
(std::size_t)features_result.p_peptide_evidence->getCharge());
// PrecursorM
mp_writer->writeCell(p_peptide_evidence->getExperimentalMhplus());
p_writer->writeCell(
features_result.p_peptide_evidence->getExperimentalMhplus());
// PrecursorMZ
mp_writer->writeCell(p_peptide_evidence->getExperimentalMz());
p_writer->writeCell(features_result.p_peptide_evidence->getExperimentalMz());
// CalMW
mp_writer->writeCell(p_peptide_evidence->getTheoreticalMz());
p_writer->writeCell(features_result.p_peptide_evidence->getTheoreticalMz());
// DeltaMass
mp_writer->writeCell(p_peptide_evidence->getDeltaMass());
p_writer->writeCell(features_result.p_peptide_evidence->getDeltaMass());
// AbsDeltaMass
mp_writer->writeCell(std::abs(p_peptide_evidence->getDeltaMass()));
p_writer->writeCell(
std::abs(features_result.p_peptide_evidence->getDeltaMass()));
// PeptideLength
std::size_t peptide_size =
p_best_peptide_evidence->getPeptideXtpSp().get()->size();
features_result.p_peptide_evidence->getPeptideXtpSp().get()->size();
mp_writer->writeCell(peptide_size);
p_writer->writeCell(peptide_size);
// IdentificationEngine
mp_writer->writeCell(
(std::int8_t)p_peptide_evidence->getIdentificationEngine());
p_writer->writeCell(
(std::int8_t)features_result.p_peptide_evidence->getIdentificationEngine());
mp_writer->writeCell(
p_peptide_evidence->getParam(PeptideEvidenceParam::deepprot_original_count)
.toInt());
mp_writer->writeCell(
p_peptide_evidence->getParam(PeptideEvidenceParam::deepprot_fitted_count)
p_writer->writeCell(
features_result.p_peptide_evidence
->getParam(PeptideEvidenceParam::deepprot_original_count)
.toInt());
mp_writer->writeCell(
p_peptide_evidence->getParam(PeptideEvidenceParam::deepprot_match_type)
.toInt());
mp_writer->writeCell(
p_peptide_evidence
p_writer->writeCell(features_result.p_peptide_evidence
->getParam(PeptideEvidenceParam::deepprot_fitted_count)
.toInt());
p_writer->writeCell(features_result.p_peptide_evidence
->getParam(PeptideEvidenceParam::deepprot_match_type)
.toInt());
p_writer->writeCell(
features_result.p_peptide_evidence
->getParam(PeptideEvidenceParam::deepprot_peptide_candidate_status)
.toInt());
m_psmFeatures.setPeptideSpectrumCharge(
p_best_peptide_evidence->getPeptideXtpSp(),
p_best_peptide_evidence->getMassSpectrumCstSPtr().get(),
p_best_peptide_evidence->getCharge());
// TIC
mp_writer->writeCell(std::log(m_psmFeatures.getTotalIntensity()));
p_writer->writeCell(std::log(features_result.total_intensity));
// MaxIntALL
mp_writer->writeCell(
checkInf(std::log(p_best_peptide_evidence->getMassSpectrumCstSPtr()
.get()
->maxIntensityDataPoint()
.y)));
p_writer->writeCell(checkInf(std::log(features_result.MaxIntALL)));
// MaxYionInt
mp_writer->writeCell(checkInf(std::log(
m_psmFeatures.getMaxIntensityPeakIonMatch(pappso::PeptideIon::y))));
p_writer->writeCell(checkInf(std::log(features_result.MaxYionInt)));
// MaxBionInt
mp_writer->writeCell(checkInf(std::log(
m_psmFeatures.getMaxIntensityPeakIonMatch(pappso::PeptideIon::b))));
p_writer->writeCell(checkInf(std::log(features_result.MaxBionInt)));
// SumYmatchInt
mp_writer->writeCell(checkInf(
std::log(m_psmFeatures.getIntensityOfMatchedIon(pappso::PeptideIon::y))));
p_writer->writeCell(checkInf(std::log(features_result.SumYmatchInt)));
// SumBmatchInt
mp_writer->writeCell(checkInf(
std::log(m_psmFeatures.getIntensityOfMatchedIon(pappso::PeptideIon::b))));
p_writer->writeCell(checkInf(std::log(features_result.SumBmatchInt)));
// FracYmatchInt
mp_writer->writeCell(
checkInf(m_psmFeatures.getIntensityOfMatchedIon(pappso::PeptideIon::y) /
m_psmFeatures.getTotalIntensity()));
p_writer->writeCell(
checkInf(features_result.SumYmatchInt / features_result.total_intensity));
// FracBmatchInt
mp_writer->writeCell(
checkInf(m_psmFeatures.getIntensityOfMatchedIon(pappso::PeptideIon::b) /
m_psmFeatures.getTotalIntensity()));
p_writer->writeCell(
checkInf(features_result.SumBmatchInt / features_result.total_intensity));
// SeqCoverYion
mp_writer->writeCell(
(double)m_psmFeatures.getAaSequenceCoverage(pappso::PeptideIon::y) /
(double)peptide_size);
p_writer->writeCell((double)features_result.NbAaCoverYion /
(double)peptide_size);
// SeqCoverBion
mp_writer->writeCell(
(double)m_psmFeatures.getAaSequenceCoverage(pappso::PeptideIon::b) /
(double)peptide_size);
p_writer->writeCell((double)features_result.NbAaCoverBion /
(double)peptide_size);
// ConsecutiveYion
mp_writer->writeCell(
(double)m_psmFeatures.getMaxConsecutiveIon(pappso::PeptideIon::y) /
(double)peptide_size);
p_writer->writeCell((double)features_result.MaxConsecutiveYion /
(double)peptide_size);
// ConsecutiveBion
mp_writer->writeCell(
(double)m_psmFeatures.getMaxConsecutiveIon(pappso::PeptideIon::b) /
(double)peptide_size);
p_writer->writeCell((double)features_result.MaxConsecutiveBion /
(double)peptide_size);
// MassErrMean
mp_writer->writeCell(m_psmFeatures.getMatchedMzDiffMean());
p_writer->writeCell(features_result.MassErrMean);
// MassErrSD
mp_writer->writeCell(m_psmFeatures.getMatchedMzDiffSd());
p_writer->writeCell(features_result.MassErrSD);
// NumofAnnoPeaks
mp_writer->writeCell(m_psmFeatures.getNumberOfMatchedIons());
p_writer->writeCell(features_result.NumofAnnoPeaks);
// NumofComplementPeaks
std::size_t num_of_pairs = m_psmFeatures.countMatchedIonComplementPairs();
std::size_t num_of_pairs = features_result.NumofComplementPeaks;
if(num_of_pairs > 0)
{
mp_writer->writeCell(num_of_pairs);
p_writer->writeCell(num_of_pairs);
// SumComplementPeaksInt
mp_writer->writeCell(
std::log(m_psmFeatures.getTotalIntensityOfMatchedIonComplementPairs()));
p_writer->writeCell(std::log(features_result.SumComplementPeaksInt));
// FracComplementPeaksInt
mp_writer->writeCell(
m_psmFeatures.getTotalIntensityOfMatchedIonComplementPairs() /
m_psmFeatures.getTotalIntensity());
p_writer->writeCell(features_result.SumComplementPeaksInt /
features_result.total_intensity);
// SeqCoverComplementPeaks
mp_writer->writeCell(
(double)m_psmFeatures.getComplementPairsAaSequenceCoverage() /
p_writer->writeCell(
(double)features_result.ComplementPairsAaSequenceCoverage /
(double)peptide_size);
}
else
{
mp_writer->writeCell(0);
p_writer->writeCell(0);
// SumComplementPeaksInt
mp_writer->writeCell(0);
p_writer->writeCell(0);
// FracComplementPeaksInt
mp_writer->writeCell(0);
p_writer->writeCell(0);
// SeqCoverComplementPeaks
mp_writer->writeCell(0);
p_writer->writeCell(0);
}
// Hyperscore
mp_writer->writeCell(p_best_hyperscore->getHyperscore());
p_writer->writeCell(features_result.p_best_hyperscore->getHyperscore());
qDebug();
......@@ -415,7 +483,7 @@ TiddDataOutput::writeFeatures(const PeptideEvidence *p_peptide_evidence,
std::vector<std::shared_ptr<PeptideEvidence>>
TiddDataOutput::generatePeptideEvidenceSolutions(
const PeptideEvidence *peptide_evidence) const
const PeptideEvidence *peptide_evidence)
{
std::vector<std::shared_ptr<PeptideEvidence>> solution_list;
std::vector<std::size_t> position_list;
......@@ -463,7 +531,7 @@ TiddDataOutput::generatePeptideEvidenceSolutions(
}
double
TiddDataOutput::checkInf(double input) const
TiddDataOutput::checkInf(double input)
{
if(input < 0)
return 0;
......
......@@ -32,6 +32,7 @@
#include <pappsomspp/psm/xtandem/xtandemspectrumprocess.h>
#include <pappsomspp/psm/features/psmfeatures.h>
#include <pappsomspp/processing/uimonitor/uimonitorinterface.h>
#include <pappsomspp/psm/xtandem/xtandemhyperscore.h>
#pragma once
......@@ -58,16 +59,38 @@ class TiddDataOutput
const std::vector<PeptideEvidence *> &getPeptideEvidenceList() const;
private:
struct StructFeatures
{
double total_intensity;
double MaxIntALL;
double MaxYionInt;
double MaxBionInt;
double SumYmatchInt;
double SumBmatchInt;
std::size_t NbAaCoverYion;
std::size_t NbAaCoverBion;
std::size_t MaxConsecutiveYion;
std::size_t MaxConsecutiveBion;
double MassErrMean;
double MassErrSD;
std::size_t NumofAnnoPeaks;
std::size_t NumofComplementPeaks;
double SumComplementPeaksInt;
std::size_t ComplementPairsAaSequenceCoverage;
const PeptideEvidence *p_peptide_evidence;
std::shared_ptr<pappso::XtandemHyperscore> p_best_hyperscore;
};
private:
void writeHeaders();
void writeFeatures(const PeptideEvidence *p_peptide_evidence,
pappso::XtandemSpectrumProcess &spectrum_process);
static void writeFeatures(CalcWriterInterface *p_writer,
const StructFeatures &features_result);
std::vector<std::shared_ptr<PeptideEvidence>>
generatePeptideEvidenceSolutions(
const PeptideEvidence *peptide_evidence) const;
static std::vector<std::shared_ptr<PeptideEvidence>>
generatePeptideEvidenceSolutions(const PeptideEvidence *peptide_evidence);
double checkInf(double input) const;
static double checkInf(double input);
void sortPeptideEvidenceList();
......
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