// Constructor Input(int argc, char **argv) : ec_(false), shortestOnly_(false), distances_(false), suppressRef_(false), overlaps_(true), delim_("|"), refFile_(""), nonRefFile_(""), chr_("all") { typedef Ext::UserError UE; if ( 1 == argc ) throw(NoInput()); int argcntr = 1; bool outoption = false; // may choose up to one type of non-default output option // [Process-Flags] std::string next = ""; while ( argcntr < argc ) { next = argv[argcntr]; if ( next == "--help" ) throw(HelpException()); else if ( next == "--version" ) throw(VersionException()); else if ( next == "--ec" || next == "--header" ) ec_ = true; else if ( next == "--no-overlaps" ) overlaps_ = false; else if ( next == "--delim" ) { Ext::Assert<UE>(++argcntr < argc, "No value given for --delim."); delim_ = argv[argcntr]; } else if ( next == "--chrom" ) { Ext::Assert<UE>(++argcntr < argc, "No value given for --chrome."); chr_ = argv[argcntr]; } else if ( next == "--closest" ) { Ext::Assert<UE>(!outoption, "Multiple output options not allowed."); shortestOnly_ = true; outoption = true; } else if ( next == "--dist" ) distances_ = true; else if ( next == "--no-ref" ) suppressRef_ = true; else if ( next == "--help" ) throw(HelpException()); else if ( next == "--shortest" ) { // silently supported for bckwd compatibility Ext::Assert<UE>(!outoption, "Multiple output options not allowed."); shortestOnly_ = true; outoption = true; } else { // the rest are two input files? Ext::Assert<UE>(argcntr + 2 == argc, "Unknown option: " + next + "."); break; } ++argcntr; } // while Ext::Assert<UE>(argcntr + 2 == argc, "Not enough input files given."); refFile_ = argv[argcntr++]; nonRefFile_ = argv[argcntr]; Ext::Assert<UE>(refFile_.find("--") != 0, "Option given where file expected: " + refFile_ + "."); Ext::Assert<UE>(nonRefFile_.find("--") != 0, "Option given where file expected: " + nonRefFile_ + "."); }
Input::Input(int argc, char** argv) : _niters(1), _nstates(1), _nsymbols(0), _verbose(false), _read_params(false), _seed(std::time(NULL)) { for ( int i = 1; i < argc; ++i ) { if ( std::string(argv[i]) == "--help" ) throw(Help()); else if ( std::string(argv[i]) == "--version" ) throw(Version()); } // for if ( argc == 1 ) throw(NoInput()); if ( argc < 4 ) throw("Wrong number of args: see --help"); const std::string ints = "0123456789"; int nextc = 1; const std::string todo = argv[nextc++]; std::string next = argv[nextc++]; if ( todo == "train" || todo == "train-and-decode" ) { if ( (argc < 5) || (argc > 7) ) throw("Wrong number of args for '" + todo + ". See --help"); _operation = Ops::TRAIN; if ( todo == "train-and-decode" ) _operation = Ops::TRAIN_AND_DECODE; int count = argc; while ( next.find_first_of("--seed") == 0 || next.find_first_of("--verbose") == 0 ) { if ( --count == 0 ) break; if ( next == "--verbose" ) { _verbose = true; } else { auto v = split(next, "="); if ( v.size() != 2 ) throw("Bad number. Expect a +integer for " + next + ". See --help"); if ( v[1].find_first_not_of(ints) != std::string::npos ) throw("Bad number. Expect a +integer for " + next + ". See --help"); _seed = std::atoi(v[1].c_str()); std::srand(_seed); } if ( nextc != argc ) next = argv[nextc++]; else break; } // while if ( count != 5 ) throw("Wrong number (or order) of arguments for " + todo + ". See --help"); if ( next.find_first_not_of(ints) != std::string::npos ) throw("Bad argument: expect a +integer for <number-states>. See --help"); _nstates = std::atoi(next.c_str()); next = argv[nextc++]; if ( next.find_first_not_of(ints) != std::string::npos ) throw("Bad argument - expect a +integer for <number-iterations>. See --help"); _niters = std::atoi(next.c_str()); } else if ( todo == "probability" ) { if ( argc != 4 ) throw("Wrong number of args for '" + todo + ". See --help"); _operation = Ops::PROB; _params = next; std::ifstream f(_params.c_str()); if (!f) throw("Input file not found: " + _params); read_parameters(); } else if ( todo == "decode" ) { if ( argc != 4 ) throw("Wrong number of args for '" + todo + ". See --help"); _operation = Ops::DECODE; _params = next; std::ifstream f(_params.c_str()); if (!f) throw("Input file not found: " + _params); read_parameters(); } else { throw("Unknown operation: '" + todo + "'. See --help."); } if ( _niters <= 0 || _niters > _MAXITER ) throw("Bad number of '" + todo + "' iterations"); else if ( _nstates <= 0 || _nstates > _MAXSTATES ) throw("Bad number of '" + todo + "' states"); _src = argv[nextc++]; std::ifstream f(_src.c_str()); if (!f) throw("Input file not found: " + _src); read_data(); // read observations; get _nsymbols from the data if ( todo == "train" || todo == "train-and-decode" ) { initialize_parameters(); // only after read_data() due to _nsymbols if ( _nsymbols == 0 ) throw("Didn't find any data"); } }