/* Last edited on 2008-06-06 16:19:03 by stolfi */ /* ---------------------------------------------------------------------- */ /* {dbd_lib.h, dbd_lib.c} */ void str_up(char *dst); /* Converts the DNA/RNA string {*dst} to upper-case. */ void str_chr_up(char *destino); /* Converts the DNA/RNA letter {*dst} to upper-case. */ void str_cat(char *dst, char ch); /* Apend {ch} to {dst}. Expects that there will be enough space. */ void str_ncat(char *dst, char ch, int size); /* Apend {ch} to {dst}, which must have at most {size} characters (excluding the final 0). If the total length of {dst} is already equal to {size}, drops the first char of {dst} and shifts everybody to the left. Expects that {dst} points to an area with at least {size+1} bytes. */ void str_ncat_ini(char *dst, char ch, int size); /* Apend {ch} to the beginning of {dst}, which must have at most {size} characters (excluding the final 0), and shifts everybody else to the right. If the total length of {dst} is already equal to {size}, drops the last char of {dst}. Expects that {dst} points to an area with at least {size+1} bytes. */ void str_incpy(char *str_origem, char *str_dst, int i, int size); void skip_header(FILE **f, char *ch); /* Skips the header of file {**f}, consisting of zero or more lines beginning with '>'. The {*ch} must be the first char of the first line. At end, {*ch} will be the firts char of the first non-header line. */ char *inverter_str(char *string); void str_up(char *dst) { while (*dst != '\0'){ switch(*dst) { case 'a': *dst='A'; break; case 't': *dst='T'; break; case 'c': *dst='C'; break; case 'g': *dst='G'; break; } dst++; } } void str_chr_up(char *dst) { switch(*dst) { case 'a': *dst='A'; break; case 't': *dst='T'; break; case 'c': *dst='C'; break; case 'g': *dst='G'; break; } } void str_cat(char *dst, char ch) { while(*dst != '\0') dst++; *dst = ch; /*a ultima posicao de dst recebe ch*/ dst++; *dst = '\0'; } void str_ncat(char *dst, char ch, int size) { char ch_aux; /*variavel auxiliar*/ if (strlen(dst)== size) { while(*dst != '\0') { /*para deslocar todos os ches de dst um ch a frente*/ dst++; ch_aux = *dst; dst--; *dst = ch_aux; dst++; } dst--; } else { /* posiciona a variavel dst na ultima posicao*/ while(*dst != '\0') dst++; } str_chr_up(&ch); *dst = ch; /*a ultima posicao de dst recebe ch*/ dst++; *dst = '\0'; } void str_ncat_ini(char *dst, char ch, int size) { int cnt = 0; char ch_atual = '\0'; char ch_anterior = ch; int size_atual = strlen(dst); if ((size - size_atual) != 0) { size_atual++; } while (cnt < size_atual) { ch_atual = *dst; *dst = ch_anterior; ch_anterior = ch_atual; dst++; cnt++; } *dst = '\0'; } void str_incpy(char *str_origem, char *str_dst, int i, int size) { int cont = 0; /* contador para manipulacao de str_origem ate' a posicao i */ char ch_aux; /* para posicionar a str_origem na posicao i */ while((*str_origem != '\0')&&(cont!= i)) { str_origem++; cont++; } /* para copiar a string de str_origem, para str_dst */ cont = 0; while ((cont!= size)&&(*str_origem != '\0')) { ch_aux = *str_origem; *str_dst = ch_aux; /*copia ch a ch de str_origem*/ str_dst++; str_origem++; cont++; } *str_dst = '\0'; } char *inverter_str(char *string) { int size = 0, cnt = 0; char *string_inv; size = strlen(string); string_inv = (char*) malloc ((size+1) * sizeof(char)); strcpy(string_inv, "\0"); /*avança o ponteiro para o final de string*/ for (cnt = 0; cnt < size - 1; cnt++) { string++; } for (cnt = 0 ; cnt < size ; cnt++) { *string_inv = *string; string_inv++; string--; }//fim do for *string_inv = '\0'; /*volta o ponteiro para o começo de string_inv*/ for (cnt = 0; cnt < size; cnt++) { string_inv--; } return(string_inv); } void skip_header(FILE **f, char *ch) { if ((*ch) == '>'){ /* Pula resto desta linha: */ while((!feof(*f))&&((*ch)!='\n')){ fscanf(*f, "%c", ch); } fscanf(*f,"%c", ch); // le a primeira letra da linha seguinte */ } } /************************************************************************* * Procedimento para calcular o tempo que o programa fica executando na * * CPU. Tempo inicial menos o tempo final. * *************************************************************************/ void tempoCPU(struct tms tempo, float *tempoCPU){ *tempoCPU = ((float)(tempo.tms_utime + tempo.tms_stime) / (float)(CLK_TCK)); }