libpappsomspp
Library for mass spectrometry
Loading...
Searching...
No Matches
pappso::specglob::SpectralAlignment Class Reference

#include <spectralalignment.h>

Public Member Functions

 SpectralAlignment (ScoreValues score_values, pappso::PrecisionPtr precision_ptr)
 ~SpectralAlignment ()
void align (PeptideSpectraCsp peptide_spectrum, ExperimentalSpectrumCsp experimental_spectrum)
 build the alignment matrix between a peptide sequence and an experimental spectrum
PeptideModel rtrim (PrecisionPtr precision_ptr)
 trim the current peptide to get a minimal alignment score
const matrix< SpectralAlignmentDataPoint > & getMatrix () const
std::vector< int > getScoreRow (std::size_t row_indice) const
int getMaxScore () const
boost::numeric::ublas::matrix< SpectralAlignmentDataPoint >::iterator2 getMaxPosIterator () const
double getPrecursorMzDelta () const
QString backTrack () const
PeptideModel buildPeptideModel () const
ExperimentalSpectrumCsp getExperimentalSpectrumCsp () const
PeptideSpectraCsp getPeptideSpectraCsp () const

Private Member Functions

const ExperimentalSpectrumDataPointgetExperimentalSpectrumDataPoint (const boost::numeric::ublas::matrix< SpectralAlignmentDataPoint >::iterator2 &itpos) const
void fillMassDelta (const PeptideSpectrum &peptide_spectrum, const ExperimentalSpectrum &experimental_spectrum)
void fillMatricesWithScores (const boost::numeric::ublas::matrix< SpectralAlignmentDataPoint >::iterator2 &it_pos, const PeptideSpectrum &peptide_spectrum, const ExperimentalSpectrum &experimental_spectrum)
SpectralAlignmentDataPoint getBestRealignScore (const boost::numeric::ublas::matrix< SpectralAlignmentDataPoint >::iterator2 &it_pos, std::size_t expeIndicesK, int reAlignScore, int alignScoreToAdd)

Private Attributes

ExperimentalSpectrumCsp mcsp_experimentalSpectrum
PeptideSpectraCsp mcsp_peptideSpectrum
matrix< SpectralAlignmentDataPointm_matrix
pappso::PrecisionPtr m_precisionPtr
ScoreValues m_scoreValues
int m_maxScore
boost::numeric::ublas::matrix< SpectralAlignmentDataPoint >::iterator2 m_itPosMax
double m_precursorMassDelta
bool m_BETTER_END_RA = false

Detailed Description

Todo
write docs

Definition at line 64 of file spectralalignment.h.

Constructor & Destructor Documentation

◆ SpectralAlignment()

pappso::specglob::SpectralAlignment::SpectralAlignment ( ScoreValues score_values,
pappso::PrecisionPtr precision_ptr )

Default constructor

Definition at line 47 of file spectralalignment.cpp.

48{
49 m_precisionPtr = precision_ptr;
50 m_scoreValues = score_values;
51}

References m_precisionPtr, and m_scoreValues.

◆ ~SpectralAlignment()

pappso::specglob::SpectralAlignment::~SpectralAlignment ( )

Destructor

Definition at line 53 of file spectralalignment.cpp.

54{
55}

Member Function Documentation

◆ align()

void pappso::specglob::SpectralAlignment::align ( PeptideSpectraCsp peptide_spectrum,
ExperimentalSpectrumCsp experimental_spectrum )

build the alignment matrix between a peptide sequence and an experimental spectrum

Parameters
peptide_spectrumthe peptide sequence
experimental_spectrumthe experimental spectrum

Definition at line 70 of file spectralalignment.cpp.

72{
73 mcsp_experimentalSpectrum = experimental_spectrum;
74 mcsp_peptideSpectrum = peptide_spectrum;
75 m_maxScore = 0;
76 m_matrix.resize(mcsp_peptideSpectrum.get()->size(), mcsp_experimentalSpectrum.get()->size());
77
78 // set the value of difference between Precursor mass and theoretical mass of
79 // the proposed peptide
80 m_precursorMassDelta = mcsp_experimentalSpectrum.get()->getPrecursorMass() -
81 mcsp_peptideSpectrum.get()->getPeptideSp().get()->getMass();
82
84
85 m_itPosMax = m_matrix.end2();
86 // Make the alignment in filling the matrices
87
88 auto last_theoretical_peptide = std::prev(m_matrix.end1());
89 for(auto itmi = ++m_matrix.begin1(); itmi != m_matrix.end1(); ++itmi)
90 {
91 for(auto itmj = ++itmi.begin(); itmj != itmi.end(); itmj++)
92 {
93 // qDebug() << "i=" << itmj.index1() << " j=" << itmj.index2();
96 // keep the Max Score during matrixes filling
97 // the condition is to keep the max score in the last line (last
98 // theoretical amino acid) This is for try to keep all amino acids of
99 // the initial Theoretical sequence (but can modify alignment choice)
100 if(itmi == last_theoretical_peptide && (*itmj).score > m_maxScore)
101 {
102 m_maxScore = (*itmj).score;
103 m_itPosMax = itmj;
104 }
105 }
106 }
107}
void fillMassDelta(const PeptideSpectrum &peptide_spectrum, const ExperimentalSpectrum &experimental_spectrum)
ExperimentalSpectrumCsp mcsp_experimentalSpectrum
boost::numeric::ublas::matrix< SpectralAlignmentDataPoint >::iterator2 m_itPosMax
matrix< SpectralAlignmentDataPoint > m_matrix
void fillMatricesWithScores(const boost::numeric::ublas::matrix< SpectralAlignmentDataPoint >::iterator2 &it_pos, const PeptideSpectrum &peptide_spectrum, const ExperimentalSpectrum &experimental_spectrum)

