~ubuntu-branches/ubuntu/wily/openms/wily

« back to all changes in this revision

Viewing changes to source/TEST/ModificationsDB_test.C

  • Committer: Package Import Robot
  • Author(s): Filippo Rusconi
  • Date: 2012-11-12 15:58:12 UTC
  • Revision ID: package-import@ubuntu.com-20121112155812-vr15wtg9b50cuesg
Tags: upstream-1.9.0
ImportĀ upstreamĀ versionĀ 1.9.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// -*- mode: C++; tab-width: 2; -*-
 
2
// vi: set ts=2:
 
3
//
 
4
// --------------------------------------------------------------------------
 
5
//                   OpenMS Mass Spectrometry Framework
 
6
// --------------------------------------------------------------------------
 
7
//  Copyright (C) 2003-2011 -- Oliver Kohlbacher, Knut Reinert
 
8
//
 
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.
 
13
//
 
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.
 
18
//
 
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
 
22
//
 
23
// --------------------------------------------------------------------------
 
24
// $Maintainer: Stephan Aiche $
 
25
// $Authors: Andreas Bertsch $
 
26
// --------------------------------------------------------------------------
 
27
 
 
28
#include <OpenMS/CONCEPT/ClassTest.h>
 
29
 
 
30
///////////////////////////
 
31
#include <OpenMS/CHEMISTRY/ModificationsDB.h>
 
32
#include <limits>
 
33
#include <algorithm>
 
34
///////////////////////////
 
35
 
 
36
using namespace OpenMS;
 
37
using namespace std;
 
38
 
 
39
START_TEST(ModificationsDB, "$Id: ModificationsDB_test.C 9373 2011-12-21 12:00:14Z timosachsenberg $")
 
40
 
 
41
/////////////////////////////////////////////////////////////
 
42
/////////////////////////////////////////////////////////////
 
43
 
 
44
ModificationsDB* ptr = 0;
 
45
ModificationsDB* nullPointer = 0;
 
46
START_SECTION(ModificationsDB* getInstance())
 
47
{
 
48
        ptr = ModificationsDB::getInstance();
 
49
        TEST_NOT_EQUAL(ptr, nullPointer)
 
50
}
 
51
END_SECTION
 
52
 
 
53
START_SECTION(Size getNumberOfModifications() const)
 
54
        // range because data may change over time
 
55
        TEST_EQUAL(ptr->getNumberOfModifications() > 100, true);
 
56
END_SECTION
 
57
 
 
58
START_SECTION(const ResidueModification& getModification(Size index) const)
 
59
        TEST_EQUAL(ptr->getModification(0).getId().size() > 0, true)
 
60
END_SECTION
 
61
 
 
62
START_SECTION(void searchModifications(std::set<const ResidueModification*>& mods, const String& orgin, const String& mod_name, ResidueModification::Term_Specificity term_spec) const)
 
63
        set<const ResidueModification*> mods;
 
64
        ptr->searchModifications(mods, "T", "Phosphorylation", ResidueModification::ANYWHERE);
 
65
        TEST_EQUAL(mods.size(), 1)
 
66
        TEST_STRING_EQUAL((*mods.begin())->getFullId(), "Phospho (T)")
 
67
END_SECTION
 
68
 
 
69
START_SECTION((void searchTerminalModifications(std::set< const ResidueModification * > &mods, const String &name, ResidueModification::Term_Specificity term_spec) const))
 
70
        set<const ResidueModification*> mods;
 
71
        ptr->searchTerminalModifications(mods, "NIC", ResidueModification::N_TERM);
 
72
        TEST_EQUAL(mods.size(), 1)
 
73
END_SECTION
 
74
 
 
75
START_SECTION((void searchModifications(std::set< const ResidueModification * > &mods, const String &mod_name, ResidueModification::Term_Specificity term_spec) const ))
 
