35 #ifndef OPENMS_ANALYSIS_OPENSWATH_MRMTRANSITIONGROUPPICKER_H 
   36 #define OPENMS_ANALYSIS_OPENSWATH_MRMTRANSITIONGROUPPICKER_H 
  107     template <
typename SpectrumT, 
typename TransitionT>
 
  110       SpectrumT & master_peak_container, 
int chr_idx, 
double best_left, 
double best_right)
 
  112       const SpectrumT & ref_chromatogram = transition_group.
getChromatograms()[chr_idx];
 
  115       typename SpectrumT::const_iterator begin = ref_chromatogram.begin();
 
  116       while (begin != ref_chromatogram.end() && begin->getMZ() < best_left) {begin++; }
 
  117       if (begin != ref_chromatogram.begin()) {begin--; }
 
  119       typename SpectrumT::const_iterator end = begin;
 
  120       while (end != ref_chromatogram.end() && end->getMZ() < best_right) {end++; }
 
  121       if (end != ref_chromatogram.end()) {end++; }
 
  124       master_peak_container.resize(distance(begin, end));
 
  125       typename SpectrumT::iterator it = master_peak_container.begin();
 
  126       for (
typename SpectrumT::const_iterator chrom_it = begin; chrom_it != end; chrom_it++, it++)
 
  128         it->setMZ(chrom_it->getMZ());
 
  133     template <
typename SpectrumT>
 
  135       SpectrumT & master_peak_container, 
double best_left, 
double best_right)
 
  140       typename SpectrumT::const_iterator begin = chromatogram.begin();
 
  141       while (begin != chromatogram.end() && begin->getMZ() < best_left) {begin++; }
 
  142       if (begin != chromatogram.begin()) {begin--; }
 
  144       typename SpectrumT::const_iterator end = begin;
 
  145       while (end != chromatogram.end() && end->getMZ() < best_right) {end++; }
 
  146       if (end != chromatogram.end()) {end++; }
 
  148       SpectrumT resampled_peak_container = master_peak_container; 
 
  150       lresampler.
raster(begin, end, resampled_peak_container.begin(), resampled_peak_container.end());
 
  152 #if DEBUG_TRANSITIONGROUPPICKER 
  154         std::cout << 
"===========================================================================  " << std::endl;
 
  157         for (
typename SpectrumT::const_iterator it = begin; it != end; it++)
 
  159           std::cout << 
" before resampl " << *it << std::endl;
 
  160           tot += it->getIntensity();
 
  162         std::cout << 
" total " << tot << std::endl;
 
  165         for (
typename SpectrumT::iterator it = resampled_peak_container.begin(); it != resampled_peak_container.end(); it++)
 
  167           std::cout << 
" resampl " << *it << std::endl;
 
  168           tot += it->getIntensity();
 
  170         std::cout << 
" total " << tot << std::endl;
 
  171         std::cout << 
" resampled size " << resampled_peak_container.size() << std::endl;
 
  174       return resampled_peak_container;
 
  180     double calculateBgEstimation_(
const RichPeakChromatogram& smoothed_chromat, 
double best_left, 
double best_right);
 
  183     void updateMembers_();
 
  201     template <
typename SpectrumT, 
typename TransitionT>
 
  205       picked_chroms_.clear();
 
  213         pickChromatogram(chromatogram, smoothed_chrom, picked_chrom);
 
  215         picked_chroms_.push_back(picked_chrom);
 
  216         smoothed_chroms_.push_back(smoothed_chrom);
 
  223       int chr_idx, peak_idx, cnt = 0;
 
  226         chr_idx = -1; peak_idx = -1;
 
  227         findLargestPeak(picked_chroms_, chr_idx, peak_idx);
 
  228         if (chr_idx == -1 && peak_idx == -1) 
break;
 
  237         MRMFeature mrm_feature = createMRMFeature(transition_group, picked_chroms_, chr_idx, peak_idx);
 
  244         if ((stop_after_feature_ > 0 && cnt > stop_after_feature_) && mrm_feature.
getIntensity() / (
double)mrm_feature.
getMetaValue(
"total_xic") < stop_after_intensity_ratio_)
 
  253     void pickChromatogram(
const RichPeakChromatogram& chromatogram, RichPeakChromatogram& smoothed_chrom, RichPeakChromatogram& picked_chrom);
 
  256     template <
typename SpectrumT, 
typename TransitionT>
 
  258       std::vector<SpectrumT> & picked_chroms, 
