Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • pappso/pappsomspp
  • thomas.renne/pappsomspp
2 results
Show changes
Showing
with 789 additions and 145 deletions
......@@ -28,24 +28,26 @@
#include "psmfeatures.h"
#include <memory>
#include <cmath>
using namespace pappso;
PsmFeatures::PsmFeatures()
PsmFeatures::PsmFeatures(PrecisionPtr ms2precision, double minimumMz)
{
m_ms2precision = PrecisionFactory::getDaltonInstance(0.02);
m_ms2precision = ms2precision;
m_ionList.push_back(PeptideIon::y);
m_ionList.push_back(PeptideIon::b);
msp_filterKeepGreater =
std::make_shared<FilterResampleKeepGreater>(minimumMz);
msp_filterChargeDeconvolution =
std::make_shared<FilterChargeDeconvolution>(m_ms2precision);
msp_filterMzExclusion = std::make_shared<FilterMzExclusion>(
PrecisionFactory::getPrecisionPtrFractionInstance(m_ms2precision, 0.5));
// TODO compute number of matched complementary peaks having m/z compatible
// with the precursor
}
PsmFeatures::~PsmFeatures()
......@@ -53,24 +55,80 @@ PsmFeatures::~PsmFeatures()
}
void
PsmFeatures::setPeptideSpectrumCharge(pappso::PeptideSp peptideSp,
PsmFeatures::setPeptideSpectrumCharge(const pappso::PeptideSp peptideSp,
const MassSpectrum *p_spectrum,
unsigned int parent_charge)
{
m_peakIonPairs.clear();
msp_peptide = peptideSp;
MassSpectrum spectrum(*p_spectrum);
msp_filterChargeDeconvolution.get()->filter(spectrum);
msp_filterMzExclusion.get()->filter(spectrum);
msp_filterKeepGreater.get()->filter(spectrum);
// msp_filterChargeDeconvolution.get()->filter(spectrum);
// msp_filterMzExclusion.get()->filter(spectrum);
msp_peptideSpectrumMatch =
std::make_shared<PeptideIsotopeSpectrumMatch>(spectrum,
peptideSp,
parent_charge,
m_ms2precision,
m_ionList,
(unsigned int)1,
0);
msp_peptideSpectrumMatch.get()->dropPeaksLackingMonoisotope();
m_spectrumSumIntensity = spectrum.sumY();
qDebug() << " accumulate";
std::vector<double> delta_list;
// TODO compute number of matched complementary peaks having m/z compatible
// with the precursor
unsigned int max_charge = parent_charge;
if(parent_charge > 1)
m_precursorTheoreticalMz = peptideSp.get()->getMz(parent_charge);
m_precursorTheoreticalMass = peptideSp.get()->getMass();
m_parentCharge = parent_charge;
findComplementIonPairs(peptideSp);
for(const pappso::PeakIonIsotopeMatch &peak_ion :
msp_peptideSpectrumMatch.get()->getPeakIonIsotopeMatchList())
{
max_charge = parent_charge - 1;
delta_list.push_back(
peak_ion.getPeptideFragmentIonSp().get()->getMz(peak_ion.getCharge()) -
peak_ion.getPeak().x);
}
pappso::pappso_double sum =
std::accumulate(delta_list.begin(), delta_list.end(), 0);
msp_peptideSpectrumMatch = std::make_shared<PeptideSpectrumMatch>(
spectrum, peptideSp, max_charge, m_ms2precision, m_ionList);
qDebug() << " delta_list.size()=" << delta_list.size();
m_matchedMzDiffMean = 0;
m_matchedMzDiffMedian = 0;
m_matchedMzDiffSd = 0;
if(delta_list.size() > 0)
{
m_matchedMzDiffMean = sum / ((pappso::pappso_double)delta_list.size());
m_spectrumSumIntensity = spectrum.sumY();
std::sort(delta_list.begin(), delta_list.end());
m_matchedMzDiffMedian = delta_list[(delta_list.size() / 2)];
qDebug() << " sd";
m_matchedMzDiffSd = 0;
for(pappso::pappso_double val : delta_list)
{
// sd = sd + ((val - mean) * (val - mean));
m_matchedMzDiffSd += std::pow((val - m_matchedMzDiffMean), 2);
}
m_matchedMzDiffSd = m_matchedMzDiffSd / delta_list.size();
m_matchedMzDiffSd = std::sqrt(m_matchedMzDiffSd);
}
else
{
}
}
......@@ -88,7 +146,7 @@ PsmFeatures::getIntensityOfMatchedIon(PeptideIon ion_type)
return sum;
}
double
PsmFeatures::getTotalIntensityOfMatchedIons()
PsmFeatures::getTotalIntensityOfMatchedIons() const
{
double sum = 0;
for(const PeakIonMatch &peak_ion_match : *msp_peptideSpectrumMatch.get())
......@@ -99,7 +157,230 @@ PsmFeatures::getTotalIntensityOfMatchedIons()
}
double
PsmFeatures::getTotalIntensity()
PsmFeatures::getTotalIntensity() const
{
return m_spectrumSumIntensity;
}
std::size_t
pappso::PsmFeatures::countMatchedIonComplementPairs() const
{
return m_peakIonPairs.size();
}
const std::vector<
std::pair<pappso::PeakIonIsotopeMatch, pappso::PeakIonIsotopeMatch>> &
pappso::PsmFeatures::getPeakIonPairs() const
{
return m_peakIonPairs;
}
double
pappso::PsmFeatures::getTotalIntensityOfMatchedIonComplementPairs() const
{
double sum = 0;
for(auto &peak_pairs : m_peakIonPairs)
{
sum += peak_pairs.first.getPeak().y;
sum += peak_pairs.second.getPeak().y;
}
return sum;
}
double
pappso::PsmFeatures::getMatchedMzDiffSd() const
{
return m_matchedMzDiffSd;
}
double
pappso::PsmFeatures::getMatchedMzDiffMean() const
{
return m_matchedMzDiffMean;
}
std::size_t
pappso::PsmFeatures::getNumberOfMatchedIons() const
{
return msp_peptideSpectrumMatch.get()->getPeakIonIsotopeMatchList().size();
}
std::size_t
pappso::PsmFeatures::getMaxConsecutiveIon(pappso::PeptideIon ion_type)
{
std::size_t max = 0;
auto peak_ion_match_list =
msp_peptideSpectrumMatch.get()->getPeakIonIsotopeMatchList();
peak_ion_match_list.erase(
std::remove_if(
peak_ion_match_list.begin(),
peak_ion_match_list.end(),
[ion_type](const PeakIonIsotopeMatch &a) {
if(a.getPeptideIonType() != ion_type)
return true;
if(a.getPeptideNaturalIsotopeAverageSp().get()->getIsotopeNumber() > 0)
return true;
return false;
}),
peak_ion_match_list.end());
peak_ion_match_list.sort(
[](const PeakIonIsotopeMatch &a, const PeakIonIsotopeMatch &b) {
if(a.getCharge() < b.getCharge())
return true;
if(a.getPeptideIonType() < b.getPeptideIonType())
return true;
if(a.getPeptideFragmentIonSp().get()->size() <
b.getPeptideFragmentIonSp().get()->size())
return true;
return false;
});
unsigned int charge = 0;
std::size_t size = 0;
std::size_t count = 0;
for(std::list<PeakIonIsotopeMatch>::iterator it = peak_ion_match_list.begin();
it != peak_ion_match_list.end();
it++)
{
qDebug()
<< it->toString() << max << " " << it->getPeak().x << " "
<< it->getPeptideNaturalIsotopeAverageSp().get()->getIsotopeNumber();
count++;
if((charge != it->getCharge()) ||
(size != (it->getPeptideFragmentIonSp().get()->size() - 1)))
{
count = 1;
charge = it->getCharge();
}
if(max < count)
max = count;
size = it->getPeptideFragmentIonSp().get()->size();
}
return max;
}
std::size_t
pappso::PsmFeatures::getAaSequenceCoverage(pappso::PeptideIon ion_type)
{
std::vector<bool> covered;
covered.resize(msp_peptide.get()->size(), false);
for(auto &peak : msp_peptideSpectrumMatch.get()->getPeakIonIsotopeMatchList())
{
if(peak.getPeptideIonType() == ion_type)
{
covered[peak.getPeptideFragmentIonSp().get()->size() - 1] = true;
}
}
return std::count(covered.begin(), covered.end(), true);
}
std::size_t
pappso::PsmFeatures::getComplementPairsAaSequenceCoverage()
{
std::vector<bool> covered;
covered.resize(msp_peptide.get()->size(), false);
for(auto &peak_pair : m_peakIonPairs)
{
std::size_t pos =
peak_pair.first.getPeptideFragmentIonSp().get()->size() - 1;
covered[pos] = true;
covered[pos + 1] = true;
}
return std::count(covered.begin(), covered.end(), true);
}
double
pappso::PsmFeatures::getMaxIntensityPeakIonMatch(
pappso::PeptideIon ion_type) const
{
std::list<pappso::PeakIonIsotopeMatch> peak_ion_type =
msp_peptideSpectrumMatch.get()->getPeakIonIsotopeMatchList();
peak_ion_type.remove_if([ion_type](const PeakIonIsotopeMatch &a) {
return (a.getPeptideIonType() != ion_type);
});
auto peak_it = std::max_element(
peak_ion_type.begin(),
peak_ion_type.end(),
[](const PeakIonIsotopeMatch &a, const PeakIonIsotopeMatch &b) {
return (a.getPeak().y < b.getPeak().y);
});
if(peak_it == peak_ion_type.end())
return 0;
return peak_it->getPeak().y;
}
double
pappso::PsmFeatures::getMaxIntensityMatchedIonComplementPairPrecursorMassDelta()
const
{
auto peak_it = std::max_element(
m_peakIonPairs.begin(),
m_peakIonPairs.end(),
[](const std::pair<pappso::PeakIonIsotopeMatch, pappso::PeakIonIsotopeMatch>
&a,
const std::pair<pappso::PeakIonIsotopeMatch, pappso::PeakIonIsotopeMatch>
&b) {
return ((a.first.getPeak().y + a.second.getPeak().y) <
(b.first.getPeak().y + b.second.getPeak().y));
});
if(peak_it == m_peakIonPairs.end())
return 0;
return getIonPairPrecursorMassDelta(*peak_it);
}
double
pappso::PsmFeatures::getIonPairPrecursorMassDelta(
const std::pair<pappso::PeakIonIsotopeMatch, pappso::PeakIonIsotopeMatch>
&ion_pair) const
{
qDebug() << m_precursorTheoreticalMz << " " << ion_pair.first.getPeak().x
<< " " << ion_pair.second.getPeak().x << " "
<< ion_pair.second.getCharge() << " " << ion_pair.first.getCharge()
<< " " << m_parentCharge;
double diff =
(m_precursorTheoreticalMass + (MHPLUS * ion_pair.first.getCharge())) /
ion_pair.first.getCharge();
return (diff - (ion_pair.first.getPeak().x + ion_pair.second.getPeak().x -
((MHPLUS * ion_pair.first.getCharge())) /
ion_pair.first.getCharge()));
}
void
pappso::PsmFeatures::findComplementIonPairs(const pappso::PeptideSp &peptideSp)
{
std::size_t peptide_size = peptideSp.get()->size();
std::vector<PeakIonIsotopeMatch> ion_isotope_list(
msp_peptideSpectrumMatch.get()->getPeakIonIsotopeMatchList().begin(),
msp_peptideSpectrumMatch.get()->getPeakIonIsotopeMatchList().end());
for(const pappso::PeakIonIsotopeMatch &peak_ion_ext : ion_isotope_list)
{
if(peptideIonIsNter(peak_ion_ext.getPeptideIonType()))
{
auto it = findComplementIonType(ion_isotope_list.begin(),
ion_isotope_list.end(),
peak_ion_ext,
peptide_size);
if(it != ion_isotope_list.end())
{ // contains the complementary ion
m_peakIonPairs.push_back({peak_ion_ext, *it});
}
}
}
}
......@@ -32,7 +32,8 @@
#include "../../peptide/peptidefragmention.h"
#include "../../processing/filters/filterchargedeconvolution.h"
#include "../../processing/filters/filterexclusionmz.h"
#include "../peptidespectrummatch.h"
#include "../../processing/filters/filterresample.h"
#include "../peptideisotopespectrummatch.h"
namespace pappso
{
......@@ -42,33 +43,119 @@ namespace pappso
class PMSPP_LIB_DECL PsmFeatures
{
public:
/**
* Default constructor
/** @brief compute psm features
* @param ms2precision precision of mass measurements for MS2 fragments
* @param minimumMz ignore mz values under this threshold
*/
PsmFeatures();
PsmFeatures(PrecisionPtr ms2precision, double minimumMz);
/**
* Destructor
*/
~PsmFeatures();
void setPeptideSpectrumCharge(pappso::PeptideSp peptideSp,
void setPeptideSpectrumCharge(const pappso::PeptideSp peptideSp,
const MassSpectrum *p_spectrum,
unsigned int parent_charge);
/** @brief get the sum of intensity of a specific ion
* @param ion_type ion species (y, b, ...)
*/
double getIntensityOfMatchedIon(PeptideIon ion_type);
double getTotalIntensity();
double getTotalIntensityOfMatchedIons();
/** @brief sum of all peak intensities (matched or not)
*/
double getTotalIntensity() const;
/** @brief sum of matched peak intensities
*/
double getTotalIntensityOfMatchedIons() const;
/** @brief number of matched ions (peaks)
*/
std::size_t getNumberOfMatchedIons() const;
/** @brief count the number of matched ion complement
*
* matched ion complement are ions with a sum compatible to the precursor mass
*
*/
std::size_t countMatchedIonComplementPairs() const;
/** @brief intensity of matched ion complement
*/
double getTotalIntensityOfMatchedIonComplementPairs() const;
const std::vector<
std::pair<pappso::PeakIonIsotopeMatch, pappso::PeakIonIsotopeMatch>> &
getPeakIonPairs() const;
/** @brief get mean deviation of matched peak mass delta
*/
double getMatchedMzDiffMean() const;
/** @brief get standard deviation of matched peak mass delta
*/
double getMatchedMzDiffSd() const;
/** @brief get the precursor mass delta of the maximum intensity pair of
* complement ions
*/
double getMaxIntensityMatchedIonComplementPairPrecursorMassDelta() const;
/** @brief get the maximum consecutive fragments of one ion type
* @param ion_type ion species (y, b, ...)
*/
std::size_t getMaxConsecutiveIon(PeptideIon ion_type);
/** @brief number of amino acid covered by matched ions
*/
std::size_t getAaSequenceCoverage(PeptideIon ion_type);
/** @brief number of amino acid covered by matched complement pairs of ions
*/
std::size_t getComplementPairsAaSequenceCoverage();
double getMaxIntensityPeakIonMatch(PeptideIon ion_type) const;
double getIonPairPrecursorMassDelta(
const std::pair<pappso::PeakIonIsotopeMatch, pappso::PeakIonIsotopeMatch>
&ion_pair) const;
private:
void findComplementIonPairs(const pappso::PeptideSp &peptideSp);
private:
std::shared_ptr<FilterChargeDeconvolution> msp_filterChargeDeconvolution;
std::shared_ptr<FilterMzExclusion> msp_filterMzExclusion;
std::shared_ptr<FilterResampleKeepGreater> msp_filterKeepGreater;
std::shared_ptr<PeptideSpectrumMatch> msp_peptideSpectrumMatch;
std::shared_ptr<PeptideIsotopeSpectrumMatch> msp_peptideSpectrumMatch;
pappso::PeptideSp msp_peptide;
PrecisionPtr m_ms2precision;
std::list<PeptideIon> m_ionList;
double m_spectrumSumIntensity;
double m_precursorTheoreticalMz;
double m_precursorTheoreticalMass;
unsigned int m_parentCharge = 1;
std::vector<
std::pair<pappso::PeakIonIsotopeMatch, pappso::PeakIonIsotopeMatch>>
m_peakIonPairs;
double m_matchedMzDiffMean = 0;
double m_matchedMzDiffMedian = 0;
double m_matchedMzDiffSd = 0;
};
} // namespace pappso
......@@ -26,6 +26,42 @@
namespace pappso
{
std::vector<PeakIonIsotopeMatch>::iterator
findComplementIonType(std::vector<PeakIonIsotopeMatch>::iterator begin,
std::vector<PeakIonIsotopeMatch>::iterator end,
const PeakIonIsotopeMatch &peak_ion,
std::size_t peptide_size)
{
return std::find_if(
begin,
end,
[peak_ion, peptide_size](const PeakIonIsotopeMatch &to_compare) {
if(to_compare.getCharge() == peak_ion.getCharge())
{
if((to_compare.getPeptideFragmentIonSp().get()->size() +
peak_ion.getPeptideFragmentIonSp().get()->size()) == peptide_size)
{
if(peptideIonTypeIsComplement(to_compare.getPeptideIonType(),
peak_ion.getPeptideIonType()))
{
if(to_compare.getPeptideNaturalIsotopeAverageSp()
.get()
->getIsotopeNumber() ==
peak_ion.getPeptideNaturalIsotopeAverageSp()
.get()
->getIsotopeNumber())
{
return true;
}
}
}
}
return false;
});
}
PeakIonIsotopeMatch::PeakIonIsotopeMatch(
const DataPoint &peak,
......@@ -34,12 +70,20 @@ PeakIonIsotopeMatch::PeakIonIsotopeMatch(
: PeakIonMatch(peak, ion_sp, naturalIsotopeAverageSp.get()->getCharge()),
_naturalIsotopeAverageSp(naturalIsotopeAverageSp)
{
qDebug();
}
PeakIonIsotopeMatch::PeakIonIsotopeMatch(const PeakIonIsotopeMatch &other)
: PeakIonMatch(other),
_naturalIsotopeAverageSp(other._naturalIsotopeAverageSp)
: PeakIonMatch(other)
{
_naturalIsotopeAverageSp = other._naturalIsotopeAverageSp;
}
PeakIonIsotopeMatch::PeakIonIsotopeMatch(PeakIonIsotopeMatch &&other)
: PeakIonMatch(std::move(other))
{
_naturalIsotopeAverageSp = other._naturalIsotopeAverageSp;
}
PeakIonIsotopeMatch::~PeakIonIsotopeMatch()
......@@ -55,11 +99,21 @@ PeakIonIsotopeMatch::getPeptideNaturalIsotopeAverageSp() const
PeakIonIsotopeMatch &
PeakIonIsotopeMatch::operator=(const PeakIonIsotopeMatch &other)
{
PeakIonMatch::operator =(other);
_naturalIsotopeAverageSp = other._naturalIsotopeAverageSp;
return *this;
}
QString
PeakIonIsotopeMatch::toString() const
{
return QString("%1isotope%2r%3mz%4")
.arg(PeakIonMatch::toString())
.arg(_naturalIsotopeAverageSp.get()->getIsotopeNumber())
.arg(_naturalIsotopeAverageSp.get()->getIsotopeRank())
.arg(getPeak().x);
}
} // namespace pappso
......@@ -33,6 +33,16 @@ namespace pappso
class PeakIonIsotopeMatch;
typedef std::shared_ptr<const PeakIonIsotopeMatch> PeakIonIsotopeMatchCstSPtr;
/** @brief find the first element containing the complementary ion
* complementary ion of y1 is b(n-1) for instance
* */
PMSPP_LIB_DECL std::vector<PeakIonIsotopeMatch>::iterator
findComplementIonType(std::vector<PeakIonIsotopeMatch>::iterator begin,
std::vector<PeakIonIsotopeMatch>::iterator end,
const PeakIonIsotopeMatch &peak_ion,
std::size_t peptide_size);
class PMSPP_LIB_DECL PeakIonIsotopeMatch : public PeakIonMatch
{
public:
......@@ -41,6 +51,7 @@ class PMSPP_LIB_DECL PeakIonIsotopeMatch : public PeakIonMatch
const PeptideNaturalIsotopeAverageSp &naturalIsotopeAverageSp,
const PeptideFragmentIonSp &ion_sp);
PeakIonIsotopeMatch(const PeakIonIsotopeMatch &other);
PeakIonIsotopeMatch(PeakIonIsotopeMatch &&other);
virtual ~PeakIonIsotopeMatch();
virtual const PeptideNaturalIsotopeAverageSp &
......@@ -48,6 +59,7 @@ class PMSPP_LIB_DECL PeakIonIsotopeMatch : public PeakIonMatch
PeakIonIsotopeMatch &operator=(const PeakIonIsotopeMatch &other);
virtual QString toString() const;
private:
PeptideNaturalIsotopeAverageSp _naturalIsotopeAverageSp;
......
......@@ -44,9 +44,63 @@ PeakIonMatch::PeakIonMatch(const PeakIonMatch &other)
{
}
PeakIonMatch::PeakIonMatch(PeakIonMatch &&other)
: _peak(std::move(other._peak)),
_ion_sp(other._ion_sp),
_charge(std::move(other._charge))
{
}
PeakIonMatch::~PeakIonMatch()
{
}
PeakIonMatch &
PeakIonMatch::operator=(const PeakIonMatch &other)
{
_peak = other._peak;
_ion_sp = other._ion_sp;
_charge = other._charge;
return *this;
}
const PeptideFragmentIonSp &
PeakIonMatch::getPeptideFragmentIonSp() const
{
return _ion_sp;
}
const DataPoint &
PeakIonMatch::getPeak() const
{
return _peak;
}
unsigned int
PeakIonMatch::getCharge() const
{
return _charge;
}
PeptideIon
PeakIonMatch::getPeptideIonType() const
{
return _ion_sp.get()->getPeptideIonType();
}
PeptideDirection
PeakIonMatch::getPeptideIonDirection() const
{
return _ion_sp.get()->getPeptideFragmentSp().get()->getPeptideIonDirection();
}
QString
PeakIonMatch::toString() const
{
return QString("%1").arg(
_ion_sp.get()->getCompletePeptideIonName(getCharge()));
}
} // namespace pappso
......@@ -43,39 +43,22 @@ class PMSPP_LIB_DECL PeakIonMatch
const PeptideFragmentIonSp &ion_sp,
unsigned int charge);
PeakIonMatch(const PeakIonMatch &other);
PeakIonMatch(PeakIonMatch &&other);
virtual ~PeakIonMatch();
virtual const PeptideFragmentIonSp &
getPeptideFragmentIonSp() const
{
return _ion_sp;
};
PeakIonMatch &operator=(const PeakIonMatch &other);
const DataPoint &
getPeak() const
{
return _peak;
};
virtual const PeptideFragmentIonSp &getPeptideFragmentIonSp() const;
unsigned int
getCharge() const
{
return _charge;
};
const DataPoint &getPeak() const;
unsigned int getCharge() const;
PeptideIon getPeptideIonType() const;
PeptideDirection getPeptideIonDirection() const;
virtual QString toString() const;
PeptideIon
getPeptideIonType() const
{
return _ion_sp.get()->getPeptideIonType();
};
PeptideDirection
getPeptideIonDirection() const
{
return _ion_sp.get()
->getPeptideFragmentSp()
.get()
->getPeptideIonDirection();
};
private:
DataPoint _peak;
......
......@@ -32,7 +32,7 @@ PeptideIsotopeSpectrumMatch::PeptideIsotopeSpectrumMatch(
const PeptideSp &peptideSp,
unsigned int parent_charge,
PrecisionPtr precision,
std::list<PeptideIon> ion_type_list,
const std::list<PeptideIon> &ion_type_list,
unsigned int max_isotope_number,
[[maybe_unused]] unsigned int max_isotope_rank)
: _precision(precision)
......@@ -40,6 +40,7 @@ PeptideIsotopeSpectrumMatch::PeptideIsotopeSpectrumMatch(
try
{
_peak_ion_match_list.clear();
qDebug() << "PeptideIsotopeSpectrumMatch::PeptideIsotopeSpectrumMatch "
"begin max_isotope_number="
<< max_isotope_number;
......@@ -47,32 +48,26 @@ PeptideIsotopeSpectrumMatch::PeptideIsotopeSpectrumMatch(
qDebug() << "PeptideIsotopeSpectrumMatch::PeptideIsotopeSpectrumMatch "
"peak_list spectrum.size="
<< spectrum.size();
std::list<DataPoint> peak_list(spectrum.begin(), spectrum.end());
qDebug() << "PeptideIsotopeSpectrumMatch::PeptideIsotopeSpectrumMatch "
"ion_type_list";
std::vector<DataPoint> peak_list(spectrum.begin(), spectrum.end());
for(auto ion_type : ion_type_list)
{
auto ion_list = fragmentIonList.getPeptideFragmentIonSp(ion_type);
qDebug() << "PeptideIsotopeSpectrumMatch::"
"PeptideIsotopeSpectrumMatch fragmentIonList";
for(unsigned int charge = 1; charge <= parent_charge; charge++)
{
for(auto &&ion : ion_list)
{
unsigned int askedIsotopeRank = 1;
for(unsigned int isotope_number = 0;
isotope_number <= max_isotope_number;
isotope_number++)
{
PeptideNaturalIsotopeAverage isotopeIon(ion,
askedIsotopeRank,
isotope_number,
charge,
precision);
PeptideNaturalIsotopeAverage isotopeIon(
ion, isotope_number, charge, precision);
qDebug()
<< isotope_number << " " << isotopeIon.toString();
std::list<DataPoint>::iterator it_peak =
std::vector<DataPoint>::iterator it_peak =
getBestPeakIterator(peak_list, isotopeIon);
if(it_peak != peak_list.end())
{
......@@ -81,13 +76,14 @@ PeptideIsotopeSpectrumMatch::PeptideIsotopeSpectrumMatch(
isotopeIon.makePeptideNaturalIsotopeAverageSp(),
ion));
peak_list.erase(it_peak);
qDebug() << isotope_number << " "
<< _peak_ion_match_list.back().toString();
}
}
}
}
}
qDebug()
<< "PeptideIsotopeSpectrumMatch::PeptideIsotopeSpectrumMatch end";
}
catch(PappsoException &exception_pappso)
{
......@@ -120,7 +116,7 @@ PeptideIsotopeSpectrumMatch::PeptideIsotopeSpectrumMatch(
PrecisionPtr precision)
: _precision(precision)
{
qDebug() << "PeptideIsotopeSpectrumMatch::PeptideIsotopeSpectrumMatch begin";
qDebug() << " begin";
if(v_peptideIsotopeList.size() != v_peptideIonList.size())
{
throw PappsoException(
......@@ -132,11 +128,11 @@ PeptideIsotopeSpectrumMatch::PeptideIsotopeSpectrumMatch(
auto isotopeIt = v_peptideIsotopeList.begin();
auto ionIt = v_peptideIonList.begin();
std::list<DataPoint> peak_list(spectrum.begin(), spectrum.end());
std::vector<DataPoint> peak_list(spectrum.begin(), spectrum.end());
while(isotopeIt != v_peptideIsotopeList.end())
{
std::list<DataPoint>::iterator it_peak =
std::vector<DataPoint>::iterator it_peak =
getBestPeakIterator(peak_list, *(isotopeIt->get()));
if(it_peak != peak_list.end())
{
......@@ -147,7 +143,7 @@ PeptideIsotopeSpectrumMatch::PeptideIsotopeSpectrumMatch(
isotopeIt++;
ionIt++;
}
qDebug() << "PeptideIsotopeSpectrumMatch::PeptideIsotopeSpectrumMatch end";
qDebug() << " end";
}
......@@ -156,6 +152,7 @@ PeptideIsotopeSpectrumMatch::PeptideIsotopeSpectrumMatch(
: _precision(other._precision),
_peak_ion_match_list(other._peak_ion_match_list)
{
qDebug();
}
PeptideIsotopeSpectrumMatch::~PeptideIsotopeSpectrumMatch()
......@@ -163,15 +160,15 @@ PeptideIsotopeSpectrumMatch::~PeptideIsotopeSpectrumMatch()
}
std::list<DataPoint>::iterator
std::vector<DataPoint>::iterator
PeptideIsotopeSpectrumMatch::getBestPeakIterator(
std::list<DataPoint> &peak_list,
std::vector<DataPoint> &peak_list,
const PeptideNaturalIsotopeAverage &ion) const
{
// qDebug();
std::list<DataPoint>::iterator itpeak = peak_list.begin();
std::list<DataPoint>::iterator itend = peak_list.end();
std::list<DataPoint>::iterator itselect = peak_list.end();
std::vector<DataPoint>::iterator itpeak = peak_list.begin();
std::vector<DataPoint>::iterator itend = peak_list.end();
std::vector<DataPoint>::iterator itselect = peak_list.end();
pappso_double best_intensity = 0;
......@@ -197,5 +194,68 @@ PeptideIsotopeSpectrumMatch::getPeakIonIsotopeMatchList() const
return _peak_ion_match_list;
}
std::size_t
PeptideIsotopeSpectrumMatch::size() const
{
return _peak_ion_match_list.size();
}
PeptideIsotopeSpectrumMatch::const_iterator
PeptideIsotopeSpectrumMatch::begin() const
{
return _peak_ion_match_list.begin();
}
PeptideIsotopeSpectrumMatch::const_iterator
PeptideIsotopeSpectrumMatch::end() const
{
return _peak_ion_match_list.end();
}
void
PeptideIsotopeSpectrumMatch::dropPeaksLackingMonoisotope()
{
qDebug();
_peak_ion_match_list.sort(
[](const PeakIonIsotopeMatch &a, const PeakIonIsotopeMatch &b) {
if(a.getPeptideIonType() < b.getPeptideIonType())
return true;
if(a.getPeptideFragmentIonSp().get()->size() <
b.getPeptideFragmentIonSp().get()->size())
return true;
if(a.getCharge() < b.getCharge())
return true;
if(a.getPeptideNaturalIsotopeAverageSp().get()->getIsotopeNumber() <
b.getPeptideNaturalIsotopeAverageSp().get()->getIsotopeNumber())
return true;
return false;
});
PeptideIon ion_type = PeptideIon::b;
std::size_t nserie = 0;
std::size_t isotopeserie = 0;
unsigned int charge = 0;
for(std::list<PeakIonIsotopeMatch>::iterator it =
_peak_ion_match_list.begin();
it != _peak_ion_match_list.end();
it++)
{
if((nserie != it->getPeptideFragmentIonSp().get()->size()) ||
(ion_type != it->getPeptideIonType()) || (charge != it->getCharge()))
{
ion_type = it->getPeptideIonType();
isotopeserie = 0;
nserie = it->getPeptideFragmentIonSp().get()->size();
charge = it->getCharge();
}
if(isotopeserie <=
it->getPeptideNaturalIsotopeAverageSp().get()->getIsotopeNumber())
{
isotopeserie =
it->getPeptideNaturalIsotopeAverageSp().get()->getIsotopeNumber();
}
else
{
it = _peak_ion_match_list.erase(it);
}
}
qDebug();
}
} // namespace pappso
......@@ -53,7 +53,7 @@ class PMSPP_LIB_DECL PeptideIsotopeSpectrumMatch
const PeptideSp &peptide_sp,
unsigned int parent_charge,
PrecisionPtr precision,
std::list<PeptideIon> ion_list,
const std::list<PeptideIon> &ion_type_list,
unsigned int max_isotope_number,
unsigned int max_isotope_rank);
PeptideIsotopeSpectrumMatch(
......@@ -63,32 +63,22 @@ class PMSPP_LIB_DECL PeptideIsotopeSpectrumMatch
PrecisionPtr precision);
PeptideIsotopeSpectrumMatch(const PeptideIsotopeSpectrumMatch &other);
~PeptideIsotopeSpectrumMatch();
virtual ~PeptideIsotopeSpectrumMatch();
const std::list<PeakIonIsotopeMatch> &getPeakIonIsotopeMatchList() const;
typedef std::list<PeakIonIsotopeMatch>::const_iterator const_iterator;
unsigned int
size() const
{
return _peak_ion_match_list.size();
}
const_iterator
begin() const
{
return _peak_ion_match_list.begin();
}
const_iterator
end() const
{
return _peak_ion_match_list.end();
}
std::size_t size() const;
const_iterator begin() const;
const_iterator end() const;
void dropPeaksLackingMonoisotope();
private:
virtual std::list<DataPoint>::iterator
getBestPeakIterator(std::list<DataPoint> &peak_list,
virtual std::vector<DataPoint>::iterator
getBestPeakIterator(std::vector<DataPoint> &peak_list,
const PeptideNaturalIsotopeAverage &ion) const;
PrecisionPtr _precision;
......
......@@ -61,7 +61,7 @@ class PMSPP_LIB_DECL PeptideSpectrumMatch
PrecisionPtr precision);
PeptideSpectrumMatch(const PeptideSpectrumMatch &other);
~PeptideSpectrumMatch();
virtual ~PeptideSpectrumMatch();
bool contains(const PeptideFragmentIon *peptideFragmentIonSp,
unsigned int z) const;
......
......@@ -262,9 +262,11 @@ XtandemHyperscore::getHyperscore() const
{
try
{
qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__
<< " _proto_hyperscore=" << _proto_hyperscore;
return (log10(_proto_hyperscore) * 4);
qDebug() << " _proto_hyperscore=" << _proto_hyperscore;
double hyperscore = (log10(_proto_hyperscore) * 4);
if(hyperscore < 0)
return 0;
return hyperscore;
}
catch(PappsoException &exception_pappso)
{
......
......@@ -323,6 +323,35 @@ areaTrace(std::vector<DataPoint>::const_iterator begin,
}
double
areaTraceMinusBase(std::vector<DataPoint>::const_iterator begin,
std::vector<DataPoint>::const_iterator end)
{
if(begin == end)
return 0;
auto previous = begin;
auto next = begin + 1;
auto last = next;
double area = 0;
while(next != end)
{
last = next;
area += ((next->x - previous->x) * (previous->y + next->y)) / (double)2;
previous++;
next++;
}
if(area > 0)
{
// remove base peak area
area -= (((last->y + begin->y) * (last->x - begin->x)) / 2);
if(area < 0)
return 0;
}
return area;
}
Trace
flooredLocalMaxima(std::vector<DataPoint>::const_iterator begin,
std::vector<DataPoint>::const_iterator end,
......
......@@ -126,7 +126,6 @@ quantileYTrace(std::vector<DataPoint>::const_iterator begin,
PMSPP_LIB_DECL double areaTrace(std::vector<DataPoint>::const_iterator begin,
std::vector<DataPoint>::const_iterator end);
PMSPP_LIB_DECL Trace
flooredLocalMaxima(std::vector<DataPoint>::const_iterator begin,
std::vector<DataPoint>::const_iterator end,
......@@ -210,14 +209,17 @@ class PMSPP_LIB_DECL Trace : public std::vector<DataPoint>
virtual Trace &filter(const FilterInterface &filter) final;
QString toString() const;
/** @brief find datapoint with exactly x value
*/
std::vector<DataPoint>::const_iterator
dataPointCstIteratorWithX(pappso_double value) const;
protected:
//! Return a reference to the DataPoint instance that has its y member equal
//! to \p value.
// const DataPoint &dataPointWithX(pappso_double value) const;
std::size_t dataPointIndexWithX(pappso_double value) const;
std::vector<DataPoint>::iterator dataPointIteratorWithX(pappso_double value);
std::vector<DataPoint>::const_iterator
dataPointCstIteratorWithX(pappso_double value) const;
};
......
......@@ -966,7 +966,7 @@ void
TimsData::getQualifiedMs1MassSpectrumByPrecursorId(
const MsRunIdCstSPtr &msrun_id,
QualifiedMassSpectrum &mass_spectrum,
SpectrumDescr &spectrum_descr,
const SpectrumDescr &spectrum_descr,
bool want_binary_data)
{
......@@ -1410,7 +1410,7 @@ void
TimsData::getQualifiedMs2MassSpectrumByPrecursorId(
const MsRunIdCstSPtr &msrun_id,
QualifiedMassSpectrum &mass_spectrum,
SpectrumDescr &spectrum_descr,
const SpectrumDescr &spectrum_descr,
bool want_binary_data)
{
try
......@@ -1799,9 +1799,10 @@ pappso::TimsData::ms2ReaderSpectrumCollectionByMsLevel(
std::function<std::vector<QualifiedMassSpectrum>(
pappso::TimsData::SpectrumDescr &)>
generate_spectrum = [itself, msrun_id, pointer_handler, ms_level](
pappso::TimsData::SpectrumDescr &spectrum_descr)
const pappso::TimsData::SpectrumDescr &)>
map_function_generate_spectrum =
[itself, msrun_id, pointer_handler, ms_level](
const pappso::TimsData::SpectrumDescr &spectrum_descr)
-> std::vector<QualifiedMassSpectrum> {
std::vector<QualifiedMassSpectrum> mass_spectrum_list;
itself->ms2ReaderGenerateMS1MS2Spectrum(msrun_id,
......@@ -1814,28 +1815,35 @@ pappso::TimsData::ms2ReaderSpectrumCollectionByMsLevel(
return mass_spectrum_list;
};
std::function<void(
std::size_t,
const std::vector<QualifiedMassSpectrum> &qualified_spectrum_list)>
reduce_function_spectrum_list =
[pointer_handler, local_filepath](
std::size_t res,
const std::vector<QualifiedMassSpectrum> &qualified_spectrum_list) {
for(auto &qualified_spectrum : qualified_spectrum_list)
{
pointer_handler->setQualifiedMassSpectrum(qualified_spectrum);
}
if(pointer_handler->shouldStop())
{
qDebug() << "The operation was cancelled. Breaking the loop.";
throw ExceptionInterrupted(
QObject::tr("reading TimsTOF job on %1 cancelled by the user")
.arg(local_filepath));
}
res++;
};
QFuture<std::size_t> res;
res = QtConcurrent::mappedReduced<std::size_t>(
spectrum_description_list.begin(),
spectrum_description_list.end(),
generate_spectrum,
[pointer_handler, res, local_filepath](
std::size_t &result,
std::vector<QualifiedMassSpectrum> qualified_spectrum_list) {
for(auto &qualified_spectrum : qualified_spectrum_list)
{
pointer_handler->setQualifiedMassSpectrum(qualified_spectrum);
}
if(pointer_handler->shouldStop())
{
qDebug() << "The operation was cancelled. Breaking the loop.";
throw ExceptionInterrupted(
QObject::tr("reading TimsTOF job cancelled by the user :\n%1")
.arg(local_filepath));
}
result++;
},
map_function_generate_spectrum,
reduce_function_spectrum_list,
QtConcurrent::OrderedReduce);
res.waitForFinished();
}
......@@ -1849,7 +1857,7 @@ pappso::TimsData::ms2ReaderGenerateMS1MS2Spectrum(
const MsRunIdCstSPtr &msrun_id,
std::vector<QualifiedMassSpectrum> &qualified_mass_spectrum_list,
pappso::SpectrumCollectionHandlerInterface &handler,
pappso::TimsData::SpectrumDescr &spectrum_descr,
const pappso::TimsData::SpectrumDescr &spectrum_descr,
unsigned int ms_level)
{
......
......@@ -129,13 +129,13 @@ class PMSPP_LIB_DECL TimsData
void
getQualifiedMs2MassSpectrumByPrecursorId(const MsRunIdCstSPtr &msrun_id,
QualifiedMassSpectrum &mass_spectrum,
SpectrumDescr &spectrum_descr,
const SpectrumDescr &spectrum_descr,
bool want_binary_data);
void
getQualifiedMs1MassSpectrumByPrecursorId(const MsRunIdCstSPtr &msrun_id,
QualifiedMassSpectrum &mass_spectrum,
SpectrumDescr &spectrum_descr,
const SpectrumDescr &spectrum_descr,
bool want_binary_data);
/** @brief filter interface to apply just after raw MS2 specturm extraction
......@@ -282,7 +282,7 @@ class PMSPP_LIB_DECL TimsData
const MsRunIdCstSPtr &msrun_id,
std::vector<QualifiedMassSpectrum> &qualified_mass_spectrum_list,
SpectrumCollectionHandlerInterface &handler,
SpectrumDescr &spectrum_descr,
const SpectrumDescr &spectrum_descr,
unsigned int ms_level);
void fillSpectrumDescriptionWithSqlRecord(SpectrumDescr &spectrum_descr,
......
......@@ -492,4 +492,69 @@ TimsFrameBase::getScanIntensities(std::size_t scanNum) const
"ERROR unable to getScanIntensities in TimsFrameBase for scan number %1")
.arg(scanNum));
}
Trace
TimsFrameBase::getIonMobilityTraceByMzIndexRange(
std::size_t mz_index_lower_bound,
std::size_t mz_index_upper_bound,
XicExtractMethod method) const
{
Trace im_trace;
DataPoint data_point;
for(quint32 i = 0; i < m_scanNumber; i++)
{
data_point.x = i;
data_point.y = 0;
qDebug() << "m_scanNumber=" << m_scanNumber << " i=" << i;
std::vector<quint32> index_list = getScanIndexList(i);
auto it_lower = std::find_if(index_list.begin(),
index_list.end(),
[mz_index_lower_bound](quint32 to_compare) {
if(to_compare < mz_index_lower_bound)
{
return false;
}
return true;
});
if(it_lower == index_list.end())
{
}
else
{
auto it_upper =
std::find_if(index_list.begin(),
index_list.end(),
[mz_index_upper_bound](quint32 to_compare) {
if(mz_index_upper_bound >= to_compare)
{
return false;
}
return true;
});
std::vector<quint32> intensity_list = getScanIntensities(i);
for(int j = std::distance(index_list.begin(), it_lower);
j < std::distance(index_list.begin(), it_upper);
j++)
{
if(method == XicExtractMethod::sum)
{
data_point.y += intensity_list[j];
}
else
{
data_point.y =
std::max((double)intensity_list[j], data_point.y);
}
}
}
im_trace.push_back(data_point);
}
qDebug();
return im_trace;
}
// namespace pappso
} // namespace pappso
......@@ -213,6 +213,17 @@ class TimsFrameBase
*/
virtual std::vector<quint32> getScanIntensities(std::size_t scanNum) const;
/** @brief get a mobility trace cumulating intensities inside the given mass
* index range
* @param mz_index_lower_bound raw mass index lower bound
* @param mz_index_upper_bound raw mass index upper bound
* @param method max or sum intensities
*/
virtual Trace
getIonMobilityTraceByMzIndexRange(std::size_t mz_index_lower_bound,
std::size_t mz_index_upper_bound,
XicExtractMethod method) const;
protected:
/** @brief total number of scans contained in this frame
......
......@@ -202,7 +202,9 @@ MassSpectrumWidget::peptideAnnotate()
_max_isotope_number,
_max_isotope_rank);
_peak_ion_isotope_match_list = psm_match.getPeakIonIsotopeMatchList();
_peak_ion_isotope_match_list = std::list<PeakIonIsotopeMatch>(
psm_match.getPeakIonIsotopeMatchList().begin(),
psm_match.getPeakIonIsotopeMatchList().end());
}
else
{
......@@ -318,11 +320,17 @@ MassSpectrumWidget::plot()
}
else
{
qDebug();
_peak_ion_isotope_match_list.sort(
[](const PeakIonIsotopeMatch &a, const PeakIonIsotopeMatch &b) {
return a.getPeak().y > b.getPeak().y;
qDebug() << a.getPeak().y << " > ";
qDebug() << b.getPeak().y << " . ";
return (a.getPeak().y > b.getPeak().y);
});
qDebug();
unsigned int i = 0;
qDebug();
for(const PeakIonIsotopeMatch &peak_ion_match :
_peak_ion_isotope_match_list)
{
......@@ -358,6 +366,7 @@ MassSpectrumWidget::plot()
}
}
qDebug();
_custom_plot->replot();
qDebug();
}
......
/**
* \file pappsomspp/widget/spectrumwidget/massspectrumwidget.h
* \file pappsomspp/widget/massspectrumwidget/massspectrumwidget.h
* \date 22/12/2017
* \author Olivier Langella
* \brief plot a sectrum and annotate with peptide
......
......@@ -300,8 +300,8 @@ QCPSpectrum::mousePressEvent(QMouseEvent *event)
<< xAxis->pixelToCoord(event->x()) << " "
<< yAxis->pixelToCoord(event->y());*/
_click = true;
_old_x = event->x();
_old_y = yAxis->pixelToCoord(event->y());
_old_x = event->position().x();
_old_y = yAxis->pixelToCoord(event->position().y());
if(_old_y < 0)
_old_y = 0;
/* qDebug() << "QCPSpectrum::mousePressEvent end";*/
......@@ -318,13 +318,13 @@ QCPSpectrum::mouseReleaseEvent(QMouseEvent *event [[maybe_unused]])
void
QCPSpectrum::mouseMoveEvent(QMouseEvent *event)
{
pappso::pappso_double x = xAxis->pixelToCoord(event->x());
pappso::pappso_double x = xAxis->pixelToCoord(event->position().x());
if(_click)
{
/* qDebug() << "QCPSpectrum::mouseMoveEvent begin "
<< xAxis->pixelToCoord(event->x()) << " "
<< yAxis->pixelToCoord(event->y());*/
pappso::pappso_double y = yAxis->pixelToCoord(event->y());
pappso::pappso_double y = yAxis->pixelToCoord(event->position().y());
if(y < 0)
{
y = 0;
......@@ -339,9 +339,9 @@ QCPSpectrum::mouseMoveEvent(QMouseEvent *event)
else
{
this->xAxis->moveRange(xAxis->pixelToCoord(_old_x) -
xAxis->pixelToCoord(event->x()));
xAxis->pixelToCoord(event->position().x()));
}
_old_x = event->x();
_old_x = event->position().x();
_old_y = y;
replot();
// qDebug() << "QCPSpectrum::mouseMoveEvent end";
......
......@@ -132,7 +132,6 @@ BaseTracePlotWidget::setGraphData(QCPGraph *graph_p,
QVector<double> key_qvector;
QVector<double> value_qvector;
#pragma GCC warning "Filippo Rusconi: Please check if the bug was fixed in Qt"
#if 0
// Now replace the graph's data. Note that the data are
......@@ -204,8 +203,6 @@ BaseTracePlotWidget::addTrace(const pappso::Trace &trace, const QColor &color)
QVector<double> key_qvector;
QVector<double> value_qvector;
#pragma GCC warning "Filippo Rusconi: Please check if the bug was fixed in Qt"
#if 0
// Now replace the graph's data. Note that the data are
// inherently sorted (true below).
......