void test_starcode_2 (void) // Test addmatch(). { useq_t *u1 = new_useq(12983, "string 1", NULL); test_assert_critical(u1 != NULL); test_assert(u1->matches == NULL); useq_t *u2 = new_useq(-20838, "string 2", NULL); test_assert_critical(u2 != NULL); test_assert(u2->matches == NULL); // Add match to u1. addmatch(u1, u2, 1, 2); test_assert(u2->matches == NULL); test_assert(u1->matches != NULL); // Check failure. test_assert(addmatch(u1, u2, 3, 2) == 1); // Add match again to u1. addmatch(u1, u2, 1, 2); test_assert(u2->matches == NULL); test_assert_critical(u1->matches != NULL); test_assert_critical(u1->matches[1] != NULL); test_assert(u1->matches[1]->nitems == 2); destroy_useq(u1); destroy_useq(u2); }
void test_compress_histo (void) { histo_t *histo = new_histo(); test_assert_critical(histo != NULL); for (size_t i = 0 ; i < 4096 ; i += 2) { test_assert(histo_push(&histo, i) == 0); } tab_t *tab; tab = compress_histo(histo); test_assert_critical(tab != NULL); test_assert(tab->size == 2048); for (size_t i = 0 ; i < tab->size ; i++) { test_assert(tab->val[i] == 2*i); test_assert(tab->num[i] == 1); } free(tab); redirect_stderr(); set_alloc_failure_rate_to(1.0); tab = compress_histo(histo); reset_alloc(); unredirect_stderr(); test_assert(tab == NULL); test_assert(strcmp(caught_in_stderr(), "") != 0); free(histo); return; }
void test_mem_index_read (void) { redirect_stderr(); index_t * index = index_build("examples/repeats.fa", "test_base30"); test_assert_critical(index != NULL); test_assert(index_ann_new(25, 1, 1, index) == 0); // Set alloc failure rate to 0.1. set_alloc_failure_rate_to(0.1); for (int i = 0; i < 1000; i++) { index_t * index_i = index_read("test_base30"); index_free(index_i); } reset_alloc(); // Set alloc countdown 0->10. for (int i = 0; i <= 200; i++) { set_alloc_failure_countdown_to(i); index_t * index_i = index_read("test_base30"); index_free(index_i); } reset_alloc(); index_free(index); unredirect_stderr(); }
void test_tabulate (void) { int x1[12] = {1,2,3,4,1,2,3,4,1,2,3,4}; tab_t *tab; tab = tabulate(x1, 12); test_assert_critical(tab != NULL); test_assert(tab->size == 4); test_assert(tab->val[0] == 1); test_assert(tab->val[1] == 2); test_assert(tab->val[2] == 3); test_assert(tab->val[3] == 4); for (int i = 0 ; i < 4 ; i++) { test_assert(tab->num[i] == 3); } free(tab); int x2[4] = {4096,2048,1024,512}; tab = tabulate(x2, 4); test_assert_critical(tab != NULL); test_assert(tab->size == 4); test_assert(tab->val[0] == 512); test_assert(tab->val[1] == 1024); test_assert(tab->val[2] == 2048); test_assert(tab->val[3] == 4096); for (int i = 0 ; i < 4 ; i++) { test_assert(tab->num[i] == 1); } free(tab); int x3[5] = {-1,2,3,-1,2}; tab = tabulate(x3, 5); test_assert_critical(tab != NULL); test_assert(tab->size == 2); test_assert(tab->val[0] == 2); test_assert(tab->val[1] == 3); test_assert(tab->num[0] == 2); test_assert(tab->num[1] == 1); free(tab); return; }
void test_starcode_6 (void) // Test 'pad_useq()' and 'unpad_useq()' { gstack_t * useqS = new_gstack(); test_assert_critical(useqS != NULL); useq_t *u1 = new_useq(1, "L@[ohztp{2@V(u(x7fLt&x80", NULL); useq_t *u2 = new_useq(2, "$Ee6xkB+.Q;Nk)|w[KQ;", NULL); test_assert_critical(u1 != NULL); test_assert_critical(u2 != NULL); push(u1, &useqS); push(u2, &useqS); test_assert(useqS->nitems == 2); int med; pad_useq(useqS, &med); test_assert(strcmp(u2->seq, " $Ee6xkB+.Q;Nk)|w[KQ;") == 0); test_assert(med == 20); useq_t *u3 = new_useq(23, "0sdfd:'!'@{1$Ee6xkB+.Q;[Nk)|w[KQ;", NULL); test_assert_critical(u3 != NULL); push(u3, &useqS); test_assert(useqS->nitems == 3); pad_useq(useqS, &med); test_assert(strcmp(u1->seq, " L@[ohztp{2@V(u(x7fLt&x80") == 0); test_assert(strcmp(u2->seq, " $Ee6xkB+.Q;Nk)|w[KQ;") == 0); test_assert(med == 24); unpad_useq(useqS); test_assert(strcmp(u1->seq, "L@[ohztp{2@V(u(x7fLt&x80") == 0); test_assert(strcmp(u2->seq, "$Ee6xkB+.Q;Nk)|w[KQ;") == 0); test_assert(strcmp(u3->seq, "0sdfd:'!'@{1$Ee6xkB+.Q;[Nk)|w[KQ;") == 0); destroy_useq(u1); destroy_useq(u2); destroy_useq(u3); free(useqS); }
void test_mem_sar_get_range (void) { sym_t * sym = sym_new_dna(); test_assert_critical(sym != NULL); txt_t * txt = txt_new(sym); test_assert_critical(txt != NULL); test_assert(txt_append("TAGCNTCGACA", txt) == 0); test_assert(txt_commit_seq("seq0",txt) == 0); test_assert(txt_commit_rc(txt) == 0); sar_t * sar = sar_build(txt); test_assert_critical(sar != NULL); int64_t * sa_buf = malloc(30*sizeof(int64_t)); test_assert_critical(sa_buf != NULL); redirect_stderr(); // Set alloc failure rate to 0.1. set_alloc_failure_rate_to(0.1); for (int i = 0; i < 100; i++) { sar_get_range(0,10,sa_buf,sar); sar_get_range(10,5,sa_buf,sar); sar_get_range(19,30,sa_buf,sar); } reset_alloc(); // Set alloc countdown 0->10. for (int i = 0; i <= 10; i++) { set_alloc_failure_countdown_to(i); sar_get_range(0,10,sa_buf,sar); sar_get_range(10,5,sa_buf,sar); sar_get_range(19,30,sa_buf,sar); } reset_alloc(); free(sa_buf); sar_free(sar); txt_free(txt); sym_free(sym); unredirect_stderr(); }
void test_mem_sar_file (void) { sym_t * sym = sym_new_dna(); test_assert_critical(sym != NULL); txt_t * txt = txt_new(sym); test_assert_critical(txt != NULL); test_assert(txt_append("TAGCNTCGACA", txt) == 0); test_assert(txt_commit_seq("seq0",txt) == 0); test_assert(txt_commit_rc(txt) == 0); sar_t * sar = sar_build(txt); test_assert_critical(sar != NULL); sar_t * sar_i; redirect_stderr(); // Set alloc failure rate to 0.1. set_alloc_failure_rate_to(0.1); for (int i = 0; i < 100; i++) { sar_file_write("test30.sar", sar); sar_i = sar_file_read("test30.sar"); sar_free(sar_i); } reset_alloc(); // Set alloc countdown 0->10. for (int i = 0; i <= 10; i++) { set_alloc_failure_countdown_to(i); sar_file_write("test30.sar", sar); sar_i = sar_file_read("test30.sar"); sar_free(sar_i); } reset_alloc(); sar_free(sar); txt_free(txt); sym_free(sym); unredirect_stderr(); }
void test_histo_push (void) { histo_t *histo; histo = new_histo(); test_assert_critical(histo != NULL); for (size_t i = 0 ; i < (1 << 16) ; i++) { test_assert(histo_push(&histo, i) == 0); } test_assert(histo->size == (1 << 16)); for (size_t i = 0 ; i < (1 << 16) ; i++) { test_assert(histo->num[i] == 1); } free(histo); histo = new_histo(); test_assert_critical(histo != NULL); for (size_t i = (1 << 16) ; i > 0 ; i--) { test_assert(histo_push(&histo, i-1) == 0); } test_assert(histo->size == 2*((1 << 16)-1)); for (size_t i = 0 ; i < (1 << 16) ; i++) { test_assert(histo->num[i] == 1); } free(histo); histo = new_histo(); test_assert_critical(histo != NULL); redirect_stderr(); set_alloc_failure_rate_to(1.0); test_assert(histo_push(&histo, HISTO_INIT_SIZE) == 1); reset_alloc(); unredirect_stderr(); test_assert(strcmp(caught_in_stderr(), "") != 0); free(histo); return; }
void test_mle_zinm (void) { // Cases checked by simulated annealing. zinm_par_t *par = new_zinm_par(1); if (par == NULL) { fprintf(stderr, "test error line %d\n", __LINE__); return; } // 0:53, 1:8, 2:9, 3:8, 4:4, 5:7, 6:3, 7:3, 8:1, 9:3, 10:1 uint32_t x1[100] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,3,7,4,5,3,5,1,5,7,3,6,1,2,9,1,10,6,2,2,2,3,2,1,1,5,0,2,3, 9,4,2,9,3,5,7,3,5,2,1,0,6,1,4,2,3,4,5,8,1 }; test_assert_critical(mle_zinm(x1, 1, 100, par) != NULL); test_assert(fabs(par->alpha-3.6855) < 1e-3); test_assert(fabs(par->mu[0]-0.5044) < 1e-3); test_assert(fabs(par->pi-0.5110) < 1e-3); // 0:73, 1:7, 2:7, 3:3, 4:4, 5:2, 7:1, 8:2, 9:1 uint32_t x2[100] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,5, 1,0,0,8,1,1,3,0,0,8,2,4,1,2,0,3,2,0,0,4,0,0,3,1,0,2,0,0,5, 7,0,0,2,4,0,2,1,0,0,0,0,0,0,0,1,2,9,0,4 }; test_assert_critical(mle_zinm(x2, 1, 100, par) != NULL); test_assert(fabs(par->alpha-1.8251) < 1e-3); test_assert(fabs(par->mu[0]-0.4109) < 1e-3); test_assert(fabs(par->pi-0.3363) < 1e-3); free(par); return; }
void test_starcode_1 // Basic tests of useq. (void) { // Regular initialization without info. useq_t *u = new_useq(1, "some sequence", NULL); test_assert_critical(u != NULL); test_assert(u->count == 1); test_assert(strcmp(u->seq, "some sequence") == 0); test_assert(u->info == NULL); test_assert(u->matches == NULL); test_assert(u->canonical == NULL); destroy_useq(u); // Regular initialization with info. u = new_useq(1, "some sequence", "some info"); test_assert_critical(u != NULL); test_assert(u->count == 1); test_assert(strcmp(u->seq, "some sequence") == 0); test_assert(strcmp(u->info, "some info") == 0); test_assert(u->matches == NULL); test_assert(u->canonical == NULL); destroy_useq(u); // Initialize with negative value and \0 string. u = new_useq(-1, "", NULL); test_assert_critical(u != NULL); test_assert(u->count == -1); test_assert(strcmp(u->seq, "") == 0); test_assert(u->info == NULL); test_assert(u->matches == NULL); test_assert(u->canonical == NULL); destroy_useq(u); // Initialize with NULL string. u = new_useq(0, NULL, NULL); test_assert(u == NULL); }
void test_mle_zinb (void) { // Cases checked by simulated annealing. zinb_par_t *par; // 0:53, 1:8, 2:9, 3:8, 4:4, 5:7, 6:3, 7:3, 8:1, 9:3, 10:1 int x1[100] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,3,7,4,5,3,5,1,5,7,3,6,1,2,9,1,10,6,2,2,2,3,2,1,1,5,0,2,3, 9,4,2,9,3,5,7,3,5,2,1,0,6,1,4,2,3,4,5,8,1 }; par = mle_zinb(x1, 100); test_assert_critical(par != NULL); test_assert(fabs(par->a - 3.6855) < 1e-3); test_assert(fabs(par->pi - 0.5110) < 1e-3); test_assert(fabs(par->p - 0.5044) < 1e-3); free(par); // 0:73, 1:7, 2:7, 3:3, 4:4, 5:2, 7:1, 8:2, 9:1 int x2[100] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,5, 1,0,0,8,1,1,3,0,0,8,2,4,1,2,0,3,2,0,0,4,0,0,3,1,0,2,0,0,5, 7,0,0,2,4,0,2,1,0,0,0,0,0,0,0,1,2,9,0,4 }; par = mle_zinb(x2, 100); test_assert_critical(par != NULL); test_assert(fabs(par->a - 1.8251) < 1e-3); test_assert(fabs(par->pi - 0.3363) < 1e-3); test_assert(fabs(par->p - 0.4109) < 1e-3); free(par); return; }
void test_starcode_7 (void) // Test 'new_lookup()' { int expected_klen[][4] = { {4,4,4,5}, {4,4,5,5}, {4,5,5,5}, {5,5,5,5}, }; for (int i = 0 ; i < 4 ; i++) { lookup_t * lut = new_lookup(20+i, 20+i, 3); test_assert_critical(lut != NULL); test_assert(lut->kmers == 3+1); test_assert(lut->slen == 20+i); test_assert_critical(lut->klen != NULL); for (int j = 0 ; j < 4 ; j++) { test_assert(lut->klen[j] == expected_klen[i][j]); } destroy_lookup(lut); } for (int i = 0 ; i < 10 ; i++) { lookup_t * lut = new_lookup(59+i, 59+i, 3); test_assert_critical(lut != NULL); test_assert(lut->kmers == 3+1); test_assert(lut->slen == 59+i); test_assert_critical(lut->klen != NULL); for (int j = 0 ; j < 4 ; j++) { test_assert(lut->klen[j] == MAX_K_FOR_LOOKUP); } destroy_lookup(lut); } }
void test_eval_zinb_g (void) { tab_t *tab; // 0:14, 1:5, 2:4, 3:1, 5:1 int x1[25] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0, 1,1,1,1,1,2,2,2,2,3,5 }; tab = tabulate(x1, 25); test_assert_critical(tab != NULL); test_assert(fabs(eval_zinb_g(1, .5, tab)+0.1325713) < 1e-6); free(tab); return; }
void test_fail_mle_nb (void) { int obs[] = {6,2,2,3,2,0,1,2,5,2}; zinb_par_t *par = NULL; redirect_stderr(); set_alloc_failure_countdown_to(0); par = mle_nb(obs, 10); reset_alloc(); unredirect_stderr(); test_assert(par == NULL); test_assert(strncmp(caught_in_stderr(), "memory error", 12) == 0); redirect_stderr(); set_alloc_failure_countdown_to(1); par = mle_nb(obs, 10); reset_alloc(); unredirect_stderr(); test_assert(par == NULL); test_assert(strncmp(caught_in_stderr(), "memory error", 12) == 0); redirect_stderr(); set_alloc_failure_countdown_to(2); par = mle_nb(obs, 10); reset_alloc(); unredirect_stderr(); test_assert(par == NULL); test_assert(strncmp(caught_in_stderr(), "memory error", 12) == 0); redirect_stderr(); set_alloc_failure_countdown_to(3); par = mle_nb(obs, 10); reset_alloc(); unredirect_stderr(); test_assert_critical(par != NULL); test_assert(strncmp(caught_in_stderr(), "$", 1) == 0); free(par); return; }
void test_eval_zinb_dgda (void) { tab_t *tab; // 0:14, 1:5, 2:4, 3:1, 5:1 int x1[25] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0, 1,1,1,1,1,2,2,2,2,3,5 }; tab = tabulate(x1, 25); test_assert_critical(tab != NULL); test_assert(fabs(eval_zinb_dgda(1, .5, tab)+2.2547559) < 1e-6); test_assert(fabs(eval_zinb_dgda(2, .5, tab)+1.2605630) < 1e-6); test_assert(fabs(eval_zinb_dgda(2, .3, tab)+1.8764955) < 1e-6); free(tab); return; }
void test_ll_zinb (void) { tab_t *tab; // 0:14, 1:5, 2:4, 3:1, 5:1 int x1[25] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0, 1,1,1,1,1,2,2,2,2,3,5 }; tab = tabulate(x1, 25); test_assert_critical(tab != NULL); test_assert(fabs(ll_zinb(1, .5, 1, tab)+22.5329303) < 1e-6); test_assert(fabs(ll_zinb(1, .5, .7, tab)+22.7832550) < 1e-6); test_assert(fabs(ll_zinb(2, .5, .7, tab)+23.7608409) < 1e-6); test_assert(fabs(ll_zinb(2, .3, .7, tab)+31.6978553) < 1e-6); free(tab); return; }
void test_mem_index_ann_new (void) { redirect_stderr(); index_t * index = index_build("examples/repeats.fa", "test_base20"); test_assert_critical(index != NULL); // Set alloc failure rate to 0.1. set_alloc_failure_rate_to(0.1); for (int i = 0; i < 1000; i++) { if (index_ann_new(25, 1, 1, index) == 0) { unlink("test_base20.ann.25.1"); ann_free(index->ann[0]); free(index->ann); index->ann = NULL; index->ann_cnt = 0; } } reset_alloc(); // Set alloc countdown 0->10. for (int i = 0; i <= 1000; i++) { set_alloc_failure_countdown_to(i); if (index_ann_new(25, 1, 1, index) == 0) { unlink("test_base20.ann.25.1"); ann_free(index->ann[0]); free(index->ann); index->ann = NULL; index->ann_cnt = 0; } } reset_alloc(); index_free(index); unredirect_stderr(); }
void test_new_histo (void) { histo_t *histo; histo = new_histo(); test_assert_critical(histo != NULL); for (size_t i = 0 ; i < HISTO_INIT_SIZE ; i++) { test_assert(histo->num[i] == 0); } free(histo); redirect_stderr(); set_alloc_failure_rate_to(1.0); histo = new_histo(); reset_alloc(); unredirect_stderr(); test_assert(histo == NULL); test_assert(strcmp(caught_in_stderr(), "") != 0); return; }
void test_mle_nb (void) { // These test cases have been verified with R. zinb_par_t *par; // 0:14, 1:5, 2:4, 3:1, 5:1 int x1[25] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0, 1,1,1,1,1,2,2,2,2,3,5 }; par = mle_nb(x1, 25); test_assert_critical(par != NULL); test_assert(fabs(par->a - 0.9237) < 1e-3); test_assert(par->pi == 1.0); test_assert(fabs(par->p - 0.5237) < 1e-3); free(par); // 0:27, 1:12, 2:8, 3:1, 4:1, 5:1 int x2[50] = {3,0,1,2,0,0,1,0,0,0,0,1,1,0,0,1,2,2,0,0,0,1,2, 0, 0,0,0,0,4,0,0,0,1,5,1,0,1,2,1,2,2,2,0,0,0,1,0,1,0,0}; par = mle_nb(x2, 50); test_assert_critical(par != NULL); test_assert(fabs(par->a - 1.3436) < 1e-3); test_assert(par->pi == 1.0); test_assert(fabs(par->p - 0.6267) < 1e-3); free(par); // 0:12, 1:7, 2:13, 3:4, 4:6, 5:2, 6:1, 7:3, 8:1, 9:1 int x3[50] = {4,5,2,1,2,4,2,2,0,4,2,1,3,6,0,0,7,3,0,8,4,2,0, 0,2,3,2,3,7,9,2,4,0,4,2,0,0,2,5,1,1,2,1,0,0,0,1,2,1,7}; par = mle_nb(x3, 50); test_assert_critical(par != NULL); test_assert(fabs(par->a - 1.7969) < 1e-3); test_assert(par->pi == 1.0); test_assert(fabs(par->p - 0.4221) < 1e-3); free(par); // 0:39, 1:8, 2:2, 3:1 int x4[50] = {1,0,0,0,0,0,3,1,0,1,0,0,0,0,0,0,0,1,0,0,0,2,0, 2,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0}; par = mle_nb(x4, 50); test_assert_critical(par != NULL); test_assert(fabs(par->a - 0.7073) < 1e-3); test_assert(par->pi == 1.0); test_assert(fabs(par->p - 0.7021) < 1e-3); free(par); // 0:59, 1:83, 2:99, 3:67, 4:67, 5:49, 6:27, 7:22, 8:11, 9:6 // 10:6, 11:3, 12:2, 13:3 int x5[500] = {1,0,0,1,1,2,1,0,5,7,1,3,3,1,6,0,2,5,7,0,5,2,1, 10,5,3,4,5,7,0,8,6,3,0,2,1,1,0,2,3,7,2,3,2,2,1,0,4,4,2,4,2, 0,6,3,2,5,2,1,4,3,4,2,2,5,3,2,0,2,8,1,3,1,7,5,1,4,1,1,0,2, 2,4,1,1,1,4,1,3,4,4,10,5,2,0,7,1,6,1,3,6,4,0,2,4,1,12,2,5, 6,5,4,1,11,0,1,3,2,4,2,0,2,3,4,0,2,9,9,7,4,2,1,3,3,3,4,2,9, 2,4,3,2,2,4,2,5,3,0,1,3,2,0,3,3,4,1,3,3,5,7,3,3,2,1,5,5,4, 6,1,1,1,2,9,5,1,2,4,0,2,1,0,3,2,4,3,1,4,2,1,4,1,6,0,6,5,3, 5,2,0,1,2,1,0,5,3,2,7,6,4,3,2,5,7,5,5,1,1,3,10,2,0,5,0,1,2, 0,5,1,2,3,6,4,0,3,1,2,2,4,3,0,3,2,5,4,10,1,2,4,4,2,13,4,3, 1,5,4,8,5,6,2,3,4,3,1,5,5,1,8,2,0,5,7,3,2,2,4,2,3,1,5,3,7, 13,1,4,7,5,5,0,3,0,4,2,3,1,2,4,2,8,1,2,5,6,1,1,0,7,2,2,3,5, 12,2,2,2,0,3,3,4,0,2,5,1,10,0,7,6,5,0,11,2,3,7,3,5,4,2,1,2, 4,0,2,2,2,0,6,2,3,4,2,3,7,3,5,2,5,0,4,4,6,3,1,2,7,3,0,2,5, 7,2,2,0,0,0,6,3,0,1,1,5,5,2,6,2,4,6,0,1,2,3,2,2,2,3,4,1,1, 4,0,2,0,1,3,4,1,2,2,3,1,4,4,3,4,4,1,5,2,13,4,10,5,6,1,0,5, 0,0,5,6,0,1,8,5,1,3,1,8,1,8,1,6,7,2,8,2,2,3,3,0,4,2,1,9,6, 0,6,7,1,8,2,2,1,11,3,0,4,2,5,1,6,8,3,4,7,0,4,2,4,1,1,1,6,0, 4,4,6,2,1,3,1,0,4,9,3,1,4,2,2,0,1}; par = mle_nb(x5, 500); test_assert_critical(par != NULL); test_assert(fabs(par->a-3.0057) < 1e-3); test_assert(par->pi == 1.0); test_assert(fabs(par->p-0.4854) < 1e-3); free(par); return; }
void test_nb_est_alpha (void) { tab_t *tab; // 0:14, 1:5, 2:4, 3:1, 5:1 int x1[25] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0, 1,1,1,1,1,2,2,2,2,3,5 }; tab = tabulate(x1, 25); test_assert_critical(tab != NULL); test_assert(fabs(nb_est_alpha(tab)-0.9237) < 1e-3); free(tab); // 0:27, 1:12, 2:8, 3:1, 4:1, 5:1 int x2[50] = {3,0,1,2,0,0,1,0,0,0,0,1,1,0,0,1,2,2,0,0,0,1,2, 0, 0,0,0,0,4,0,0,0,1,5,1,0,1,2,1,2,2,2,0,0,0,1,0,1,0,0}; tab = tabulate(x2, 50); test_assert_critical(tab != NULL); test_assert(fabs(nb_est_alpha(tab)-1.3436) < 1e-3); free(tab); // 0:12, 1:7, 2:13, 3:4, 4:6, 5:2, 6:1, 7:3, 8:1, 9:1 int x3[50] = {4,5,2,1,2,4,2,2,0,4,2,1,3,6,0,0,7,3,0,8,4,2,0, 0,2,3,2,3,7,9,2,4,0,4,2,0,0,2,5,1,1,2,1,0,0,0,1,2,1,7}; tab = tabulate(x3, 50); test_assert_critical(tab != NULL); test_assert(fabs(nb_est_alpha(tab)-1.7969) < 1e-3); free(tab); // 0:39, 1:8, 2:2, 3:1 int x4[50] = {1,0,0,0,0,0,3,1,0,1,0,0,0,0,0,0,0,1,0,0,0,2,0, 2,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0}; tab = tabulate(x4, 50); test_assert_critical(tab != NULL); test_assert(fabs(nb_est_alpha(tab)-0.7073) < 1e-3); free(tab); // 0:59, 1:83, 2:99, 3:67, 4:67, 5:49, 6:27, 7:22, 8:11, 9:6 // 10:6, 11:3, 12:2, 13:3 int x5[500] = {1,0,0,1,1,2,1,0,5,7,1,3,3,1,6,0,2,5,7,0,5,2,1, 10,5,3,4,5,7,0,8,6,3,0,2,1,1,0,2,3,7,2,3,2,2,1,0,4,4,2,4,2, 0,6,3,2,5,2,1,4,3,4,2,2,5,3,2,0,2,8,1,3,1,7,5,1,4,1,1,0,2, 2,4,1,1,1,4,1,3,4,4,10,5,2,0,7,1,6,1,3,6,4,0,2,4,1,12,2,5, 6,5,4,1,11,0,1,3,2,4,2,0,2,3,4,0,2,9,9,7,4,2,1,3,3,3,4,2,9, 2,4,3,2,2,4,2,5,3,0,1,3,2,0,3,3,4,1,3,3,5,7,3,3,2,1,5,5,4, 6,1,1,1,2,9,5,1,2,4,0,2,1,0,3,2,4,3,1,4,2,1,4,1,6,0,6,5,3, 5,2,0,1,2,1,0,5,3,2,7,6,4,3,2,5,7,5,5,1,1,3,10,2,0,5,0,1,2, 0,5,1,2,3,6,4,0,3,1,2,2,4,3,0,3,2,5,4,10,1,2,4,4,2,13,4,3, 1,5,4,8,5,6,2,3,4,3,1,5,5,1,8,2,0,5,7,3,2,2,4,2,3,1,5,3,7, 13,1,4,7,5,5,0,3,0,4,2,3,1,2,4,2,8,1,2,5,6,1,1,0,7,2,2,3,5, 12,2,2,2,0,3,3,4,0,2,5,1,10,0,7,6,5,0,11,2,3,7,3,5,4,2,1,2, 4,0,2,2,2,0,6,2,3,4,2,3,7,3,5,2,5,0,4,4,6,3,1,2,7,3,0,2,5, 7,2,2,0,0,0,6,3,0,1,1,5,5,2,6,2,4,6,0,1,2,3,2,2,2,3,4,1,1, 4,0,2,0,1,3,4,1,2,2,3,1,4,4,3,4,4,1,5,2,13,4,10,5,6,1,0,5, 0,0,5,6,0,1,8,5,1,3,1,8,1,8,1,6,7,2,8,2,2,3,3,0,4,2,1,9,6, 0,6,7,1,8,2,2,1,11,3,0,4,2,5,1,6,8,3,4,7,0,4,2,4,1,1,1,6,0, 4,4,6,2,1,3,1,0,4,9,3,1,4,2,2,0,1}; tab = tabulate(x5, 500); test_assert_critical(tab != NULL); test_assert(fabs(nb_est_alpha(tab)-3.0057) < 1e-3); free(tab); }
void test_seqsort (void) { gstack_t * useqS = new_gstack(); // Basic cases. for (int i = 0 ; i < 9 ; i++) { push(new_useq(1, "A", NULL), &useqS); } test_assert(useqS->nitems == 9); test_assert(seqsort((useq_t **) useqS->items, 9, 1) == 1); test_assert_critical(useqS->items[0] != NULL); useq_t *u = useqS->items[0]; test_assert(strcmp(u->seq, "A") == 0); test_assert(u->count == 9); test_assert(u->canonical == NULL); for (int i = 1 ; i < 9 ; i++) { test_assert(useqS->items[i] == NULL); } destroy_useq(useqS->items[0]); useqS->nitems = 0; for (int i = 0 ; i < 9 ; i++) { push(new_useq(1, i % 2 ? "A":"B", NULL), &useqS); } test_assert(useqS->nitems == 9); test_assert(seqsort((useq_t **) useqS->items, 9, 1) == 2); test_assert_critical(useqS->items[0] != NULL); test_assert_critical(useqS->items[1] != NULL); for (int i = 2 ; i < 9 ; i++) { test_assert(useqS->items[i] == NULL); } u = useqS->items[0]; test_assert(strcmp(u->seq, "A") == 0); test_assert(u->count == 4); test_assert(u->canonical == NULL); u = useqS->items[1]; test_assert(strcmp(u->seq, "B") == 0); test_assert(u->count == 5); test_assert(u->canonical == NULL); destroy_useq(useqS->items[0]); destroy_useq(useqS->items[1]); // Case 1 (no repeat). char *sequences_1[10] = { "IRrLv<'*3S?UU<JF4S<,", "tcKvz5JTm!h*X0mSTg", "tW:0K&Mvtax<PP/qY6er", "hcU+f!=`.Xs6[a,C7XpN", ":3ILp'w?)f]4(a;mf%A9", "RlEF',$6[}ouJQyWqqT#", "U Ct`3w8(#KAE+z;vh,", "[S^jXvNS VP' cwg~_iq", ".*/@*Q/]]}32kNB#`qqv", "#`Hwp(&,z|bN~07CSID'", }; const char *sorted_1[10] = { "tcKvz5JTm!h*X0mSTg", "U Ct`3w8(#KAE+z;vh,", "#`Hwp(&,z|bN~07CSID'", ".*/@*Q/]]}32kNB#`qqv", ":3ILp'w?)f]4(a;mf%A9", "IRrLv<'*3S?UU<JF4S<,", "RlEF',$6[}ouJQyWqqT#", "[S^jXvNS VP' cwg~_iq", "hcU+f!=`.Xs6[a,C7XpN", "tW:0K&Mvtax<PP/qY6er", }; useq_t *to_sort_1[10]; for (int i = 0 ; i < 10 ; i++) { to_sort_1[i] = new_useq(1, sequences_1[i], NULL); } test_assert(seqsort(to_sort_1, 10, 1) == 10); for (int i = 0 ; i < 10 ; i++) { test_assert(strcmp(to_sort_1[i]->seq, sorted_1[i]) == 0); test_assert(to_sort_1[i]->count == 1); destroy_useq(to_sort_1[i]); } // Case 2 (different lengths). char *sequences_2[10] = { "IRr", "tcKvz5JTm!h*X0mSTg", "tW:0K&Mvtax<PP/qY6er", "hcU+f!=`.Xs6[a,C7XpNwoi~OWe88", "z3ILp'w?)f]4(a;mf9", "RlEFWqqT#", "U Ct`3w8(#Kz;vh,", "aS^jXvNS VP' cwg~_iq", ".*/@*Q/]]}32#`", "(&,z|bN~07CSID'", }; const char *sorted_2[10] = { "IRr", "RlEFWqqT#", ".*/@*Q/]]}32#`", "(&,z|bN~07CSID'", "U Ct`3w8(#Kz;vh,", "tcKvz5JTm!h*X0mSTg", "z3ILp'w?)f]4(a;mf9", "aS^jXvNS VP' cwg~_iq", "tW:0K&Mvtax<PP/qY6er", "hcU+f!=`.Xs6[a,C7XpNwoi~OWe88", }; useq_t *to_sort_2[10]; for (int i = 0 ; i < 10 ; i++) { to_sort_2[i] = new_useq(1, sequences_2[i], NULL); } test_assert(seqsort(to_sort_2, 10, 1) == 10); for (int i = 0 ; i < 10 ; i++) { test_assert(strcmp(to_sort_2[i]->seq, sorted_2[i]) == 0); test_assert(to_sort_2[i]->count == 1); destroy_useq(to_sort_2[i]); } // Case 3 (repeats). char *sequences_3[6] = { "repeat", "repeat", "repeat", "repeat", "repeat", "xyz" }; char *sorted_3[6] = { "xyz", "repeat", NULL, NULL, NULL, NULL, }; int counts[2] = {1,5}; useq_t *to_sort_3[6]; for (int i = 0 ; i < 6 ; i++) { to_sort_3[i] = new_useq(1, sequences_3[i], NULL); } test_assert(seqsort(to_sort_3, 6, 1) == 2); for (int i = 0 ; i < 2 ; i++) { test_assert(strcmp(to_sort_3[i]->seq, sorted_3[i]) == 0); test_assert(to_sort_3[i]->count == counts[i]); destroy_useq(to_sort_3[i]); } for (int i = 2 ; i < 6 ; i++) { test_assert(to_sort_3[i] == NULL); } // Case 4 (realistic). char *seq[35] = { "AGGGCTTACAAGTATAGGCC", "TGCGCCAAGTACGATTTCCG", "CCTCATTATTTGTCGCAATG", "AGGGCTTACAAGTATAGGCC", "AGGGCTTACAAGTATAGGCC", "GGGAGCCCACAGTAAGCGAA", "GGGAGCCCACAGTAAGCGAA", "TAGCCTGGTGCGACTGTCAT", "TAGCCTGGTGCGACTGTCAT", "GGAAGCCCACAGCAAGCGAA", "TGCGCCAAGTACGATTTCCG", "GGGAGCCCACAGTAAGCGAA", "AGGGGTTACAAGTCTAGGCC", "CCTCATTATTTGTCGCAATG", "GGGAGCCCACAGTAAGCGAA", "TAGCCTGGTGCGACTGTCAT", "AGGGCTTACAAGTATAGGCC", "TGCGCCAAGTACGATTTCCG", "CCTCATTATTTGTCGCAATG", "AGGGCTTACAAGTATAGGCC", "TAGCCTGGTGCGACTGTCAT", "AGGGCTTACAAGTATAGGCC", "TGCGCCAAGTAAGAATTCCG", "GGGAGCCCACAGTAAGCGAA", "GGGAGCCCACAGTAAGCGAA", "TGCGCCAAGTACGATTTCCG", "CCTCATTATTTGTCGCAATG", "TAGCCTGGTGCGACTGTCAT", "TGCGCCAAGTACGATTTCCG", "CCTCATTATTTGTCGCAATG", "CCTCATTATTTGTCGCAATG", "CCTCATTATTTACCGCAATG", "TAGCCTGGTGCGACTGTCAT", "TGCGCCAAGTACGATTTCCG", "TAACCTGGTGCGACTGTTAT", }; char *sorted_4[10] = { "AGGGCTTACAAGTATAGGCC", "AGGGGTTACAAGTCTAGGCC", "CCTCATTATTTACCGCAATG", "CCTCATTATTTGTCGCAATG", "GGAAGCCCACAGCAAGCGAA", "GGGAGCCCACAGTAAGCGAA", "TAACCTGGTGCGACTGTTAT", "TAGCCTGGTGCGACTGTCAT", "TGCGCCAAGTAAGAATTCCG", "TGCGCCAAGTACGATTTCCG", }; int counts_4[10] = {6,1,1,6,1,6,1,6,1,6}; // Test 'seqsort()' with 1 to 8 threads. for (int t = 1 ; t < 9 ; t++) { useqS->nitems = 0; for (int i = 0 ; i < 35 ; i++) { push(new_useq(1, seq[i], NULL), &useqS); } test_assert(seqsort((useq_t **) useqS->items, 35, t) == 10); for (int i = 0 ; i < 10 ; i++) { test_assert_critical(useqS->items[i] != NULL); u = useqS->items[i]; test_assert(strcmp(u->seq, sorted_4[i]) == 0); test_assert(u->count == counts_4[i]); test_assert(u->canonical == NULL); destroy_useq(u); } for (int i = 10 ; i < 35 ; i++) { test_assert(useqS->items[i] == NULL); } } free(useqS); }
void test_starcode_9 (void) // Test 'lut_insert()' and lut_search(). { srand48(123); lookup_t *lut = new_lookup(20, 20, 3); test_assert_critical(lut != NULL); // Insert a too short string (nothing happens). useq_t *u = new_useq(0, "", NULL); test_assert_critical(u != NULL); test_assert(lut_insert(lut, u) == 0); destroy_useq(u); // Insert the following k-mers: ACG|TAGC|GCTA|TAGC|GATCA u = new_useq(0, "ACGTAGCGCTATAGCGATCA", NULL); test_assert_critical(u != NULL); test_assert(lut_insert(lut, u) == 0); test_assert(lut_search(lut, u) == 1); destroy_useq(u); u = new_useq(0, "CGTAGCGCTATAGCGATCAA", NULL); test_assert_critical(u != NULL); test_assert(lut_search(lut, u) == 1); destroy_useq(u); u = new_useq(0, "AAAATAGCGCCCCCCCCCCC", NULL); test_assert_critical(u != NULL); test_assert(lut_search(lut, u) == 1); destroy_useq(u); u = new_useq(0, "CCCCCCCCCCCCCCCGATCA", NULL); test_assert_critical(u != NULL); test_assert(lut_search(lut, u) == 1); destroy_useq(u); u = new_useq(0, "CCCCCGCTACCCCCCCCCCC", NULL); test_assert_critical(u != NULL); test_assert(lut_search(lut, u) == 1); destroy_useq(u); u = new_useq(0, "TAGCAAAAAAAAAAAAAAAA", NULL); test_assert_critical(u != NULL); test_assert(lut_search(lut, u) == 1); destroy_useq(u); u = new_useq(0, "CCCCCCCCCCCCCCGATCAC", NULL); test_assert_critical(u != NULL); test_assert(lut_search(lut, u) == 0); destroy_useq(u); u = new_useq(0, "AAAAAAAAAAAAAAAAAAAA", NULL); test_assert_critical(u != NULL); test_assert(lut_search(lut, u) == 0); destroy_useq(u); destroy_lookup(lut); lut = NULL; lut = new_lookup(20, 20, 3); test_assert_critical(lut != NULL); for (int i = 0 ; i < 10000 ; i++) { // Create random sequences without "N". char seq[21] = {0}; for (int j = 0 ; j < 20 ; j++) { seq[j] = untranslate[(int)(1 + 4*drand48())]; } u = new_useq(0, seq, NULL); test_assert(lut_insert(lut, u) == 0); test_assert(lut_search(lut, u) == 1); destroy_useq(u); } destroy_lookup(lut); // Insert every 4-mer. lut = new_lookup(19, 19, 3); test_assert_critical(lut != NULL); char seq[20] = "AAAAAAAAAAAAAAAAAAA"; //AAA|AAAA|AAAA|AAAA for (int i = 0 ; i < 256 ; i++) { for (int j = 0 ; j < 4 ; j++) { char nt = untranslate[1 + (int)((i >> (2*j)) & 3)]; seq[j+3] = seq[j+7] = seq[j+11] = seq[j+15] = nt; } u = new_useq(0, seq, NULL); test_assert_critical(u != NULL); test_assert(lut_insert(lut, u) == 0); destroy_useq(u); } for (int i = 0 ; i < 4 ; i++) { test_assert(*lut->lut[i] == 255); } destroy_lookup(lut); // Insert randomly. lut = new_lookup(64, 64, 3); test_assert_critical(lut != NULL); for (int i = 0 ; i < 4 ; i++) { // MAX_K_FOR_LOOKUP test_assert_critical(lut->klen[i] == 14); } for (int i = 0 ; i < 4096 ; i++) { char seq[65] = {0}; // Create random sequences without "N". for (int j = 0 ; j < 64 ; j++) { seq[j] = untranslate[(int)(1 + 4*drand48())]; } u = new_useq(0, seq, NULL); test_assert_critical(u != NULL); test_assert(lut_insert(lut, u) == 0); destroy_useq(u); } const int set_bits_per_byte[256] = { 0,1,1,2,1,2,2,3,1,2,2,3,2,3,3,4, 1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5, 1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5, 2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6, 1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5, 2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6, 2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6, 3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7, 1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5, 2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6, 2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6, 3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7, 2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6, 3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7, 3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7, 4,5,5,6,5,6,6,7,5,6,6,7,6,7,7,8, }; int jmax = 1 << (2*14 - 3); for (int i = 0 ; i < 4 ; i++) { int total = 0; for (int j = 0 ; j < jmax ; j++) { total += set_bits_per_byte[lut->lut[i][j]]; } // The probability of collision is negligible. test_assert(total == 4096); } destroy_lookup(lut); }
void test_starcode_4 (void) // Test 'canonical_order'. { useq_t *u1 = new_useq(1, "ABCD", NULL); useq_t *u2 = new_useq(2, "EFGH", NULL); test_assert_critical(u1 != NULL); test_assert_critical(u2 != NULL); // 'u1' and 'u2' have no canonical, so the // comparison is alphabetical. test_assert(canonical_order(&u1, &u2) < 0); test_assert(canonical_order(&u2, &u1) > 0); // Add match to 'u1', and update canonicals. addmatch(u1, u2, 1, 1); test_assert_critical(u1->matches != NULL); transfer_counts_and_update_canonicals(u1); test_assert(u1->count == 0); test_assert(u2->count == 3); // Now 'u1' and 'u2' have the same canonical ('u2') // so the comparison is again alphabetical. test_assert(canonical_order(&u1, &u2) < 0); test_assert(canonical_order(&u2, &u1) > 0); useq_t *u3 = new_useq(1, "CDEF", NULL); useq_t *u4 = new_useq(2, "GHIJ", NULL); test_assert_critical(u3 != NULL); test_assert_critical(u4 != NULL); // Comparisons with 'u1' or with 'u2' give the same // results because they have the same canonical ('u2'). test_assert(canonical_order(&u1, &u3) == -1); test_assert(canonical_order(&u2, &u3) == -1); test_assert(canonical_order(&u3, &u1) == 1); test_assert(canonical_order(&u3, &u2) == 1); test_assert(canonical_order(&u1, &u4) == -1); test_assert(canonical_order(&u2, &u4) == -1); test_assert(canonical_order(&u4, &u1) == 1); test_assert(canonical_order(&u4, &u2) == 1); // Comparisons between 'u3' and 'u4' are alphabetical. test_assert(canonical_order(&u3, &u4) < 0); test_assert(canonical_order(&u4, &u3) > 0); // Add match to 'u3', and update canonicals. addmatch(u3, u4, 1, 1); test_assert_critical(u3->matches != NULL); transfer_counts_and_update_canonicals(u3); test_assert(u3->count == 0); test_assert(u4->count == 3); // Now canonicals ('u2' and 'u4') have the same counts // so comparisons are always alphabetical. test_assert(canonical_order(&u1, &u3) < 0); test_assert(canonical_order(&u2, &u3) < 0); test_assert(canonical_order(&u3, &u1) > 0); test_assert(canonical_order(&u3, &u2) > 0); test_assert(canonical_order(&u1, &u4) < 0); test_assert(canonical_order(&u2, &u4) < 0); test_assert(canonical_order(&u4, &u1) > 0); test_assert(canonical_order(&u4, &u2) > 0); test_assert(canonical_order(&u3, &u4) < 0); test_assert(canonical_order(&u4, &u3) > 0); useq_t *u5 = new_useq(1, "CDEF", NULL); useq_t *u6 = new_useq(3, "GHIJ", NULL); test_assert_critical(u5 != NULL); test_assert_critical(u6 != NULL); // Comparisons between canonicals. test_assert(canonical_order(&u1, &u5) == -1); test_assert(canonical_order(&u2, &u5) == -1); test_assert(canonical_order(&u5, &u1) == 1); test_assert(canonical_order(&u5, &u2) == 1); test_assert(canonical_order(&u1, &u6) == -1); test_assert(canonical_order(&u2, &u6) == -1); test_assert(canonical_order(&u6, &u1) == 1); test_assert(canonical_order(&u6, &u2) == 1); test_assert(canonical_order(&u3, &u5) == -1); test_assert(canonical_order(&u4, &u5) == -1); test_assert(canonical_order(&u5, &u3) == 1); test_assert(canonical_order(&u5, &u4) == 1); test_assert(canonical_order(&u3, &u6) == -1); test_assert(canonical_order(&u4, &u6) == -1); test_assert(canonical_order(&u6, &u3) == 1); test_assert(canonical_order(&u6, &u4) == 1); // Alphabetical comparisons. test_assert(canonical_order(&u5, &u6) < 0); test_assert(canonical_order(&u6, &u5) > 0); // Add match to 'u5', and update canonicals. addmatch(u5, u6, 1, 1); test_assert_critical(u5->matches != NULL); transfer_counts_and_update_canonicals(u5); test_assert(u5->count == 0); test_assert(u6->count == 4); // Comparisons between canonicals ('u2', 'u4', 'u6'). test_assert(canonical_order(&u1, &u5) == 1); test_assert(canonical_order(&u2, &u5) == 1); test_assert(canonical_order(&u5, &u1) == -1); test_assert(canonical_order(&u5, &u2) == -1); test_assert(canonical_order(&u1, &u6) == 1); test_assert(canonical_order(&u2, &u6) == 1); test_assert(canonical_order(&u6, &u1) == -1); test_assert(canonical_order(&u6, &u2) == -1); test_assert(canonical_order(&u3, &u5) == 1); test_assert(canonical_order(&u4, &u5) == 1); test_assert(canonical_order(&u5, &u3) == -1); test_assert(canonical_order(&u5, &u4) == -1); test_assert(canonical_order(&u3, &u6) == 1); test_assert(canonical_order(&u4, &u6) == 1); test_assert(canonical_order(&u6, &u3) == -1); test_assert(canonical_order(&u6, &u4) == -1); // Alphabetical. test_assert(canonical_order(&u5, &u6) < 0); test_assert(canonical_order(&u6, &u5) > 0); useq_t *useq_array[6] = {u1,u2,u3,u4,u5,u6}; useq_t *sorted[6] = {u5,u6,u1,u2,u3,u4}; qsort(useq_array, 6, sizeof(useq_t *), canonical_order); for (int i = 0 ; i < 6 ; i++) { test_assert(useq_array[i] == sorted[i]); } destroy_useq(u1); destroy_useq(u2); destroy_useq(u3); destroy_useq(u4); destroy_useq(u5); destroy_useq(u6); }
void test_tabulate (void) { uint32_t x[] = {1,2,3,4,5,6,7,8,9,10,11,12}; tab_t *tab; tab = tabulate(x, 3, 4); test_assert_critical(tab != NULL); test_assert(tab->size == 4); test_assert(tab->val[0] == 15); test_assert(tab->val[1] == 18); test_assert(tab->val[2] == 21); test_assert(tab->val[3] == 24); for (int i = 0 ; i < 4 ; i++) { test_assert(tab->num[i] == 1); } free(tab); tab = tabulate(x, 4, 3); test_assert_critical(tab != NULL); test_assert(tab->size == 3); test_assert(tab->val[0] == 22); test_assert(tab->val[1] == 26); test_assert(tab->val[2] == 30); for (int i = 0 ; i < 3 ; i++) { test_assert(tab->num[i] == 1); } free(tab); uint32_t y[] = {4096,2048,1024,512}; tab = tabulate(y, 1, 4); test_assert_critical(tab != NULL); test_assert(tab->size == 4); test_assert(tab->val[0] == 512); test_assert(tab->val[1] == 1024); test_assert(tab->val[2] == 2048); test_assert(tab->val[3] == 4096); for (int i = 0 ; i < 4 ; i++) { test_assert(tab->num[i] == 1); } free(tab); tab = tabulate(y, 2, 2); test_assert_critical(tab != NULL); test_assert(tab->size == 2); test_assert(tab->val[0] == 2560); test_assert(tab->val[1] == 5120); for (int i = 0 ; i < 2 ; i++) { test_assert(tab->num[i] == 1); } free(tab); uint32_t z[] = {1,2,23784983}; tab = tabulate(z, 1, 3); test_assert_critical(tab != NULL); test_assert(tab->size == 3); test_assert(tab->val[0] == 1); test_assert(tab->val[1] == 2); test_assert(tab->val[2] == 23784983); free(tab); return; }
void test_io_stream_read_seq (void) { iostream_t * stream; gstack_t * stack; seqread_t * read; // Invalid arguments. redirect_stderr(); test_assert(io_stream_read_seq(NULL) == NULL); unredirect_stderr(); // Load files. // Read RAW file. stream = io_stream_open("examples/io_input.raw"); test_assert_critical(stream != NULL); stack = io_stream_read_seq(stream); test_assert_critical(stack != NULL); test_assert(gstack_num_elm(stack) == 6); read = seqread_pop(stack); test_assert(read != NULL); test_assert(strcmp(seqread_seq(read), "NNNNNNLLYYYYJDFLS") == 0); test_assert(strcmp(seqread_tag(read), "6") == 0); seqread_free(read); read = seqread_pop(stack); test_assert(read != NULL); test_assert(strcmp(seqread_seq(read), "NNNNNNNNACGTACGCC") == 0); test_assert(strcmp(seqread_tag(read), "5") == 0); seqread_free(read); read = seqread_pop(stack); test_assert(read != NULL); test_assert(strcmp(seqread_seq(read), "ACGTACATGTATGACAC") == 0); test_assert(strcmp(seqread_tag(read), "4") == 0); seqread_free(read); gstack_free(stack); io_stream_free(stream); // Read FASTA file. stream = io_stream_open_buf("examples/io_input.fasta", 80); test_assert_critical(stream != NULL); stack = io_stream_read_seq(stream); test_assert_critical(stack != NULL); test_assert(gstack_num_elm(stack) == 4); read = seqread_pop(stack); test_assert(read != NULL); test_assert(strcmp(seqread_seq(read), "ACGTACATGTATGACAC") == 0); test_assert(strcmp(seqread_tag(read), "seq4") == 0); seqread_free(read); read = seqread_pop(stack); test_assert(read != NULL); test_assert(strcmp(seqread_seq(read), "AGTCGANTATACNTACG") == 0); test_assert(strcmp(seqread_tag(read), "seq3") == 0); seqread_free(read); read = seqread_pop(stack); test_assert(read != NULL); test_assert(strcmp(seqread_seq(read), "GTATCGACTACGAGCTA") == 0); test_assert(strcmp(seqread_tag(read), "seq2") == 0); seqread_free(read); read = seqread_pop(stack); test_assert(read != NULL); test_assert(strcmp(seqread_seq(read), "ATGCGTACGTCGTATCA") == 0); test_assert(strcmp(seqread_tag(read), "seq1") == 0); seqread_free(read); gstack_free(stack); stack = io_stream_read_seq(stream); test_assert_critical(stack != NULL); test_assert(gstack_num_elm(stack) == 2); read = seqread_pop(stack); test_assert(read != NULL); test_assert(strcmp(seqread_seq(read), "NNNNNNLLYYYYJDFLS") == 0); test_assert(strcmp(seqread_tag(read), "seq6") == 0); seqread_free(read); read = seqread_pop(stack); test_assert(read != NULL); test_assert(strcmp(seqread_seq(read), "NNNNNNNNACGTACGCC") == 0); test_assert(strcmp(seqread_tag(read), "seq5") == 0); seqread_free(read); gstack_free(stack); io_stream_free(stream); // Read FASTQ file. stream = io_stream_open_buf("examples/io_input.fastq", 50); test_assert_critical(stream != NULL); stack = io_stream_read_seq(stream); test_assert_critical(stack != NULL); test_assert(gstack_num_elm(stack) == 2); read = seqread_pop(stack); test_assert(read != NULL); test_assert(strcmp(seqread_seq(read), "GTATCGACTACGAGCTA") == 0); test_assert(strcmp(seqread_tag(read), "seq2") == 0); test_assert(strcmp(seqread_qscore(read), "BACBABCA0ACBB00AC") == 0); seqread_free(read); read = seqread_pop(stack); test_assert(read != NULL); test_assert(strcmp(seqread_seq(read), "ATGCGTACGTCGTATCA") == 0); test_assert(strcmp(seqread_tag(read), "seq1") == 0); test_assert(strcmp(seqread_qscore(read), "12391284194819241") == 0); seqread_free(read); gstack_free(stack); stack = io_stream_read_seq(stream); test_assert_critical(stack != NULL); test_assert(gstack_num_elm(stack) == 2); gstack_free(stack); stack = io_stream_read_seq(stream); test_assert_critical(stack != NULL); test_assert(gstack_num_elm(stack) == 2); gstack_free(stack); stack = io_stream_read_seq(stream); test_assert_critical(stack != NULL); test_assert(gstack_num_elm(stack) == 0); gstack_free(stack); stack = io_stream_read_seq(stream); test_assert(stack == NULL); io_stream_free(stream); }