From: Matt C. <mat...@gm...> - 2012-11-15 16:19:16
|
Hi Witold, Is this pseudocode? A default-constructed MSData document will have a default-constructed spectrumListPtr, which get() will always return NULL for. The compile error is because SpectrumIterator returns cached spectra by const-reference. If you want a copy of the actual SpectrumPtr, you need to use the sl->spectrum() method. But to make changes to a SpectrumList, you need to use the in-memory SpectrumListSimple or define your own SpectrumList subclass. Basically avoid SpectrumIterator entirely and add new spectra to a SpectrumListSimple instead of trying to modify existing spectra. All you need to know is in: pwiz\data\msdata\examples.cpp (initializeTiny()) BTW MS_Th is not an intensity unit, but pwiz doesn't do semantic validation so it won't throw an error on it. :) Hope this helps, -Matt On 11/15/2012 3:41 AM, Witold E Wolski wrote: > Hi, > > I would like to know how to change spectrum content in a MSData object and than to serialise it. > > What I have tried is something on this line (but it does not work). > > - get spectrumListPtr > - iterate over spectrumList > - call setMZIntensityArrays on the iterator > > pwiz::msdata::MSData msd; > pwiz::msdata::SpectrumListPtr sl = msd.run.spectrumListPtr; > if (sl.get()) > { > std::cout << "# of spectra: " << sl->size() << std::endl; > pwiz::msdata::SpectrumIterator it(*sl); > pwiz::msdata::SpectrumIterator end; > std::vector<double> mz(500,1.),intens(500,10.); > int i=0; > for(; it !=end ; ++it, ++i){ > std::cout << i << std::endl; > it->setMZIntensityArrays(mz,intens,pwiz::cv::MS_Th); // compilation error: passing ‘const > pwiz::msdata::Spectrum’ as ‘this’ argument of ‘void pwiz:: ... > } > } > pwiz::msdata::MSDataFile::write(msd, filenameOut, pwiz::msdata::MSDataFile::Format_mzXML); // > uncomment if you want mzXML > > > Can anyone point me to example code how to do it properly. > > Thx > Witold |