Home  · Classes  · Annotated Classes  · Modules  · Members  · Namespaces  · Related Pages
MapAlignmentAlgorithmIdentification.h
Go to the documentation of this file.
1 // --------------------------------------------------------------------------
2 // OpenMS -- Open-Source Mass Spectrometry
3 // --------------------------------------------------------------------------
4 // Copyright The OpenMS Team -- Eberhard Karls University Tuebingen,
5 // ETH Zurich, and Freie Universitaet Berlin 2002-2016.
6 //
7 // This software is released under a three-clause BSD license:
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 // * Neither the name of any author or any participating institution
14 // may be used to endorse or promote products derived from this software
15 // without specific prior written permission.
16 // For a full list of authors, refer to the file AUTHORS.
17 // --------------------------------------------------------------------------
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 // ARE DISCLAIMED. IN NO EVENT SHALL ANY OF THE AUTHORS OR THE CONTRIBUTING
22 // INSTITUTIONS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 //
30 // --------------------------------------------------------------------------
31 // $Maintainer: Hendrik Weisser $
32 // $Authors: Eva Lange, Clemens Groepl, Hendrik Weisser $
33 // --------------------------------------------------------------------------
34 
35 #ifndef OPENMS_ANALYSIS_MAPMATCHING_MAPALIGNMENTALGORITHMIDENTIFICATION_H
36 #define OPENMS_ANALYSIS_MAPMATCHING_MAPALIGNMENTALGORITHMIDENTIFICATION_H
37 
46 
47 #include <cmath> // for "abs"
48 #include <limits> // for "max"
49 #include <map>
50 
51 namespace OpenMS
52 {
74  public DefaultParamHandler,
75  public ProgressLogger
76  {
77 public:
80 
83 
84  // Set a reference for the alignment
85  template <typename DataType> void setReference(DataType& data)
86  {
87  reference_.clear();
88  if (data.empty()) return; // empty input resets the reference
89  SeqToList rt_data;
90  bool sorted = getRetentionTimes_(data, rt_data);
91  computeMedians_(rt_data, reference_, sorted);
92  if (reference_.empty())
93  {
94  throw Exception::MissingInformation(__FILE__, __LINE__, __PRETTY_FUNCTION__, "Could not extract retention time information from the reference file");
95  }
96  }
97 
104  template <typename DataType>
105  void align(std::vector<DataType>& data,
106  std::vector<TransformationDescription>& transformations,
107  Int reference_index = -1)
108  {
109  checkParameters_(data.size());
110  startProgress(0, 3, "aligning maps");
111 
112  reference_index_ = reference_index;
113  // is reference one of the input files?
114  bool use_internal_reference = (reference_index >= 0);
115  if (use_internal_reference)
116  {
117  if (reference_index >= data.size())
118  {
119  throw Exception::IndexOverflow(__FILE__, __LINE__,
120  __PRETTY_FUNCTION__, reference_index,
121  data.size());
122  }
123  setReference(data[reference_index]);
124  }
125 
126  // one set of RT data for each input map, except reference (if any):
127  std::vector<SeqToList> rt_data(data.size() - use_internal_reference);
128  bool all_sorted = true;
129  for (Size i = 0, j = 0; i < data.size(); ++i)
130  {
131  if (reference_index >= 0 && i == (Size)reference_index)
132  {
133  continue; // skip reference map, if any
134  }
135  all_sorted &= getRetentionTimes_(data[i], rt_data[j++]);
136  }
137  setProgress(1);
138 
139  computeTransformations_(rt_data, transformations, all_sorted);
140  setProgress(2);
141 
142  setProgress(3);
143  endProgress();
144  }
145 
146 protected:
147 
149  typedef std::map<String, DoubleList> SeqToList;
150 
152  typedef std::map<String, double> SeqToValue;
153 
156 
158  SeqToValue reference_;
159 
162 
165 
175  void computeMedians_(SeqToList& rt_data, SeqToValue& medians,
176  bool sorted = false);
177 
179  bool hasGoodHit_(PeptideIdentification& peptide);
180 
189  bool getRetentionTimes_(std::vector<PeptideIdentification>& peptides,
190  SeqToList& rt_data);
191 
200  bool getRetentionTimes_(MSExperiment<>& experiment, SeqToList& rt_data);
201 
214  template <typename MapType>
215  bool getRetentionTimes_(MapType& features, SeqToList& rt_data)
216  {
217  bool use_feature_rt = param_.getValue("use_feature_rt").toBool();
218  for (typename MapType::Iterator feat_it = features.begin();
219  feat_it != features.end(); ++feat_it)
220  {
221  if (use_feature_rt)
222  {
223  // find the peptide ID closest in RT to the feature centroid:
224  String sequence;
225  double rt_distance = std::numeric_limits<double>::max();
226  bool any_good_hit = false;
227  for (std::vector<PeptideIdentification>::iterator pep_it =
228  feat_it->getPeptideIdentifications().begin(); pep_it !=
229  feat_it->getPeptideIdentifications().end(); ++pep_it)
230  {
231  if (hasGoodHit_(*pep_it))
232  {
233  any_good_hit = true;
234  double current_distance = abs(pep_it->getRT() - feat_it->getRT());
235  if (current_distance < rt_distance)
236  {
237  sequence = pep_it->getHits()[0].getSequence().toString();
238  rt_distance = current_distance;
239  }
240  }
241  }
242 
243  if (any_good_hit) rt_data[sequence].push_back(feat_it->getRT());
244  }
245  else
246  {
247  getRetentionTimes_(feat_it->getPeptideIdentifications(), rt_data);
248  }
249  }
250 
251  if (!use_feature_rt &&
252  param_.getValue("use_unassigned_peptides").toBool())
253  {
254  getRetentionTimes_(features.getUnassignedPeptideIdentifications(),
255  rt_data);
256  }
257 
258  // remove duplicates (can occur if a peptide ID was assigned to several
259  // features due to overlap or annotation tolerance):
260  for (SeqToList::iterator rt_it = rt_data.begin(); rt_it != rt_data.end();
261  ++rt_it)
262  {
263  DoubleList& rt_values = rt_it->second;
264  sort(rt_values.begin(), rt_values.end());
265  DoubleList::iterator it = unique(rt_values.begin(), rt_values.end());
266  rt_values.resize(it - rt_values.begin());
267  }
268  return true; // RTs were already sorted for duplicate detection
269  }
270 
278  void computeTransformations_(std::vector<SeqToList>& rt_data,
279  std::vector<TransformationDescription>&
280  transforms, bool sorted = false);
281 
289  void checkParameters_(const Size runs);
290 
297  void getReference_();
298 
299 private:
300 
303 
306 
307  };
308 
309 } // namespace OpenMS
310 
311 #endif // OPENMS_ANALYSIS_MAPMATCHING_MAPALIGNMENTALGORITHMIDENTIFICATION_H
A more convenient string class.
Definition: String.h:57
std::vector< double > DoubleList
Vector of double precision real types.
Definition: ListUtils.h:66
std::vector< SpectrumType >::iterator Iterator
Mutable iterator.
Definition: MSExperiment.h:103
Int overflow exception.
Definition: Exception.h:255
Iterator begin()
Definition: MSExperiment.h:149
bool getRetentionTimes_(MapType &features, SeqToList &rt_data)
Collect retention time data ("RT" MetaInfo) from peptide IDs contained in feature maps or consensus m...
Definition: MapAlignmentAlgorithmIdentification.h:215
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
double score_threshold_
Score threshold for peptide hits.
Definition: MapAlignmentAlgorithmIdentification.h:161
Int reference_index_
Index of input file to use as reference (if any)
Definition: MapAlignmentAlgorithmIdentification.h:155
Iterator end()
Definition: MSExperiment.h:159
A map alignment algorithm based on peptide identifications from MS2 spectra.
Definition: MapAlignmentAlgorithmIdentification.h:73
void align(std::vector< DataType > &data, std::vector< TransformationDescription > &transformations, Int reference_index=-1)
Align feature maps, consensus maps, peak maps, or peptide identifications.
Definition: MapAlignmentAlgorithmIdentification.h:105
std::map< String, DoubleList > SeqToList
Type to store retention times given for individual peptide sequences.
Definition: MapAlignmentAlgorithmIdentification.h:149
Base class for all classes that want to report their progress.
Definition: ProgressLogger.h:55
A base class for all classes handling default parameters.
Definition: DefaultParamHandler.h:92
Size min_run_occur_
Minimum number of runs a peptide must occur in.
Definition: MapAlignmentAlgorithmIdentification.h:164
SeqToValue reference_
Reference retention times (per peptide sequence)
Definition: MapAlignmentAlgorithmIdentification.h:158
int Int
Signed integer type.
Definition: Types.h:103
void setReference(DataType &data)
Definition: MapAlignmentAlgorithmIdentification.h:85
std::map< String, double > SeqToValue
Type to store one representative retention time per peptide sequence.
Definition: MapAlignmentAlgorithmIdentification.h:152
Not all required information provided.
Definition: Exception.h:196
Represents the peptide hits for a spectrum.
Definition: PeptideIdentification.h:63

OpenMS / TOPP release 2.0.0 Documentation generated on Tue Jan 31 2017 06:39:47 using doxygen 1.8.8