References fillMassDelta(), fillMatricesWithScores(), m_itPosMax, m_matrix, m_maxScore, m_precursorMassDelta, mcsp_experimentalSpectrum, and mcsp_peptideSpectrum.

Referenced by pappso::cbor::psm::PsmSpecGlobScan::process(), and rtrim().

◆ backTrack()

QString pappso::specglob::SpectralAlignment::backTrack ( ) const

Backtrack is here to get the HitModified Sequence during the backtrack of score calculation. It start from best score align case in matrix and use origin matrix to go back to the start of the alignment

Parameters
row: the row indices of the best score
column: the column indices of the best score
precision: the precision of measures

Definition at line 414 of file spectralalignment.cpp.

415{
416 if(m_maxScore < 1)
417 {
418 throw pappso::PappsoException("no backtrack");
419 }
420 QString pepModified = "";
421 QString theoSequence = mcsp_peptideSpectrum.get()->getPeptideSp().get()->getSequence();
422 int actualI = m_itPosMax.index1();
423 int prevI;
424 int actualJ = m_itPosMax.index2();
425 int prevJ;
426 double actualDelMass;
427 double prevDelMass;
428 int modifCount = 0;
429 double totExplainMass = 0.0;
430
431 // System.out.println(theoSequence);
432 // System.out.println("actualI is : " + actualI + " and actualJ is : " +
433 // actualJ);
434
435 while(actualI > 0)
436 {
437 // System.out.println(actualI);
438 // define the actual mass delta to the actual i and j
439 QString tempPepSeq = "";
440 QString tempAA = "";
441 QString aminoAcid = "";
442 actualDelMass = m_matrix(actualI, actualJ).mass_difference;
443 prevI = actualI - 1;
444 prevJ = m_matrix(actualI, actualJ).origin_column_indices;
445 prevDelMass = m_matrix(prevI, prevJ).mass_difference;
446
447 // We checking first if last Amino acid are not aligned
448
449 if(m_matrix(actualI, actualJ).alignment_type == SpectralAlignmentType::nonAlign)
450 {
451 // System.out.println("I'm NON ALIGN");
452 tempPepSeq = QString("[%1]").arg(theoSequence.at(actualI - 1));
453
454 while(m_matrix(prevI, prevJ).alignment_type == SpectralAlignmentType::nonAlign &&
455 prevI > 0)
456 {
457 tempPepSeq = QString("[%1]").arg(theoSequence.at(prevI - 1)) + tempPepSeq;
458 prevI--;
459 }
460 // modifCount++;
461 actualI = prevI;
462 actualJ = prevJ;
463
464 pepModified = tempPepSeq + pepModified;
465
466 qDebug() << "a1 pepModified=" << pepModified;
467 // if not, we are in the case where there is an alignment or a
468 // realignment if there is Align or a re-align, put the letter of
469 // Amino Acid and check what we get before to see if we have a mass
470 // change
471 }
472 else
473 {
474 // we put the actual amino acid because he is found, and in function
475 // of alignment type, we can have a mass offset
476 tempPepSeq = QString("%1").arg(theoSequence.at(actualI - 1));
477 aminoAcid = tempPepSeq;
478
479 // we check if there is a deletion before the founded aminoAcid
480 if(prevI > 0 && m_matrix(prevI, prevJ).alignment_type == SpectralAlignmentType::nonAlign)
481 {
482
483 // modifCount++;
484
485 // we continue to check if this is a deletion bloc to keep the
486 // mass difference due to the deletion of the block
487 while(prevI > 0 &&
488 m_matrix(prevI, prevJ).alignment_type == SpectralAlignmentType::nonAlign)
489 {
490
491 tempPepSeq = QString("[%1]").arg(theoSequence.at(prevI - 1)) + tempPepSeq;
492 tempAA = QString("%1").arg(theoSequence.at(prevI - 1)) + tempAA;
493
494 prevI--;
495 prevDelMass = m_matrix(prevI, prevJ).mass_difference;
496 if(prevI == 0)
497 {
498 prevDelMass = 0.0;
499 }
500 }
501
502 // check the mass delta to avoid showing a null mass delta
503 if(std::abs(actualDelMass - prevDelMass) > m_precisionPtr->getNominal())
504 {
505
506 tempPepSeq = tempPepSeq.mid(0, tempPepSeq.length() - 1);
507
508 tempPepSeq += QString("[%1]").arg(actualDelMass - prevDelMass) + aminoAcid;
509 totExplainMass += (actualDelMass - prevDelMass);
510 modifCount++;
511 qDebug() << "a2a1 tempPepSeq=" << tempPepSeq;
512 }
513
514 // if there this is just a re-align, we need to indicate the mass
515 // offset
516 }
517 else if(m_matrix(actualI, actualJ).alignment_type == SpectralAlignmentType::reAlign)
518 {
519
520 tempPepSeq = QString("[%1]").arg(actualDelMass - prevDelMass) + tempPepSeq;
521 modifCount++;
522 totExplainMass += (actualDelMass - prevDelMass);
523
524 // the fact when you align the first amino acid, but there is a
525 // leak of Amino acid in OMS solution before
526 }
527 else if(actualI == 1 &&
528 m_matrix(actualI, actualJ).alignment_type == SpectralAlignmentType::align &&
529 (std::abs(actualDelMass) > m_precisionPtr->getNominal()))
530 {
531 tempPepSeq = QString("[%1]").arg(actualDelMass) + tempPepSeq;
532 totExplainMass += actualDelMass;
533 modifCount++;
534 }
535
536 pepModified = tempPepSeq + pepModified;
537 qDebug() << "a2 pepModified=" << pepModified;
538 // System.out.println(pepModified);
539
540 actualI = prevI;
541 actualJ = prevJ;
542 }
543 }
544
545 // setModificationNumber(modifCount);
546
547 return QString("%1_[%2]").arg(pepModified).arg(m_precursorMassDelta - totExplainMass);
548}
@ nonAlign
the type of alignment to put in origin matrix NON Alignment (0 - NA)
Definition types.h:49
@ reAlign
Re Alignment (1 - RE).
Definition types.h:51

