ProteoWizard
TextWriter.hpp
Go to the documentation of this file.
1//
2// $Id$
3//
4//
5// Original author: Matt Chambers <matt.chambers .@. vanderbilt.edu>
6//
7// Copyright 2009 Vanderbilt University - Nashville, TN 37232
8//
9// Licensed under the Apache License, Version 2.0 (the "License");
10// you may not use this file except in compliance with the License.
11// You may obtain a copy of the License at
12//
13// http://www.apache.org/licenses/LICENSE-2.0
14//
15// Unless required by applicable law or agreed to in writing, software
16// distributed under the License is distributed on an "AS IS" BASIS,
17// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18// See the License for the specific language governing permissions and
19// limitations under the License.
20//
21
22
23#ifndef _TRADATA_TEXTWRITER_HPP_
24#define _TRADATA_TEXTWRITER_HPP_
25
26
28#include "TraData.hpp"
29#include "boost/lexical_cast.hpp"
30#include <iostream>
31#include <string>
32#include <vector>
33
34
35namespace pwiz {
36namespace tradata {
37
38
40using std::string;
41
42
44{
45 public:
46
47 TextWriter(std::ostream& os, int depth = 0)
48 : os_(os), depth_(depth), indent_(depth*2, ' ')
49 {}
50
51 TextWriter child() {return TextWriter(os_, depth_+1);}
52
53 TextWriter& operator()(const std::string& text)
54 {
55 os_ << indent_ << text << std::endl;
56 return *this;
57 }
58
59 TextWriter& operator()(const CVParam& cvParam)
60 {
61 os_ << indent_ << "cvParam: " << cvTermInfo(cvParam.cvid).name;
62 if (!cvParam.value.empty())
63 os_ << ", " << cvParam.value;
64 if (cvParam.units != CVID_Unknown)
65 os_ << ", " << cvParam.unitsName();
66 os_ << std::endl;
67 return *this;
68 }
69
70 TextWriter& operator()(const UserParam& userParam)
71 {
72 os_ << indent_ << "userParam: " << userParam.name;
73 if (!userParam.value.empty()) os_ << ", " << userParam.value;
74 if (!userParam.type.empty()) os_ << ", " << userParam.type;
75 if (userParam.units != CVID_Unknown) os_ << ", " << cvTermInfo(userParam.units).name;
76 os_ << std::endl;
77 return *this;
78 }
79
80 template<typename object_type>
81 TextWriter& operator()(const std::string& label, const std::vector<object_type>& v)
82 {
83 (*this)(label);
84 for_each(v.begin(), v.end(), child());
85 return *this;
86 }
87
88 template<typename object_type>
89 TextWriter& operator()(const std::string& label, const object_type& v)
90 {
91 (*this)(label)(boost::lexical_cast<std::string>(v));
92 return *this;
93 }
94
95
97 {
98 (*this)("tradata:");
99 child()("version: " + msd.version());
100 if (!msd.cvs.empty())
101 child()("cvList: ", msd.cvs);
102 if (!msd.contactPtrs.empty())
103 child()("contactList: ", msd.contactPtrs);
104 if (!msd.publications.empty())
105 child()("publicationList: ", msd.publications);
106 if (!msd.instrumentPtrs.empty())
107 child()("instrumentList: ", msd.instrumentPtrs);
108 if (!msd.softwarePtrs.empty())
109 child()("softwareList: ", msd.softwarePtrs);
110 if (!msd.proteinPtrs.empty())
111 child()("proteinList: ", msd.proteinPtrs);
112 if (!msd.peptidePtrs.empty())
113 child()("peptideList: ", msd.peptidePtrs);
114 if (!msd.compoundPtrs.empty())
115 child()("compoundList: ", msd.compoundPtrs);
116 if (!msd.transitions.empty())
117 child()("transitionList: ", msd.transitions);
118 if (!msd.targets.empty())
119 child()(msd.targets);
120
121 return *this;
122 }
123
125 {
126 (*this)("cv:");
127 child()
128 ("id: " + cv.id)
129 ("fullName: " + cv.fullName)
130 ("version: " + cv.version)
131 ("URI: " + cv.URI);
132 return *this;
133 }
134
135 TextWriter& operator()(const ParamContainer& paramContainer)
136 {
137 for_each(paramContainer.cvParams.begin(), paramContainer.cvParams.end(), *this);
138 for_each(paramContainer.userParams.begin(), paramContainer.userParams.end(), *this);
139 return *this;
140 }
141
142 TextWriter& operator()(const Publication& publication)
143 {
144 (*this)("publication:");
145 child()
146 ("id: " + publication.id)
147 (static_cast<const ParamContainer&>(publication));
148 return *this;
149 }
150
152 {
153 (*this)("software:");
154 child()
155 ("id: " + software.id)
156 ("version: " + software.version)
157 (static_cast<const ParamContainer&>(software));
158 return *this;
159 }
160
162 {
163 (*this)("contact:");
164 child()(static_cast<const ParamContainer&>(contact));
165 return *this;
166 }
167
168 TextWriter& operator()(const RetentionTime& retentionTime)
169 {
170 (*this)("retentionTime:");
171 child()(static_cast<const ParamContainer&>(retentionTime));
172 if (retentionTime.softwarePtr.get() &&
173 !retentionTime.softwarePtr->empty())
174 child()("softwareRef: " + retentionTime.softwarePtr->id);
175 return *this;
176 }
177
178 TextWriter& operator()(const Prediction& prediction)
179 {
180 (*this)("prediction:");
181 child()(static_cast<const ParamContainer&>(prediction));
182 return *this;
183 }
184
186 {
187 (*this)("evidence:");
188 child()(static_cast<const ParamContainer&>(evidence));
189 return *this;
190 }
191
192 TextWriter& operator()(const Validation& validation)
193 {
194 (*this)("validation:");
195 child()(static_cast<const ParamContainer&>(validation));
196 return *this;
197 }
198
200 {
201 (*this)("protein:");
202 child()("id: " + protein.id)
203 ("sequence: " + protein.sequence);
204 child()(static_cast<const ParamContainer&>(protein));
205 return *this;
206 }
207
208 TextWriter& operator()(const Modification& modification)
209 {
210 (*this)("modification:");
211 child()("location: ", lexical_cast<string>(modification.location))
212 ("monoisotopicMassDelta: " + lexical_cast<string>(modification.monoisotopicMassDelta))
213 ("averageMassDelta: " + lexical_cast<string>(modification.averageMassDelta));
214 child()(static_cast<const ParamContainer&>(modification));
215 return *this;
216 }
217
219 {
220 (*this)("peptide:");
221 child()("id: " + peptide.id)
222 ("sequence: " + peptide.sequence)
223 (peptide.evidence);
224
225 if (!peptide.proteinPtrs.empty())
226 child()("proteinRefs:", peptide.proteinPtrs);
227 if (!peptide.modifications.empty())
228 child()("modifications:", peptide.modifications);
229 if (!peptide.retentionTimes.empty())
230 child()("retentionTimes:", peptide.retentionTimes);
231
232 child()(static_cast<const ParamContainer&>(peptide));
233 return *this;
234 }
235
237 {
238 (*this)("compound:");
239 child()("id: " + compound.id)
240 ("retentionTimes:", compound.retentionTimes);
241 child()(static_cast<const ParamContainer&>(compound));
242 return *this;
243 }
244
245 TextWriter& operator()(const Precursor& precursor)
246 {
247 (*this)("precursor:");
248 child()(static_cast<const ParamContainer&>(precursor));
249 return *this;
250 }
251
253 {
254 (*this)("product:");
255 child()(static_cast<const ParamContainer&>(product));
256 return *this;
257 }
258
259 TextWriter& operator()(const Transition& transition)
260 {
261 (*this)("transition:");
262 child()("id: ", transition.id);
263 if (!transition.precursor.empty())
264 child()(transition.precursor);
265 if (!transition.product.empty())
266 child()(transition.product);
267 if (!transition.prediction.empty())
268 child()(transition.prediction);
269 if (!transition.interpretationList.empty())
270 child()("interpretationList: ", transition.interpretationList);
271 if (!transition.configurationList.empty())
272 child()("configurationList: ", transition.configurationList);
273 if (transition.peptidePtr.get() && !transition.peptidePtr->empty())
274 child()("peptideRef: " + transition.peptidePtr->id);
275 if (transition.compoundPtr.get() && !transition.compoundPtr->empty())
276 child()("compoundRef: " + transition.compoundPtr->id);
277 return *this;
278 }
279
281 {
282 (*this)("target:");
283 child()("id: ", target.id);
284 if (!target.precursor.empty())
285 child()(target.precursor);
286 if (!target.configurationList.empty())
287 child()("configurationList: ", target.configurationList);
288 if (target.peptidePtr.get() && !target.peptidePtr->empty())
289 child()("peptideRef: " + target.peptidePtr->id);
290 if (target.compoundPtr.get() && !target.compoundPtr->empty())
291 child()("compoundRef: " + target.compoundPtr->id);
292 return *this;
293 }
294
295 TextWriter& operator()(const TargetList& targetList)
296 {
297 (*this)("targetList:");
298 child()(static_cast<const ParamContainer&>(targetList));
299 if (!targetList.targetExcludeList.empty())
300 child()("targetExcludeList: ", targetList.targetExcludeList);
301 if (!targetList.targetIncludeList.empty())
302 child()("targetIncludeList: ", targetList.targetIncludeList);
303 return *this;
304 }
305
306 // if no other overload matches, assume the object is a shared_ptr of a valid overloaded type
307 template<typename object_type>
308 TextWriter& operator()(const boost::shared_ptr<object_type>& p)
309 {
310 return p.get() ? (*this)(*p) : *this;
311 }
312
313 private:
314 std::ostream& os_;
316 std::string indent_;
317};
318
319
320} // namespace tradata
321} // namespace pwiz
322
323
324#endif // _TRADATA_TEXTWRITER_HPP_
325
#define PWIZ_API_DECL
Definition Export.hpp:32
represents a post-translational modification (PTM) modification formula or masses must be provided at...
represents a peptide or polypeptide (a sequence of amino acids)
Definition Peptide.hpp:62
const std::string & sequence() const
returns the sequence of amino acids making up the peptide
ModificationMap & modifications()
the map of sequence offsets (0-based) to modifications; modifications can be added or removed from th...
TextWriter & operator()(const boost::shared_ptr< object_type > &p)
TextWriter & operator()(const ParamContainer &paramContainer)
TextWriter & operator()(const TraData &msd)
TextWriter & operator()(const Prediction &prediction)
TextWriter & operator()(const RetentionTime &retentionTime)
TextWriter & operator()(const std::string &label, const object_type &v)
TextWriter & operator()(const Evidence &evidence)
TextWriter & operator()(const std::string &label, const std::vector< object_type > &v)
TextWriter & operator()(const Publication &publication)
TextWriter & operator()(const Protein &protein)
TextWriter & operator()(const Peptide &peptide)
TextWriter & operator()(const Transition &transition)
TextWriter & operator()(const Compound &compound)
TextWriter(std::ostream &os, int depth=0)
TextWriter & operator()(const Product &product)
TextWriter & operator()(const Validation &validation)
TextWriter & operator()(const UserParam &userParam)
TextWriter & operator()(const CV &cv)
TextWriter & operator()(const TargetList &targetList)
TextWriter & operator()(const Precursor &precursor)
TextWriter & operator()(const std::string &text)
TextWriter & operator()(const Modification &modification)
TextWriter & operator()(const Software &software)
TextWriter & operator()(const CVParam &cvParam)
TextWriter & operator()(const Contact &contact)
TextWriter & operator()(const Target &target)
virtual bool empty() const
Returns true if the map is empty, false otherwise.
CVID_Unknown
Definition cv.hpp:114
toType lexical_cast(const std::string &str, bool &success)
PWIZ_API_DECL const CVTermInfo & cvTermInfo(CVID cvid)
returns CV term info for the specified CVID
PWIZ_API_DECL const CV & cv(const std::string &prefix)
returns a CV object for the specified namespace (prefix); currently supported namespaces are: MS UO
Information about an ontology or CV source and a short 'lookup' tag to refer to.
Definition cv.hpp:14916
std::string id
the short label to be used as a reference tag with which to refer to this particular Controlled Vocab...
Definition cv.hpp:14918
std::string fullName
the usual name for the resource (e.g. The PSI-MS Controlled Vocabulary).
Definition cv.hpp:14924
std::string URI
the URI for the resource.
Definition cv.hpp:14921
std::string version
the version of the CV from which the referred-to terms are drawn.
Definition cv.hpp:14927
std::string name
Definition cv.hpp:14947
represents a tag-value pair, where the tag comes from the controlled vocabulary
std::string unitsName() const
convenience function to return string for the units
The base class for elements that may contain cvParams, userParams, or paramGroup references.
std::vector< CVParam > cvParams
a collection of controlled vocabulary terms
std::vector< UserParam > userParams
a collection of uncontrolled user terms
Uncontrolled user parameters (essentially allowing free text). Before using these,...
CVID units
an optional CV parameter for the unit term associated with the value, if any (e.g....
std::string value
the value for the parameter, where appropriate.
std::string name
the name for the parameter.
std::string type
the datatype of the parameter, where appropriate (e.g.: xsd:float).
Chemical compound other than a peptide for which one or more transitions.
Definition TraData.hpp:241
std::vector< RetentionTime > retentionTimes
List of retention time information entries.
Definition TraData.hpp:246
std::string id
Identifier for the compound to be used for referencing within a document.
Definition TraData.hpp:243
Information about empirical mass spectrometer observations of the peptide.
Definition TraData.hpp:117
Precursor (Q1) of the transition.
Definition TraData.hpp:259
bool empty() const
returns true iff contains no params
Information about a prediction for a suitable transition using some software.
Definition TraData.hpp:103
bool empty() const
returns true iff all members are empty and contain no params
Product (Q3) of the transition.
Definition TraData.hpp:267
bool empty() const
returns true iff contains no params
std::string id
Identifier for the publication to be used for referencing within a document.
Definition TraData.hpp:63
SoftwarePtr softwarePtr
Software used to determine the retention time.
Definition TraData.hpp:94
std::string id
Identifier for the software to be used for referencing within a document.
Definition TraData.hpp:73
std::string version
Version of the software program described.
Definition TraData.hpp:76
A peptide or compound that is to be included or excluded from a target list of precursor m/z values.
Definition TraData.hpp:309
PeptidePtr peptidePtr
Reference to a peptide for which this target is the trigger.
Definition TraData.hpp:314
std::string id
String label for this target.
Definition TraData.hpp:311
Precursor precursor
Precursor (Q1) of the target.
Definition TraData.hpp:320
CompoundPtr compoundPtr
Reference to a compound for which this target is the trigger.
Definition TraData.hpp:317
std::vector< Configuration > configurationList
List of instrument configurations used in the validation or optimization of the target.
Definition TraData.hpp:326
List of precursor m/z targets to include or exclude.
Definition TraData.hpp:335
std::vector< Target > targetExcludeList
List of precursor m/z targets to exclude.
Definition TraData.hpp:337
std::vector< Target > targetIncludeList
List of precursor m/z targets to include.
Definition TraData.hpp:340
bool empty() const
returns true iff all members are empty and contain no params
std::vector< CV > cvs
List of controlled vocabularies used in a TraML document note: one of the <cv> elements in this list ...
Definition TraData.hpp:357
std::vector< ContactPtr > contactPtrs
List of contacts referenced in the generation or validation of transitions.
Definition TraData.hpp:360
std::vector< InstrumentPtr > instrumentPtrs
List of instruments on which transitions are validated.
Definition TraData.hpp:366
std::vector< Publication > publications
List of publications from which the transitions were collected or wherein they are published.
Definition TraData.hpp:363
std::vector< ProteinPtr > proteinPtrs
List of proteins for which one or more transitions are intended to identify.
Definition TraData.hpp:372
const std::string & version() const
returns the version of this traML document; for a document created programmatically,...
std::vector< CompoundPtr > compoundPtrs
Definition TraData.hpp:376
TargetList targets
List of precursor m/z targets to include or exclude.
Definition TraData.hpp:382
std::vector< PeptidePtr > peptidePtrs
List of compounds (including peptides) for which one or more transitions are intended to identify.
Definition TraData.hpp:375
std::vector< SoftwarePtr > softwarePtrs
List of software packages used in the generation of one of more transitions described in the document...
Definition TraData.hpp:369
std::vector< Transition > transitions
List of transitions.
Definition TraData.hpp:379
PeptidePtr peptidePtr
Reference to a peptide which this transition is intended to identify.
Definition TraData.hpp:279
Prediction prediction
Information about a prediction for a suitable transition using some software.
Definition TraData.hpp:291
Product product
Product (Q3) of the transition.
Definition TraData.hpp:288
Precursor precursor
Precursor (Q1) of the transition.
Definition TraData.hpp:285
std::string id
String label for this transition.
Definition TraData.hpp:276
std::vector< Interpretation > interpretationList
List of possible interprations of fragment ions for a transition.
Definition TraData.hpp:297
CompoundPtr compoundPtr
Reference to a compound for this transition.
Definition TraData.hpp:282
std::vector< Configuration > configurationList
List of insutrument configurations used in the validation or optimization of the transitions.
Definition TraData.hpp:300
Information about the state of validation of a transition on a given instrument model.
Definition TraData.hpp:125