Esempio n. 1
0
static void initialize_output_data_structures(shared_options_data_t *shared_options, list_t **output_list, cp_hashtable **summary_count, cp_hashtable **gene_list) {
    // Initialize output text list
    *output_list = (list_t*) malloc (sizeof(list_t));
    list_init("output", shared_options->num_threads, shared_options->max_batches * shared_options->batch_lines, *output_list);
    
    // Initialize summary counters and genes list
    *summary_count = cp_hashtable_create_by_option(COLLECTION_MODE_DEEP,
                                                 64,
                                                 cp_hash_istring,
                                                 (cp_compare_fn) strcasecmp,
                                                 NULL,
                                                 (cp_destructor_fn) free_file_key2,
                                                 NULL,
                                                 (cp_destructor_fn) free_summary_counter
                                                 );

    *gene_list = cp_hashtable_create_by_option(COLLECTION_MODE_DEEP,
                                              64,
                                              cp_hash_istring,
                                              (cp_compare_fn) strcasecmp,
                                              NULL,
                                              (cp_destructor_fn) free_file_key2,
                                              NULL,
                                              NULL
                                             );
}
Esempio n. 2
0
static int initialize_output_files(char *output_directory, size_t output_directory_len, cp_hashtable **output_files) {
    // Initialize collections of file descriptors
    *output_files = cp_hashtable_create_by_option(COLLECTION_MODE_DEEP,
                                                  50,
                                                  cp_hash_int,
                                                  (cp_compare_fn) int_cmp,
                                                  NULL,
                                                  (cp_destructor_fn) free_file_key1,
                                                  NULL,
                                                  (cp_destructor_fn) free_file_descriptor
                                                 );
    
    char all_variants_filename[output_directory_len + 18];
    sprintf(all_variants_filename, "%s/all_variants.txt", output_directory);
    FILE *all_variants_file = fopen(all_variants_filename, "a");
    if (!all_variants_file) {   // Can't store results
        return 1;
    }
    char *key = (char*) calloc (13, sizeof(char));
    strncat(key, "all_variants", 12);
    cp_hashtable_put(*output_files, key, all_variants_file);
    
    char summary_filename[output_directory_len + 13];
    sprintf(summary_filename, "%s/summary.txt", output_directory);
    FILE *summary_file = fopen(summary_filename, "a");
    if (!summary_file) {   // Can't store results
        return 2;
    }
    key = (char*) calloc (8, sizeof(char));
    strncat(key, "summary", 7);
    cp_hashtable_put(*output_files, key, summary_file);
    
    char snp_phenotype_filename[output_directory_len + 20];
    sprintf(snp_phenotype_filename, "%s/snp_phenotypes.txt", output_directory);
    FILE *snp_phenotype_file = fopen(snp_phenotype_filename, "a");
    if (!snp_phenotype_filename) {
        return 3;
    }
    key = (char*) calloc (15, sizeof(char));
    strncat(key, "snp_phenotypes", 14);
    cp_hashtable_put(*output_files, key, snp_phenotype_file);
    
    char mutation_phenotype_filename[output_directory_len + 25];
    sprintf(mutation_phenotype_filename, "%s/mutation_phenotypes.txt", output_directory);
    FILE *mutation_phenotype_file = fopen(mutation_phenotype_filename, "a");
    if (!mutation_phenotype_filename) {
        return 3;
    }
    key = (char*) calloc (20, sizeof(char));
    strncat(key, "mutation_phenotypes", 19);
    cp_hashtable_put(*output_files, key, mutation_phenotype_file);
    
    return 0;
}
Esempio n. 3
0
int load_mime_types(char *filename)
{
    FILE *fp;
    char mimebuf[LINELEN];
    int rc = 0;
    char *name;
    char *ext;
    char *curr;

    mimemap = 
        cp_hashtable_create_by_option(COLLECTION_MODE_NOSYNC | 
                                      COLLECTION_MODE_COPY | 
                                      COLLECTION_MODE_DEEP, 
                                      500,
                                      cp_hash_string,
                                      cp_hash_compare_string,
                                      (cp_copy_fn) strdup, 
                                      (cp_destructor_fn) free,
                                      (cp_copy_fn) strdup, 
                                      (cp_destructor_fn) free);
    fp = fopen(filename, "r");
    if (fp == NULL)
    {
        cp_error(CP_INVALID_VALUE, "can\'t open %s", filename);
        cp_hashtable_destroy(mimemap);
        return -1;
    }

    while (fgets(mimebuf, LINELEN, fp))
    {
        if (mimebuf[0] == '#') continue;
        name = curr = mimebuf;
        while (*curr && !isspace(*curr)) curr++;
        if (*curr == '\0') continue; /* no extension for this type */
        *curr++ = '\0';

        while (1)
        {
            while (*curr && isspace(*curr)) curr++;
            ext = curr;
            while (*curr && !isspace(*curr)) curr++;
            if (strlen(ext))
            {
                *curr++ = '\0';
                cp_hashtable_put(mimemap, ext, name);
            }
            else
                break;
        }
    }

    fclose(fp);
    return rc;
}
Esempio n. 4
0
int cp_log_init(char *filename, int verbosity)
{
	int i, err_code_count;
	unsigned long thread_no;
#ifdef SIGHUP
	struct sigaction act;
#endif

	log_filename = strdup(filename);
	logfile = fopen(filename, "a+");
	if (logfile == NULL)
		return CP_LOG_FILE_OPEN_FAILURE;

	loglevel = verbosity;

	err_code_count = sizeof(error_messages) / sizeof(error_code_legend);
	error_message_lookup = 
		cp_hashtable_create_by_mode(COLLECTION_MODE_NOSYNC, 
				                    err_code_count * 2, 
									cp_hash_int, 
									cp_hash_compare_int);
	for (i = 0; i < err_code_count; i++)
	{
		error_code_legend *entry = &error_messages[i];
		cp_hashtable_put(error_message_lookup, &entry->code, entry->msg);
	}
	
	thread_id = 
		cp_hashtable_create_by_option(COLLECTION_MODE_DEEP, 10,
									  cp_hash_long, cp_hash_compare_long,
									  NULL, free, NULL, free);

	thread_count = 0;
//    thread_no = (unsigned long) pthread_self();
	thread_no = (unsigned long) cp_thread_self();
	get_thread_serial(thread_no); /* establish this as thread number one */

	log_closing = 0;

#ifdef SIGHUP
	act.sa_handler = cp_log_default_signal_handler;
	sigemptyset(&act.sa_mask);
	act.sa_flags = 0;
	sigaction(SIGHUP, &act, NULL);
#endif
//	signal(SIGHUP, cp_log_default_signal_handler);

	return 0;
}
Esempio n. 5
0
int initialize_ws_output(shared_options_data_t *shared_options, effect_options_data_t *options_data){
    int num_threads = shared_options->num_threads;
    char *outdir = shared_options->output_directory;
    
    // Initialize output text list
    output_list = (list_t*) malloc (sizeof(list_t));
    list_init("output", num_threads, shared_options->max_batches * shared_options->batch_lines, output_list);
    
    // Initialize collections of file descriptors
    output_files = cp_hashtable_create_by_option(COLLECTION_MODE_DEEP,
                                                 50,
                                                 cp_hash_int,
                                                 (cp_compare_fn) int_cmp,
                                                 NULL,
                                                 (cp_destructor_fn) free_file_key1,
                                                 NULL,
                                                 (cp_destructor_fn) free_file_descriptor
                                                );
    
    char all_variants_filename[strlen(outdir) + 18];
    sprintf(all_variants_filename, "%s/all_variants.txt", outdir);
    all_variants_file = fopen(all_variants_filename, "a");
    if (!all_variants_file) {   // Can't store results
        return 1;
    }
    char *key = (char*) calloc (13, sizeof(char));
    strncat(key, "all_variants", 12);
    cp_hashtable_put(output_files, key, all_variants_file);
    
    char summary_filename[strlen(outdir) + 13];
    sprintf(summary_filename, "%s/summary.txt", outdir);
    summary_file = fopen(summary_filename, "a");
    if (!summary_file) {   // Can't store results
        return 2;
    }
    key = (char*) calloc (8, sizeof(char));
    strncat(key, "summary", 7);
    cp_hashtable_put(output_files, key, summary_file);
    
    char snp_phenotype_filename[strlen(outdir) + 20];
    sprintf(snp_phenotype_filename, "%s/snp_phenotypes.txt", outdir);
    snp_phenotype_file = fopen(snp_phenotype_filename, "a");
    if (!snp_phenotype_filename) {
        return 3;
    }
    key = (char*) calloc (15, sizeof(char));
    strncat(key, "snp_phenotypes", 14);
    cp_hashtable_put(output_files, key, snp_phenotype_file);
    
    char mutation_phenotype_filename[strlen(outdir) + 25];
    sprintf(mutation_phenotype_filename, "%s/mutation_phenotypes.txt", outdir);
    mutation_phenotype_file = fopen(mutation_phenotype_filename, "a");
    if (!mutation_phenotype_filename) {
        return 3;
    }
    key = (char*) calloc (20, sizeof(char));
    strncat(key, "mutation_phenotypes", 19);
    cp_hashtable_put(output_files, key, mutation_phenotype_file);
    
    
    // Initialize summary counters and genes list
    summary_count = cp_hashtable_create_by_option(COLLECTION_MODE_DEEP,
                                                 64,
                                                 cp_hash_istring,
                                                 (cp_compare_fn) strcasecmp,
                                                 NULL,
                                                 (cp_destructor_fn) free_file_key2,
                                                 NULL,
                                                 (cp_destructor_fn) free_summary_counter
                                                 );

    gene_list = cp_hashtable_create_by_option(COLLECTION_MODE_DEEP,
                                              64,
                                              cp_hash_istring,
                                              (cp_compare_fn) strcasecmp,
                                              NULL,
                                              (cp_destructor_fn) free_file_key2,
                                              NULL,
                                              NULL
                                             );
    
    // Create a buffer for each thread
    line = (char**) calloc (num_threads, sizeof(char*));
    output_line = (char**) calloc (num_threads, sizeof(char*));
    max_line_size = (int*) calloc (num_threads, sizeof(int));
    
    snp_line = (char**) calloc (num_threads, sizeof(char*));
    snp_output_line = (char**) calloc (num_threads, sizeof(char*));
    snp_max_line_size = (int*) calloc (num_threads, sizeof(int));
    
    mutation_line = (char**) calloc (num_threads, sizeof(char*));
    mutation_output_line = (char**) calloc (num_threads, sizeof(char*));
    mutation_max_line_size = (int*) calloc (num_threads, sizeof(int));
    
    for (int i = 0; i < num_threads; i++) {
        max_line_size[i] = snp_max_line_size[i] = mutation_max_line_size[i] = 512;
        
        line[i] = (char*) calloc (max_line_size[i], sizeof(char));
        output_line[i] = (char*) calloc (max_line_size[i], sizeof(char));
        snp_line[i] = (char*) calloc (snp_max_line_size[i], sizeof(char));
        snp_output_line[i] = (char*) calloc (snp_max_line_size[i], sizeof(char));
        mutation_line[i] = (char*) calloc (mutation_max_line_size[i], sizeof(char));
        mutation_output_line[i] = (char*) calloc (mutation_max_line_size[i], sizeof(char));
    }
         
    return 0;
}