 |
OpenMS
3.0.0
|
|
Go to the documentation of this file.
62 template <
typename ValueType = UInt,
typename BinSizeType =
double>
95 Histogram(BinSizeType min, BinSizeType max, BinSizeType bin_size) :
109 template <
typename DataIterator>
110 Histogram(DataIterator
begin, DataIterator
end, BinSizeType min, BinSizeType max, BinSizeType bin_size) :
116 for (DataIterator it =
begin; it !=
end; ++it)
118 this->
inc((BinSizeType) *it);
144 return *(std::max_element(
bins_.begin(),
bins_.end()));
150 return *(std::min_element(
bins_.begin(),
bins_.end()));
172 if (index >=
bins_.size())
186 if (bin_index >=
bins_.size())
191 return (BinSizeType)(
min_ + ((BinSizeType)bin_index + 0.5) *
bin_size_);
201 if (bin_index >=
bins_.size())
205 if (bin_index + 1 ==
bins_.size())
209 return (BinSizeType)(
min_ + ((BinSizeType) bin_index + 1) *
bin_size_);
219 if (bin_index >=
bins_.size())
224 return (BinSizeType)(
min_ + (BinSizeType)bin_index *
bin_size_);
244 Size inc(BinSizeType val, ValueType increment = 1)
247 this->
bins_[bin_index] += increment;
258 Size incUntil(BinSizeType val,
bool inclusive, ValueType increment = 1)
261 for (
Size i = 0; i < bin_index; ++i)
263 this->
bins_[i] += increment;
267 this->
bins_[bin_index] += increment;
279 Size incFrom(BinSizeType val,
bool inclusive, ValueType increment = 1)
282 for (
Size i = bin_index + 1; i < this->
bins_.size(); ++i)
284 this->
bins_[i] += increment;
288 this->
bins_[bin_index] += increment;
293 template<
typename DataIterator >
299 for (DataIterator it =
begin; it !=
end; ++it)
307 histogram.
incFrom(*it, inclusive);
318 void reset(BinSizeType min, BinSizeType max, BinSizeType bin_size)
364 if (&histogram ==
this)
return *
this;
389 for (
typename std::vector<ValueType>::iterator it =
bins_.begin(); it !=
bins_.end(); ++it)
391 *it = (ValueType)(multiplier * log((BinSizeType)(*it + 1.0f)));
403 if (val < min_ || val >
max_)
431 if (this->bin_size_ <= 0)
437 if (this->max_ != this->min_)
443 this->bins_ = std::vector<ValueType>(1, 0);
450 template <
typename ValueType,
typename BinSizeType>
453 for (
Size i = 0; i < hist.
size(); ++i)
455 os << hist.
centerOfBin(i) <<
"\t"<< hist[i] << std::endl;
static void writeHist(const String &out_csv, const std::vector< double > &delta_mzs, const std::vector< double > &mzs, const std::vector< double > &rts)
Writer can be used in association with correctToNearestMS1Peak or correctToHighestIntensityMS1Peak.
Base class for TOPP applications.
Definition: TOPPBase.h:147
Size incUntil(BinSizeType val, bool inclusive, ValueType increment=1)
Increment all bins from to lowest(=first) bin up to (and including?) the bin for val by a certain num...
Definition: Histogram.h:258
Histogram()
default constructor
Definition: Histogram.h:74
BinSizeType centerOfBin(Size bin_index) const
returns the center position of the bin with the index bin_index
Definition: Histogram.h:184
Size incFrom(BinSizeType val, bool inclusive, ValueType increment=1)
Increment all bins from the bin of val to the highest(=last) bin by a certain number of counts.
Definition: Histogram.h:279
static std::set< Size > correctToNearestMS1Peak(MSExperiment &exp, double mz_tolerance, bool ppm, std::vector< double > &delta_mzs, std::vector< double > &mzs, std::vector< double > &rts)
Selection of the peak in closest proximity as corrected precursor mass in a given mass range (e....
virtual ~Histogram()
destructor
Definition: Histogram.h:123
void store(const String &filename, const PeakMap &map) const
Stores a map in an MzML file.
std::ostream & operator<<(std::ostream &os, const Histogram< ValueType, BinSizeType > &hist)
Print the contents to a stream.
Definition: Histogram.h:451
Histogram(BinSizeType min, BinSizeType max, BinSizeType bin_size)
constructor with min, max (inclusive) and bin width
Definition: Histogram.h:95
File adapter for MzML files.
Definition: MzMLFile.h:57
In-Memory representation of a mass spectrometry run.
Definition: MSExperiment.h:70
BinSizeType rightBorderOfBin(Size bin_index) const
returns the first value to the right side of the bin with the index bin_index, which is not part of t...
Definition: Histogram.h:199
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:127
Size valueToBin(BinSizeType val) const
Returns the bin index a given value belongs to.
Definition: Histogram.h:400
static std::set< Size > correctToHighestIntensityMS1Peak(MSExperiment &exp, double mz_tolerance, bool ppm, std::vector< double > &delta_mzs, std::vector< double > &mzs, std::vector< double > &rts)
Selection of the peak with the highest intensity as corrected precursor mass in a given mass range (e...
#define OPENMS_LOG_WARN
Macro if a warning, a piece of information which should be read by the user, should be logged.
Definition: LogStream.h:460
Size size() const
returns the number of bins
Definition: Histogram.h:160
static std::set< Size > correctToNearestFeature(const FeatureMap &features, MSExperiment &exp, double rt_tolerance_s=0.0, double mz_tolerance=0.0, bool ppm=true, bool believe_charge=false, bool keep_original=false, bool all_matching_features=false, int max_trace=2, int debug_level=0)
Reassigns a precursor to the nearest feature in a given rt and mass range. Wrong assignment of the mo...
ConstIterator end() const
Non-mutable iterator pointing after the last bin.
Definition: Histogram.h:383
BinSizeType max_
Upper bound.
Definition: Histogram.h:421
static String concatenate(const std::vector< T > &container, const String &glue="")
Concatenates all elements of the container and puts the glue string between elements.
Definition: ListUtils.h:209
Out of range exception.
Definition: Exception.h:311
std::vector< ValueType > bins_
Vector of bins.
Definition: Histogram.h:425
Histogram(DataIterator begin, DataIterator end, BinSizeType min, BinSizeType max, BinSizeType bin_size)
constructor with data iterator and min, max, bin_size parameters
Definition: Histogram.h:110
Histogram & operator=(const Histogram &histogram)
Assignment.
Definition: Histogram.h:362
Size inc(BinSizeType val, ValueType increment=1)
increases the bin corresponding to value val by increment
Definition: Histogram.h:244
std::vector< ValueType >::const_iterator ConstIterator
Non-mutable iterator of the bins.
Definition: Histogram.h:68
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
BinSizeType min_
Lower bound.
Definition: Histogram.h:419
Representation of a histogram.
Definition: Histogram.h:63
ValueType operator[](Size index) const
returns the value of bin index
Definition: Histogram.h:170
void load(const String &filename, PeakMap &map)
Loads a map from a MzML file. Spectra and chromatograms are sorted by default (this can be disabled u...
BinSizeType minBound() const
returns the lower bound (inclusive)
Definition: Histogram.h:130
void load(const String &filename, FeatureMap &feature_map)
loads the file with name filename into map and calls updateRanges().
bool operator!=(const Histogram &histogram) const
Inequality operator.
Definition: Histogram.h:356
BinSizeType binSize() const
returns the bin size
Definition: Histogram.h:154
bool operator==(const Histogram &histogram) const
Equality operator.
Definition: Histogram.h:347
Histogram(const Histogram &histogram)
copy constructor
Definition: Histogram.h:82
void initBins_()
initialize the bins
Definition: Histogram.h:429
BinSizeType maxBound() const
returns the upper bound (inclusive)
Definition: Histogram.h:136
static void getCumulativeHistogram(DataIterator begin, DataIterator end, bool complement, bool inclusive, Histogram< ValueType, BinSizeType > &histogram)
Definition: Histogram.h:294
Int overflow exception.
Definition: Exception.h:245
int main(int argc, const char **argv)
Definition: INIFileEditor.cpp:71
ValueType minValue() const
returns the bin with lowest count
Definition: Histogram.h:148
#define OPENMS_LOG_ERROR
Macro to be used if non-fatal error are reported (processing continues)
Definition: LogStream.h:455
ValueType binValue(BinSizeType val) const
returns the value of bin corresponding to the value val
Definition: Histogram.h:232
A container for features.
Definition: FeatureMap.h:98
BinSizeType bin_size_
Bin size.
Definition: Histogram.h:423
BinSizeType leftBorderOfBin(Size bin_index) const
returns the leftmost value of the bin with the index bin_index, which is part of this bin,...
Definition: Histogram.h:217
This class provides Input/Output functionality for feature maps.
Definition: FeatureXMLFile.h:62
#define OPENMS_LOG_INFO
Macro if a information, e.g. a status should be reported.
Definition: LogStream.h:465
ConstIterator begin() const
Non-mutable iterator pointing to the first bin.
Definition: Histogram.h:380
void applyLogTransformation(BinSizeType multiplier)
Transforms the bin values with f(x)=multiplier*log(x+1)
Definition: Histogram.h:387
void reset(BinSizeType min, BinSizeType max, BinSizeType bin_size)
resets the histogram with the given range and bin size
Definition: Histogram.h:318
static const std::string csv_header
Definition: PrecursorCorrection.h:67
ValueType maxValue() const
returns the bin with the highest count
Definition: Histogram.h:142