Exemple #1
0
void OptionGroupOptions::OptionParsingStarting(
    ExecutionContext *execution_context) {
  std::set<OptionGroup *> group_set;
  OptionInfos::iterator pos, end = m_option_infos.end();
  for (pos = m_option_infos.begin(); pos != end; ++pos) {
    OptionGroup *group = pos->option_group;
    if (group_set.find(group) == group_set.end()) {
      group->OptionParsingStarting(execution_context);
      group_set.insert(group);
    }
  }
}
Exemple #2
0
Error OptionGroupOptions::OptionParsingFinished(
    ExecutionContext *execution_context) {
  std::set<OptionGroup *> group_set;
  Error error;
  OptionInfos::iterator pos, end = m_option_infos.end();
  for (pos = m_option_infos.begin(); pos != end; ++pos) {
    OptionGroup *group = pos->option_group;
    if (group_set.find(group) == group_set.end()) {
      error = group->OptionParsingFinished(execution_context);
      group_set.insert(group);
      if (error.Fail())
        return error;
    }
  }
  return error;
}
 void collect()
 {
     if( !m_finalized && m_first_group )
     {
         m_first_group->collect( m_option_map );
     }
 }
 void fill_default()
 {
     if( !m_finalized && m_first_group )
     {
         m_first_group->fill_default();
     }
 }
Exemple #5
0
int
main(int argc, char *argv[])
{
    OptionParser parser = create_common_options( USAGE, DESCRIPTION, false );
    
    OptionGroup group = OptionGroup( parser, "Options for bayes", "These options will change the behaviour of bayes and fine." );
    group.add_option( "-n", "--num-interactions" ).type( "int" ).help( "The number of interactions to correct for, this is used in the model prior (default: all)." );
    group.add_option( "-s", "--num-single" ).type( "int" ).help( "The number of snps to consider when correcting (default: proportional to square of the number of interactions)." );
    group.add_option( "-t", "--single-prior" ).type( "float" ).help( "The probability that a single snp is associated (default: %default)." ).set_default( 0.0 );
    group.add_option( "-i", "--mc-iterations" ).type( "int" ).help( "The number of monte carlo iterations to use in the fine method (default: %default)." ).set_default( 4000000 );
    group.add_option( "-a", "--beta-prior-param1" ).type( "float" ).help( "First shape parameter of beta prior (default: %default)." ).set_default( 2.0 );
    group.add_option( "-b", "--beta-prior-param2" ).type( "float" ).help( "Second shape parameter of beta prior (default: %default)." ).set_default( 2.0 );
    group.add_option( "-e", "--estimate-prior-params" ).action( "store_true" ).help( "Estimate prior parameters from data by permuting phenotype (default: off)." );
    parser.add_option( "--additive" ).action( "store_true" ).help( "Use an additive model (slow)." );
    parser.add_option_group( group );

    Values options = parser.parse_args( argc, argv );
    if( parser.args( ).size( ) != 2 )
    {
        parser.print_help( );
        exit( 1 );
    }

    shared_ptr<common_options> parsed_data = parse_common_options( options, parser.args( ) );

    /* Read prior parameters */
    arma::vec alpha = arma::ones<arma::vec>( 2 );
    alpha[ 0 ] = (float) options.get( "beta_prior_param1" );
    alpha[ 1 ] = (float) options.get( "beta_prior_param2" );
    if( options.is_set( "estimate_prior_params" ) )
    {
        alpha = estimate_prior_parameters( parsed_data->genotypes, parsed_data->data->phenotype, parsed_data->data->missing, 5000 );
    }

    /* Count the number of interactions to adjust for */
    parsed_data->data->single_prior = (float) options.get( "single_prior" );
    parsed_data->data->num_single = (unsigned int) options.get( "num_single" );
    parsed_data->data->num_interactions = (unsigned int) options.get( "num_interactions" );

    method_type *m = new besiq_method( parsed_data->data, alpha );
    if( options.is_set( "additive" ) )
    {
        m = new besiq_method( parsed_data->data, alpha );
    }
    else
    {
        m = new besiq_fine_method( parsed_data->data, (int) options.get( "mc_iterations" ), alpha );
    }
    
    run_method( *m, parsed_data->genotypes, *parsed_data->pairs, *parsed_data->result_file );

    delete m;

    return 0;
}
 void collect( OptionMap &m )
 {
     if( m_first_option )
     {
         m_first_option->collect( m );
     }
     if( m_next_group )
     {
         m_next_group->collect(m);
     }
 }
 void fill_default()
 {
     if( m_first_option )
     {
         m_first_option->fill_default();
     }
     if( m_next_group )
     {
         m_next_group->fill_default();
     }
 }
