ProteoWizard
Reader.hpp
Go to the documentation of this file.
1 //
2 // $Id: Reader.hpp 8904 2015-09-29 19:20:14Z chambm $
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 
28 #include "MSData.hpp"
29 #include <string>
30 #include <stdexcept>
31 
32 
33 namespace pwiz {
34 namespace msdata {
35 
36 /// interface for file readers
38 {
39  public:
40 
41 
42  /// Reader configuration
44  {
45  /// when true, sets certain vendor readers to produce SIM/SRM transitions as spectra instead of chromatograms
48 
49  /// when true, allows for skipping 0 length checks (and thus skip re-reading data for ABI)
51 
52  /// when true, all drift bins/scans in a frame/block are written in combined form instead of as individual spectra
54 
55  /// when true, if a reader cannot identify an instrument, an exception will be thrown asking users to report it
57 
58  /// 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;
59  /// when false, the reader will treat times with unknown time zone as UTC
61 
62  Config();
63  Config(const Config& rhs);
64  };
65 
66 
67  /// return true iff Reader recognizes the file as one it should handle
68  /// that's not to say one it CAN handle, necessarily, as in Thermo on linux,
69  /// see comment for identify() below
70  bool accept(const std::string& filename,
71  const std::string& head) const
72  {
73  return (identify(filename,head).length() != 0);
74  }
75 
76  /// return file type iff Reader recognizes the file, else empty;
77  /// note: for formats requiring a 3rd party DLL identify() should
78  /// return non-empty if it recognized the format, even though reading
79  /// may fail if the 3rd party DLL isn't actually present
80  /// Reader may filter based on filename and/or head of the file
81  virtual std::string identify(const std::string& filename,
82  const std::string& head) const = 0;
83 
84  /// fill in the MSData structure from the first (or only) sample
85  virtual void read(const std::string& filename,
86  const std::string& head,
87  MSData& result,
88  int runIndex = 0,
89  const Config& config = Config()) const = 0;
90 
91  /// fill in a vector of MSData structures; provides support for multi-run input files
92  virtual void read(const std::string& filename,
93  const std::string& head,
94  std::vector<MSDataPtr>& results,
95  const Config& config = Config()) const = 0;
96 
97  /// fill in a vector of MSData.Id values; provides support for multi-run input files
98  virtual void readIds(const std::string& filename,
99  const std::string& head,
100  std::vector<std::string>& dataIds,
101  const Config& config = Config()) const;
102 
103  /// returns a unique string identifying the reader type
104  virtual const char* getType() const = 0;
105 
106  virtual ~Reader(){}
107 };
108 
109 class PWIZ_API_DECL ReaderFail : public std::runtime_error // reader failure exception
110 {
111  public:
112 
113  ReaderFail(const std::string& error)
114  : std::runtime_error(("[ReaderFail] " + error).c_str()),
115  error_(error)
116  {}
117 
118  virtual const std::string& error() const {return error_;}
119  virtual ~ReaderFail() throw() {}
120 
121  private:
122  std::string error_;
123 };
124 
125 typedef boost::shared_ptr<Reader> ReaderPtr;
126 
127 
128 ///
129 /// Reader container (composite pattern).
130 ///
131 /// The template get<reader_type>() gives access to child Readers by type, to facilitate
132 /// Reader-specific configuration at runtime.
133 ///
135  public std::vector<ReaderPtr>
136 {
137  public:
138 
139  /// returns child name iff some child identifies, else empty string
140  virtual std::string identify(const std::string& filename) const;
141 
142  /// returns child name iff some child identifies, else empty string
143  virtual std::string identify(const std::string& filename,
144  const std::string& head) const;
145 
146  /// delegates to first child that identifies
147  virtual void read(const std::string& filename,
148  MSData& result,
149  int runIndex = 0,
150  const Config& config = Config()) const;
151 
152  /// delegates to first child that identifies
153  virtual void read(const std::string& filename,
154  const std::string& head,
155  MSData& result,
156  int runIndex = 0,
157  const Config& config = Config()) const;
158 
159  /// delegates to first child that identifies;
160  /// provides support for multi-run input files
161  virtual void read(const std::string& filename,
162  std::vector<MSDataPtr>& results,
163  const Config& config = Config()) const;
164 
165  /// delegates to first child that identifies;
166  /// provides support for multi-run input files
167  virtual void read(const std::string& filename,
168  const std::string& head,
169  std::vector<MSDataPtr>& results,
170  const Config& config = Config()) const;
171 
172  /// delegates to first child that identifies;
173  /// provides support for multi-run input files
174  virtual void readIds(const std::string& filename,
175  std::vector<std::string>& results,
176  const Config& config = Config()) const;
177 
178  /// delegates to first child that identifies;
179  /// provides support for multi-run input files
180  virtual void readIds(const std::string& filename,
181  const std::string& head,
182  std::vector<std::string>& results,
183  const Config& config = Config()) const;
184 
185  /// appends all of the rhs operand's Readers to the list
186  ReaderList& operator +=(const ReaderList& rhs);
187 
188  /// appends the rhs Reader to the list
189  ReaderList& operator +=(const ReaderPtr& rhs);
190 
191  /// returns a concatenated list of all the Readers from the lhs and rhs operands
192  ReaderList operator +(const ReaderList& rhs) const;
193 
194  /// returns a concatenated list of all the Readers from the lhs and rhs operands
195  ReaderList operator +(const ReaderPtr& rhs) const;
196 
197  /// returns pointer to Reader of the specified type
198  template <typename reader_type>
199  reader_type* get()
200  {
201  for (iterator it=begin(); it!=end(); ++it)
202  {
203  reader_type* p = dynamic_cast<reader_type*>(it->get());
204  if (p) return p;
205  }
206 
207  return 0;
208  }
209 
210  /// returns const pointer to Reader of the specified type
211  template <typename reader_type>
212  const reader_type* get() const
213  {
214  return const_cast<ReaderList*>(this)->get<reader_type>();
215  }
216 
217  virtual const char* getType() const {return "ReaderList";} // satisfy inheritance
218 };
219 
220 
221 /// returns a list containing the lhs and rhs as readers
222 PWIZ_API_DECL ReaderList operator +(const ReaderPtr& lhs, const ReaderPtr& rhs);
223 
224 
225 /// tries to identify a filepath using the provided Reader or ReaderList;
226 /// returns the CVID file format of the specified filepath,
227 /// or CVID_Unknown if the file format has no CV term or the filepath doesn't exist
228 PWIZ_API_DECL CVID identifyFileFormat(const ReaderPtr& reader, const std::string& filepath);
229 
230 
231 } // namespace msdata
232 } // namespace pwiz
233 
234 
235 #endif // _READER_HPP_
236 
ReaderFail(const std::string &error)
Definition: Reader.hpp:113
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:217
STL namespace.
Reader container (composite pattern).
Definition: Reader.hpp:134
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:60
boost::shared_ptr< Reader > ReaderPtr
Definition: Reader.hpp:125
bool acceptZeroLengthSpectra
when true, allows for skipping 0 length checks (and thus skip re-reading data for ABI) ...
Definition: Reader.hpp:50
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:37
virtual const std::string & error() const
Definition: Reader.hpp:118
virtual ~Reader()
Definition: Reader.hpp:106
bool simAsSpectra
when true, sets certain vendor readers to produce SIM/SRM transitions as spectra instead of chromatog...
Definition: Reader.hpp:46
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:70
PWIZ_API_DECL void read(std::istream &is, CV &cv)
PWIZ_API_DECL ReaderList operator+(const ReaderPtr &lhs, const ReaderPtr &rhs)
returns a list containing the lhs and rhs as readers
bool combineIonMobilitySpectra
when true, all drift bins/scans in a frame/block are written in combined form instead of as individua...
Definition: Reader.hpp:53
Reader configuration.
Definition: Reader.hpp:43
This is the root element of ProteoWizard; it represents the mzML element, defined as: intended to cap...
Definition: MSData.hpp:845
bool unknownInstrumentIsError
when true, if a reader cannot identify an instrument, an exception will be thrown asking users to rep...
Definition: Reader.hpp:56