OpenMS  2.4.0
QcMLFile.h
Go to the documentation of this file.
1 // --------------------------------------------------------------------------
2 // OpenMS -- Open-Source Mass Spectrometry
3 // --------------------------------------------------------------------------
4 // Copyright The OpenMS Team -- Eberhard Karls University Tuebingen,
5 // ETH Zurich, and Freie Universitaet Berlin 2002-2018.
6 //
7 // This software is released under a three-clause BSD license:
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 // * Neither the name of any author or any participating institution
14 // may be used to endorse or promote products derived from this software
15 // without specific prior written permission.
16 // For a full list of authors, refer to the file AUTHORS.
17 // --------------------------------------------------------------------------
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 // ARE DISCLAIMED. IN NO EVENT SHALL ANY OF THE AUTHORS OR THE CONTRIBUTING
22 // INSTITUTIONS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 //
30 // --------------------------------------------------------------------------
31 // $Maintainer: Mathias Walzer $
32 // $Authors: Mathias Walzer $
33 // --------------------------------------------------------------------------
34 
35 #pragma once
36 
39 #include <OpenMS/FORMAT/XMLFile.h>
40 
41 #include <vector>
42 #include <map>
43 #include <set>
44 #include <algorithm>
45 
46 namespace OpenMS
47 {
57  class OPENMS_DLLAPI QcMLFile :
58  public Internal::XMLHandler,
59  public Internal::XMLFile,
60  public ProgressLogger
61  {
62 public:
63 
65  struct OPENMS_DLLAPI QualityParameter
66  {
75 
78 
80 
81  QualityParameter& operator=(const QualityParameter& rhs);
82  bool operator==(const QualityParameter& rhs) const;
83  bool operator<(const QualityParameter& rhs) const;
84  bool operator>(const QualityParameter& rhs) const;
85 
86  String toXMLString(UInt indentation_level) const;
87  };
88 
90  struct OPENMS_DLLAPI Attachment
91  {
101  std::vector<String> colTypes;
102  std::vector< std::vector<String> > tableRows;
103  //~ TODO -schema- coltypes with full definition (uintRef, unitAcc)
104 
106  Attachment();
107 
108  Attachment(const Attachment& rhs);
109 
110  Attachment& operator=(const Attachment& rhs);
111  bool operator==(const Attachment& rhs) const;
112  bool operator<(const Attachment& rhs) const;
113  bool operator>(const Attachment& rhs) const;
114 
115  String toXMLString(UInt indentation_level) const;
116  String toCSVString(String separator) const;
117  };
118 
120  QcMLFile();
122  ~QcMLFile() override;
123 
124  String map2csv(const std::map< String, std::map<String, String> >& cvs_table, const String& separator) const;
125  String exportIDstats(const String& filename) const;
126 
128  void registerRun(const String id, const String name);
130  void registerSet(const String id, const String name, const std::set<String>& names);
132  void addRunQualityParameter(String r, QualityParameter qp);
134  void addRunAttachment(String r, Attachment at);
136  void addSetQualityParameter(String r, QualityParameter qp);
138  void addSetAttachment(String r, Attachment at);
140  void removeAttachment(String r, std::vector<String>& ids, String at = "");
142  void removeAttachment(String r, String at);
144  void removeAllAttachments(String at);
146  void removeQualityParameter(String r, std::vector<String>& ids);
148  void merge(const QcMLFile & addendum, String setname = "");
150  void/* std::vector<String>& */ collectSetParameter(const String setname, const String qp, std::vector<String>& ret);
152  String exportAttachment(const String filename, const String qpname) const;
154  String exportQP(const String filename, const String qpname) const;
156  String exportQPs(const String filename, const StringList qpnames) const;
158  void getRunIDs (std::vector<String>& ids) const;
160  void getRunNames (std::vector<String>& ids) const;
162  bool existsRun(const String filename, bool checkname = false) const;
164  bool existsSet(const String filename, bool checkname = false) const;
166  void existsRunQualityParameter(const String filename, const String qpname, std::vector<String>& ids) const;
168  void existsSetQualityParameter(const String filename, const String qpname, std::vector<String>& ids) const;
170  void store(const String & filename) const;
172  void load(const String & filename);
173 
174  //~ int siz; //debug
175 
176 protected:
177  // Docu in base class
178  void endElement(const XMLCh * const /*uri*/, const XMLCh * const /*local_name*/, const XMLCh * const qname) override;
179 
180  // Docu in base class
181  void startElement(const XMLCh * const /*uri*/, const XMLCh * const /*local_name*/, const XMLCh * const qname, const xercesc::Attributes & attributes) override;
182 
183  // Docu in base class
184  void characters(const XMLCh * const chars, const XMLSize_t length) override;
185 
186  std::map<String, std::vector< QualityParameter > > runQualityQPs_; //TODO run name attribute to schema of RunQuality
187  std::map<String, std::vector< Attachment > > runQualityAts_;
188  std::map<String, std::vector< QualityParameter > > setQualityQPs_;
189  std::map<String, std::vector< Attachment > > setQualityAts_;
190  std::map<String, std::set< String > > setQualityQPs_members_;
191  std::map<String, String > run_Name_ID_map_;
192  std::map<String, String > set_Name_ID_map_;
193 
198  std::vector<String> row_;
199  std::vector<String> header_;
202  std::set<String> names_;
203  std::vector<QualityParameter> qps_;
204  std::vector<Attachment> ats_;
205 
206  };
207 
208 } // namespace OpenMS
209 
String value
Value.
Definition: QcMLFile.h:69
String unitRef
cv reference of the unit
Definition: QcMLFile.h:97
A more convenient string class.
Definition: String.h:57
String value
Value.
Definition: QcMLFile.h:94
std::map< String, std::vector< Attachment > > setQualityAts_
Definition: QcMLFile.h:189
QualityParameter qp_
Definition: QcMLFile.h:196
std::vector< std::vector< String > > tableRows
cell values if QP has a table, type see colType
Definition: QcMLFile.h:102
String id
Name.
Definition: QcMLFile.h:93
String id
Identifier.
Definition: QcMLFile.h:68
String unitRef
cv reference of the unit
Definition: QcMLFile.h:72
String cvAcc
cv accession
Definition: QcMLFile.h:71
std::map< String, std::vector< QualityParameter > > runQualityQPs_
Definition: QcMLFile.h:186
std::map< String, String > set_Name_ID_map_
Definition: QcMLFile.h:192
unsigned int UInt
Unsigned integer type.
Definition: Types.h:94
String cvAcc
cv accession
Definition: QcMLFile.h:96
Attachment at_
Definition: QcMLFile.h:197
Base class for XML handlers.
Definition: XMLHandler.h:148
bool operator==(_Iterator< _Val, _Ref, _Ptr > const &, _Iterator< _Val, _Ref, _Ptr > const &)
Definition: KDTree.h:806
std::vector< String > row_
Definition: QcMLFile.h:198
String name_
Definition: QcMLFile.h:200
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:46
bool operator<(const MultiplexDeltaMasses &dm1, const MultiplexDeltaMasses &dm2)
String unitAcc
cv accession of the unit
Definition: QcMLFile.h:98
std::vector< String > header_
Definition: QcMLFile.h:199
String name
Name.
Definition: QcMLFile.h:67
std::map< String, std::set< String > > setQualityQPs_members_
Definition: QcMLFile.h:190
Representation of an attachment.
Definition: QcMLFile.h:90
String flag
cv accession of the unit
Definition: QcMLFile.h:74
std::map< String, String > run_Name_ID_map_
Definition: QcMLFile.h:191
String tag_
Definition: QcMLFile.h:194
String unitAcc
cv accession of the unit
Definition: QcMLFile.h:73
std::map< String, std::vector< QualityParameter > > setQualityQPs_
Definition: QcMLFile.h:188
std::vector< String > StringList
Vector of String.
Definition: ListUtils.h:73
File adapter for QcML files used to load and store QcML files.
Definition: QcMLFile.h:57
String cvRef
cv reference
Definition: QcMLFile.h:95
std::set< String > names_
Definition: QcMLFile.h:202
Base class for all classes that want to report their progress.
Definition: ProgressLogger.h:54
Representation of a quality parameter.
Definition: QcMLFile.h:65
Base class for loading/storing XML files that have a handler derived from XMLHandler.
Definition: XMLFile.h:48
UInt progress_
Definition: QcMLFile.h:195
std::vector< String > colTypes
type of the cols if QP has a table of values
Definition: QcMLFile.h:101
String name
Name.
Definition: QcMLFile.h:92
String qualityRef
reference to qp to which attachment, if empty attached to run/set
Definition: QcMLFile.h:100
String run_id_
Definition: QcMLFile.h:201
String cvRef
cv reference
Definition: QcMLFile.h:70
std::map< String, std::vector< Attachment > > runQualityAts_
Definition: QcMLFile.h:187
std::vector< Attachment > ats_
Definition: QcMLFile.h:204
String binary
binary content of the attachment
Definition: QcMLFile.h:99
std::vector< QualityParameter > qps_
Definition: QcMLFile.h:203