76
{
 
77
  set<const ResidueModification*> mods;
 
78
  ptr->searchTerminalModifications(mods, "Label:18O(1)", ResidueModification::ANYWHERE);
 
79
 
 
80
  TEST_EQUAL(mods.size(), 4)
 
81
  ABORT_IF(mods.size() != 4)
 
82
 
 
83
  set<const ResidueModification*>::const_iterator mod_it = mods.begin();
 
84
 
 
85
  TEST_STRING_EQUAL((*mod_it)->getOrigin(), "Y")
 
86
  TEST_STRING_EQUAL((*mod_it)->getId(), "Label:18O(1)")
 
87
  TEST_EQUAL((*mod_it)->getTermSpecificity(), ResidueModification::ANYWHERE)
 
88
  ++mod_it;
 
89
 
 
90
  TEST_STRING_EQUAL((*mod_it)->getOrigin(), "T")
 
91
  TEST_STRING_EQUAL((*mod_it)->getId(), "Label:18O(1)")
 
92
  TEST_EQUAL((*mod_it)->getTermSpecificity(), ResidueModification::ANYWHERE)
 
93
  ++mod_it;
 
94
 
 
95
  TEST_STRING_EQUAL((*mod_it)->getOrigin(), "S")
 
96
  TEST_STRING_EQUAL((*mod_it)->getId(), "Label:18O(1)")
 
97
  TEST_EQUAL((*mod_it)->getTermSpecificity(), ResidueModification::ANYWHERE)
 
98
  ++mod_it;
 
99
 
 
100
  TEST_STRING_EQUAL((*mod_it)->getOrigin(), "C-term")
 
101
  TEST_STRING_EQUAL((*mod_it)->getId(), "Label:18O(1)")
 
102
  TEST_EQUAL((*mod_it)->getTermSpecificity(), ResidueModification::C_TERM)
 
103
 
 
104
  mods.clear();
 
105
  ptr->searchTerminalModifications(mods, "Label:18O(1)", ResidueModification::C_TERM);
 
106
 
 
107
  TEST_EQUAL(mods.size(), 1)
 
108
  ABORT_IF(mods.size() != 1)
 
109
 
 
110
  mod_it = mods.begin();
 
111
  TEST_STRING_EQUAL((*mod_it)->getOrigin(), "C-term")
 
112
  TEST_STRING_EQUAL((*mod_it)->getId(), "Label:18O(1)")
 
113
  TEST_EQUAL((*mod_it)->getTermSpecificity(), ResidueModification::C_TERM)
 
114
 
 
115
  mods.clear();
 
116
  ptr->searchTerminalModifications(mods, "Label:18O(1)", ResidueModification::N_TERM);
 
117
 
 
118
  TEST_EQUAL(mods.size(), 0)
 
119
  ABORT_IF( !mods.empty() )
 
120
}
 
121
END_SECTION
 
122
 
 
123
 
 
124
START_SECTION((void getTerminalModificationsByDiffMonoMass(std::vector< String > &mods, DoubleReal mass, DoubleReal error, ResidueModification::Term_Specificity term_spec)))
 
125
        vector<String> mods;
 
126
        ptr->getTerminalModificationsByDiffMonoMass(mods, 42, 0.1, ResidueModification::N_TERM);
 
127
        set<String> uniq_mods;
 
128
        for (vector<String>::const_iterator it = mods.begin(); it != mods.end(); ++it)
 
129
        {
 
130
                uniq_mods.insert(*it);
 
131
        }
 
132
        TEST_EQUAL(mods.size(), 16)
 
133
        TEST_EQUAL(uniq_mods.size(), 16)
 
134
        TEST_EQUAL(uniq_mods.find("Acetyl (N-term)") != uniq_mods.end(), true)
 
135
 
 
136
END_SECTION
 
137
 
 
138
START_SECTION(const ResidueModification& getModification(const String & modification) const)
 
139
        TEST_EQUAL(ptr->getModification("Carboxymethyl (C)").getFullId(), "Carboxymethyl (C)")
 
140
        TEST_EQUAL(ptr->getModification("Carboxymethyl (C)").getId(), "Carboxymethyl")
 
141
END_SECTION
 
142
 
 
143
START_SECTION((const ResidueModification& getModification(const String &residue_name, const String &mod_name, ResidueModification::Term_Specificity term_spec) const))
 
144
        TEST_EQUAL(ptr->getModification("S", "Phosphorylation", ResidueModification::ANYWHERE).getId(), "Phospho")
 
