Exemplo n.º 1
0
void
print_km_tree(KM_node *root, int *vecs, const SeqSet *seq_set, char *out_f)
{
	FILE *out_F = fopen(out_f, "w");
	Stack *to_do =Stack_init();
	Node_pair *tmp = (Node_pair*)my_malloc(sizeof(Node_pair));
	tmp->node=root;
	tmp->id = 0;
	push(to_do, tmp);

	KM_node* current;
	size_t child;
	size_t k;
	// 	size_t pos;
// 	char command[1000];
	while (to_do->size != 0)
	{

		current = ((Node_pair*)to_do->last)->node;
		child = ((Node_pair*)to_do->last)->id;
		if (current->n_children==0)
		{
			if (current->end-current->start >1)
				fprintf(out_F, "(");
			for (k=current->start; k<current->end; ++k)
			{
				fprintf(out_F, "%s", seq_set->seqs[vecs[k]]->name);
				if (k<current->end-1)
					fprintf(out_F, ",");
			}
			tmp =(Node_pair*) pop(to_do);
			if (current->end-current->start >1)
				fprintf(out_F, ")");
		}
		else
		{
			if (child == 0)
			{
				fprintf(out_F, "(");
			}
			if (child == current->n_children)
			{
				fprintf(out_F, ")");
				pop(to_do);
			}
			else
			{
				if (child != 0)
					fprintf(out_F, ",");
				++((Node_pair*)to_do->last)->id;
				tmp = (Node_pair*)my_malloc(sizeof(Node_pair));
				tmp->node=current->children[child];
				tmp->id = 0;
				push(to_do, tmp);
			}
		}
	}
	fprintf(out_F, ";");
}
Exemplo n.º 2
0
/* Input:   a file pointer
 * Output:  a Mem_T structure
 * Purpose: Initializes the Mem_T memory structure. Stores 32 bit words from 
 *          input into segment 0 in memory. This is location which holds the 
 *          instructions that the um will execute
 */
Mem_T Mem_new(FILE *input)
{
        long unsigned lSize;
        uint32_t *buffer;
        size_t buffer_size;

        assert(input != NULL);

        Mem_T memory = malloc(sizeof(*memory));
        assert(memory!=NULL);

        memory->segment_seq = Mem_arr_new(1);
        memory->reusable_indices = Stack_init(1);

        /* determines length of input file */
        fseek(input, 0, SEEK_END);
        lSize = ftell(input);
        rewind(input);

        /* creates buffer that will grab words from input*/
        buffer = malloc(sizeof(uint32_t) * lSize/4);
        assert(buffer != NULL);

        buffer_size = fread(buffer, 4, lSize / 4, input);

        if(buffer_size != lSize/4){
                fprintf(stderr, "Reading error\n");
        }


        /* Program index will be 0*/
        int programIndex = map_segment(memory, buffer_size);

        /*transfers instructions from buffer to segment 0 in memory*/
        for(unsigned i = 0; i < buffer_size; i++){
                uint32_t word = buffer[i];
                word = flip_word(word);
                store_word(memory, word, programIndex, i);
        }
        free(buffer);
        return memory;
}
Exemplo n.º 3
0
/**
 * \brief Frees all memory occupied by this structure
 * \param root The root of the tree to delete.
 */
void
del_tree(KM_node* root)
{
		Stack *to_do = Stack_init();

		Node_pair *tmp = (Node_pair*)my_malloc(sizeof(Node_pair));
		tmp->node=root;
		tmp->id = 0;
		push(to_do, tmp);

		KM_node* current;
		size_t child;
		while (to_do->size != 0)
		{
			current = ((Node_pair*)to_do->last)->node;
			child = ((Node_pair*)to_do->last)->id;
			if (current->n_children==0)
			{
				free(pop(to_do));
				delKM_node(current);
			}
			else
			{
				if (child == current->n_children)
				{
					delKM_node(current);
					free(pop(to_do));
				}
				else
				{
					++((Node_pair*)to_do->last)->id;
					tmp = (Node_pair*)my_malloc(sizeof(Node_pair));
					tmp->node=current->children[child];
					tmp->id = 0;
					push(to_do, tmp);
				}
			}
		}
		delStack(to_do);
}
Exemplo n.º 4
0
/**
 * \brief Traverses the tree and calls t_coffee to produce the alignments
 * \param root The root of the tree.
 * \param vecs The vector set.
 * \param seq_set The sequence set.
 * \param out_f The output file.
 * \param n_core The number of cores to use (OPEN-MP for kmeans/fork in T-Coffee)
 * \param gapopen The gapopening costs
 * \param gapext The gapextension costs
 * \param method The method to use in the alignment
 */