References pappso::specglob::align, m_itPosMax, m_matrix, m_maxScore, m_precisionPtr, m_precursorMassDelta, mcsp_peptideSpectrum, pappso::specglob::nonAlign, and pappso::specglob::reAlign.

◆ buildPeptideModel()

PeptideModel pappso::specglob::SpectralAlignment::buildPeptideModel ( ) const

Definition at line 552 of file spectralalignment.cpp.

553{
554 if(m_maxScore < 1)
555 {
556 throw pappso::PappsoException(
557 QObject::tr("building peptide model failed m_maxScore == %1").arg(m_maxScore));
558 }
559 PeptideModel sg_peptide_model(mcsp_experimentalSpectrum.get()->getQualifiedMassSpectrum(),
560 *(mcsp_peptideSpectrum.get()->getPeptideSp().get()));
561 int actualI = m_itPosMax.index1();
562 int prevI;
563 int actualJ = m_itPosMax.index2();
564 int prevJ;
565 double actualDelMass;
566 double prevDelMass;
567
568 // System.out.println(theoSequence);
569 // System.out.println("actualI is : " + actualI + " and actualJ is : " +
570 // actualJ);
571
572 while(actualI > 0)
573 {
574 // System.out.println(actualI);
575 // define the actual mass delta to the actual i and j
576 QString aminoAcid = "";
577 actualDelMass = m_matrix(actualI, actualJ).mass_difference;
578 prevI = actualI - 1;
579 prevJ = m_matrix(actualI, actualJ).origin_column_indices;
580 prevDelMass = m_matrix(prevI, prevJ).mass_difference;
581
582 // We checking first if last Amino acid are not aligned
583
584 if(m_matrix(actualI, actualJ).alignment_type == SpectralAlignmentType::nonAlign)
585 {
586 // System.out.println("I'm NON ALIGN");
587
588 while(m_matrix(prevI, prevJ).alignment_type == SpectralAlignmentType::nonAlign &&
589 prevI > 0)
590 {
591 if(prevI > 0)
592 sg_peptide_model[prevI - 1].bracket = true;
593 prevI--;
594 }
595 // modifCount++;
596 actualI = prevI;
597 actualJ = prevJ;
598
599 // if not, we are in the case where there is an alignment or a
600 // realignment if there is Align or a re-align, put the letter of
601 // Amino Acid and check what we get before to see if we have a mass
602 // change
603 }
604 else
605 {
606 // we put the actual amino acid because he is found, and in function
607 // of alignment type, we can have a mass offset
608
609 // we check if there is a deletion before the founded aminoAcid
610 if(prevI > 0 && m_matrix(prevI, prevJ).alignment_type == SpectralAlignmentType::nonAlign)
611 {
612
613 // modifCount++;
614
615 // we continue to check if this is a deletion bloc to keep the
616 // mass difference due to the deletion of the block
617 while(prevI > 0 &&
618 m_matrix(prevI, prevJ).alignment_type == SpectralAlignmentType::nonAlign)
619 {
620
621
622 if(prevI > 0)
623 sg_peptide_model[prevI - 1].bracket = true;
624 prevI--;
625 prevDelMass = m_matrix(prevI, prevJ).mass_difference;
626 if(prevI == 0)
627 {
628 prevDelMass = 0.0;
629 }
630 }
631
632 // check the mass delta to avoid showing a null mass delta
633 if(std::abs(actualDelMass - prevDelMass) > m_precisionPtr->getNominal())
634 {
635
636 int mass_i = actualI - 1;
637 if(mass_i == 0)
638 {
639 sg_peptide_model.setBeginMassDelta(actualDelMass - prevDelMass);
640 }
641 else
642 {
643 sg_peptide_model[mass_i - 1].mass_difference = actualDelMass - prevDelMass;
644 }
645 }
646
647 // if there this is just a re-align, we need to indicate the mass
648 // offset
649 }
650 else if(m_matrix(actualI, actualJ).alignment_type == SpectralAlignmentType::reAlign)
651 {
652
653 int mass_i = actualI - 1;
654 if(mass_i == 0)
655 {
656 sg_peptide_model.setBeginMassDelta(actualDelMass - prevDelMass);
657 }
658 else
659 {
660 sg_peptide_model[mass_i - 1].mass_difference = actualDelMass - prevDelMass;
661 }
662 // the fact when you align the first amino acid, but there is a
663 // leak of Amino acid in OMS solution before
664 }
665 else if(actualI == 1 &&
666 m_matrix(actualI, actualJ).alignment_type == SpectralAlignmentType::align &&
667 (std::abs(actualDelMass) > m_precisionPtr->getNominal()))
668 {
669 sg_peptide_model.setBeginMassDelta(actualDelMass);
670 }
671
672 actualI = prevI;
673 actualJ = prevJ;
674 }
675 }
676
677 // setModificationNumber(modifCount);
678
679 // return QString("%1_[%2]")
680 // .arg(pepModified)
681 // .arg(m_precursorMassDelta - totExplainMass);
682 return sg_peptide_model;
683}

