33#include <unordered_set>
42namespace specpeptidoms
48 : std::vector<
pappso::specglob::ExperimentalSpectrumDataPoint>(
49 specglob::ExperimentalSpectrum(qmass_spectrum, precision_ptr)),
50 m_qualifiedMassSpectrum(qmass_spectrum),
51 m_precision_ptr(precision_ptr),
53 m_precursor_mass_error(0)
58 m_aapositions.push_back(std::make_shared<std::vector<AaPosition>>());
64 for(std::size_t iter = 1; iter < this->size(); iter++)
75 : std::vector<
pappso::specglob::ExperimentalSpectrumDataPoint>(
76 pappso::specglob::ExperimentalSpectrum(other.m_qualifiedMassSpectrum, other.m_precision_ptr)),
77 m_qualifiedMassSpectrum(other.m_qualifiedMassSpectrum),
78 m_aapositions(other.m_aapositions),
79 m_precision_ptr(other.m_precision_ptr),
80 m_supported_peaks(other.m_supported_peaks),
81 m_reindexed_peaks(other.m_reindexed_peaks),
82 m_aaCode(other.m_aaCode),
83 m_complementary_peak_indexes(other.m_complementary_peak_indexes),
84 m_precursor_mass_error(other.m_precursor_mass_error)
89 double precursor_mass_error)
90 : std::vector<
pappso::specglob::ExperimentalSpectrumDataPoint>(
91 pappso::specglob::ExperimentalSpectrum(
92 other.m_qualifiedMassSpectrum, other.m_precision_ptr, precursor_mass_error)),
93 m_qualifiedMassSpectrum(other.m_qualifiedMassSpectrum),
94 m_precision_ptr(other.m_precision_ptr),
95 m_aaCode(other.m_aaCode),
96 m_precursor_mass_error(precursor_mass_error)
101 m_aapositions.push_back(std::make_shared<std::vector<AaPosition>>());
107 for(std::size_t iter = 1; iter < this->size(); iter++)
113 this->back().peak_mz =
128 std::vector<double>::iterator iter1, iter2;
129 std::size_t peak1, peak2, next_l_peak;
130 std::vector<double> mass_list = getMassList();
133 for(iter1 = mass_list.begin(); iter1 != mass_list.end(); iter1++)
137 for(iter2 = iter1 + 1; iter2 != mass_list.end(); iter2++)
140 aa = m_aaCode.getAaCodeByMass(*(iter2) - *(iter1), m_precision_ptr);
144 for(std::size_t iter = 1; iter < peak1;
148 if(m_reindexed_peaks.at(iter) >= 0)
153 if(m_reindexed_peaks.at(peak2) == -1)
155 addSupportedPeak(peak2);
156 m_supported_peaks.at(peak2)->push_back(aa);
158 if(m_reindexed_peaks.at(peak1) >= 0)
160 addAaPosition(aa, peak2, peak1, next_l_peak,
true);
164 addAaPosition(aa, peak2, next_l_peak, next_l_peak,
false);
170 removeUnsupportedMasses();
171 correctPeakIndexes();
180 fillComplementaryPeakIndexes();
222 std::vector<specglob::ExperimentalSpectrumDataPoint> kept_peaks;
223 for(std::vector<specglob::ExperimentalSpectrumDataPoint>::iterator iter = this->begin();
227 if(m_reindexed_peaks.at(iter->indice) >= 0)
229 kept_peaks.push_back(*iter);
233 this->assign(kept_peaks.begin(), kept_peaks.end());
238 const std::size_t r_peak,
239 const std::size_t l_peak,
240 const std::size_t next_l_peak,
247 m_aapositions.at(aa - 1)->push_back(
248 {r_peak, l_peak, next_l_peak, computeCondition(l_peak, l_support), l_support});
252 m_aapositions.at(aa - 1)->push_back(
253 {r_peak, next_l_peak, next_l_peak, computeCondition(l_peak, l_support), l_support});
259 bool l_support)
const
273 for(std::vector<uint8_t>::iterator aa = m_supported_peaks.at(l_peak)->begin();
274 aa != m_supported_peaks.at(l_peak)->end();
277 condition += 2 << *(aa);
284const std::vector<pappso::specpeptidoms::AaPosition> &
288 return *m_aapositions.at(aa_code - 1);
291std::vector<pappso::specpeptidoms::AaPosition>
293 std::uint8_t aa_code, std::vector<std::size_t> &peaks_to_remove)
const
295 std::vector<AaPosition> aa_positions;
296 for(
auto aap : *m_aapositions.at(aa_code - 1))
298 if(std::find(peaks_to_remove.begin(), peaks_to_remove.end(), aap.r_peak) ==
299 peaks_to_remove.end())
301 aa_positions.push_back(aap);
310 std::vector<double> mass_list;
313 mass_list.push_back(n.peak_mz);
321 return this->at(indice).type;
327 return m_qualifiedMassSpectrum.getPrecursorCharge();
332 return m_qualifiedMassSpectrum.getPrecursorMass();
339 if(std::max(r_peak, l_peak) > size())
342 QObject::tr(
"getMZShift : l_peak %1 or r_peak %2 greater than size %3")
347 return this->at(r_peak).peak_mz - this->at(l_peak).peak_mz;
356 QObject::tr(
"getMissingMass : peak %1 greater than size %2").arg(peak).arg(size()));
358 return this->m_qualifiedMassSpectrum.getPrecursorMass() - m_precursor_mass_error -
359 this->at(peak).peak_mz +
MHPLUS;
365 std::size_t counter = 0;
366 for(std::size_t iter = 0; iter < peak; iter++)
368 if(m_reindexed_peaks.at(iter) >= 0)
373 m_reindexed_peaks.at(peak) = counter;
374 for(std::size_t iter = peak + 1; iter < m_reindexed_peaks.size(); iter++)
376 if(m_reindexed_peaks.at(iter) >= 0)
378 m_reindexed_peaks.at(iter)++;
386 for(
auto aa = m_aapositions.begin(); aa != m_aapositions.end(); aa++)
388 for(
auto aap = aa->get()->begin(); aap != aa->get()->end(); aap++)
390 aap->l_peak = m_reindexed_peaks.at(aap->l_peak);
391 aap->r_peak = m_reindexed_peaks.at(aap->r_peak);
392 aap->next_l_peak = m_reindexed_peaks.at(aap->next_l_peak);
400 std::size_t left_index, right_index;
402 m_complementary_peak_indexes.reserve(this->size());
403 while(m_complementary_peak_indexes.size() < this->size())
405 m_complementary_peak_indexes.push_back(0);
408 right_index = this->size() - 1;
409 double comp_mass = m_qualifiedMassSpectrum.getPrecursorMass() + 2 *
MHPLUS;
411 while(left_index < right_index)
413 pappso::MzRange mz_range(comp_mass - this->at(left_index).peak_mz, m_precision_ptr);
414 if(mz_range.
contains(this->at(right_index).peak_mz))
416 m_complementary_peak_indexes.at(left_index) = right_index;
417 m_complementary_peak_indexes.at(right_index) = left_index;
418 qDebug() << left_index << right_index;
420 if(comp_mass - this->at(left_index).peak_mz - this->at(right_index).peak_mz >= 0)
434 return m_complementary_peak_indexes.at(peak);
collection of integer code for each amino acid 0 => null 1 to 20 => amino acid sorted by there mass (...
std::size_t getSize() const
bool contains(pappso_double) const
Class representing a fully specified mass spectrum.
double getPrecursorMass(bool *ok_p=nullptr) const
get precursor mass given the charge stats and precursor mz
void preprocessSpectrum()
Preprocess the spectrum.
double getMZShift(std::size_t l_peak, std::size_t r_peak) const
Returns the mz difference between two peaks.
uint getPrecursorCharge() const
Returns the spectrum's precursor's charge.
SpOMSSpectrum(pappso::QualifiedMassSpectrum &qmass_spectrum, pappso::PrecisionPtr precision_ptr, const pappso::AaCode &aaCode)
double getMissingMass(std::size_t peak) const
Returns the missing mass between a peak and the precursor's mass (shift at the end).
std::vector< std::shared_ptr< std::vector< uint8_t > > > m_supported_peaks
uint32_t computeCondition(const std::size_t l_peak, bool l_support) const
Computes the "condition" integer, used to apply the three peaks rule.
void addAaPosition(uint8_t aa, const std::size_t r_peak, const std::size_t l_peak, const std::size_t next_l_peak, bool l_support)
Adds an amino acid position to the data structure.
void removeUnsupportedMasses()
Removes the unsupported peaks (without an amino acid to the left) from the spectrum.
pappso::QualifiedMassSpectrum m_qualifiedMassSpectrum
std::vector< std::shared_ptr< std::vector< AaPosition > > > m_aapositions
void correctPeakIndexes()
Reindexes the peaks after removal of the unsupported peaks.
void addSupportedPeak(std::size_t peak)
Add a peak to the supported peaks list.
void fillComplementaryPeakIndexes()
For each point of the spectrum, indicate the index of its complementary peak;.
std::vector< int > m_reindexed_peaks
std::size_t getComplementaryPeak(std::size_t peak) const
const std::vector< AaPosition > & getAaPositions(std::uint8_t aa_code) const
Returns the list of aa_positions for a given amino acid code.
specglob::ExperimentalSpectrumDataPointType peakType(std::size_t indice) const
Returns the type of one of the spectrum's peaks.
std::vector< double > getMassList() const
Returns the spectrum's list of masses.
double getPrecursorMass() const
const pappso::AaCode & m_aaCode
ExperimentalSpectrumDataPointType
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
const pappso_double MHPLUS(1.007276466879)
const pappso_double MPROTIUM(1.007825032241)
const pappso_double MASSOXYGEN(15.99491461956)