void interval_set_mixed_ctor_4_ordered_types()
{         
    typedef interval_set<T> IntervalSetT;
    typedef typename IntervalSetT::interval_type IntervalT;

    T v0 = boost::icl::identity_element<T>::value();
    
    split_interval_set<T>    split_set(v0);
    separate_interval_set<T> sep_set(split_set);
    interval_set<T>          join_set(sep_set);

    BOOST_CHECK_EQUAL( hull(split_set).lower(), hull(sep_set).lower() );
    BOOST_CHECK_EQUAL( hull(split_set).lower(), hull(join_set).lower() );
}
Beispiel #2
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);
    }
}