/*****************************************************************************/ // Copyright (c) Illumina 2008 // Author: Richard Shaw // // This software is covered by the "Illumina Genome Analyzer Software // License Agreement" and the "Illumina Source Code License Agreement", // and certain third party copyright/licenses, and any user of this // source file is bound by the terms therein (see accompanying files // Illumina_Genome_Analyzer_Software_License_Agreement.pdf and // Illumina_Source_Code_License_Agreement.pdf and third party // copyright/license notices). /*****************************************************************************/ #include #include #include #include #include #include "common/Tile_List.h" #include "statistics/PAS_Options.h" using namespace CommandLine; /*****************************************************************************/ PAS_Options::PAS_Options() : CommandLine::Options(), my_input_compr_name("none"), my_input_compr(File_Buffer::compressionNone), my_tile_list_file_path_str("tiles.txt"), max_patterns_to_store(0) { ; } /*****************************************************************************/ PAS_Options::~PAS_Options() { ; } /*****************************************************************************/ int PAS_Options::getOptions(int argc, char* const argv[]) throw (CommandLine::UnknownOptionException, CommandLine::MissingOptionException, CommandLine::InvalidArgumentException) { const char* short_option_cstr = "heaz:O:Q:o:T:"; const struct option long_option_arr[] = { {"help", no_argument, 0, 'h'}, {"export_input", no_argument, 0, 'e'}, {"align_input", no_argument, 0, 'a'}, {"sample", required_argument, 0, 's'}, {"barcode", required_argument, 0, 'b'}, {"input_compr", required_argument, 0, 'z'}, {"output_dir", required_argument, 0, 'O'}, {"output_qualifier", required_argument, 0, 'Q'}, {"score_file", required_argument, 0, 'o'}, {"read_list", required_argument, 0, 'r'}, {"tile_list_file", required_argument, 0, 'T'}, {"stats_prefix", required_argument, 0, 'p'}, {"max_patterns_to_store", required_argument, 0, 'm'}, {0, 0, 0, 0} }; int long_option_index(0); int option(0); bool input_type_specified(false); // Note: case 'h' returns immediately. while (-1 != (option = getopt_long(argc, argv, short_option_cstr, long_option_arr, &long_option_index))) { switch (option) { case 0: break; case 'h': return usage(argc, argv); break; case 'e': // Input type must be specified exactly once (<1 checked below). if (input_type_specified) { const std::string msg_str("Multiple specification of input type"); throw InvalidArgumentException(msg_str); } input_type_specified = true; break; case 's': my_sample_name = optarg; break; case 'b': my_barcode = optarg; break; case 'z': my_input_compr_name = optarg; break; case 'O': my_output_dir_str = optarg; break; case 'Q': my_output_qualifier_str = optarg; break; case 'r': add_read(optarg); break; case 'T': my_tile_list_file_path_str = optarg; break; case 'p': my_stats_file_prefix = optarg; break; case 'm': max_patterns_to_store = atoi(optarg); break; case '?': case ':': default: throw UnknownOptionException(""); break; } } if (!input_type_specified) { throw MissingOptionException("No input type specified."); } if (my_read_list.empty()) { throw MissingOptionException("No read specified."); } return RUN; } /*****************************************************************************/ void PAS_Options::processOptions() throw (CommandLine::InvalidArgumentException) { std::string msg_str("input "); if (!resolve_compression(my_input_compr_name, my_input_compr, msg_str)) { BOOST_THROW_EXCEPTION(InvalidArgumentException(msg_str)); } } /*****************************************************************************/ void PAS_Options::getParameters(int argc, char* const argv[]) throw (CommandLine::InvalidArgumentException) { while (argc > optind) { const std::string arg_str(argv[optind++]); my_input_path_str_list.push_back(arg_str); } if (my_input_path_str_list.size() % my_read_list.size()) { throw InvalidArgumentException("The number of input files must be a multiple of the number of reads"); } } /*****************************************************************************/ int PAS_Options::usage(int , char* const arg_cstr_arr[], const std::string& msg_str) { if (0 != msg_str.size()) { std::cerr << "ERROR: " << msg_str << std::endl; } const std::string app_name(arg_cstr_arr[0]); std::ostringstream ostrm; ostrm << "Usage : " << app_name << " -h|--help" << std::endl << " OR : " << app_name << std::endl << " -e|--export_input " << std::endl << " | <-a|--align_input -o|--score_file >" << std::endl << "[-z|--input_compr ]" << std::endl << "{-r|--read READ}" << std::endl << "[-T|tile_list_file ]" << std::endl << " []" << std::endl; std::cerr << "INFO: " << ostrm.str() << std::endl; return NO_RUN; } /*****************************************************************************/ void PAS_Options::add_read(const std::string &read) { if (read.empty()) { throw InvalidArgumentException("Empty read"); } try { my_read_list.push_back(boost::lexical_cast(read)); } catch(boost::bad_lexical_cast &) { throw InvalidArgumentException("Invalid read: " + read); } }