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