References pappso::specglob::align, m_itPosMax, m_matrix, m_maxScore, m_precisionPtr, mcsp_experimentalSpectrum, mcsp_peptideSpectrum, pappso::specglob::nonAlign, pappso::specglob::reAlign, and pappso::specglob::PeptideModel::setBeginMassDelta().

Referenced by pappso::cbor::psm::PsmSpecGlobScan::process(), and rtrim().

◆ fillMassDelta()

void pappso::specglob::SpectralAlignment::fillMassDelta ( const PeptideSpectrum & peptide_spectrum,
const ExperimentalSpectrum & experimental_spectrum )
private

Definition at line 344 of file spectralalignment.cpp.

346{
347
348 auto it_peptide = peptide_spectrum.begin();
349 auto it_spectrum = experimental_spectrum.begin();
350 for(auto itr1 = m_matrix.begin1(); itr1 != m_matrix.end1(); ++itr1, it_peptide++)
351 {
352 it_spectrum = experimental_spectrum.begin();
353 for(auto itr2 = itr1.begin(); itr2 != itr1.end(); itr2++, it_spectrum++)
354 {
355 (*itr2).alignment_type = SpectralAlignmentType::nonAlign;
356 if(it_peptide == peptide_spectrum.begin())
357 (*itr2).alignment_type = SpectralAlignmentType::nonAlign;
358 (*itr2).origin_column_indices = 0;
359 (*itr2).score = 0;
360 (*itr2).mass_difference = it_spectrum->peak_mz - it_peptide->mz;
361 // qDebug() << " i=" << itr2.index1() << " j=" << itr2.index2()
362 // << " mass_difference=" << (*itr2).mass_difference;
363 }
364 }
365}

References m_matrix, and pappso::specglob::nonAlign.

Referenced by align().

◆ fillMatricesWithScores()

void pappso::specglob::SpectralAlignment::fillMatricesWithScores ( const boost::numeric::ublas::matrix< SpectralAlignmentDataPoint >::iterator2 & it_pos,
const PeptideSpectrum & peptide_spectrum,
const ExperimentalSpectrum & experimental_spectrum )
private

This method do the alignment of the 2 Spectra and fill matrices at actual coordinates i(row - theoretical) and j(column - experimental)

Parameters
theoIndiceI: The actual theoretical peak indices
expeIndiceJ: The actual experimental peak indices

Definition at line 154 of file spectralalignment.cpp.

