Matrix Science header

config_quantitation.py

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

#!/usr/bin/python
##############################################################################
# file: config_quantitation.py                                               #
# 'msparser' toolkit example code                                            #
##############################################################################
# COPYRIGHT NOTICE                                                           #
# Copyright 1998-2010 Matrix Science Limited  All Rights Reserved.           #
#                                                                            #
##############################################################################
#     $Source: /vol/cvsroot/parser/examples/test_python/config_quantitation.py,v $  #
#     $Author: neilr $                                                       #
#       $Date: 2016/03/22 10:13:16 $                                         #
#   $Revision: 1.3 $                                                         #
# $NoKeywords::                                                            $ #
##############################################################################

import msparser
import sys

if len(sys.argv) < 2 :
    print("""
The location of quantitation.xml file has to be specified as a parameter.
The location should either be the full path to the quantitation.xml file
or a URL to a Mascot server - e.g. http://mascot-server/mascot/cgi
""")
    sys.exit(1)

if len(sys.argv) < 3 :
    print("""
The location of schema file quantitation_XXX.xsd has to be specified as the
second parameter. The location should only be a full or relative path to the
quantitation_XXX.xsd file.
""")
    sys.exit(1)

# A sessionID can optionally be passed as the third parameter.
# This will only be required if the 'file' is a URL.
if len(sys.argv) > 3 :
    cs = msparser.ms_connection_settings()
    cs.setSessionID(sys.argv[3])
    file = msparser.ms_quant_configfile(sys.argv[1], sys.argv[2], cs)
else :
    file = msparser.ms_quant_configfile(sys.argv[1], sys.argv[2])

if not file.isValid() :
    print("There are errors. Cannot continue. The last error description:")
    print(file.getLastErrorString())
    sys.exit(1)

n = file.getNumberOfMethods()
print("There are %d quantitation methods available:" % n)

for i in range(n) :
    print(file.getMethodByNumber(i).getName())

# Validate the original document.
errs = file.validateDocument()
if errs :
    print("Initial document validation errors: %s" % errs)

# Now try to read in the schema file.
schemaFile = msparser.ms_xml_schema()
schemaFile.setFileName(sys.argv[2])
schemaFile.read_file()

if not schemaFile.isValid() :
    print("Errors while reading schema-file. The last error description: %s" % schemaFile.getLastErrorString())
    sys.exit(1)

# The document can be validated programmatically, but this is different from
# real validation against a schema. We'll validate each quantitation
# method separately.
for i in range(n) :
    # Shallow validation: only check the presence of required attributes and
    # elements.
    pMethod = file.getMethodByNumber(i)

    errs = pMethod.validateShallow(schemaFile)
    if errs :
        print("Shallow validation errors (method %s): %s" % (pMethod.getName(), errs))
        
    # Deep validation: check attributes and elements recursively applying basic
    # constraints.
    errs = pMethod.validateDeep(schemaFile)
    if errs :
        print("Deep validation errors (method %s): %s" % (pMethod.getName(), errs))
        
# We can validate objects as well. First, copy the first method from the
# original file (method "null").
myMethodInvalid = msparser.ms_quant_method(file.getMethodByNumber(0))
# And set an invalid name with less than allowed string length.
myMethodInvalid.setName("")

# First way: use shallow and deep validation as above.
errs = myMethodInvalid.validateShallow(schemaFile)
if errs :
    print("Shallow validation of a method: %s" % errs)

errs = myMethodInvalid.validateDeep(schemaFile)
if errs :
    print("Deep validation of a method: %s" % errs)

# Second way: use the schema object. This is equivalent to the previous
# two-step process as long as you pass 'true' as the second parameter
# for deep validation.

errs = schemaFile.validateComplexObject(myMethodInvalid, 1)
if errs :
    print("Deep validation using schema-object: %s" % errs)

# Third way: validate an attribute separately. Available validation methods
# are validateSimpleInteger(), validateSimpleDouble(), validateSimpleBool()
# and validateSimpleString().
errs = schemaFile.validateSimpleString(myMethodInvalid.getName(), myMethodInvalid.getNameSchemaType())
if errs :
    print("Attribute validation: %s" % errs)

# Fourth way: validate an entire document. For this, we need to create
# a new document and append the invalid method definition.
configFileInvalid = msparser.ms_quant_configfile()
configFileInvalid.appendMethod(myMethodInvalid)

errs = configFileInvalid.validateDocument()
if errs :
    print("Document validation errors: %s" % errs)

# The config file object itself stays valid, even if it has an invalid
# method definition.
if not configFileInvalid.isValid() :
    # Control flow never comes here!
    print("Errors in config file object. The last error description: %s" % configFileInvalid.getLastErrorString())
    
# The file can be saved even if it has invalid definitions. 
configFileInvalid.setFileName("quantitation_temp.xml")
configFileInvalid.save_file()

if not configFileInvalid.isValid() :
    print("Failed to save: %s" % configFileInvalid.getLastErrorString())


"""

Running the program as 

python config_quantitation.pl /usr/local/mascot/config/quantitation.xml /usr/local/mascot/html/xmlns/schema/quantitation_2/quantitation_2.xsd

will give the following output under Mascot Server 2.3 (depending on how
quantitation methods have been configured): 


There are 26 quantitation methods available:
None
iTRAQ 4plex
iTRAQ 8plex
TMT 6plex
TMT 2plex
18O multiplex
SILAC K+6 R+6 multiplex
IPTL (Succinyl and IMID) multiplex
ICPL duplex pre-digest [MD]
ICPL duplex post-digest [MD]
ICPL triplex pre-digest [MD]
18O corrected [MD]
15N Metabolic [MD]
15N + 13C Metabolic [MD]
SILAC K+6 R+10 [MD]
SILAC K+6 R+10 Arg-Pro [MD]
SILAC K+6 R+6 [MD]
SILAC R+6 R+10 [MD]
SILAC K+8 R+10 [MD]
SILAC K+4 K+8 R+6 R+10 [MD]
ICAT ABI Cleavable [MD]
ICAT D8 [MD]
Dimethylation [MD]
NBS Shimadzu [MD]
Label-free [MD]
Average [MD]
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


"""

Copyright © 2016 Matrix Science Ltd.  All Rights Reserved. Generated on Fri Jun 2 2017 01:44:50