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