コード例 #1
0
ファイル: main_stats.c プロジェクト: CharoL/hpg-variant
int vcf_tool_stats(int argc, char *argv[], const char *configuration_file) {

    /* ******************************
     *       Modifiable options     *
     * ******************************/

    shared_options_t *shared_options = new_shared_cli_options();
    stats_options_t *stats_options = new_stats_cli_options();

    // If no arguments or only --help are provided, show usage
    void **argtable;
    if (argc == 1 || !strcmp(argv[1], "-h") || !strcmp(argv[1], "--help")) {
        argtable = merge_stats_options(stats_options, shared_options, arg_end(stats_options->num_options + shared_options->num_options));
        show_usage("hpg-var-vcf stats", argtable, stats_options->num_options + shared_options->num_options);
        arg_freetable(argtable, stats_options->num_options + shared_options->num_options - 10);
        return 0;
    }


    /* ******************************
     *       Execution steps        *
     * ******************************/

    // Step 1: read options from configuration file
    int config_errors = read_shared_configuration(configuration_file, shared_options);
    config_errors &= read_stats_configuration(configuration_file, stats_options, shared_options);
    
    if (config_errors) {
        LOG_FATAL("Configuration file read with errors\n");
        return CANT_READ_CONFIG_FILE;
    }
    
    // Step 2: parse command-line options
    argtable = parse_stats_options(argc, argv, stats_options, shared_options);

    // Step 3: check that all options are set with valid values
    // Mandatory that couldn't be read from the config file must be set via command-line
    // If not, return error code!
    int check_vcf_tools_opts = verify_stats_options(stats_options, shared_options);
    if (check_vcf_tools_opts > 0) {
        return check_vcf_tools_opts;
    }

    // Step 4: Create XXX_options_data_t structures from valid XXX_options_t
    shared_options_data_t *shared_options_data = new_shared_options_data(shared_options);
    stats_options_data_t *options_data = new_stats_options_data(stats_options);

    // Step 5: Perform the requested task
    int result = run_stats(shared_options_data, options_data);

    free_stats_options_data(options_data);
    free_shared_options_data(shared_options_data);
    arg_freetable(argtable, stats_options->num_options + shared_options->num_options - 10);

    return 0;
}
コード例 #2
0
ファイル: main.c プロジェクト: chwress/salad
const saladstate_t parse_options(int argc, char* argv[], config_t* const config, test_config_t* const test_config)
{
	assert(argv != NULL);
	assert(config != NULL);
	assert(test_config != NULL);

	if (argc <= 1)
	{
		return SALAD_HELP;
	}

	*config = DEFAULT_CONFIG;
	*test_config = DEFAULT_TEST_CONFIG;

	if (*argv[1] != '-')
	{
		config->mode = to_saladmode(argv[1]);
		switch (config->mode)
		{
		case TRAINING: return parse_training_options(argc, argv, config);
		case PREDICT:  return parse_predict_options(argc, argv, config);
		case INSPECT:  return parse_inspect_options(argc, argv, config);
		case STATS:    return parse_stats_options(argc, argv, config);
#ifdef TEST_SALAD
		case TEST:     return parse_test_options(argc, argv, test_config);
#endif
		default:
			error("Unknown mode '%s'.", argv[1]);
			return SALAD_EXIT;
		}
	}

	int option;
	while ((option = getopt_long(argc, argv, MAIN_OPTION_STR, main_longopts, NULL)) != -1)
	{
		switch (option)
		{
		case '?':
		case 'h':
			return SALAD_HELP;

		case 'v':
			return SALAD_VERSION;

		default: break;
	}
		}
	return SALAD_EXIT;
}