/* Performs some basic tests. Feel free to define additional tests. */ void test_basic() { Row *sparse_matrix; unsigned char small[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09 }; unsigned char empty[] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; unsigned char tiny[] = { 56 }; unsigned char sample[] = { 0xFF, 0x01, 0x02, 0xFF, 0XFF, 0XFF, 0x03, 0x04, 0x05, 0x06, 0xFF, 0x07 }; sparse_matrix = dense_to_sparse(small, 3, 3); test_sparse("small", sparse_matrix); free_sparse(sparse_matrix); sparse_matrix = dense_to_sparse(empty, 3, 3); test_sparse("empty", sparse_matrix); free_sparse(sparse_matrix); sparse_matrix = dense_to_sparse(tiny, 1, 1); test_sparse("tiny", sparse_matrix); free_sparse(sparse_matrix); sparse_matrix = dense_to_sparse(sample, 3, 4); test_sparse("sample", sparse_matrix); free_sparse(sparse_matrix); }
int main(int argc, char **argv) { Image img; Row *sparse_matrix; if ( argc != 2 ) { test_basic(); } else { img = load_bmp(argv[1]); sparse_matrix = dense_to_sparse(img.data, img.width, img.height); test_sparse(argv[1], sparse_matrix); free_sparse(sparse_matrix); } return 0; }
void iterate(Fastal_param *param, void *method_arguments_p, char *aln_file_name, char *out_file_name_end, int iteration_number) { // calculate alignment length //count gap int it_coutner_2 = 0; const int LINE_LENGTH = 200; char line[LINE_LENGTH]; char *seq1 = (char*)vcalloc(1,sizeof(char)); char *seq2 = (char*)vcalloc(1,sizeof(char)); Fastal_profile **profiles =(Fastal_profile**) vcalloc(3,sizeof(Fastal_profile*)); initiate_profiles(profiles, param); Fastal_profile *gap_prf = profiles[0]; Fastal_profile *no_gap_prf = profiles[1]; int alphabet_size = param->alphabet_size; int *gap_list_1 = (int*)vcalloc(1, sizeof(int)); int *gap_list_1_length = (int*)vcalloc(1, sizeof(int)); *gap_list_1_length = 1; int num_gaps_1 = 0; int *gap_list_2 = (int*)vcalloc(1, sizeof(int)); int *gap_list_2_length = (int*)vcalloc(1, sizeof(int)); *gap_list_2_length = 1; int num_gaps_2 = 0; int alignment_length = 1; //from here repeat! int it_counter = 0; char *out_file_name = aln_file_name; int *gap_profile = (int*)vcalloc(alignment_length, sizeof(int)); // while (it_counter < alignment_length) // { FILE *alignment_file = fopen(aln_file_name,"r"); if (alignment_file == NULL) { printf("Could not open alignment file %s\n", aln_file_name); exit(1); } alignment_length = 0; int tmp_len = -1; fgets(line, LINE_LENGTH , alignment_file); while(fgets(line, LINE_LENGTH , alignment_file)!=NULL) { tmp_len = -1; if (line[0] == '>') { break; } while ((line[++tmp_len] != '\n') && (line[tmp_len] != '\0')); alignment_length += tmp_len; } // printf("ALN_LENGTH %i\n", alignment_length); seq1 =(char*)vrealloc(seq1, (1+alignment_length)*sizeof(char)); gap_profile = (int*)vrealloc(gap_profile, alignment_length * sizeof(int)); int i; for (i = 0; i < alignment_length; ++i) { gap_profile[i] = 0; } int number_of_sequences = 0; int pos = -1; fseek (alignment_file , 0 , SEEK_SET); while(fgets(line, LINE_LENGTH , alignment_file)!=NULL) { if (line[0] == '>') { ++number_of_sequences; pos = -1; } else { i = -1; while ((line[++i] != '\n') && (line[i] != '\0')) { ++pos; if (line[i] == '-') { ++gap_profile[pos]; } } } } double max_entrop = 0; int column_index = 0; double entrop = 0; double last = 0; double p; // for (i = it_counter; i<=it_counter; ++i) // { // p = gap_profile[i]/(double)number_of_sequences; // if (!p) // { // entrop = 0; // } // else // { // entrop = (-1)*(p*log(p) + (1-p)*log(1-p) ) ; // } // if (entrop > max_entrop) // { // column_index = i; // max_entrop = entrop; // } // last = entrop; // } // ++it_counter; // if (max_entrop < 0.6) // { // printf("CONTINUE %f\n",entrop); // continue; // } // column_index = 18;//it_counter-1; // if (column_index == 19) column_index = 58; out_file_name = vtmpnam(NULL); char *edit_file_name = "EDIT";//vtmpnam(NULL); FILE *edit_file = fopen(edit_file_name,"w"); char *profile_file_name = vtmpnam(NULL); FILE *profile_file = fopen(profile_file_name,"w"); char *split_file_name = "AHA";//vtmpnam(NULL); ++it_coutner_2; gap_prf = enlarge_prof(gap_prf, alignment_length, alphabet_size); no_gap_prf = enlarge_prof(no_gap_prf, alignment_length, alphabet_size ); no_gap_prf->number_of_sequences = 0; gap_prf->number_of_sequences = 0; split_set(alignment_file, gap_prf, no_gap_prf, seq1, column_index, param->char2pos, split_file_name); gap_prf -> length = alignment_length; no_gap_prf -> length = alignment_length; gap_list_1 = del_gap_from_profile(gap_prf, alphabet_size, gap_list_1, gap_list_1_length, &num_gaps_1 ); gap_list_2 = del_gap_from_profile(no_gap_prf, alphabet_size, gap_list_2, gap_list_2_length, &num_gaps_2 ); fclose(alignment_file); profiles[0] = gap_prf; profiles[1] = no_gap_prf; alignment_length = gotoh_dyn(profiles, param, method_arguments_p, 0, edit_file, profile_file, 0); seq1 =(char*)vrealloc(seq1, (1+alignment_length)*sizeof(char)); seq2 =(char*)vrealloc(seq2, (1+alignment_length)*sizeof(char)); fclose(edit_file); edit_file = fopen(edit_file_name,"r"); edit2seq_pattern(edit_file, seq1, seq2); fclose(edit_file); fclose(profile_file); write_iterated_aln(aln_file_name, out_file_name, split_file_name, seq1, gap_list_1, num_gaps_1, seq2, gap_list_2, num_gaps_2); aln_file_name = out_file_name; // if (it_coutner_2 == 2) // break; // } char command[1000]; sprintf(command, "mv %s %s",out_file_name, out_file_name_end); system(command); vfree(seq1); vfree(seq2); vfree(gap_list_1); vfree(gap_list_2); if (!strcmp(param->method, "fast")) { free_sparse((Sparse_dynamic_param*)method_arguments_p); } else if (!strcmp(param->method, "nw")) { free_nw((Nw_param*)method_arguments_p, alphabet_size); } else if (!strcmp(param->method, "gotoh")) { free_gotoh((Gotoh_param*)method_arguments_p, alphabet_size); } }
/* Performs some basic tests. Feel free to define additional tests. */ void test_basic() { Row *sparse_matrix; unsigned char small[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09 }; unsigned char empty[] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; unsigned char tiny[] = { 56 }; unsigned char empty_center[] = { 0x01, 0x02, 0x03, 0x04, 0xFF, 0x06, 0x07, 0x08, 0x09 }; unsigned char white_margins_empty_spots[] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x01, 0x01, 0x01, 0x01, 0xFF, 0xFF, 0x02, 0x02, 0x02, 0x02, 0xFF, 0xFF, 0x03, 0xFF, 0xFF, 0x03, 0xFF, 0xFF, 0xFF, 0x04, 0x04, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; unsigned char theres_a_seven_in_there[] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x07, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; unsigned char skips_middle_line[] = { 0x01, 0x02, 0x03, 0xFF, 0xFF, 0xFF, 0x07, 0x08, 0x09 }; sparse_matrix = dense_to_sparse(small, 3, 3); test_sparse("small", sparse_matrix); free_sparse(sparse_matrix); sparse_matrix = dense_to_sparse(empty, 3, 3); test_sparse("empty", sparse_matrix); free_sparse(sparse_matrix); sparse_matrix = dense_to_sparse(tiny, 1, 1); test_sparse("tiny", sparse_matrix); free_sparse(sparse_matrix); sparse_matrix = dense_to_sparse(empty_center, 3, 3); test_sparse("empty_center", sparse_matrix); free_sparse(sparse_matrix); sparse_matrix = dense_to_sparse(white_margins_empty_spots, 6, 6); test_sparse("white_margins_empty_spots", sparse_matrix); free_sparse(sparse_matrix); sparse_matrix = dense_to_sparse(theres_a_seven_in_there, 6, 6); test_sparse("theres_a_seven_in_there", sparse_matrix); free_sparse(sparse_matrix); sparse_matrix = dense_to_sparse(skips_middle_line, 3, 3); test_sparse("skips_middle_line", sparse_matrix); free_sparse(sparse_matrix); }