29 #include "boost/thread/thread.hpp"
30 #include "boost/thread/barrier.hpp"
31 #include "boost/exception/all.hpp"
32 #include "boost/foreach_field.hpp"
46 const vector<string>& cleavageAgentNames = Digestion::getCleavageAgentNames();
50 *
os_ <<
"Cleavage agents:" << endl;
54 << Digestion::getCleavageAgentRegex(agentCvid)
58 *
os_ <<
"\nCleavage agent names" << endl;
59 BOOST_FOREACH(
string agentName, cleavageAgentNames)
61 *
os_ << agentName << endl;
122 const string& expectedSequence,
123 size_t expectedOffset,
124 size_t expectedMissedCleavages,
125 size_t expectedSpecificTermini,
126 const string& expectedPrefix,
127 const string& expectedSuffix)
141 cerr <<
"Testing peptide " <<
peptide.
sequence() <<
": " << e.what() << endl;
148 if (
os_) *
os_ <<
"Fully-specific BSA digest (offset, missed cleavages, specific termini, length, sequence)" << endl;
150 vector<DigestedPeptide> trypticPeptides(trypticDigestion.
begin(), trypticDigestion.
end());
151 set<DigestedPeptide, DigestedPeptideLessThan> trypticPeptideSet(trypticPeptides.begin(), trypticPeptides.end());
173 unit_assert(!trypticPeptideSet.count(
"MKWVTFISLLLL"));
177 unit_assert(trypticPeptideSet.count(
"RDTHKSEIAHRFK"));
178 unit_assert(trypticPeptideSet.count(
"DTHKSEIAHRFK"));
181 unit_assert(trypticPeptideSet.count(
"EACFAVEGPKLVVSTQTALA"));
182 unit_assert(trypticPeptides.back().sequence() ==
"LVVSTQTALA");
185 unit_assert(!trypticPeptideSet.count(
"MKWVTFISLLLLFSSAYSRGVFRRDTHK"));
186 unit_assert(!trypticPeptideSet.count(
"LKPDPNTLCDEFKADEKKFWGKYLYEIARR"));
191 unit_assert(trypticPeptideSet.count(
"VLASSARQRLR"));
194 unit_assert(!trypticPeptideSet.count(
"MKWVTFISLLLLFSSAYSRGVFRRDTHKSEIAHRFKDLGEEHFK"));
197 unit_assert(trypticPeptideSet.count(
"KWVTFISLLLLFSSAYSR"));
202 if (
os_) *
os_ <<
"Semi-specific BSA digest (offset, missed cleavages, specific termini, length, sequence)" << endl;
204 set<DigestedPeptide, DigestedPeptideLessThan>::const_iterator peptideItr;
206 vector<DigestedPeptide> semitrypticPeptides(semitrypticDigestion.
begin(), semitrypticDigestion.
end());
207 set<DigestedPeptide, DigestedPeptideLessThan> semitrypticPeptideSet(semitrypticPeptides.begin(), semitrypticPeptides.end());
239 unit_assert(semitrypticPeptides[0].NTerminusIsSpecific() &&
240 !semitrypticPeptides[0].CTerminusIsSpecific());
242 peptideItr = semitrypticPeptideSet.find(
"MKWVTFISLLLLFSSAYSR");
243 unit_assert(peptideItr != semitrypticPeptideSet.end());
248 peptideItr->CTerminusIsSpecific());
250 peptideItr = semitrypticPeptideSet.find(
"KWVTFISLLLLFSSAYSR");
251 unit_assert(peptideItr != semitrypticPeptideSet.end());
256 peptideItr->CTerminusIsSpecific());
258 peptideItr = semitrypticPeptideSet.find(
"KWVTFISLLLLFSSAYSRG");
259 unit_assert(peptideItr == semitrypticPeptideSet.end());
261 peptideItr = semitrypticPeptideSet.find(
"WVTFISLLLLFSSAYSR");
262 unit_assert(peptideItr != semitrypticPeptideSet.end());
267 peptideItr->CTerminusIsSpecific());
269 peptideItr = semitrypticPeptideSet.find(
"WVTFISLLLLFSSAYSRG");
270 unit_assert(peptideItr != semitrypticPeptideSet.end());
275 !peptideItr->CTerminusIsSpecific());
277 peptideItr = semitrypticPeptideSet.find(
"VTFISLLLLFSSAYSRG");
278 unit_assert(peptideItr == semitrypticPeptideSet.end());
281 unit_assert(semitrypticPeptideSet.count(
"WVTFISLLLLFSSAYSR"));
282 unit_assert(semitrypticPeptideSet.count(
"VTFISLLLLFSSAYSR"));
283 unit_assert(!semitrypticPeptideSet.count(
"VTFISLLLLFSSAYS"));
286 unit_assert(semitrypticPeptideSet.count(
"FAVEGPKLVVSTQTALA"));
287 unit_assert(!semitrypticPeptideSet.count(
"FAVEGPKLVVSTQTAL"));
292 if (
os_) *
os_ <<
"Non-specific BSA digest (offset, missed cleavages, specific termini, length, sequence)" << endl;
294 set<DigestedPeptide, DigestedPeptideLessThan>::const_iterator peptideItr;
296 vector<DigestedPeptide> nontrypticPeptides(nontrypticDigestion.
begin(), nontrypticDigestion.
end());
297 set<DigestedPeptide, DigestedPeptideLessThan> nontrypticPeptideSet(nontrypticPeptides.begin(), nontrypticPeptides.end());
321 unit_assert(nontrypticPeptides[0].NTerminusIsSpecific() &&
322 !nontrypticPeptides[0].CTerminusIsSpecific());
324 peptideItr = nontrypticPeptideSet.find(
"MKWVTFISLLLLFSSAYSR");
325 unit_assert(peptideItr != nontrypticPeptideSet.end());
330 peptideItr->CTerminusIsSpecific());
332 peptideItr = nontrypticPeptideSet.find(
"KWVTFISLLLLFSSAYSR");
333 unit_assert(peptideItr != nontrypticPeptideSet.end());
338 peptideItr->CTerminusIsSpecific());
340 peptideItr = nontrypticPeptideSet.find(
"KWVTFISLLLLFSSAYSRG");
341 unit_assert(peptideItr == nontrypticPeptideSet.end());
343 peptideItr = nontrypticPeptideSet.find(
"WVTFISLLLLFSSAYSR");
344 unit_assert(peptideItr != nontrypticPeptideSet.end());
349 peptideItr->CTerminusIsSpecific());
351 peptideItr = nontrypticPeptideSet.find(
"WVTFISLLLLFSSAYSRG");
352 unit_assert(peptideItr != nontrypticPeptideSet.end());
357 !peptideItr->CTerminusIsSpecific());
359 peptideItr = nontrypticPeptideSet.find(
"VTFISLLLLFSSAYSRG");
360 unit_assert(peptideItr != nontrypticPeptideSet.end());
365 !peptideItr->CTerminusIsSpecific());
368 unit_assert(nontrypticPeptideSet.count(
"WVTFISLLLLFSSAYSR"));
369 unit_assert(nontrypticPeptideSet.count(
"VTFISLLLLFSSAYSR"));
370 unit_assert(nontrypticPeptideSet.count(
"VTFISLLLLFSSAYS"));
373 unit_assert(nontrypticPeptideSet.count(
"FAVEGPKLVVSTQTALA"));
374 unit_assert(nontrypticPeptideSet.count(
"FAVEGPKLVVSTQTAL"));
378 unit_assert(nontrypticPeptideSet.count(
"KWVTFISLLLLFSSAYSR"));
379 unit_assert(!nontrypticPeptideSet.count(
"KWVTFISLLLLFSSAYSRG"));
384 unit_assert(nontrypticPeptideSet.count(
"VLASSAR"));
387 unit_assert(!nontrypticPeptideSet.count(
"EYEATLEECCAKDDPHACYSTVFDK"));
392 if (
os_) *
os_ <<
"Semi-specific BSA digest w/ methionine clipping (offset, missed cleavages, specific termini, length, sequence)" << endl;
394 set<DigestedPeptide, DigestedPeptideLessThan>::const_iterator peptideItr;
396 vector<DigestedPeptide> semitrypticPeptides(semitrypticDigestion.
begin(), semitrypticDigestion.
end());
397 set<DigestedPeptide, DigestedPeptideLessThan> semitrypticPeptideSet(semitrypticPeptides.begin(), semitrypticPeptides.end());
430 unit_assert(semitrypticPeptides[0].NTerminusIsSpecific() &&
431 !semitrypticPeptides[0].CTerminusIsSpecific());
433 peptideItr = semitrypticPeptideSet.find(
"KWVTFISLLLLFSSAYS");
434 unit_assert(peptideItr != semitrypticPeptideSet.end());
440 peptideItr = semitrypticPeptideSet.find(
"KWVTFISLLLLFSSAYSR");
441 unit_assert(peptideItr != semitrypticPeptideSet.end());
446 peptideItr->CTerminusIsSpecific());
448 peptideItr = semitrypticPeptideSet.find(
"KWVTFISLLLLFSSAYSRG");
449 unit_assert(peptideItr == semitrypticPeptideSet.end());
451 peptideItr = semitrypticPeptideSet.find(
"WVTFISLLLLFSSAYSR");
452 unit_assert(peptideItr != semitrypticPeptideSet.end());
457 peptideItr->CTerminusIsSpecific());
459 peptideItr = semitrypticPeptideSet.find(
"WVTFISLLLLFSSAYSRG");
460 unit_assert(peptideItr != semitrypticPeptideSet.end());
465 !peptideItr->CTerminusIsSpecific());
467 peptideItr = semitrypticPeptideSet.find(
"VTFISLLLLFSSAYSRG");
468 unit_assert(peptideItr == semitrypticPeptideSet.end());
471 unit_assert(semitrypticPeptideSet.count(
"WVTFISLLLLFSSAYSR"));
472 unit_assert(semitrypticPeptideSet.count(
"KWVTFISLLLLFSSAYSR"));
473 unit_assert(semitrypticPeptideSet.count(
"KWVTFISLLLLFSSAYS"));
474 unit_assert(!semitrypticPeptideSet.count(
"VTFISLLLLFSSAYS"));
477 unit_assert(semitrypticPeptideSet.count(
"FAVEGPKLVVSTQTALA"));
478 unit_assert(!semitrypticPeptideSet.count(
"FAVEGPKLVVSTQTAL"));
483 if (
os_) *
os_ <<
"BSA digestion test" << endl;
486 Peptide bsa(
"MKWVTFISLLLLFSSAYSRGVFRRDTHKSEIAHRFKDLGEEHFKGLVLIAFSQYLQQCPF"
487 "DEHVKLVNELTEFAKTCVADESHAGCEKSLHTLFGDELCKVASLRETYGDMADCCEKQEP"
488 "ERNECFLSHKDDSPDLPKLKPDPNTLCDEFKADEKKFWGKYLYEIARRHPYFYAPELLYY"
489 "ANKYNGVFQECCQAEDKGACLLPKIETMREKVLASSARQRLRCASIQKFGERALKAWSVA"
490 "RLSQKFPKAEFVEVTKLVTDLTKVHKECCHGDLLECADDRADLAKYICDNQDTISSKLKE"
491 "CCDKPLLEKSHCIAEVEKDAIPENLPPLTADFAEDKDVCKNYQEAKDAFLGSFLYEYSRR"
492 "HPEYAVSVLLRLAKEYEATLEECCAKDDPHACYSTVFDKLKHLVDEPQNLIKQNCDQFEK"
493 "LGEYGFQNALIVRYTRKVPQVSTPTLVEVSRSLGKVGTRCCTKPESERMPCTEDYLSLIL"
494 "NRLCVLHEKTPVSEKVTKCCTESLVNRRPCFSALTPDETYVPKAFDEKLFTFHADICTLP"
495 "DTEKQIKKQTALVELLKHKPKATEEQLKTVMENFVAFVDKCCAADDKEACFAVEGPKLVV"
516 vector<Peptide> funkyPeptides(funkyDigestion.
begin(), funkyDigestion.
end());
518 unit_assert_operator_equal(
"MKWVTFISLLLLFSSAYSRGVFRRDTHKSEIAHRFKDLGEEHFKGLVLIAFSQYLQQCPFDEHVKLVNELTEFAKTCVADESHAGCEKSLHTLFGDELCKVASLRETYGDMADCCEKQEPERNECFLSHKDDSPDLPKLKPDPNTLCDEFKADEKKFWGKYLYEIARRHPYFYAPELLYYANKYNGVFQECCQAEDKGACLLPKIETMREKVLASSARQRLRCASIQKFGERALKAWSVARLSQKFPKAE", funkyPeptides[0].sequence());
519 unit_assert_operator_equal(
"FVEVTKLVTDLTKVHKECCHGDLLECADDRADLAKYICDNQDTISSKLKECCDKPLLEKSHCIAEVEKDAIPENLPPLTAD", funkyPeptides[1].sequence());
520 unit_assert_operator_equal(
"FAEDKDVCKNYQEAKDAFLGSFLYEYSRRHPEYAVSVLLRLAKEYEATLEECCAKDDPHACYSTVFDKLKHLVDEPQNLIKQNCDQFEKLGEYGFQNALIVRYTRKVPQVSTPTLVEVSRSLGKVGTRCCTKPESERMPCTEDYLSLILNRLCVLHEKTPVSEKVTKCCTESLVNRRPCFSALTPDETYVPKAFDEKLFTFHADICTLPDTEKQIKKQTALVELLKHKPKATEEQLKTVMENFVAFVDKCCAADDKEACFAVEGPKLVVSTQTALA", funkyPeptides[2].sequence());
524 vector<Peptide> aspnPeptides(aspnDigestion.
begin(), aspnDigestion.
end());
533 vector<Peptide> noCleavagePeptides(noCleavageDigestion.
begin(), noCleavageDigestion.
end());
540 vector<Peptide> unspecificCleavagePeptides(unspecificCleavageDigestion.
begin(), unspecificCleavageDigestion.
end());
551 Peptide bsa(
"MKWVTFISLLLLFSSAYSRGVFRRDTHKSEIAHRFKDLGEEHFKGLVLIAFSQYLQQCPF"
552 "DEHVKLVNELTEFAKTCVADESHAGCEKSLHTLFGDELCKVASLRETYGDMADCCEKQEP"
553 "ERNECFLSHKDDSPDLPKLKPDPNTLCDEFKADEKKFWGKYLYEIARRHPYFYAPELLYY"
554 "ANKYNGVFQECCQAEDKGACLLPKIETMREKVLASSARQRLRCASIQKFGERALKAWSVA"
555 "RLSQKFPKAEFVEVTKLVTDLTKVHKECCHGDLLECADDRADLAKYICDNQDTISSKLKE"
556 "CCDKPLLEKSHCIAEVEKDAIPENLPPLTADFAEDKDVCKNYQEAKDAFLGSFLYEYSRR"
557 "HPEYAVSVLLRLAKEYEATLEECCAKDDPHACYSTVFDKLKHLVDEPQNLIKQNCDQFEK"
558 "LGEYGFQNALIVRYTRKVPQVSTPTLVEVSRSLGKVGTRCCTKPESERMPCTEDYLSLIL"
559 "NRLCVLHEKTPVSEKVTKCCTESLVNRRPCFSALTPDETYVPKAFDEKLFTFHADICTLP"
560 "DTEKQIKKQTALVELLKHKPKATEEQLKTVMENFVAFVDKCCAADDKEACFAVEGPKLVV"
689 status.
exception = boost::copy_exception(runtime_error(e.what()));
693 status.
exception = boost::copy_exception(runtime_error(
"Unhandled exception in worker thread."));
701 boost::barrier testBarrier(testThreadCount);
702 list<pair<boost::shared_ptr<thread>,
ThreadStatus> > threads;
703 for (
int i=0; i < testThreadCount; ++i)
705 threads.push_back(make_pair(boost::shared_ptr<thread>(),
ThreadStatus()));
706 threads.back().first.reset(
new thread(
testThreadSafetyWorker, &testBarrier, boost::ref(threads.back().second)));
709 set<boost::shared_ptr<thread> > finishedThreads;
710 while (finishedThreads.size() < threads.size())
711 BOOST_FOREACH_FIELD((boost::shared_ptr<thread>& t)(
ThreadStatus& status), threads)
713 if (t->timed_join(boost::posix_time::seconds(1)))
714 finishedThreads.insert(t);
717 boost::rethrow_exception(status.
exception);
722 int main(
int argc,
char* argv[])
726 if (argc>1 && !strcmp(argv[1],
"-v"))
os_ = &cout;
727 if (
os_) *
os_ <<
"DigestionTest\n";