static p_search_result setup_searcher_16_test( char * query_string, char * db_file, size_t hit_count ) { set_max_compute_capability( COMPUTE_ON_SSE2 ); mat_init_constant_scoring( 1, -1 ); init_symbol_translation( NUCLEOTIDE, FORWARD_STRAND, 3, 3 ); p_query query = query_read_from_string( query_string ); s_init( NEEDLEMAN_WUNSCH, BIT_WIDTH_16, query ); ssa_db_init( concat( "./tests/testdata/", db_file ) ); gapO = -1; gapE = -1; adp_init( hit_count ); p_search_result res = s_search( &hit_count ); minheap_sort( res->heap ); query_free( query ); return res; }
}END_TEST START_TEST (test_add_more) { p_minheap m = minheap_init( 5 ); ck_assert_int_eq( 0, m->count ); ck_assert_int_eq( 5, m->alloc ); for( int i = 0; i < 20; i++ ) { elem_t e = new_elem( i, i, i ); minheap_add( m, &e ); } minheap_sort( m ); ck_assert_int_eq( 5, m->count ); ck_assert_int_eq( 5, m->alloc ); ck_assert_int_eq( 19, m->array[0].score ); ck_assert_int_eq( 19, m->array[0].query_id ); ck_assert_int_eq( 19, m->array[0].db_id ); ck_assert_int_eq( 18, m->array[1].score ); ck_assert_int_eq( 17, m->array[2].score ); ck_assert_int_eq( 16, m->array[3].score ); ck_assert_int_eq( 15, m->array[4].score ); minheap_exit( m ); }END_TEST
}END_TEST static void test_searcher_overflow_to_64bit( int search_type ) { init_constant_scores( 127, -1 ); init_symbol_translation( AMINOACID, FORWARD_STRAND, 3, 3 ); p_query query = query_read_from_file( "./tests/testdata/NP_009305.1.fas" ); s_init( search_type, BIT_WIDTH_8, query ); ssa_db_init( "./tests/testdata/NP_009305.1.fas" ); gapO = -1; gapE = -1; size_t hit_count = 1; adp_init( hit_count ); p_search_result res = s_search( &hit_count ); minheap_sort( res->heap ); query_free( query ); ck_assert_int_eq( hit_count, res->heap->count ); ck_assert_int_eq( 1, res->overflow_8_bit_count ); ck_assert_int_eq( 1, res->overflow_16_bit_count ); int result[2] = { 67818, 0 }; test_result( res, result, 2 ); }
}END_TEST static p_search_result setup_BLOSUM62_test( int bit_width, int search_type, size_t hit_count ) { init_symbol_translation( AMINOACID, FORWARD_STRAND, 3, 3 ); mat_init_buildin( BLOSUM62 ); p_query query = query_read_from_string( "HPEVYILIIPGFGIISHVVSTYSKKPVFGEISMVYAMASIGLLGFLVWSHHMYIVGLDADTRAYFTSATMIIAIPTGIKI" ); s_init( search_type, bit_width, query ); ssa_db_init( concat( "./tests/testdata/", "short_AA.fas" ) ); gapO = -1; gapE = -1; adp_init( hit_count ); p_search_result res = s_search( &hit_count ); minheap_sort( res->heap ); query_free( query ); ck_assert_int_eq( hit_count, res->heap->count ); return res; }
}END_TEST static void test_result( p_search_result res, int * result, int result_len ) { minheap_sort( res->heap ); ck_assert_int_eq( result_len / 2, res->heap->count ); p_minheap heap = res->heap; /* * Result contains tuple of the score and the database ID */ for( int i = 0; i < result_len; i += 2 ) { // TODO test query ID as well!! ck_assert_int_eq( result[i], heap->array[i / 2].score ); ck_assert_int_eq( result[i + 1], heap->array[i / 2].db_id ); } exit_searcher_test( res ); }
static p_search_result setup_searcher_test( int bit_width, int search_type, char * query_string, char * db_file, size_t hit_count, int symtype, int strands ) { init_symbol_translation( symtype, strands, 3, 3 ); mat_init_constant_scoring( 1, -1 ); p_query query = query_read_from_string( query_string ); s_init( search_type, bit_width, query ); ssa_db_init( concat( "./tests/testdata/", db_file ) ); gapO = -1; gapE = -1; adp_init( hit_count ); p_search_result res = s_search( &hit_count ); minheap_sort( res->heap ); query_free( query ); return res; }
int main(void) { uint32_t cnt, i, data[] = {14, 2, 22, 13, 23, 10, 90, 36, 108, 12, 9, 91, 1, 51, 11, 3, 15, 80, 3, 78, 53, 5, 12, 21, 65, 70, 4}; const uint32_t data_len = sizeof(data)/sizeof(uint32_t); struct heap heap = heap_create(data_len + 5); printf(COL_BEG "push data...\n" COL_END); for (i = 0; i < data_len; i++) if (!heap_full(&heap)) heap_push(&heap, &data[i]); printf("data len = %u, heap size = %u.\n", data_len, heap_size(&heap)); printf(COL_BEG "heap tree:\n" COL_END); heap_print_tr(&heap, &test_print); printf(COL_BEG "heap array:\n" COL_END); heap_print_arr(&heap, &test_print); heap_set_callbk(&heap, &test_less_than); printf(COL_BEG "after heapify:\n" COL_END); minheap_heapify(&heap); heap_print_tr(&heap, &test_print); cnt = 0; printf(COL_BEG "ranking emulation...:\n" COL_END); while (cnt < 100) { i = (i + 1) % data_len; if (!heap_full(&heap)) { printf("insert %d\n", data[i]); minheap_insert(&heap, &data[i]); } else { void *top = heap_top(&heap); if (test_less_than(top, &data[i])) { printf("replace with %d\n", data[i]); minheap_delete(&heap, 0); minheap_insert(&heap, &data[i]); } } cnt ++; } printf(COL_BEG "a heavy heap tree now:\n" COL_END); heap_print_tr(&heap, &test_print); minheap_sort(&heap); printf(COL_BEG "heap array after min-heap sort:\n" COL_END); heap_print_arr(&heap, &test_print); heap_destory(&heap); printf(COL_BEG "a new heap...\n" COL_END); heap = heap_create(data_len + 5); heap_set_callbk(&heap, &test_less_than); for (i = 0; i < data_len; i++) if (!heap_full(&heap)) heap_push(&heap, &data[i]); printf(COL_BEG "heap array:\n" COL_END); heap_print_arr(&heap, &test_print); heap_sort_desc(&heap); printf(COL_BEG "heap array after heap sort:\n" COL_END); heap_print_arr(&heap, &test_print); heap_print_tr(&heap, &test_print); heap_destory(&heap); printf(COL_BEG "sort a heap with one element...\n" COL_END); heap = heap_create(data_len + 5); heap_set_callbk(&heap, &test_less_than); heap_push(&heap, &data[0]); heap_print_tr(&heap, &test_print); heap_sort_desc(&heap); heap_destory(&heap); return 0; }