158{
159 // long theoIndiceI = it_pos.index1();
160 // long expeIndiceJ = it_pos.index2();
161 // in first time, we set score corresponding to type of peak (initial/mirror
162 // or both) we set initial score to peak mirror or initial
164 // experimental_spectrum.at(expeIndiceJ).type;
165
166 int alignScoreToAdd = m_scoreValues.get(ScoreValueType::scoreAlignNative);
167 int reAlignScoreToAdd = m_scoreValues.get(ScoreValueType::scoreReAlignNative);
168 int reAlignScoreNOToAdd = m_scoreValues.get(ScoreValueType::scoreReAlignNativeNO);
169
170 switch(expePeakType)
171 {
173 // this is a symmetric peak
174 alignScoreToAdd = m_scoreValues.get(ScoreValueType::scoreAlignSym);
175 reAlignScoreToAdd = m_scoreValues.get(ScoreValueType::scoreReAlignSym);
176 reAlignScoreNOToAdd = m_scoreValues.get(ScoreValueType::scoreReAlignSymNO);
177 if(m_BETTER_END_RA && it_pos.index1() == peptide_spectrum.getPeptideSp().get()->size())
178 {
179 reAlignScoreToAdd = m_scoreValues.get(ScoreValueType::scoreNonAlign) +
181 }
182 break;
184 // this is a native peak with a symmetric corresponding
185 alignScoreToAdd = m_scoreValues.get(ScoreValueType::scoreAlignBoth);
186 reAlignScoreToAdd = m_scoreValues.get(ScoreValueType::scoreReAlignBoth);
187 reAlignScoreNOToAdd = m_scoreValues.get(ScoreValueType::scoreReAlignBothNO);
188 if(m_BETTER_END_RA && it_pos.index1() == peptide_spectrum.getPeptideSp().get()->size())
189 {
190 reAlignScoreToAdd = m_scoreValues.get(ScoreValueType::scoreNonAlign) +
192 }
193 break;
194 default:
195 // this is a native or synthetic peak
196 alignScoreToAdd = m_scoreValues.get(ScoreValueType::scoreAlignNative);
197 reAlignScoreToAdd = m_scoreValues.get(ScoreValueType::scoreReAlignNative);
198 reAlignScoreNOToAdd = m_scoreValues.get(ScoreValueType::scoreReAlignNativeNO);
199 if(m_BETTER_END_RA && it_pos.index1() == peptide_spectrum.getPeptideSp().get()->size())
200 {
201 reAlignScoreToAdd = m_scoreValues.get(ScoreValueType::scoreNonAlign) +
203 }
204 break;
205 }
206 SpectralAlignmentDataPoint &matrix_data_point_i_j = *it_pos;
207
208 /*
209 long k = getkValue(it_pos,
210 peptide_spectrum.at(it_pos.index1()).diff_mz,
211 experimental_spectrum);
212
213 if(it_pos.index1() == 15)
214 qDebug() << "position1" << it_pos.index1() << "position2" << it_pos.index1()
215 << " k=" << k << " " << peptide_spectrum.at(it_pos.index1()).diff_mz;
216 */
217 pappso::MzRange aaMassRange(peptide_spectrum.at(it_pos.index1()).diff_mz, m_precisionPtr);
218 qDebug();
219 // long k = -1;
220 auto itKpeak = experimental_spectrum.reverseFindDiffMz(it_pos.index2(), aaMassRange);
221 // if(itKpeak != experimental_spectrum.rend())
222 // k = itKpeak->indice;
223
224 if(itKpeak == experimental_spectrum.rend())
225 {
226 matrix_data_point_i_j.score = m_matrix(it_pos.index1() - 1, it_pos.index2()).score +
228 matrix_data_point_i_j.origin_column_indices = it_pos.index2();
229 matrix_data_point_i_j.alignment_type = SpectralAlignmentType::nonAlign;
230 }
231 else
232 {
233 SpectralAlignmentDataPoint &matrix_data_point_previ_k =
234 m_matrix(it_pos.index1() - 1, itKpeak->indice);
235 int scoreAlignK = matrix_data_point_previ_k.score + alignScoreToAdd;
236 // if it come from non align, we must verify that there is no offset from
237 // previous align
238 if(matrix_data_point_previ_k.alignment_type == SpectralAlignmentType::nonAlign)
239 {
240 int l;
241 for(l = it_pos.index1() - 1; l > 0; l--)
242 {
243 if(m_matrix(l, itKpeak->indice).origin_column_indices != itKpeak->indice)
244 break;
245 }
246 if(std::abs(m_matrix(l, itKpeak->indice).mass_difference - (*it_pos).mass_difference) >
247 m_precisionPtr->getNominal())
248 scoreAlignK = matrix_data_point_previ_k.score + reAlignScoreToAdd;
249 }
250
251 // int[0] = the j value m and int[1] = the score value
252 SpectralAlignmentDataPoint reAlignBestScore =
253 getBestRealignScore(it_pos, itKpeak->indice, reAlignScoreToAdd, reAlignScoreNOToAdd);
254
255 // For debug to see value for any match
256 // System.out.println("score k = " + scoreAlignK + " - score m = " +
257 // reAlignBestScore[1] + " - origin m = "
258 // + reAlignBestScore[0]);
259
260 if(scoreAlignK >= reAlignBestScore.score)
261 {
262 // setMatricesData(theoIndiceI, expeIndiceJ, scoreAlignK, k, 2);
263 matrix_data_point_i_j.score = scoreAlignK;
264 matrix_data_point_i_j.origin_column_indices = itKpeak->indice;
265 matrix_data_point_i_j.alignment_type = SpectralAlignmentType::align;
266 }
267 else
268 {
269 /*setMatricesData(theoIndiceI,
270 expeIndiceJ,
271 reAlignBestScore[1],
272 reAlignBestScore[0],
273 reAlignBestScore[2]);*/
274
275 matrix_data_point_i_j = reAlignBestScore;
276 }
277 }
278}
SpectralAlignmentDataPoint getBestRealignScore(const boost::numeric::ublas::matrix< SpectralAlignmentDataPoint >::iterator2 &it_pos, std::size_t expeIndicesK, int reAlignScore, int alignScoreToAdd)
const ExperimentalSpectrumDataPoint & getExperimentalSpectrumDataPoint(const boost::numeric::ublas::matrix< SpectralAlignmentDataPoint >::iterator2 &itpos) const
@ scoreAlignNative
Score for good alignment native (int).
Definition types.h:65
@ scoreReAlignSymNO
Score for re-alignment without offset symmetric (int).
Definition types.h:71
@ scoreNonAlign
Score for non alignment (int).
Definition types.h:58
@ scoreAlignBoth
Score for good alignment both (int).
Definition types.h:67
@ scoreReAlignBoth
Score for re-alignment both (int).
Definition types.h:62
@ scoreReAlignBothNO
Score for re-alignment without offset both (int).
Definition types.h:73
@ scoreReAlignSym
Score for re-alignment symmetric (int).
Definition types.h:61
@ scoreAlignSym
Score for good alignment symmetric (int).
Definition types.h:66
@ scoreReAlignNativeNO
Score for re-alignment without offset native (int).
Definition types.h:69
ExperimentalSpectrumDataPointType
Definition types.h:78
@ both
both, the ion and the complement exists in the original spectrum
Definition types.h:83
@ symmetric
new peak : computed symmetric mass from a corresponding native peak
Definition types.h:81

