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

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

1#!/usr/bin/python
2
16
17import msparser
18import sys
19
20if len(sys.argv) < 2 :
21 print("""
22The location of quantitation.xml file has to be specified as a parameter.
23The location should either be the full path to the quantitation.xml file
24or a URL to a Mascot server - e.g. http://mascot-server/mascot/cgi
25""")
26 sys.exit(1)
27
28if len(sys.argv) < 3 :
29 print("""
30The location of schema file quantitation_XXX.xsd has to be specified as the
31second parameter. The location should only be a full or relative path to the
32quantitation_XXX.xsd file.
33""")
34 sys.exit(1)
35
36# A sessionID can optionally be passed as the third parameter.
37# This will only be required if the 'file' is a URL.
38if len(sys.argv) > 3 :
39 cs = msparser.ms_connection_settings()
40 cs.setSessionID(sys.argv[3])
41 file = msparser.ms_quant_configfile(sys.argv[1], sys.argv[2], cs)
42else :
43 file = msparser.ms_quant_configfile(sys.argv[1], sys.argv[2])
44
45if not file.isValid() :
46 print("There are errors. Cannot continue. The last error description:")
47 print(file.getLastErrorString())
48 sys.exit(1)
49
50n = file.getNumberOfMethods()
51print("There are %d quantitation methods available:" % n)
52
53for i in range(n) :
54 print(file.getMethodByNumber(i).getName())
55
56# Validate the original document.
57errs = file.validateDocument()
58if errs :
59 print("Initial document validation errors: %s" % errs)
60
61# Now try to read in the schema file.
62schemaFile = msparser.ms_xml_schema()
63schemaFile.setFileName(sys.argv[2])
64schemaFile.read_file()
65
66if not schemaFile.isValid() :
67 print("Errors while reading schema-file. The last error description: %s" % schemaFile.getLastErrorString())
68 sys.exit(1)
69
70# The document can be validated programmatically, but this is different from
71# real validation against a schema. We'll validate each quantitation
72# method separately.
73for i in range(n) :
74 # Shallow validation: only check the presence of required attributes and
75 # elements.
76 pMethod = file.getMethodByNumber(i)
77
78 errs = pMethod.validateShallow(schemaFile)
79 if errs :
80 print("Shallow validation errors (method %s): %s" % (pMethod.getName(), errs))
81
82 # Deep validation: check attributes and elements recursively applying basic
83 # constraints.
84 errs = pMethod.validateDeep(schemaFile)
85 if errs :
86 print("Deep validation errors (method %s): %s" % (pMethod.getName(), errs))
87
88# We can validate objects as well. First, copy the first method from the
89# original file (method "null").
90myMethodInvalid = msparser.ms_quant_method(file.getMethodByNumber(0))
91# And set an invalid name with less than allowed string length.
92myMethodInvalid.setName("")
93
94# First way: use shallow and deep validation as above.
95errs = myMethodInvalid.validateShallow(schemaFile)
96if errs :
97 print("Shallow validation of a method: %s" % errs)
98
99errs = myMethodInvalid.validateDeep(schemaFile)
100if errs :
101 print("Deep validation of a method: %s" % errs)
102
103# Second way: use the schema object. This is equivalent to the previous
104# two-step process as long as you pass 'true' as the second parameter
105# for deep validation.
106
107errs = schemaFile.validateComplexObject(myMethodInvalid, True)
108if errs :
109 print("Deep validation using schema-object: %s" % errs)
110
111# Third way: validate an attribute separately. Available validation methods
112# are validateSimpleInteger(), validateSimpleDouble(), validateSimpleBool()
113# and validateSimpleString().
114errs = schemaFile.validateSimpleString(myMethodInvalid.getName(), myMethodInvalid.getNameSchemaType())
115if errs :
116 print("Attribute validation: %s" % errs)
117
118# Fourth way: validate an entire document. For this, we need to create
119# a new document and append the invalid method definition.
120configFileInvalid = msparser.ms_quant_configfile()
121configFileInvalid.appendMethod(myMethodInvalid)
122
123errs = configFileInvalid.validateDocument()
124if errs :
125 print("Document validation errors: %s" % errs)
126
127# The config file object itself stays valid, even if it has an invalid
128# method definition.
129if not configFileInvalid.isValid() :
130 # Control flow never comes here!
131 print("Errors in config file object. The last error description: %s" % configFileInvalid.getLastErrorString())
132
133# The file can be saved even if it has invalid definitions.
134configFileInvalid.setFileName("quantitation_temp.xml")
135configFileInvalid.save_file()
136
137if not configFileInvalid.isValid() :
138 print("Failed to save: %s" % configFileInvalid.getLastErrorString())
139
140
141"""
142
143Running the program as
144
145python config_quantitation.pl /usr/local/mascot/config/quantitation.xml /usr/local/mascot/html/xmlns/schema/quantitation_2/quantitation_2.xsd
146
147will give the following output under Mascot Server 2.3 (depending on how
148quantitation methods have been configured):
149
150
151There are 26 quantitation methods available:
152None
153iTRAQ 4plex
154iTRAQ 8plex
155TMT 6plex
156TMT 2plex
15718O multiplex
158SILAC K+6 R+6 multiplex
159IPTL (Succinyl and IMID) multiplex
160ICPL duplex pre-digest [MD]
161ICPL duplex post-digest [MD]
162ICPL triplex pre-digest [MD]
16318O corrected [MD]
16415N Metabolic [MD]
16515N + 13C Metabolic [MD]
166SILAC K+6 R+10 [MD]
167SILAC K+6 R+10 Arg-Pro [MD]
168SILAC K+6 R+6 [MD]
169SILAC R+6 R+10 [MD]
170SILAC K+8 R+10 [MD]
171SILAC K+4 K+8 R+6 R+10 [MD]
172ICAT ABI Cleavable [MD]
173ICAT D8 [MD]
174Dimethylation [MD]
175NBS Shimadzu [MD]
176Label-free [MD]
177Average [MD]
178Deep validation of a method: Attribute 'name' -> String is shorter than minLength-limit
179Deep validation using schema-object: Attribute 'name' -> String is shorter than minLength-limit
180Attribute validation: String is shorter than minLength-limit
181
182
183"""
184