Home  · Classes  · Annotated Classes  · Modules  · Members  · Namespaces  · Related Pages
OnDiscMSExperiment.h
Go to the documentation of this file.
1 // --------------------------------------------------------------------------
2 // OpenMS -- Open-Source Mass Spectrometry
3 // --------------------------------------------------------------------------
4 // Copyright The OpenMS Team -- Eberhard Karls University Tuebingen,
5 // ETH Zurich, and Freie Universitaet Berlin 2002-2015.
6 //
7 // This software is released under a three-clause BSD license:
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 // * Neither the name of any author or any participating institution
14 // may be used to endorse or promote products derived from this software
15 // without specific prior written permission.
16 // For a full list of authors, refer to the file AUTHORS.
17 // --------------------------------------------------------------------------
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 // ARE DISCLAIMED. IN NO EVENT SHALL ANY OF THE AUTHORS OR THE CONTRIBUTING
22 // INSTITUTIONS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 //
30 // --------------------------------------------------------------------------
31 // $Maintainer: Hannes Roest $
32 // $Authors: Hannes Roest $
33 // --------------------------------------------------------------------------
34 
35 #ifndef OPENMS_KERNEL_ONDISCMSEXPERIMENT_H
36 #define OPENMS_KERNEL_ONDISCMSEXPERIMENT_H
37 
39 
45 #include <OpenMS/FORMAT/MzMLFile.h>
46 
47 #include <vector>
48 #include <algorithm>
49 #include <limits>
50 
51 #include <boost/shared_ptr.hpp>
52 
53 namespace OpenMS
54 {
66  template <typename PeakT = Peak1D, typename ChromatogramPeakT = ChromatogramPeak>
68  {
69 
70 public:
71 
73 
80  OnDiscMSExperiment(const String& filename)
81  {
82  openFile(filename);
83  }
84 
85  bool openFile(const String& filename, bool skipMetaData = false)
86  {
87  filename_ = filename;
88  indexed_mzml_file_.openFile(filename);
89  if (filename != "" && !skipMetaData)
90  {
91  loadMetaData_(filename);
92  }
94  }
95 
98  filename_(source.filename_),
101  {
102  }
103 
111  bool operator==(const OnDiscMSExperiment& rhs) const
112  {
113  // check if file and meta information is the same
114  return filename_ == rhs.filename_ &&
115  (*meta_ms_experiment_) == (*rhs.meta_ms_experiment_);
116  // do not check if indexed_mzml_file_ is equal -> they have the same filename...
117  }
118 
120  bool operator!=(const OnDiscMSExperiment& rhs) const
121  {
122  return !(operator==(rhs));
123  }
124 
131  bool isSortedByRT() const
132  {
133  return meta_ms_experiment_->isSorted(false);
134  }
135 
137  inline Size size() const
138  {
139  return getNrSpectra();
140  }
141 
143  inline bool empty() const
144  {
145  return indexed_mzml_file_.getNrSpectra() == 0;
146  }
147 
149  inline Size getNrSpectra() const
150  {
152  }
153 
155  inline Size getNrChromatograms() const
156  {
158  }
159 
161  boost::shared_ptr<const ExperimentalSettings> getExperimentalSettings() const
162  {
163  return boost::static_pointer_cast<const ExperimentalSettings>(meta_ms_experiment_);
164  }
165 
168  {
169  return getSpectrum(n);
170  }
171 
178  {
180  MSSpectrum<PeakT> spectrum(meta_ms_experiment_->operator[](id));
181 
182  // recreate a spectrum from the data arrays!
183  OpenMS::Interfaces::BinaryDataArrayPtr mz_arr = sptr->getMZArray();
184  OpenMS::Interfaces::BinaryDataArrayPtr int_arr = sptr->getIntensityArray();
185  spectrum.reserve(mz_arr->data.size());
186  for (Size i = 0; i < mz_arr->data.size(); i++)
187  {
188  PeakT p;
189  p.setMZ(mz_arr->data[i]);
190  p.setIntensity(int_arr->data[i]);
191  spectrum.push_back(p);
192  }
193  return spectrum;
194  }
195 
200  {
202  }
203 
210  {
212  MSChromatogram<ChromatogramPeakT> chromatogram(meta_ms_experiment_->getChromatogram(id));
213 
214  // recreate a chromatogram from the data arrays!
215  OpenMS::Interfaces::BinaryDataArrayPtr rt_arr = cptr->getTimeArray();
216  OpenMS::Interfaces::BinaryDataArrayPtr int_arr = cptr->getIntensityArray();
217  chromatogram.reserve(rt_arr->data.size());
218  for (Size i = 0; i < rt_arr->data.size(); i++)
219  {
220  ChromatogramPeakT p;
221  p.setRT(rt_arr->data[i]);
222  p.setIntensity(int_arr->data[i]);
223  chromatogram.push_back(p);
224  }
225 
226  return chromatogram;
227  }
228 
233  {
235  }
236 
238  void setSkipXMLChecks(bool skip)
239  {
241  }
242 
243 private:
246 
247  void loadMetaData_(const String& filename)
248  {
249  meta_ms_experiment_ = boost::shared_ptr< MSExperiment<> >(new MSExperiment<>);
250 
251  MzMLFile f;
252  PeakFileOptions options = f.getOptions();
253  options.setFillData(false);
254  f.setOptions(options);
255  f.load(filename, *meta_ms_experiment_.get());
256  }
257 
258 
259 protected:
260 
266  boost::shared_ptr<MSExperiment<> > meta_ms_experiment_;
267  };
268 
269 } // namespace OpenMS
270 
271 #endif // OPENMS_KERNEL_ONDISCMSEXPERIMENT_H
boost::shared_ptr< Spectrum > SpectrumPtr
Definition: openms/include/OpenMS/INTERFACES/DataStructures.h:237
MSChromatogram< ChromatogramPeakT > getChromatogram(Size id)
returns a single chromatogram
Definition: OnDiscMSExperiment.h:209
Size getNrChromatograms() const
get the total number of chromatograms available
Definition: OnDiscMSExperiment.h:155
OnDiscMSExperiment(const String &filename)
Constructor.
Definition: OnDiscMSExperiment.h:80
void setSkipXMLChecks(bool skip)
sets whether to skip some XML checks and be fast instead
Definition: IndexedMzMLFile.h:162
bool operator!=(const OnDiscMSExperiment &rhs) const
Inequality operator.
Definition: OnDiscMSExperiment.h:120
boost::shared_ptr< Chromatogram > ChromatogramPtr
Definition: openms/include/OpenMS/INTERFACES/DataStructures.h:157
A more convenient string class.
Definition: String.h:57
bool openFile(const String &filename, bool skipMetaData=false)
Definition: OnDiscMSExperiment.h:85
boost::shared_ptr< MSExperiment<> > meta_ms_experiment_
The meta-data.
Definition: OnDiscMSExperiment.h:266
The representation of a chromatogram.
Definition: MSChromatogram.h:52
Size size() const
alias for getNrSpectra
Definition: OnDiscMSExperiment.h:137
boost::shared_ptr< BinaryDataArray > BinaryDataArrayPtr
Definition: openms/include/OpenMS/INTERFACES/DataStructures.h:81
OnDiscMSExperiment & operator=(const OnDiscMSExperiment &)
Private Assignment operator -> we cannot copy file streams in IndexedMzMLFile.
Definition: OnDiscMSExperiment.h:245
OpenMS::Interfaces::ChromatogramPtr getChromatogramById(int id)
Retrieve the raw data for the chromatogram at position "id".
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
bool isSortedByRT() const
Checks if all spectra are sorted with respect to ascending RT.
Definition: OnDiscMSExperiment.h:131
MSSpectrum< PeakT > operator[](Size n)
alias for getSpectrum
Definition: OnDiscMSExperiment.h:167
void openFile(String filename)
Open a file.
String filename_
The filename of the underlying data file.
Definition: OnDiscMSExperiment.h:262
size_t getNrChromatograms() const
Returns the number of chromatograms available.
File adapter for MzML files.
Definition: MzMLFile.h:55
Representation of a mass spectrometry experiment on disk.
Definition: OnDiscMSExperiment.h:67
The representation of a 1D spectrum.
Definition: MSSpectrum.h:66
size_t getNrSpectra() const
Returns the number of spectra available.
OnDiscMSExperiment()
Definition: OnDiscMSExperiment.h:72
A class to read an indexedmzML file.
Definition: IndexedMzMLFile.h:70
OpenMS::Interfaces::SpectrumPtr getSpectrumById(Size id)
returns a single spectrum
Definition: OnDiscMSExperiment.h:199
OpenMS::Interfaces::ChromatogramPtr getChromatogramById(Size id)
returns a single chromatogram
Definition: OnDiscMSExperiment.h:232
boost::shared_ptr< const ExperimentalSettings > getExperimentalSettings() const
returns the meta information of this experiment (const access)
Definition: OnDiscMSExperiment.h:161
bool operator==(const OnDiscMSExperiment &rhs) const
Equality operator.
Definition: OnDiscMSExperiment.h:111
OpenMS::Interfaces::SpectrumPtr getSpectrumById(int id)
Retrieve the raw data for the spectrum at position "id".
OnDiscMSExperiment(const OnDiscMSExperiment &source)
Copy constructor.
Definition: OnDiscMSExperiment.h:97
MSSpectrum< PeakT > getSpectrum(Size id)
returns a single spectrum
Definition: OnDiscMSExperiment.h:177
Size getNrSpectra() const
get the total number of spectra available
Definition: OnDiscMSExperiment.h:149
void loadMetaData_(const String &filename)
Definition: OnDiscMSExperiment.h:247
Options for loading files containing peak data.
Definition: PeakFileOptions.h:48
IndexedMzMLFile indexed_mzml_file_
The index of the underlying data file.
Definition: OnDiscMSExperiment.h:264
void setFillData(bool only)
sets whether to fill the actual data into the container (spectrum/chromatogram)
bool empty() const
returns whether spectra are empty
Definition: OnDiscMSExperiment.h:143
Description of the experimental settings.
Definition: ExperimentalSettings.h:59
void setSkipXMLChecks(bool skip)
sets whether to skip some XML checks and be fast instead
Definition: OnDiscMSExperiment.h:238
bool getParsingSuccess() const
Returns whether parsing was successful.

OpenMS / TOPP release 2.0.0 Documentation generated on Tue Aug 25 2015 05:53:50 using doxygen 1.8.9.1