References pappso::specglob::align, pappso::specglob::SpectralAlignmentDataPoint::alignment_type, pappso::specglob::both, getBestRealignScore(), getExperimentalSpectrumDataPoint(), pappso::specglob::PeptideSpectrum::getPeptideSp(), m_BETTER_END_RA, m_matrix, m_precisionPtr, m_scoreValues, pappso::specglob::nonAlign, pappso::specglob::SpectralAlignmentDataPoint::origin_column_indices, pappso::specglob::ExperimentalSpectrum::reverseFindDiffMz(), pappso::specglob::SpectralAlignmentDataPoint::score, pappso::specglob::scoreAlignBoth, pappso::specglob::scoreAlignNative, pappso::specglob::scoreAlignSym, pappso::specglob::scoreNonAlign, pappso::specglob::scoreReAlignBoth, pappso::specglob::scoreReAlignBothNO, pappso::specglob::scoreReAlignNative, pappso::specglob::scoreReAlignNativeNO, pappso::specglob::scoreReAlignSym, pappso::specglob::scoreReAlignSymNO, pappso::specglob::symmetric, and pappso::specglob::ExperimentalSpectrumDataPoint::type.

Referenced by align().

◆ getBestRealignScore()

SpectralAlignmentDataPoint pappso::specglob::SpectralAlignment::getBestRealignScore ( const boost::numeric::ublas::matrix< SpectralAlignmentDataPoint >::iterator2 & it_pos,
std::size_t expeIndicesK,
int reAlignScore,
int alignScoreToAdd )
private

Method to get a realigned j value of where come from the realignment and get the associated realigned score

Parameters
theoIndicesI: The row where we are actually
expeIndicesK: The founded k indices
expeIndicesJ: The column where we are actually
reAlignScore: Score to add if it is needed to add offset to realign
alignScoreToAdd: Score to add if there is an alignment with peak k
precision: Precision of measures
Returns
an int[] where int[0] is the origin column (m) where come from the re-alignment and int[1] is the calculated re-aligned score and int[3] is the alignment type code

Definition at line 282 of file spectralalignment.cpp.

