1
// -*- mode: C++; tab-width: 2; -*-
4
// --------------------------------------------------------------------------
5
// OpenMS Mass Spectrometry Framework
6
// --------------------------------------------------------------------------
7
// Copyright (C) 2003-2011 -- Oliver Kohlbacher, Knut Reinert
9
// This library is free software; you can redistribute it and/or
10
// modify it under the terms of the GNU Lesser General Public
11
// License as published by the Free Software Foundation; either
12
// version 2.1 of the License, or (at your option) any later version.
14
// This library is distributed in the hope that it will be useful,
15
// but WITHOUT ANY WARRANTY; without even the implied warranty of
16
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17
// Lesser General Public License for more details.
19
// You should have received a copy of the GNU Lesser General Public
20
// License along with this library; if not, write to the Free Software
21
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
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-2013.
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.
23
30
// --------------------------------------------------------------------------
24
31
// $Maintainer: Clemens Groepl $
53
60
setName(getProductName());
55
62
defaults_.setValue("mz_pair_max_distance", 0.5, "Maximum of m/z deviation of corresponding elements in different maps. "
56
"This condition applies to the pairs considered in hashing.");
63
"This condition applies to the pairs considered in hashing.");
57
64
defaults_.setMinFloat("mz_pair_max_distance", 0.);
59
66
defaults_.setValue("num_used_points", 2000, "Maximum number of elements considered in each map "
60
"(selected by intensity). Use this to reduce the running time "
61
"and to disregard weak signals during alignment. For using all points, set this to -1.");
67
"(selected by intensity). Use this to reduce the running time "
68
"and to disregard weak signals during alignment. For using all points, set this to -1.");
62
69
defaults_.setMinInt("num_used_points", -1);
64
71
defaults_.setValue("shift_bucket_size", 3.0, "The shift of the retention time "
65
"interval is being hashed into buckets of this size during pose "
66
"clustering. A good choice for this would be about "
67
"the time between consecutive MS scans.");
72
"interval is being hashed into buckets of this size during pose "
73
"clustering. A good choice for this would be about "
74
"the time between consecutive MS scans.");
68
75
defaults_.setMinFloat("shift_bucket_size", 0.);
70
77
defaults_.setValue("max_shift", 1000.0, "Maximal shift which is considered during histogramming. "
71
"This applies for both directions.", StringList::create("advanced"));
78
"This applies for both directions.", StringList::create("advanced"));
72
79
defaults_.setMinFloat("max_shift", 0.);
74
81
defaults_.setValue("dump_buckets", "", "[DEBUG] If non-empty, base filename where hash table buckets will be dumped to. "
75
"A serial number for each invocation will be appended automatically.", StringList::create("advanced"));
82
"A serial number for each invocation will be appended automatically.", StringList::create("advanced"));
77
84
defaults_.setValue("dump_pairs", "", "[DEBUG] If non-empty, base filename where the individual hashed pairs will be dumped to (large!). "
78
"A serial number for each invocation will be appended automatically.", StringList::create("advanced"));
85
"A serial number for each invocation will be appended automatically.", StringList::create("advanced"));
80
87
defaultsToParam_();
85
PoseClusteringShiftSuperimposer::run(const std::vector<ConsensusMap>& maps, std::vector<TransformationDescription>& transformations)
91
void PoseClusteringShiftSuperimposer::run(const ConsensusMap & map_model, const ConsensusMap & map_scene, TransformationDescription & transformation)
88
if ( maps.size() != 2 )
90
throw Exception::IllegalArgument(__FILE__, __LINE__, __PRETTY_FUNCTION__, "Exactly two input maps are required");
93
93
typedef ConstRefVector<ConsensusMap> PeakPointerArray_;
94
94
typedef Math::LinearInterpolation<DoubleReal, DoubleReal> LinearInterpolationType_;
139
139
//**************************************************************************
140
140
// Select the most abundant data points only. After that, disallow modifications
141
141
// (we tend to have annoying issues with const_iterator versus iterator).
142
PeakPointerArray_ model_map_ini(maps[0].begin(), maps[0].end());
142
PeakPointerArray_ model_map_ini(map_model.begin(), map_model.end());
143
143
const PeakPointerArray_ & model_map(model_map_ini);
144
PeakPointerArray_ scene_map_ini(maps[1].begin(), maps[1].end());
144
PeakPointerArray_ scene_map_ini(map_scene.begin(), map_scene.end());
145
145
const PeakPointerArray_ & scene_map(scene_map_ini);
147
147
// truncate the data as necessary
148
148
// casting to SignedSize is done on PURPOSE here! (num_used_points will be maximal if -1 is used)
149
149
const Size num_used_points = (SignedSize) param_.getValue("num_used_points");
150
if ( model_map_ini.size() > num_used_points )
150
if (model_map_ini.size() > num_used_points)
152
152
model_map_ini.sortByIntensity(true);
153
153
model_map_ini.resize(num_used_points);
155
155
model_map_ini.sortByComparator(Peak2D::MZLess());
156
156
setProgress(++actual_progress);
157
if ( scene_map_ini.size() > num_used_points )
157
if (scene_map_ini.size() > num_used_points)
159
159
scene_map_ini.sortByIntensity(true);
160
160
scene_map_ini.resize(num_used_points);
171
171
// get RT ranges (NOTE: we trust that min and max have been updated in the
172
172
// ConsensusMap::convert() method !)
174
const DoubleReal model_low = maps[0].getMin()[ConsensusFeature::RT];
175
const DoubleReal scene_low = maps[1].getMin()[ConsensusFeature::RT];
176
const DoubleReal model_high = maps[0].getMax()[ConsensusFeature::RT];
177
const DoubleReal scene_high = maps[1].getMax()[ConsensusFeature::RT];
174
const DoubleReal model_low = map_model.getMin()[ConsensusFeature::RT];
175
const DoubleReal scene_low = map_scene.getMin()[ConsensusFeature::RT];
176
const DoubleReal model_high = map_model.getMax()[ConsensusFeature::RT];
177
const DoubleReal scene_high = map_scene.getMax()[ConsensusFeature::RT];
180
180
// const DoubleReal rt_low = (maps[0].getMin()[ConsensusFeature::RT] + maps[1].getMin()[ConsensusFeature::RT]) / 2.;
275
275
setProgress(++actual_progress);
277
277
// first point in model map
278
for ( Size i = 0, i_low = 0, i_high = 0, k_low = 0, k_high = 0; i < model_map_size - 1; ++i )
278
for (Size i = 0, i_low = 0, i_high = 0, k_low = 0, k_high = 0; i < model_map_size - 1; ++i)
280
280
setProgress(actual_progress + Real(i) / model_map_size * 10.f);
282
282
// Adjust window around i in model map
283
while ( i_low < model_map_size && model_map[i_low].getMZ() < model_map[i].getMZ() - mz_pair_max_distance )
283
while (i_low < model_map_size && model_map[i_low].getMZ() < model_map[i].getMZ() - mz_pair_max_distance)
285
while ( i_high < model_map_size && model_map[i_high].getMZ() <= model_map[i].getMZ() + mz_pair_max_distance )
285
while (i_high < model_map_size && model_map[i_high].getMZ() <= model_map[i].getMZ() + mz_pair_max_distance)
287
287
DoubleReal i_winlength_factor = 1. / (i_high - i_low);
288
288
i_winlength_factor -= winlength_factor_baseline;
289
if ( i_winlength_factor <= 0 )
289
if (i_winlength_factor <= 0)
292
292
// Adjust window around k in scene map
293
while ( k_low < scene_map_size && scene_map[k_low].getMZ() < model_map[i].getMZ() - mz_pair_max_distance )
293
while (k_low < scene_map_size && scene_map[k_low].getMZ() < model_map[i].getMZ() - mz_pair_max_distance)
295
while ( k_high < scene_map_size && scene_map[k_high].getMZ() <= model_map[i].getMZ() + mz_pair_max_distance )
295
while (k_high < scene_map_size && scene_map[k_high].getMZ() <= model_map[i].getMZ() + mz_pair_max_distance)
298
298
// first point in scene map
299
for ( Size k = k_low; k < k_high; ++k )
299
for (Size k = k_low; k < k_high; ++k)
301
301
DoubleReal k_winlength_factor = 1. / (k_high - k_low);
302
302
k_winlength_factor -= winlength_factor_baseline;
303
if ( k_winlength_factor <= 0 )
303
if (k_winlength_factor <= 0)
306
306
// compute similarity of intensities i k
321
321
// hash the images of scaling, rt_low and rt_high into their respective hash tables
322
322
shift_hash_.addValue(shift, similarity_ik);
326
326
dump_pairs_file << i << ' ' << model_map[i].getRT() << ' ' << model_map[i].getMZ() << ' ' << k << ' ' << scene_map[k].getRT() << ' '
327
<< scene_map[k].getMZ() << ' ' << similarity_ik << ' ' << std::endl;
327
<< scene_map[k].getMZ() << ' ' << similarity_ik << ' ' << std::endl;
333
while ( 0 ); // end of hashing (the extra syntax helps with code folding in eclipse!)
333
while (0); // end of hashing (the extra syntax helps with code folding in eclipse!)
335
335
setProgress((actual_progress = 30));
337
337
///////////////////////////////////////////////////////////////////
338
338
// work on shift_hash_
339
// DoubleReal shift_low;
340
// DoubleReal shift_centroid;
341
// DoubleReal shift_high;
339
// DoubleReal shift_low;
340
// DoubleReal shift_centroid;
341
// DoubleReal shift_high;
344
344
DoubleReal shift_low;
345
345
DoubleReal shift_centroid;
346
346
DoubleReal shift_high;
409
409
std::sort(buffer.begin(), buffer.end(), std::greater<DoubleReal>());
410
410
DoubleReal freq_intercept = shift_hash_.getData().front();
411
411
DoubleReal freq_slope = (shift_hash_.getData().back() - shift_hash_.getData().front()) / DoubleReal(buffer.size())
412
/ scaling_histogram_crossing_slope;
413
if ( !freq_slope || !buffer.size() )
412
/ scaling_histogram_crossing_slope;
413
if (!freq_slope || !buffer.size())
415
415
// in fact these conditions are actually impossible, but let's be really sure ;-)
416
416
freq_cutoff_low = 0;
474
474
shift_low = (outside_mean - outside_stdev);
475
475
shift_centroid = (outside_mean);
476
476
shift_high = (outside_mean + outside_stdev);
477
if ( do_dump_buckets )
479
dump_buckets_file << "# loop: " << loop << " mean: " << outside_mean << " stdev: " << outside_stdev << " (mean-stdev): " << outside_mean
480
- outside_stdev << " (mean+stdev): " << outside_mean + outside_stdev << " data_range_begin: " << data_range_begin << " data_range_end: "
481
<< data_range_end << std::endl;
479
dump_buckets_file << "# loop: " << loop << " mean: " << outside_mean << " stdev: " << outside_stdev << " (mean-stdev): "
480
<< outside_mean - outside_stdev << " (mean+stdev): " << outside_mean + outside_stdev
481
<< " data_range_begin: " << data_range_begin << " data_range_end: "
482
<< data_range_end << std::endl;
484
485
setProgress(++actual_progress);
486
if ( do_dump_buckets )
488
489
dump_buckets_file << "# EOF" << std::endl;
489
490
dump_buckets_file.close();
515
transformations.clear();
518
517
params.setValue("slope", 1.0);
519
518
params.setValue("intercept", intercept);
521
TransformationDescription trafo;
522
trafo.fitModel("linear", params);
523
transformations.push_back(trafo);
520
TransformationDescription trafo;
521
trafo.fitModel("linear", params);
522
transformation = trafo;
526
525
setProgress(++actual_progress);