Пример #1
0
int main(int args, char** argsv)
{
    char root_route[] = "/";
    char ping_route[] = "/ping";
    configuration config;
    config.http_listen_address = "0.0.0.0";

    struct opt_config *conf;
    conf = opt_config_init();
    opt_flag_int(conf, &config.http_listen_port, "port", 8000, "Port to listen on.");
    opt_flag_int(conf, &config.thread_count, "threads", 0, "Number of threads to use.");
    opt_flag_string(conf, &config.parser, "parser", "http_parser", "HTTP parser to use");
    opt_flag_int(conf, &config.max_request_size, "max_request_size", 1048576, "Maximum request size. Defaults to 1MB.");
    opt_flag_bool(conf, &config.tcp_nodelay, "tcp_nodelay", "If present, enables tcp_nodelay (i.e. disables Nagle's algorithm).");
    opt_flag_int(conf, &config.listen_backlog, "listen_backlog", 0, "Maximum size of the backlog when accepting connection. Defaults to SOMAXCONN.");
    args = opt_config_parse(conf, args, argsv);

    hw_init_with_config(&config);

    hw_http_add_route(ping_route, get_ping, NULL);
    hw_http_add_route(root_route, get_root, NULL);

    hw_http_open();

    opt_config_free(conf);
    return 0;
}
Пример #2
0
int main(int argc, char **argv){
    FILE *query_file = NULL, *test_hits_file = NULL;
    struct cb_database_r *db = NULL;
    struct opt_config *conf;
    struct opt_args *args;
    struct DSVector *iterations = NULL, *expanded_hits = NULL, *queries = NULL,
                    *oseqs = ds_vector_create();
    struct fasta_seq *query = NULL;
    xmlDoc *doc = NULL;
    xmlNode *root = NULL;
    uint64_t dbsize = 0;
    int i = 0, j = 0;

    conf = load_search_args();
    args = opt_config_parse(conf, argc, argv);

    if (args->nargs < 2) {
        fprintf(stderr, 
                "Usage: %s [flags] database-dir fasta-file "
                "[ --blast_args BLASTN_ARGUMENTS ]\n", argv[0]);
        opt_config_print_usage(conf);
        exit(1);
    }

    system("rm CaBLAST_results.xml");

    if (!search_flags.hide_progress)
        fprintf(stderr, "Loading database data\n\n");


    db = cb_database_r_init(args->args[0],
                            (search_flags.load_coarse_db ||
                             search_flags.load_coarse_residues),
                            (search_flags.load_coarse_db ||
                             search_flags.load_coarse_links),
                            search_flags.load_compressed_db,
                            search_flags.link_block_size);
    dbsize = read_int_from_file(8, db->coarse_db->db->file_params);

    if (!search_flags.hide_progress)
        fprintf(stderr, "Running coarse BLAST\n\n");
    blast_coarse(args, dbsize);

    if (NULL == (query_file = fopen(args->args[1], "r"))) {
        fprintf(stderr, "fopen: 'fopen %s' failed: %s\n",
                args->args[1], strerror(errno));
        exit(1);
    }

    queries = ds_vector_create();
    query = fasta_read_next(query_file, "");
    while (query) {
        ds_vector_append(queries, (void *)query);
        query = fasta_read_next(query_file, "");
    }

    fclose(query_file);

    if (!search_flags.hide_progress)
        fprintf(stderr, "Processing coarse BLAST hits for fine BLAST\n\n");
    if (search_flags.show_hit_info)
        if (NULL == (test_hits_file = fopen("CaBLAST_hits.txt", "w"))) {
            fprintf(stderr, "fopen: 'fopen %s' failed: %s\n",
                    "CaBLAST_hits.txt", strerror(errno));
            exit(1);
        }

    //Parse the XML file generated from coarse BLAST and get its iterations.
    doc = xmlReadFile("CaBLAST_temp_blast_results.xml", NULL, 0);
    if (doc == NULL) {
        fprintf(stderr, "Could not parse CaBLAST_temp_blast_results.xml\n");
        return 0;
    }
    root = xmlDocGetRootElement(doc);
    iterations = get_blast_iterations(root);

    for (i = 0; i < iterations->size; i++) {
        if (!search_flags.hide_progress) {
            int32_t digits_full = floor(log10((double)iterations->size)),
                    digits_i    = floor(log10((double)i)), spaces;
            char *bar = progress_bar(i, iterations->size);
            spaces = digits_full - digits_i;
            fprintf(stderr, "\r");
            fprintf(stderr, "iteration: %d/%d", i+1, iterations->size);
            for (j = 0; j < spaces; j++)
                putc(' ', stderr);
            fprintf(stderr, " %s ", bar);
            free(bar);
        }

        /*Expand any BLAST hits we got from the current query sequence during
          coarse BLAST.*/
        expanded_hits = expand_blast_hits(iterations, i, db);

        for (j = 0; j < expanded_hits->size; j++)
            ds_vector_append(oseqs, ds_vector_get(expanded_hits, j));
        ds_vector_free_no_data(expanded_hits);
    }

    write_fine_fasta(oseqs);

    for (i = 0; i < oseqs->size; i++)
        cb_hit_expansion_free(
          (struct cb_hit_expansion *)ds_vector_get(oseqs, i));
    ds_vector_free_no_data(oseqs);

    blast_fine(args, dbsize);

    if (!search_flags.hide_progress)
        fprintf(stderr, "\n"); //Make a newline after the progress bar

    for (i = 0; i < queries->size; i++)
        fasta_free_seq((struct fasta_seq *)ds_vector_get(queries, i));
    ds_vector_free_no_data(queries);

    if (search_flags.show_hit_info)
        fclose(test_hits_file);

    //Free the XML data and expanded hits
    for (i = 0; i < iterations->size; i++) {
        struct DSVector *iteration =
          (struct DSVector *)ds_vector_get(iterations, i);
        for (j = 0; j < iteration->size; j++) {
            struct hit *h = (struct hit *)ds_vector_get(iteration, j);
            ds_vector_free(h->hsps);
            free(h);
        }
    }
    ds_vector_free_no_data(iterations);

    cb_database_r_free(db);
    xmlFreeDoc(doc);

    /*Free the coarse BLAST results file if the --no-cleanup flag is not being
      used.*/
    if (!search_flags.no_cleanup)
        system("rm CaBLAST_temp_blast_results.xml");

    opt_args_free(args);
    opt_config_free(conf);

    return 0;
}
Пример #3
0
int main(int argc, char **argv){ 
    struct cb_database_r *db;
    struct fasta_seq_gen *fsg;
    struct fasta_seq *seq;
    struct timeval start;
    struct fasta_seq **coarse_sequences;
    struct cb_link_to_coarse *link;
    struct opt_config *conf = load_compress_args();
    struct cb_compressed_seq **compressed;
    uint64_t last_end, num_coarse_sequences = 0;
    int i, org_seq_id, overlap;
    char *fasta_filename, *compressed_filename;

    FILE *compressed_file;

    struct opt_args *args = opt_config_parse(conf, argc, argv);
    if (args->nargs < 2) {
        fprintf(stderr, "Usage: %s [flags] database-dir output-fasta-file\n",
                argv[0]);
        exit(1);
    }

    db = cb_database_r_init(args->args[0], false, false, false, 30000);

    org_seq_id = 0;
    gettimeofday(&start, NULL);
    fasta_filename      = path_join(args->args[0], CABLAST_COARSE_FASTA);
    compressed_filename = path_join(args->args[0], CABLAST_COMPRESSED);
    if (NULL == (compressed_file = fopen(compressed_filename, "r"))) {
        fprintf(stderr, "fopen: 'fopen %s' failed: %s\n",
                compressed_filename, strerror(errno));
        exit(1);
    }
    compressed = read_compressed(compressed_file);

    coarse_sequences = malloc(10000*sizeof(*coarse_sequences));
    assert(coarse_sequences);

    fsg = fasta_generator_start(fasta_filename, "", 100);
    while (NULL != (seq = fasta_generator_next(fsg)))
        coarse_sequences[num_coarse_sequences++] = seq;
    for (i = 0; compressed[i] != NULL; i++) {
        int current_chunk = 0;
        last_end = 0;
        printf(">%s\n", compressed[i]->name);
        for (link = (compressed[i])->links; link != NULL; link = link->next) {
            struct cb_seq *chunk =
              cb_seq_init_range(-1, "",
                                coarse_sequences[link->coarse_seq_id]->seq,
                                link->coarse_start, link->coarse_end + 1);
            int length;
            char *decompressed;

            /*overlap represents the length of the overlap of the parts of the
              decompressed sequence that has been printed and the parts of the
              decompressed sequence currently being decompressed.*/
            overlap = last_end - link->original_start;

            for (length = 0; chunk->residues[length] != '\0'; length++);

            decompressed = read_edit_script(link->diff,chunk->residues,length);

            /*Print all characters of the decompressed chunk past the index
             *"overlap" unless overlap is greater than the length of the
             *decompressed chunk.
             */
            decompressed += overlap;
            if (overlap < link->original_end - link->original_start ||
                 (overlap == link->original_end - link->original_start &&
                  !link->next))
                printf("%s", decompressed);
            decompressed -= overlap;

            free(decompressed);

            if (link->original_end > last_end)
                last_end = link->original_end + 1;

            cb_seq_free(chunk);

            current_chunk++;
        }
        putc('\n', stdout);
    }

    free(fasta_filename);
    free(compressed_filename);

    for (i = 0; compressed[i] != NULL; i++)
        cb_compressed_seq_free(compressed[i]);
    free(compressed);

    fasta_generator_free(fsg);
    for (i = 0; i < num_coarse_sequences; i++)
        free(coarse_sequences[i]);
    free(coarse_sequences);

    cb_database_r_free(db);
    opt_config_free(conf);
    opt_args_free(args);

    return 0;
}