static void initialise_rbt(GtHuffman *huffman, const void *distr, GtDistrFunc distrfunc) { GtHuffmanTree *huffptr, GT_UNUSED *huffptr2; unsigned long i; bool nodecreated = false; huffman->numofsymbols = 0; huffman->rbt_root = gt_rbtree_new(huffman_tree_cmp, huffman_tree_delete, NULL); gt_assert(huffman->rbt_root); for (i = 0; i < huffman->totalnumofsymbols; i++) { if (distrfunc(distr, i) > 0) { huffptr = huffman_tree_new(i, distrfunc(distr, i)); huffptr2 = (GtHuffmanTree*)gt_rbtree_search(huffman->rbt_root, huffptr, &nodecreated); gt_assert(nodecreated && huffptr2); huffman->numofsymbols++; } } }
static GtRBTree *seq_decoder_init_file_info(FastqFileInfo *fileinfos, GtUword num_off_files) { GtRBTree *tree; bool nodecreated = false; GtUword i; tree = gt_rbtree_new(hcr_cmp_FastqFileInfo, NULL, NULL); for (i = 0; i < num_off_files; i++) { (void) gt_rbtree_search(tree, &fileinfos[i], &nodecreated); } gt_assert(nodecreated); return tree; }
int gt_rbtree_unit_test(GtError *err) { int had_err = 0; GtRBTree *tree = NULL; GtUword i, j, k, *v; gt_error_check (err); gt_rbtree_xtab = gt_malloc(GT_RBTREE_SIZE * sizeof (*gt_rbtree_xtab)); gt_rbtree_ytab = gt_malloc(2*GT_RBTREE_SIZE * sizeof (*gt_rbtree_ytab)); gt_rbtree_ztab = gt_malloc(GT_RBTREE_SIZE * sizeof (*gt_rbtree_ztab)); gt_rbtree_depths = gt_malloc(GT_RBTREE_SIZE * sizeof (*gt_rbtree_depths)); tree = gt_rbtree_new(nrbt_cmp_fn, NULL, NULL); gt_ensure(tree != NULL); for (i = 0; i < (GtUword) GT_RBTREE_SIZE; ++i) { gt_rbtree_xtab[i] = i; } /* Do this loop several times to get different permutations for the random case. */ for (i = 0; i < (GtUword) GT_RBTREE_PASSES; ++i) { NRBT_MANGLECHECK(GT_RBTREE_ASCENDING, GtRBTreeBuild, 0); NRBT_MANGLECHECK(GT_RBTREE_ASCENDING, GtRBTreeFind, 0); NRBT_MANGLECHECK(GT_RBTREE_DESCENDING, GtRBTreeFind, 0); NRBT_MANGLECHECK(GT_RBTREE_RANDOMORDER, GtRBTreeFind, 0); NRBT_WALKCHECK; NRBT_MANGLECHECK (GT_RBTREE_ASCENDING, GtRBTreeDelete, 0); NRBT_MANGLECHECK (GT_RBTREE_ASCENDING, GtRBTreeBuild, 0); NRBT_WALKCHECK; NRBT_MANGLECHECK (GT_RBTREE_DESCENDING, GtRBTreeDelete, 0); NRBT_MANGLECHECK (GT_RBTREE_ASCENDING, GtRBTreeBuild, 0); NRBT_WALKCHECK; NRBT_MANGLECHECK (GT_RBTREE_RANDOMORDER, GtRBTreeDelete, 0); NRBT_MANGLECHECK (GT_RBTREE_DESCENDING, GtRBTreeBuild, 0); NRBT_MANGLECHECK (GT_RBTREE_ASCENDING, GtRBTreeFind, 0); NRBT_MANGLECHECK (GT_RBTREE_DESCENDING, GtRBTreeFind, 0); NRBT_MANGLECHECK (GT_RBTREE_RANDOMORDER, GtRBTreeFind, 0); NRBT_WALKCHECK; NRBT_MANGLECHECK (GT_RBTREE_DESCENDING, GtRBTreeDelete, 0); NRBT_MANGLECHECK (GT_RBTREE_DESCENDING,GtRBTreeBuild, 0); NRBT_WALKCHECK; NRBT_MANGLECHECK (GT_RBTREE_DESCENDING, GtRBTreeDelete, 0); NRBT_MANGLECHECK (GT_RBTREE_DESCENDING, GtRBTreeBuild, 0); NRBT_WALKCHECK; NRBT_MANGLECHECK (GT_RBTREE_RANDOMORDER, GtRBTreeDelete, 0); NRBT_MANGLECHECK (GT_RBTREE_RANDOMORDER, GtRBTreeBuild, 0); NRBT_MANGLECHECK (GT_RBTREE_ASCENDING, GtRBTreeFind, 0); NRBT_MANGLECHECK (GT_RBTREE_DESCENDING, GtRBTreeFind, 0); NRBT_MANGLECHECK (GT_RBTREE_RANDOMORDER, GtRBTreeFind, 0); NRBT_WALKCHECK; NRBT_MANGLECHECK (GT_RBTREE_RANDOMORDER, GtRBTreeDelete, 0); for (j = 1UL; j < (GtUword) GT_RBTREE_SIZE; j *= 2) { NRBT_MANGLECHECK (GT_RBTREE_RANDOMORDER, GtRBTreeBuildDelete, j); } } for (i = 1UL; i < (GtUword) GT_RBTREE_SIZE; i *= 2) { NRBT_MANGLECHECK (GT_RBTREE_ASCENDING, GtRBTreeBuildDelete, i); NRBT_MANGLECHECK (GT_RBTREE_DESCENDING, GtRBTreeBuildDelete, i); NRBT_MANGLECHECK (GT_RBTREE_ASCENDING, GtRBTreeBuildDelete, i); NRBT_MANGLECHECK (GT_RBTREE_DESCENDING, GtRBTreeBuildDelete, i); NRBT_MANGLECHECK (GT_RBTREE_ASCENDING, GtRBTreeBuildDelete, i); NRBT_MANGLECHECK (GT_RBTREE_DESCENDING, GtRBTreeBuildDelete, i); NRBT_MANGLECHECK (GT_RBTREE_ASCENDING, GtRBTreeBuildDelete, i); NRBT_MANGLECHECK (GT_RBTREE_DESCENDING, GtRBTreeBuildDelete, i); } gt_rbtree_delete(tree); gt_free(gt_rbtree_xtab); gt_free(gt_rbtree_ytab); gt_free(gt_rbtree_ztab); gt_free(gt_rbtree_depths); i = 0; j = 1UL, k = 2UL; tree = gt_rbtree_new(nrbt_cmp_fn, NULL, NULL); v = gt_rbtree_root_key(tree); gt_ensure(!v); (void) gt_rbtree_insert(tree, &i); v = gt_rbtree_root_key(tree); gt_ensure(v == &i); gt_ensure(*v == i); (void) gt_rbtree_insert(tree, &j); (void) gt_rbtree_insert(tree, &k); v = gt_rbtree_root_key(tree); gt_ensure(v == &j); gt_ensure(*v == j); gt_rbtree_delete(tree); return had_err; }
static int hmmsearch_process_coarse_hits( char *table_filename, GtCondenseq *ces, GtCondenseqHmmsearchArguments *arguments, GtLogger *logger, GtError *err) { int had_err = 0; GtStr *line = gt_str_new(); FILE *table = NULL; GtSplitter *splitter = gt_splitter_new(); GtStr *query = gt_str_new(), *fine_fasta_filename = gt_str_new_cstr("condenseq"); GtRBTree *sequences = NULL; GtUword filecount = (GtUword) 1; unsigned int querycount = 0; const GtUword fine_fasta_name_length = gt_str_length(fine_fasta_filename); const GtUword table_name_length = gt_str_length(arguments->outtable_filename); table = gt_xfopen(table_filename, "r"); sequences = gt_rbtree_new(hmmsearch_cmp_seqnum, hmmsearch_tree_free_node, NULL); while (!had_err && gt_str_read_next_line(line, table) == 0) { char *c_line = gt_str_get(line); GtUword uid; const GtUword target_column = 0, query_column = (GtUword) 3; if (c_line[0] != '#') { gt_splitter_split_non_empty(splitter, c_line, gt_str_length(line), ' '); gt_assert(gt_splitter_size(splitter) == (GtUword) 23); if (sscanf(gt_splitter_get_token(splitter, target_column), GT_WU, &uid) != 1) { gt_error_set(err, "couldn't parse target number: %s", gt_splitter_get_token(splitter, target_column)); had_err = -1; } if (gt_str_length(query) == 0 || strcmp(gt_str_get(query), gt_splitter_get_token(splitter, query_column)) != 0) { gt_str_set(query, gt_splitter_get_token(splitter, query_column)); gt_logger_log(logger, "new query: %s", gt_str_get(query)); querycount++; } if (!had_err && querycount == arguments->max_queries) { hmmsearch_create_fine_fas(fine_fasta_filename, sequences, ces); if (table_name_length != 0) gt_str_append_uword(arguments->outtable_filename, filecount++); had_err = hmmsearch_call_fine_search(table_name_length != 0 ? arguments->outtable_filename : NULL, gt_str_get(fine_fasta_filename), gt_str_get(arguments->hmmsearch_path), gt_str_get(arguments->hmm), logger, err); gt_rbtree_clear(sequences); gt_str_set_length(fine_fasta_filename, fine_fasta_name_length); if (table_name_length != 0) gt_str_set_length(arguments->outtable_filename, table_name_length); querycount = 0; } if (!had_err) { if (gt_condenseq_each_redundant_seq(ces, uid, hmmsearch_process_seq, sequences, err) == 0) { had_err = -1; } } gt_splitter_reset(splitter); } gt_str_reset(line); } gt_splitter_delete(splitter); gt_str_delete(line); gt_str_delete(query); gt_xfclose(table); if (!had_err) { hmmsearch_create_fine_fas(fine_fasta_filename, sequences, ces); if (table_name_length != 0) gt_str_append_uword(arguments->outtable_filename, filecount++); had_err = hmmsearch_call_fine_search(table_name_length != 0 ? arguments->outtable_filename : NULL, gt_str_get(fine_fasta_filename), gt_str_get(arguments->hmmsearch_path), gt_str_get(arguments->hmm), logger, err); } gt_log_log("created " GT_WU " files", filecount); gt_rbtree_delete(sequences); gt_str_delete(fine_fasta_filename); return had_err; }