int main(int argc, char **argv) { uint32_t num_chrms = 100; if ((argc != 4)) { errx(1, "usage:\t%s <index dir> <region> <w|i>", argv[0]); } char *index_dir = argv[1]; char *region_s = argv[2]; char *i_type = argv[3]; struct giggle_index *gi; gi = giggle_load(index_dir, uint32_t_ll_giggle_set_data_handler); #if 0 char *chrm = region_s; uint32_t start = 0, end = 0; uint32_t i, len = strlen(region_s); for (i = 0; i < len; ++i) { if (region_s[i] == ':') { region_s[i] = '\0'; start = atoi(region_s + i + 1); } else if (region_s[i] == '-') { region_s[i] = '\0'; end = atoi(region_s + i + 1); break; } } struct giggle_index *gi; if (i_type[0] == 'i') { gi = giggle_load(index_dir, uint32_t_ll_giggle_set_data_handler); struct uint32_t_ll *R = (struct uint32_t_ll *)giggle_query_region(gi, chrm, start, end); if (R != NULL) printf("Hits:%u\n", R->len); else printf("Hits:0\n"); } else { gi = giggle_load(index_dir, wah_giggle_set_data_handler); uint32_t chr_id = giggle_get_chrm_id(gi, chrm); //return giggle_search(chr_id, gi->root_ids[chr_id], start, end); uint32_t domain = chr_id; uint32_t root_id = gi->root_ids[chr_id]; uint32_t leaf_start_id; int pos_start_id; uint32_t nld_start_id = bpt_find(domain, root_id, &leaf_start_id, &pos_start_id, start); fprintf(stderr, "nld_start_id:%u\t" "leaf_start_id:%u\t" "pos_start_id:%u\n", nld_start_id, leaf_start_id, pos_start_id); struct bpt_node *leaf_start = cache.get(domain, leaf_start_id - 1, &bpt_node_cache_handler); bpt_print_node(leaf_start); struct wah_bpt_non_leading_data *nld = cache.get(domain, BPT_POINTERS(leaf_start)[0] - 1, &wah_non_leading_cache_handler); fprintf(stderr, "WAH_LEN:%u\t" "wah_get_ints_count:%u\t" "\n", WAH_LEN(nld->SA), wah_get_ints_count(nld->SA)); uint32_t *R = NULL; uint32_t R_len = wah_get_ints(nld->SA, &R); uint32_t i; for (i = 0; i < R_len; ++i) { fprintf(stderr, "%u:%u\n", i, R[i]); } /* uint8_t *R = (uint8_t *)giggle_query_region(gi, chrm, start, end); if (R != NULL) printf("Hits:%u\n", wah_get_ints_count(R)); else printf("Hits:0\n"); */ } #endif giggle_index_destroy(&gi); cache.destroy(); }
// NOTE: this function could easily be rewritten using the general funtions //{{{ void wah_leading_repair(uint32_t domain, void wah_leading_repair(uint32_t domain, struct bpt_node *a, struct bpt_node *b) { #if DEBUG fprintf(stderr, "START leading_repair\n"); #endif if ( (BPT_IS_LEAF(a) == 1) && (BPT_IS_LEAF(b) == 1) ) { // make a new leading value for the new right node struct wah_bpt_leading_data *d = (struct wah_bpt_leading_data *) malloc(sizeof(struct wah_bpt_leading_data)); d->B = NULL; // if the left node had leading data, grab all of it if (BPT_LEADING(a) != 0) { // get it from cache struct wah_bpt_leading_data *l = cache.get(domain, BPT_LEADING(a) - 1, &wah_leading_cache_handler); #if DEBUG uint32_t *R = NULL, R_size; uint32_t j; fprintf(stderr, "LEADING\t"); if (l->B != NULL) { R_size = wah_get_ints(l->B, &R); fprintf(stderr, "R_size:%u\t", R_size); for (j = 0; j < R_size; ++j) fprintf(stderr, "R[%u]:%u\t", j, R[j]); free(R); R = NULL; } fprintf(stderr, "\n"); #endif d->B = wah_copy(l->B); } uint32_t i; for (i = 0 ; i < BPT_NUM_KEYS(a); ++i) { struct wah_bpt_non_leading_data *nl = cache.get(domain, BPT_POINTERS(a)[i] - 1, &wah_non_leading_cache_handler); #if DEBUG uint32_t *R = NULL, R_size; uint32_t j; fprintf(stderr, "%u\tSA\t",BPT_KEYS(a)[i]); if (nl->SA != NULL) { R_size = wah_get_ints(nl->SA, &R); fprintf(stderr, "R_size:%u\t", R_size); for (j = 0; j < R_size; ++j) fprintf(stderr, "R[%u]:%u\t", j, R[j]); free(R); R = NULL; } fprintf(stderr, "\n"); fprintf(stderr, "SE\t"); if (nl->SE != NULL) { R_size = wah_get_ints(nl->SE, &R); fprintf(stderr, "R_size:%u\t", R_size); for (j = 0; j < R_size; ++j) fprintf(stderr, "R[%u]:%u\t", j, R[j]); free(R); R = NULL; } fprintf(stderr, "\n"); #endif wah_non_leading_union_with_SA_subtract_SE(domain, (void **)(&d->B), nl); } if (d->B != NULL) { uint32_t v_id = cache.seen(domain) + 1; cache.add(domain, v_id - 1, d, &wah_leading_cache_handler); BPT_LEADING(b) = v_id; } else { free(d); } } #if DEBUG fprintf(stderr, "END leading_repair\n"); #endif }