void
traverse_km_tree(KM_node* root, int *vecs, const SeqSet *seq_set, char *out_f, int n_cores, int gapopen, int gapext, char *method)
{
	Stack *to_do =Stack_init();
	Node_pair *tmp = (Node_pair*)my_malloc(sizeof(Node_pair));
	tmp->node=root;
	tmp->id = 0;
	push(to_do, tmp);

	KM_node* current;
	size_t child;
	size_t j;
// 	size_t pos;
	char command[1000];
	while (to_do->size != 0)
	{

		current = ((Node_pair*)to_do->last)->node;
		child = ((Node_pair*)to_do->last)->id;
		if (current->n_children==0)
		{
			if(current->end-current->start > 2)
			{
				sprintf(command, "%li",current->id);
				write_files(current, vecs, seq_set, command);
// 				sprintf(command,"clustalo --guidetree-out co_tree.dnd -i %li --force >/dev/null 2>/dev/null", current->id);
// 				if (system(command))
// 				{
// 					printf("%s\n",command);
// 					exit(1);
// 				}
				if (current->id!=0)
					sprintf(command,"t_coffee -in %li -output fasta_aln -outfile %li.fa -n_core %i -gapopen %i -gapext %i -method %s -quiet >/dev/null 2>/dev/null", current->id, current->id, n_cores, gapopen, gapext, method);
				else
					sprintf(command,"t_coffee -in %li -output fasta_aln -outfile %s -n_core %i -gapopen %i -gapext %i -method %s -quiet >/dev/null 2>/dev/null ",  current->id, out_f, n_cores, gapopen, gapext, method);
				if (system(command))
				{
					printf("ERROR when running: %s\n",command);
					exit(1);
				}
			}
			else
				if(current->end-current->start > 1)
			{
				sprintf(command, "%li",current->id);
				write_files(current, vecs, seq_set, command);
				if (current->id!=0)
					sprintf(command,"t_coffee -in %li -output fasta_aln -outfile %li.fa -n_core %i -gapopen %i -gapext %i -method %s -quiet >/dev/null 2>/dev/null", current->id, current->id, n_cores, gapopen, gapext, method);
				else
					sprintf(command,"t_coffee -in %li -output fasta_aln -outfile %s -n_core %i -gapopen %i -gapext %i -method %s -quiet >/dev/null 2>/dev/null ",  current->id, out_f, n_cores, gapopen, gapext, method);

				printf("%s\n", command);
				if (system(command))
				{
					printf("ERROR when running: %s\n",command);
					exit(1);
				}
			}
			else
			{
				sprintf(command, "%li.fa",current->id);
				write_files(current, vecs, seq_set, command);
			}
			tmp =(Node_pair*) pop(to_do);
		}
		else
		{
			if (child == current->n_children)
			{
				if (current->id!=0)
					sprintf(command, "t_coffee -output fasta_aln -method %s -quiet -outfile %li.fa -n_core %i -gapopen %i -profile FILE::prf.fa ", method, current->id,n_cores, gapopen);
				else
					sprintf(command, "t_coffee -output fasta_aln -method %s -quiet -outfile %s -n_core %i -gapopen %i   -profile FILE::prf.fa ", method, out_f, n_cores, gapopen);
				FILE *prf_F = my_fopen("prf.fa", "w");
				for(j=0; j<current->n_children;++j)
				{
					fprintf(prf_F, "%li.fa\n", current->children[j]->id);
				}
				fclose(prf_F);

				printf("%s\n", command);
				if (system(command))
				{

					printf("ERROR when running: %s\n",command);
					exit(1);
				}
				pop(to_do);
			}
			else
			{
				++((Node_pair*)to_do->last)->id;
				tmp = (Node_pair*)my_malloc(sizeof(Node_pair));
				tmp->node=current->children[child];
				tmp->id = 0;
				push(to_do, tmp);
			}
		}
	}
	exit(1);
}