コード例 #1
0
ファイル: main.cpp プロジェクト: dmpas/e8engine
static char *
get_global_config_path()
{
    #ifdef __linux
    return strdup("/etc/e8script");
    #endif // __linux
    #ifdef __WINNT
    TCHAR buffer[MAX_PATH] = {0};
    DWORD bufSize = sizeof(buffer) / sizeof(*buffer);

    if (GetModuleFileName(NULL, buffer, bufSize) == bufSize)
        return strdup("");

    return extract_dir(buffer);
    #endif // __WINDOWS
}
コード例 #2
0
ファイル: unzip.c プロジェクト: coyizumi/cs111
/*
 * Extract a zipfile entry: first perform some sanity checks to ensure
 * that it is either a directory or a regular file and that the path is
 * not absolute and does not try to break out of the current directory;
 * then call either extract_dir() or extract_file() as appropriate.
 *
 * This is complicated a bit by the various ways in which we need to
 * manipulate the path name.  Case conversion (if requested by the -L
 * option) happens first, but the include / exclude patterns are applied
 * to the full converted path name, before the directory part of the path
 * is removed in accordance with the -j option.  Sanity checks are
 * intentionally done earlier than they need to be, so the user will get a
 * warning about insecure paths even for files or directories which
 * wouldn't be extracted anyway.
 */
