ProteoWizard
MSDataAnalyzer.hpp
Go to the documentation of this file.
1 //
2 // $Id: MSDataAnalyzer.hpp 1191 2009-08-14 19:33:05Z 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 _MSDATAANALYZER_HPP_
25 #define _MSDATAANALYZER_HPP_
26 
27 
30 #include <iosfwd>
31 
32 
33 namespace pwiz {
34 namespace analysis {
35 
36 
37 using namespace msdata;
38 
39 
40 ///
41 /// Interface for MSData analyzers.
42 ///
43 /// MSDataAnalyzer encapsulates a passive update strategy. The MSDataAnalyzer expects to
44 /// handle events generated from an outside driver. This allows the driver to
45 /// control access to the MSData object -- in particular, the driver can ensure
46 /// that scans are read from file only once.
47 ///
48 /// Event sequence:
49 /// - open
50 /// - loop:
51 /// - updateReqested
52 /// - update
53 /// - close
54 ///
55 /// UpdateRequest_Ok handles the following use case: a spectrum cache wants to cache
56 /// only those spectra that are requested by other MSDataAnalyzers; it won't request
57 /// any updates, but it needs to see any update requested by someone else.
58 ///
60 {
61  public:
62 
63  /// information about the data to be analyzed
65  {
66  const MSData& msd;
67  std::string sourceFilename;
68  std::string outputDirectory;
69  std::ostream* log;
70 
71  DataInfo(const MSData& _msd) : msd(_msd), log(0) {}
72  };
73 
74  enum PWIZ_API_DECL UpdateRequest
75  {
76  UpdateRequest_None, // do not update
77  UpdateRequest_Ok, // will accept an update
78  UpdateRequest_NoBinary, // update requested, no binary data needed
79  UpdateRequest_Full // update requested, with binary data
80  };
81 
82  /// \name Event Handling
83  //@{
84 
85  /// start analysis of the data
86  virtual void open(const DataInfo& dataInfo) {}
87 
88  /// ask analyzer if it wants an update
89  virtual UpdateRequest updateRequested(const DataInfo& dataInfo,
90  const SpectrumIdentity& spectrumIdentity) const
91  {
92  return UpdateRequest_None;
93  }
94 
95  /// analyze a single spectrum
96  virtual void update(const DataInfo& dataInfo,
97  const Spectrum& spectrum) {}
98 
99  /// end analysis of the data
100  virtual void close(const DataInfo& dataInfo) {}
101  //@}
102 
103  virtual ~MSDataAnalyzer() {}
104 };
105 
106 
107 typedef boost::shared_ptr<MSDataAnalyzer> MSDataAnalyzerPtr;
108 
109 
110 /// This auxilliary class should be specialized for MSDataAnalyzers
111 /// whose instantiation is controlled by user-supplied strings
112 /// (via command line, config file, etc.).
113 template <typename analyzer_type>
115 {
116  /// string identifier for the analyzer
117  static const char* id() {return "analyzer_traits not specialized";}
118 
119  /// description of the analyzer
120  static const char* description() {return typeid(analyzer_type).name();}
121 
122  /// format of args string
123  static const char* argsFormat() {return "";}
124 
125  /// description of args string options
126  static std::vector<std::string> argsUsage() {return std::vector<std::string>();}
127 };
128 
129 
130 ///
131 /// container of MSDataAnalyzer (composite pattern)
132 ///
134  public std::vector<MSDataAnalyzerPtr>
135 {
136  public:
137 
138  /// \name MSDataAnalyzer interface
139  //@{
140  virtual void open(const DataInfo& dataInfo);
141 
142  virtual UpdateRequest updateRequested(const DataInfo& dataInfo,
143  const SpectrumIdentity& spectrumIdentity) const;
144 
145  virtual void update(const DataInfo& dataInfo,
146  const Spectrum& spectrum);
147 
148  virtual void close(const DataInfo& dataInfo);
149  //@}
150 };
151 
152 
153 ///
154 /// event generator for MSDataAnalyzer
155 ///
157 {
158  public:
159 
160  /// instantiate with an MSDataAnalyzer
162 
163  enum PWIZ_API_DECL Status {Status_Ok, Status_Cancel};
164 
165  /// progress callback interface
167  {
168  public:
169  virtual size_t iterationsPerCallback() const {return 100;}
170  virtual Status progress(size_t index, size_t size) {return Status_Ok;}
171  virtual ~ProgressCallback(){}
172  };
173 
174  ///
175  /// analyze a single MSData object, calling back to client if requested
176  ///
177  /// If progressCallback->progress() returns Status_Cancel, analysis
178  /// is canceled and Status_Cancel is returned.
179  ///
180  Status analyze(const MSDataAnalyzer::DataInfo& dataInfo,
181  ProgressCallback* progressCallback = 0) const;
182 
183  private:
185 };
186 
187 
188 } // namespace analysis
189 } // namespace pwiz
190 
191 
192 #endif // _MSDATAANALYZER_HPP_
193