ProteoWizard
Classes | Functions | Variables
AminoAcidTest.cpp File Reference
#include "pwiz/utility/misc/unit.hpp"
#include "AminoAcid.hpp"
#include <cstring>
#include "pwiz/utility/misc/Std.hpp"
#include "boost/thread/thread.hpp"
#include "boost/thread/barrier.hpp"

Go to the source code of this file.

Classes

struct  TestAminoAcid
 

Functions

bool hasLowerMass (const AminoAcid::Info::Record &a, const AminoAcid::Info::Record &b)
 
void printRecord (ostream *os, const AminoAcid::Info::Record &record)
 
void test ()
 
void testThreadSafetyWorker (boost::barrier *testBarrier)
 
void testThreadSafety (const int &testThreadCount)
 
int main (int argc, char *argv[])
 

Variables

ostream * os_ = 0
 
TestAminoAcid testAminoAcids []
 

Function Documentation

◆ hasLowerMass()

bool hasLowerMass ( const AminoAcid::Info::Record a,
const AminoAcid::Info::Record b 
)

◆ printRecord()

void printRecord ( ostream *  os,
const AminoAcid::Info::Record record 
)

Definition at line 48 of file AminoAcidTest.cpp.

49{
50 if (!os) return;
51
52 *os << record.symbol << ": "
53 << setw(14) << record.name << " "
54 << setw(11) << record.formula << " "
55 << setprecision(3)
56 << setw(5) << record.abundance << " "
57 << fixed << setprecision(6)
58 << setw(10) << record.formula.monoisotopicMass() << " "
59 << setw(10) << record.formula.molecularWeight() << " "
60 << setw(10) << record.residueFormula.monoisotopicMass() << " "
61 << setw(10) << record.residueFormula.molecularWeight() << endl;
62}
double molecularWeight() const
PWIZ_API_DECL const Record & record(Type type)
returns the amino acid's Record by type

References pwiz::proteome::AminoAcid::Info::Record::abundance, pwiz::proteome::AminoAcid::Info::Record::formula, pwiz::chemistry::Formula::molecularWeight(), pwiz::chemistry::Formula::monoisotopicMass(), pwiz::proteome::AminoAcid::Info::Record::name, pwiz::proteome::AminoAcid::Info::Record::residueFormula, and pwiz::proteome::AminoAcid::Info::Record::symbol.

Referenced by test().

◆ test()

void test ( )

Definition at line 102 of file AminoAcidTest.cpp.