static void
extract(struct archive *a, struct archive_entry *e)
{
	char *pathname, *realpathname;
	mode_t filetype;
	char *p, *q;

	pathname = pathdup(archive_entry_pathname(e));
	filetype = archive_entry_filetype(e);

	/* sanity checks */
	if (pathname[0] == '/' ||
	    strncmp(pathname, "../", 3) == 0 ||
	    strstr(pathname, "/../") != NULL) {
		warningx("skipping insecure entry '%s'", pathname);
		ac(archive_read_data_skip(a));
		free(pathname);
		return;
	}

	/* I don't think this can happen in a zipfile.. */
	if (!S_ISDIR(filetype) && !S_ISREG(filetype)) {
		warningx("skipping non-regular entry '%s'", pathname);
		ac(archive_read_data_skip(a));
		free(pathname);
		return;
	}

	/* skip directories in -j case */
	if (S_ISDIR(filetype) && j_opt) {
		ac(archive_read_data_skip(a));
		free(pathname);
		return;
	}

	/* apply include / exclude patterns */
	if (!accept_pathname(pathname)) {
		ac(archive_read_data_skip(a));
		free(pathname);
		return;
	}

	/* apply -j and -d */
	if (j_opt) {
		for (p = q = pathname; *p; ++p)
			if (*p == '/')
				q = p + 1;
		realpathname = pathcat(d_arg, q);
	} else {
		realpathname = pathcat(d_arg, pathname);
	}

	/* ensure that parent directory exists */
	make_parent(realpathname);

	if (S_ISDIR(filetype))
		extract_dir(a, e, realpathname);
	else
		extract_file(a, e, &realpathname);

	free(realpathname);
	free(pathname);
}
コード例 #3
0
ファイル: config.cpp プロジェクト: BioInfoTools/diamond
Config::Config(int argc, const char **argv)
{
	Command_line_parser parser;
	parser.add_command("makedb", "Build DIAMOND database from a FASTA file")
		.add_command("blastp", "Align amino acid query sequences against a protein reference database")
		.add_command("blastx", "Align DNA query sequences against a protein reference database")
		.add_command("view", "View DIAMOND alignment archive (DAA) formatted file")
		.add_command("help", "Produce help message")
		.add_command("version", "Display version information")
		.add_command("getseq", "")
		.add_command("benchmark", "")
		.add_command("random-seqs", "")
		.add_command("compare", "");

	Options_group general ("General options");
	general.add()
		("threads", 'p', "number of CPU threads", threads_)
		("db", 'd', "database file", database)
		("out", 'o', "output file", output_file)
		("outfmt", 'f', "output format (tab/sam/xml/daa)", output_format)
		("verbose", 'v', "verbose console output", verbose)
		("log", 0, "enable debug log", debug_log)
		("quiet", 0, "disable console output", quiet);

	Options_group makedb("Makedb options");
	makedb.add()
		("in", 0, "input reference file in FASTA format", input_ref_file)
#ifdef EXTRA
		("dbtype", po::value<string>(&program_options::db_type), "database type (nucl/prot)")
#endif
		;

	Options_group aligner("Aligner options");
	aligner.add()
		("query",'q', "input query file", query_file)
		("max-target-seqs",'k', "maximum number of target sequences to report alignments for", max_alignments, uint64_t(25))
		("top", 0, "report alignments within this percentage range of top alignment score (overrides --max-target-seqs)", toppercent, 100.0)
		("compress", 0, "compression for output files (0=none, 1=gzip)", compression)
		("evalue",'e', "maximum e-value to report alignments", max_evalue, 0.001)
		("min-score", 0, "minimum bit score to report alignments (overrides e-value setting)", min_bit_score)
		("id", 0, "minimum identity% to report an alignment", min_id)
		("query-cover", 0, "minimum query cover% to report an alignment", query_cover)
		("sensitive", 0, "enable sensitive mode (default: fast)", mode_sensitive)
		("more-sensitive", 0, "enable more sensitive mode (default: fast)", mode_more_sensitive)
		("block-size", 'b', "sequence block size in billions of letters (default=2.0)", chunk_size, 2.0)
		("index-chunks",'c', "number of chunks for index processing", lowmem, 4u)
		("tmpdir",'t', "directory for temporary files", tmpdir)
		("gapopen", 0, "gap open penalty (default=11 for protein)", gap_open, -1)
		("gapextend", 0, "gap extension penalty (default=1 for protein)", gap_extend, -1)
#ifdef EXTRA
		("reward", po::value<int>(&program_options::reward)->default_value(2), "match reward score (blastn only)")
		("penalty", po::value<int>(&program_options::penalty)->default_value(-3), "mismatch penalty score (blastn only)")
#endif
		("matrix", 0, "score matrix for protein alignment", matrix, string("blosum62"))
		("seg", 0, "enable SEG masking of queries (yes/no)", seg)
		("salltitles", 0, "print full subject titles in output files", salltitles);

	Options_group advanced("Advanced options");
	advanced.add()		
		("run-len", 'l', "mask runs between stop codons shorter than this length", run_len)
		("freq-sd", 0, "number of standard deviations for ignoring frequent seeds", freq_sd, 0.0)
		("id2", 0, "minimum number of identities for stage 1 hit", min_identities)
		("window", 'w', "window size for local hit search", window)
		("xdrop", 'x', "xdrop for ungapped alignment", xdrop, 20)
		("gapped-xdrop", 'X', "xdrop for gapped alignment in bits", gapped_xdrop, 20)
		("ungapped-score", 0, "minimum raw alignment score to continue local extension", min_ungapped_raw_score)
		("hit-band", 0, "band for hit verification", hit_band)
		("hit-score", 0, "minimum score to keep a tentative alignment", min_hit_score)
		("band", 0, "band for dynamic programming computation", padding)
		("shapes", 's', "number of seed shapes (0 = all available)", shapes)
		("index-mode", 0, "index mode (0=4x12, 1=16x9)", index_mode)
		("fetch-size", 0, "trace point fetch size", fetch_size, 4096u)
		("rank-factor", 0, "include subjects within this range of max-target-seqs", rank_factor, 2.0)
		("rank-ratio", 0, "include subjects within this ratio of last hit", rank_ratio, 0.35)
		("single-domain", 0, "Discard secondary domains within one target sequence", single_domain)
		("dbsize", 0, "effective database size (in letters)", db_size)
		("no-auto-append", 0, "disable auto appending of DAA and DMND file extensions", no_auto_append)
		("target-fetch-size", 0, "", target_fetch_size, 4u);
	
	Options_group view_options("View options");
	view_options.add()
		("daa", 'a', "DIAMOND alignment archive (DAA) file", daa_file)		
		("forwardonly", 0, "only show alignments of forward strand", forwardonly);

	Options_group hidden_options("");
	hidden_options.add()
		("extend-all", 0, "extend all seed hits", extend_all)
		("local-align", 0, "Local alignment algorithm", local_align_mode, 0u)
		("slow-search", 0, "", slow_search)
		("seq", 0, "", seq_no)
		("ht", 0, "", ht_mode)
		("old-freq", 0, "", old_freq)
		("qp", 0, "", query_parallel)
		("match1", 0, "", match_file1)
		("match2", 0, "", match_file2)
		("max-hits", 'C', "maximum number of hits to consider for one seed", hit_cap)
		("seed-freq", 0, "maximum seed frequency", max_seed_freq, -15.0);

	parser.add(general).add(makedb).add(aligner).add(advanced).add(view_options).add(hidden_options);
	parser.store(argc, argv, command);

	switch (command) {
	case Config::makedb:
		if (input_ref_file == "")
			throw std::runtime_error("Missing parameter: input file (--in)");
		if (database == "")
			throw std::runtime_error("Missing parameter: database file (--db/-d)");
		if (chunk_size != 2.0)
			throw std::runtime_error("Invalid option: --block-size/-b. Block size is set for the alignment commands.");
		break;
	case Config::blastp:
	case Config::blastx:
		if (query_file == "")
			throw std::runtime_error("Missing parameter: query file (--query/-q)");
		if (database == "")
			throw std::runtime_error("Missing parameter: database file (--db/-d)");
		if (daa_file.length() > 0) {
			if (output_file.length() > 0)
				throw std::runtime_error("Options --daa and --out cannot be used together.");
			if (output_format.length() > 0 && output_format != "daa")
				throw std::runtime_error("Invalid parameter: --daa/-a. Output file is specified with the --out/-o parameter.");
			output_file = daa_file;
		}
		if (daa_file.length() > 0 || output_format == "daa") {
			if (compression != 0)
				throw std::runtime_error("Compression is not supported for DAA format.");
			if (!no_auto_append)
				auto_append_extension(output_file, ".daa");
		}
		break;
	case Config::view:
		if (daa_file == "")
			throw std::runtime_error("Missing parameter: DAA file (--daa/-a)");
	default:
		;
	}

	if (hit_cap != 0)
		throw std::runtime_error("Deprecated parameter: --max-hits/-C.");

	if (debug_log)
		verbosity = 3;
	else if (quiet)
		verbosity = 0;
	else if (verbose)
		verbosity = 2;
	else if (((command == Config::view || command == blastx || command == blastp) && output_file == "")
		|| command == Config::version)
		verbosity = 0;
	else
		verbosity = 1;

	switch (verbosity) {
	case 0:
		message_stream = Message_stream(false);
		break;
	case 3:
		log_stream = Message_stream();
	case 2:
		verbose_stream = Message_stream();
	default:
		;
	}

	if (!no_auto_append) {
		auto_append_extension(database, ".dmnd");
		if (command == Config::view)
			auto_append_extension(daa_file, ".daa");
		if (compression == 1)
			auto_append_extension(output_file, ".gz");
	}

	message_stream << Const::program_name << " v" << Const::version_string << "." << (unsigned)Const::build_version << " | by Benjamin Buchfink <*****@*****.**>" << endl; 
	message_stream << "Check http://github.com/bbuchfink/diamond for updates." << endl << endl;
#ifndef NDEBUG
	verbose_stream << "Assertions enabled." << endl;
#endif
	set_option(threads_, tthread::thread::hardware_concurrency());

	switch (command) {
	case Config::makedb:
	case Config::blastp:
	case Config::blastx:
	case Config::view:
		message_stream << "#CPU threads: " << threads_ << endl;
	default:
		;
	}	

	if (command == Config::blastp || command == Config::blastx || command == Config::benchmark) {
		if (tmpdir == "")
			tmpdir = extract_dir(output_file);
		if (gap_open == -1)
			gap_open = 11;
		if (gap_extend == -1)
			gap_extend = 1;
		score_matrix = Score_matrix(to_upper_case(matrix), gap_open, gap_extend, reward, penalty);
		message_stream << "Scoring parameters: " << score_matrix << endl;
		if (seg == "" && command == blastx)
			seg = "yes";
		verbose_stream << "SEG masking = " << (seg == "yes") << endl;
		have_ssse3 = check_SSSE3();
		if (have_ssse3)
			verbose_stream << "SSSE3 enabled." << endl;
		verbose_stream << "Reduction: " << Reduction::reduction << endl;

		if (mode_more_sensitive) {
			set_option(index_mode, 1u);
			set_option(freq_sd, 200.0);
		}
		else if (mode_sensitive) {
			set_option(index_mode, 1u);
			set_option(freq_sd, 10.0);
		}
		else {
			set_option(index_mode, 0u);
			set_option(freq_sd, 50.0);
		}

		verbose_stream << "Seed frequency SD: " << freq_sd << endl;
		::shapes = shape_config(index_mode, shapes);
		verbose_stream << "Shape configuration: " << ::shapes << endl;

		message_stream << "#Target sequences to report alignments for: ";
		if (max_alignments == 0) {
			max_alignments = std::numeric_limits<uint64_t>::max();
			message_stream << "unlimited" << endl;
		} else
			message_stream << max_alignments << endl;
	}

	if (command == blastx)
		input_value_traits = nucleotide_traits;
	if (command == help)
		parser.print_help();

	/*log_stream << "sizeof(hit)=" << sizeof(hit) << " sizeof(packed_uint40_t)=" << sizeof(packed_uint40_t)
		<< " sizeof(sorted_list::entry)=" << sizeof(sorted_list::entry) << endl;*/
}
コード例 #4
0
ファイル: grid_polsarpro.c プロジェクト: C-Cazals/DEV
int main(int argc, char** argv)
{
	int **jobs = NULL,value,i,n_elts;
	int nr_c = 0, c_begin, c_end, c_step;
	int nr_g = 0, g_begin, g_end, g_step;
	int best_c, best_g;
	float best_acc = -1;
	float cost_tmp,gamma_tmp, accuracy;
	int fold=5;
	int Npolar;
	char cluster_file_norm[Max_Char], svm_model_file[Max_Char];
	char svm_train_path[Max_Char], gnuplot_path[Max_Char];
	char out_put_cv_txt_path[Max_Char],out_put_cv_png_path[Max_Char];
	char additional_svm_param[Max_Char];
	char command_line[Max_Char];
	char name_tmp_accuracy[Max_Char],name_script_gp[Max_Char];
	char* script_gp_path;
	char* tmp_crossval_txt;
	char buffer[Max_Char], gp_cmd[Max_Char];
	
	FILE *file_out_CV, *tmp_accuracy, *gp;
	
	// Name of the file which contain the accuracy of on step (c,g) of the CV
	sprintf(name_tmp_accuracy, "tmp_crossval.txt");
	// Name of the gnuplot script file
	sprintf(name_script_gp, "script_gnuplot.gp");
	
	// parse options
	if (argc >= 16) {
	c_begin = atoi(argv[2]);
	c_end = atoi(argv[3]);
	c_step = atoi(argv[4]);
	
	g_begin = atoi(argv[6]);
	g_end = atoi(argv[7]);
	g_step = atoi(argv[8]);
	
	strcpy(out_put_cv_txt_path, argv[10]);
	strcpy(out_put_cv_png_path, argv[12]);
	
	strcpy(svm_train_path, argv[14]);
	strcpy(gnuplot_path, argv[16]);
	
	for(i=17;i<argc - 3;i++){
		sprintf(additional_svm_param, "%s %s", additional_svm_param,argv[i]);
	}	
	
	Npolar = atoi(argv[argc-1]);
	strcpy(svm_model_file, argv[argc-2]);
	strcpy(cluster_file_norm, argv[argc-3]);
	}else{
		fprintf(stderr,"The synntax is not good ! :\n");
		fprintf(stderr,"Usage: grid_polsarpro -log2c begin end step -log2g begin end step  -out cv_txt_path -png cv_png_path -svmtrain svm_train_path -gnuplot gnuplot_path [additional parameters for svm-train like wi] training_set_file model_file number_of_polarimetric_indices\n");
		exit(1);
	}
	
	//Loop to count the number of c test step
	value = c_begin;
	if(c_begin > c_end){
		while(value >= c_end){
			value = value + c_step;
			nr_c++;
		}
	}else{
		while(value <= c_end){
			value = value + c_step;
			nr_c++;
		}
	}
	
	//Loop to count the number of g test step
	value = g_begin;
	if(g_begin > g_end){
		while(value >= g_end){
			value = value + g_step;
			nr_g++;
		}
	}else{
		while(value <= g_end){
			value = value + g_step;
			nr_g++;
		}
	}
	
	n_elts = nr_c * nr_g; // Content the number of (c,g) to test
	jobs = malloc(n_elts*sizeof(int*));
	if (jobs == NULL){
		fprintf(stderr,"Not enough memory!\n");
		exit(1);
	}
	for(i=0;i<n_elts;i++){
		jobs[i] = malloc(2 * sizeof(int));
		if (jobs[i] == NULL){
			fprintf(stderr,"Not enough memory!\n");
			exit(1);
		}
	}

	// define the order to browse the CV grid (c,g)
	calculate_jobs(jobs,nr_c, c_begin, c_end, c_step,nr_g, g_begin, g_end, g_step);
	remove(out_put_cv_txt_path);
	
	//We build the path of the temporary accuracy file
	tmp_crossval_txt = extract_dir(cluster_file_norm);
	sprintf(tmp_crossval_txt, "%s%s", tmp_crossval_txt,name_tmp_accuracy);
	
	//We build the path of gnuplot script file
	script_gp_path = extract_dir(cluster_file_norm);
	sprintf(script_gp_path, "%s%s", script_gp_path,name_script_gp);
	
	//We built the first command of gnuplot to call the gnuplot pipe
	sprintf(gp_cmd, "%s%s -persist", gp_cmd,gnuplot_path);
	gp=popen(gp_cmd, "w");
	
	for(i=0;i<n_elts;i++){	
		cost_tmp = pow(2,jobs[i][0]);
		gamma_tmp = pow(2,jobs[i][1]);
		
//AJOUTER COMMANDE POUR LA REGRESSION!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!


		//sprintf(command_line, "%s -q -c %f -g %f -v %d %s %s %s %d",
		sprintf(command_line, "%s -c %f -g %f -v %d %s %s %s %d",
		svm_train_path,cost_tmp, gamma_tmp, fold, additional_svm_param,
		cluster_file_norm,svm_model_file, Npolar);
		system(command_line);// We run the CV with (cost_tmp,gamma_tmp)
		
		//We open the txt file which contain the CV accuracy computed with (cost_tmp,gamma_tmp)
		if ((tmp_accuracy = fopen(tmp_crossval_txt, "rt")) == NULL) {
			fprintf(stderr,"Could not open temporary cross validation accuracy file : %s\n", tmp_crossval_txt);
			exit(1);
		}
		fscanf(tmp_accuracy,"%s",buffer);
		accuracy = atof(buffer);
		if(accuracy > best_acc){
			best_acc = accuracy;
			best_c = jobs[i][0];
			best_g = jobs[i][1];
		}
		fclose(tmp_accuracy);
			
		if ((file_out_CV = fopen(out_put_cv_txt_path, "at")) == NULL) {
			fprintf(stderr,"Could not open svm script file : %s\n", out_put_cv_txt_path);
			exit(1);
		}
		fprintf(file_out_CV, "%d %d %.4f\n",jobs[i][0], jobs[i][1],accuracy);
		fclose(file_out_CV);
		
		//We write the gnuplot script to plot the contour of the computed CV
		write_gnuplot_script(script_gp_path, out_put_cv_txt_path, nr_c,
			c_begin, c_end, nr_g, g_begin, g_end, best_c, best_g, best_acc);
		fprintf(gp,"load '%s'\n",script_gp_path); // We plot into the pipe the Graph
		fflush(gp);
		printf("%f\r", 100. * (i)/ n_elts);fflush(stdout);
	}
	pclose(gp);
	// New gnuplot pipe to build the png file of the CV contour
	gp=popen(gnuplot_path, "w");
	write_gnuplot_script_png(script_gp_path, out_put_cv_txt_path,out_put_cv_png_path,
		nr_c, c_begin,  c_end, nr_g, g_begin, g_end, best_c, best_g, best_acc);
	fprintf(gp,"load '%s'\n",script_gp_path); // We plot into the pipe the Graph
	fflush(gp);
	pclose(gp);

	remove(tmp_crossval_txt);
	remove(script_gp_path);
	free(jobs);
	return 0;
}
コード例 #5
0
ファイル: main.cpp プロジェクト: dmpas/e8engine
static int
exec_cli(int argc, char **argv)
{
    int fni;

    char **s_params;
    (void)s_params;
    const char *fname;
    if (!get_file_name(argc, argv, &fname, &fni)) {
        USAGE();
        return 0;
    }

    e8_environment env = e8_env_new();
    e8_translator tr = e8_env_get_translator(env);
    e8_env_set_debug_flag(env, true);

    #ifdef __WINNT
    e8_env_set_output_encoding(env, "cp866");
    #endif // __WINNT
    #ifdef __linux
    e8_env_set_output_encoding(env, "utf-8");
    #endif // __linux

    char *source_cwd = gnu_getcwd();

    load_global_settings(env, tr);

    /* Настройки из папки скрипта */

    settings_from_file("./e8script.cfg", env, tr);

    e8_env_apply_PATH(env, "PATH");

    bool no_run = false;
    /* settings_from_cli: */
    {
        int i = 1;
        while (i < fni) {

            if (strcmp(argv[i], "--no-run") == 0) {
                no_run = true;
                ++i;
                continue;
            }

            e8_runtime_error *__err;
            __err = e8_option_apply_cli_option(argv[i], env, tr);
            if (__err) {
                print_error(__err, e8_env_get_output_encoding(env));
                e8_free_exception(__err);
                __err = 0;
            }
            ++i;
        }
        s_params = &argv[fni + 1];
    }

    setlocale(LC_NUMERIC, "C");
    setlocale(LC_MONETARY, "C");

    e8_register_stdlib(env);
    e8_register_stdio(env);

    int first_argument_index = fni + 1;

    {
        /* Создаём массив Аргументы командной строки */
        e8_array *a_args = __e8_new_array(false, 0);

        E8_VAR(va_args);
        e8_var_object(&va_args, a_args);

        for (int i = first_argument_index; i < argc; i++) {
            e8_string *s_arg = e8_string_ascii(argv[i]);

            E8_VAR(vs_arg);
            e8_var_string(&vs_arg, s_arg->s);
            e8_string_destroy(s_arg);

            e8_array_add_nvalues(&va_args, 1, &vs_arg);

            e8_var_destroy(&vs_arg);
        }

        e8_env_add_global_value_utf(env, "АргументыКоманднойСтроки", &va_args);
        e8_env_add_global_value_utf(env, "CommandLineArguments", &va_args);

        e8_var_destroy(&va_args);
    }

    e8_runtime_error *__err;
    e8_unit u;
    int res = 0;

    char *used_filename = (char*)malloc(strlen(source_cwd) + strlen(fname) + 3);
    sprintf(used_filename, "%s/%s", source_cwd, fname);

    __err = e8_env_unit_from_file(env, used_filename, E8_FILE_AUTO, &u);

    free(used_filename);

    {
        /* Устанавливаем текущий каталог по первому файлу */
        char *fdir = extract_dir(fname);
        chdir(fdir);
        free(fdir);
    }

    if (!__err) {

        e8_gc_use_object(u);

        if (!no_run)
            __err = e8_env_execute(u, false);

        e8_env_unit_free(u);

    }
    const char *enc = e8_env_get_output_encoding(env);
    if (__err) {
        res = __err->error_no;
        print_error(__err, enc);
        e8_free_exception(__err);
    }

    e8_env_close(env);

    e8_gc_done();

    chdir(source_cwd);
    free(source_cwd);

    return res;

} // exec_cli