OpenMS  2.8.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-2021.
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, Axel Walter $
32 // $Authors: Mathias Walzer $
33 // --------------------------------------------------------------------------
34 
35 #pragma once
36 
39 #include <OpenMS/FORMAT/XMLFile.h>
41 #include <vector>
42 
43 namespace OpenMS
44 {
45  class ConsensusMap;
46  class FeatureMap;
47 
57  class OPENMS_DLLAPI QcMLFile :
58  public Internal::XMLHandler,
59  public Internal::XMLFile,
60  public ProgressLogger
61  {
62 public:
64  class OPENMS_DLLAPI QualityParameter
65  {
66  public:
75 
78 
80 
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  class OPENMS_DLLAPI Attachment
91  {
92  public:
102  std::vector<String> colTypes;
103  std::vector< std::vector<String> > tableRows;
104  //~ TODO -schema- coltypes with full definition (uintRef, unitAcc)
105 
108 
109  Attachment(const Attachment& rhs);
110 
112  bool operator==(const Attachment& rhs) const;
113  bool operator<(const Attachment& rhs) const;
114  bool operator>(const Attachment& rhs) const;
115 
116  String toXMLString(UInt indentation_level) const;
117  String toCSVString(String separator) const;
118  };
119 
123  ~QcMLFile() override;
124 
125  String map2csv(const std::map< String, std::map<String, String> >& cvs_table, const String& separator) const;
126  String exportIDstats(const String& filename) const;
127 
129  void registerRun(const String id, const String name);
131  void registerSet(const String id, const String name, const std::set<String>& names);
141  void removeAttachment(String r, std::vector<String>& ids, String at = "");
147  void removeQualityParameter(String r, std::vector<String>& ids);
149  void merge(const QcMLFile & addendum, String setname = "");
151  void/* std::vector<String>& */ collectSetParameter(const String setname, const String qp, std::vector<String>& ret);
153  String exportAttachment(const String filename, const String qpname) const;
155  String exportQP(const String filename, const String qpname) const;
157  String exportQPs(const String filename, const StringList qpnames) const;
159  void getRunIDs (std::vector<String>& ids) const;
161  void getRunNames (std::vector<String>& ids) const;
163  bool existsRun(const String filename, bool checkname = false) const;
165  bool existsSet(const String filename, bool checkname = false) const;
167  void existsRunQualityParameter(const String filename, const String qpname, std::vector<String>& ids) const;
169  void existsSetQualityParameter(const String filename, const String qpname, std::vector<String>& ids) const;
171 
181  void collectQCData(std::vector<ProteinIdentification>& prot_ids,
182  std::vector<PeptideIdentification>& pep_ids,
183  const FeatureMap& feature_map,
184  const ConsensusMap& consensus_map,
185  const String& inputfile_raw,
186  const bool remove_duplicate_features,
187  const MSExperiment& exp);
189 
193  void store(const String& filename) const;
194 
196  void load(const String & filename);
197 
198  //~ int siz; //debug
199 
200 protected:
201  // Docu in base class
202  void endElement(const XMLCh * const /*uri*/, const XMLCh * const /*local_name*/, const XMLCh * const qname) override;
203 
204  // Docu in base class
205  void startElement(const XMLCh * const /*uri*/, const XMLCh * const /*local_name*/, const XMLCh * const qname, const xercesc::Attributes & attributes) override;
206 
207  // Docu in base class
208  void characters(const XMLCh * const chars, const XMLSize_t length) override;
209 
210  std::map<String, std::vector< QualityParameter > > runQualityQPs_; //TODO run name attribute to schema of RunQuality
211  std::map<String, std::vector< Attachment > > runQualityAts_;
212  std::map<String, std::vector< QualityParameter > > setQualityQPs_;
213  std::map<String, std::vector< Attachment > > setQualityAts_;
214  std::map<String, std::set< String > > setQualityQPs_members_;
215  std::map<String, String > run_Name_ID_map_;
216  std::map<String, String > set_Name_ID_map_;
217 
222  std::vector<String> row_;
223  std::vector<String> header_;
226  std::set<String> names_;
227  std::vector<QualityParameter> qps_;
228  std::vector<Attachment> ats_;
229  };
230 
231 } // namespace OpenMS
A container for consensus elements.
Definition: ConsensusMap.h:90
A container for features.
Definition: FeatureMap.h:106
Base class for loading/storing XML files that have a handler derived from XMLHandler.
Definition: XMLFile.h:49
Base class for XML handlers.
Definition: XMLHandler.h:325
In-Memory representation of a mass spectrometry run.
Definition: MSExperiment.h:73
Base class for all classes that want to report their progress.
Definition: ProgressLogger.h:53
Representation of an attachment.
Definition: QcMLFile.h:91
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:101
String value
Value.
Definition: QcMLFile.h:95
String unitRef
cv reference of the unit
Definition: QcMLFile.h:98
String cvRef
cv reference
Definition: QcMLFile.h:96
String unitAcc
cv accession of the unit
Definition: QcMLFile.h:99
String id
Name.
Definition: QcMLFile.h:94
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:100
std::vector< String > colTypes
type of the cols if QP has a table of values
Definition: QcMLFile.h:102
String name
Name.
Definition: QcMLFile.h:93
Attachment()
Default constructor.
String cvAcc
cv accession
Definition: QcMLFile.h:97
std::vector< std::vector< String > > tableRows
cell values if QP has a table, type see colType
Definition: QcMLFile.h:103
String toCSVString(String separator) const
bool operator>(const Attachment &rhs) const
Representation of a quality parameter.
Definition: QcMLFile.h:65
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:69
String unitRef
cv reference of the unit
Definition: QcMLFile.h:72
bool operator==(const QualityParameter &rhs) const
String cvRef
cv reference
Definition: QcMLFile.h:70
String unitAcc
cv accession of the unit
Definition: QcMLFile.h:73
String id
Identifier.
Definition: QcMLFile.h:68
String name
Name.
Definition: QcMLFile.h:67
String cvAcc
cv accession
Definition: QcMLFile.h:71
QualityParameter & operator=(const QualityParameter &rhs)
String flag
cv accession of the unit
Definition: QcMLFile.h:74
File adapter for QcML files used to load and store QcML files.
Definition: QcMLFile.h:61
std::map< String, std::vector< QualityParameter > > runQualityQPs_
Definition: QcMLFile.h:210
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 removeAllAttachments(String at)
Removes attachment with cv accession at from all runs/sets.
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...
std::vector< Attachment > ats_
Definition: QcMLFile.h:228
String map2csv(const std::map< String, std::map< String, String > > &cvs_table, const String &separator) const
void merge(const QcMLFile &addendum, String setname="")
merges the given QCFile into this one
void addRunAttachment(String r, Attachment at)
Just adds a attachment to run by the name r.
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...
~QcMLFile() override
Destructor.
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...
String name_
Definition: QcMLFile.h:224
std::vector< String > row_
Definition: QcMLFile.h:222
void addSetQualityParameter(String r, QualityParameter qp)
Just adds a qualityparameter to set by the name r.
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.
String tag_
Definition: QcMLFile.h:218
std::map< String, std::set< String > > setQualityQPs_members_
Definition: QcMLFile.h:214
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...
void load(const String &filename)
Load a QCFile.
Attachment at_
Definition: QcMLFile.h:221
QualityParameter qp_
Definition: QcMLFile.h:220
void registerRun(const String id, const String name)
Registers a run in the qcml file with the respective mappings.
void getRunIDs(std::vector< String > &ids) const
Gives the ids of the registered runs in the vector ids.
void store(const String &filename) const
Store the QCFile.
UInt progress_
Definition: QcMLFile.h:219
std::vector< QualityParameter > qps_
Definition: QcMLFile.h:227
std::map< String, std::vector< Attachment > > runQualityAts_
Definition: QcMLFile.h:211
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.
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 startElement(const XMLCh *const, const XMLCh *const, const XMLCh *const qname, const xercesc::Attributes &attributes) override
QcMLFile()
Default constructor.
std::map< String, std::vector< Attachment > > setQualityAts_
Definition: QcMLFile.h:213
std::set< String > names_
Definition: QcMLFile.h:226
std::map< String, String > run_Name_ID_map_
Definition: QcMLFile.h:215
void collectSetParameter(const String setname, const String qp, std::vector< String > &ret)
collects the values of given QPs (as CVid) of the given set
String exportIDstats(const String &filename) const
void characters(const XMLCh *const chars, const XMLSize_t length) override
void endElement(const XMLCh *const, const XMLCh *const, const XMLCh *const qname) override
std::vector< String > header_
Definition: QcMLFile.h:223
std::map< String, std::vector< QualityParameter > > setQualityQPs_
Definition: QcMLFile.h:212
void removeAttachment(String r, String at)
Removes attachment with cv accession at from run/set r.
std::map< String, String > set_Name_ID_map_
Definition: QcMLFile.h:216
void addRunQualityParameter(String r, QualityParameter qp)
Just adds a qualityparameter to run by the name r.
void addSetAttachment(String r, Attachment at)
Just adds a attachment to set by the name r.
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:225
void removeAttachment(String r, std::vector< String > &ids, String at="")
Removes attachments referencing a id given in ids, from run/set r. All attachments if no attachment n...
void removeQualityParameter(String r, std::vector< String > &ids)
Just removes qualityparameter going by one of the ID attributes given in ids.
A more convenient string class.
Definition: String.h:60
unsigned int UInt
Unsigned integer type.
Definition: Types.h:94
std::vector< String > StringList
Vector of String.
Definition: ListUtils.h:70
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47