6 Commits

8 changed files with 157 additions and 141 deletions

View File

@ -69,15 +69,34 @@ char* fastaSeqPtr_header_add_field(fastaSeqPtr seq, char* name, char* value)
element_from_header* table_header_add_field(element_from_header* header, char* name, char* value)
{
int nbf;
int i, j;
element_from_header* new_header;
nbf = atoi(header[0].value);
nbf++;
header = (element_from_header*) realloc(header, (nbf+1)*sizeof(element_from_header));
header[nbf].name = (char*) malloc((1+strlen(name))*sizeof(char));
strcpy(header[nbf].name, name);
header[nbf].value = (char*) malloc((1+strlen(value))*sizeof(char));
strcpy(header[nbf].value, value);
sprintf(header[0].value, "%d", nbf);
return(header);
new_header = (element_from_header*) realloc(header, ((nbf+1)*sizeof(element_from_header)));
i=0;
while ((strcmp(new_header[i].name, "definition") != 0) && (i < nbf))
i++;
if (strcmp(new_header[i].name, "definition") == 0)
{
j = nbf-1;
while (strcmp(new_header[j].name, "definition") == 0)
{
new_header[j+1].name = new_header[j].name;
new_header[j+1].value = new_header[j].value;
j--;
}
}
new_header[i].name = (char*) malloc((1+strlen(name))*sizeof(char));
strcpy(new_header[i].name, name);
new_header[i].value = (char*) malloc((1+strlen(value))*sizeof(char));
strcpy(new_header[i].value, value);
sprintf(new_header[0].value, "%d", nbf+1);
return(new_header);
}
@ -86,7 +105,7 @@ void free_header_table(element_from_header* header)
int i;
int nbf = atoi(header[0].value);
for (i = 0; i <= nbf; i++)
for (i = 0; i < nbf; i++)
{
free((header[i]).name);
free((header[i]).value);
@ -101,7 +120,7 @@ char* getItemFromHeader(char* name, element_from_header* header)
int nbf;
int i;
nbf = atoi(header[0].value);
for (i = 1; i <= nbf; i++)
for (i = 1; i < nbf; i++)
{
if (strcmp(header[i].name,name)==0)
value = header[i].value;
@ -115,7 +134,7 @@ void changeValue(element_from_header* header, char* name, char* newValue)
int i;
int nbf = atoi(header[0].value);
for (i = 1; i <= nbf; i++)
for (i = 1; i < nbf; i++)
{
if (strcmp(header[i].name, name)==0)
{

View File

@ -27,7 +27,7 @@
#define FLEX_SCANNER
#define YY_FLEX_MAJOR_VERSION 2
#define YY_FLEX_MINOR_VERSION 5
#define YY_FLEX_SUBMINOR_VERSION 37
#define YY_FLEX_SUBMINOR_VERSION 35
#if YY_FLEX_SUBMINOR_VERSION > 0
#define FLEX_BETA
#endif
@ -65,6 +65,7 @@ typedef int16_t flex_int16_t;
typedef uint16_t flex_uint16_t;
typedef int32_t flex_int32_t;
typedef uint32_t flex_uint32_t;
typedef uint64_t flex_uint64_t;
#else
typedef signed char flex_int8_t;
typedef short int flex_int16_t;
@ -72,6 +73,7 @@ typedef int flex_int32_t;
typedef unsigned char flex_uint8_t;
typedef unsigned short int flex_uint16_t;
typedef unsigned int flex_uint32_t;
#endif /* ! C99 */
/* Limits of integral types. */
#ifndef INT8_MIN
@ -102,8 +104,6 @@ typedef unsigned int flex_uint32_t;
#define UINT32_MAX (4294967295U)
#endif
#endif /* ! C99 */
#endif /* ! FLEXINT_H */
#ifdef __cplusplus
@ -374,7 +374,7 @@ static void yy_fatal_error (yyconst char msg[] );
*/
#define YY_DO_BEFORE_ACTION \
(yytext_ptr) = yy_bp; \
header_yyleng = (size_t) (yy_cp - yy_bp); \
header_yyleng = (yy_size_t) (yy_cp - yy_bp); \
(yy_hold_char) = *yy_cp; \
*yy_cp = '\0'; \
(yy_c_buf_p) = yy_cp;
@ -390,9 +390,9 @@ struct yy_trans_info
};
static yyconst flex_int16_t yy_accept[29] =
{ 0,
0, 0, 0, 0, 0, 0, 0, 0, 13, 12,
3, 2, 1, 5, 4, 7, 6, 9, 8, 10,
11, 3, 2, 5, 4, 9, 8, 0
0, 0, 0, 0, 0, 0, 0, 0, 13, 2,
3, 1, 12, 4, 5, 7, 6, 8, 9, 10,
11, 2, 3, 4, 5, 8, 9, 0
} ;
static yyconst flex_int32_t yy_ec[256] =
@ -400,17 +400,17 @@ static yyconst flex_int32_t yy_ec[256] =
1, 1, 1, 1, 1, 1, 1, 1, 2, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 2, 1, 3, 3, 1, 3, 3, 3, 3,
3, 1, 3, 3, 3, 3, 3, 3, 3, 3,
3, 3, 3, 3, 3, 3, 3, 3, 4, 1,
5, 6, 1, 1, 3, 3, 3, 3, 3, 3,
3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
3, 1, 3, 1, 3, 1, 3, 3, 3, 3,
1, 2, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 3, 1,
4, 5, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
3, 3, 3, 3, 3, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
@ -427,41 +427,41 @@ static yyconst flex_int32_t yy_ec[256] =
1, 1, 1, 1, 1
} ;
static yyconst flex_int32_t yy_meta[7] =
static yyconst flex_int32_t yy_meta[6] =
{ 0,
1, 2, 3, 4, 4, 1
1, 2, 3, 3, 4
} ;
static yyconst flex_int16_t yy_base[35] =
static yyconst flex_int16_t yy_base[36] =
{ 0,
0, 0, 22, 21, 6, 0, 12, 0, 26, 29,
0, 0, 29, 0, 0, 29, 29, 0, 0, 29,
29, 0, 0, 0, 0, 0, 0, 29, 23, 16,
22, 20, 20, 18
0, 4, 23, 0, 9, 0, 14, 0, 27, 0,
0, 29, 29, 0, 0, 29, 29, 0, 0, 29,
29, 0, 0, 0, 0, 0, 0, 29, 19, 23,
23, 7, 5, 3, 1
} ;
static yyconst flex_int16_t yy_def[35] =
static yyconst flex_int16_t yy_def[36] =
{ 0,
28, 1, 1, 1, 28, 5, 28, 7, 28, 28,
29, 30, 28, 31, 32, 28, 28, 33, 34, 28,
28, 29, 30, 31, 32, 33, 34, 0, 28, 28,
29, 29, 2, 3, 28, 5, 28, 7, 28, 30,
31, 28, 28, 32, 33, 28, 28, 34, 35, 28,
28, 30, 31, 32, 33, 34, 35, 0, 28, 28,
28, 28, 28, 28, 28
} ;
static yyconst flex_int16_t yy_nxt[35] =
{ 0,
28, 11, 27, 26, 12, 11, 25, 24, 12, 14,
15, 16, 17, 13, 18, 19, 20, 21, 13, 10,
10, 10, 10, 22, 23, 22, 28, 13, 9, 28,
28, 28, 28, 28
} ;
static yyconst flex_int16_t yy_nxt[36] =
static yyconst flex_int16_t yy_chk[35] =
{ 0,
10, 11, 12, 12, 12, 13, 10, 14, 15, 16,
17, 10, 10, 18, 19, 20, 21, 10, 23, 23,
27, 26, 25, 24, 22, 28, 10, 10, 9, 28,
28, 28, 28, 28, 28
} ;
static yyconst flex_int16_t yy_chk[36] =
{ 0,
1, 1, 1, 1, 1, 1, 5, 5, 5, 5,
5, 5, 7, 7, 7, 7, 7, 7, 30, 30,
34, 33, 32, 31, 29, 9, 4, 3, 28, 28,
28, 28, 28, 28, 28
0, 1, 35, 34, 1, 2, 33, 32, 2, 5,
5, 5, 5, 5, 7, 7, 7, 7, 7, 29,
29, 29, 29, 30, 31, 30, 9, 3, 28, 28,
28, 28, 28, 28
} ;
static yy_state_type yy_last_accepting_state;
@ -590,7 +590,7 @@ static int input (void );
/* This used to be an fputs(), but since the string might contain NUL's,
* we now use fwrite().
*/
#define ECHO do { if (fwrite( header_yytext, header_yyleng, 1, header_yyout )) {} } while (0)
#define ECHO fwrite( header_yytext, header_yyleng, 1, header_yyout )
#endif
/* Gets input and stuffs it into "buf". number of characters read, or YY_NULL,
@ -601,7 +601,7 @@ static int input (void );
if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \
{ \
int c = '*'; \
size_t n; \
yy_size_t n; \
for ( n = 0; n < max_size && \
(c = getc( header_yyin )) != EOF && c != '\n'; ++n ) \
buf[n] = (char) c; \
@ -784,6 +784,7 @@ YY_RULE_SETUP
}
YY_BREAK
case 2:
/* rule 2 can match eol */
YY_RULE_SETUP
#line 45 "fasta_header_parser.l"
{
@ -797,7 +798,7 @@ YY_RULE_SETUP
(*p_header)[*nbf].value = (char*) malloc(sizeof(char)*size_needed);
strcpy(((*p_header)[*nbf]).value,header_yytext);
(*nbf)++;
p_header = check_and_realloc_mem_in_header_table(p_header, nbf, memory_allocated);
}
YY_BREAK
case 3:
@ -808,6 +809,7 @@ YY_RULE_SETUP
}
YY_BREAK
case 4:
/* rule 4 can match eol */
YY_RULE_SETUP
#line 64 "fasta_header_parser.l"
{
@ -818,7 +820,7 @@ YY_RULE_SETUP
case 5:
YY_RULE_SETUP
#line 69 "fasta_header_parser.l"
{
{ // TODO
/*fprintf(stderr,"\n<REGNAME>{SPACE} **%s**",header_yytext);*/
if (i != 0)
field = store_in_field(field,header_yytext,&free_size,&i);
@ -846,6 +848,7 @@ YY_RULE_SETUP
}
YY_BREAK
case 8:
/* rule 8 can match eol */
YY_RULE_SETUP
#line 90 "fasta_header_parser.l"
{
@ -883,24 +886,21 @@ case YY_STATE_EOF(REGVAL):
#line 113 "fasta_header_parser.l"
{
field = store_in_header_table(field, &((*p_header)[*nbf].value), &free_size, &i);
p_header = check_and_realloc_mem_in_header_table(p_header, nbf, memory_allocated);
(*nbf)++;
end_header_table(p_header, *nbf);
free(field);
BEGIN(INITIAL);
return 0;
}
YY_BREAK
case YY_STATE_EOF(REGNAME):
#line 123 "fasta_header_parser.l"
#line 122 "fasta_header_parser.l"
{
/*(*p_header)[*nbf].name = (char*) malloc(sizeof(char)*19);
strcpy((*p_header)[*nbf].name,"other_informations");
(*p_header)[*nbf].name = (char*) malloc(sizeof(char)*19);
strcpy((*p_header)[*nbf].name,"definition");
field = store_in_header_table(field, &((*p_header)[*nbf].value), &free_size, &i);
p_header = check_and_realloc_mem_in_header_table(p_header, nbf, memory_allocated);
*/
end_header_table(p_header, *nbf);
(*nbf)++;
end_header_table(p_header, nbf);
free(field);
BEGIN(INITIAL);
return 0;
@ -908,7 +908,7 @@ case YY_STATE_EOF(REGNAME):
YY_BREAK
case 12:
YY_RULE_SETUP
#line 136 "fasta_header_parser.l"
#line 133 "fasta_header_parser.l"
ECHO;
YY_BREAK
#line 915 "<stdout>"
@ -1105,7 +1105,7 @@ static int yy_get_next_buffer (void)
{ /* Not enough room in the buffer - grow it. */
/* just a shorter name for the current buffer */
YY_BUFFER_STATE b = YY_CURRENT_BUFFER_LVALUE;
YY_BUFFER_STATE b = YY_CURRENT_BUFFER;
int yy_c_buf_p_offset =
(int) ((yy_c_buf_p) - b->yy_ch_buf);
@ -1238,7 +1238,7 @@ static int yy_get_next_buffer (void)
yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
yy_is_jam = (yy_current_state == 28);
return yy_is_jam ? 0 : yy_current_state;
return yy_is_jam ? 0 : yy_current_state;
}
static void yyunput (int c, register char * yy_bp )
@ -1326,7 +1326,7 @@ static int yy_get_next_buffer (void)
case EOB_ACT_END_OF_FILE:
{
if ( header_yywrap( ) )
return EOF;
return 0;
if ( ! (yy_did_buffer_switch_on_eof) )
YY_NEW_FILE;
@ -1462,6 +1462,10 @@ static void header_yy_load_buffer_state (void)
header_yyfree((void *) b );
}
#ifndef __cplusplus
extern int isatty (int );
#endif /* __cplusplus */
/* Initializes or reinitializes a buffer.
* This function is sometimes called more than once on the same buffer,
* such as during a header_yyrestart() or at EOF.
@ -1666,8 +1670,8 @@ YY_BUFFER_STATE header_yy_scan_string (yyconst char * yystr )
/** Setup the input buffer state to scan the given bytes. The next call to header_yylex() will
* scan from a @e copy of @a bytes.
* @param yybytes the byte buffer to scan
* @param _yybytes_len the number of bytes in the buffer pointed to by @a bytes.
* @param bytes the byte buffer to scan
* @param len the number of bytes in the buffer pointed to by @a bytes.
*
* @return the newly allocated buffer state object.
*/
@ -1675,8 +1679,7 @@ YY_BUFFER_STATE header_yy_scan_bytes (yyconst char * yybytes, yy_size_t _yybyt
{
YY_BUFFER_STATE b;
char *buf;
yy_size_t n;
int i;
yy_size_t n, i;
/* Get memory for full buffer, including space for trailing EOB's. */
n = _yybytes_len + 2;
@ -1906,7 +1909,7 @@ void header_yyfree (void * ptr )
#define YYTABLES_NAME "yytables"
#line 136 "fasta_header_parser.l"
#line 133 "fasta_header_parser.l"
@ -1917,38 +1920,32 @@ int header_yywrap()
element_from_header* header_parser_main(char *h)
{
int nbfields,memory_allocated;
int nbfields, memory_allocated;
element_from_header* header;
char* nbfields_n;
char* nbfields_v;
nbfields_n = (char*) malloc(9*sizeof(char));
nbfields_v = (char*) malloc(5*sizeof(char));
YY_BUFFER_STATE state;
state=header_yy_scan_string(h);
memory_allocated=MEMALLOCATED;
header = (element_from_header*) malloc(memory_allocated * sizeof(element_from_header));
nbfields_n = (char*) malloc(9*sizeof(char));
strcpy(nbfields_n, "nbfields");
header[0].name = nbfields_n;
// Initialize memory to store the number of fields
header[0].value = (char*) malloc(10*sizeof(char));
nbfields=1;
strcpy(nbfields_n, "nbfields");
strcpy(nbfields_v, "1");
header = (element_from_header*) malloc(memory_allocated * sizeof(element_from_header));
header[0].name = nbfields_n;
header[0].value = nbfields_v;
YY_BUFFER_STATE state;
state=header_yy_scan_string(h);
header_parser(&nbfields, &memory_allocated, &header);
header_yy_delete_buffer(state);
return header;
}

View File

@ -21,8 +21,8 @@
%}
WORD [[:alnum:]:\-.{},'_()\#\[\]\|\&\"\'\/\%\+]+
WORDID [[:alnum:]:\-.{},'_()\#\[\]\|\&\"\'\/\%\+=;]+
WORD [^>[:blank:]=;]+
WORDID [^>[:blank:]]+
SUP >
EOL \n
SEP ;
@ -53,7 +53,7 @@ EQUAL =
(*p_header)[*nbf].value = (char*) malloc(sizeof(char)*size_needed);
strcpy(((*p_header)[*nbf]).value,yytext);
(*nbf)++;
p_header = check_and_realloc_mem_in_header_table(p_header, nbf, memory_allocated);
}
@ -66,7 +66,7 @@ EQUAL =
field = store_in_field(field,yytext,&free_size,&i);
}
<REGNAME>{SPACE} {
<REGNAME>{SPACE} { // TODO
/*fprintf(stderr,"\n<REGNAME>{SPACE} **%s**",yytext);*/
if (i != 0)
field = store_in_field(field,yytext,&free_size,&i);
@ -112,22 +112,19 @@ EQUAL =
<REGVAL><<EOF>> {
field = store_in_header_table(field, &((*p_header)[*nbf].value), &free_size, &i);
p_header = check_and_realloc_mem_in_header_table(p_header, nbf, memory_allocated);
(*nbf)++;
end_header_table(p_header, *nbf);
free(field);
BEGIN(INITIAL);
return 0;
}
<REGNAME><<EOF>> {
/*(*p_header)[*nbf].name = (char*) malloc(sizeof(char)*19);
strcpy((*p_header)[*nbf].name,"other_informations");
(*p_header)[*nbf].name = (char*) malloc(sizeof(char)*19);
strcpy((*p_header)[*nbf].name,"definition");
field = store_in_header_table(field, &((*p_header)[*nbf].value), &free_size, &i);
p_header = check_and_realloc_mem_in_header_table(p_header, nbf, memory_allocated);
*/
end_header_table(p_header, *nbf);
(*nbf)++;
end_header_table(p_header, nbf);
free(field);
BEGIN(INITIAL);
return 0;
@ -142,37 +139,31 @@ int header_yywrap()
element_from_header* header_parser_main(char *h)
{
int nbfields,memory_allocated;
int nbfields, memory_allocated;
element_from_header* header;
char* nbfields_n;
char* nbfields_v;
nbfields_n = (char*) malloc(9*sizeof(char));
nbfields_v = (char*) malloc(5*sizeof(char));
YY_BUFFER_STATE state;
state=yy_scan_string(h);
memory_allocated=MEMALLOCATED;
header = (element_from_header*) malloc(memory_allocated * sizeof(element_from_header));
nbfields_n = (char*) malloc(9*sizeof(char));
strcpy(nbfields_n, "nbfields");
header[0].name = nbfields_n;
// Initialize memory to store the number of fields
header[0].value = (char*) malloc(10*sizeof(char));
nbfields=1;
strcpy(nbfields_n, "nbfields");
strcpy(nbfields_v, "1");
header = (element_from_header*) malloc(memory_allocated * sizeof(element_from_header));
header[0].name = nbfields_n;
header[0].value = nbfields_v;
YY_BUFFER_STATE state;
state=yy_scan_string(h);
header_parser(&nbfields, &memory_allocated, &header);
yy_delete_buffer(state);
return header;
}

View File

@ -52,7 +52,7 @@ void printOnlyHeaderFromTable(element_from_header* header, FILE* output)
fprintf(output,">%s ",header[1].value);
for (i = 2; i <= nbf; i++)
for (i = 2; i < nbf; i++)
{
if (strcmp(header[i].name, "definition") != 0)
{
@ -60,11 +60,10 @@ void printOnlyHeaderFromTable(element_from_header* header, FILE* output)
fprintf(output,"=");
fprintf(output,"%s; ",header[i].value);
}
else if (strcmp(header[i].name, "definition") == 0)
fprintf(output,"%s ", header[i].value);
}
if (strcmp(header[nbf].name, "definition") == 0)
fprintf(output,"%s; ",header[nbf].value);
fprintf(output,"\n");
}

View File

@ -76,7 +76,7 @@ element_from_header** check_and_realloc_mem_in_header_table(element_from_header*
{
(*nbf)++;
if (*nbf == *memory_allocated)
if ((*nbf)+1 == *memory_allocated)
{
(*memory_allocated)++;
*p_header = (element_from_header*) realloc(*p_header, (*memory_allocated) * sizeof(element_from_header));
@ -87,7 +87,6 @@ element_from_header** check_and_realloc_mem_in_header_table(element_from_header*
void end_header_table(element_from_header** p_header, int nbf)
{
nbf = nbf - 1;
//fprintf(stderr, "nbf = %d", nbf);
*p_header = (element_from_header*) realloc(*p_header, nbf * sizeof(element_from_header));
sprintf((*p_header)->value, "%d", nbf);
}

View File

@ -223,7 +223,13 @@ fastaSeqCount seq_readAllSeq2(char *fileName, BOOL isStandardSeq, BOOL onlyATGC)
fastaSeqCount allseqs;
int32_t discarded=0;
fp = file_open(fileName, TRUE);
if ((fileName == NULL) || (strcmp(fileName, "-") == 0))
fp = stdin;
else
{
fp = file_open(fileName, TRUE);
exitIfEmptyFile(fp);
}
if (fp == NULL)
{
@ -231,8 +237,6 @@ fastaSeqCount seq_readAllSeq2(char *fileName, BOOL isStandardSeq, BOOL onlyATGC)
exit(1);
}
exitIfEmptyFile(fp);
seqPtrAr = (fastaSeqPtr) util_malloc(slots*sizeof(fastaSeq), __FILE__, __LINE__);
seqPtr = seq_getNext(fp, " ", isStandardSeq, onlyATGC);

View File

@ -44,7 +44,7 @@ FILE *file_openrw(char* fileName, BOOL abortOnError)
/*
* Function Name: fileNextChar(FILE* fp)
* Description: Reads the file and returns next character, if file is null or its end of file, returns \<5C>.
* Description: Reads the file and returns next character, if file is null or its end of file, returns \<5C>.
*/
char file_nextChar(FILE* fp)
{
@ -59,7 +59,7 @@ char file_nextChar(FILE* fp)
/*
* Function Name: *fileNextLine(FILE *fp, char *buffer, int32_t bufferSize)
* Description: Reads the file and returns next line, if file is null or its end of file, returns \<5C>.
* Description: Reads the file and returns next line, if file is null or its end of file, returns \<5C>.
*/
char *file_nextLine(FILE *fp, char *buffer, int32_t bufferSize)
{
@ -76,7 +76,11 @@ char *file_nextLine(FILE *fp, char *buffer, int32_t bufferSize)
void exitIfEmptyFile(FILE *file)
{
long savedOffset = ftell(file);
fseek(file, 0, SEEK_END);
if (fseek(file, 0, SEEK_END) != 0)
{
fprintf(stderr, "\nError moving the offset in an input file\n");
exit(1);
}
if (ftell(file) == 0)
{

View File

@ -458,6 +458,9 @@ int calculateSizeToAllocate(int maxLen, int minLen, int LCSmin)
calculateBandLengths(maxLen, minLen, &notUsed, &size, LCSmin); // max size = max left band length * 2
if (!size) // Happens if there is no threshold (threshold is 100% similarity) and generates bugs if left to 0
size = 1;
//fprintf(stderr, "\nsize for address before %8 = %d", size);
size*= 2;