ProteoWizard
TextWriter.hpp
Go to the documentation of this file.
1 //
2 // $Id: TextWriter.hpp 2820 2011-06-27 22:51:16Z chambm $
3 //
4 //
5 // Original author: Robert Burke <robert.burke@proteowizard.org>
6 //
7 // Copyright 2009 Spielberg Family Center for Applied Proteomics
8 // University of Southern California, Los Angeles, California 90033
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 _IDENTDATA_TEXTWRITER_HPP_
25 #define _IDENTDATA_TEXTWRITER_HPP_
26 
27 
30 #include "IdentData.hpp"
31 #include <boost/foreach.hpp>
32 #include <iostream>
33 #include <string>
34 #include <vector>
35 
36 
37 namespace pwiz {
38 namespace identdata {
39 
40 using namespace pwiz::cv;
41 using namespace pwiz::data;
42 using namespace boost::logic;
43 
45 {
46  public:
47 
48  TextWriter(std::ostream& os, int depth = 0)
49  : os_(os), depth_(depth), indent_(depth*2, ' ')
50  {
51  os_.precision(14);
52  }
53 
54 
55  TextWriter child() {return TextWriter(os_, depth_+1);}
56 
57 
58  TextWriter& operator()(const std::string& text)
59  {
60  os_ << indent_ << text << std::endl;
61  return *this;
62  }
63 
64 
65  TextWriter& operator()(const float value)
66  {
67  os_ << indent_ << value << std::endl;
68  return *this;
69  }
70 
71 
72  TextWriter& operator()(const CVParam& cvParam)
73  {
74  os_ << indent_ << "cvParam: " << cvTermInfo(cvParam.cvid).name;
75  if (!cvParam.value.empty())
76  os_ << ", " << cvParam.value;
77  if (cvParam.units != CVID_Unknown)
78  os_ << ", " << cvParam.unitsName();
79  os_ << std::endl;
80  return *this;
81  }
82 
83 
84  TextWriter& operator()(const std::string& label, const float& v)
85  {
86  os_ << indent_ << label << v << std::endl;
87  return *this;
88  }
89 
90 
91  TextWriter& operator()(const std::string& label, const double& v)
92  {
93  os_ << indent_ << label << v << std::endl;
94  return *this;
95  }
96 
97 
98  TextWriter& operator()(const std::string& label, const bool& v)
99  {
100  os_ << indent_ << label << std::boolalpha << v << std::endl;
101  return *this;
102  }
103 
104 
105  TextWriter& operator()(const UserParam& userParam)
106  {
107  os_ << indent_ << "userParam: " << userParam.name;
108  if (!userParam.value.empty()) os_ << ", " << userParam.value;
109  if (!userParam.type.empty()) os_ << ", " << userParam.type;
110  if (userParam.units != CVID_Unknown) os_ << ", " << cvTermInfo(userParam.units).name;
111  os_ << std::endl;
112  return *this;
113  }
114 
115 
116  template<typename object_type>
117  TextWriter& operator()(const std::string& label, const std::vector<object_type>& v)
118  {
119  (*this)(label);
120  for_each(v.begin(), v.end(), child());
121  return *this;
122  }
123 
124 
125  template<typename object_type>
126  TextWriter& operator()(const std::vector<object_type>& v)
127  {
128  for_each(v.begin(), v.end(), child());
129  return *this;
130  }
131 
132 
133  template<typename object_type>
134  TextWriter& operator()(const std::string& label, const object_type& v)
135  {
136  (*this)(label + boost::lexical_cast<std::string>(v));
137  return *this;
138  }
139 
140 
141  TextWriter& operator()(const std::string& label, const ParamContainer& paramContainer)
142  {
143  (*this)(label); // + ":"
144  for_each(paramContainer.cvParams.begin(), paramContainer.cvParams.end(), child());
145  for_each(paramContainer.userParams.begin(), paramContainer.userParams.end(), child());
146  return *this;
147  }
148 
149 
150  TextWriter& operator()(const ParamContainer& paramContainer)
151  {
152  for_each(paramContainer.cvParams.begin(), paramContainer.cvParams.end(), *this);
153  for_each(paramContainer.userParams.begin(), paramContainer.userParams.end(), *this);
154  return *this;
155  }
156 
157 
158  TextWriter& operator()(const BibliographicReference& br)
159  {
160  (*this)("BibliographicReference: ");
161  (*this)((Identifiable)br);
162  if (!br.authors.empty())
163  child()("authors: "+br.authors);
164  if (!br.publication.empty())
165  child()("publication: "+br.publication);
166  if (!br.publisher.empty())
167  child()(br.publisher);
168  if (!br.editor.empty())
169  child()("editor: "+br.editor);
170  if (br.year != 0)
171  child()("year: ", br.year);
172  if (!br.volume.empty())
173  child()("volume: "+br.volume);
174  if (!br.issue.empty())
175  child()("issue: "+br.issue);
176  if (!br.pages.empty())
177  child()("pages: "+br.pages);
178  if (!br.title.empty())
179  child()("title: "+br.title);
180 
181  return *this;
182  }
183 
184 
185  TextWriter& operator()(const TranslationTable& tt)
186  {
187  (*this)("TranslationTable:");
188  (*this)((const IdentifiableParamContainer&)tt);
189  return *this;
190  }
191 
192 
193  TextWriter& operator()(const DatabaseTranslation& dt)
194  {
195  (*this)("DatabaseTranslation:");
196  if (!dt.frames.empty())
197  child()("frames: ", dt.frames);
198  if (!dt.translationTable.empty())
199  child()("translationTable: ", dt.translationTable);
200  return *this;
201  }
202 
203 
205  {
206  (*this)("SpectrumIdentificationProtocol:");
207  (*this)((Identifiable&)si);
208  if (si.analysisSoftwarePtr.get() &&
209  !si.analysisSoftwarePtr->empty())
210  child()("analysisSoftware_ref: "+si.analysisSoftwarePtr->id);
211  if (!si.searchType.empty())
212  child()("SearchType: ", si.searchType);
213  if (!si.additionalSearchParams.empty())
214  child()("AdditionalSearchParams", si.additionalSearchParams);
215  if (!si.modificationParams.empty())
216  child()("ModificationParams", si.modificationParams);
217  if (!si.enzymes.empty())
218  child()(si.enzymes);
219  if (!si.massTable.empty())
220  child()(si.massTable);
221  if (!si.fragmentTolerance.empty())
222  child()("FragmentTolerance", si.fragmentTolerance);
223  if (!si.parentTolerance.empty())
224  child()("ParentTolerance", si.parentTolerance);
225  if (!si.threshold.empty())
226  child()("Threshold", si.threshold);
227  if (!si.databaseFilters.empty())
228  child()("DatabaseFilters", si.databaseFilters);
229  if (si.databaseTranslation.get() && !si.databaseTranslation->empty())
230  child()("DatabaseTranslation", si.databaseTranslation);
231 
232  return *this;
233  }
234 
235 
236  TextWriter& operator()(const DBSequence& ds)
237  {
238  (*this)("DBSequence: ");
239  (*this)((const IdentifiableParamContainer&)ds);
240  if (ds.length!=0)
241  child()("length: ", ds.length);
242  if (!ds.accession.empty())
243  child()("accession: "+ds.accession);
244  if (ds.searchDatabasePtr.get() && !ds.searchDatabasePtr->empty())
245  child()("searchDatabase_ref: "+ds.searchDatabasePtr->id);
246  if (!ds.seq.empty())
247  child()("Seq: "+ds.seq);
248 
249  return *this;
250  }
251 
252 
253  TextWriter& operator()(const SubstitutionModification& ds)
254  {
255  (*this)("SubstitutionModification: ");
256  if (ds.originalResidue != 0)
257  child()("originalResidue: ", ds.originalResidue);
258  if (ds.replacementResidue != 0)
259  child()("replacementResidue: ", ds.replacementResidue);
260  if (ds.location != 0)
261  child()("location: ", ds.location);
262  child()("avgMassDelta: ", ds.avgMassDelta);
263  child()("monoisotopicMassDelta: ", ds.monoisotopicMassDelta);
264 
265  return *this;
266  }
267 
268 
269  TextWriter& operator()(const IonType& it)
270  {
271  (*this)("IonType: ");
272  if (!it.index.empty())
273  child()("index: " + makeDelimitedListString(it.index));
274  if (it.charge != 0)
275  child()("charge: ", it.charge);
276  if (!it.fragmentArray.empty())
277  (*this)(it.fragmentArray);
278  (*this)((const CVParam&)it);
279  return *this;
280  }
281 
282 
283  TextWriter& operator()(const Measure& m)
284  {
285  (*this)("Measure: ");
286  (*this)((const ParamContainer&)m);
287 
288  return *this;
289  }
290 
291 
292  TextWriter& operator()(const SearchDatabase& sd)
293  {
294  (*this)("SearchDatabase: ");
295  (*this)((const IdentifiableParamContainer&)sd);
296  if (!sd.location.empty())
297  child()("location: " + sd.location);
298  if (!sd.version.empty())
299  child()("version: " + sd.version);
300  if (!sd.releaseDate.empty())
301  child()("releaseDate: " + sd.releaseDate);
302  if (sd.numDatabaseSequences != 0)
303  child()("numDatabaseSequences: ", sd.numDatabaseSequences);
304  if (sd.numResidues != 0)
305  child()("numResidues: ", sd.numResidues);
306  if (!sd.fileFormat.empty())
307  child()("FileFormat: ", sd.fileFormat);
308  if (!sd.databaseName.empty())
309  child()("DatabaseName: ", sd.databaseName);
310  return *this;
311  }
312 
313 
314  TextWriter& operator()(const SpectraData& sd)
315  {
316  (*this)("SpectraData: ");
317  if (!sd.location.empty())
318  child()("location: " + sd.location);
319  if (!sd.externalFormatDocumentation.empty())
320  child()("ExternalFormatDocumentation: ", sd.externalFormatDocumentation);
321  if (!sd.fileFormat.empty())
322  child()("FileFormat: ", sd.fileFormat);
323  if (!sd.spectrumIDFormat.empty())
324  child()("SpectrumIDFormat: ", sd.spectrumIDFormat);
325  return *this;
326  }
327 
328 
329  TextWriter& operator()(const SpectrumIdentificationItem& sii)
330  {
331  (*this)("SpectrumIdentificationItem:");
332  if (!sii.id.empty())
333  child()("id: ", sii.id);
334  if (!sii.name.empty())
335  child()("name: ", sii.name);
336  if (!sii.empty())
337  {
338  child()("rank: ", sii.rank);
339  child()("chargeState: ", sii.chargeState);
340  child()("experimentalMassToCharge: ", sii.experimentalMassToCharge);
341  child()("calculatedMassToCharge: ", sii.calculatedMassToCharge);
342  child()("calculatedPI: ", sii.calculatedPI);
343  child()("passThreshold: ", sii.passThreshold);
344  }
345  if (sii.peptidePtr.get() && !sii.peptidePtr->empty())
346  child()("peptide_ref: ", sii.peptidePtr->id);
347  if (sii.massTablePtr.get() && !sii.massTablePtr->empty())
348  child()("massTable_ref: ", sii.massTablePtr->id);
349  if (sii.samplePtr.get() && !sii.samplePtr->empty())
350  child()("sample_ref: ", sii.samplePtr->id);
351 
352  BOOST_FOREACH(const PeptideEvidencePtr& pe, sii.peptideEvidencePtr)
353  if (pe.get() && !pe->empty())
354  child()("peptideEvidence_ref: ", pe->id);
355 
356  if (!sii.fragmentation.empty())
357  child()("fragmentation", sii.fragmentation);
358 
359  child()((const ParamContainer&)sii);
360 
361  return *this;
362  }
363 
364 
365  TextWriter& operator()(const SpectrumIdentificationResult& sir)
366  {
367  (*this)("SpectrumIdentificationResult: ");
368  (*this)((const IdentifiableParamContainer&)sir);
369  if (!sir.spectrumID.empty())
370  child()("spectrumID: "+sir.spectrumID);
371  if (sir.spectraDataPtr.get() && !sir.spectraDataPtr->empty())
372  child()("spectraData_ref: "+sir.spectraDataPtr->id);
373  if (!sir.spectrumIdentificationItem.empty())
374  (*this)(sir.spectrumIdentificationItem);
375 
376  return *this;
377  }
378 
379 
380  TextWriter& operator()(const SpectrumIdentificationList& sil)
381  {
382  (*this)("SpectrumIdentificationList: ");
383  (*this)((Identifiable)sil);
384  if (!sil.empty())
385  child()("numSequencesSearched: ", sil.numSequencesSearched);
386  if (!sil.fragmentationTable.empty())
387  child()("FragmentationTable", sil.fragmentationTable);
388  if (!sil.spectrumIdentificationResult.empty())
389  (*this)(sil.spectrumIdentificationResult);
390  return *this;
391  }
392 
393 
394  TextWriter& operator()(const ProteinDetectionList& pdl)
395  {
396  (*this)("ProteinDetectionList: ");
397  if (!pdl.proteinAmbiguityGroup.empty())
398  (*this)(pdl.proteinAmbiguityGroup);
399  (*this)((const ParamContainer&)pdl);
400  return *this;
401  }
402 
403 
404  TextWriter& operator()(const AnalysisData& ad)
405  {
406  (*this)("AnalysisData: ");
407 
408  if (!ad.spectrumIdentificationList.empty())
409  (*this)(ad.spectrumIdentificationList);
410  if (ad.proteinDetectionListPtr.get() &&
411  !ad.proteinDetectionListPtr->empty())
412  (*this)(*ad.proteinDetectionListPtr);
413 
414  return *this;
415  }
416 
417 
418  TextWriter& operator()(const FragmentArray& fa)
419  {
420  (*this)("FragmentArray: ");
421 
422  if (fa.measurePtr.get() && !fa.measurePtr->empty())
423  child()("measure_ref: " + fa.measurePtr->id);
424  if (!fa.values.empty())
425  child()("values: " + makeDelimitedListString(fa.values));
426 
427  return *this;
428  }
429 
430 
431  TextWriter& operator()(const SourceFile& sf)
432  {
433  //(*this)("sourceFile: ");
434 
435  (*this)((const IdentifiableParamContainer&)sf);
436  if (!sf.location.empty())
437  child()("location: " + sf.location);
438  if (!sf.fileFormat.empty())
439  child()(sf.fileFormat);
440  if (!sf.externalFormatDocumentation.empty())
441  child()("externalFormatDocumentation: ",
443 
444  return *this;
445  }
446 
447 
448  TextWriter& operator()(const Inputs& inputs)
449  {
450  (*this)("Inputs: ");
451 
452  if (!inputs.sourceFile.empty())
453  child()("sourceFile: ", inputs.sourceFile);
454  if (!inputs.searchDatabase.empty())
455  child()("searchDatabase: ", inputs.searchDatabase);
456  if (!inputs.spectraData.empty())
457  child()("spectraData: ", inputs.spectraData);
458 
459  return *this;
460  }
461 
462 
463  TextWriter& operator()(const DataCollection& dc)
464  {
465  (*this)("DataCollection: ");
466 
467  if (!dc.inputs.empty())
468  child()(dc.inputs);
469  if (!dc.analysisData.empty())
470  child()(dc.analysisData);
471 
472  return *this;
473  }
474 
475 
476  TextWriter& operator()(const Filter& f)
477  {
478  (*this)("Filter: ");
479  if (!f.filterType.empty())
480  child()("filterType: ", f.filterType);
481  if (!f.include.empty())
482  child()("include: ", f.include);
483  if (!f.exclude.empty())
484  child()("exclude: ", f.exclude);
485  return *this;
486  }
487 
488 
489  TextWriter& operator()(const SearchModification& sm)
490  {
491  (*this)("SearchModification: ");
492  if (sm.fixedMod != 0)
493  child()("fixedMod: ", sm.fixedMod);
494  if (sm.massDelta != 0)
495  child()("massDelta: ", sm.massDelta);
496  if (!sm.residues.empty())
497  child()("residues: " + makeDelimitedListString(sm.residues));
498  if (!sm.specificityRules.empty())
499  child()("specificityRules: ", sm.specificityRules);
500  child()((const ParamContainer&)sm);
501  return *this;
502  }
503 
504 
505  TextWriter& operator()(const Enzymes& ezs)
506  {
507  (*this)("Enzymes: ");
508  if (!indeterminate(ezs.independent))
509  child()("independent: ", ezs.independent);
510  if (!ezs.enzymes.empty())
511  child()("enzymes: ", ezs.enzymes);
512  return *this;
513  }
514 
515 
516  TextWriter& operator()(const MassTable& mt)
517  {
518  (*this)("MassTable: ");
519  if (!mt.id.empty())
520  child()("id: " + mt.id);
521  if (!mt.msLevel.empty())
522  child()("msLevel: ", mt.msLevel);
523  if (!mt.residues.empty())
524  child()("residues: ", mt.residues);
525  if (!mt.ambiguousResidue.empty())
526  child()("ambiguousResidue: ", mt.residues);
527  return *this;
528  }
529 
530 
531  TextWriter& operator()(const AnalysisProtocolCollection& apc)
532  {
533  (*this)("AnalysisProtocolCollection: ");
534  if (!apc.spectrumIdentificationProtocol.empty())
535  child()("spectrumIdentificationProtocol: ",
537  if (!apc.proteinDetectionProtocol.empty())
538  child()("proteinDetectionProtocol: ",
540  return *this;
541  }
542 
543 
544  TextWriter& operator()(const PeptideHypothesis& ph)
545  {
546  (*this)("PeptideHypothesis: ");
547 
548  if (ph.peptideEvidencePtr.get())
549  child()("peptideEvidence: ", ph.peptideEvidencePtr->id);
550  child()("spectrumIdentificationItem: " + makeDelimitedRefListString(ph.spectrumIdentificationItemPtr));
551  return *this;
552  }
553 
554 
555  TextWriter& operator()(const ProteinDetectionHypothesis& pdh)
556  {
557  (*this)("ProteinDetectionHypothesis: ");
558  if (pdh.dbSequencePtr.get() && !pdh.dbSequencePtr->empty())
559  child()("DBSequence_ref: " + pdh.dbSequencePtr->id);
560  // TODO: Resolve if (!pdh.passThreshold.empty())
561  // child()("passThreshold: " + boost::lexical_cast<std::string>(pdh.passThreshold));
562  if (!pdh.peptideHypothesis.empty())
563  (*this)(pdh.peptideHypothesis);
564 
565  child()((const ParamContainer&)pdh);
566  return *this;
567  }
568 
569 
570  TextWriter& operator()(const ProteinAmbiguityGroup& pag)
571  {
572  (*this)("ProteinAmbiguityGroup: ");
573  if (!pag.proteinDetectionHypothesis.empty())
574  (*this)(pag.proteinDetectionHypothesis);
575  (*this)((const ParamContainer&)pag);
576 
577  return *this;
578  }
579 
580 
581  TextWriter& operator()(const ProteinDetection& pd)
582  {
583  (*this)("ProteinDetection: ");
584  if (pd.proteinDetectionProtocolPtr.get() &&
585  !pd.proteinDetectionProtocolPtr->empty())
586  child()("proteinDetectionProtocol_ref: "+pd.proteinDetectionProtocolPtr->id);
587  if (pd.proteinDetectionListPtr.get() &&
588  !pd.proteinDetectionListPtr->empty())
589  child()("proteinDetectionList_ref: "+pd.proteinDetectionListPtr->id);
590  if (!pd.activityDate.empty())
591  child()("activityDate: "+pd.activityDate);
592  child()("inputSpectrumIdentifications: " + makeDelimitedRefListString(pd.inputSpectrumIdentifications));
593  return *this;
594  }
595 
596 
597  TextWriter& operator()(const SpectrumIdentification& si)
598  {
599  (*this)("SpectrumIdentification: ");
600  if (si.spectrumIdentificationProtocolPtr.get() &&
602  child()("spectrumIdentificationProtocol_ref: "+si.spectrumIdentificationProtocolPtr->id);
603  if (si.spectrumIdentificationListPtr.get() &&
604  !si.spectrumIdentificationListPtr->empty())
605  child()("spectrumIdentificationList_ref: "+si.spectrumIdentificationListPtr->id);
606  if (!si.activityDate.empty())
607  child()("activityDate: "+si.activityDate);
608  if (!si.inputSpectra.empty())
609  child()("inputSpectra: " + makeDelimitedRefListString(si.inputSpectra));
610  if (!si.searchDatabase.empty())
611  child()("searchDatabase: " + makeDelimitedRefListString(si.searchDatabase));
612 
613  return *this;
614  }
615 
616 
617  TextWriter& operator()(const AnalysisCollection& ac)
618  {
619  (*this)("AnalysisCollection: ", ac.spectrumIdentification);
620  if (!ac.proteinDetection.empty())
621  child()(ac.proteinDetection);
622  return *this;
623  }
624 
625 
626  TextWriter& operator()(const SequenceCollection& sc)
627  {
628  (*this)("SequenceCollection: ");
629  if (!sc.dbSequences.empty())
630  child()("dbSequences: ", sc.dbSequences);
631  if (!sc.peptides.empty())
632  child()("peptides: ", sc.peptides);
633  if (!sc.peptideEvidence.empty())
634  child()("peptideEvidence: ", sc.peptideEvidence);
635  return *this;
636  }
637 
638 
639  TextWriter& operator()(const Contact& cont)
640  {
641  (*this)((const IdentifiableParamContainer&)cont);
642 
643  return *this;
644  }
645 
646 
647  TextWriter& operator()(const Person& per)
648  {
649  (*this)("Person: ");
650  (*this)((const Contact&)per);
651  if (!per.lastName.empty())
652  child()("lastName: "+per.lastName);
653  if (!per.firstName.empty())
654  child()("firstName: "+per.firstName);
655  if (!per.midInitials.empty())
656  child()("midInitials: "+per.midInitials);
657  if (!per.affiliations.empty())
658  child()("affiliations: ", per.affiliations);
659 
660  return *this;
661  }
662 
663 
664  TextWriter& operator()(const Organization& org)
665  {
666  (*this)("Organization: ");
667  (*this)((const Contact&)org);
668  if (org.parent.get())
669  child()("Parent: ", org.parent->id);
670 
671  return *this;
672  }
673 
674 
675  TextWriter& operator()(const ContactPtr cont)
676  {
677  if (dynamic_cast<Person*>(cont.get()))
678  (*this)((const Person&)(*cont));
679  else if (dynamic_cast<Organization*>(cont.get()))
680  (*this)((const Organization&)(*cont));
681  else
682  (*this)(*cont);
683 
684  return *this;
685  }
686 
687 
688  TextWriter& operator()(const std::string& label, const ContactPtr cont)
689  {
690  (*this)(label);
691  (*this)(cont);
692 
693  return *this;
694  }
695 
696 
697  TextWriter& operator()(const ContactRole& cr)
698  {
699  (*this)("ContactRole: ");
700  if (cr.contactPtr.get() && !cr.contactPtr->empty())
701  child()("contact_ref: ", cr.contactPtr->id);
702  if (!cr.CVParam::empty())
703  child()("Role: ", (const CVParam&)cr);
704  return (*this);
705  }
706 
707 
708  TextWriter& operator()(const Provider& provider)
709  {
710  (*this)("Provider: ");
711  (*this)((Identifiable&)provider);
712  if (provider.contactRolePtr.get() && !provider.contactRolePtr->empty())
713  child()(provider.contactRolePtr);
714  return *this;
715  }
716 
717 
718  TextWriter& operator()(const Sample& sample)
719  {
720  (*this)("Sample: ");
721  (*this)((const IdentifiableParamContainer&)sample);
722  (*this)(sample.contactRole);
723  child()(sample.cvParams);
724  child()("SubSamples:", sample.subSamples);
725 
726  return *this;
727  }
728 
729 
730  TextWriter& operator()(const AnalysisSampleCollection& asc)
731  {
732  (*this)("AnalysisSampleCollection: ", asc.samples);
733 
734  return *this;
735  }
736 
737 
738  TextWriter& operator()(const AnalysisSoftwarePtr& asp)
739  {
740  (*this)("analysisSoftware:");
741  (*this)((Identifiable)*asp);
742  if (!asp->version.empty())
743  child()("version: "+asp->version);
744  if (asp->contactRolePtr.get() && asp->contactRolePtr->empty())
745  child()(*asp->contactRolePtr);
746  if (!asp->softwareName.empty())
747  child()("softwareName: ", asp->softwareName);
748  if (!asp->URI.empty())
749  child()("uri: "+asp->URI);
750  if (!asp->customizations.empty())
751  child()("customizations: "+asp->customizations);
752  return *this;
753  }
754 
755 
756  TextWriter& operator()(const Enzyme& enzyme)
757  {
758  (*this)("Enzyme: ");
759  if (!enzyme.id.empty())
760  child()("id: "+enzyme.id);
761  if (!enzyme.nTermGain.empty())
762  child()("nTermGain: "+enzyme.nTermGain);
763  if (!enzyme.cTermGain.empty())
764  child()("cTermGain: "+enzyme.cTermGain);
765  child()("semiSpecific: ", (enzyme.terminalSpecificity != proteome::Digestion::FullySpecific ? "true": "false"));
766  if (enzyme.missedCleavages != 0)
767  child()("missedCleavages: ", enzyme.missedCleavages);
768  if (enzyme.minDistance != 0)
769  child()("minDistance: ", enzyme.minDistance);
770  if (!enzyme.siteRegexp.empty())
771  child()("SiteRegexp: "+enzyme.siteRegexp);
772  if (!enzyme.enzymeName.empty())
773  child()("EnzymeName: ", enzyme.enzymeName);
774 
775  return *this;
776  }
777 
778 
779  TextWriter& operator()(const Identifiable& id)
780  {
781  if (!id.id.empty())
782  child()("id: "+id.id);
783  if (!id.name.empty())
784  child()("name: "+id.name);
785 
786  return *this;
787  }
788 
789 
790  TextWriter& operator()(const IdentifiableParamContainer& id)
791  {
792  if (!id.id.empty())
793  child()("id: "+id.id);
794  if (!id.name.empty())
795  child()("name: "+id.name);
796 
797  child()((const ParamContainer&)id);
798 
799  return *this;
800  }
801 
802 
803  TextWriter& operator()(const Residue& res)
804  {
805  (*this)("Residue: ");
806  if (res.code != 0)
807  child()("code: ", res.code);
808  if (res.mass != 0)
809  child()("mass: ", res.mass);
810  return *this;
811  }
812 
813 
814  TextWriter& operator()(const AmbiguousResidue& res)
815  {
816  (*this)("AmbiguousResidue: ");
817  if (res.code != 0)
818  child()("code: ", res.code);
819  (*this)((const ParamContainer&)res);
820 
821  return *this;
822  }
823 
824 
825  TextWriter& operator()(const Modification& mod)
826  {
827  (*this)("Modification: ");
828  if (mod.location != 0)
829  child()("location: ", mod.location);
830  if (!mod.residues.empty())
831  child()("residues: " + makeDelimitedListString(mod.residues));
832  if (mod.avgMassDelta != 0)
833  child()("avgMassDelta: ", mod.avgMassDelta);
834  if (mod.monoisotopicMassDelta != 0)
835  child()("monoisotopicMassDelta: ", mod.monoisotopicMassDelta);
836  child()((const ParamContainer&)mod);
837 
838  return *this;
839  }
840 
841 
842  TextWriter& operator()(const Peptide& pep)
843  {
844  (*this)("Peptide: ");
845  (*this)((const IdentifiableParamContainer&)pep);
846  if (!pep.peptideSequence.empty())
847  child()("peptideSequence: "+pep.peptideSequence);
848  if (!pep.modification.empty())
849  child()("modification", pep.modification);
850  if (!pep.substitutionModification.empty())
851  child()(pep.substitutionModification);
852 
853  return *this;
854  }
855 
856 
857  TextWriter& operator()(const PeptideEvidence& pe)
858  {
859  (*this)("PeptideEvidence: ");
860  (*this)((const IdentifiableParamContainer&)pe);
861  if (pe.peptidePtr.get() && !pe.peptidePtr->empty())
862  child()("peptide_ref: "+pe.peptidePtr->id);
863  if (pe.dbSequencePtr.get() && !pe.dbSequencePtr->empty())
864  child()("dBSequence_ref: "+pe.dbSequencePtr->id);
865  if (pe.start != 0)
866  child()("start: ", pe.start);
867  if (pe.end != 0)
868  child()("end: ", pe.end);
869  if (pe.pre != 0)
870  child()("pre: ", pe.pre);
871  if (pe.post != 0)
872  child()("post: ", pe.post);
873  if (pe.translationTablePtr.get() && !pe.translationTablePtr->empty())
874  child()("translationTable_ref: "+pe.translationTablePtr->id);
875  if (pe.frame != 0)
876  child()("frame: ", pe.frame);
877  child()("isDecoy: ", pe.isDecoy);
878 
879  return *this;
880  }
881 
882 
883  TextWriter& operator()(const IdentData& mzid)
884  {
885  (*this)("mzid:");
886  child()((Identifiable)mzid);
887  ("version: " + mzid.version());
888  if (!mzid.cvs.empty())
889  child()("cvList: ", mzid.cvs);
890  if (!mzid.analysisSoftwareList.empty())
891  child()("analysisSoftwareList: ", mzid.analysisSoftwareList);
892  if (!mzid.provider.empty())
893  child()(mzid.provider);
894  if (!mzid.auditCollection.empty())
895  child()("auditCollection: ", mzid.auditCollection);
896  if (!mzid.analysisSampleCollection.empty())
897  child()(mzid.analysisSampleCollection);
898  if (!mzid.sequenceCollection.empty())
899  child()(mzid.sequenceCollection);
900  if (!mzid.analysisCollection.empty())
901  child()(mzid.analysisCollection);
902  if (!mzid.analysisProtocolCollection.empty())
903  child()(mzid.analysisProtocolCollection);
904  if (!mzid.dataCollection.empty())
905  child()(mzid.dataCollection);
906  if (!mzid.bibliographicReference.empty())
907  child()(mzid.bibliographicReference);
908  return *this;
909  }
910 
911 
912  TextWriter& operator()(const CV& cv)
913  {
914  (*this)("cv:");
915  child()
916  ("id: " + cv.id)
917  ("fullName: " + cv.fullName)
918  ("version: " + cv.version)
919  ("URI: " + cv.URI);
920  return *this;
921  }
922 
923 
924  // if no other overload matches, assume the object is a shared_ptr of a valid overloaded type
925  template<typename object_type>
926  TextWriter& operator()(const boost::shared_ptr<object_type>& p)
927  {
928  return p.get() ? (*this)(*p) : *this;
929  }
930 
931  private:
932  std::ostream& os_;
933  int depth_;
934  std::string indent_;
935 
936  template <typename object_type>
937  std::string makeDelimitedRefListString(const std::vector<boost::shared_ptr<object_type> >& objects, const char* delimiter = " ")
938  {
939  std::ostringstream oss;
940  for (size_t i=0; i < objects.size(); ++i)
941  {
942  if (i > 0) oss << delimiter;
943  oss << objects[i]->id;
944  }
945  return oss.str();
946  }
947 
948  template <typename object_type>
949  std::string makeDelimitedListString(const std::vector<object_type>& objects, const char* delimiter = " ")
950  {
951  std::ostringstream oss;
952  oss.precision(9);
953  for (size_t i=0; i < objects.size(); ++i)
954  {
955  if (i > 0) oss << delimiter;
956  oss << objects[i];
957  }
958  return oss.str();
959  }
960 };
961 
962 
963 } // namespace identdata
964 } // namespace pwiz
965 
966 
967 #endif // _IDENTDATA_TEXTWRITER_HPP_
968