103{
104 // get a copy of all the records
105
106 vector<AminoAcid::Info::Record> records;
107
108 for (char symbol='A'; symbol<='Z'; symbol++)
109 {
110 try
111 {
113 records.push_back(record);
114 }
115 catch (exception&)
116 {}
117 }
118
119 for (vector<AminoAcid::Info::Record>::iterator it=records.begin(); it!=records.end(); ++it)
120 printRecord(os_, *it);
121
122 unit_assert(AminoAcid::Info::record(Alanine).residueFormula[C] == 3);
123 unit_assert(AminoAcid::Info::record(Alanine).residueFormula[H] == 5);
124 unit_assert(AminoAcid::Info::record(Alanine).residueFormula[N] == 1);
125 unit_assert(AminoAcid::Info::record(Alanine).residueFormula[O] == 1);
126 unit_assert(AminoAcid::Info::record(Alanine).residueFormula[S] == 0);
127
133
135
136 // test single amino acids
137 for (int i=0; i < 22; ++i) // skip X for now
138 {
141 unit_assert_equal(residueFormula.monoisotopicMass(), aa.monoMass, 0.00001);
142 unit_assert_equal(residueFormula.molecularWeight(), aa.avgMass, 0.0001);
143 //set<char> mmNames = mm2n.getNames(aa.monoMass, EPSILON);
144 //set<char> amNames = am2n.getNames(aa.avgMass, EPSILON);
145 //unit_assert(mmNames.count(aa.symbol) > 0);
146 //unit_assert(amNames.count(aa.symbol) > 0);
147 }
148
149
150 // compute some averages
151
152 double averageMonoisotopicMass = 0;
153 double averageC = 0;
154 double averageH = 0;
155 double averageN = 0;
156 double averageO = 0;
157 double averageS = 0;
158
159 for (vector<AminoAcid::Info::Record>::iterator it=records.begin(); it!=records.end(); ++it)
160 {
161 const AminoAcid::Info::Record& record = *it;
162
163 Formula residueFormula = record.residueFormula;
164 averageMonoisotopicMass += residueFormula.monoisotopicMass() * record.abundance;
165 averageC += residueFormula[C] * record.abundance;
166 averageH += residueFormula[H] * record.abundance;
167 averageN += residueFormula[N] * record.abundance;
168 averageO += residueFormula[O] * record.abundance;
169 averageS += residueFormula[S] * record.abundance;
170 }
171
172 if (os_) *os_ << setprecision(8) << endl;
173 if (os_) *os_ << "average residue C: " << averageC << endl;
174 if (os_) *os_ << "average residue H: " << averageH << endl;
175 if (os_) *os_ << "average residue N: " << averageN << endl;
176 if (os_) *os_ << "average residue O: " << averageO << endl;
177 if (os_) *os_ << "average residue S: " << averageS << endl;
178 if (os_) *os_ << endl;
179
180 if (os_) *os_ << "average monoisotopic mass: " << averageMonoisotopicMass << endl;
181 double averageResidueMass = averageMonoisotopicMass;
182 if (os_) *os_ << "average residue mass: " << averageResidueMass << endl << endl;
183
184 // sort by monoisotopic mass and print again
185 sort(records.begin(), records.end(), hasLowerMass);
186 for (vector<AminoAcid::Info::Record>::iterator it=records.begin(); it!=records.end(); ++it)
187 printRecord(os_, *it);
188}
Selenocysteine
Definition AminoAcid.hpp:65
Alanine
Definition AminoAcid.hpp:45
bool hasLowerMass(const AminoAcid::Info::Record &a, const AminoAcid::Info::Record &b)
TestAminoAcid testAminoAcids[]
void printRecord(ostream *os, const AminoAcid::Info::Record &record)
ostream * os_
Se
Definition Chemistry.hpp:84
N
Definition Chemistry.hpp:80
C
Definition Chemistry.hpp:80
S
Definition Chemistry.hpp:80
O
Definition Chemistry.hpp:80
H
Definition Chemistry.hpp:80
class to represent a chemical formula
struct for holding data for a single amino acid
Definition AminoAcid.hpp:79
#define unit_assert(x)
Definition unit.hpp:85
#define unit_assert_equal(x, y, epsilon)
Definition unit.hpp:99

References pwiz::proteome::AminoAcid::Info::Record::abundance, Alanine, TestAminoAcid::avgMass, C, H, hasLowerMass(), pwiz::chemistry::Formula::molecularWeight(), pwiz::chemistry::Formula::monoisotopicMass(), TestAminoAcid::monoMass, N, O, os_, printRecord(), pwiz::proteome::AminoAcid::Info::record(), pwiz::proteome::AminoAcid::Info::Record::residueFormula, S, Se, Selenocysteine, TestAminoAcid::symbol, testAminoAcids, unit_assert, and unit_assert_equal.

Referenced by testThreadSafetyWorker().

◆ testThreadSafetyWorker()

void testThreadSafetyWorker ( boost::barrier *  testBarrier)

Definition at line 191 of file AminoAcidTest.cpp.

192{
193 testBarrier->wait(); // wait until all threads have started
194
195 try
196 {
197 test();
198 }
199 catch (exception& e)
200 {
201 cerr << "Exception in worker thread: " << e.what() << endl;
202 }
203 catch (...)
204 {
205 cerr << "Unhandled exception in worker thread." << endl;
206 }
207}
void test()

References test().

Referenced by testThreadSafety().

◆ testThreadSafety()

void testThreadSafety ( const int &  testThreadCount)

Definition at line 209 of file AminoAcidTest.cpp.

210{
211 boost::barrier testBarrier(testThreadCount);
212 boost::thread_group testThreadGroup;
213 for (int i=0; i < testThreadCount; ++i)
214 testThreadGroup.add_thread(new boost::thread(&testThreadSafetyWorker, &testBarrier));
215 testThreadGroup.join_all();
216}
void testThreadSafetyWorker(boost::barrier *testBarrier)