287{
288
289 std::size_t previous_peptide_row = it_pos.index1() - 1;
290 SpectralAlignmentDataPoint return_data_point = *it_pos;
291 int bestScore = -10000;
292 int origin = -1;
293
294 // find the best score column indice on previous row, walking back from
295 // expeIndicesK m is a j value between 0 and k where a realign can be do if we
296 // accept mass offset
297 for(long m = expeIndicesK; m > -1; m--)
298 {
299 // the >= here is for keep the highest S value if there is multiple S with
300 // the same best score
301 if(m_matrix(previous_peptide_row, m).score > bestScore)
302 {
303 bestScore = m_matrix(previous_peptide_row, m).score;
304 origin = m;
305 }
306 }
307
308 return_data_point.origin_column_indices = origin;
309 return_data_point.score = bestScore + reAlignScore;
310 return_data_point.alignment_type = SpectralAlignmentType::reAlign; // [2] = 1;
311
312 if(origin == -1)
313 return return_data_point;
314
315 // We check for the last alignment if we have chain of Non Alignment to
316 // compare the last mass offset found
317 std::size_t lastAlignIndiceI = previous_peptide_row;
318 for(long l = previous_peptide_row; l > 0; l--)
319 {
320 if(m_matrix(l, origin).origin_column_indices != 0)
321 {
322 lastAlignIndiceI = l;
323 break;
324 }
325 }
326
327 // if the difference of mass offset between actual state and last align (or
328 // realign) is null, we consider that to an alignment
329 if((lastAlignIndiceI != (previous_peptide_row)) && (it_pos.index1() > 1) &&
330 (std::abs(m_matrix(previous_peptide_row, expeIndicesK).mass_difference -
331 m_matrix(lastAlignIndiceI, origin).mass_difference) < m_precisionPtr->getNominal()))
332 {
333 return_data_point.score = bestScore + alignScoreToAdd;
334 return_data_point.alignment_type = SpectralAlignmentType::align; //[2] = 2;
335 }
336
337 // we return the origin (value of m) and the associate calculated score and
338 // the type of Alignment
339 return return_data_point;
340}

References pappso::specglob::align, pappso::specglob::SpectralAlignmentDataPoint::alignment_type, m_matrix, m_precisionPtr, pappso::specglob::SpectralAlignmentDataPoint::origin_column_indices, pappso::specglob::reAlign, and pappso::specglob::SpectralAlignmentDataPoint::score.

Referenced by fillMatricesWithScores().

◆ getExperimentalSpectrumCsp()

ExperimentalSpectrumCsp pappso::specglob::SpectralAlignment::getExperimentalSpectrumCsp ( ) const

Definition at line 59 of file spectralalignment.cpp.

60{
62}

References mcsp_experimentalSpectrum.

◆ getExperimentalSpectrumDataPoint()

const ExperimentalSpectrumDataPoint & pappso::specglob::SpectralAlignment::getExperimentalSpectrumDataPoint ( const boost::numeric::ublas::matrix< SpectralAlignmentDataPoint >::iterator2 & itpos) const
private

Definition at line 400 of file spectralalignment.cpp.

402{
403 return mcsp_experimentalSpectrum.get()->at(itpos.index2());
404}

References mcsp_experimentalSpectrum.

Referenced by fillMatricesWithScores().

◆ getMatrix()

const matrix< SpectralAlignmentDataPoint > & pappso::specglob::SpectralAlignment::getMatrix ( ) const

Definition at line 368 of file spectralalignment.cpp.

369{
370 return m_matrix;
371}

References m_matrix.

◆ getMaxPosIterator()

boost::numeric::ublas::matrix< SpectralAlignmentDataPoint >::iterator2 pappso::specglob::SpectralAlignment::getMaxPosIterator ( ) const

Definition at line 394 of file spectralalignment.cpp.

395{
396 return m_itPosMax;
397}

References m_itPosMax.

◆ getMaxScore()

int pappso::specglob::SpectralAlignment::getMaxScore ( ) const

Definition at line 388 of file spectralalignment.cpp.

389{
390 return m_maxScore;
391}

References m_maxScore.

Referenced by pappso::cbor::psm::PsmSpecGlobScan::process().

◆ getPeptideSpectraCsp()

PeptideSpectraCsp pappso::specglob::SpectralAlignment::getPeptideSpectraCsp ( ) const

Definition at line 65 of file spectralalignment.cpp.

66{
68}

References mcsp_peptideSpectrum.

◆ getPrecursorMzDelta()

double pappso::specglob::SpectralAlignment::getPrecursorMzDelta ( ) const

Definition at line 407 of file spectralalignment.cpp.

408{
410}

References m_precursorMassDelta.

◆ getScoreRow()

std::vector< int > pappso::specglob::SpectralAlignment::getScoreRow ( std::size_t row_indice) const

Definition at line 374 of file spectralalignment.cpp.

375{
376 std::vector<int> score;
377
378 auto itr1 = m_matrix.begin1() + row_indice;
379 for(auto itr2 = itr1.begin(); itr2 != itr1.end(); itr2++)
380 {
381 score.push_back((*itr2).score);
382 }
383
384 return score;
385}

