OpenMS  3.0.0
ControlledVocabulary.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-2022.
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: Timo Sachsenberg $
32 // $Authors: Marc Sturm, Andreas Bertsch, Mathias Walzer $
33 // --------------------------------------------------------------------------
34 
35 #pragma once
36 
37 #include <OpenMS/DATASTRUCTURES/ListUtils.h> // StringList
40 
41 #include <set>
42 #include <map>
43 
44 namespace OpenMS
45 {
54  class OPENMS_DLLAPI ControlledVocabulary
55  {
56  friend OPENMS_DLLAPI std::ostream& operator<<(std::ostream& os, const ControlledVocabulary& cv);
57 
58 public:
60  struct OPENMS_DLLAPI CVTerm
61  {
63  enum XRefType
64  {
65  XSD_STRING = 0, // xsd:string A string
66  XSD_INTEGER, // xsd:integer Any integer
67  XSD_DECIMAL, // xsd:decimal Any real number
68  XSD_NEGATIVE_INTEGER, // xsd:negativeInteger Any negative integer
69  XSD_POSITIVE_INTEGER, // xsd:positiveInteger Any integer > 0
70  XSD_NON_NEGATIVE_INTEGER, // xsd:nonNegativeInteger Any integer >= 0
71  XSD_NON_POSITIVE_INTEGER, // xsd:nonPositiveInteger Any integer < 0
72  XSD_BOOLEAN, // xsd:boolean True or false
73  XSD_DATE, // xsd:date An XML-Schema date
74  XSD_ANYURI, // xsd:anyURI uniform resource identifier
76  };
77 
78  static String getXRefTypeName(XRefType type);
79  //static bool isSearchEngineSpecificScore();
80  static bool isHigherBetterScore(ControlledVocabulary::CVTerm term);
81 
84  std::set<String> parents;
85  std::set<String> children;
86  bool obsolete;
92  std::set<String> units;
93 
95  CVTerm();
96 
97  CVTerm(const CVTerm& rhs);
98 
99  CVTerm& operator=(const CVTerm& rhs);
100 
102  String toXMLString(const String& ref, const String& value = String("")) const;
103 
105  String toXMLString(const String& ref, const DataValue& value) const;
106 
107  };
108 
111 
113  virtual ~ControlledVocabulary();
114 
116  const String& name() const;
117 
119  const String& label() const;
120 
122  const String& version() const;
123 
125  const String& url() const;
126 
133  void loadFromOBO(const String& name, const String& filename);
134 
136  bool exists(const String& id) const;
137 
139  bool hasTermWithName(const String& name) const;
140 
146  const CVTerm& getTerm(const String& id) const;
147 
153  const CVTerm& getTermByName(const String& name, const String& desc = "") const;
154 
155 
157  const std::map<String, CVTerm>& getTerms() const;
158 
166  void getAllChildTerms(std::set<String>& terms, const String& parent_id) const;
167 
177  template <class LAMBDA>
178  bool iterateAllChildren(const String& parent_id, LAMBDA lbd) const
179  {
180  for (const auto& child_id : getTerm(parent_id).children)
181  {
182  if (lbd(child_id) || iterateAllChildren(child_id, lbd))
183  return true;
184  }
185  return false;
186  }
187 
193  const ControlledVocabulary::CVTerm* checkAndGetTermByName(const OpenMS::String& name) const;
194 
200  bool isChildOf(const String& child_id, const String& parent_id) const;
201 
202 
217  static const ControlledVocabulary& getPSIMSCV();
218 
219 protected:
225  bool checkName_(const String& id, const String& name, bool ignore_case = true) const;
226 
228  std::map<String, CVTerm> terms_;
230  std::map<String, String> namesToIds_;
239  };
240 
242  OPENMS_DLLAPI std::ostream& operator<<(std::ostream& os, const ControlledVocabulary& cv);
243 
244 
245 } // namespace OpenMS
246 
OpenMS::ControlledVocabulary::CVTerm::XSD_DECIMAL
Definition: ControlledVocabulary.h:67
OpenMS::ControlledVocabulary::CVTerm::XSD_INTEGER
Definition: ControlledVocabulary.h:66
OpenMS::ControlledVocabulary
Representation of a controlled vocabulary.
Definition: ControlledVocabulary.h:54
OpenMS::ControlledVocabulary::CVTerm::unparsed
StringList unparsed
Unparsed lines from the definition file.
Definition: ControlledVocabulary.h:89
OpenMS::DriftTimeUnit::NONE
No unit.
OpenMS::ControlledVocabulary::CVTerm::obsolete
bool obsolete
Flag that indicates of the term is obsolete.
Definition: ControlledVocabulary.h:86
OpenMS::String
A more convenient string class.
Definition: String.h:58
OpenMS::ControlledVocabulary::url_
String url_
CV URL.
Definition: ControlledVocabulary.h:238
OpenMS::ControlledVocabulary::CVTerm::XSD_NEGATIVE_INTEGER
Definition: ControlledVocabulary.h:68
ListUtils.h
OpenMS::ControlledVocabulary::CVTerm::XRefType
XRefType
define xsd types allowed in cv term to specify their value-type
Definition: ControlledVocabulary.h:63
OpenMS::ControlledVocabulary::CVTerm::xref_type
XRefType xref_type
xref value-type for the CV-term
Definition: ControlledVocabulary.h:90
OpenMS::ControlledVocabulary::namesToIds_
std::map< String, String > namesToIds_
Map from name to id.
Definition: ControlledVocabulary.h:230
OpenMS::ControlledVocabulary::CVTerm::id
String id
Identifier.
Definition: ControlledVocabulary.h:83
OpenMS::ControlledVocabulary::CVTerm::name
String name
if it is a score type, lookup has_order
Definition: ControlledVocabulary.h:82
OpenMS::ControlledVocabulary::CVTerm::XSD_BOOLEAN
Definition: ControlledVocabulary.h:72
OpenMS
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
Exception.h
OpenMS::ControlledVocabulary::name_
String name_
Name set in the load method.
Definition: ControlledVocabulary.h:232
OpenMS::DataValue
Class to hold strings, numeric values, lists of strings and lists of numeric values.
Definition: DataValue.h:58
OpenMS::ControlledVocabulary::CVTerm::synonyms
StringList synonyms
List of synonyms.
Definition: ControlledVocabulary.h:88
OpenMS::ControlledVocabulary::CVTerm::parents
std::set< String > parents
The parent IDs.
Definition: ControlledVocabulary.h:84
OpenMS::operator<<
std::ostream & operator<<(std::ostream &os, const AccurateMassSearchResult &amsr)
OpenMS::StringList
std::vector< String > StringList
Vector of String.
Definition: ListUtils.h:70
OpenMS::ControlledVocabulary::CVTerm::XSD_DATE
Definition: ControlledVocabulary.h:73
OpenMS::ControlledVocabulary::CVTerm::XSD_POSITIVE_INTEGER
Definition: ControlledVocabulary.h:69
OpenMS::ControlledVocabulary::CVTerm::XSD_NON_POSITIVE_INTEGER
Definition: ControlledVocabulary.h:71
OpenMS::ControlledVocabulary::CVTerm
Representation of a CV term.
Definition: ControlledVocabulary.h:60
OpenMS::ControlledVocabulary::terms_
std::map< String, CVTerm > terms_
Map from ID to CVTerm.
Definition: ControlledVocabulary.h:228
OpenMS::ControlledVocabulary::CVTerm::units
std::set< String > units
unit accession ids, defined by relationship has units
Definition: ControlledVocabulary.h:92
OpenMS::ControlledVocabulary::CVTerm::description
String description
Term description.
Definition: ControlledVocabulary.h:87
OpenMS::ControlledVocabulary::CVTerm::XSD_ANYURI
Definition: ControlledVocabulary.h:74
OpenMS::ControlledVocabulary::CVTerm::XSD_NON_NEGATIVE_INTEGER
Definition: ControlledVocabulary.h:70
OpenMS::ControlledVocabulary::label_
String label_
CV label.
Definition: ControlledVocabulary.h:234
OpenMS::ControlledVocabulary::iterateAllChildren
bool iterateAllChildren(const String &parent_id, LAMBDA lbd) const
Iterates over all children of parent recursively.
Definition: ControlledVocabulary.h:178
OpenMS::ControlledVocabulary::version_
String version_
CV version.
Definition: ControlledVocabulary.h:236
OpenMS::ControlledVocabulary::CVTerm::xref_binary
StringList xref_binary
xref binary-data-type for the CV-term (list of all allowed data value types for the current binary da...
Definition: ControlledVocabulary.h:91
StringListUtils.h
OpenMS::ControlledVocabulary::CVTerm::children
std::set< String > children
The child IDs.
Definition: ControlledVocabulary.h:85