int & chr_idx, 
int & peak_idx)
 
  261       const double best_left = picked_chroms[chr_idx].getFloatDataArrays()[1][peak_idx];
 
  262       const double best_right = picked_chroms[chr_idx].getFloatDataArrays()[2][peak_idx];
 
  263       const double peak_apex = picked_chroms[chr_idx][peak_idx].getRT();
 
  268       remove_overlapping_features(picked_chroms, best_left, best_right);
 
  269       picked_chroms[chr_idx][peak_idx].setIntensity(0.0);
 
  274       SpectrumT master_peak_container;
 
  275       prepareMasterContainer_(transition_group, master_peak_container, chr_idx, best_left, best_right);
 
  277       double total_intensity = 0; 
double total_peak_apices = 0; 
double total_xic = 0;
 
  281         for (
typename SpectrumT::const_iterator it = chromatogram.begin(); it != chromatogram.end(); it++)
 
  283           total_xic += it->getIntensity();
 
  287         const SpectrumT used_chromatogram = resampleChromatogram_(chromatogram, master_peak_container, best_left, best_right);
 
  297         double peak_apex_int = -1;
 
  298         double peak_apex_dist = std::fabs(used_chromatogram.begin()->getMZ() - peak_apex);
 
  300         for (
typename SpectrumT::const_iterator it = used_chromatogram.begin(); it != used_chromatogram.end(); it++)
 
  302           if (it->getMZ() > best_left && it->getMZ() < best_right)
 
  306             p[1] = it->getIntensity();
 
  307             hull_points.push_back(p);
 
  308             if (std::fabs(it->getMZ() - peak_apex) <= peak_apex_dist)
 
  310               peak_apex_int = p[1];
 
  311               peak_apex_dist = std::fabs(it->getMZ() - peak_apex);
 
  313             rt_sum += it->getMZ();
 
  314             intensity_sum += it->getIntensity();
 
  318         if (background_subtraction_ != 
"none")
 
  320           double background = 0;
 
  322           if (background_subtraction_ == 
"smoothed")
 
  324             if (smoothed_chroms_.size() <= 
k)
 
  326               std::cerr << 
"Tried to calculate background estimation without any smoothed chromatograms" << std::endl;
 
  331               background = calculateBgEstimation_(smoothed_chroms_[
k], best_left, best_right);
 
  334           else if (background_subtraction_ == 
"original")
 
  336             background = calculateBgEstimation_(used_chromatogram, best_left, best_right);
 
  338           intensity_sum -= background;
 
  339           if (intensity_sum < 0)
 
  341             std::cerr << 
"Warning: Intensity was below 0 after background subtraction: " << intensity_sum << 
". Setting it to 0." << std::endl;
 
  346         f.
setRT(picked_chroms[chr_idx][peak_idx].getMZ());
 
  347         f.
setMZ(chromatogram.getMetaValue(
"product_mz"));
 
  352         f.
setMetaValue(
"MZ", chromatogram.getMetaValue(
"product_mz"));
 
  353         f.
setMetaValue(
"native_id", chromatogram.getNativeID());
 
  358         total_intensity += intensity_sum;
 
  359         total_peak_apices += peak_apex_int;
 
  360         mrmFeature.
addFeature(f, chromatogram.getNativeID()); 
 
  362       mrmFeature.
setRT(picked_chroms[chr_idx][peak_idx].getMZ());
 
  368       mrmFeature.
setMetaValue(
"peak_apices_sum", total_peak_apices);
 
  376     template <
typename SpectrumT>
 
  380       for (
Size k = 0; 
k < picked_chroms.size(); 
k++)
 
  382         for (
Size i = 0; i < picked_chroms[
k].size(); i++)
 
  384           if (picked_chroms[
k][i].getMZ() >= best_left && picked_chroms[
k][i].getMZ() <= best_right)
 
  386             picked_chroms[
k][i].setIntensity(0.0);
 
  392       for (
Size k = 0; 
k < picked_chroms.size(); 
k++)
 
  394         for (
Size i = 0; i < picked_chroms[
k].size(); i++)
 
  396           double left = picked_chroms[
k].getFloatDataArrays()[1][i];
 
  397           double right = picked_chroms[
k].getFloatDataArrays()[2][i];
 
  398           if ((left >= best_left && left <= best_right)
 
  399              || (right >= best_left && right <= best_right))
 
  401             picked_chroms[
k][i].setIntensity(0.0);
 
  408     void findLargestPeak(std::vector<RichPeakChromatogram>& picked_chroms, 
int& chr_idx, 
int& peak_idx);
 
