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

Example program for handling errors in the Mascot results files.

/*
##############################################################################
# file: resfile_error.cpp #
# 'msparser' toolkit example code #
##############################################################################
# COPYRIGHT NOTICE #
# Copyright 1998-2005 Matrix Science Limited All Rights Reserved. #
# #
##############################################################################
# $Source: parser/examples/test_cxx/resfile_error.cpp $ #
# $Author: robertog@matrixscience.com $ #
# $Date: 2024-09-04 10:23:46 +0100 $ #
# $Revision: 526921a73137894bb1eae0b0fc8ccb4bb52ea662 | MSPARSER_REL_3_0_0-2024-09-24-0-g93ebaeb4f4 $ #
# $NoKeywords:: $ #
##############################################################################
*/
#include "msparser.hpp"
#include <iostream>
#include <time.h>
#include <iomanip>
// All the classes are part of the matrix_science namespace
using namespace matrix_science;
/*****************************************************************************/
/* Local functions */
/* (This test harness is 'C' and not C++) */
/*****************************************************************************/
static void checkErrorHandler(ms_mascotresfilebase & file);
/*****************************************************************************/
/* main */
/* Call this program with a single argument - the name of the .dat file */
/*****************************************************************************/
int main(int argc, char * argv[])
{
if (argc == 2)
{
ms_mascotresfilebase file = ms_mascotresfilebase::createResfile(argv[1]);
if (file.isValid())
{
checkErrorHandler(file);
}
else
std::cout << "Error: " << file.getLastErrorString() << std::endl;
}
else
std::cout << "Must supply the name of a .dat file as a command line argument" << std::endl;
return 0;
}
/*****************************************************************************/
/* checkErrorHandler */
/* Calls a couple of functions with invalid arguments */
/*****************************************************************************/
static void checkErrorHandler(ms_mascotresfilebase & file)
{
std::cout << "Testing the error handling... " << std::endl;
std::cout << "=========================================" << std::endl;
int numQueries = file.getNumQueries();
file.getObservedCharge(numQueries + 40); // Should fail
std::cout << "Error number: " << file.getLastError() << std::endl;
std::cout << "Error string: " << file.getLastErrorString() << std::endl;
std::cout << "Cleared all errors - should have no errors left: "
<< file.getNumberOfErrors()
<< " errors left"
<< std::endl << std::endl;
for (int x=1; x <= 20; x++)
file.getObservedCharge(numQueries + x); // Should fail
// Now, the best way, print out all errors.
std::cout << "More errors added - there are now "
<< " errors"
<< std::endl;
for (int i=1; i <= file.getNumberOfErrors(); i++)
{
std::cout << "Error number: "
<< file.getErrorNumber(i)
<< " : "
<< file.getErrorString(i)
<< std::endl;
}
std::cout << std::endl;
}
/*
will give the output:
# resfile_error_handling F981123.dat
Testing the error handling...
=========================================
Error number: 4
Error string: c:\inetpub\mascot\data\F981123.dat. Query out of range.
In function getObservedCharge. Request query 44, num queries: 4
Cleared all errors - should have no errors left: 0 errors left
More errors added - there are now 2 errors
Error number: 4 : c:\inetpub\mascot\data\F981123.dat. Query out of range. In function
getObservedCharge. Request query 5, num queries: 4
Error number: 4 : c:\inetpub\mascot\data\F981123.dat. Query out of range. In function
getObservedCharge. Request query 6, num queries: 4 (Error repeated 19 times)
*/
bool isValid() const
Call this function to determine if there have been any errors.
Definition: ms_errors.cpp:1472
void clearAllErrors()
Remove all errors from the current list of errors.
Definition: ms_errors.cpp:1457
Abstract base class of ms_mascotresfile_dat and ms_mascotresfile_msr.
Definition: ms_mascotresfilebase.hpp:72
std::string getLastErrorString() const
Return the last error number - or an empty string.
Definition: ms_mascotresfilebase.cpp:824
virtual int getObservedCharge(const int query, const bool decoy=false) const =0
The 'charge' returned will be 0 for Mr, otherwise it will be 1, -1, 2, -2, 3, -3 etc....
int getErrorNumber(const int num=-1) const
Return a specific error number - or ms_errs::ERR_NO_ERROR.
Definition: ms_mascotresfilebase.cpp:776
int getLastError() const
Return the last error number - or ms_erros::ERR_NO_ERROR.
Definition: ms_mascotresfilebase.cpp:786
std::string getErrorString(const int num) const
Return a specific error as a string.
Definition: ms_mascotresfilebase.cpp:814
virtual int getNumQueries(const int resfileID=0) const =0
Returns the number of queries (peptide masses or ms-ms spectra).
int getNumberOfErrors() const
Return the number of errors since the last call to clearAllErrors.
Definition: ms_mascotresfilebase.cpp:749