libpappsomspp
Library for mass spectrometry
pappso::FilterLowIntensitySignalRemoval Class Reference

Redefines the floor intensity of the Trace. More...

#include <filterlowintensitysignalremoval.h>

Inheritance diagram for pappso::FilterLowIntensitySignalRemoval:
pappso::FilterNameInterface pappso::FilterInterface

Public Member Functions

 FilterLowIntensitySignalRemoval (double mean, double std_dev, double threshold)
 
 FilterLowIntensitySignalRemoval (const QString &parameters)
 
 FilterLowIntensitySignalRemoval (const FilterLowIntensitySignalRemoval &other)
 
virtual ~FilterLowIntensitySignalRemoval ()
 
FilterLowIntensitySignalRemovaloperator= (const FilterLowIntensitySignalRemoval &other)
 
Tracefilter (Trace &data_points) const override
 
double getThreshold () const
 
QString name () const override
 
QString toString () const override
 Return a string with the textual representation of the configuration data. More...
 
- Public Member Functions inherited from pappso::FilterNameInterface
virtual ~FilterNameInterface ()
 
- Public Member Functions inherited from pappso::FilterInterface
virtual ~FilterInterface ()
 

Protected Member Functions

void buildFilterFromString (const QString &strBuildParams) override
 build this filter using a string More...
 
TracenonConstFilter (Trace &data_points)
 

Private Types

using IndexIntensity = std::pair< std::size_t, double >
 
using ApexSPtr = std::shared_ptr< IndexIntensity >
 
using Cluster = std::vector< ApexSPtr >
 
using ClusterSPtr = std::shared_ptr< std::vector< ApexSPtr > >
 

Private Member Functions

std::size_t detectIsotopicClusters (const Trace &trace)
 

Private Attributes

const double nan = std::numeric_limits<double>::quiet_NaN()
 
double m_threshold
 
double m_noiseMean
 
double m_noiseStdDev
 
Trace m_helperTraceCopy
 
const std::size_t m_minIntPointCount = 5
 
const std::size_t m_minIntStdDevFactor = 2
 
double m_min
 
double m_max
 
double m_minMean
 
double m_minStdDev
 
double m_noiseLevel
 
bool m_seen_upward_phase = false
 
IndexIntensity m_prevApex = std::pair(0, nan)
 
IndexIntensity m_curApex = std::pair(0, nan)
 
IndexIntensity m_cur = std::pair(0, nan)
 
IndexIntensity m_prev = std::pair(0, nan)
 
std::vector< ClusterSPtrm_isotopicClusters
 

Static Private Attributes

constexpr static double INTRA_CLUSTER_INTER_PEAK_DISTANCE = 1.1
 

Detailed Description

Redefines the floor intensity of the Trace.

The amplitude of the trace is computed (maxValue - minValue) Its fraction is calculated = amplitude * (percentage / 100) The threshold value is computed as (minValue + fraction)

When the values to be filtered are below that threshold they acquire that threshold value.

When the values to be filtered are above that threshold they remain unchanged.

This effectively re-floors the values to threshold.

Definition at line 71 of file filterlowintensitysignalremoval.h.

Member Typedef Documentation

◆ ApexSPtr

Definition at line 126 of file filterlowintensitysignalremoval.h.

◆ Cluster

Definition at line 127 of file filterlowintensitysignalremoval.h.

◆ ClusterSPtr

using pappso::FilterLowIntensitySignalRemoval::ClusterSPtr = std::shared_ptr<std::vector<ApexSPtr> >
private

Definition at line 128 of file filterlowintensitysignalremoval.h.

◆ IndexIntensity

using pappso::FilterLowIntensitySignalRemoval::IndexIntensity = std::pair<std::size_t, double>
private

Definition at line 75 of file filterlowintensitysignalremoval.h.

Constructor & Destructor Documentation

◆ FilterLowIntensitySignalRemoval() [1/3]

pappso::FilterLowIntensitySignalRemoval::FilterLowIntensitySignalRemoval ( double  mean,
double  std_dev,
double  threshold 
)

◆ FilterLowIntensitySignalRemoval() [2/3]

pappso::FilterLowIntensitySignalRemoval::FilterLowIntensitySignalRemoval ( const QString &  parameters)

Definition at line 60 of file filterlowintensitysignalremoval.cpp.

62 {
63  buildFilterFromString(parameters);
64 }
void buildFilterFromString(const QString &strBuildParams) override
build this filter using a string

References buildFilterFromString().

◆ FilterLowIntensitySignalRemoval() [3/3]

