Пример #1
0
int hpx_main()
{
    {
        std::vector<int> keys =
        {
            1,   4,   2,   8,   5,   7,   1,   4,   2,   8,   5,   7,
            1,   4,   2,   8,   5,   7,   1,   4,   2,   8,   5,   7,
            1,   4,   2,   8,   5,   7,   1,   4,   2,   8,   5,   7
        };
        std::vector<char> values =
        {
            'a', 'b', 'c', 'd', 'e', 'f', 'a', 'b', 'c', 'd', 'e', 'f',
            'a', 'b', 'c', 'd', 'e', 'f', 'a', 'b', 'c', 'd', 'e', 'f',
            'a', 'b', 'c', 'd', 'e', 'f', 'a', 'b', 'c', 'd', 'e', 'f'
        };

        hpx::cout << "unsorted sequence: {";
        print_sequence(keys, values);

        hpx::parallel::sort_by_key(
            hpx::parallel::par,
            keys.begin(),
            keys.end(),
            values.begin());

        hpx::cout << "sorted sequence:   {";
        print_sequence(keys, values);
    }

    return hpx::finalize();
}
Пример #2
0
void print_sorted_alignment(sorted_alignment_block aln){
   if(aln==NULL) return;
   printf("\na %s\n", aln->data);
   int i =0;
   for(;i<aln->in_size; ++i) print_sequence(aln->in_sequences[i]);
   for(i=0; i < aln->out_size; ++i) print_sequence(aln->out_sequences[i]);
}
int main(int argc, char *argv[])
{
    int sequence[] = {3, 3242, 21, 55, 653, 19, 139, 459, 138, 45349, 19, 2, 1}; 
    int sequence_length = sizeof(sequence)/sizeof(sequence[0]);

    printf("Sorting %d values in sequence ", sequence_length);
    print_sequence(sequence, sequence_length);

    /* Insertion Sort */
    int marker, key_index, key;

    for (key_index = 1; key_index < sequence_length; key_index++) {  // traverse sequence, start at 2nd index
        key = sequence[key_index];
        marker = key_index - 1;  // set marker at first index left of current key index

        while (marker > -1 && sequence[marker] > key) {
            sequence[marker+1] = sequence[marker];  // if marker val greater than key, shift right
            marker = marker - 1;  // count left while current marker val is greater than key
        }
        sequence[marker+1] = key;  // replace key
    }

    printf("Done sorting into result sequence ");
    print_sequence(sequence, sequence_length);

    return 0;
}
Пример #4
0
int main() {
	/* integers all must have the same amount of digits */
	int seq[SEQUENCE_LENGTH] = {7325, 1334, 4432, 5991, 1324, 8421, 5838, 3492, 6539, 3591};

	print_before_message();
	print_sequence(seq);

	radix_sort(seq);

	print_after_message();
	print_sequence(seq);
}
void init_screen(uint8_t i2c_address)
{
	//_delay_ms(110); //TOO FAST, WILL NOT TURN ON.
	//_delay_ms(115); //WORKS
	//_delay_ms(112); //SOMETIMES WORKED THEN STOPPED WORKING
	_delay_ms(150);
	print_sequence(init_sequence,i2c_address);
}
Пример #6
0
void cq(int sum) {
    if (sum < 3)  return;
    int small = 1;
    int big = 2;
    int mid = (sum + 1)/2;
    int cur_sum = small + big;
    while (small < mid) {
        if (cur_sum == sum) {
            print_sequence(small, big);
        }
        while (cur_sum > sum && small < mid) {
            cur_sum -= small;
            small++;
            if (cur_sum == sum)  print_sequence(small, big);
        }
        big++;
        cur_sum += big;
    }
    return;
}
int main(int argc, char *argv[])
{
    int sequence[] = {3, 3242, 21, 55, 653, 19, 139, 459, 138, 45349, 19, 2, 1}; 
    int sequence_length = sizeof(sequence)/sizeof(sequence[0]);

    printf("Sorting %d values in sequence ", sequence_length);
    print_sequence(sequence, sequence_length);

    insertion_sort(sequence, sequence_length);

    printf("Done sorting. Result ");
    print_sequence(sequence, sequence_length);

    printf("Testing if result sort is valid....");
    int pass = test_insertion_sort(sequence, sequence_length);
    if (pass)
        printf("Yes!\n");
    else
        printf("No!\n");

    return 0;
}
Пример #8
0
void print_hash_alignment(hash_alignment_block aln){
   if(aln==NULL) return;
   printf("\na %s\n",aln->data);
   ENTRY *ret_val;
   int hc=0;
   for(int i = 0; i < aln->size; ++i){
      ENTRY search={aln->species[i],NULL};
      hc = hsearch_r(search,FIND,&ret_val,aln->sequences);
      if(hc == 0){
         fprintf(stderr,"Failed to read hash table: %s\n", strerror(errno));
         exit(1);
      }
      if(ret_val != NULL) print_sequence(ret_val->data);
   }
}
Пример #9
0
void radix_sort(int *seq) {
	int i, j, h;
	int bucket[10][SEQUENCE_LENGTH];
	int largest;
	int n_digits;

	largest = largest_number_in_sequence(seq);
	n_digits = how_many_digits_in_number(largest);

	for (i = (n_digits - 1); i >= 0; i--) {
  	    zero_out_bucket(bucket);
 	    populate_bucket(i, seq, bucket);
	    restore_bucket_to_seq(seq, bucket);
	    printf("Sequence after sorting %dth digit\n", i);
	    print_sequence(seq);
	}
}
Пример #10
0
/* used in window-mode to shift the input sequence */
void shift_input(toptions *opts, tsequence *seq, char output){
  int i;
  
/*   printf("window_pos:        %d\n", opts->window_pos); */
/*   printf("window_size:       %d\n", opts->window_size); */
/*   printf("seq->seq:          %s\n", seq->seq); */
/*   printf("seq->original_seq: %s\n", seq->original_seq); */

  for (i=opts->window_pos; i<=opts->window_pos + opts->window_size; i++) 
    seq->seq[i-opts->window_pos] = seq->original_seq[i];
  if (number_of_graphics) {
    for (i=opts->window_pos; i<=opts->window_pos + opts->window_size; i++) 
       graphics_sequence[i-opts->window_pos] = seq->original_seq[i];
    graphics_sequence[strlen(seq->seq)] = 0;
  }
  convert_input(0, seq->seq, opts->window_size);
  if (output) print_sequence(opts, seq, opts->window_pos, opts->window_size);
}
Пример #11
0
void rna_output_subopt_start(toptions *opts, tsequence *seq, char *algebra, int result_score, int range_begin, int range_end)
{
  if (!opts->window_mode && (strcmp(algebra, "count"))) {
    printf("Suboptimal range: [%.2f kcal/mol - %.2f kcal/mol]\n", ((float) range_begin)/100, ((float) range_end)/100);
    printf("\n");

    if (seq->descr && seq->descr[0]) {
      pcolor(opts->colored_output,COLOR_BOLD);
      printf(">%s", seq->descr);
      pcolor(opts->colored_output,COLOR_DEFAULT);
      printf("\n");
    }
    if (!opts->split_output_mode) printf("%s\n", seq->original_seq);
  }
  // print subsequence for first window iteration
  // for later iterations, this is done in function shift_input
  if (opts->window_mode && (opts->window_pos==0) && (strcmp(algebra, "count"))) {
    print_sequence(opts, seq, opts->window_pos, opts->window_size);
  }
}
Пример #12
0
int4 main(int4 argc, char* argv[])
{
    // User must provide FASTA format file at command line
	if (argc < 4)
	{
		fprintf(stderr, "Useage: indexdb <DB filename> <Query Length> <Number of Sequences>\n");
		exit(-1);
	}

	char *filename = argv[1];
    int queryLen = atoi(argv[2]);
	int numSeqs = atoi(argv[3]);

    // Open sequence data file and read information
	encoding_initialize(encoding_protein);
    readdb_open_mem(filename);

    int ii;
    //int interval = readdb_numberOfSequences / numSeqs; 

    int queryCnt = 0;
    for(ii = 0; ii < readdb_numVolumeSequences && queryCnt < numSeqs; ii++)
    {
        if(readdb_sequenceData[ii].sequenceLength >= queryLen)
        {
            print_sequence(ii);
            if(queryCnt < 50)
                fprint_sequence(ii, queryCnt + 1);
            queryCnt++;
        }
    }

    fprintf(stderr, "maxQueryLength: %d\n", readdb_sequenceData[ii].sequenceLength);

    //close database
    readdb_close_mem();
    return 0;
}
Пример #13
0
void assembly_run(Params *p, double nfert, double **regpool, int poolsize, char *folder, char *replicate_identity)
{
    // Define and initialize the history and ecosystem lists
    //------------------------------------------------------
    sll history;
    sll_init(&history,(void*)free_seq);
    sll ecosys;
    sll_init(&ecosys,(void*)free_species);

    // create the basal resources
    //---------------------------
    basal(p,&ecosys,nfert);


    // create and initialize the presence matrix (ne pas oublier de mettre les espèces au minimum pour l'invasion)
    //------------------------------------------
    unsigned int **presence = (unsigned int**)mat_alloc(2,poolsize,sizeof(unsigned int));
    for(int i = 0 ; i < poolsize ; ++i)
    {
        presence[0][i] = regpool[i][1];
        presence[1][i] = 0;
    }

    // get the initial values of the sequence
    //---------------------------------------
    seqlevel *seq0 = fill_seq(&ecosys,0,0);
    seq0->success = 0;
    sll_add_head(&history,seq0);

    // assemble until any species can install (or all are already installed)
    //----------------------------------------------------------------------
    int a = poolsize + EAM_NBNUT + EAM_NBDET;                              /* expected ecosystem size */
    int stop_endcycles = poolsize * EAM_STOP_ENDCYCLE;                     /* variable to stop the sequence if infinite */
    int endcycles = 0;                                                     /* 0 if endpoint / 1 if endcycle */ 
    int unsucc = EAM_STOP;                                                 /* check the success of the invader */
    int invasion = 1;                                                      /* invasion number */

    while(ecosys.length != a)
    {
        int b = get_int(p->rng,0,poolsize);                                /* select randomly the number of the species in the regional pool */
        if(presence[1][b] == 0)                                            /* if the species is not already in the ecosystem */
	{
	    ParamSP *sp = (ParamSP*)malloc(sizeof(ParamSP));
	    tr_sp_struct(regpool[b],sp);
	    install_process(p,&ecosys,sp);                                  /* install the species */
	    seqlevel *seq = fill_seq(&ecosys,invasion,presence[0][b]);      /* create and initialize a sequence node */
	    sll_rm(&ecosys,extinct_condition);                              /* remove the extincted species */
	    presence_absence(&ecosys,presence,poolsize);                    /* fill the presence-absence matrix */
	    unsucc = (presence[1][b] == 0) ? unsucc-1 : EAM_STOP;          /* upgrade the counter of unsuccessfull installations */
	    seq->success =  presence[1][b];                                /* fill the success of invader installation in the sequence node */
	    sll_add_head(&history,seq);                                    /* add the sequence node to the assembly history */
	    ++invasion;                                                    /* upgrade the invasion number */
	    --stop_endcycles;                                              /* upgrade the endcycle detector */
	}
	if(unsucc == 0) break;
        if(stop_endcycles == 0)                                              /* break the loop if its an endcycle */
	{
	    endcycles = 1;
	    break;
	}
    }


    // print the outputs : subpool / final community / sequence / abundances history / identity history
    //------------------
    print_final_community(&ecosys,folder,replicate_identity);
    print_id_history(&history,poolsize,folder,replicate_identity);
    print_final_biomasses_history(&history,poolsize,folder,replicate_identity);
    print_sequence(&history,folder,replicate_identity);
    char *buffer = (char*)malloc(100);
    sprintf(buffer, "%s/%s_endcycle.txt",folder,replicate_identity);
    FILE *out = fopen(buffer,"w");
    fprintf(out,"%d",endcycles);
    fclose(out);

    // free the memory
    //----------------
    mat_free((void**)presence,2);
    sll_rm_all(&history);
    sll_rm_all(&ecosys);
    free(buffer);

}
Пример #14
0
void edit_sequence(char s[], char t[]) {
    int m = strlen(s);  
    int n = strlen(t);          
    int i, j;
    int i_cost, d_cost, s_cost;
    edit_struct a[MAX_LEN][MAX_LEN];

    a[0][0].p_i = -1;
    a[0][0].p_j = -1;
    a[0][0].op = '\0';
    a[0][0].edit_dist = 0;

    for(i = 1; i <= m; i++) {
        a[i][0].p_i = i-1;
        a[i][0].p_j = 0;
        a[i][0].op = 'd';
        a[i][0].edit_dist = i;
    }

    for(j = 1; j <= n; j++) {
        a[0][j].p_i = 0;
        a[0][j].p_j = j-1;
        a[0][j].op = 'i';
        a[0][j].edit_dist = j;
    }
                                        
    for(i = 1; i <= m; i++) {
        for(j = 1; j <= n; j++) {
            i_cost = a[i][j-1].edit_dist + insert_cost(t[j-1]);
            d_cost = a[i-1][j].edit_dist + delete_cost(s[i-1]);
            s_cost = a[i-1][j-1].edit_dist + substitute_cost(s[i-1], t[j-1]);

            if(i_cost <= d_cost) {
                if(i_cost <= s_cost) {
                    a[i][j].p_i = i;
                    a[i][j].p_j = j-1;
                    a[i][j].op = 'i';
                    a[i][j].edit_dist = i_cost;
                }
                else {
                    a[i][j].p_i = i-1;
                    a[i][j].p_j = j-1;
                    if(substitute_cost(s[i-1], t[j-1]))
                        a[i][j].op = 's';
                    else 
                        a[i][j].op = 'm';
                    a[i][j].edit_dist = s_cost;
                }
            }
            else {
                if(d_cost <= s_cost) {
                    a[i][j].p_i = i-1;
                    a[i][j].p_j = j;
                    a[i][j].op = 'd';
                    a[i][j].edit_dist = d_cost;
                }
                else {
                    a[i][j].p_i = i-1;
                    a[i][j].p_j = j-1;
                    if(substitute_cost(s[i-1], t[j-1]))
                        a[i][j].op = 's';
                    else
                        a[i][j].op = 'm';
                    a[i][j].edit_dist = s_cost;
                }
            }
        }
    }
    printf("%d\n", a[m][n].edit_dist);
    print_sequence(a, m, n);
    printf("\n");
}
Пример #15
0
void print_sequence(edit_struct a[][MAX_LEN], int i, int j) {
    if(i == 0 && j == 0) return;
    print_sequence(a, a[i][j].p_i, a[i][j].p_j);
    printf("%c", a[i][j].op);
}
Пример #16
0
inline Ostream& operator <<(Ostream& os, const std::forward_list<T, A>& x)
{
    return print_sequence(os, x.begin(), x.end());
}
Пример #17
0
inline Ostream& operator <<(Ostream& os, const std::array<T, N>& x)
{
    return print_sequence(os, x.begin(), x.end());
}
Пример #18
0
void print_alignment(alignment_block aln){
   if(aln==NULL)return;
   printf("\na %s\n",aln->data);
   for(int i=0; i < aln->size; ++i)
    if(aln->sequences[i] != NULL) print_sequence(aln->sequences[i]);
}
Пример #19
0
int main(void)
{
	int n, m;
	int l1, l2;
	scanf("%d %d", &n, &m);
	while(n!= 0 || m != 0)
	{
		int i,j;
		int sum = 0;
		int flag = 0;
		int step = 0;
		char s[5];
		
		for(i = 0; i < n; ++i)
			for(j = 0; j < n; ++j)
			map[i][j] = 0;
		for(i = 0; i < m; ++i)
		{
 			scanf("%s", s);
			int x, y;
			x = s[0] - 'A';
			y = s[2] - 'A';
			if(map[y][x] != 0)
			{
				flag = 2;
				step = i + 1;
				break;
			}
			if(map[x][y] == 0)
			{
				map[x][y] = 1;
				sum++;
				int i1, i2;
				for(i1 = 0 ; i1 < n; ++i1)
				{
					if(map[i1][x] != 0)
					{
						if(map[y][i1] == 1)
						{
							flag = 2;
							step = i + 1;
							break;
						}
						if(map[i1][y] == 0)
						{
							sum++;
							map[i1][y] = 1;
						}
					}
				}
				for(i2 = 0; i2 < n; ++i2)
				{
					if(map[y][i2] != 0)
					{
						if(map[i2][x] == 1)
						{
							flag = 2;
							step = i + 1;
							break;
						}
						if(map[x][i2] == 0)
						{
							sum++;
							map[x][i2] = 1;
						}
					}
				}
				for(i1 = 0; i1 < n; ++i1)
				{
					for(i2 = 0; i2 < n; ++i2)
					{
						if(map[i1][x] != 0 && map[y][i2] != 0)
						{
							if(map[i2][i1] != 0)
							{
								flag = 2;
								step = i + 1;
								break;
							}
							if(map[i1][i2] == 0)
							{
								sum ++;
								map[i1][i2] = 1;
							}
						}
					}
					if(flag == 2)
						break;
				}
			}
			if(flag == 2)
				break;	
			if(sum == n * (n - 1) / 2 && flag == 0)
			{
				flag = 1;
				step = i + 1;
				break;
			}		
			
			
/*
			for(l1 = 0; l1 < n; ++l1)
		 	{
	 			for(l2 = 0; l2 < n; ++l2)
	 			{
			 		printf("%d ", map[l1][l2]);
			 	}
			 	printf("\n");
		 	}*/
		 		
		}
/*
		for(l1 = 0; l1 < n; ++l1)
		 	{
	 			for(l2 = 0; l2 < n; ++l2)
	 			{
			 		printf("%d ", map[l1][l2]);
			 	}
			 	printf("\n");
		 	}*/
		for(i = i + 1; i < m; ++i)
		{
			scanf("%s", s);
		}
		
		switch(flag)
		{
			case 0: printf("Sorted sequence cannot be determined.\n");break;
			case 1: printf("Sorted sequence determined after %d relations: ", step);
					print_sequence(n);
					break;
			case 2: printf("Inconsistency found after %d relations.\n", step);
		}
		scanf("%d %d", &n, &m);	
	}	
	return 0;
}