References m_matrix.

◆ rtrim()

PeptideModel pappso::specglob::SpectralAlignment::rtrim ( PrecisionPtr precision_ptr)

trim the current peptide to get a minimal alignment score

Definition at line 110 of file spectralalignment.cpp.

111{
112 pappso::specglob::PeptideModel model;
114
115 double precursor_mass = mcsp_experimentalSpectrum.get()->getPrecursorMass();
116 std::size_t start = 1;
117 int max_score = m_maxScore;
118 pappso::specglob::PeptideSpectraCsp ref_best_peptide = ref_peptide;
119
120 while(start < ref_peptide.get()->getPeptideSp().get()->size() - 5)
121 {
122 pappso::PeptideSp peptide_sp = std::make_shared<pappso::Peptide>(
123 ref_peptide.get()->getPeptideSp().get()->getSequence().mid(start));
124 std::size_t length = peptide_sp.get()->size();
125 while(peptide_sp.get()->getMass() > (precursor_mass * 1.1))
126 {
127 peptide_sp =
128 std::make_shared<pappso::Peptide>(peptide_sp.get()->getSequence().mid(0, length - 1));
129 if(length > 1)
130 length--;
131 }
133 std::make_shared<pappso::specglob::PeptideSpectrum>(peptide_sp);
134 align(peptide_spectra, mcsp_experimentalSpectrum);
135
136 if(max_score < m_maxScore)
137 {
138 if(m_maxScore > 0)
139 {
140 model = buildPeptideModel();
141 model.eliminateComplementaryDelta(precision_ptr);
142 model.ltrimOnRemoval();
143 max_score = m_maxScore;
144 ref_best_peptide = mcsp_peptideSpectrum;
145 }
146 }
147 start++;
148 }
149 align(ref_best_peptide, mcsp_experimentalSpectrum);
150 return model;
151}
bool ltrimOnRemoval()
try to remove left amino acid if there is a removal
bool eliminateComplementaryDelta(pappso::PrecisionPtr precision)
void align(PeptideSpectraCsp peptide_spectrum, ExperimentalSpectrumCsp experimental_spectrum)
build the alignment matrix between a peptide sequence and an experimental spectrum
std::shared_ptr< const PeptideSpectrum > PeptideSpectraCsp
std::shared_ptr< const Peptide > PeptideSp

References align(), buildPeptideModel(), pappso::specglob::PeptideModel::eliminateComplementaryDelta(), pappso::specglob::PeptideModel::ltrimOnRemoval(), m_maxScore, mcsp_experimentalSpectrum, and mcsp_peptideSpectrum.

Member Data Documentation

◆ m_BETTER_END_RA

bool pappso::specglob::SpectralAlignment::m_BETTER_END_RA = false
private

modifies the score on the last amino acid alignment (RA score rather than NA Not documented anyMore in the interface

Definition at line 189 of file spectralalignment.h.

Referenced by fillMatricesWithScores().

◆ m_itPosMax

boost::numeric::ublas::matrix<SpectralAlignmentDataPoint>::iterator2 pappso::specglob::SpectralAlignment::m_itPosMax
private

Definition at line 178 of file spectralalignment.h.

Referenced by align(), backTrack(), buildPeptideModel(), and getMaxPosIterator().

◆ m_matrix

matrix<SpectralAlignmentDataPoint> pappso::specglob::SpectralAlignment::m_matrix
private

◆ m_maxScore

int pappso::specglob::SpectralAlignment::m_maxScore
private

Definition at line 176 of file spectralalignment.h.

Referenced by align(), backTrack(), buildPeptideModel(), getMaxScore(), and rtrim().

◆ m_precisionPtr

pappso::PrecisionPtr pappso::specglob::SpectralAlignment::m_precisionPtr
private

◆ m_precursorMassDelta

double pappso::specglob::SpectralAlignment::m_precursorMassDelta
private
Initial value:
=
0

Definition at line 180 of file spectralalignment.h.

Referenced by align(), backTrack(), and getPrecursorMzDelta().

◆ m_scoreValues

ScoreValues pappso::specglob::SpectralAlignment::m_scoreValues
private

Definition at line 175 of file spectralalignment.h.

Referenced by SpectralAlignment(), and fillMatricesWithScores().

◆ mcsp_experimentalSpectrum

ExperimentalSpectrumCsp pappso::specglob::SpectralAlignment::mcsp_experimentalSpectrum
private

◆ mcsp_peptideSpectrum

PeptideSpectraCsp pappso::specglob::SpectralAlignment::mcsp_peptideSpectrum
private

Definition at line 172 of file spectralalignment.h.

Referenced by align(), backTrack(), buildPeptideModel(), getPeptideSpectraCsp(), and rtrim().


The documentation for this class was generated from the following files: