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 public:
70 
72 
79  OnDiscMSExperiment(const String& filename)
80  {
81  openFile(filename);
82  }
83 
84  bool openFile(const String& filename)
85  {
86  filename_ = filename;
87  indexed_mzml_file_.openFile(filename);
88  if (filename != "")
89  {
90  meta_ms_experiment_ = boost::shared_ptr<MSExperiment<> >(new MSExperiment<>);
91 
92  MzMLFile f;
93  PeakFileOptions options = f.getOptions();
94  options.setFillData(false);
95  f.setOptions(options);
96  f.load(filename, *meta_ms_experiment_.get());
97  }
99  }
100 
103  filename_(source.filename_),
106  {
107  }
108 
116  bool operator==(const OnDiscMSExperiment& rhs) const
117  {
118  // check if file and meta information is the same
119  return filename_ == rhs.filename_ &&
120  (*meta_ms_experiment_) == (*rhs.meta_ms_experiment_);
121  // do not check if indexed_mzml_file_ is equal -> they have the same filename...
122  }
123 
125  bool operator!=(const OnDiscMSExperiment& rhs) const
126  {
127  return !(operator==(rhs));
128  }
129 
136  bool isSortedByRT() const
137  {
138  return meta_ms_experiment_->isSorted(false);
139  }
140 
142  inline Size size() const
143  {
144  return getNrSpectra();
145  }
146 
148  inline bool empty() const
149  {
150  return indexed_mzml_file_.getNrSpectra() == 0;
151  }
152 
154  inline Size getNrSpectra() const
155  {
157  }
158 
160  inline Size getNrChromatograms() const
161  {
163  }
164 
166  boost::shared_ptr<const ExperimentalSettings> getExperimentalSettings() const
167  {
168  return boost::static_pointer_cast<const ExperimentalSettings>(meta_ms_experiment_);
169  }
170 
173  {
174  return getSpectrum(n);
175  }
176 
183  {
185  MSSpectrum<PeakT> spectrum(meta_ms_experiment_->operator[](id));
186 
187  // recreate a spectrum from the data arrays!
188  OpenMS::Interfaces::BinaryDataArrayPtr mz_arr = sptr->getMZArray();
189  OpenMS::Interfaces::BinaryDataArrayPtr int_arr = sptr->getIntensityArray();
190  spectrum.reserve(mz_arr->data.size());
191  for (Size i = 0; i < mz_arr->data.size(); i++)
192  {
193  PeakT p;
194  p.setMZ(mz_arr->data[i]);
195  p.setIntensity(int_arr->data[i]);
196  spectrum.push_back(p);
197  }
198  return spectrum;
199  }
200 
205  {
207  }
208 
215  {
217  MSChromatogram<ChromatogramPeakT> chromatogram(meta_ms_experiment_->getChromatogram(id));
218 
219  // recreate a chromatogram from the data arrays!
220  OpenMS::Interfaces::BinaryDataArrayPtr rt_arr = cptr->getTimeArray();
221  OpenMS::Interfaces::BinaryDataArrayPtr int_arr = cptr->getIntensityArray();
222  chromatogram.reserve(rt_arr->data.size());
223  for (Size i = 0; i < rt_arr->data.size(); i++)
224  {
225  ChromatogramPeakT p;
226  p.setRT(rt_arr->data[i]);
227  p.setIntensity(int_arr->data[i]);
228  chromatogram.push_back(p);
229  }
230 
231  return chromatogram;
232  }
233 
238  {
240  }
241 
242 private:
245 
246 protected:
247 
253  boost::shared_ptr<MSExperiment<> > meta_ms_experiment_;
254  };
255 
256 } // namespace OpenMS
257 
258 #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:214
Size getNrChromatograms() const
get the total number of chromatograms available
Definition: OnDiscMSExperiment.h:160
OnDiscMSExperiment(const String &filename)
Constructor.
Definition: OnDiscMSExperiment.h:79
bool operator!=(const OnDiscMSExperiment &rhs) const
Inequality operator.
Definition: OnDiscMSExperiment.h:125
boost::shared_ptr< Chromatogram > ChromatogramPtr
Definition: openms/include/OpenMS/INTERFACES/DataStructures.h:157
A more convenient string class.
Definition: String.h:57
boost::shared_ptr< MSExperiment<> > meta_ms_experiment_
The meta-data.
Definition: OnDiscMSExperiment.h:253
The representation of a chromatogram.
Definition: MSChromatogram.h:52
Size size() const
alias for getNrSpectra
Definition: OnDiscMSExperiment.h:142
boost::shared_ptr< BinaryDataArray > BinaryDataArrayPtr
Definition: openms/include/OpenMS/INTERFACES/DataStructures.h:81
OnDiscMSExperiment & operator=(const OnDiscMSExperiment &)
Private Assignment operator -&gt; we cannot copy file streams in IndexedMzMLFile.
Definition: OnDiscMSExperiment.h:244
OpenMS::Interfaces::ChromatogramPtr getChromatogramById(int id)
Retrieve the raw data for the chromatogram at position &quot;id&quot;.
bool isSortedByRT() const
Checks if all spectra are sorted with respect to ascending RT.
Definition: OnDiscMSExperiment.h:136
MSSpectrum< PeakT > operator[](Size n)
alias for getSpectrum
Definition: OnDiscMSExperiment.h:172
void openFile(String filename)
Open a file.
String filename_
The filename of the underlying data file.
Definition: OnDiscMSExperiment.h:249
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:71
bool openFile(const String &filename)
Definition: OnDiscMSExperiment.h:84
A class to read an indexedmzML file.
Definition: IndexedMzMLFile.h:70
OpenMS::Interfaces::SpectrumPtr getSpectrumById(Size id)
returns a single spectrum
Definition: OnDiscMSExperiment.h:204
OpenMS::Interfaces::ChromatogramPtr getChromatogramById(Size id)
returns a single chromatogram
Definition: OnDiscMSExperiment.h:237
boost::shared_ptr< const ExperimentalSettings > getExperimentalSettings() const
returns the meta information of this experiment (const access)
Definition: OnDiscMSExperiment.h:166
bool operator==(const OnDiscMSExperiment &rhs) const
Equality operator.
Definition: OnDiscMSExperiment.h:116
OpenMS::Interfaces::SpectrumPtr getSpectrumById(int id)
Retrieve the raw data for the spectrum at position &quot;id&quot;.
OnDiscMSExperiment(const OnDiscMSExperiment &source)
Copy constructor.
Definition: OnDiscMSExperiment.h:102
MSSpectrum< PeakT > getSpectrum(Size id)
returns a single spectrum
Definition: OnDiscMSExperiment.h:182
Size getNrSpectra() const
get the total number of spectra available
Definition: OnDiscMSExperiment.h:154
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:251
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:148
Description of the experimental settings.
Definition: ExperimentalSettings.h:59
bool getParsingSuccess() const
Returns whether parsing was successful.

OpenMS / TOPP release 2.0.0 Documentation generated on Wed Mar 30 2016 16:18:40 using doxygen 1.8.5