References testThreadSafetyWorker().

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 219 of file AminoAcidTest.cpp.

220{
221 TEST_PROLOG(argc, argv)
222
223 if (argc>1 && !strcmp(argv[1],"-v")) os_ = &cout;
224 if (os_) *os_ << "AminoAcidTest\n";
225
226 try
227 {
228 //testThreadSafety(1); // does not test thread-safety of singleton initialization
233 }
234 catch (exception& e)
235 {
236 TEST_FAILED(e.what())
237 }
238 catch (...)
239 {
240 TEST_FAILED("Caught unknown exception.")
241 }
242
244}
void testThreadSafety()
#define TEST_EPILOG
Definition unit.hpp:183
#define TEST_FAILED(x)
Definition unit.hpp:177
#define TEST_PROLOG(argc, argv)
Definition unit.hpp:175

References os_, TEST_EPILOG, TEST_FAILED, TEST_PROLOG, and testThreadSafety().

Variable Documentation

◆ os_

ostream* os_ = 0

Definition at line 39 of file AminoAcidTest.cpp.

Referenced by main(), and test().

◆ testAminoAcids

TestAminoAcid testAminoAcids[]
Initial value:
=
{
{ 71.0371140, 71.07790, 'A' },
{ 156.101111, 156.1857, 'R' },
{ 114.042927, 114.1026, 'N' },
{ 115.026943, 115.0874, 'D' },
{ 103.009185, 103.1429, 'C' },
{ 129.042593, 129.1140, 'E' },
{ 128.058578, 128.1292, 'Q' },
{ 57.0214640, 57.05130, 'G' },
{ 137.058912, 137.1393, 'H' },
{ 113.084064, 113.1576, 'I' },
{ 113.084064, 113.1576, 'L' },
{ 128.094963, 128.1723, 'K' },
{ 131.040485, 131.1961, 'M' },
{ 147.068414, 147.1739, 'F' },
{ 97.0527640, 97.11520, 'P' },
{ 87.0320280, 87.07730, 'S' },
{ 150.953636, 150.0379, 'U' },
{ 101.047679, 101.1039, 'T' },
{ 186.079313, 186.2099, 'W' },
{ 163.063329, 163.1733, 'Y' },
{ 99.0684140, 99.13110, 'V' },
{ 114.042927, 114.1026, 'B' },
{ 128.058578, 128.1292, 'Z' },
{ 114.091900, 114.1674, 'X' }
}

Definition at line 73 of file AminoAcidTest.cpp.

74{
75 { 71.0371140, 71.07790, 'A' }, // Alanine
76 { 156.101111, 156.1857, 'R' }, // Arginine
77 { 114.042927, 114.1026, 'N' }, // Asparagine
78 { 115.026943, 115.0874, 'D' }, // Aspartic acid
79 { 103.009185, 103.1429, 'C' }, // Cysteine
80 { 129.042593, 129.1140, 'E' }, // Glutamic acid
81 { 128.058578, 128.1292, 'Q' }, // Glutamine
82 { 57.0214640, 57.05130, 'G' }, // Glycine
83 { 137.058912, 137.1393, 'H' }, // Histidine
84 { 113.084064, 113.1576, 'I' }, // Isoleucine
85 { 113.084064, 113.1576, 'L' }, // Leucine
86 { 128.094963, 128.1723, 'K' }, // Lysine
87 { 131.040485, 131.1961, 'M' }, // Methionine
88 { 147.068414, 147.1739, 'F' }, // Phenylalanine
89 { 97.0527640, 97.11520, 'P' }, // Proline
90 { 87.0320280, 87.07730, 'S' }, // Serine
91 { 150.953636, 150.0379, 'U' }, // Selenocysteine
92 { 101.047679, 101.1039, 'T' }, // Threonine
93 { 186.079313, 186.2099, 'W' }, // Tryptophan
94 { 163.063329, 163.1733, 'Y' }, // Tyrosine
95 { 99.0684140, 99.13110, 'V' }, // Valine
96 { 114.042927, 114.1026, 'B' }, // AspX
97 { 128.058578, 128.1292, 'Z' }, // GlutX
98 { 114.091900, 114.1674, 'X' } // Unknown (Averagine)
99};

Referenced by test().