ProteoWizard
Reader.hpp
Go to the documentation of this file.
1 //
2 // $Id$
3 //
4 //
5 // Original author: Darren Kessner <darren@proteowizard.org>
6 //
7 // Copyright 2008 Spielberg Family Center for Applied Proteomics
8 // Cedars-Sinai Medical Center, Los Angeles, California 90048
9 //
10 // Licensed under the Apache License, Version 2.0 (the "License");
11 // you may not use this file except in compliance with the License.
12 // You may obtain a copy of the License at
13 //
14 // http://www.apache.org/licenses/LICENSE-2.0
15 //
16 // Unless required by applicable law or agreed to in writing, software
17 // distributed under the License is distributed on an "AS IS" BASIS,
18 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 // See the License for the specific language governing permissions and
20 // limitations under the License.
21 //
22 
23 
24 #ifndef _READER_HPP_
25 #define _READER_HPP_
26 
29 #include "MSData.hpp"
30 #include <string>
31 #include <stdexcept>
32 
33 
34 namespace pwiz {
35 namespace msdata {
36 
37 /// interface for file readers
39 {
40  public:
41 
42 
43  /// Reader configuration
45  {
46  /// when true, sets certain vendor readers to produce SIM transitions as spectra instead of chromatograms
48 
49  /// when true, sets certain vendor readers to produce SRM transitions as spectra instead of chromatograms
51 
52  /// when true, allows for skipping 0 length checks (and thus skip re-reading data for Sciex)
54 
55  /// when true, allows certain vendor readers to produce profile data without zero intensity samples flanking each peak profile
57 
58  /// when true, all drift bins/scans in a frame/block are written in combined form instead of as individual spectra
60 
61  /// when true, if a reader cannot identify an instrument, an exception will be thrown asking users to report it
63 
64  /// when true, if a reader does not know what time zone was used to record a time, it will assume the time refers to the host's local time;
65  /// when false, the reader will treat times with unknown time zone as UTC
67 
68  /// progress listener for when initializing a file takes a long time,
69  /// or the reader has to run a long process before continuing,
70  /// such as centroiding all spectra at once instead of one at a time
72 
73  /// when nonzero, if reader can enumerate only spectra of ms level, it will (currently only supported by Bruker TDF)
75 
76  Config();
77  Config(const Config& rhs);
78  };
79 
80 
81  /// return true iff Reader recognizes the file as one it should handle
82  /// that's not to say one it CAN handle, necessarily, as in Thermo on linux,
83  /// see comment for identify() below
84  bool accept(const std::string& filename,
85  const std::string& head) const
86  {
87  return (identify(filename,head).length() != 0);
88  }
89 
90  /// return file type iff Reader recognizes the file, else empty;
91  /// note: for formats requiring a 3rd party DLL identify() should
92  /// return non-empty if it recognized the format, even though reading
93  /// may fail if the 3rd party DLL isn't actually present
94  /// Reader may filter based on filename and/or head of the file
95  virtual std::string identify(const std::string& filename,
96  const std::string& head) const = 0;
97 
98  /// fill in the MSData structure from the first (or only) sample
99  virtual void read(const std::string& filename,
100  const std::string& head,
101  MSData& result,
102  int runIndex = 0,
103  const Config& config = Config()) const = 0;
104 
105  /// fill in a vector of MSData structures; provides support for multi-run input files
106  virtual void read(const std::string& filename,
107  const std::string& head,
108  std::vector<MSDataPtr>& results,
109  const Config& config = Config()) const = 0;
110 
111  /// fill in a vector of MSData.Id values; provides support for multi-run input files
112  virtual void readIds(const std::string& filename,
113  const std::string& head,
114  std::vector<std::string>& dataIds,
115  const Config& config = Config()) const;
116 
117  /// returns a unique string identifying the reader type
118  virtual const char* getType() const = 0;
119 
120  virtual ~Reader(){}
121 };
122 
123 class PWIZ_API_DECL ReaderFail : public std::runtime_error // reader failure exception
124 {
125  public:
126 
127  ReaderFail(const std::string& error)
128  : std::runtime_error(("[ReaderFail] " + error).c_str()),
129  error_(error)
130  {}
131 
132  virtual const std::string& error() const {return error_;}
133  virtual ~ReaderFail() throw() {}
134 
135  private:
136  std::string error_;
137 };
138 
139 typedef boost::shared_ptr<Reader> ReaderPtr;
140 
141 
142 ///
143 /// Reader container (composite pattern).
144 ///
145 /// The template get<reader_type>() gives access to child Readers by type, to facilitate
146 /// Reader-specific configuration at runtime.
147 ///
149  public std::vector<ReaderPtr>
150 {
151  public:
152 
153  /// returns child name iff some child identifies, else empty string
154  virtual std::string identify(const std::string& filename) const;
155 
156  /// returns child name iff some child identifies, else empty string
157  virtual std::string identify(const std::string& filename,
158  const std::string& head) const;
159 
160  /// delegates to first child that identifies
161  virtual void read(const std::string& filename,
162  MSData& result,
163  int runIndex = 0,
164  const Config& config = Config()) const;
165 
166  /// delegates to first child that identifies
167  virtual void read(const std::string& filename,
168  const std::string& head,
169  MSData& result,
170  int runIndex = 0,
171  const Config& config = Config()) const;
172 
173  /// delegates to first child that identifies;
174  /// provides support for multi-run input files
175  virtual void read(const std::string& filename,
176  std::vector<MSDataPtr>& results,
177  const Config& config = Config()) const;
178 
179  /// delegates to first child that identifies;
180  /// provides support for multi-run input files
181  virtual void read(const std::string& filename,
182  const std::string& head,
183  std::vector<MSDataPtr>& results,
184  const Config& config = Config()) const;
185 
186  /// delegates to first child that identifies;
187  /// provides support for multi-run input files
188  virtual void readIds(const std::string& filename,
189  std::vector<std::string>& results,
190  const Config& config = Config()) const;
191 
192  /// delegates to first child that identifies;
193  /// provides support for multi-run input files
194  virtual void readIds(const std::string& filename,
195  const std::string& head,
196  std::vector<std::string>& results,
197  const Config& config = Config()) const;
198 
199  /// appends all of the rhs operand's Readers to the list
200  ReaderList& operator +=(const ReaderList& rhs);
201 
202  /// appends the rhs Reader to the list
203  ReaderList& operator +=(const ReaderPtr& rhs);
204 
205  /// returns a concatenated list of all the Readers from the lhs and rhs operands
206  ReaderList operator +(const ReaderList& rhs) const;
207 
208  /// returns a concatenated list of all the Readers from the lhs and rhs operands
209  ReaderList operator +(const ReaderPtr& rhs) const;
210 
211  /// returns pointer to Reader of the specified type
212  template <typename reader_type>
213  reader_type* get()
214  {
215  for (iterator it=begin(); it!=end(); ++it)
216  {
217  reader_type* p = dynamic_cast<reader_type*>(it->get());
218  if (p) return p;
219  }
220 
221  return 0;
222  }
223 
224  /// returns const pointer to Reader of the specified type
225  template <typename reader_type>
226  const reader_type* get() const
227  {
228  return const_cast<ReaderList*>(this)->get<reader_type>();
229  }
230 
231  virtual const char* getType() const {return "ReaderList";} // satisfy inheritance
232 };
233 
234 
235 /// returns a list containing the lhs and rhs as readers
236 PWIZ_API_DECL ReaderList operator +(const ReaderPtr& lhs, const ReaderPtr& rhs);
237 
238 
239 /// tries to identify a filepath using the provided Reader or ReaderList;
240 /// returns the CVID file format of the specified filepath,
241 /// or CVID_Unknown if the file format has no CV term or the filepath doesn't exist
242 PWIZ_API_DECL CVID identifyFileFormat(const ReaderPtr& reader, const std::string& filepath);
243 
244 
245 } // namespace msdata
246 } // namespace pwiz
247 
248 
249 #endif // _READER_HPP_
250 
ReaderFail(const std::string &error)
Definition: Reader.hpp:127
bool ignoreZeroIntensityPoints
when true, allows certain vendor readers to produce profile data without zero intensity samples flank...
Definition: Reader.hpp:56
PWIZ_API_DECL double & operator+=(double &d, const MZTolerance &tolerance)
virtual const char * getType() const
returns a unique string identifying the reader type
Definition: Reader.hpp:231
STL namespace.
Reader container (composite pattern).
Definition: Reader.hpp:148
bool adjustUnknownTimeZonesToHostTimeZone
when true, if a reader does not know what time zone was used to record a time, it will assume the tim...
Definition: Reader.hpp:66
boost::shared_ptr< Reader > ReaderPtr
Definition: Reader.hpp:139
bool acceptZeroLengthSpectra
when true, allows for skipping 0 length checks (and thus skip re-reading data for Sciex) ...
Definition: Reader.hpp:53
PWIZ_API_DECL CVID identifyFileFormat(const ReaderPtr &reader, const std::string &filepath)
tries to identify a filepath using the provided Reader or ReaderList; returns the CVID file format of...
#define PWIZ_API_DECL
Definition: Export.hpp:32
interface for file readers
Definition: Reader.hpp:38
virtual const std::string & error() const
Definition: Reader.hpp:132
virtual ~Reader()
Definition: Reader.hpp:120
bool srmAsSpectra
when true, sets certain vendor readers to produce SRM transitions as spectra instead of chromatograms...
Definition: Reader.hpp:50
bool simAsSpectra
when true, sets certain vendor readers to produce SIM transitions as spectra instead of chromatograms...
Definition: Reader.hpp:47
bool accept(const std::string &filename, const std::string &head) const
return true iff Reader recognizes the file as one it should handle
Definition: Reader.hpp:84
PWIZ_API_DECL void read(std::istream &is, CV &cv)
int preferOnlyMsLevel
when nonzero, if reader can enumerate only spectra of ms level, it will (currently only supported by ...
Definition: Reader.hpp:74
PWIZ_API_DECL ReaderList operator+(const ReaderPtr &lhs, const ReaderPtr &rhs)
returns a list containing the lhs and rhs as readers
handles registration of IterationListeners and broadcast of update messages
bool combineIonMobilitySpectra
when true, all drift bins/scans in a frame/block are written in combined form instead of as individua...
Definition: Reader.hpp:59
Reader configuration.
Definition: Reader.hpp:44
pwiz::util::IterationListenerRegistry * iterationListenerRegistry
progress listener for when initializing a file takes a long time, or the reader has to run a long pro...
Definition: Reader.hpp:71
This is the root element of ProteoWizard; it represents the mzML element, defined as: intended to cap...
Definition: MSData.hpp:849
bool unknownInstrumentIsError
when true, if a reader cannot identify an instrument, an exception will be thrown asking users to rep...
Definition: Reader.hpp:62