ProteoWizard
TextWriter.hpp
Go to the documentation of this file.
1 //
2 // $Id: TextWriter.hpp 1605 2009-12-09 23:50:27Z chambm $
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 
35 namespace pwiz {
36 namespace tradata {
37 
38 
40 using 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 
151  TextWriter& operator()(const Software& software)
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 
161  TextWriter& operator()(const Contact& contact)
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 
185  TextWriter& operator()(const Evidence& evidence)
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 
199  TextWriter& operator()(const Protein& protein)
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 
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 
236  TextWriter& operator()(const Compound& compound)
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 
252  TextWriter& operator()(const Product& product)
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 
280  TextWriter& operator()(const Target& target)
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_;
315  int depth_;
316  std::string indent_;
317 };
318 
319 
320 } // namespace tradata
321 } // namespace pwiz
322 
323 
324 #endif // _TRADATA_TEXTWRITER_HPP_
325 
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:13356
TextWriter & operator()(const Target &target)
Definition: TextWriter.hpp:280
PWIZ_API_DECL const Modification & modification(CVID cvid)
find a modification by CVID
TextWriter & operator()(const Protein &protein)
Definition: TextWriter.hpp:199
TextWriter & operator()(const UserParam &userParam)
Definition: TextWriter.hpp:70
std::string value
Definition: ParamTypes.hpp:47
virtual bool empty() const
Returns true if the map is empty, false otherwise.
PWIZ_API_DECL const CVTermInfo & cvTermInfo(CVID cvid)
returns CV term info for the specified CVID
TextWriter & operator()(const Software &software)
Definition: TextWriter.hpp:151
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 ...
std::vector< CompoundPtr > compoundPtrs
Definition: TraData.hpp:376
Precursor (Q1) of the transition.
Definition: TraData.hpp:258
TextWriter & operator()(const Publication &publication)
Definition: TextWriter.hpp:142
bool empty() const
returns true iff contains no params
bool empty() const
returns true iff contains no params
ostream * os_
List of precursor m/z targets to include or exclude.
Definition: TraData.hpp:334
bool empty() const
returns true iff all members are empty and contain no params
TextWriter & operator()(const std::string &label, const object_type &v)
Definition: TextWriter.hpp:89
std::string value
the value for the parameter, where appropriate.
Definition: ParamTypes.hpp:191
std::vector< InstrumentPtr > instrumentPtrs
List of instruments on which transitions are validated.
Definition: TraData.hpp:366
PWIZ_API_DECL proteome::Peptide peptide(const Peptide &peptide)
creates a proteome::Peptide from an identdata::Peptide
std::string unitsName() const
convenience function to return string for the units
std::vector< Interpretation > interpretationList
List of possible interprations of fragment ions for a transition.
Definition: TraData.hpp:297
Precursor precursor
Precursor (Q1) of the target.
Definition: TraData.hpp:320
TextWriter & operator()(const Transition &transition)
Definition: TextWriter.hpp:259
std::vector< Target > targetExcludeList
List of precursor m/z targets to exclude.
Definition: TraData.hpp:337
TextWriter & operator()(const std::string &label, const std::vector< object_type > &v)
Definition: TextWriter.hpp:81
Information about the state of validation of a transition on a given instrument model.
Definition: TraData.hpp:124
std::string id
Identifier for the compound to be used for referencing within a document.
Definition: TraData.hpp:243
Information about an ontology or CV source and a short &#39;lookup&#39; tag to refer to.
Definition: cv.hpp:13353
TextWriter & operator()(const Validation &validation)
Definition: TextWriter.hpp:192
Prediction prediction
Information about a prediction for a suitable transition using some software.
Definition: TraData.hpp:291
Information about a prediction for a suitable transition using some software.
Definition: TraData.hpp:102
TargetList targets
List of precursor m/z targets to include or exclude.
Definition: TraData.hpp:382
A peptide or compound that is to be included or excluded from a target list of precursor m/z values...
Definition: TraData.hpp:308
std::string id
String label for this transition.
Definition: TraData.hpp:276
std::string version
Version of the software program described.
Definition: TraData.hpp:76
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
Information about empirical mass spectrometer observations of the peptide.
Definition: TraData.hpp:116
std::string id
Identifier for the software to be used for referencing within a document.
Definition: TraData.hpp:73
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
represents a post-translational modification (PTM) modification formula or masses must be provided at...
TextWriter & operator()(const Peptide &peptide)
Definition: TextWriter.hpp:218
CompoundPtr compoundPtr
Reference to a compound for which this target is the trigger.
Definition: TraData.hpp:317
TextWriter & operator()(const Evidence &evidence)
Definition: TextWriter.hpp:185
TextWriter & operator()(const Contact &contact)
Definition: TextWriter.hpp:161
float lexical_cast(const std::string &str)
Chemical compound other than a peptide for which one or more transitions.
Definition: TraData.hpp:240
std::string fullName
the usual name for the resource (e.g. The PSI-MS Controlled Vocabulary).
Definition: cv.hpp:13362
represents a peptide or polypeptide (a sequence of amino acids)
Definition: Peptide.hpp:61
TextWriter & operator()(const RetentionTime &retentionTime)
Definition: TextWriter.hpp:168
Uncontrolled user parameters (essentially allowing free text). Before using these, one should verify whether there is an appropriate CV term available, and if so, use the CV term instead.
Definition: ParamTypes.hpp:185
TextWriter & operator()(const Product &product)
Definition: TextWriter.hpp:252
TextWriter & operator()(const Modification &modification)
Definition: TextWriter.hpp:208
TextWriter & operator()(const boost::shared_ptr< object_type > &p)
Definition: TextWriter.hpp:308
std::vector< UserParam > userParams
a collection of uncontrolled user terms
Definition: ParamTypes.hpp:253
std::vector< Publication > publications
List of publications from which the transitions were collected or wherein they are published...
Definition: TraData.hpp:363
ModificationMap & modifications()
the map of sequence offsets (0-based) to modifications; modifications can be added or removed from th...
std::string type
the datatype of the parameter, where appropriate (e.g.: xsd:float).
Definition: ParamTypes.hpp:194
TextWriter & operator()(const Compound &compound)
Definition: TextWriter.hpp:236
The base class for elements that may contain cvParams, userParams, or paramGroup references.
Definition: ParamTypes.hpp:244
std::string URI
the URI for the resource.
Definition: cv.hpp:13359
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< CVParam > cvParams
a collection of controlled vocabulary terms
Definition: ParamTypes.hpp:250
TextWriter & operator()(const Prediction &prediction)
Definition: TextWriter.hpp:178
TextWriter & operator()(const CVParam &cvParam)
Definition: TextWriter.hpp:59
Product (Q3) of the transition.
Definition: TraData.hpp:266
Product product
Product (Q3) of the transition.
Definition: TraData.hpp:288
TextWriter & operator()(const ParamContainer &paramContainer)
Definition: TextWriter.hpp:135
PeptidePtr peptidePtr
Reference to a peptide which this transition is intended to identify.
Definition: TraData.hpp:279
#define PWIZ_API_DECL
Definition: Export.hpp:32
std::string name
Definition: cv.hpp:13385
std::string name
the name for the parameter.
Definition: ParamTypes.hpp:188
CompoundPtr compoundPtr
Reference to a compound for this transition.
Definition: TraData.hpp:282
std::vector< Transition > transitions
List of transitions.
Definition: TraData.hpp:379
CVID units
an optional CV parameter for the unit term associated with the value, if any (e.g. MS_electron_volt).
Definition: ParamTypes.hpp:197
std::vector< Configuration > configurationList
List of insutrument configurations used in the validation or optimization of the transitions.
Definition: TraData.hpp:300
bool empty() const
returns true iff all members are empty and contain no params
TextWriter & operator()(const TraData &msd)
Definition: TextWriter.hpp:96
TextWriter(std::ostream &os, int depth=0)
Definition: TextWriter.hpp:47
SoftwarePtr softwarePtr
Software used to determine the retention time.
Definition: TraData.hpp:94
CVID_Unknown
Definition: cv.hpp:97
std::vector< Configuration > configurationList
List of instrument configurations used in the validation or optimization of the target.
Definition: TraData.hpp:326
std::vector< RetentionTime > retentionTimes
List of retention time information entries.
Definition: TraData.hpp:246
Precursor precursor
Precursor (Q1) of the transition.
Definition: TraData.hpp:285
std::vector< PeptidePtr > peptidePtrs
List of compounds (including peptides) for which one or more transitions are intended to identify...
Definition: TraData.hpp:375
TextWriter & operator()(const CV &cv)
Definition: TextWriter.hpp:124
std::vector< Target > targetIncludeList
List of precursor m/z targets to include.
Definition: TraData.hpp:340
const std::string & version() const
returns the version of this traML document; for a document created programmatically, the version is the current release version of traML; for a document created from a file/stream, the version is the schema version read from the file/stream
std::vector< ProteinPtr > proteinPtrs
List of proteins for which one or more transitions are intended to identify.
Definition: TraData.hpp:372
TextWriter & operator()(const TargetList &targetList)
Definition: TextWriter.hpp:295
std::string version
the version of the CV from which the referred-to terms are drawn.
Definition: cv.hpp:13365
TextWriter & operator()(const Precursor &precursor)
Definition: TextWriter.hpp:245
std::string id
Identifier for the publication to be used for referencing within a document.
Definition: TraData.hpp:63
TextWriter & operator()(const std::string &text)
Definition: TextWriter.hpp:53
std::vector< ContactPtr > contactPtrs
List of contacts referenced in the generation or validation of transitions.
Definition: TraData.hpp:360
represents a tag-value pair, where the tag comes from the controlled vocabulary
Definition: ParamTypes.hpp:44
const std::string & sequence() const
returns the sequence of amino acids making up the peptide