void raster(SpecT< PeakType > &spectrum)
Applies the resampling algorithm to an MSSpectrum. 
Definition: LinearResamplerAlign.h:69
std::vector< RichPeakChromatogram > smoothed_chroms_
Definition: MRMTransitionGroupPicker.h:103
String background_subtraction_
Definition: MRMTransitionGroupPicker.h:91
A more convenient string class. 
Definition: String.h:56
void setMZ(CoordinateType coordinate)
Mutable access to the m/z coordinate (index 1) 
Definition: Peak2D.h:197
void sortByPosition()
Lexicographically sorts the peaks by their position. 
Definition: MSSpectrum.h:391
IntensityType getIntensity() const 
Definition: Peak2D.h:161
const std::vector< SpectrumType > & getChromatograms() const 
Definition: MRMTransitionGroup.h:148
std::vector< PointType > PointArrayType
Definition: ConvexHull2D.h:79
bool isSorted() const 
Checks if all peaks are sorted with respect to ascending m/z. 
Definition: MSSpectrum.h:453
std::vector< RichPeakChromatogram > picked_chroms_
Definition: MRMTransitionGroupPicker.h:102
int stop_after_feature_
Definition: MRMTransitionGroupPicker.h:99
A 2-dimensional hull representation in [counter]clockwise direction - depending on axis labelling...
Definition: ConvexHull2D.h:75
DoubleReal gauss_width_
Definition: MRMTransitionGroupPicker.h:88
void setIntensity(IntensityType intensity)
Non-mutable access to the data point intensity (height) 
Definition: Peak2D.h:167
UInt sgolay_polynomial_order_
Definition: MRMTransitionGroupPicker.h:87
void addFeature(Feature &feature, const String &key)
Adds an feature from a single chromatogram into the feature. 
bool use_gauss_
Definition: MRMTransitionGroupPicker.h:89
DoubleReal sn_win_len_
Definition: MRMTransitionGroupPicker.h:96
The representation of a 1D spectrum. 
Definition: MSSpectrum.h:67
void setRT(CoordinateType coordinate)
Mutable access to the RT coordinate (index 0) 
Definition: Peak2D.h:209
The MRMTransitionGroupPicker finds peaks in chromatograms that belong to the same precursors...
Definition: MRMTransitionGroupPicker.h:76
const std::vector< ConvexHull2D > & getConvexHulls() const 
Non-mutable access to the convex hulls. 
void sortByIntensity(bool reverse=false)
Lexicographically sorts the peaks by their intensity. 
Definition: MSSpectrum.h:314
void setQuality(Size index, QualityType q)
Set the quality in dimension c. 
UInt sgolay_frame_length_
Definition: MRMTransitionGroupPicker.h:86
Linear Resampling of raw data with alignment. 
Definition: LinearResamplerAlign.h:58
void setHullPoints(const PointArrayType &points)
accessor for the outer(!) points (no checking is performed if this is actually a convex hull) ...
An LC-MS feature. 
Definition: Feature.h:66
void addFeature(MRMFeature &feature)
Definition: MRMTransitionGroup.h:184
void prepareMasterContainer_(MRMTransitionGroup< SpectrumT, TransitionT > &transition_group, SpectrumT &master_peak_container, int chr_idx, double best_left, double best_right)
create an empty master peak container that has the correct mz / RT values set 
Definition: MRMTransitionGroupPicker.h:109
void setOverallQuality(QualityType q)
Set the overall quality. 
SpectrumT resampleChromatogram_(const SpectrumT &chromatogram, SpectrumT &master_peak_container, double best_left, double best_right)
use the master container from above to resample a chromatogram at those points stored in the master c...
Definition: MRMTransitionGroupPicker.h:134
size_t Size
Size type e.g. used as variable which can hold result of size() 
Definition: Types.h:144
void pickTransitionGroup(MRMTransitionGroup< SpectrumT, TransitionT > &transition_group)
Definition: MRMTransitionGroupPicker.h:202
UInt sn_bin_count_
Definition: MRMTransitionGroupPicker.h:97
DoubleReal stop_after_intensity_ratio_
Definition: MRMTransitionGroupPicker.h:100
A base class for all classes handling default parameters. 
Definition: DefaultParamHandler.h:90
MRMFeature createMRMFeature(MRMTransitionGroup< SpectrumT, TransitionT > &transition_group, std::vector< SpectrumT > &picked_chroms, int &chr_idx, int &peak_idx)
Create feature from a vector of chromatograms and a specified peak. 
Definition: MRMTransitionGroupPicker.h:257
void remove_overlapping_features(std::vector< SpectrumT > &picked_chroms, double best_left, double best_right)
Remove overlaping features that are within the current seed feature or overlap with it...
Definition: MRMTransitionGroupPicker.h:377
A multi-chromatogram MRM feature. 
Definition: MRMFeature.h:50
MSSpectrum< ChromatogramPeak > RichPeakChromatogram
Definition: MRMTransitionGroupPicker.h:83
const String & getTransitionGroupID() const 
Definition: MRMTransitionGroup.h:112
DoubleReal peak_width_
Definition: MRMTransitionGroupPicker.h:93
DoubleReal signal_to_noise_
Definition: MRMTransitionGroupPicker.h:94