From aeb76d31b423fe382b925b27de6aaf626cddc1e0 Mon Sep 17 00:00:00 2001 From: Henric Zazzi Date: Fri, 11 Apr 2014 12:17:56 +0200 Subject: [PATCH] updated for windows compatibility --- CMakeLists.txt | 4 +-- global.h | 32 +++++++++++++++++++++- main.cpp | 74 ++++++++++++++++++++++++++------------------------ xmlio.h | 1 - 4 files changed, 71 insertions(+), 40 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f1db55e..4ee6a66 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,7 +10,7 @@ set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake) set(POUT2MZIML_VERSION_MAJOR "0") set(POUT2MZIML_VERSION_MINOR "2") -set(POUT2MZIML_VERSION_PATCH "6") +set(POUT2MZIML_VERSION_PATCH "7") configure_file( version_config.h.in ${CMAKE_BINARY_DIR}/version_config.h ) @@ -41,7 +41,7 @@ include_directories(${XSD_INCLUDE_DIR}) SET (Boost_ADDITIONAL_VERSIONS "1.36" "1.36.0" "1.41" "1.41.0" "1.39" "1.39.0" "1.42.0" "1.42" "1.43.0" "1.43." "1.44.0" "1.44.0" "1.45.0" "1.45" "1.46.0" "1.46" "1.47.0" "1.47") -find_package(Boost COMPONENTS filesystem system REQUIRED) +find_package(Boost COMPONENTS filesystem system program_options REQUIRED) if(Boost_FOUND) message(STATUS "Package Boost-${Boost_VERSION} found : ${Boost_INCLUDE_DIR}") else(Boost_FOUND) diff --git a/global.h b/global.h index a298797..0ffa9ea 100644 --- a/global.h +++ b/global.h @@ -41,7 +41,37 @@ namespace global { } } //------------------------------------------------------------------------------ -// strings used for reporting error messages and status +// strings used for options +//------------------------------------------------------------------------------ +namespace CMDOPTIONS { + const char HELP_OPTION[]="help,h"; + const char HELP_TEST[]="help"; + const char HELP_TEXT[]="Displays available commands\n"; + const char PERCOLATORFILE_OPTION[]="percolatorfile,p"; + const char PERCOLATORFILE_TEST[]="percolatorfile"; + const char PERCOLATORFILE_TEXT[]="Percolator Out XML result file\n"; + const char MZIDFILE_OPTION[]="mzidfile,m"; + const char MZIDFILE_TEST[]="mzidfile"; + const char MZIDFILE_TEXT[]="MzIdentML input file\n"; + const char MZIDOUTPUT_OPTION[]="output,o"; + const char MZIDOUTPUT_TEST[]="output"; + const char MZIDOUTPUT_TEXT[]="Outputs the results to original filename+[File]+.mzid.\n" + "DEFAULT: output to stdout\n"; + const char MZIDFILES_OPTION[]="filesmzid,f"; + const char MZIDFILES_TEST[]="filesmzid"; + const char MZIDFILES_TEXT[]="File containing a list of mzIdentML filenames\n"; + const char DECOY_OPTION[]="decoy,d"; + const char DECOY_TEST[]="decoy"; + const char DECOY_TEXT[]="Only adds results to entries with decoy set to true. DEFAULT: false\n"; + const char VALIDATION_OPTION[]="validate,v"; + const char VALIDATION_TEST[]="validate"; + const char VALIDATION_TEXT[]="Sets that validation of XML schema should not be performed. Faster parsing.\n"; + const char WARNING_OPTION[]="warning,w"; + const char WARNING_TEST[]="warning"; + const char WARNING_TEXT[]="Sets that upon warning the software should terminate.\n"; + } +//------------------------------------------------------------------------------ +// strings used for reporting error messages, status //------------------------------------------------------------------------------ namespace PRINT_TEXT { const char HELP[]="pout2mzid [OPTIONS]\n" diff --git a/main.cpp b/main.cpp index d55f23c..850b4fb 100644 --- a/main.cpp +++ b/main.cpp @@ -17,8 +17,10 @@ #include "version_config.h" #include "xmlio.h" +#include "boost/program_options.hpp" //------------------------------------------------------------------------------ +namespace prgm_opt=boost::program_options; PercolatorOutI percolator; MzIDIO mzid; boost::unordered_map pout_values; @@ -30,44 +32,44 @@ void CleanUp(bool exitvalue) { } //------------------------------------------------------------------------------ int main(int argc, char **argv) { - int opt; + prgm_opt::variables_map option_map; + prgm_opt::options_description options("Options"); try { - while ((opt=getopt(argc,argv,"o::m:p:f:vdhw")) != EOF) - switch(opt) { - case 'd': - percolator.setDecoy(); - break; - case 'v': - percolator.unsetValidation(); - mzid.unsetValidation(); - break; - case 'o': - mzid.setOutputFileEnding(optarg?optarg:MZID_PARAM::FILE_END_DEFAULT); - break; - case 'p': - if (!percolator.setFilename(optarg)) - THROW_ERROR_VALUE(PRINT_TEXT::NO_PERCOLATOR_FILE,optarg); - break; - case 'm': - mzid.setFilename(optarg); - break; - case 'f': - if (!mzid.addFilenames(optarg)) - THROW_ERROR_VALUE(PRINT_TEXT::NO_MZID_FILE,optarg); - break; - case 'w': - mzid.unsetWarningFlag(); - break; - case 'h': - case '?': - printVersion(); - cout << PRINT_TEXT::HELP << endl; - CleanUp(EXIT_SUCCESS); - break; - default: - CleanUp(EXIT_SUCCESS); - } + prgm_opt::arg="[File]"; + options.add_options() + (CMDOPTIONS::HELP_OPTION,CMDOPTIONS::HELP_TEXT) + (CMDOPTIONS::PERCOLATORFILE_OPTION,prgm_opt::value()->required(),CMDOPTIONS::PERCOLATORFILE_TEXT) + (CMDOPTIONS::MZIDFILE_OPTION,prgm_opt::value()->required(),CMDOPTIONS::MZIDFILE_TEXT) + (CMDOPTIONS::MZIDOUTPUT_OPTION,prgm_opt::value()->required(),CMDOPTIONS::MZIDOUTPUT_TEXT) + (CMDOPTIONS::MZIDFILES_OPTION,prgm_opt::value()->required(),CMDOPTIONS::MZIDFILES_TEXT) + (CMDOPTIONS::DECOY_OPTION,CMDOPTIONS::DECOY_TEXT) + (CMDOPTIONS::VALIDATION_OPTION,CMDOPTIONS::VALIDATION_TEXT) + (CMDOPTIONS::WARNING_OPTION,CMDOPTIONS::WARNING_TEXT); + prgm_opt::store(prgm_opt::parse_command_line(argc,argv,options),option_map); + if (option_map.count(CMDOPTIONS::HELP_TEST)) { + printVersion(); + cout << options; + CleanUp(EXIT_SUCCESS); + } + if (option_map.count(CMDOPTIONS::DECOY_TEST)) + percolator.setDecoy(); + if (option_map.count(CMDOPTIONS::VALIDATION_TEST)) { + percolator.unsetValidation(); + mzid.unsetValidation(); + } + if (option_map.count(CMDOPTIONS::MZIDOUTPUT_TEST)) + mzid.setOutputFileEnding(option_map[CMDOPTIONS::MZIDOUTPUT_TEST].as()); + if (option_map.count(CMDOPTIONS::PERCOLATORFILE_TEST)) + if (!percolator.setFilename(option_map[CMDOPTIONS::PERCOLATORFILE_TEST].as())) + THROW_ERROR_VALUE(PRINT_TEXT::NO_PERCOLATOR_FILE,option_map[CMDOPTIONS::PERCOLATORFILE_TEST].as()); + if (option_map.count(CMDOPTIONS::MZIDFILE_TEST)) + mzid.setFilename(option_map[CMDOPTIONS::MZIDFILE_TEST].as()); + if (option_map.count(CMDOPTIONS::MZIDFILES_TEST)) + if (!mzid.addFilenames(option_map[CMDOPTIONS::MZIDFILES_TEST].as())) + THROW_ERROR_VALUE(PRINT_TEXT::NO_MZID_FILE,option_map[CMDOPTIONS::MZIDFILES_TEST].as()); + if (option_map.count(CMDOPTIONS::WARNING_TEST)) + mzid.unsetWarningFlag(); if (!mzid.checkFilenames()) CleanUp(EXIT_FAILURE); if (percolator.noFilename()) diff --git a/xmlio.h b/xmlio.h index c3a82ce..071f69d 100644 --- a/xmlio.h +++ b/xmlio.h @@ -43,7 +43,6 @@ using namespace std; namespace MZID_PARAM { const char SCHEMA_NAME[]="http://psidev.info/psi/pi/mzIdentML/1.1"; const char SCHEMA[]="mzIdentML1.1.0.xsd"; - const char FILE_END_DEFAULT[]="_output"; enum ELEMENT_TYPE { USERPARAM,CVPARAM }; namespace ELEMENT_DATA {