Matrix Science Mascot Parser toolkit
 
Loading...
Searching...
No Matches
config_quantitation.cpp

Example program for reading and manipulating the quantitation.xml file.

/*
##############################################################################
# file: config_quantitation.cpp #
# 'msparser' toolkit example code #
##############################################################################
# COPYRIGHT NOTICE #
# Copyright 1998-2005 Matrix Science Limited All Rights Reserved. #
# #
##############################################################################
# $Source: parser/examples/test_cxx/config_quantitation.cpp $ #
# $Author: villek@matrixscience.com $ #
# $Date: 2018-07-30 16:23:53 +0100 $ #
# $Revision: 1b450440f9c97e1e41d0fc6016a27d68951d4532 | MSPARSER_REL_3_0_0-2024-09-24-0-g93ebaeb4f4 $ #
# $NoKeywords:: $ #
##############################################################################
*/
#include "msparser.hpp"
#include <iostream>
// All the classes are part of the matrix_science namespace
using namespace matrix_science;
int main(int argc, char * argv[])
{
if ( argc < 3 )
{
std::cout << "The location of quantitation.xml file has to be specified as a parameter" << std::endl;
std::cout << "The location should either be the full path to the file" << std::endl;
std::cout << "or a URL to a Mascot server - e.g. http://mascot-server/mascot/cgi" << std::endl;
std::cout << "The second parameter should specify schema file path, for instance C:\\quantitation_1.xsd" << std::endl;
std::cout << "It should be either relative to the local quantitation.xml path or to the current folder" << std::endl;
return 1;
}
// A sessionID can optionally be passed as the third parameter
// This will only be required if the 'file' is a URL
if (argc > 3)
{
cs.setSessionID(argv[3]);
}
ms_quant_configfile file(argv[1], argv[2], &cs);
if (!file.isValid())
{
std::cout << "There are errors. Cannot continue. The last error description:" << std::endl;
std::cout << file.getLastErrorString() << std::endl;
return 1;
}
int n = file.getNumberOfMethods();
std::cout << "There are " << n << " methods available:" << std::endl;
// now get'em all!
int i = 0;
for(i=0; i < n; i++)
{
std::cout << file.getMethodByNumber(i)->getName() << std::endl;
}
// now try to retrieve typeinfo from the schema file
ms_xml_schema schemaFile;
schemaFile.setFileName(argv[2]);
schemaFile.read_file();
if (!schemaFile.isValid())
{
std::cout << "Errors while reading schema-file. The last error description:" << std::endl;
std::cout << schemaFile.getLastErrorString() << std::endl;
return 1;
}
// validate the original document
std::string strValidationErrors = file.validateDocument();
if ( !strValidationErrors.empty() )
{
printf("Initial document validation errors: %s\n", strValidationErrors.c_str());
}
// the document can be validated programmatically
// but it is not schema-validation!!!
for(i = 0; i < n; i++)
{
// Shallow validation: we check only presence of required attributes and elements
const ms_quant_method *pMethod = file.getMethodByNumber(i);
std::string strErrors = pMethod->validateShallow(&schemaFile); // pass the schema object as a parameter
if ( !strErrors.empty() )
{
printf("Method %s\n", pMethod->getName().c_str());
printf("Shallow validation errors: %s\n\n", strErrors.c_str());
}
// Deep validation: we check attributes and elements recursively applying basic constraints
strErrors = pMethod->validateDeep(&schemaFile);
if ( !strErrors.empty() )
{
printf("Method %s\n", pMethod->getName().c_str());
printf("Deep validation errors: %s\n\n", strErrors.c_str());
}
}
// create a new invalid document
ms_quant_configfile configFileInvalid;
// copy the first method from the original file (method "null")
ms_quant_method myMethodInvalid(*file.getMethodByNumber(0));
myMethodInvalid.setName(""); // invalid name with less than allowed string length
// one way to validate an object
// 1. shallow validation - only presence of attributes and elements is checked
std::string strErr1 = myMethodInvalid.validateShallow(&schemaFile);
printf("shallow validation of a method: %s\n", strErr1.c_str());
// 2. deep validation - data types of attributes and elements are checked and a base type too
std::string strErr2 = myMethodInvalid.validateDeep(&schemaFile);
printf("deep validation of a method: %s\n", strErr2.c_str());
// another way to validate an object - by using schema-object (not schema-document!!!)
// the result is absolutely equivalent to the previous call
std::string strErr3 = schemaFile.validateComplexObject(&myMethodInvalid, true); // "true" for deep validation
printf("deep validation using schema-object: %s\n", strErr3.c_str());
// one can validate an attribute separately
// also methods validateSimpleInteger(), validateSimpleDouble() and validateSimpleBool() can be used
std::string strErr4 = schemaFile.validateSimpleString(myMethodInvalid.getName().c_str(), // attribute value
myMethodInvalid.getNameSchemaType().c_str()); // attribute data type
printf("attribute validation: %s\n", strErr4.c_str());
// and finally, the whole document validation
configFileInvalid.appendMethod(&myMethodInvalid);
std::string errMethod = configFileInvalid.validateDocument();
printf("document validation errors: %s\n", errMethod.c_str());
// however, the config-file object itself stays valid
if (!configFileInvalid.isValid())
{
std::cout << "Errors in config-file object. The last error description:" << std::endl;
std::cout << configFileInvalid.getLastErrorString() << std::endl;
}
// file is going to be saved even if its invalid
// but the errors will be stored in the config-file object and the object will become invalid
configFileInvalid.setFileName("quantitation_temp.xml"); // give it another name
configFileInvalid.save_file();
if (!configFileInvalid.isValid())
{
std::cout << "Errors in config-file object. The last error description:" << std::endl;
std::cout << configFileInvalid.getLastErrorString() << std::endl;
}
return 0;
}
/*
will give the output, for instance:
# config_quantitation ../config/quantitation.xml quantitation_1.xsd
There are 10 methods available:
None
iTRAQ
ICAT C+9
ICPL C+6 pre-digest
ICPL C+6 post-digest
SILAC K+6 R+10
18O corrected, single scan
18O simple, single scan
SILAC K+6 R+4 multiplex
15N Metabolic
shallow validation of a method:
deep validation of a method: Attribute 'name' -> String is shorter than minLength-limit
deep validation using schema-object: Attribute 'name' -> String is shorter than minLength-limit
attribute validation: String is shorter than minLength-limit
document validation errors: XML library failure with error: quantitation.xml: line 4, col 240 - Datatype error: Type:InvalidDatatypeValueException, Message:Value '' with length '0' is less than minimum length facet of '1' .
Errors in config-file object. The last error description:
Failed to save quantitation configuration file
*/
Settings required to make an HTTP connection to a Mascot server.
Definition: ms_connection_settings.hpp:54
void setSessionID(const std::string sessionID)
Sets the Mascot security sessionID to be used for the connection.
Definition: ms_connection_settings.cpp:242
std::string getLastErrorString() const
Return the error description of the last error that occurred.
Definition: ms_errors.cpp:1488
bool isValid() const
Call this function to determine if there have been any errors.
Definition: ms_errors.cpp:1472
Use this class in order to read/write quantitation.xml.
Definition: ms_quant_configfile.hpp:52
int getNumberOfMethods() const
Returns a number of quantitation methods currently held in memory.
Definition: ms_quant_configfile.cpp:294
void save_file()
Stores modification information in the file.
Definition: ms_quant_configfile.cpp:245
std::string validateDocument() const
Validates the whole document against the schema and return errors as a string.
Definition: ms_quant_configfile.cpp:286
void appendMethod(const ms_quant_method *item)
Adds a new quantitation method at the end of the list.
Definition: ms_quant_configfile.cpp:310
const ms_quant_method * getMethodByNumber(const int idx) const
Returns a quantitation method object by its number.
Definition: ms_quant_configfile.cpp:319
void setFileName(const char *name)
Call this member to set a custom file name to read from a different location.
Definition: ms_quant_configfile.cpp:123
An object of this class represent a single quantitation method from quantitation.xml.
Definition: ms_quant_method.hpp:51
virtual std::string validateShallow(const ms_xml_schema *pSchemaFileObj) const
Performs simple validation of the top-level elements only.
Definition: ms_quant_method.cpp:120
std::string getName() const
Returns the value of the name attribute.
Definition: ms_quant_method.cpp:923
void setName(const char *value)
Set a custom value for the name attribute.
Definition: ms_quant_method.cpp:931
virtual std::string validateDeep(const ms_xml_schema *pSchemaFileObj) const
Performs validation of all child elements in addition to 'shallow' validation.
Definition: ms_quant_method.cpp:148
std::string getNameSchemaType() const
Obtain a symbolic name for the "name attribute" schema type.
Definition: ms_quant_method.cpp:950