Example program for handling errors in the Mascot results files.
1
2
17
18import sys
19import msparser
20
21def main() :
22 if len(sys.argv) < 2 :
23 print("Must specify results filename as parameter")
24 return 1
25
26 file = msparser.ms_mascotresfilebase.createResfile(sys.argv[1])
27
28 if file.isValid() :
29 checkErrorHandler(file)
30 else :
31 print("Invalid file: %s" % file.getLastErrorString())
32
33
34
35def checkErrorHandler(resfile) :
36 """
37 Calls a couple of functions with invalid arguments, then prints
38 their error messages.
39 """
40
41 print("Testing the error handling... ")
42 print("=========================================")
43
44 numQueries = resfile.getNumQueries()
45 resfile.getObservedCharge(numQueries + 40);
46
47 print("Error number: %s" % resfile.getLastError())
48 print("Error string: %s" % resfile.getLastErrorString())
49
50 resfile.clearAllErrors()
51 print("Cleared all errors - should have no errors left: %s errors left" %resfile.getNumberOfErrors())
52
53 for x in range(1, 21) :
54 resfile.getObservedCharge(numQueries + x);
55
56
57 print("More errors added - there are now %s errors" % resfile.getNumberOfErrors())
58
59 for i in range(1, 1 + resfile.getNumberOfErrors()) :
60 print("Error number: %s : %s" % (resfile.getErrorNumber(i), resfile.getErrorString(i)))
61
62
63 print(" ")
64 resfile.clearAllErrors()
65
66
67
68if __name__ == "__main__":
69 sys.exit(main())
70
71""" Running the program as
72
73python resfile_error.py F981123.dat
74
75will give the following output:
76
77
78Testing the error handling...
79=========================================
80Error number: 4
81Error string: Query out of range. In function getObservedCharge. Request query 107, num queries: 67
82Cleared all errors - should have no errors left: 0 errors left
83More errors added - there are now 2 errors
84Error number: 4 : Query out of range. In function getObservedCharge. Request query 68, num queries: 67
85Error number: 4 : Query out of range. In function getObservedCharge. Request query 69, num queries: 67 (Error repeated 19 times)
86
87
88"""
89