pappso::FilterLowIntensitySignalRemoval::FilterLowIntensitySignalRemoval ( const FilterLowIntensitySignalRemoval other)

Definition at line 67 of file filterlowintensitysignalremoval.cpp.

69 {
70  m_noiseMean = other.m_noiseMean;
71  m_noiseStdDev = other.m_noiseStdDev;
72  m_threshold = other.m_threshold;
73 }

References m_noiseMean, m_noiseStdDev, and m_threshold.

◆ ~FilterLowIntensitySignalRemoval()

pappso::FilterLowIntensitySignalRemoval::~FilterLowIntensitySignalRemoval ( )
virtual

Definition at line 76 of file filterlowintensitysignalremoval.cpp.

77 {
78 }

Member Function Documentation

◆ buildFilterFromString()

void pappso::FilterLowIntensitySignalRemoval::buildFilterFromString ( const QString &  strBuildParams)
overrideprotectedvirtual

build this filter using a string

Parameters
strBuildParamsa string coding the filter and its parameters "filterName|param1;param2;param3"

Implements pappso::FilterNameInterface.

Definition at line 97 of file filterlowintensitysignalremoval.cpp.

99 {
100  // Typical string: "FloorAmplitudePercentage|15"
101  if(parameters.startsWith(QString("%1|").arg(name())))
102  {
103  QStringList params = parameters.split("|").back().split(";");
104 
105  m_noiseMean = params.at(0).toDouble();
106  m_noiseStdDev = params.at(1).toDouble();
107  m_threshold = params.at(2).toDouble();
108  }
109  else
110  {
112  QString(
113  "Building of FilterLowIntensitySignalRemoval from string %1 failed")
114  .arg(parameters));
115  }
116 }
excetion to use when an item type is not recognized

References m_noiseMean, m_noiseStdDev, m_threshold, and name().

Referenced by FilterLowIntensitySignalRemoval().

◆ detectIsotopicClusters()

std::size_t pappso::FilterLowIntensitySignalRemoval::detectIsotopicClusters ( const Trace trace)
private

Definition at line 120 of file filterlowintensitysignalremoval.cpp.