void
ProgramOptions::findMissingOptions(const OptionGroup& group, SetString& missing) const
{
	 
	for (OptionMap::const_iterator it = group.getOptions().begin(); 
		it != group.getOptions().end();
		++it)
	{
		if (it->second.isMandatory() && !isOptionDefined (it->first)){
			missing.insert(it->second.getName());
		}
	}

	for (OptionGroupMap::const_iterator git = group.getGroups().begin();
		git != group.getGroups().end();
		++git)
	{
		findMissingOptions(git->second, missing);
	}
}
Exemple #9
0
int main(int argc, const char** argv)
{
	Turbopump::Options options;
	string versionStr = "0.1." + string(__DATE__) + " " + string(__TIME__);

	ezOptionParser opt;
	opt.overview = "A high performance distributed key value store. 'high performance' is a relative term.";
	opt.syntax = "./turbopumpd --dothething";
	opt.example = examples();
	opt.footer = "\n\n***version " + versionStr;

	opt.add("", false, 0, 0, "Display usage instructions.", "-h", "--help");
	opt.add("localhost:1592", false, 1, 0, "local server. File path (domain socket), or tcp bind address.", "-l", "--local-addr");
	opt.add(str::str(options.internal_port).c_str(), false, 1, 0, "udp port", "-p", "--port");
	opt.add("", false, 0, 0, "run cluster in clone mode", "-c", "--clone");
	opt.add(options.home_dir.c_str(), false, 1, 0, "Home directory for settings data. Default is cwd.", "--home");
	opt.add(options.store.c_str(), false, 1, 0, "Data store backend. Default is file-system backed database at `--home`/store.", "--store");

	opt.add("2000", false, 1, 0, "sync interval (ms)", "--sync-interval");

	opt.add("", false, 0, 0, "TEST-ONLY: disable data forwarding", "--no-write-chaining");
	opt.add("", false, 0, 0, "TEST-ONLY: disable query-response data sync between peers", "--no-active-sync");
	opt.add("", false, 0, 0, "peer-to-peer communications use UDP instead of congestion-aware, reliable UDT", "--udp");

	opt.parse(argc, argv);

	if (opt.isSet("-h"))
	{
		std::string usage;
		opt.getUsage(usage);
		std::cout << usage << std::endl;
		return 1;
	}
	OptionGroup* og;

	socket_address localAddr;
	if ((og = opt.get("--local-addr")) != NULL)
	{
		string turbopath;
		og->getString(turbopath);
		std::vector<string> comps = str::split(turbopath, ':');
		if (comps.size() == 1)
			localAddr = socket_address(comps[0]);
		else if (comps.size() == 2)
			localAddr = socket_address(comps[0], std::stoi(comps[1]));
	}

	// update Turbopump::Options
	if ((og = opt.get("--port")) != NULL)
	{
		unsigned long temp;
		og->getULong(temp);
		options.internal_port = temp;
	}

	if ((og = opt.get("--sync-interval")) != NULL)
	{
		unsigned long temp;
		og->getULong(temp);
		options.sync_interval_ms = temp;
	}

	if ((og = opt.get("--home")) != NULL)
		og->getString(options.home_dir);
	if ((og = opt.get("--store")) != NULL)
		og->getString(options.store);
	if (opt.isSet("--clone"))
		options.partition_keys = false;
	if (opt.isSet("--no-write-chaining"))
		options.write_chaining = false;
	if (opt.isSet("--no-active-sync"))
		options.active_sync = false;
	if (opt.isSet("--udp"))
		options.udt = false;

	std::cout << localAddr.toString() << ":" << options.internal_port << std::endl;
	_app.reset( new TurboApp(options, localAddr) );

	::signal(SIGINT, &onShutdown);
	::signal(SIGTERM, &onShutdown);
	::signal(SIGPIPE, SIG_IGN); // may use SO_NOSIGPIPE and/or MSG_NOSIGNAL instead...
	_app->run();
	return 0;
}
Exemple #10
0
int m111ain(int argc, char *argv[])
{
#ifndef DISABLE_USAGE
  const string usage = "usage: %prog [OPTION]... DIR [FILE]...";
#else
  const string usage = SUPPRESS_USAGE;
#endif
  const string version = "%prog 1.0\nCopyright (C) 2010 Johannes Weißl\n"
    "License GPLv3+: GNU GPL version 3 or later "
    "<http://gnu.org/licenses/gpl.html>.\n"
    "This is free software: you are free to change and redistribute it.\n"
    "There is NO WARRANTY, to the extent permitted by law.";
  const string desc = "Lorem ipsum dolor sit amet, consectetur adipisicing"
    " elit, sed do eiusmod tempor incididunt ut labore et dolore magna"
    " aliqua.\nUt enim ad minim veniam, quis nostrud exercitation ullamco"
    " laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor"
    " in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla"
    " pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa"
    " qui officia deserunt mollit anim id est laborum.";
  const string epilog = "Sed ut perspiciatis unde omnis iste natus error sit"
    " voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque"
    " ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae"
    " dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit"
    " aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos"
    " qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui"
    " dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia"
    " non numquam eius modi tempora incidunt ut labore et dolore magnam"
    " aliquam quaerat voluptatem.";

  OptionParser parser = OptionParser()
    .usage(usage)
    .version(version)
    .description(desc)
    .epilog(epilog)
#ifdef DISABLE_INTERSPERSED_ARGS
    .disable_interspersed_args()
#endif
  ;

  parser.set_defaults("verbosity", "50");
  parser.set_defaults("no_clear", "0");

  // test all actions
  parser.add_option("--clear") .action("store_false") .dest("no_clear") .help("clear (default)");
  parser.add_option("--no-clear") .action("store_true") .help("not clear");
  parser.add_option("--string")
    .help("This is a really long text... very long indeed! It must be wrapped on normal terminals.");
  parser.add_option("-x", "--clause", "--sentence") .metavar("SENTENCE") .set_default("I'm a sentence")
    .help("This is a really long text... very long indeed! It must be wrapped on normal terminals. "
          "Also it should appear not on the same line as the option.");
  parser.add_option("-k") .action("count") .help("how many times?");
  parser.add_option("-v", "--verbose") .action("store_const") .set_const("100") .dest("verbosity") .help("be verbose!");
  parser.add_option("-s", "--silent") .action("store_const") .set_const("0") .dest("verbosity") .help("be silent!");
  parser.add_option("-n", "--number") .type("int") .set_default("1") .metavar("NUM") .help("number of files (default: %default)");
  parser.add_option("-H") .action("help") .help("alternative help");
  parser.add_option("-V") .action("version") .help("alternative version");
  parser.add_option("-i", "--int") .action("store") .type("int") .set_default(3) .help("default: %default");
  parser.add_option("-f", "--float") .action("store") .type("float") .set_default(5.3) .help("default: %default");
  parser.add_option("-c", "--complex") .action("store") .type("complex");
  char const* const choices[] = { "foo", "bar", "baz" };
  parser.add_option("-C", "--choices") .choices(&choices[0], &choices[3]);
  parser.add_option("-m", "--more") .action("append");
  parser.add_option("--more-milk") .action("append_const") .set_const("milk");
  parser.add_option("--hidden") .help(SUPPRESS_HELP);

  MyCallback mc;
  parser.add_option("-K", "--callback") .action("callback") .callback(mc) .help("callback test");

  OptionGroup group = OptionGroup(parser, "Dangerous Options",
      "Caution: use these options at your own risk. "
      "It is believed that some of them bite.");
  group.add_option("-g") .action("store_true") .help("Group option.") .set_default("0");
  parser.add_option_group(group);

  Values& options = parser.parse_args(argc, argv);
  vector<string> args = parser.args();

  cout << "clear: " << (options.get("no_clear") ? "false" : "true") << endl;
  cout << "string: " << options["string"] << endl;
  cout << "clause: " << options["clause"] << endl;
  cout << "k: " << options["k"] << endl;
  cout << "verbosity: " << options["verbosity"] << endl;
  cout << "number: " << (int) options.get("number") << endl;
  cout << "int: " << (int) options.get("int") << endl;
  cout << "float: " << (float) options.get("float") << endl;
  complex<double> c = 0;
  if (options.is_set("complex")) {
    stringstream ss;
    ss << options["complex"];
    ss >> c;
  }
/*
 *
 * public groups
 *
 */
void
ProgramOptions::set(const OptionGroup& group)
{
		groups[group.getName()] = group;
}