Matrix Science header

config_modfile.cpp

Read in the modifications file - modfile.

/*
##############################################################################
# file: config_modfile.cpp                                                   #
# 'msparser' toolkit example code                                            #
##############################################################################
# COPYRIGHT NOTICE                                                           #
# Copyright 1998-2005 Matrix Science Limited  All Rights Reserved.           #
#                                                                            #
##############################################################################
#    $Source: /vol/cvsroot/parser/examples/test_cxx/config_modfile.cpp,v $ #
#     $Author: davidc $                                                      #
#       $Date: 2005/04/14 17:19:57 $                                         #
#   $Revision: 1.4 $                                                         #
# $NoKeywords::                                                            $ #
##############################################################################
*/


#include "msparser.hpp"

#include <iostream>


// All the classes are part of the matrix_science namespace
using namespace matrix_science;

int main(int argc, char * argv[])
{
    if ( argc < 2 )
    {
        std::cout << "The location of modifications file has to be specified as a parameter" << std::endl;
        std::cout << "The location should either be the full path to the modifications file" << std::endl;
        std::cout << "or a URL to a Mascot server - e.g. http://mascot-server/mascot/cgi" << std::endl;
        return 1;
    }

    // A sessionID can optionally be passed as the second parameter
    // This will only be required if the 'file' is a URL
    ms_connection_settings cs;
    if (argc > 2) 
    {
        cs.setSessionID(argv[2]);
    }

    // we need ms_masses class instance
    // in practice, it has to be also read from a disc file
    // but, for simplicity, we will use default masses
    ms_masses massesFile;

    ms_modfile file(argv[1], &massesFile, false, &cs);

    if ( !file.isValid() )
    {
        std::cout << "There are errors. Cannot continue. The last error description:" << std::endl;
        std::cout << file.getLastErrorString() << std::endl;
        return 1;
    }

    int n = file.getNumberOfModifications();
    std::cout << "There are " << n << " modifications configured:" << std::endl;

    // now get'em all!
    int i = 0;
    for(i=0; i < n; i++)
    {
        std::cout << file.getModificationByNumber(i)->getTitle() << std::endl;
    }

    // Now change Acetyl (K)
    ms_modification mod = *file.getModificationByName("Acetyl (K)");
    mod.setHidden(true);
    file.updateModificationByName("Acetyl (K)", mod);

    // And delete Methyl (R)
    file.deleteModificationByName("Methyl (R)");

    //Finally, save the file under a new name - but only if not http:
    if (strncmp("http:", argv[1], 5) != 0) {
        std::string filename = argv[1];
        filename +=  ".new";
        file.setFileName(filename.c_str());
        file.save_file();
    }
    std::cout << "There are now " << file.getNumberOfModifications() << " modifications configured:" << std::endl;

    return 0;
}


/*

will give the output, for instance: 


# config_modfile ../config/mod_file

There are 12 modifications configured:
Acetyl (N-term)
Acetyl (K)
Acetyl/Methyl (K)
Propionyl/Methyl (K)
Methyl (R)
Dimethyl (R)
Succininyl (K)
Succininyl+Methyl (K)
Biotinylated (N-term)
Biotinylated (K)
Carbamidomethyl (C)
Carbamyl (N-term)

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