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
23
// --------------------------------------------------------------------------
24
// $Maintainer: Mathias Walzer$
26
// --------------------------------------------------------------------------
28
#include <OpenMS/CONCEPT/ClassTest.h>
30
///////////////////////////
31
#include <OpenMS/COMPARISON/CLUSTERING/ClusterHierarchical.h>
32
#include <OpenMS/COMPARISON/CLUSTERING/SingleLinkage.h>
33
#include <OpenMS/COMPARISON/SPECTRA/BinnedSpectrum.h>
34
#include <OpenMS/COMPARISON/SPECTRA/BinnedSharedPeakCount.h>
35
#include <OpenMS/SYSTEM/File.h>
36
#include <OpenMS/FORMAT/DTAFile.h>
40
///////////////////////////
42
using namespace OpenMS;
46
class LowlevelComparator
49
double operator()(const Size first, const Size second) const
52
x = min(second,first);
53
y = max(first,second);
155
START_TEST(ClusterHierarchical, "$Id: ClusterHierarchical_test.C 8210 2011-03-28 13:19:52Z aiche $")
157
/////////////////////////////////////////////////////////////
158
/////////////////////////////////////////////////////////////
160
ClusterHierarchical* ptr = 0;
161
ClusterHierarchical* nullPointer = 0;
162
START_SECTION(ClusterHierarchical())
164
ptr = new ClusterHierarchical();
165
TEST_NOT_EQUAL(ptr, nullPointer)
169
START_SECTION(~ClusterHierarchical())
175
START_SECTION((ClusterHierarchical(const ClusterHierarchical &source)))
177
ClusterHierarchical ch;
178
ch.setThreshold(66.6);
179
ClusterHierarchical copy(ch);
180
TEST_EQUAL(copy.getThreshold(), 66.6);
184
START_SECTION((double getThreshold()))
186
ClusterHierarchical ch;
187
ch.setThreshold(0.666);
188
TEST_EQUAL(ch.getThreshold(),0.666);
192
START_SECTION((void setThreshold(double x)))
194
ClusterHierarchical ch;
195
ch.setThreshold(0.666);
196
TEST_EQUAL(ch.getThreshold(),0.666);
200
START_SECTION((template <typename Data, typename SimilarityComparator> void cluster(std::vector< Data > &data, const SimilarityComparator &comparator, const ClusterFunctor &clusterer, std::vector<BinaryTreeNode>& cluster_tree, DistanceMatrix<Real>& original_distance)))
203
for (Size i = 0; i<d.size(); ++i)
207
ClusterHierarchical ch;
208
LowlevelComparator lc;
210
vector< BinaryTreeNode > result;
211
vector< BinaryTreeNode > tree;
212
tree.push_back(BinaryTreeNode(1,2,0.3f));
213
tree.push_back(BinaryTreeNode(3,4,0.4f));
214
tree.push_back(BinaryTreeNode(0,1,0.5f));
215
tree.push_back(BinaryTreeNode(0,3,0.6f));
216
tree.push_back(BinaryTreeNode(0,5,0.7f));
217
DistanceMatrix<Real> matrix;
219
ch.cluster<Size,LowlevelComparator>(d,lc,sl,result, matrix);
221
TEST_EQUAL(tree.size(), result.size());
222
for (Size i = 0; i < tree.size(); ++i)
224
TOLERANCE_ABSOLUTE(0.0001);
225
TEST_EQUAL(tree[i].left_child, result[i].left_child);
226
TEST_EQUAL(tree[i].right_child, result[i].right_child);
227
TEST_REAL_SIMILAR(tree[i].distance, result[i].distance);
232
START_SECTION((void cluster(std::vector<PeakSpectrum>& data, const BinnedSpectrumCompareFunctor& comparator, double sz, UInt sp, const ClusterFunctor& clusterer, std::vector<BinaryTreeNode>& cluster_tree, DistanceMatrix<Real>& original_distance)))
235
PeakSpectrum s1, s2, s3;
238
DTAFile().load(OPENMS_GET_TEST_DATA_PATH("PILISSequenceDB_DFPIANGER_1.dta"), s1);
244
peak.setIntensity(999.99f);
250
vector<PeakSpectrum> d(3);
251
d[0] = s1; d[1] = s2; d[2] = s3;
252
ClusterHierarchical ch;
253
BinnedSharedPeakCount bspc;
255
vector< BinaryTreeNode > result;
256
vector< BinaryTreeNode > tree;
257
tree.push_back(BinaryTreeNode(1,2,0.0));
258
tree.push_back(BinaryTreeNode(0,1,0.0086f));
259
DistanceMatrix<Real> matrix;
261
ch.cluster(d,bspc,1.5,2,sl,result, matrix);
263
TEST_EQUAL(tree.size(), result.size());
264
for (Size i = 0; i < tree.size(); ++i)
266
TOLERANCE_ABSOLUTE(0.0001);
267
TEST_EQUAL(tree[i].left_child, result[i].left_child);
268
TEST_EQUAL(tree[i].right_child, result[i].right_child);
269
TEST_REAL_SIMILAR(tree[i].distance, result[i].distance);
274
/////////////////////////////////////////////////////////////
275
/////////////////////////////////////////////////////////////