38 : m_ms2MedianFilter(10), m_ms2MeanFilter(15), m_ms1MeanFilter(1)
45 [](
const double &
a,
const double &
b) { return (a < b); });
50 : m_ms2MedianFilter(other.m_ms2MedianFilter),
51 m_ms2MeanFilter(other.m_ms2MeanFilter),
52 m_ms1MeanFilter(other.m_ms1MeanFilter)
74 return m_ms2MedianFilter;
81 m_ms2MedianFilter = ms2MedianFilter;
88 return m_ms2MeanFilter;
96 m_ms2MeanFilter = ms2MeanFilter;
103 return m_ms1MeanFilter;
110 m_ms1MeanFilter = ms1MeanFilter;
114const std::vector<MsRunRetentionTimeSeamarkPoint<T>> &
122const std::vector<double> &
125 return m_alignedRetentionTimeVector;
132 return m_valuesCorrected;
135const std::vector<double> &
138 return m_ms1RetentionTimeVector;
147 getCommonDeltaRt(common_points, other_seamarks);
148 return common_points;
154 double retentionTime,
155 double precursorIntensity)
161 m_allMs2Points.push_back(ms2point);
171 if(m_allMs2Points.size() == 0)
177 if(m_retentionTimeReferenceMethod == ComputeRetentionTimeReference::maximum_intensity)
181 std::sort(m_allMs2Points.begin(),
182 m_allMs2Points.end(),
184 if(a.entityHash == b.entityHash)
186 return (a.precursorIntensity > b.precursorIntensity);
188 return (
a.entityHash <
b.entityHash);
191 auto itend = std::unique(m_allMs2Points.begin(),
192 m_allMs2Points.end(),
194 return (a.entityHash == b.entityHash);
197 auto it = m_allMs2Points.begin();
200 m_seamarks.push_back({it->entityHash, it->retentionTime, it->precursorIntensity});
204 m_allMs2Points.clear();
210 return (a.entityHash < b.entityHash);
222 auto it = other_seamarks.begin();
226 while((it != other_seamarks.end()) && (it->entityHash < seamark.entityHash))
230 if(it == other_seamarks.end())
232 if(it->entityHash == seamark.entityHash)
235 DataPoint(seamark.retentionTime, seamark.retentionTime - it->retentionTime));
240 if((m_ms2MedianFilter.getHalfWindowSize() * 2 + 1) >= delta_rt.size())
243 "\ntoo few MS2 points (%1) in common")
244 .arg(delta_rt.size()));
248 if((m_ms2MeanFilter.getHalfWindowSize() * 2 + 1) >= delta_rt.size())
251 "\ntoo few MS2 points (%1) in common")
252 .arg(delta_rt.size()));
270 return m_alignedRetentionTimeVector.front();
272 return m_ms1RetentionTimeVector.front();
280 return m_alignedRetentionTimeVector.back();
282 return m_ms1RetentionTimeVector.back();
290 if(m_alignedRetentionTimeVector.size() < 3)
293 "retention time (%1)")
294 .arg(m_ms1RetentionTimeVector.size()));
296 if(m_alignedRetentionTimeVector.size() != m_ms1RetentionTimeVector.size())
299 "m_ms1RetentionTimeVector.size()")
300 .arg(m_alignedRetentionTimeVector.size())
301 .arg(m_ms1RetentionTimeVector.size()));
303 auto it_plus = std::find_if(m_ms1RetentionTimeVector.begin(),
304 m_ms1RetentionTimeVector.end(),
305 [original_retention_time](
const double &rt_point) {
306 return original_retention_time < rt_point;
308 double rt1_a, rt2_a, rt1_b, rt2_b;
309 if(it_plus == m_ms1RetentionTimeVector.end())
313 if(it_plus == m_ms1RetentionTimeVector.begin())
317 auto it_minus = it_plus - 1;
322 double ratio = (original_retention_time - rt1_a) / (rt2_a - rt1_a);
324 auto itref = m_alignedRetentionTimeVector.begin() +
325 std::distance(m_ms1RetentionTimeVector.begin(), it_minus);
331 return (((rt2_b - rt1_b) * ratio) + rt1_b);
338 if(m_alignedRetentionTimeVector.size() < 3)
341 "retention time (%1)")
342 .arg(m_ms1RetentionTimeVector.size()));
344 if(m_alignedRetentionTimeVector.size() != m_ms1RetentionTimeVector.size())
347 "m_ms1RetentionTimeVector.size()")
348 .arg(m_alignedRetentionTimeVector.size())
349 .arg(m_ms1RetentionTimeVector.size()));
351 auto it_plus = std::find_if(
352 m_alignedRetentionTimeVector.begin(),
353 m_alignedRetentionTimeVector.end(),
354 [aligned_retention_time](
const double &rt_point) { return aligned_retention_time < rt_point; });
355 double rt1_a, rt2_a, rt1_b, rt2_b;
356 if(it_plus == m_alignedRetentionTimeVector.end())
360 if(it_plus == m_alignedRetentionTimeVector.begin())
364 auto it_minus = it_plus - 1;
369 double ratio = (aligned_retention_time - rt1_a) / (rt2_a - rt1_a);
371 auto itref = m_ms1RetentionTimeVector.begin() +
372 std::distance(m_alignedRetentionTimeVector.begin(), it_minus);
378 return (((rt2_b - rt1_b) * ratio) + rt1_b);
382const std::vector<MsRunRetentionTimeSeamarkPoint<T>>
385 std::vector<MsRunRetentionTimeSeamarkPoint<T>> other_seamarks = m_seamarks;
386 for(
auto &seamark : other_seamarks)
388 seamark.retentionTime = translateOriginal2AlignedRetentionTime(seamark.retentionTime);
390 return other_seamarks;
397 return (m_alignedRetentionTimeVector.size() > 0);
405 std::vector<MsRunRetentionTimeSeamarkPoint<T>> other_seamarks;
406 if(msrun_retention_time_reference.
isAligned())
412 other_seamarks = msrun_retention_time_reference.
getSeamarks();
415 if((m_ms1MeanFilter.getHalfWindowSize() * 2 + 1) >= m_ms1RetentionTimeVector.size())
418 "\ntoo few MS1 points (%1)")
419 .arg(m_ms1RetentionTimeVector.size()));
422 qDebug() << m_seamarks[0].entityHash <<
" " << m_seamarks[0].retentionTime <<
" "
423 << other_seamarks[0].entityHash << other_seamarks[0].retentionTime <<
" ";
426 getCommonDeltaRt(common_points, other_seamarks);
430 qDebug() << common_points.front().x <<
" " << common_points.front().y;
431 m_ms2MedianFilter.
filter(common_points);
433 m_ms2MeanFilter.
filter(common_points);
436 qDebug() << common_points.front().x <<
" " << common_points.front().y;
441 first_point.
x = m_ms1RetentionTimeVector.front() - (double)1;
442 if(first_point.
x < 0)
446 first_point.
y = m_ms1RetentionTimeVector.front() -
449 common_points.push_back(first_point);
452 last_point.
x = m_ms1RetentionTimeVector.back() + 1;
453 last_point.
y = m_ms1RetentionTimeVector.back() -
455 common_points.push_back(last_point);
456 common_points.
sortX();
460 m_alignedRetentionTimeVector.clear();
462 qDebug() << common_points.front().x <<
" " << common_points.front().y;
464 Trace ms1_aligned_points;
466 linearRegressionMs2toMs1(ms1_aligned_points, common_points);
471 m_ms1MeanFilter.filter(ms1_aligned_points);
476 for(
DataPoint &data_point : ms1_aligned_points)
478 data_point.y = (data_point.x - data_point.y);
484 double correction_parameter =
485 (m_ms1RetentionTimeVector.back() - m_ms1RetentionTimeVector.front()) /
486 (ms1_aligned_points.size());
488 correction_parameter = correction_parameter / (double)4;
489 correctNewTimeValues(ms1_aligned_points, correction_parameter);
491 m_alignedRetentionTimeVector = ms1_aligned_points.
yValues();
494 return ms1_aligned_points;
501 const Trace &common_points)
505 std::vector<DataPoint>::const_iterator itms2 = common_points.begin();
506 std::vector<DataPoint>::const_iterator itms2next = itms2 + 1;
507 if(itms2next == common_points.end())
511 "\ntoo few common points (%1)")
512 .arg(common_points.size()));
514 qDebug() <<
"() itms2->x=" << itms2->x <<
" itms2->y=" << itms2->y;
516 for(
double &original_rt_point : m_ms1RetentionTimeVector)
519 ms1_point.
x = original_rt_point;
521 while(ms1_point.
x > itms2next->x)
527 double ratio = (itms2next->x - itms2->x);
530 ratio = (ms1_point.
x - itms2->x) / ratio;
540 ms1_point.
y = itms2->y + ((itms2next->y - itms2->y) * ratio);
544 ms1_aligned_points.push_back(ms1_point);
553 m_valuesCorrected = 0;
554 auto new_it(ms1_aligned_points.begin());
555 auto new_nextit(ms1_aligned_points.begin());
557 for(; new_nextit != ms1_aligned_points.end(); ++new_nextit, ++new_it)
559 if(new_nextit->y < new_it->y)
562 new_nextit->y = new_it->y + correction_parameter;
570 const std::vector<double> &aligned_times)
573 if(aligned_times.size() == m_ms1RetentionTimeVector.size())
575 m_alignedRetentionTimeVector = aligned_times;
579 if(aligned_times.size() == m_ms1RetentionTimeVector.size() * 2)
581 m_alignedRetentionTimeVector = m_ms1RetentionTimeVector;
582 for(std::size_t i = 0; i < m_ms1RetentionTimeVector.size(); i++)
584 if(aligned_times[2 * i] != m_ms1RetentionTimeVector[i])
587 QObject::tr(
"ERROR : aligned_times (size=%1) vector does not have "
588 "required size (size=%2)")
589 .arg(aligned_times.size())
590 .arg(m_ms1RetentionTimeVector.size()));
592 m_alignedRetentionTimeVector[i] = aligned_times[(2 * i) + 1];
598 QObject::tr(
"ERROR : aligned_times (size=%1) vector does not have "
599 "required size (size=%2)")
600 .arg(aligned_times.size())
601 .arg(m_ms1RetentionTimeVector.size()));
613 std::vector<MsRunRetentionTimeSeamarkPoint<T>> other_seamarks;
614 if(msrun_retention_time_reference.
isAligned())
620 other_seamarks = msrun_retention_time_reference.
getSeamarks();
624 qDebug() << m_seamarks[0].entityHash <<
" " << m_seamarks[0].retentionTime <<
" "
625 << other_seamarks[0].entityHash << other_seamarks[0].retentionTime <<
" ";
628 getCommonDeltaRt(common_points, other_seamarks);
629 return common_points;
mean filter apply mean of y values inside the window : this results in a kind of smoothing
void setMs2MedianFilter(const FilterMorphoMedian &ms2MedianFilter)
std::vector< double > m_alignedRetentionTimeVector
std::vector< PeptideMs2Point > m_allMs2Points
const FilterMorphoMean & getMs1MeanFilter() const
const FilterMorphoMedian & getMs2MedianFilter() const
std::size_t m_valuesCorrected
void computeSeamarks()
convert PeptideMs2Point into Peptide seamarks this is required before computing alignment
Trace getCommonSeamarksDeltaRt(const MsRunRetentionTime< T > &msrun_retention_time_reference) const
get common seamarks between msrunretentiontime objects and their deltart
MsRunRetentionTime(const std::vector< double > &msrun_retention_time_line)
void setMs1MeanFilter(const FilterMorphoMean &ms1MeanFilter)
void linearRegressionMs2toMs1(Trace &ms1_aligned_points, const Trace &common_points)
void setMs2MeanFilter(const FilterMorphoMean &ms2MeanFilter)
double getFrontRetentionTimeReference() const
const std::vector< double > & getAlignedRetentionTimeVector() const
get aligned retention time vector
void setAlignedRetentionTimeVector(const std::vector< double > &aligned_times)
std::vector< MsRunRetentionTimeSeamarkPoint< T > > m_seamarks
Trace align(const MsRunRetentionTime< T > &msrun_retention_time_reference)
align the current msrunretentiontime object using the given reference
double translateAligned2OriginalRetentionTime(double aligned_retention_time) const
double translateOriginal2AlignedRetentionTime(double original_retention_time) const
const std::vector< double > & getMs1RetentionTimeVector() const
get orginal retention time vector (not aligned)
void correctNewTimeValues(Trace &ms1_aligned_points, double correction_parameter)
const std::vector< MsRunRetentionTimeSeamarkPoint< T > > & getSeamarks() const
Trace getCommonDeltaRt(const std::vector< MsRunRetentionTimeSeamarkPoint< T > > &other_seamarks) const
ComputeRetentionTimeReference m_retentionTimeReferenceMethod
const std::vector< MsRunRetentionTimeSeamarkPoint< T > > getSeamarksReferences() const
std::vector< double > m_ms1RetentionTimeVector
void addPeptideAsSeamark(const T &peptide_id, double retentionTime, double precursorIntensity)
collects all peptide evidences of a given MSrun seamarks has to be converted to peptide retention tim...
const FilterMorphoMean & getMs2MeanFilter() const
double getBackRetentionTimeReference() const
std::size_t getNumberOfCorrectedValues() const
A simple container of DataPoint instances.
virtual Trace & filter(const FilterInterface &filter) final
apply a filter on this trace
std::vector< pappso_double > yValues() const
void sortX(Enums::SortOrder sort_order=Enums::SortOrder::ascending)
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
double precursorIntensity