121 {
122  // We want to iterate in the trace and check if we can get the clusters
123  // isolated one by one.
124 
125  m_isotopicClusters.clear();
126 
127  std::size_t trace_size = trace.size();
128  if(trace_size <= 2)
129  {
130  qDebug() << "The original trace has less than 3 points. Returning it "
131  "without modification.";
132  return m_isotopicClusters.size();
133  }
134  else
135  qDebug() << "The original trace has" << trace_size << "data points";
136 
137  std::size_t index = 0;
138 
139  // Seed the system with the first point of the trace.
140  m_prev = IndexIntensity(index, trace[index].y);
141 
142  qDebug() << "First trace point: "
143  << "(" << trace[m_prev.first].x << "," << m_prev.second << ");";
144 
145  // We still have not found any apex!
146  m_prevApex = std::pair(0, nan);
147 
148  // We will need to know if we were ascending to an apex.
149  bool was_ascending_to_apex = false;
150 
151  ClusterSPtr cluster_sp = std::make_shared<Cluster>();
152 
153  // Now that we have seeded the system with the first point of the original
154  // trace, go to the next one.
155  ++index;
156 
157  // And now iterate in the original trace and make sure we detect all the
158  // clusters.
159 
160  while(index < trace_size)
161  {
162  // Get the current trace point as an IndexIntensity.
163  m_cur = IndexIntensity(index, trace[index].y);
164 
165  qDebug() << "Current trace point: "
166  << "(" << trace[m_cur.first].x << "," << m_cur.second << ");";
167 
168  // We monitor if we are going up or down a peak.
169 
170  if(m_cur.second > m_prev.second)
171  // We are ascending a peak. We do not know if we are at the apex.
172  {
173  qDebug().noquote() << "We are ascending to an apex.\n";
174  was_ascending_to_apex = true;
175  }
176  else
177  // We are descending a peak.
178  {
179  qDebug().noquote() << "Descending a peak. ";
180 
181  // There are two situations:
182  //
183  // 1. Either we were ascending to an apex, and m_prev is that apex,
184  //
185  // 2. Or we were not ascending to an apex and in fact all we are doing
186  // is going down an apex that occurred more than one trace point ago.
187 
188  if(!was_ascending_to_apex)
189  // We were not ascending to an apex.
190  {
191  // Do nothing here.
192 
193  qDebug().noquote()
194  << "But, we were not ascending to an apex, so do nothing.\n";
195  }
196  else
197  // We are effectively descending a peak right after the apex was
198  // reached.
199  {
200  qDebug().noquote()
201  << "And, we were ascending to an apex, so "
202  "m_curApeex becomes m_prev: ("
203  << trace[m_curApex.first].x << "," << m_curApex.second << ")\n";
204 
205  m_curApex = m_prev;
206 
207  // We might have two situations:
208 
209  // 1. We had already encountered an apex.
210  // 2. We had not yet encountered an apex.
211 
212  if(!std::isnan(m_prevApex.second))
213  // We had already encountered an apex.
214  {
215  // Was that apex far on the left of the current apex ?
216 
217  if(trace[m_curApex.first].x - trace[m_prevApex.first].x >
219  // The distance is not compatible with both apices to belong
220  // to the same cluster.
221  {
222  // We are creating a new isotopic cluster.
223 
224  // But, since another apex had been encountered already,
225  // that means that an isotopic cluster was cooking
226  // already. We must store it.
227 
228  if(!cluster_sp->size())
229  qFatal("Cannot be that the cluster has no apex.");
230 
231  m_isotopicClusters.push_back(cluster_sp);
232 
233  qDebug().noquote()
234  << "There was a previous apex already, BUT "
235  "outside of cluster range. "
236  "Pushing the cooking cluster that has size:"
237  << cluster_sp->size();
238 
239  // Now create a brand new cluster.
240  cluster_sp = std::make_shared<Cluster>();
241 
242  qDebug() << "Created a brand new cluster.";
243 
244  // We only start the new cluster with the current apex if
245  // that apex is above the threshold.
246 
247  if(m_curApex.second > m_threshold)
248  {
249  // And start it with the current apex.
250  cluster_sp->push_back(
251  std::make_shared<IndexIntensity>(m_curApex));
252 
253  qDebug()
254  << "Since the current apex is above the threshold, "
255  "we PUSH it to the newly created cluster: ("
256  << trace[m_curApex.first].x << ","
257  << m_curApex.second << ")";
258 
260 
261  qDebug() << "Set prev apex to be cur apex.";
262  }
263  else
264  {
265  qDebug()
266  << "Since the current apex is below the threshold, "
267  "we DO NOT push it to the newly created "
268  "cluster: ("
269  << trace[m_curApex.first].x << ","
270  << m_curApex.second << ")";
271 
272  // Since previous apex went to the closed cluster, we
273  // need to reset it.
274 
275  m_prevApex = std::pair(0, nan);
276 
277  qDebug() << "Since the previous apex went to the "
278  "closed cluster, and cur apex has too "
279  "small an intensity, we reset prev apex "
280  "to std::pair(0, nan).";
281  }
282  }
283  else
284  // The distance is compatible with both apices to belong to
285  // the same isotopic cluster.
286  {
287 
288  // But we only push back the current apex to the cluster
289  // if its intensity is above the threshold.
290 
291  if(m_curApex.second > m_threshold)
292  // The current apex was above the threshold
293  {
294  cluster_sp->push_back(
295  std::make_shared<IndexIntensity>(m_curApex));
296 
297  qDebug().noquote()
298  << "There was an apex already inside of cluster "
299  "range. "
300  "AND, since the current apex was above the "
301  "threshold, we indeed push it to cluster.\n";
302 
303  qDebug().noquote() << "Current apex PUSHED: "
304  << trace[m_curApex.first].x << ", "
305  << m_curApex.second;
306 
308 
309  qDebug() << "We set prev apex to be cur apex.";
310  }
311  else
312  {
313  qDebug().noquote()
314  << "There was an apex already inside of cluster "
315  "range. "
316  "BUT, since the current apex was below the "
317  "threshold, we do not push it to cluster.\n";
318 
319  qDebug().noquote() << "Current apex NOT pushed: "
320  << trace[m_curApex.first].x << ", "
321  << m_curApex.second;
322  }
323  }
324  }
325  else
326  // No apex was previously found. We are fillin-up a new isotopic
327  // cluster.
328  {
329  if(m_curApex.second > m_threshold)
330  // We can actually add that apex to a new isotopic cluster.
331  {
332  if(cluster_sp->size() != 0)
333  qCritical(
334  "At this point, the cluster should be new and "
335  "empty.");
336 
337  cluster_sp->push_back(
338  std::make_shared<IndexIntensity>(m_curApex));
339 
340  qDebug().noquote()
341  << "No previous apex was found. Since current apex' "
342  "intensity is above threshold, we push it back to "
343  "the "
344  "cluster.\n";
345 
346  // Store current apex as previous apex for next rounds.
348 
349  qDebug().noquote() << "And thus we store the current "
350  "apex as previous apex.\n";
351  }
352  else
353  {
354  qDebug().noquote()
355  << "No previous apex was found. Since current apex' "
356  "intensity is below threshold, we do nothing.\n";
357  }
358  }
359  }
360  // End of
361  // ! if(!was_ascending_to_apex)
362  // That is, we were ascending to an apex.
363 
364  // Tell what it is: we were not ascending to an apex.
365  was_ascending_to_apex = false;
366  }
367  // End of
368  // ! if(m_cur.second > m_prev.second)
369  // That is, we are descending a peak.
370 
371  // At this point, prepare next round.
372 
373  qDebug().noquote()
374  << "Preparing next round, with m_prev = m_cur and ++index.\n";
375 
376  m_prev = m_cur;
377  ++index;
378  }
379  // End of
380  // while(index < trace_size)
381 
382  // At this point, if a cluster had been cooking, add it.
383 
384  if(cluster_sp->size())
385  m_isotopicClusters.push_back(cluster_sp);
386 
387  return m_isotopicClusters.size();
388 }
std::shared_ptr< std::vector< ApexSPtr > > ClusterSPtr

References INTRA_CLUSTER_INTER_PEAK_DISTANCE, m_cur, m_curApex, m_isotopicClusters, m_prev, m_prevApex, m_threshold, nan, and pappso::y.

Referenced by nonConstFilter().

◆ filter()

Trace & pappso::FilterLowIntensitySignalRemoval::filter ( Trace data_points) const
overridevirtual

Implements pappso::FilterInterface.

Definition at line 392 of file filterlowintensitysignalremoval.cpp.

393 {
394  qDebug();
395 
396  // Horrible hack to have a non const filtering process.
397  return const_cast<FilterLowIntensitySignalRemoval *>(this)->nonConstFilter(
398  trace);
399 }
FilterLowIntensitySignalRemoval(double mean, double std_dev, double threshold)

References nonConstFilter().

◆ getThreshold()

double pappso::FilterLowIntensitySignalRemoval::getThreshold ( ) const

Definition at line 447 of file filterlowintensitysignalremoval.cpp.

448 {
449  return m_threshold;
450 }

References m_threshold.

◆ name()

QString pappso::FilterLowIntensitySignalRemoval::name ( ) const
overridevirtual

Implements pappso::FilterNameInterface.

Definition at line 462 of file filterlowintensitysignalremoval.cpp.

463 {
464  return "FilterLowIntensitySignalRemoval";
465 }

Referenced by buildFilterFromString(), and toString().

◆ nonConstFilter()

Trace & pappso::FilterLowIntensitySignalRemoval::nonConstFilter ( Trace data_points)
protected

Definition at line 403 of file filterlowintensitysignalremoval.cpp.

404 {
405  qDebug();
406 
407  // Make a copy of the trace.
408  m_helperTraceCopy = Trace(trace);
409 
410  if(trace.size() <= 2)
411  {
412  qDebug() << "The original trace has less than 3 points. Returning it "
413  "without modification.";
414  return trace;
415  }
416  else
417  qDebug() << "The original trace had" << trace.size() << "data points";
418 
419  std::size_t isotopic_cluster_count = detectIsotopicClusters(trace);
420 
421  qDebug() << "Number of isotopic clusters: " << isotopic_cluster_count;
422 
423  Trace final_trace;
424 
425  for(auto &&apices_p : m_isotopicClusters)
426  {
427  qDebug() << "iterating in new cluster.";
428 
429  for(auto &&apex_p : *apices_p)
430  {
431  DataPoint data_point =
432  DataPoint(trace[apex_p->first].x, apex_p->second);
433 
434  qDebug() << "Current cluster data point:" << data_point.toString();
435 
436  final_trace.push_back(data_point);
437  }
438  }
439 
440  trace = std::move(final_trace);
441 
442  return trace;
443 }

References detectIsotopicClusters(), m_helperTraceCopy, m_isotopicClusters, and pappso::DataPoint::toString().

Referenced by filter().

◆ operator=()

FilterLowIntensitySignalRemoval & pappso::FilterLowIntensitySignalRemoval::operator= ( const FilterLowIntensitySignalRemoval other)

Definition at line 82 of file filterlowintensitysignalremoval.cpp.

84 {
85  if(&other == this)
86  return *this;
87 
88  m_noiseMean = other.m_noiseMean;
89  m_noiseStdDev = other.m_noiseStdDev;
90  m_threshold = other.m_threshold;
91 
92  return *this;
93 }

References m_noiseMean, m_noiseStdDev, and m_threshold.

◆ toString()

QString pappso::FilterLowIntensitySignalRemoval::toString ( ) const
overridevirtual

Return a string with the textual representation of the configuration data.

Implements pappso::FilterNameInterface.

Definition at line 455 of file filterlowintensitysignalremoval.cpp.

456 {
457  return QString("%1|%2").arg(name()).arg(QString::number(m_threshold, 'f', 2));
458 }

References m_threshold, and name().

Member Data Documentation

◆ INTRA_CLUSTER_INTER_PEAK_DISTANCE

constexpr static double pappso::FilterLowIntensitySignalRemoval::INTRA_CLUSTER_INTER_PEAK_DISTANCE = 1.1
staticconstexprprivate

Definition at line 107 of file filterlowintensitysignalremoval.h.

Referenced by detectIsotopicClusters().

◆ m_cur

IndexIntensity pappso::FilterLowIntensitySignalRemoval::m_cur = std::pair(0, nan)
private

Definition at line 123 of file filterlowintensitysignalremoval.h.

Referenced by detectIsotopicClusters().

◆ m_curApex

IndexIntensity pappso::FilterLowIntensitySignalRemoval::m_curApex = std::pair(0, nan)
private

Definition at line 122 of file filterlowintensitysignalremoval.h.

Referenced by detectIsotopicClusters().

◆ m_helperTraceCopy

Trace pappso::FilterLowIntensitySignalRemoval::m_helperTraceCopy
private

Definition at line 109 of file filterlowintensitysignalremoval.h.

Referenced by nonConstFilter().

◆ m_isotopicClusters

std::vector<ClusterSPtr> pappso::FilterLowIntensitySignalRemoval::m_isotopicClusters
private

Definition at line 131 of file filterlowintensitysignalremoval.h.

Referenced by detectIsotopicClusters(), and nonConstFilter().

◆ m_max

double pappso::FilterLowIntensitySignalRemoval::m_max
private

Definition at line 114 of file filterlowintensitysignalremoval.h.

◆ m_min

double pappso::FilterLowIntensitySignalRemoval::m_min
private

Definition at line 113 of file filterlowintensitysignalremoval.h.

◆ m_minIntPointCount

const std::size_t pappso::FilterLowIntensitySignalRemoval::m_minIntPointCount = 5
private

Definition at line 110 of file filterlowintensitysignalremoval.h.

◆ m_minIntStdDevFactor

const std::size_t pappso::FilterLowIntensitySignalRemoval::m_minIntStdDevFactor = 2
private

Definition at line 111 of file filterlowintensitysignalremoval.h.

◆ m_minMean

double pappso::FilterLowIntensitySignalRemoval::m_minMean
private

Definition at line 115 of file filterlowintensitysignalremoval.h.

◆ m_minStdDev

double pappso::FilterLowIntensitySignalRemoval::m_minStdDev
private

Definition at line 116 of file filterlowintensitysignalremoval.h.

◆ m_noiseLevel

double pappso::FilterLowIntensitySignalRemoval::m_noiseLevel
private

Definition at line 117 of file filterlowintensitysignalremoval.h.

◆ m_noiseMean

double pappso::FilterLowIntensitySignalRemoval::m_noiseMean
private

◆ m_noiseStdDev

double pappso::FilterLowIntensitySignalRemoval::m_noiseStdDev
private

◆ m_prev

IndexIntensity pappso::FilterLowIntensitySignalRemoval::m_prev = std::pair(0, nan)
private

Definition at line 124 of file filterlowintensitysignalremoval.h.

Referenced by detectIsotopicClusters().

◆ m_prevApex

IndexIntensity pappso::FilterLowIntensitySignalRemoval::m_prevApex = std::pair(0, nan)
private

Definition at line 121 of file filterlowintensitysignalremoval.h.

Referenced by detectIsotopicClusters().

◆ m_seen_upward_phase

bool pappso::FilterLowIntensitySignalRemoval::m_seen_upward_phase = false
private

Definition at line 119 of file filterlowintensitysignalremoval.h.

◆ m_threshold

double pappso::FilterLowIntensitySignalRemoval::m_threshold
private

◆ nan

const double pappso::FilterLowIntensitySignalRemoval::nan = std::numeric_limits<double>::quiet_NaN()
private

Definition at line 101 of file filterlowintensitysignalremoval.h.

Referenced by detectIsotopicClusters().


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