Matrix Science header

resfile_error.py

Example program for handling errors in the Mascot results files.

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

import sys
import msparser

def main() :
    if len(sys.argv) < 2 :  
        print("Must specify results filename as parameter")
        return 1

    file = msparser.ms_mascotresfile(sys.argv[1])

    if file.isValid() : 
        checkErrorHandler(file)
    else :
        print("Invalid file: %s" % file.getLastErrorString())



def checkErrorHandler(resfile) :
    """
    Calls a couple of functions with invalid arguments, then prints
    their error messages.
    """

    print("Testing the error handling...            ")
    print("=========================================")

    numQueries = resfile.getNumQueries()
    resfile.getObservedCharge(numQueries + 40);  # Should fail

    print("Error number: %s" % resfile.getLastError())
    print("Error string: %s" % resfile.getLastErrorString())

    resfile.clearAllErrors()
    print("Cleared all errors - should have no errors left: %s errors left" %resfile.getNumberOfErrors())
    
    for x in range(1, 21) :
        resfile.getObservedCharge(numQueries + x);  # Should fail
    
    # Now, the best way, print out all errors.
    print("More errors added - there are now %s errors" % resfile.getNumberOfErrors())

    for i in range(1, 1 + resfile.getNumberOfErrors()) :
        print("Error number: %s : %s" % (resfile.getErrorNumber(i), resfile.getErrorString(i)))
           

    print(" ")
    resfile.clearAllErrors()



if __name__ == "__main__":
    sys.exit(main())

""" Running the program as

python resfile_error.py F981123.dat

will give the following output:


Testing the error handling...            
=========================================
Error number: 4
Error string: Query out of range. In function getObservedCharge. Request query 107, num queries: 67
Cleared all errors - should have no errors left: 0 errors left
More errors added - there are now 2 errors
Error number: 4 : Query out of range. In function getObservedCharge. Request query 68, num queries: 67
Error number: 4 : Query out of range. In function getObservedCharge. Request query 69, num queries: 67 (Error repeated 19 times)


"""

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