OpenMS
ControlledVocabulary Class Reference

#include <OpenMS/FORMAT/ControlledVocabulary.h>

Collaboration diagram for ControlledVocabulary:
[legend]

Classes

struct  CVTerm
 Representation of a CV term. More...
 

Public Member Functions

 ControlledVocabulary ()
 Constructor. More...
 
virtual ~ControlledVocabulary ()
 Destructor. More...
 
const Stringname () const
 Returns the CV name (set in the load method) More...
 
const Stringlabel () const
 Returns the CV label (set in the load method) More...
 
const Stringversion () const
 Returns the CV version (set in the load method) More...
 
const Stringurl () const
 Returns the CV url (set in the load method) More...
 
void loadFromOBO (const String &name, const String &filename)
 Loads the CV from an OBO file. More...
 
bool exists (const String &id) const
 Returns true if the term is in the CV. Returns false otherwise. More...
 
bool hasTermWithName (const String &name) const
 Returns true if a term with the given name is in the CV. Returns false otherwise. More...
 
const CVTermgetTerm (const String &id) const
 Returns a term specified by ID. More...
 
const CVTermgetTermByName (const String &name, const String &desc="") const
 Returns a term specified by name. More...
 
const std::map< String, CVTerm > & getTerms () const
 returns all the terms stored in the CV More...
 
void getAllChildTerms (std::set< String > &terms, const String &parent_id) const
 Writes all child terms recursively into terms. More...
 
template<class LAMBDA >
bool iterateAllChildren (const String &parent_id, LAMBDA lbd) const
 Iterates over all children (incl. subchildren etc) of parent recursively, i.e. the whole subtree. More...
 
const ControlledVocabulary::CVTermcheckAndGetTermByName (const OpenMS::String &name) const
 Searches the existing terms for the given name. More...
 
bool isChildOf (const String &child_id, const String &parent_id) const
 Returns if child is a child of parent. More...
 

Static Public Member Functions

static const ControlledVocabularygetPSIMSCV ()
 Returns a CV for parsing/storing PSI-MS related data, e.g. mzML, or handle accessions/ids in datastructures. More...
 

Protected Member Functions

bool checkName_ (const String &id, const String &name, bool ignore_case=true) const
 checks if a name corresponds to an id More...
 

Protected Attributes

std::map< String, CVTermterms_
 Map from ID to CVTerm. More...
 
std::map< String, StringnamesToIds_
 Map from name to id. More...
 
String name_
 Name set in the load method. More...
 
String label_
 CV label. More...
 
String version_
 CV version. More...
 
String url_
 CV URL. More...
 

Friends

std::ostream & operator<< (std::ostream &os, const ControlledVocabulary &cv)
 Print the contents to a stream. More...
 

Detailed Description

@brief Representation of a controlled vocabulary.

This representation only contains the information used for parsing and validation.
All other lines are stored in the @em unparsed member of the CVTerm struct.

Constructor & Destructor Documentation

◆ ControlledVocabulary()

Constructor.

◆ ~ControlledVocabulary()

virtual ~ControlledVocabulary ( )
virtual

Destructor.

Member Function Documentation

◆ checkAndGetTermByName()

const ControlledVocabulary::CVTerm* checkAndGetTermByName ( const OpenMS::String name) const

Searches the existing terms for the given name.

Returns
const Pointer to found term. When term is not found, returns nullptr

◆ checkName_()

bool checkName_ ( const String id,
const String name,
bool  ignore_case = true 
) const
protected

checks if a name corresponds to an id

If the term is not known, 'true' is returned!

◆ exists()

bool exists ( const String id) const

Returns true if the term is in the CV. Returns false otherwise.

◆ getAllChildTerms()

void getAllChildTerms ( std::set< String > &  terms,
const String parent_id 
) const

Writes all child terms recursively into terms.

If parent has child this method writes them recursively into the term object

Exceptions
Exception::InvalidValueis thrown if the term is not present

◆ getPSIMSCV()

static const ControlledVocabulary& getPSIMSCV ( )
static

Returns a CV for parsing/storing PSI-MS related data, e.g. mzML, or handle accessions/ids in datastructures.

The CV will be initialized on first access. Repeated access is therefor cheap.

It consists of the following CVs:

  • PSI-MS (psi-ms.obo)
  • PATO (quality.obo)
  • UO (unit.obo)
  • BTO (CV/brenda.obo)
  • GO (goslim_goa.obo)

◆ getTerm()

const CVTerm& getTerm ( const String id) const

Returns a term specified by ID.

Exceptions
Exception::InvalidValueis thrown if the term is not present

◆ getTermByName()

const CVTerm& getTermByName ( const String name,
const String desc = "" 
) const

Returns a term specified by name.

Exceptions
Exception::InvalidValueis thrown if the term is not present

◆ getTerms()

const std::map<String, CVTerm>& getTerms ( ) const

returns all the terms stored in the CV

◆ hasTermWithName()

bool hasTermWithName ( const String name) const

Returns true if a term with the given name is in the CV. Returns false otherwise.

◆ isChildOf()

bool isChildOf ( const String child_id,
const String parent_id 
) const

Returns if child is a child of parent.

Exceptions
Exception::InvalidValueis thrown if one of the terms is not present

◆ iterateAllChildren()

bool iterateAllChildren ( const String parent_id,
LAMBDA  lbd 
) const
inline

Iterates over all children (incl. subchildren etc) of parent recursively, i.e. the whole subtree.

Parameters
parent_idId of parent (to be passed to getTerm(), to obtain its children).
lbdFunction that gets the child-Ids passed. Must return bool. Used for comparisons and / or to set captured variables. If the lambda returns true, the iteration is exited prematurely. E.g. if you have found your search, you don't need to continue searching. Otherwise, if you want to go through the whole tree (e.g. to fill a vector) you can just return false always to not quit early.

◆ label()

const String& label ( ) const

Returns the CV label (set in the load method)

◆ loadFromOBO()

void loadFromOBO ( const String name,
const String filename 
)

Loads the CV from an OBO file.

Exceptions
Exception::FileNotFoundis thrown if the file could not be opened
Exception::ParseErroris thrown if an error occurs during parsing

◆ name()

const String& name ( ) const

Returns the CV name (set in the load method)

◆ url()

const String& url ( ) const

Returns the CV url (set in the load method)

◆ version()

const String& version ( ) const

Returns the CV version (set in the load method)

Friends And Related Function Documentation

◆ operator<<

std::ostream& operator<< ( std::ostream &  os,
const ControlledVocabulary cv 
)
friend

Print the contents to a stream.

Member Data Documentation

◆ label_

String label_
protected

CV label.

◆ name_

String name_
protected

Name set in the load method.

◆ namesToIds_

std::map<String, String> namesToIds_
protected

Map from name to id.

◆ terms_

std::map<String, CVTerm> terms_
protected

Map from ID to CVTerm.

◆ url_

String url_
protected

CV URL.

◆ version_

String version_
protected

CV version.