This class represents the file unimod.xml
.
More...
#include <ms_umod_configfile.hpp>
Public Types | |
enum | MODFILE_FLAGS { MODFILE_FLAGS_EMPTY = 0x00000000 , MODFILE_FLAGS_REGULAR = 0x00000001 , MODFILE_FLAGS_HIDDEN = 0x00000002 , MODFILE_FLAGS_AASUBST = 0x00000004 , MODFILE_FLAGS_ALL = 0x7FFFFFFF } |
Flags for the type of modifications to retrieve. More... | |
Public Member Functions | |
ms_umod_configfile () | |
Default constructor. | |
ms_umod_configfile (const char *fileName, const char *schemaFileName, const ms_connection_settings *cs=0, bool useSchema=true) | |
Immediate action constructor that reads the XML file with the given name. | |
ms_umod_configfile (const ms_umod_configfile &right) | |
Copying constructor. | |
virtual | ~ms_umod_configfile () |
Desctructor. | |
void | appendAminoAcid (const ms_umod_aminoacid *aa) |
Adds a new amino acid at the end of the list. | |
void | appendElement (const ms_umod_element *elem) |
Adds a new element at the end of the list. | |
void | appendErrors (const ms_errors &src) |
Copies all errors from another instance and appends them at the end of own list. | |
void | appendModBrick (const ms_umod_modbrick *brick) |
Adds a new modification brick at the end of the list. | |
void | appendModification (const ms_umod_modification *mod) |
Adds a new modification at the end of the list. | |
void | applyVisibility (const ms_session *session) |
If visibility settings are present for this file and session then apply to the currently loaded list of modifications. | |
void | applyVisibility (const std::vector< int > &groupIds) |
If visibility settings are present for this file and these group ids, then apply to the currently loaded list of modifications. | |
void | clearAllErrors () |
Remove all errors from the current list of errors. | |
void | clearAminoAcids () |
Deletes all amino acids from the list. | |
void | clearElements () |
Deletes all elements from the list. | |
void | clearModBricks () |
Deletes all modification bricks from the list. | |
void | clearModifications () |
Deletes all modifications from the list. | |
void | copyFrom (const ms_errors *right) |
Use this member to make a copy of another instance. | |
void | copyFrom (const ms_umod_configfile *right) |
Copies all the information from another instance. | |
virtual void | defaultValues () |
Re-initialises the instance. | |
bool | deleteAminoAcidByName (const char *name) |
Remove an amino acid from the list in memory. | |
bool | deleteAminoAcidByNumber (const int idx) |
Remove an amino acid from the list in memory. | |
bool | deleteElementByName (const char *name) |
Remove an element from the list in memory. | |
bool | deleteElementByNumber (const int idx) |
Remove an element from the list in memory. | |
bool | deleteModBrickByName (const char *name) |
Remove a modification brick from the list in memory. | |
bool | deleteModBrickByNumber (const int idx) |
Remove a modification brick from the list in memory. | |
bool | deleteModificationByName (const char *name) |
Remove a modification from the list in memory. | |
bool | deleteModificationByNumber (const int idx) |
Remove a modification from the list in memory. | |
int | findModFileName (const char *modFileName) const |
Returns modification index by its mod_file -style name (like "Acetyl (K)"). | |
int | findModification (const char *modName) const |
Retrieves modification index by its plain name. | |
const ms_umod_aminoacid * | getAminoAcidByName (const char *name) const |
Returns an amino acid object by its name or NULL in case of not found. | |
const ms_umod_aminoacid * | getAminoAcidByNumber (const int idx) const |
Returns an amino acid object by its number. | |
ms_connection_settings | getConnectionSettings () const |
Returns the sessionID and proxy server for use with an HTTP transfer. | |
const ms_umod_element * | getElementByName (const char *name) const |
Returns an element object by its name or NULL in case of not found. | |
const ms_umod_element * | getElementByNumber (const int idx) const |
Returns an element object by its number. | |
const ms_errs * | getErrorHandler () const |
Retrive the error object using this function to get access to all errors and error parameters. | |
std::string | getFileName () const |
Returns the current file name. | |
int | getLastError () const |
Return the error description of the last error that occurred. | |
std::string | getLastErrorString () const |
Return the error description of the last error that occurred. | |
std::string | getMajorVersion () const |
Returns major document schema version as read from the file, otherwise the latest. | |
std::string | getMinorVersion () const |
Returns minor document schema version as read from the file, otherwise the latest. | |
const ms_umod_modbrick * | getModBrickByName (const char *name) const |
Returns a modification brick object by its name or NULL in case of not found. | |
const ms_umod_modbrick * | getModBrickByNumber (const int idx) const |
Returns an modification brick object by its number. | |
std::vector< std::string > | getModFileList (const unsigned int flags=MODFILE_FLAGS_ALL) const |
Returns an ordered list of modification names in mod_file-style, i.e. "Acetyl (K)" instead of "Acetyl". | |
const ms_umod_modification * | getModificationByName (const char *name) const |
Returns a modification object by its name or NULL in case of not found. | |
const ms_umod_modification * | getModificationByNumber (const int idx) const |
Returns a modification object by its number. | |
int | getNumberOfAminoAcids () const |
Returns a number of amino acids currently held in memory. | |
int | getNumberOfElements () const |
Returns a number of elements currently held in memory. | |
int | getNumberOfModBricks () const |
Returns a number of modification bricks currently held in memory. | |
int | getNumberOfModifications () const |
Returns a number of modifications currently held in memory. | |
std::string | getSchemaFileName () const |
Returns the current schema file name that is used to validate the XML file. | |
bool | isValid () const |
Call this function to determine if there have been any errors. | |
ms_umod_configfile & | operator= (const ms_umod_configfile &right) |
Assignment operator for C++ applications. | |
void | read_buffer (const char *buffer) |
Reads configuration information from a string buffer. | |
void | read_file () |
Reads configuration information from the XML file. | |
std::string | save_buffer (bool validateAgainstSchema=true) |
Creates a string representation of the XML document with all the content of the object. | |
void | save_file () |
Saves configuration information in the XML file (not mod_file ). | |
void | setConnectionSettings (const ms_connection_settings &cs) |
Sets the sessionID and proxy server for use with an HTTP transfer. | |
void | setFileName (const char *filename) |
Changes the file name for subsequent read/write operations (do not use it for saving in a mod_file !). | |
void | setMajorVersion (const std::string &version) |
Update the major document schema version. | |
void | setMinorVersion (const std::string &version) |
Update the minor document schema version. | |
void | setSchemaFileName (const char *name) |
Call this member to specify a custom schema file name for validating the XML file. | |
bool | updateAminoAcidByName (const char *name, const ms_umod_aminoacid *aa) |
Update the information for a specific amino acid. | |
bool | updateAminoAcidByNumber (const int idx, const ms_umod_aminoacid *aa) |
Update the information for a specific amino acid. | |
bool | updateElementByName (const char *name, const ms_umod_element *element) |
Update the information for a specific element. | |
bool | updateElementByNumber (const int idx, const ms_umod_element *element) |
Update the information for a specific element. | |
void | updateMasses () |
Recalculates all masses derived from elements (brick masses, modification deltas etc.). | |
bool | updateModBrickByName (const char *name, const ms_umod_modbrick *brick) |
Update the information for a specific modification brick. | |
bool | updateModBrickByNumber (const int idx, const ms_umod_modbrick *brick) |
Update the information for a specific modification brick. | |
bool | updateModificationByName (const char *name, const ms_umod_modification *mod) |
Update the information for a specific modification. | |
bool | updateModificationByNumber (const int idx, const ms_umod_modification *mod) |
Update the information for a specific modification. | |
std::string | validateDocument () const |
Validates the whole document against schema and returns errors as a string. | |
Static Public Member Functions | |
static std::string | getDefaultSchemaFileName () |
Returns the default schema filename (no path) | |
This class represents the file unimod.xml
.
The Unimod file comprises chemical elements, amino-acids and modifications. The file can be created from scratch, read from a disk file or retrieved from a remote location (HTTP) and then saved as a mod_file
or another unimod.xml
.
After reading a file and before using the object check validity by calling isValid() and retrieve error descriptions with getLastErrorString() if not valid. Similarly, after writing out the file, isValid() can be used to check if the file has been created correctly and is valid for further use.
enum MODFILE_FLAGS |
Flags for the type of modifications to retrieve.
See Using enumerated values and static const ints in Perl, Java, Python and C#.
The result of combining these flags is a union of modifications sets.
ms_umod_configfile | ( | const char * | fileName, |
const char * | schemaFileName, | ||
const ms_connection_settings * | cs = 0 , |
||
bool | useSchema = true |
||
) |
Immediate action constructor that reads the XML file with the given name.
An instance of this class is normally created using this form of the constructor.
fileName | represents either local file name (for example, "C:/unimod.xml") or a fully formed URL such as http://www.matrixscience.com/cgi . The filename may use backslashes or forward slashes on Windows and spaces in file or directory names are allowed. |
schemaFileName | is a local file name for the schema (for example, "C:/unimod_2.xsd"). The schema must be a local file – it cannot be accessed using HTTP. The schema filename may use backslashes or forward slashes on Windows and spaces in file or directory names are allowed. |
cs | a connection settings object for downloading the file from a Mascot server. This should contain a sessionID and optionally the proxy server settings. For a local file cs is not required and will be ignored. |
useSchema | specify whether it should use a xsd schema validator, true by default |
ms_umod_configfile | ( | const ms_umod_configfile & | src | ) |
Copying constructor.
src | another instance of this class to copy the content from. |
void appendAminoAcid | ( | const ms_umod_aminoacid * | aa | ) |
Adds a new amino acid at the end of the list.
Creates a new amino acid object, copies all content from the object supplied as a parameter and adds it at the end of the amino acids list.
aa | an instance of the amino acid object to copy content from. |
void appendElement | ( | const ms_umod_element * | elem | ) |
Adds a new element at the end of the list.
Creates a new element object, copies all content from the object supplied as a parameter and adds it at the end of the elements list.
elem | an instance of the element object to copy content from. |
|
inherited |
Copies all errors from another instance and appends them at the end of own list.
src | The object to copy the errors across from. See Maintaining object references: two rules of thumb. |
void appendModBrick | ( | const ms_umod_modbrick * | brick | ) |
Adds a new modification brick at the end of the list.
Creates a new modification brick object, copies all content from the object supplied as a parameter and adds it at the end of the modification bricks list.
brick | an instance of the modification brick object to copy content from. |
void appendModification | ( | const ms_umod_modification * | mod | ) |
Adds a new modification at the end of the list.
Creates a new modification object, copies all content from the object supplied as a parameter and adds it at the end of the modifications list.
mod | an instance of the modification object to copy content from. |
void applyVisibility | ( | const ms_session * | session | ) |
If visibility settings are present for this file and session then apply to the currently loaded list of modifications.
If visibility settings are present for this file and session then apply to the currently loaded list of modifications.
session | Optional session object used to apply user security restrictions. Can be NULL or not supplied. |
void applyVisibility | ( | const std::vector< int > & | groupIds | ) |
If visibility settings are present for this file and these group ids, then apply to the currently loaded list of modifications.
If visibility settings are present for this file and group ids then apply to the currently loaded list of modifications.
groupIds | vector of group ids to apply visibility for |
|
inherited |
Remove all errors from the current list of errors.
The list of 'errors' can include fatal errors, warning messages, information messages and different levels of debugging messages.
All messages are accumulated into a list in this object, until clearAllErrors() is called.
See Error Handling.
|
inherited |
Use this member to make a copy of another instance.
right | is the source to initialise from |
void copyFrom | ( | const ms_umod_configfile * | right | ) |
Copies all the information from another instance.
right | another instance of this class to copy the content from. |
|
virtual |
Re-initialises the instance.
After calling this method, all internal values will be reset to their defaults, as if the object had been freshly created with the default constructor.
This method, however, doesn't change file name, schema location and connection settings. If a complete cleanup is required, you need to do three additional calls:
umod_configfile.setFileName(""); umod_configfile.setSchemaFileName(""); umod_configfile.setConnectionSetting(ms_connection_settings());
bool deleteAminoAcidByName | ( | const char * | name | ) |
Remove an amino acid from the list in memory.
name | name of the amino acid for deletion. |
bool deleteAminoAcidByNumber | ( | const int | idx | ) |
Remove an amino acid from the list in memory.
idx | number of the amino acid for deletion from 0 to (getNumberOfAminoAcids() - 1). |
bool deleteElementByName | ( | const char * | name | ) |
Remove an element from the list in memory.
name | name of the element for deletion. |
bool deleteElementByNumber | ( | const int | idx | ) |
Remove an element from the list in memory.
idx | number of the element for deletion from 0 to (getNumberOfElements() - 1). |
bool deleteModBrickByName | ( | const char * | name | ) |
Remove a modification brick from the list in memory.
name | name of the modification brick for deletion. |
bool deleteModBrickByNumber | ( | const int | idx | ) |
Remove a modification brick from the list in memory.
idx | number of the modification brick for deletion from 0 to (getNumberOfModBricks() - 1). |
bool deleteModificationByName | ( | const char * | name | ) |
Remove a modification from the list in memory.
name | name of the modification for deletion. |
bool deleteModificationByNumber | ( | const int | idx | ) |
Remove a modification from the list in memory.
idx | number of the modification for deletion from 0 to (getNumberOfModifications() - 1). |
int findModFileName | ( | const char * | modFileName | ) | const |
Returns modification index by its mod_file
-style name (like "Acetyl (K)").
modFileName | modification string name. |
int findModification | ( | const char * | modName | ) | const |
Retrieves modification index by its plain name.
Tries to find modification by its name (not mod_file
-style name).
modName | modification string name. |
const ms_umod_aminoacid * getAminoAcidByName | ( | const char * | name | ) | const |
Returns an amino acid object by its name or NULL in case of not found.
name | a unique name of the amino acid. |
const ms_umod_aminoacid * getAminoAcidByNumber | ( | const int | idx | ) | const |
Returns an amino acid object by its number.
idx | number of the amino acid from 0 to (getNumberOfAminoAcids() - 1). |
|
static |
Returns the default schema filename (no path)
Static method to return the filename of the currently used schema
const ms_umod_element * getElementByName | ( | const char * | name | ) | const |
Returns an element object by its name or NULL in case of not found.
name | a unique name of the element. |
const ms_umod_element * getElementByNumber | ( | const int | idx | ) | const |
Returns an element object by its number.
idx | number of the element from 0 to (getNumberOfElements() - 1). |
|
inherited |
Retrive the error object using this function to get access to all errors and error parameters.
See Error Handling.
std::string getFileName | ( | ) | const |
Returns the current file name.
|
inherited |
Return the error description of the last error that occurred.
All errors are accumulated into a list in this object, until clearAllErrors() is called. This function returns the last error that occurred.
See Error Handling.
|
inherited |
Return the error description of the last error that occurred.
All errors are accumulated into a list in this object, until clearAllErrors() is called. This function returns the last error that occurred.
See Error Handling.
const ms_umod_modbrick * getModBrickByName | ( | const char * | name | ) | const |
Returns a modification brick object by its name or NULL in case of not found.
name | a unique name of the modification brick. |
const ms_umod_modbrick * getModBrickByNumber | ( | const int | idx | ) | const |
Returns an modification brick object by its number.
idx | number of the modification brick from 0 to (getNumberOfModBricks() - 1). |
std::vector< std::string > getModFileList | ( | const unsigned int | flags = MODFILE_FLAGS_ALL | ) | const |
Returns an ordered list of modification names in mod_file-style, i.e. "Acetyl (K)" instead of "Acetyl".
flags | can be one or more of the ms_umod_configfile::MODFILE_FLAGS values OR'ed together. |
const ms_umod_modification * getModificationByName | ( | const char * | name | ) | const |
Returns a modification object by its name or NULL in case of not found.
name | a unique name of the modification. |
const ms_umod_modification * getModificationByNumber | ( | const int | idx | ) | const |
Returns a modification object by its number.
idx | number of the modification from 0 to (getNumberOfModifications() - 1). |
int getNumberOfAminoAcids | ( | ) | const |
Returns a number of amino acids currently held in memory.
int getNumberOfElements | ( | ) | const |
Returns a number of elements currently held in memory.
int getNumberOfModBricks | ( | ) | const |
Returns a number of modification bricks currently held in memory.
int getNumberOfModifications | ( | ) | const |
Returns a number of modifications currently held in memory.
std::string getSchemaFileName | ( | ) | const |
Returns the current schema file name that is used to validate the XML file.
|
inherited |
Call this function to determine if there have been any errors.
This will return true unless there have been any fatal errors.
See Error Handling.
ms_umod_configfile & operator= | ( | const ms_umod_configfile & | right | ) |
Assignment operator for C++ applications.
right | another instance of this class to copy the content from. |
void read_buffer | ( | const char * | buffer | ) |
Reads configuration information from a string buffer.
This method is useful when reading configuration information from a mascor result file. Old content of the object will be removed and substituted with the information read from the buffer.
buffer | string buffer that contains a valid xml-document. It can be a document with just one modification in it, or only with amino acid masses. |
void read_file | ( | ) |
Reads configuration information from the XML file.
Downloads the file if necessary from the Unimod web site and parses it. Check for errors before using any other methods for retrieving content.
std::string save_buffer | ( | bool | validateAgainstSchema = true | ) |
Creates a string representation of the XML document with all the content of the object.
Creates a valid XML document and returns it as a string which can be used, for example, for writing out configuration information to mascot result file.
To produce a 'file' that validates against the schema, it is not sufficient to add, for example, just a modification because this will be missing keyrefs to elements and termini building 'bricks'.
If you choose not to validate against the schema, then it is sufficient to just output, say, a single modification.
validateAgainstSchema | specifies whether to validate against the schema. If true and the schema file exists and the resulting XML fails to validate, then an empty string will be returned and the errors will indicate why it failed to validate. |
void save_file | ( | ) |
Saves configuration information in the XML file (not mod_file
).
Check for errors after calling this method to see if the operation has been successful or to get any schema validation errors. If the document is not valid it is going to be saved anyway unless there are other problems.
If you want to validate document without actually saving it use validateDocument().
void setConnectionSettings | ( | const ms_connection_settings & | cs | ) |
Sets the sessionID and proxy server for use with an HTTP transfer.
This value would normally be passed in the constructor.
cs | is the new connection settings. |
void setFileName | ( | const char * | name | ) |
Changes the file name for subsequent read/write operations (do not use it for saving in a mod_file
!).
Calling this method does not mean an immediate update on disk. Use either read_file() or save_file() for that.
name | a new file location. |
void setSchemaFileName | ( | const char * | name | ) |
Call this member to specify a custom schema file name for validating the XML file.
name | a new file location (if empty default value will be assigned). |
bool updateAminoAcidByName | ( | const char * | name, |
const ms_umod_aminoacid * | aa | ||
) |
Update the information for a specific amino acid.
name | name of the amino acid for updating. |
aa | an object to copy the content from. |
bool updateAminoAcidByNumber | ( | const int | idx, |
const ms_umod_aminoacid * | aa | ||
) |
Update the information for a specific amino acid.
idx | number of the amino acid for updating from 0 to (getNumberOfAminoAcids() - 1). |
aa | an object to copy the content from. |
bool updateElementByName | ( | const char * | name, |
const ms_umod_element * | element | ||
) |
Update the information for a specific element.
name | name of the element for updating. |
element | an object to copy the content from. |
bool updateElementByNumber | ( | const int | idx, |
const ms_umod_element * | element | ||
) |
Update the information for a specific element.
idx | number of the element for updating from 0 to (getNumberOfElements() - 1). |
element | an object to copy the content from. |
bool updateModBrickByName | ( | const char * | name, |
const ms_umod_modbrick * | brick | ||
) |
Update the information for a specific modification brick.
name | name of the modification brick for updating. |
brick | an object to copy the content from. |
bool updateModBrickByNumber | ( | const int | idx, |
const ms_umod_modbrick * | brick | ||
) |
Update the information for a specific modification brick.
idx | number of the modification brick for updating from 0 to (getNumberOfModBricks() - 1). |
brick | an object to copy the content from. |
bool updateModificationByName | ( | const char * | name, |
const ms_umod_modification * | mod | ||
) |
Update the information for a specific modification.
name | name of the modification for updating. |
mod | an object to copy the content from. |
bool updateModificationByNumber | ( | const int | idx, |
const ms_umod_modification * | mod | ||
) |
Update the information for a specific modification.
idx | number of the modification for updating from 0 to (getNumberOfModifications() - 1). |
mod | an object to copy the content from. |
std::string validateDocument | ( | ) | const |
Validates the whole document against schema and returns errors as a string.
This method doesn't attempt to store the document anywhere and doesn't make the object invalid. Also, no errors are stored. Therefore, this method can be called as many times as necessary without any consequences.
All validation errors will be returned back as a string. However, the XML parser will describe errors in terms of row and column numbers as if the document was actually saved in a file.