24 #ifndef _IDENTDATA_TEXTWRITER_HPP_
25 #define _IDENTDATA_TEXTWRITER_HPP_
31 #include <boost/foreach.hpp>
41 using namespace pwiz::data;
42 using namespace boost::logic;
49 :
os_(os), depth_(depth), indent_(depth*2,
' ')
60 os_ << indent_ << text << std::endl;
67 os_ << indent_ << value << std::endl;
75 if (!cvParam.
value.empty())
84 TextWriter& operator()(
const std::string& label,
const float& v)
86 os_ << indent_ << label << v << std::endl;
91 TextWriter& operator()(
const std::string& label,
const double& v)
93 os_ << indent_ << label << v << std::endl;
98 TextWriter& operator()(
const std::string& label,
const bool& v)
100 os_ << indent_ << label << std::boolalpha << v << std::endl;
107 os_ << indent_ <<
"userParam: " << userParam.
name;
108 if (!userParam.
value.empty())
os_ <<
", " << userParam.
value;
109 if (!userParam.
type.empty())
os_ <<
", " << userParam.
type;
116 template<
typename object_type>
117 TextWriter& operator()(
const std::string& label,
const std::vector<object_type>& v)
120 for_each(v.begin(), v.end(), child());
125 template<
typename object_type>
128 for_each(v.begin(), v.end(), child());
133 template<
typename object_type>
134 TextWriter& operator()(
const std::string& label,
const object_type& v)
144 for_each(paramContainer.
cvParams.begin(), paramContainer.
cvParams.end(), child());
152 for_each(paramContainer.
cvParams.begin(), paramContainer.
cvParams.end(), *
this);
160 (*this)(
"BibliographicReference: ");
163 child()(
"authors: "+br.
authors);
169 child()(
"editor: "+br.
editor);
171 child()(
"year: ", br.
year);
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);
187 (*this)(
"TranslationTable:");
195 (*this)(
"DatabaseTranslation:");
197 child()(
"frames: ", dt.
frames);
206 (*this)(
"SpectrumIdentificationProtocol:");
238 (*this)(
"DBSequence: ");
241 child()(
"length: ", ds.
length);
247 child()(
"Seq: "+ds.
seq);
255 (*this)(
"SubstitutionModification: ");
271 (*this)(
"IonType: ");
272 if (!it.
index.empty())
273 child()(
"index: " + makeDelimitedListString(it.
index));
275 child()(
"charge: ", it.
charge);
285 (*this)(
"Measure: ");
294 (*this)(
"SearchDatabase: ");
297 child()(
"location: " + sd.
location);
299 child()(
"version: " + sd.
version);
316 (*this)(
"SpectraData: ");
318 child()(
"location: " + sd.
location);
331 (*this)(
"SpectrumIdentificationItem:");
333 child()(
"id: ", sii.
id);
334 if (!sii.
name.empty())
335 child()(
"name: ", sii.
name);
338 child()(
"rank: ", sii.
rank);
350 child()(
"sample_ref: ", sii.
samplePtr->id);
353 if (pe.get() && !pe->empty())
354 child()(
"peptideEvidence_ref: ", pe->id);
367 (*this)(
"SpectrumIdentificationResult: ");
382 (*this)(
"SpectrumIdentificationList: ");
396 (*this)(
"ProteinDetectionList: ");
406 (*this)(
"AnalysisData: ");
420 (*this)(
"FragmentArray: ");
425 child()(
"values: " + makeDelimitedListString(fa.
values));
437 child()(
"location: " + sf.
location);
441 child()(
"externalFormatDocumentation: ",
465 (*this)(
"DataCollection: ");
482 child()(
"include: ", f.
include);
484 child()(
"exclude: ", f.
exclude);
491 (*this)(
"SearchModification: ");
497 child()(
"residues: " + makeDelimitedListString(sm.
residues));
507 (*this)(
"Enzymes: ");
511 child()(
"enzymes: ", ezs.
enzymes);
518 (*this)(
"MassTable: ");
520 child()(
"id: " + mt.
id);
522 child()(
"msLevel: ", mt.
msLevel);
526 child()(
"ambiguousResidue: ", mt.
residues);
533 (*this)(
"AnalysisProtocolCollection: ");
535 child()(
"spectrumIdentificationProtocol: ",
538 child()(
"proteinDetectionProtocol: ",
546 (*this)(
"PeptideHypothesis: ");
557 (*this)(
"ProteinDetectionHypothesis: ");
572 (*this)(
"ProteinAmbiguityGroup: ");
583 (*this)(
"ProteinDetection: ");
599 (*this)(
"SpectrumIdentification: ");
609 child()(
"inputSpectra: " + makeDelimitedRefListString(si.
inputSpectra));
611 child()(
"searchDatabase: " + makeDelimitedRefListString(si.
searchDatabase));
628 (*this)(
"SequenceCollection: ");
666 (*this)(
"Organization: ");
669 child()(
"Parent: ", org.
parent->id);
677 if (dynamic_cast<Person*>(cont.get()))
678 (*this)((
const Person&)(*cont));
679 else if (dynamic_cast<Organization*>(cont.get()))
699 (*this)(
"ContactRole: ");
702 if (!cr.CVParam::empty())
703 child()(
"Role: ", (
const CVParam&)cr);
710 (*this)(
"Provider: ");
732 (*this)(
"AnalysisSampleCollection: ", asc.
samples);
740 (*this)(
"analysisSoftware:");
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);
759 if (!enzyme.
id.empty())
760 child()(
"id: "+enzyme.
id);
765 child()(
"semiSpecific: ", (enzyme.
terminalSpecificity != proteome::Digestion::FullySpecific ?
"true":
"false"));
782 child()(
"id: "+
id.id);
783 if (!
id.name.empty())
784 child()(
"name: "+
id.name);
793 child()(
"id: "+
id.id);
794 if (!
id.name.empty())
795 child()(
"name: "+
id.name);
805 (*this)(
"Residue: ");
807 child()(
"code: ", res.
code);
809 child()(
"mass: ", res.
mass);
816 (*this)(
"AmbiguousResidue: ");
818 child()(
"code: ", res.
code);
827 (*this)(
"Modification: ");
829 child()(
"location: ", mod.
location);
831 child()(
"residues: " + makeDelimitedListString(mod.
residues));
844 (*this)(
"Peptide: ");
859 (*this)(
"PeptideEvidence: ");
866 child()(
"start: ", pe.
start);
868 child()(
"end: ", pe.
end);
870 child()(
"pre: ", pe.
pre);
872 child()(
"post: ", pe.
post);
876 child()(
"frame: ", pe.
frame);
877 child()(
"isDecoy: ", pe.
isDecoy);
887 (
"version: " + mzid.
version());
888 if (!mzid.
cvs.empty())
889 child()(
"cvList: ", mzid.
cvs);
925 template<
typename object_type>
926 TextWriter& operator()(
const boost::shared_ptr<object_type>& p)
928 return p.get() ? (*this)(*p) : *
this;
936 template <
typename object_type>
937 std::string makeDelimitedRefListString(
const std::vector<boost::shared_ptr<object_type> >& objects,
const char* delimiter =
" ")
939 std::ostringstream oss;
940 for (
size_t i=0; i < objects.size(); ++i)
942 if (i > 0) oss << delimiter;
943 oss << objects[i]->id;
948 template <
typename object_type>
949 std::string makeDelimitedListString(
const std::vector<object_type>& objects,
const char* delimiter =
" ")
951 std::ostringstream oss;
953 for (
size_t i=0; i < objects.size(); ++i)
955 if (i > 0) oss << delimiter;
967 #endif // _IDENTDATA_TEXTWRITER_HPP_