void test() { MSData msd; examples::initializeTiny(msd); SpectrumListPtr originalList = msd.run.spectrumListPtr; SpectrumListPtr defaultArrayLengthSortedList( new SpectrumList_Sorter(originalList, DefaultArrayLengthSorter())); SpectrumListPtr msLevelUnstableSortedList( new SpectrumList_Sorter(originalList, MSLevelSorter())); SpectrumListPtr msLevelStableSortedList( new SpectrumList_Sorter(originalList, MSLevelSorter(), true)); SpectrumListPtr sillySortedList( new SpectrumList_Sorter(msLevelStableSortedList, DefaultArrayLengthSorter())); if (os_) { *os_ << "Original spectrum list (" << originalList->size() << "):\n"; TextWriter write(*os_); write(*originalList); *os_ << endl; } if (os_) { *os_ << "Default array length sorted spectrum list (" << defaultArrayLengthSortedList->size() << "):\n"; TextWriter write(*os_); write(*defaultArrayLengthSortedList); *os_ << endl; } if (os_) { *os_ << "MS level unstable sorted spectrum list (" << msLevelUnstableSortedList->size() << "):\n"; TextWriter write(*os_); write(*msLevelUnstableSortedList); *os_ << endl; } if (os_) { *os_ << "MS level stable sorted spectrum list (" << msLevelStableSortedList->size() << "):\n"; TextWriter write(*os_); write(*msLevelStableSortedList); *os_ << endl; } if (os_) { *os_ << "Silly (nested) sorted spectrum list (" << sillySortedList->size() << "):\n"; TextWriter write(*os_); write(*sillySortedList); *os_ << endl; } unit_assert_operator_equal(originalList->size(), defaultArrayLengthSortedList->size()); unit_assert_operator_equal(originalList->size(), msLevelUnstableSortedList->size()); unit_assert_operator_equal(originalList->size(), msLevelStableSortedList->size()); unit_assert_operator_equal(originalList->size(), sillySortedList->size()); SpectrumPtr s; // assert that the original list is unmodified unit_assert_operator_equal("scan=19", originalList->spectrumIdentity(0).id); unit_assert_operator_equal(0, originalList->spectrumIdentity(0).index); unit_assert_operator_equal("scan=20", originalList->spectrumIdentity(1).id); unit_assert_operator_equal(1, originalList->spectrumIdentity(1).index); unit_assert_operator_equal("scan=21", originalList->spectrumIdentity(2).id); unit_assert_operator_equal(2, originalList->spectrumIdentity(2).index); unit_assert_operator_equal("scan=22", originalList->spectrumIdentity(3).id); unit_assert_operator_equal(3, originalList->spectrumIdentity(3).index); s = originalList->spectrum(0); unit_assert_operator_equal("scan=19", s->id); unit_assert_operator_equal(0, s->index); // validate the default array length sorted list (ascending order, scan=19 and scan=22 are interchangeable) unit_assert_operator_equal("scan=21", defaultArrayLengthSortedList->spectrumIdentity(0).id); unit_assert_operator_equal(0, defaultArrayLengthSortedList->spectrumIdentity(0).index); unit_assert_operator_equal("scan=20", defaultArrayLengthSortedList->spectrumIdentity(1).id); unit_assert_operator_equal(1, defaultArrayLengthSortedList->spectrumIdentity(1).index); unit_assert_operator_equal(2, defaultArrayLengthSortedList->spectrumIdentity(2).index); unit_assert_operator_equal(3, defaultArrayLengthSortedList->spectrumIdentity(3).index); s = defaultArrayLengthSortedList->spectrum(0); unit_assert_operator_equal("scan=21", s->id); unit_assert_operator_equal(0, s->index); s = defaultArrayLengthSortedList->spectrum(1); unit_assert_operator_equal("scan=20", s->id); unit_assert_operator_equal(1, s->index); s = defaultArrayLengthSortedList->spectrum(2); unit_assert_operator_equal(2, s->index); s = defaultArrayLengthSortedList->spectrum(3); unit_assert_operator_equal(3, s->index); for (size_t i=1, end=defaultArrayLengthSortedList->size(); i < end; ++i) unit_assert(defaultArrayLengthSortedList->spectrum(i)->defaultArrayLength >= defaultArrayLengthSortedList->spectrum(i-1)->defaultArrayLength); // validate the MS level unstable sorted list (scan=19, scan=21, and scan=22 are interchangeable) unit_assert_operator_equal(0, msLevelUnstableSortedList->spectrumIdentity(0).index); unit_assert_operator_equal(1, msLevelUnstableSortedList->spectrumIdentity(1).index); unit_assert_operator_equal(2, msLevelUnstableSortedList->spectrumIdentity(2).index); unit_assert_operator_equal("scan=20", msLevelUnstableSortedList->spectrumIdentity(3).id); unit_assert_operator_equal(3, msLevelUnstableSortedList->spectrumIdentity(3).index); s = msLevelUnstableSortedList->spectrum(0); unit_assert_operator_equal(0, s->index); s = msLevelUnstableSortedList->spectrum(1); unit_assert_operator_equal(1, s->index); s = msLevelUnstableSortedList->spectrum(2); unit_assert_operator_equal(2, s->index); s = msLevelUnstableSortedList->spectrum(3); unit_assert_operator_equal("scan=20", s->id); unit_assert_operator_equal(3, s->index); // validate the MS level stable sorted list (scan=19, scan=21, and scan=22 should stay in order) unit_assert_operator_equal("scan=19", msLevelStableSortedList->spectrumIdentity(0).id); unit_assert_operator_equal(0, msLevelStableSortedList->spectrumIdentity(0).index); unit_assert_operator_equal("scan=21", msLevelStableSortedList->spectrumIdentity(1).id); unit_assert_operator_equal(1, msLevelStableSortedList->spectrumIdentity(1).index); unit_assert_operator_equal("sample=1 period=1 cycle=23 experiment=1", msLevelStableSortedList->spectrumIdentity(2).id); unit_assert_operator_equal(2, msLevelStableSortedList->spectrumIdentity(2).index); unit_assert_operator_equal("scan=20", msLevelStableSortedList->spectrumIdentity(3).id); unit_assert_operator_equal(3, msLevelStableSortedList->spectrumIdentity(3).index); s = msLevelStableSortedList->spectrum(0); unit_assert_operator_equal("scan=19", s->id); unit_assert_operator_equal(0, s->index); s = msLevelStableSortedList->spectrum(1); unit_assert_operator_equal("scan=21", s->id); unit_assert_operator_equal(1, s->index); s = msLevelStableSortedList->spectrum(2); unit_assert_operator_equal("sample=1 period=1 cycle=23 experiment=1", s->id); unit_assert_operator_equal(2, s->index); s = msLevelStableSortedList->spectrum(3); unit_assert_operator_equal("scan=20", s->id); unit_assert_operator_equal(3, s->index); // validate the silly (nested) sorted list unit_assert_operator_equal("scan=21", sillySortedList->spectrumIdentity(0).id); unit_assert_operator_equal(0, sillySortedList->spectrumIdentity(0).index); unit_assert_operator_equal("scan=20", sillySortedList->spectrumIdentity(1).id); unit_assert_operator_equal(1, sillySortedList->spectrumIdentity(1).index); unit_assert_operator_equal(2, sillySortedList->spectrumIdentity(2).index); unit_assert_operator_equal(3, sillySortedList->spectrumIdentity(3).index); s = sillySortedList->spectrum(0); unit_assert_operator_equal("scan=21", s->id); unit_assert_operator_equal(0, s->index); s = sillySortedList->spectrum(1); unit_assert_operator_equal("scan=20", s->id); unit_assert_operator_equal(1, s->index); s = sillySortedList->spectrum(2); unit_assert_operator_equal(2, s->index); s = sillySortedList->spectrum(3); unit_assert_operator_equal(3, s->index); for (size_t i=1, end=sillySortedList->size(); i < end; ++i) unit_assert(sillySortedList->spectrum(i)->defaultArrayLength >= sillySortedList->spectrum(i-1)->defaultArrayLength); }
void test(bool indexed) { if (os_) *os_ << "test(): indexed=\"" << boolalpha << indexed << "\"\n"; MSData tiny; examples::initializeTiny(tiny); Serializer_mzML::Config config; config.indexed = indexed; Serializer_mzML serializer(config); ostringstream oss; serializer.write(oss, tiny); if (os_) *os_ << "oss:\n" << oss.str() << endl; shared_ptr<istream> is(new istringstream(oss.str())); // dummy would normally be read in from file MSData dummy; ParamGroupPtr pg1(new ParamGroup); pg1->id = "CommonMS1SpectrumParams"; pg1->cvParams.push_back(MS_positive_scan); pg1->cvParams.push_back(MS_full_scan); dummy.paramGroupPtrs.push_back(pg1); ParamGroupPtr pg2(new ParamGroup); pg2->id = "CommonMS2SpectrumParams"; pg2->cvParams.push_back(MS_positive_scan); pg2->cvParams.push_back(MS_full_scan); dummy.paramGroupPtrs.push_back(pg2); // so we don't have any dangling references dummy.instrumentConfigurationPtrs.push_back(InstrumentConfigurationPtr(new InstrumentConfiguration("LCQDeca"))); dummy.dataProcessingPtrs.push_back(DataProcessingPtr(new DataProcessing("XcaliburProcessing"))); SpectrumListPtr sl = SpectrumList_mzML::create(is, dummy, indexed); // check easy functions unit_assert(sl.get()); unit_assert(sl->size() == 4); unit_assert(sl->find ("S19") == 0); unit_assert(sl->findNative("19") == 0); unit_assert(sl->find("S20") == 1); unit_assert(sl->findNative("20") == 1); unit_assert(sl->find("S21") == 2); unit_assert(sl->findNative("21") == 2); unit_assert(sl->find("S22") == 3); unit_assert(sl->findNative("22") == 3); unit_assert(sl->findSpotID("A1").empty()); IndexList spotIndexList = sl->findSpotID("A1,42x42,4242x4242"); unit_assert(spotIndexList.size() == 1); unit_assert(spotIndexList[0] == 3); // check scan 19 SpectrumPtr s = sl->spectrum(0); // read without binary data unit_assert(s.get()); unit_assert(s->id == "S19"); unit_assert(s->nativeID == "19"); unit_assert(s->spotID.empty()); unit_assert(s->cvParam(MS_ms_level).valueAs<int>() == 1); unit_assert(s->binaryDataArrayPtrs.empty()); unit_assert(sl->spectrumIdentity(0).index == 0); unit_assert(sl->spectrumIdentity(0).id == "S19"); unit_assert(sl->spectrumIdentity(0).nativeID == "19"); unit_assert(sl->spectrumIdentity(0).spotID.empty()); SpectrumPtr s_cache = sl->spectrum(0); // cache read unit_assert(s_cache.get() == s.get()); s = sl->spectrum(0, true); // read with binary data unit_assert(s_cache.get() != s.get()); vector<MZIntensityPair> pairs; s->getMZIntensityPairs(pairs); unit_assert(pairs.size() == 15); for (int i=0; i<15; i++) unit_assert(pairs[i].mz==i && pairs[i].intensity==15-i); unit_assert(s->spectrumDescription.scan.paramGroupPtrs.size() == 1); unit_assert(s->spectrumDescription.scan.paramGroupPtrs.back()->id == "CommonMS1SpectrumParams"); unit_assert(s->spectrumDescription.scan.paramGroupPtrs.back()->cvParams.size() == 2); // check scan 20 s = sl->spectrum(1, true); unit_assert(s.get()); unit_assert(s->id == "S20"); unit_assert(s->nativeID == "20"); unit_assert(s->spotID.empty()); unit_assert(s->cvParam(MS_ms_level).valueAs<int>() == 2); unit_assert(sl->spectrumIdentity(1).index == 1); unit_assert(sl->spectrumIdentity(1).id == "S20"); unit_assert(sl->spectrumIdentity(1).nativeID == "20"); unit_assert(sl->spectrumIdentity(1).spotID.empty()); pairs.clear(); s->getMZIntensityPairs(pairs); unit_assert(pairs.size() == 10); for (int i=0; i<10; i++) unit_assert(pairs[i].mz==2*i && pairs[i].intensity==(10-i)*2); unit_assert(s->spectrumDescription.scan.paramGroupPtrs.size() == 1); unit_assert(s->spectrumDescription.scan.paramGroupPtrs.back()->id == "CommonMS2SpectrumParams"); unit_assert(s->spectrumDescription.scan.paramGroupPtrs.back()->cvParams.size() == 2); // check scan 22 (MALDI) s = sl->spectrum(3, true); unit_assert(s.get()); unit_assert(s->id == "S22"); unit_assert(s->nativeID == "22"); unit_assert(s->spotID == "A1,42x42,4242x4242"); unit_assert(s->cvParam(MS_ms_level).valueAs<int>() == 1); unit_assert(sl->spectrumIdentity(3).index == 3); unit_assert(sl->spectrumIdentity(3).id == "S22"); unit_assert(sl->spectrumIdentity(3).nativeID == "22"); unit_assert(sl->spectrumIdentity(3).spotID == "A1,42x42,4242x4242"); }