OpenMS  2.8.0
MzTabBase.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-2020.
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: Oliver Alka $
32 // $Authors: Timo Sachsenberg, Oliver Alka $
33 // --------------------------------------------------------------------------
34 
35 #pragma once
36 
40 
41 
42 #include <map>
43 #include <vector>
44 #include <list>
45 #include <algorithm>
46 
47 
48 namespace OpenMS
49 {
58  {
64  };
65 
66  class OPENMS_DLLAPI MzTabDouble
67  {
68 public:
70 
71  explicit MzTabDouble(const double v);
72 
73  void set(const double& value);
74 
75  double get() const;
76 
78 
79  void fromCellString(const String& s);
80 
81  bool isNull() const;
82 
83  void setNull(bool b);
84 
85  bool isNaN() const;
86 
87  void setNaN();
88 
89  bool isInf() const;
90 
91  void setInf();
92 
93  ~MzTabDouble() = default;
94 
95  bool operator<(const MzTabDouble& rhs) const;
96 
97  bool operator==(const MzTabDouble& rhs) const;
98 
99 protected:
100  double value_;
102  };
103 
104  class OPENMS_DLLAPI MzTabDoubleList
105  {
106 public:
107  MzTabDoubleList() = default;
108 
109  bool isNull() const;
110 
111  void setNull(bool b);
112 
114 
115  void fromCellString(const String& s);
116 
117  std::vector<MzTabDouble> get() const;
118 
119  void set(const std::vector<MzTabDouble>& entries);
120 
121  ~MzTabDoubleList() = default;
122 protected:
123  std::vector<MzTabDouble> entries_;
124  };
125 
126  class OPENMS_DLLAPI MzTabInteger
127  {
128 public:
130 
131  explicit MzTabInteger(const int v);
132 
133  void set(const Int& value);
134 
135  Int get() const;
136 
138 
139  void fromCellString(const String& s);
140 
141  bool isNull() const;
142 
143  void setNull(bool b);
144 
145  bool isNaN() const;
146 
147  void setNaN();
148 
149  bool isInf() const;
150 
151  void setInf();
152 
153  ~MzTabInteger() = default;
154 protected:
157  };
158 
159  class OPENMS_DLLAPI MzTabIntegerList
160  {
161 public:
162  MzTabIntegerList() = default;
163 
164  bool isNull() const;
165 
166  void setNull(bool b);
167 
169 
170  void fromCellString(const String& s);
171 
172  std::vector<MzTabInteger> get() const;
173 
174  void set(const std::vector<MzTabInteger>& entries);
175 
176  ~MzTabIntegerList() = default;
177 protected:
178  std::vector<MzTabInteger> entries_;
179  };
180 
181  class OPENMS_DLLAPI MzTabBoolean
182  {
183 public:
185 
186  bool isNull() const;
187 
188  void setNull(bool b);
189 
190  explicit MzTabBoolean(bool v);
191 
192  void set(const bool& value);
193 
194  Int get() const;
195 
197 
198  void fromCellString(const String& s);
199 
200  ~MzTabBoolean() = default;
201 protected:
202  int value_;
203  };
204 
205  class OPENMS_DLLAPI MzTabString
206  {
207 public:
209 
210  explicit MzTabString(const String& s);
211 
212  bool isNull() const;
213 
214  void setNull(bool b);
215 
216  void set(const String& value);
217 
218  String get() const;
219 
221 
222  void fromCellString(const String& s);
223 
224  ~MzTabString() = default;
225 protected:
227  };
228 
229  typedef std::pair<String, MzTabString> MzTabOptionalColumnEntry; //< column name (not null able), value (null able)
230 
231  class OPENMS_DLLAPI MzTabParameter
232  {
233  public:
235 
236  bool isNull() const;
237 
238  void setNull(bool b);
239 
240  void setCVLabel(const String& CV_label);
241 
242  void setAccession(const String& accession);
243 
244  void setName(const String& name);
245 
246  void setValue(const String& value);
247 
249 
251 
252  String getName() const;
253 
254  String getValue() const;
255 
257 
258  void fromCellString(const String& s);
259 
260  ~MzTabParameter() = default;
261  protected:
266  };
267 
268  class OPENMS_DLLAPI MzTabParameterList
269  {
270  public:
271  MzTabParameterList() = default;
272 
273  bool isNull() const;
274 
275  void setNull(bool b);
276 
278 
279  void fromCellString(const String& s);
280 
281  std::vector<MzTabParameter> get() const;
282 
283  void set(const std::vector<MzTabParameter>& parameters);
284 
285  ~MzTabParameterList() = default;
286 
287  protected:
288  std::vector<MzTabParameter> parameters_;
289  };
290 
291  class OPENMS_DLLAPI MzTabStringList
292  {
293  public:
295 
296  bool isNull() const;
297 
298  void setNull(bool b);
299 
301  void setSeparator(char sep);
302 
304 
305  void fromCellString(const String& s);
306 
307  std::vector<MzTabString> get() const;
308 
309  void set(const std::vector<MzTabString>& entries);
310 
311  ~MzTabStringList() = default;
312  protected:
313  std::vector<MzTabString> entries_;
314  char sep_;
315  };
316 
317  class OPENMS_DLLAPI MzTabSpectraRef
318  {
319  public:
321 
322  bool isNull() const;
323 
324  void setNull(bool b);
325 
326  void setMSFile(Size index);
327 
328  void setSpecRef(const String& spec_ref);
329 
331 
332  Size getMSFile() const;
333 
334  void setSpecRefFile(const String& spec_ref);
335 
337 
338  void fromCellString(const String& s);
339 
340  ~MzTabSpectraRef() = default;
341  protected:
342  Size ms_run_; //< number is specified in the meta data section.
344  };
345 
346  // MTD
347  struct OPENMS_DLLAPI MzTabSoftwareMetaData
348  {
350  std::map<Size, MzTabString> setting;
351  };
352 
353  struct OPENMS_DLLAPI MzTabSampleMetaData
354  {
356  std::map<Size, MzTabParameter> species;
357  std::map<Size, MzTabParameter> tissue;
358  std::map<Size, MzTabParameter> cell_type;
359  std::map<Size, MzTabParameter> disease;
360  std::map<Size, MzTabParameter> custom;
361  };
362 
363  struct OPENMS_DLLAPI MzTabCVMetaData
364  {
369  };
370 
371  struct OPENMS_DLLAPI MzTabInstrumentMetaData
372  {
375  std::map<Size, MzTabParameter> analyzer;
377  };
378 
379  struct OPENMS_DLLAPI MzTabContactMetaData
380  {
384  };
385 
386  class OPENMS_DLLAPI MzTabBase
387  {
388  public:
389  MzTabBase() = default;
390  virtual ~MzTabBase() = default;
391 
392  protected:
394  template <typename SectionRows>
395  std::vector<String> getOptionalColumnNames_(const SectionRows& rows) const
396  {
397  // vector is used to preserve the column order
398  std::vector<String> names;
399  if (!rows.empty())
400  {
401  for (typename SectionRows::const_iterator it = rows.begin(); it != rows.end(); ++it)
402  {
403  for (auto it_opt = it->opt_.cbegin(); it_opt != it->opt_.cend(); ++it_opt)
404  {
405  if (std::find(names.begin(), names.end(), it_opt->first) == names.end())
406  {
407  names.push_back(it_opt->first);
408  }
409  }
410  }
411  }
412  return names;
413  }
414  };
415 } // namespace OpenMS
Definition: MzTabBase.h:387
virtual ~MzTabBase()=default
MzTabBase()=default
std::vector< String > getOptionalColumnNames_(const SectionRows &rows) const
Helper function for "get...OptionalColumnNames" functions.
Definition: MzTabBase.h:395
Definition: MzTabBase.h:182
String toCellString() const
void fromCellString(const String &s)
void set(const bool &value)
bool isNull() const
int value_
Definition: MzTabBase.h:202
void setNull(bool b)
Definition: MzTabBase.h:105
std::vector< MzTabDouble > entries_
Definition: MzTabBase.h:123
String toCellString() const
void fromCellString(const String &s)
std::vector< MzTabDouble > get() const
void set(const std::vector< MzTabDouble > &entries)
Definition: MzTabBase.h:67
MzTabCellStateType state_
Definition: MzTabBase.h:101
bool isNaN() const
double value_
Definition: MzTabBase.h:100
String toCellString() const
void fromCellString(const String &s)
MzTabDouble(const double v)
~MzTabDouble()=default
bool operator==(const MzTabDouble &rhs) const
bool operator<(const MzTabDouble &rhs) const
void set(const double &value)
bool isNull() const
void setNull(bool b)
double get() const
bool isInf() const
Definition: MzTabBase.h:160
void set(const std::vector< MzTabInteger > &entries)
String toCellString() const
void fromCellString(const String &s)
std::vector< MzTabInteger > get() const
std::vector< MzTabInteger > entries_
Definition: MzTabBase.h:178
Definition: MzTabBase.h:127
MzTabCellStateType state_
Definition: MzTabBase.h:156
bool isNaN() const
Int value_
Definition: MzTabBase.h:155
String toCellString() const
void fromCellString(const String &s)
MzTabInteger(const int v)
bool isNull() const
void setNull(bool b)
void set(const Int &value)
bool isInf() const
Definition: MzTabBase.h:269
void set(const std::vector< MzTabParameter > &parameters)
String toCellString() const
void fromCellString(const String &s)
std::vector< MzTabParameter > parameters_
Definition: MzTabBase.h:288
std::vector< MzTabParameter > get() const
Definition: MzTabBase.h:232
String CV_label_
Definition: MzTabBase.h:262
String getValue() const
String name_
Definition: MzTabBase.h:264
String toCellString() const
void fromCellString(const String &s)
String getCVLabel() const
void setName(const String &name)
void setCVLabel(const String &CV_label)
String getAccession() const
String getName() const
String accession_
Definition: MzTabBase.h:263
String value_
Definition: MzTabBase.h:265
void setAccession(const String &accession)
void setValue(const String &value)
Definition: MzTabBase.h:318
void setMSFile(Size index)
String getSpecRef() const
String spec_ref_
Definition: MzTabBase.h:343
String toCellString() const
void fromCellString(const String &s)
Size ms_run_
Definition: MzTabBase.h:342
void setSpecRefFile(const String &spec_ref)
void setSpecRef(const String &spec_ref)
Definition: MzTabBase.h:292
std::vector< MzTabString > get() const
String toCellString() const
void setSeparator(char sep)
needed for e.g. ambiguity_members and GO accessions as these use ',' as separator while the others us...
void fromCellString(const String &s)
char sep_
Definition: MzTabBase.h:314
std::vector< MzTabString > entries_
Definition: MzTabBase.h:313
void set(const std::vector< MzTabString > &entries)
Definition: MzTabBase.h:206
String toCellString() const
void fromCellString(const String &s)
~MzTabString()=default
void set(const String &value)
String value_
Definition: MzTabBase.h:226
bool isNull() const
String get() const
MzTabString(const String &s)
void setNull(bool b)
A more convenient string class.
Definition: String.h:60
int Int
Signed integer type.
Definition: Types.h:102
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:127
MzTabCellStateType
Base functionality to for MzTab data models.
Definition: MzTabBase.h:58
@ SIZE_OF_MZTAB_CELLTYPE
Definition: MzTabBase.h:63
@ MZTAB_CELLSTATE_NULL
Definition: MzTabBase.h:60
@ MZTAB_CELLSTATE_INF
Definition: MzTabBase.h:62
@ MZTAB_CELLSTATE_NAN
Definition: MzTabBase.h:61
@ MZTAB_CELLSTATE_DEFAULT
Definition: MzTabBase.h:59
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
MzTabParameter software
Definition: MzTabBase.h:349
MzTabString url
Definition: MzTabBase.h:368
MzTabString email
Definition: MzTabBase.h:383
MzTabString full_name
Definition: MzTabBase.h:366
MzTabString name
Definition: MzTabBase.h:381
MzTabString label
Definition: MzTabBase.h:365
MzTabParameter source
Definition: MzTabBase.h:374
std::map< Size, MzTabParameter > disease
Definition: MzTabBase.h:359
std::map< Size, MzTabString > setting
Definition: MzTabBase.h:350
std::map< Size, MzTabParameter > tissue
Definition: MzTabBase.h:357
MzTabString description
Definition: MzTabBase.h:355
MzTabParameter detector
Definition: MzTabBase.h:376
std::map< Size, MzTabParameter > cell_type
Definition: MzTabBase.h:358
MzTabString affiliation
Definition: MzTabBase.h:382
std::map< Size, MzTabParameter > custom
Definition: MzTabBase.h:360
MzTabParameter name
Definition: MzTabBase.h:373
std::pair< String, MzTabString > MzTabOptionalColumnEntry
Definition: MzTabBase.h:229
MzTabString version
Definition: MzTabBase.h:367
std::map< Size, MzTabParameter > species
Definition: MzTabBase.h:356
std::map< Size, MzTabParameter > analyzer
Definition: MzTabBase.h:375
Definition: MzTabBase.h:364
Definition: MzTabBase.h:380
Definition: MzTabBase.h:372
Definition: MzTabBase.h:354
Definition: MzTabBase.h:348