OpenMS
QcMLFile.h
Go to the documentation of this file.
1 // Copyright (c) 2002-present, OpenMS Inc. -- EKU Tuebingen, ETH Zurich, and FU Berlin
2 // SPDX-License-Identifier: BSD-3-Clause
3 //
4 // --------------------------------------------------------------------------
5 // $Maintainer: Mathias Walzer, Axel Walter $
6 // $Authors: Mathias Walzer $
7 // --------------------------------------------------------------------------
8 
9 #pragma once
10 
13 #include <OpenMS/FORMAT/XMLFile.h>
15 #include <vector>
16 
17 namespace OpenMS
18 {
19  class ConsensusMap;
20  class FeatureMap;
21 
31  class OPENMS_DLLAPI QcMLFile :
32  public Internal::XMLHandler,
33  public Internal::XMLFile,
34  public ProgressLogger
35  {
36 public:
38  class OPENMS_DLLAPI QualityParameter
39  {
40  public:
49 
52 
54 
56  bool operator==(const QualityParameter& rhs) const;
57  bool operator<(const QualityParameter& rhs) const;
58  bool operator>(const QualityParameter& rhs) const;
59 
60  String toXMLString(UInt indentation_level) const;
61  };
62 
64  class OPENMS_DLLAPI Attachment
65  {
66  public:
76  std::vector<String> colTypes;
77  std::vector< std::vector<String> > tableRows;
78  //~ TODO -schema- coltypes with full definition (uintRef, unitAcc)
79 
82 
83  Attachment(const Attachment& rhs);
84 
86  bool operator==(const Attachment& rhs) const;
87  bool operator<(const Attachment& rhs) const;
88  bool operator>(const Attachment& rhs) const;
89 
90  String toXMLString(UInt indentation_level) const;
91  String toCSVString(const String& separator) const;
92  };
93 
97  ~QcMLFile() override;
98 
99  String map2csv(const std::map< String, std::map<String, String> >& cvs_table, const String& separator) const;
100  String exportIDstats(const String& filename) const;
101 
103  void registerRun(const String& id, const String& name);
105  void registerSet(const String& id, const String& name, const std::set<String>& names);
107  void addRunQualityParameter(const String& r, const QualityParameter& qp);
109  void addRunAttachment(const String& r, const Attachment& at);
111  void addSetQualityParameter(const String& r, const QualityParameter& qp);
113  void addSetAttachment(const String& r, const Attachment& at);
115  void removeAttachment(const String& r, std::vector<String>& ids, const String& at = "");
117  void removeAttachment(const String& r, const String& at);
119  void removeAllAttachments(const String& at);
121  void removeQualityParameter(const String& r, std::vector<String>& ids);
123  void merge(const QcMLFile & addendum, const String& setname = "");
125  void/* std::vector<String>& */ collectSetParameter(const String& setname, const String& qp, std::vector<String>& ret);
127  String exportAttachment(const String& filename, const String& qpname) const;
129  String exportQP(const String& filename, const String& qpname) const;
131  String exportQPs(const String& filename, const StringList& qpnames) const;
133  void getRunIDs (std::vector<String>& ids) const;
135  void getRunNames (std::vector<String>& ids) const;
137  bool existsRun(const String& filename, bool checkname = false) const;
139  bool existsSet(const String& filename, bool checkname = false) const;
141  void existsRunQualityParameter(const String& filename, const String& qpname, std::vector<String>& ids) const;
143  void existsSetQualityParameter(const String& filename, const String& qpname, std::vector<String>& ids) const;
145 
155  void collectQCData(std::vector<ProteinIdentification>& prot_ids,
156  std::vector<PeptideIdentification>& pep_ids,
157  const FeatureMap& feature_map,
158  const ConsensusMap& consensus_map,
159  const String& inputfile_raw,
160  const bool remove_duplicate_features,
161  const MSExperiment& exp);
163 
167  void store(const String& filename) const;
168 
170  void load(const String & filename);
171 
172  //~ int siz; //debug
173 
174 protected:
175  // Docu in base class
176  void endElement(const XMLCh * const /*uri*/, const XMLCh * const /*local_name*/, const XMLCh * const qname) override;
177 
178  // Docu in base class
179  void startElement(const XMLCh * const /*uri*/, const XMLCh * const /*local_name*/, const XMLCh * const qname, const xercesc::Attributes & attributes) override;
180 
181  // Docu in base class
182  void characters(const XMLCh * const chars, const XMLSize_t length) override;
183 
184  std::map<String, std::vector< QualityParameter > > runQualityQPs_; //TODO run name attribute to schema of RunQuality
185  std::map<String, std::vector< Attachment > > runQualityAts_;
186  std::map<String, std::vector< QualityParameter > > setQualityQPs_;
187  std::map<String, std::vector< Attachment > > setQualityAts_;
188  std::map<String, std::set< String > > setQualityQPs_members_;
189  std::map<String, String > run_Name_ID_map_;
190  std::map<String, String > set_Name_ID_map_;
191 
196  std::vector<String> row_;
197  std::vector<String> header_;
200  std::set<String> names_;
201  std::vector<QualityParameter> qps_;
202  std::vector<Attachment> ats_;
203  };
204 
205 } // namespace OpenMS
A container for consensus elements.
Definition: ConsensusMap.h:66
A container for features.
Definition: FeatureMap.h:80
Base class for loading/storing XML files that have a handler derived from XMLHandler.
Definition: XMLFile.h:23
Base class for XML handlers.
Definition: XMLHandler.h:302
In-Memory representation of a mass spectrometry run.
Definition: MSExperiment.h:46
Base class for all classes that want to report their progress.
Definition: ProgressLogger.h:27
Representation of an attachment.
Definition: QcMLFile.h:65
Attachment(const Attachment &rhs)
String toXMLString(UInt indentation_level) const
String qualityRef
reference to qp to which attachment, if empty attached to run/set
Definition: QcMLFile.h:75
String value
Value.
Definition: QcMLFile.h:69
String unitRef
cv reference of the unit
Definition: QcMLFile.h:72
String cvRef
cv reference
Definition: QcMLFile.h:70
String unitAcc
cv accession of the unit
Definition: QcMLFile.h:73
String id
Name.
Definition: QcMLFile.h:68
Attachment & operator=(const Attachment &rhs)
bool operator==(const Attachment &rhs) const
bool operator<(const Attachment &rhs) const
String binary
binary content of the attachment
Definition: QcMLFile.h:74
std::vector< String > colTypes
type of the cols if QP has a table of values
Definition: QcMLFile.h:76
String name
Name.
Definition: QcMLFile.h:67
Attachment()
Default constructor.
String cvAcc
cv accession
Definition: QcMLFile.h:71
std::vector< std::vector< String > > tableRows
cell values if QP has a table, type see colType
Definition: QcMLFile.h:77
String toCSVString(const String &separator) const
bool operator>(const Attachment &rhs) const
Representation of a quality parameter.
Definition: QcMLFile.h:39
bool operator<(const QualityParameter &rhs) const
String toXMLString(UInt indentation_level) const
QualityParameter(const QualityParameter &rhs)
QualityParameter()
Default constructor.
bool operator>(const QualityParameter &rhs) const
String value
Value.
Definition: QcMLFile.h:43
String unitRef
cv reference of the unit
Definition: QcMLFile.h:46
bool operator==(const QualityParameter &rhs) const
String cvRef
cv reference
Definition: QcMLFile.h:44
String unitAcc
cv accession of the unit
Definition: QcMLFile.h:47
String id
Identifier.
Definition: QcMLFile.h:42
String name
Name.
Definition: QcMLFile.h:41
String cvAcc
cv accession
Definition: QcMLFile.h:45
QualityParameter & operator=(const QualityParameter &rhs)
String flag
cv accession of the unit
Definition: QcMLFile.h:48
File adapter for QcML files used to load and store QcML files.
Definition: QcMLFile.h:35
std::map< String, std::vector< QualityParameter > > runQualityQPs_
Definition: QcMLFile.h:184
void addRunAttachment(const String &r, const Attachment &at)
Just adds a attachment to run by the name r.
void merge(const QcMLFile &addendum, const String &setname="")
merges the given QCFile into this one
std::vector< Attachment > ats_
Definition: QcMLFile.h:202
void addSetAttachment(const String &r, const Attachment &at)
Just adds a attachment to set by the name r.
String map2csv(const std::map< String, std::map< String, String > > &cvs_table, const String &separator) const
String exportQP(const String &filename, const String &qpname) const
Returns a String value in quotation of a qualityparameter by the name qpname in run/set by the name f...
void removeQualityParameter(const String &r, std::vector< String > &ids)
Just removes qualityparameter going by one of the ID attributes given in ids.
String exportQPs(const String &filename, const StringList &qpnames) const
Returns a String of a tab separated qualityparameter by the name qpname in run/set by the name filena...
void collectSetParameter(const String &setname, const String &qp, std::vector< String > &ret)
collects the values of given QPs (as CVid) of the given set
~QcMLFile() override
Destructor.
String name_
Definition: QcMLFile.h:198
std::vector< String > row_
Definition: QcMLFile.h:196
String tag_
Definition: QcMLFile.h:192
std::map< String, std::set< String > > setQualityQPs_members_
Definition: QcMLFile.h:188
void load(const String &filename)
Load a QCFile.
Attachment at_
Definition: QcMLFile.h:195
QualityParameter qp_
Definition: QcMLFile.h:194
void removeAllAttachments(const String &at)
Removes attachment with cv accession at from all runs/sets.
bool existsRun(const String &filename, bool checkname=false) const
Returns true if the given run id is present in this file, if checkname is true it also checks the nam...
void existsSetQualityParameter(const String &filename, const String &qpname, std::vector< String > &ids) const
Returns the ids of the parameter name given if found in given set, empty else.
void getRunIDs(std::vector< String > &ids) const
Gives the ids of the registered runs in the vector ids.
void registerRun(const String &id, const String &name)
Registers a run in the qcml file with the respective mappings.
void store(const String &filename) const
Store the QCFile.
UInt progress_
Definition: QcMLFile.h:193
void existsRunQualityParameter(const String &filename, const String &qpname, std::vector< String > &ids) const
Returns the ids of the parameter name given if found in given run empty else.
std::vector< QualityParameter > qps_
Definition: QcMLFile.h:201
std::map< String, std::vector< Attachment > > runQualityAts_
Definition: QcMLFile.h:185
void startElement(const XMLCh *const, const XMLCh *const, const XMLCh *const qname, const xercesc::Attributes &attributes) override
QcMLFile()
Default constructor.
String exportAttachment(const String &filename, const String &qpname) const
Returns a String of a tab separated rows if found empty string else from run/set by the name filename...
std::map< String, std::vector< Attachment > > setQualityAts_
Definition: QcMLFile.h:187
std::set< String > names_
Definition: QcMLFile.h:200
std::map< String, String > run_Name_ID_map_
Definition: QcMLFile.h:189
void removeAttachment(const String &r, std::vector< String > &ids, const String &at="")
Removes attachments referencing a id given in ids, from run/set r. All attachments if no attachment n...
String exportIDstats(const String &filename) const
void addSetQualityParameter(const String &r, const QualityParameter &qp)
Just adds a qualityparameter to set by the name r.
void characters(const XMLCh *const chars, const XMLSize_t length) override
void endElement(const XMLCh *const, const XMLCh *const, const XMLCh *const qname) override
bool existsSet(const String &filename, bool checkname=false) const
Returns true if the given set id is present in this file, if checkname is true it also checks the nam...
std::vector< String > header_
Definition: QcMLFile.h:197
std::map< String, std::vector< QualityParameter > > setQualityQPs_
Definition: QcMLFile.h:186
std::map< String, String > set_Name_ID_map_
Definition: QcMLFile.h:190
void registerSet(const String &id, const String &name, const std::set< String > &names)
Registers a set in the qcml file with the respective mappings.
void getRunNames(std::vector< String > &ids) const
Gives the names of the registered runs in the vector ids.
void collectQCData(std::vector< ProteinIdentification > &prot_ids, std::vector< PeptideIdentification > &pep_ids, const FeatureMap &feature_map, const ConsensusMap &consensus_map, const String &inputfile_raw, const bool remove_duplicate_features, const MSExperiment &exp)
Calculation and collection of QC data.
String run_id_
Definition: QcMLFile.h:199
void addRunQualityParameter(const String &r, const QualityParameter &qp)
Just adds a qualityparameter to run by the name r.
void removeAttachment(const String &r, const String &at)
Removes attachment with cv accession at from run/set r.
A more convenient string class.
Definition: String.h:34
unsigned int UInt
Unsigned integer type.
Definition: Types.h:64
std::vector< String > StringList
Vector of String.
Definition: ListUtils.h:44
Main OpenMS namespace.
Definition: openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19