145
        TEST_EQUAL(ptr->getModification("S", "Phosphorylation", ResidueModification::ANYWHERE).getFullId(), "Phospho (S)")
 
146
END_SECTION
 
147
 
 
148
START_SECTION(Size findModificationIndex(const String &mod_name) const)
 
149
        Size index = numeric_limits<Size>::max();
 
150
        index = ptr->findModificationIndex("Phospho (T)");
 
151
        TEST_NOT_EQUAL(index, numeric_limits<Size>::max())
 
152
END_SECTION
 
153
    
 
154
START_SECTION(void getModificationsByDiffMonoMass(std::vector< String > &mods, DoubleReal mass, DoubleReal error=0.0))
 
155
        vector<String> mods;
 
156
        ptr->getModificationsByDiffMonoMass(mods, 80.0, 0.1);
 
157
        set<String> uniq_mods;
 
158
        for (vector<String>::const_iterator it = mods.begin(); it != mods.end(); ++it)
 
159
        {
 
160
                uniq_mods.insert(*it);
 
161
        }
 
162
 
 
163
        TEST_EQUAL(uniq_mods.find("Phospho (S)") != uniq_mods.end(), true)
 
164
        TEST_EQUAL(uniq_mods.find("Phospho (T)") != uniq_mods.end(), true)
 
165
        TEST_EQUAL(uniq_mods.find("Phospho (Y)") != uniq_mods.end(), true)
 
166
        TEST_EQUAL(uniq_mods.find("Sulfo (S)") != uniq_mods.end(), true)
 
167
END_SECTION
 
168
 
 
169
START_SECTION(void readFromOBOFile(const String &filename))
 
170
        // implicitely tested above
 
171
        NOT_TESTABLE
 
172
END_SECTION
 
173
 
 
174
START_SECTION(void readFromUnimodXMLFile(const String &filename))
 
175
        // just provided for convenience at the moment
 
176
        NOT_TESTABLE
 
177
END_SECTION
 
178
 
 
179
START_SECTION((const ResidueModification& getTerminalModification(const String &name, ResidueModification::Term_Specificity term_spec) const))
 
180
        TEST_EQUAL(ptr->getTerminalModification("NIC", ResidueModification::N_TERM).getId(), "NIC")
 
181
        TEST_EQUAL(ptr->getTerminalModification("NIC", ResidueModification::N_TERM).getFullId(), "NIC (N-term)")
 
182
        TEST_EQUAL(ptr->getTerminalModification("Acetyl", ResidueModification::N_TERM).getFullId(), "Acetyl (N-term)")  
 
183
END_SECTION
 
184
 
 
185
START_SECTION((void getModificationsByDiffMonoMass(std::vector< String > &mods, const String &residue, DoubleReal mass, DoubleReal error=0.0)))
 
186
        vector<String> mods;
 
187
        ptr->getModificationsByDiffMonoMass(mods, "S", 80.0, 0.1);
 
188
        TEST_EQUAL(find(mods.begin(), mods.end(), "Phospho (S)") != mods.end(), true)
 
189
        TEST_EQUAL(find(mods.begin(), mods.end(), "Sulfo (S)") != mods.end(), true)
 
190
END_SECTION
 
191
 
 
192
START_SECTION((void getAllSearchModifications(std::vector< String > &modifications)))
 
193
        vector<String> mods;
 
194
        ptr->getAllSearchModifications(mods);
 
195
        TEST_EQUAL(find(mods.begin(), mods.end(), "Phospho (S)") != mods.end(), true)
 
196
        TEST_EQUAL(find(mods.begin(), mods.end(), "Sulfo (S)") != mods.end(), true)
 
197
        TEST_EQUAL(find(mods.begin(), mods.end(), "NIC (N-term)") != mods.end(), true)
 
198
        TEST_EQUAL(find(mods.begin(), mods.end(), "Phospho") != mods.end(), false)
 
199
        TEST_EQUAL(find(mods.begin(), mods.end(), "Dehydrated (N-term C)") != mods.end(), true)
 
200
END_SECTION
 
201
 
 
202
 
 
203
 
 
204
/////////////////////////////////////////////////////////////
 
205
/////////////////////////////////////////////////////////////
 
206
END_TEST
 
207
 
 
208
 
 
209