本文整理汇总了C++中SpectrumPtr类的典型用法代码示例。如果您正苦于以下问题:C++ SpectrumPtr类的具体用法?C++ SpectrumPtr怎么用?C++ SpectrumPtr使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SpectrumPtr类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: verifySpectrumSize
void verifySpectrumSize(const SpectrumList& sl, size_t index, size_t size)
{
SpectrumPtr spectrum = sl.spectrum(index, true);
vector<MZIntensityPair> data;
spectrum->getMZIntensityPairs(data);
unit_assert(data.size() == size);
}
示例2: lower_bound
PWIZ_API_DECL
msdata::SpectrumPtr SpectrumList_MZWindow::spectrum(size_t index, bool getBinaryData) const
{
SpectrumPtr spectrum = inner_->spectrum(index, getBinaryData);
if (!getBinaryData) return spectrum;
vector<MZIntensityPair> data;
spectrum->getMZIntensityPairs(data);
vector<MZIntensityPair>::const_iterator begin = lower_bound(
data.begin(), data.end(), MZIntensityPair(mzLow_,0), hasLowerMZ);
vector<MZIntensityPair>::const_iterator end = upper_bound(
data.begin(), data.end(), MZIntensityPair(mzHigh_,0), hasLowerMZ);
vector<MZIntensityPair> newData;
copy(begin, end, back_inserter(newData));
BinaryDataArrayPtr intensityArray = spectrum->getIntensityArray();
CVID intensityUnits = intensityArray.get() ? intensityArray->cvParam(MS_intensity_unit).cvid : CVID_Unknown;
SpectrumPtr newSpectrum(new Spectrum(*spectrum));
newSpectrum->binaryDataArrayPtrs.clear();
newSpectrum->setMZIntensityPairs(newData, intensityUnits);
return newSpectrum;
}
示例3: writeCompressedPeaks
void writeCompressedPeaks(SpectrumPtr s, ostream& os)
{
// Build arrays to hold peaks prior to compression
int numPeaks = (int) s->defaultArrayLength;
double *pD = new double[numPeaks];
float *pF = new float[numPeaks];
const BinaryDataArray& mzArray = *s->getMZArray();
const BinaryDataArray& intensityArray = *s->getIntensityArray();
for(int j = 0; j < numPeaks; j++)
{
pD[j] = mzArray.data[j];
pF[j] = (float) intensityArray.data[j];
}
// compress mz
uLong sizeM = (uLong) (numPeaks * sizeDoubleMSn);
uLong comprLenM = compressBound(sizeM);
Byte *comprM = (Byte*)calloc((uInt)comprLenM, 1);
int retM = compress(comprM, &comprLenM, (const Bytef*)pD, sizeM);
// compress intensity
uLong sizeI = (uLong) (numPeaks * sizeFloatMSn);
uLong comprLenI = compressBound(sizeI);
Byte *comprI = (Byte*)calloc((uInt)comprLenI, 1);
int retI = compress(comprI, &comprLenI, (const Bytef*)pF, sizeI);
// Write the compressed peaks if all is well
if ((Z_OK == retM) && (Z_OK == retI))
{
// write length of compressed array of m/z
os.write(reinterpret_cast<char *>(&comprLenM), sizeIntMSn);
// write length of compressed array of intensities
os.write(reinterpret_cast<char *>(&comprLenI), sizeIntMSn);
// write compressed array of m/z
os.write(reinterpret_cast<char *>(comprM), comprLenM);
// write compressed array of intensities
os.write(reinterpret_cast<char *>(comprI), comprLenI);
}
// Clean up memory
free(comprM);
free(comprI);
delete [] pD;
delete [] pF;
// In case of error, throw exception AFTER cleaning up memory
if (Z_OK != retM || Z_OK != retI)
{
throw runtime_error("[Serializer_MSn::writeCompressedPeaks] Error compressing peaks.");
}
}
示例4: writeSpectrumText
void writeSpectrumText(SpectrumPtr s, ostream& os)
{
os << std::setprecision(7); // 124.4567
// Write the scan numbers
os << "S\t";
int scanNum = getScanNumber(s);
os << scanNum << "\t" << scanNum << "\t";
// Write the precursor mz
Precursor& precur = s->precursors[0];
SelectedIon& si = precur.selectedIons[0];
double mz = si.cvParam(MS_selected_ion_m_z).valueAs<double>();
os << mz << "\n";
// Write the scan time, if available
if( s->scanList.scans[0].cvParam(MS_scan_start_time).timeInSeconds() )
os << "I\tRTime\t" << s->scanList.scans[0].cvParam(MS_scan_start_time).timeInSeconds() << "\n";
// Collect charge and mass info
vector<int> charges;
vector<double> masses;
int numChargeStates = 0;
// for each selected ion
BOOST_FOREACH(const SelectedIon& curIon, precur.selectedIons){
numChargeStates += getChargeStates(curIon, charges, masses);
}
// Write EZ lines if accurate masses are available
CVParam massParam = si.cvParam(MS_accurate_mass);
if( !massParam.empty() ){
for(int i=0; i < numChargeStates; i++){
os << "I\tEZ\t" << charges[i] << "\t" << masses[i] << "\t0\t0" << endl; // pad last two fields with 0
}
}
// For each charge, write the charge and mass
for(int i = 0; i < numChargeStates; i++)
{
os << "Z\t" << charges[i] << "\t" << masses[i] << "\n";
}
// Write each mz, intensity pair
const BinaryDataArray& mzArray = *s->getMZArray();
const BinaryDataArray& intensityArray = *s->getIntensityArray();
for (size_t p=0; p < s->defaultArrayLength; ++p)
{
os << mzArray.data[p] << " " << intensityArray.data[p] << "\n";
}
}
示例5: printSpectrumList
void printSpectrumList(const SpectrumList& sl, ostream& os)
{
os << "size: " << sl.size() << endl;
for (size_t i=0, end=sl.size(); i<end; i++)
{
SpectrumPtr spectrum = sl.spectrum(i, false);
os << spectrum->index << " "
<< spectrum->id << " "
<< "ms" << spectrum->cvParam(MS_ms_level).value << " "
<< "scanEvent:" << spectrum->scanList.scans[0].cvParam(MS_preset_scan_configuration).value << " "
<< "scanTime:" << spectrum->scanList.scans[0].cvParam(MS_scan_start_time).timeInSeconds() << " "
<< endl;
}
}
示例6: cat
void cat(const char* filename)
{
// open the data file
ExtendedReaderList readers; // for vendor Reader support
MSDataFile msd(filename, &readers);
// verify that we have a SpectrumList
if (!msd.run.spectrumListPtr.get())
throw runtime_error("[mscat] No spectra found.");
SpectrumList& spectrumList = *msd.run.spectrumListPtr;
// write header
const size_t columnWidth = 14;
cout << "#"
<< setw(columnWidth) << "scanNumber"
<< setw(columnWidth) << "msLevel"
<< setw(columnWidth) << "m/z"
<< setw(columnWidth) << "intensity" << endl;
// iterate through the spectra in the SpectrumList
for (size_t i=0, size=spectrumList.size(); i!=size; i++)
{
// retrieve the spectrum, with binary data
const bool getBinaryData = true;
SpectrumPtr spectrum = spectrumList.spectrum(i, getBinaryData);
// fill in MZIntensityPair vector for convenient access to binary data
vector<MZIntensityPair> pairs;
spectrum->getMZIntensityPairs(pairs);
// iterate through the m/z-intensity pairs
for (vector<MZIntensityPair>::const_iterator it=pairs.begin(), end=pairs.end(); it!=end; ++it)
{
cout << " "
<< setw(columnWidth) << spectrum->nativeID
<< setw(columnWidth) << "ms" + spectrum->cvParam(MS_ms_level).value
<< setw(columnWidth) << fixed << setprecision(4) << it->mz
<< setw(columnWidth) << fixed << setprecision(2) << it->intensity << endl;
}
}
}
示例7: if
void RAMPAdapter::Impl::getScanPeaks(size_t index, std::vector<double>& result) const
{
// use previous spectrum if possible (it must have binary data)
if (!lastSpectrum.get() || lastSpectrum->index != index) {
lastSpectrum = msd_.run.spectrumListPtr->spectrum(index, true); // full read
} else if (!lastSpectrum->hasBinaryData()) {
// copy lastSpectrum header, avoids reread of header if format supports it
lastSpectrum = msd_.run.spectrumListPtr->spectrum(lastSpectrum, true);
}
SpectrumPtr spectrum = lastSpectrum;
result.clear();
result.resize(spectrum->defaultArrayLength * 2);
if (spectrum->defaultArrayLength == 0) return;
spectrum->getMZIntensityPairs(reinterpret_cast<MZIntensityPair*>(&result[0]),
spectrum->defaultArrayLength);
}
示例8: printSpectrumList
void printSpectrumList(const SpectrumList& sl, ostream& os)
{
os << "size: " << sl.size() << endl;
for (size_t i=0, end=sl.size(); i<end; i++)
{
SpectrumPtr spectrum = sl.spectrum(i, false);
vector<MZIntensityPair> data;
spectrum->getMZIntensityPairs(data);
os << spectrum->index << " "
<< spectrum->id << ": ";
copy(data.begin(), data.end(), ostream_iterator<MZIntensityPair>(os, " "));
os << endl;
}
}
示例9: spectrum
PWIZ_API_DECL SpectrumPtr SpectrumList_MetadataFixer::spectrum(size_t index, bool getBinaryData) const
{
// always get binary data
SpectrumPtr s = inner_->spectrum(index, true);
BinaryDataArrayPtr mzArray = s->getMZArray();
BinaryDataArrayPtr intensityArray = s->getIntensityArray();
if (!mzArray.get() || !intensityArray.get())
return s;
vector<double>& mzs = mzArray->data;
vector<double>& intensities = intensityArray->data;
double tic = 0;
if (!mzs.empty())
{
double bpmz, bpi = -1;
for (size_t i=0, end=mzs.size(); i < end; ++i)
{
tic += intensities[i];
if (bpi < intensities[i])
{
bpi = intensities[i];
bpmz = mzs[i];
}
}
replaceCvParam(*s, MS_base_peak_intensity, bpi, MS_number_of_counts);
replaceCvParam(*s, MS_base_peak_m_z, bpmz, MS_m_z);
replaceCvParam(*s, MS_lowest_observed_m_z, mzs.front(), MS_m_z);
replaceCvParam(*s, MS_highest_observed_m_z, mzs.back(), MS_m_z);
}
replaceCvParam(*s, MS_TIC, tic, MS_number_of_counts);
return s;
}
示例10: getValue
void mzDataCache::getValue(const string& s, SpectrumPtr& spec) {
//printf("hola\n");
size_t* size = (size_t*) malloc(sizeof (size_t));
size_t* size_ = (size_t*) malloc(sizeof (size_t));
double* mz = (double*) (db.get((s + "mz").c_str(), (s + "mz").size() * sizeof (char), size));
double* intensity = (double*) (db.get((s + "int").c_str(), (s + "int").size() * sizeof (char), size_));
vector<double> mzData(mz, mz + (*size) / sizeof (double));
vector<double> intData(intensity, intensity + (*size_) / sizeof (double));
free(size);
free(size_);
delete [] mz;
delete [] intensity;
//printf("data get size: %d", mzData.size());
spec->setMZIntensityArrays(mzData, intData, CVID_Unknown);
}
示例11: writeSpectrumText
void writeSpectrumText(SpectrumPtr s, ostream& os)
{
os << std::setprecision(7); // 123.4567
bool ms1File = s->cvParam(MS_ms_level).valueAs<int>() == 1;
// Write the scan numbers
os << "S\t";
int scanNum = getScanNumber(s);
os << scanNum << "\t" << scanNum;
if (!ms1File)
{
// Write the precursor mz
Precursor& precur = s->precursors[0];
double mz = precur.isolationWindow.cvParam(MS_isolation_window_target_m_z).valueAs<double>();
os << "\t" << mz;
}
os << "\n";
// Write the scan time, if available
if( !(s->scanList.empty()) && s->scanList.scans[0].cvParam(MS_scan_start_time).timeInSeconds() )
os << "I\tRTime\t" << s->scanList.scans[0].cvParam(MS_scan_start_time).timeInSeconds()/60 << "\n";
if (s->defaultArrayLength > 0)
{
// Write the base peak intensity and base peak m/z
if (s->hasCVParam(MS_base_peak_intensity))
{
double bpi = s->cvParam(MS_base_peak_intensity).valueAs<double>();
os << "I\tBPI\t" << bpi << "\n";
}
if (s->hasCVParam(MS_base_peak_m_z))
{
double bpm = s->cvParam(MS_base_peak_m_z).valueAs<double>();
os << "I\tBPM\t" << bpm << "\n";
}
// Write the total ion current
if (s->hasCVParam(MS_total_ion_current))
{
double tic = s->cvParam(MS_total_ion_current).valueAs<double>();
os << "I\tTIC\t" << tic << "\n";
}
}
//TODO
// Write ConvA/ConvB information
// Write the ion injection time
//os << "I\tIIT\t" << s->scanList.scans[0].cvParam(MS_ion_injection_time).timeInSeconds()/60 << "\n";
if (!ms1File)
{
Precursor& precur = s->precursors[0];
SelectedIon& si = precur.selectedIons[0];
// Collect charge and mass info
vector<int> charges;
vector<double> masses;
int numChargeStates = 0;
// for each selected ion
BOOST_FOREACH(const SelectedIon& curIon, precur.selectedIons){
numChargeStates += getChargeStates(curIon, charges, masses);
}
// Write EZ lines if accurate masses are available
CVParam massParam = si.cvParam(MS_accurate_mass_OBSOLETE);
if( !massParam.empty() ){
for(int i=0; i < numChargeStates; i++){
os << "I\tEZ\t" << charges[i] << "\t" << masses[i] << "\t0\t0" << endl; // pad last two fields with 0
}
}
// For each charge, write the charge and mass
for(int i = 0; i < numChargeStates; i++)
{
os << "Z\t" << charges[i] << "\t" << masses[i] << "\n";
}
}
示例12: getScanNumber
void RAMPAdapter::Impl::getScanHeader(size_t index, ScanHeaderStruct& result, bool reservePeaks /*= true*/) const
{
// use previous spectrum if possible
if (!lastSpectrum.get() || lastSpectrum->index != index)
lastSpectrum = msd_.run.spectrumListPtr->spectrum(index, reservePeaks);
SpectrumPtr spectrum = lastSpectrum;
Scan dummy;
Scan& scan = spectrum->scanList.scans.empty() ? dummy : spectrum->scanList.scans[0];
result.seqNum = static_cast<int>(index + 1);
result.acquisitionNum = getScanNumber(index);
result.msLevel = spectrum->cvParam(MS_ms_level).valueAs<int>();
result.peaksCount = static_cast<int>(spectrum->defaultArrayLength);
result.totIonCurrent = spectrum->cvParam(MS_total_ion_current).valueAs<double>();
result.retentionTime = scan.cvParam(MS_scan_start_time).timeInSeconds();
result.basePeakMZ = spectrum->cvParam(MS_base_peak_m_z).valueAs<double>();
result.basePeakIntensity = spectrum->cvParam(MS_base_peak_intensity).valueAs<double>();
result.collisionEnergy = 0;
result.ionisationEnergy = spectrum->cvParam(MS_ionization_energy).valueAs<double>();
result.lowMZ = spectrum->cvParam(MS_lowest_observed_m_z).valueAs<double>();
result.highMZ = spectrum->cvParam(MS_highest_observed_m_z).valueAs<double>();
result.precursorScanNum = 0;
result.precursorMZ = 0;
result.precursorCharge = 0;
result.precursorIntensity = 0;
result.compensationVoltage = 0;
std::string filterLine = scan.cvParam(MS_filter_string).value;
size_t found = filterLine.find("cv=");
if (found!=string::npos) {
filterLine = filterLine.substr(found+3);
found = filterLine.find_first_of(" ");
if (found!=string::npos) {
filterLine = filterLine.substr(0, found);
result.compensationVoltage = atof(filterLine.c_str());
}
}
result.filterLine = filterLine;
if (!spectrum->precursors.empty())
{
const Precursor& precursor = spectrum->precursors[0];
result.collisionEnergy = precursor.activation.cvParam(MS_collision_energy).valueAs<double>();
size_t precursorIndex = msd_.run.spectrumListPtr->find(precursor.spectrumID);
if (precursorIndex < msd_.run.spectrumListPtr->size())
{
const SpectrumIdentity& precursorSpectrum = msd_.run.spectrumListPtr->spectrumIdentity(precursorIndex);
string precursorScanNumber = id::translateNativeIDToScanNumber(nativeIdFormat_, precursorSpectrum.id);
if (precursorScanNumber.empty()) // unsupported nativeID type
{
// assume scanNumber is a 1-based index, consistent with this->index() method
result.precursorScanNum = precursorIndex+1;
}
else
{
result.precursorScanNum = lexical_cast<int>(precursorScanNumber);
}
}
if (!precursor.selectedIons.empty())
{
result.precursorMZ = precursor.selectedIons[0].cvParam(MS_selected_ion_m_z).valueAs<double>();
if (!result.precursorMZ)
{ // mzML 1.0?
result.precursorMZ = precursor.selectedIons[0].cvParam(MS_m_z).valueAs<double>();
}
result.precursorCharge = precursor.selectedIons[0].cvParam(MS_charge_state).valueAs<int>();
result.precursorIntensity = precursor.selectedIons[0].cvParam(MS_peak_intensity).valueAs<double>();
}
}
BOOST_STATIC_ASSERT(SCANTYPE_LENGTH > 4);
memset(result.scanType, 0, SCANTYPE_LENGTH);
strcpy(result.scanType, "Full"); // default
if (spectrum->hasCVParam(MS_zoom_scan))
strcpy(result.scanType, "Zoom");
result.mergedScan = 0; // TODO
result.mergedResultScanNum = 0; // TODO
result.mergedResultStartScanNum = 0; // TODO
result.mergedResultEndScanNum = 0; // TODO
result.filePosition = spectrum->sourceFilePosition;
}
示例13: test
int test()
{
int failedTests = 0;
// create the spectrum list
SpectrumListSimple* sl = new SpectrumListSimple;
SpectrumListPtr originalList(sl);
for (size_t i=0; i < testScanSummerSize; ++i)
{
TestScanSummerCalculator& t = testScanSummerCalculators[i];
SpectrumPtr s(new Spectrum);
s->set(MS_MSn_spectrum);
s->set(MS_ms_level,2);
s->index = i;
s->scanList.scans.push_back(Scan());
Scan& scanRef = s->scanList.scans[0];
scanRef.set(MS_scan_start_time,t.rTime,UO_second);
s->precursors.push_back(Precursor(t.inputPrecursorMZ));
vector<double> inputMZArray = parseDoubleArray(t.inputMZArray);
vector<double> inputIntensityArray = parseDoubleArray(t.inputIntensityArray);
s->setMZIntensityArrays(inputMZArray, inputIntensityArray, MS_number_of_detector_counts);
s->defaultArrayLength = inputMZArray.size();
scanRef.scanWindows.push_back(ScanWindow());
scanRef.scanWindows[0].set(MS_scan_window_lower_limit,inputMZArray[0]);
scanRef.scanWindows[0].set(MS_scan_window_upper_limit,inputMZArray[inputMZArray.size()-1]);
sl->spectra.push_back(s);
}
vector<double> goldMZArray = parseDoubleArray(goldStandard[0].inputMZArray);
vector<double> goldIntensityArray = parseDoubleArray(goldStandard[0].inputIntensityArray);
// run spectral summation
try
{
SpectrumListPtr calculator(new SpectrumList_ScanSummer(originalList,0.05,10));
for (size_t i=0; i < calculator->size(); ++i)
{
SpectrumPtr s = calculator->spectrum(i,true);
vector<double>& mzs = s->getMZArray()->data;
vector<double>& intensities = s->getIntensityArray()->data;
Precursor& precursor = s->precursors[0];
SelectedIon& selectedIon = precursor.selectedIons[0];
double precursorMZ = selectedIon.cvParam(MS_selected_ion_m_z).valueAs<double>();
double rTime = s->scanList.scans[0].cvParam(MS_scan_start_time).timeInSeconds();
vector<double> goldMZArray = parseDoubleArray(goldStandard[i].inputMZArray);
vector<double> goldIntensityArray = parseDoubleArray(goldStandard[i].inputIntensityArray);
unit_assert(mzs.size() == goldMZArray.size());
unit_assert(intensities.size() == goldIntensityArray.size());
unit_assert(precursorMZ == goldStandard[i].inputPrecursorMZ);
unit_assert(rTime == goldStandard[i].rTime);
for (size_t j=0; j < mzs.size(); ++j)
{
unit_assert_equal(mzs[j], goldMZArray[j], 1e-5);
unit_assert_equal(intensities[j], goldIntensityArray[j], 1e-5);
}
}
}
catch (exception& e)
{
cerr << "Test failed:\n" << e.what() << endl;
++failedTests;
}
return failedTests;
}
示例14: lock
PWIZ_API_DECL SpectrumPtr SpectrumList_ABI::spectrum(size_t index, DetailLevel detailLevel, const pwiz::util::IntegerSet& msLevelsToCentroid) const
{
boost::lock_guard<boost::mutex> lock(readMutex); // lock_guard will unlock mutex when out of scope or when exception thrown (during destruction)
boost::call_once(indexInitialized_.flag, boost::bind(&SpectrumList_ABI::createIndex, this));
if (index >= size_)
throw runtime_error("[SpectrumList_ABI::spectrum()] Bad index: " + lexical_cast<string>(index));
// allocate a new Spectrum
IndexEntry& ie = index_[index];
SpectrumPtr result = SpectrumPtr(new Spectrum);
if (!result.get())
throw std::runtime_error("[SpectrumList_ABI::spectrum()] Allocation error.");
result->index = index;
result->id = ie.id;
//Console::WriteLine("spce: {0}.{1}.{2}.{3}", ie.sample, ie.period, ie.cycle, ie.experiment);
result->scanList.set(MS_no_combination);
result->scanList.scans.push_back(Scan());
Scan& scan = result->scanList.scans[0];
ExperimentPtr msExperiment = ie.experiment;
// Synchronize access to cached spectrum for multi-threaded use
pwiz::vendor_api::ABI::SpectrumPtr spectrum;
{
boost::mutex::scoped_lock spectrum_lock(spectrum_mutex);
if (spectrumLastIndex_ != index)
{
spectrumLastIndex_ = index;
spectrumLast_ = wifffile_->getSpectrum(msExperiment, ie.cycle);
}
spectrum = spectrumLast_;
}
double scanTime = spectrum->getStartTime();
if (scanTime > 0)
scan.set(MS_scan_start_time, scanTime, UO_minute);
scan.set(MS_preset_scan_configuration, msExperiment->getExperimentNumber());
ExperimentType experimentType = msExperiment->getExperimentType();
int msLevel = spectrum->getMSLevel();
result->set(MS_ms_level, msLevel);
result->set(translateAsSpectrumType(experimentType));
result->set(translate(msExperiment->getPolarity()));
// CONSIDER: Can anything below here be added to instant?
if (detailLevel == DetailLevel_InstantMetadata)
return result;
// Revert to previous behavior for getting binary data or not.
bool getBinaryData = (detailLevel == DetailLevel_FullData);
double startMz, stopMz;
msExperiment->getAcquisitionMassRange(startMz, stopMz);
scan.scanWindows.push_back(ScanWindow(startMz, stopMz, MS_m_z));
// decide whether to use Points or Peaks to populate data arrays
bool doCentroid = msLevelsToCentroid.contains(msLevel);
bool continuousData = spectrum->getDataIsContinuous();
if (continuousData && !doCentroid)
result->set(MS_profile_spectrum);
else
{
result->set(MS_centroid_spectrum);
doCentroid = continuousData;
}
/*if (experimentType == MRM)
{
MRMTransitions^ transitions = msExperiment->MRMTransitions;
double q1mz = transitions[ie.transition]->Q1Mass;//ie.transition->first;
double q3mz = transitions[ie.transition]->Q3Mass;
double intensity = points[ie.transition]->Y;
result->defaultArrayLength = 1;//ie.transition->second.size();
Precursor precursor;
SelectedIon selectedIon;
selectedIon.set(MS_selected_ion_m_z, q1mz, MS_m_z);
precursor.activation.set(MS_CID); // assume CID
precursor.selectedIons.push_back(selectedIon);
result->precursors.push_back(precursor);
if (getBinaryData)
{
mzArray.resize(result->defaultArrayLength, q3mz);
intensityArray.resize(result->defaultArrayLength, intensity);
}
}
else*/
{
if (spectrum->getHasPrecursorInfo())
{
//.........这里部分代码省略.........
示例15: test
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);
//.........这里部分代码省略.........