/*****************************************************************************/ /* */ /* UNIT: NTL2_Load_Conserved (Level 2 library routine) */ /* */ /* Author: Nikola Stojanovic */ /* */ /* Revision: 22 SEP 94 Version 1.0 */ /* 15 OCT 94 Version 2.0 */ /* 10 JUL 95 Version 3.0 */ /* */ /* Function: */ /* */ /* Procedure loads the conserved structure (data structure containing */ /* information about conserved sites in sequences) from the specified */ /* file containing that information in the "database tuples" format. */ /* Procedure receives the name of the file containing data, fills the */ /* pointer (reference parameter) to the begining of the assembled list of */ /* conserved regions; returns the error structure, NULL if everything was OK */ /* */ /* */ /* Expected format of the file containing data about conserved regions: */ /* */ /* - First non-white-space sequence of symbols in the file must be: */ /* */ /* #:TUPLES: */ /* */ /* - */ /* */ /*****************************************************************************/ #include #include #include #include "ntl2.h" /*****************************************************************************/ /* */ /* Definitions section */ /* */ /*****************************************************************************/ /*****************************************************************************/ /* Definitions of local constants of the unit */ /*****************************************************************************/ /* Limit for the length of an error message that can be assembled */ #define ERR_MSGLIMIT 128 /* Information is read from database files by supplementary buffer of size: */ #define IN_LIMIT 512 /* Maximal permitted length for a long integer */ #define MAX_LONG_LEN 9 /* Values of "tokens" found in the file containing data about conserved reg. */ #define FTOK_EOF 0 #define FTOK_CONSERVED 1 #define FTOK_REGION 11 #define FTOK_ORIGIN 12 #define FTOK_START 13 #define FTOK_STOP 14 #define FTOK_LOCATION 17 #define FTOK_DESCRIPTION 21 #define FTOK_REFERENCE 22 #define FTOK_NUMBER 23 #define FTOK_CORRECTIONS 24 #define FTOK_CONTRIBUTOR 25 #define FTOK_CONSENSUS 28 #define FTOK_END 31 /*****************************************************************************/ /* Prototypes of all locally used functions of this unit */ /*****************************************************************************/ errind NTL2_LC_Read_Conserved (FILE **db_file, conserved_ptr *conserved); errind NTL2_LC_Next_Conserved (FILE **db_file, conserved_ptr conserved_rec, conserved_ptr *new_record); errind NTL2_LC_Conserved_Token (FILE **db_file, int *next_tok, char **str); errind NTL2_LC_Fill_Conserved (conserved_ptr conserved_rec, int next_tok, char **str); errind NTL2_LC_Assemble_Error (int severity, int code, char *comment, int description); /*****************************************************************************/ /* Definitions of global (static) variables of the unit */ /*****************************************************************************/ static char In_Buff [IN_LIMIT]; /* Global input line buffer, for convenience */ static char Error_Message [ERR_MSGLIMIT]; /* Temporary buffer, error passing */ static bool in_region; /* Indicator whether the tuple is within nested scope */ /*****************************************************************************/ /* */ /* Code section */ /* */ /*****************************************************************************/ /*****************************************************************************/ /* */ /* Procedure: NTL2_Load_Conserved */ /* */ /* Main (interface) procedure of this unit */ errind NTL2_Load_Conserved (char *file_name, conserved_ptr *conserved) { FILE *db_file; char ch; errind erret; conserved_ptr sscan, tscan; /* Initialize the list of "conserved" to return to "empty", before actions */ *conserved = NULL; /* Check whether the file with given file name exists and open it for read */ if ((db_file = fopen (file_name, "r")) == NULL) { /* Error condition */ sprintf (Error_Message, "File <%s> does not exist", file_name); return NTL2_LC_Assemble_Error (USER_ERROR, ERR_NO_FILE, Error_Message, 1); } else { /* There is a file with the specified name */ /* Check the file format by means of the recorded header code */ do { /* Skip the initial "white space" characters in the file */ ch = fgetc (db_file); } while ((ch == ' ') || (ch == '\n') || (ch == '\t')); if (ch != '#') return NTL2_LC_Assemble_Error (USER_ERROR, ERR_FILE_FORMAT, "Illegal file format", 2); ch = fgetc (db_file); if (ch != ':') return NTL2_LC_Assemble_Error (USER_ERROR, ERR_FILE_FORMAT, "Illegal file format", 3); ch = fgetc (db_file); if ((ch != 't') && (ch != 'T')) return NTL2_LC_Assemble_Error (USER_ERROR, ERR_FILE_FORMAT, "Illegal file format", 4); ch = fgetc (db_file); if ((ch != 'u') && (ch != 'U')) return NTL2_LC_Assemble_Error (USER_ERROR, ERR_FILE_FORMAT, "Illegal file format", 5); ch = fgetc (db_file); if ((ch != 'p') && (ch != 'P')) return NTL2_LC_Assemble_Error (USER_ERROR, ERR_FILE_FORMAT, "Illegal file format", 6); ch = fgetc (db_file); if ((ch != 'l') && (ch != 'L')) return NTL2_LC_Assemble_Error (USER_ERROR, ERR_FILE_FORMAT, "Illegal file format", 7); ch = fgetc (db_file); if ((ch != 'e') && (ch != 'E')) return NTL2_LC_Assemble_Error (USER_ERROR, ERR_FILE_FORMAT, "Illegal file format", 8); ch = fgetc (db_file); if ((ch != 's') && (ch != 'S')) return NTL2_LC_Assemble_Error (USER_ERROR, ERR_FILE_FORMAT, "Illegal file format", 9); ch = fgetc (db_file); if (ch != ':') return NTL2_LC_Assemble_Error (USER_ERROR, ERR_FILE_FORMAT, "Illegal file format", 10); /* Now load the conserved regions from the file and close when done */ erret = NTL2_LC_Read_Conserved (&db_file, conserved); /* Read the file */ if ((erret != NULL) && (erret -> kind != WARNING)) { /* Error status ret. */ /* Release the assembled part of the conserved list - it won't be needed */ sscan = *conserved; while (sscan != NULL) { tscan = sscan; sscan = sscan -> next; free (tscan); } *conserved = NULL; } fclose (db_file); return erret; } } /*****************************************************************************/ /* */ /* Procedure: NTL2_LC_Read_Conserved */ /* */ /* Top level procedure for reading the conserved file contents; loops for */ /* each new conserved record in the file (and accounts for field contents */ /* inherritance, as well) and loads it via lower-level procedures. */ /* Procedure receives the file pointer and (already initialized) list of */ /* "consensus" sites; returns the assembled error record, NULL if there */ /* was no error in loading */ errind NTL2_LC_Read_Conserved (FILE **db_file, conserved_ptr *conserved) { conserved_ptr conserved_rec, new_conserved; errind erret; /* Allocate a record to store the new loaded consensus before passing it to */ /* procedure: since there is no attribute to inherit, initialize contents */ conserved_rec = (conserved_ptr) NTL0_ckalloc (sizeof (Conserved_Struct)); conserved_rec -> origin = NULL; conserved_rec -> start = 0; conserved_rec -> stop = 0; conserved_rec -> description = NULL; conserved_rec -> reference = NULL; conserved_rec -> corrections = NULL; conserved_rec -> contributor = NULL; conserved_rec -> consensus = NULL; conserved_rec -> next = NULL; in_region = FALSE; /* Loop to get conserved sites until there are no more in the file */ while (((erret = NTL2_LC_Next_Conserved (db_file, conserved_rec, &new_conserved)) == NULL) && (new_conserved != NULL)) { /* Allocate the next record and prepare to copy previous contents for inhr.*/ conserved_rec = (conserved_ptr) NTL0_ckalloc (sizeof (Conserved_Struct)); if (new_conserved -> origin != NULL) conserved_rec -> origin = NTL0_strsave (new_conserved -> origin); else conserved_rec -> origin = NULL; conserved_rec -> start = new_conserved -> start; conserved_rec -> stop = new_conserved -> stop; if (new_conserved -> description != NULL) conserved_rec -> description = NTL0_strsave (new_conserved -> description); else conserved_rec -> description = NULL; if (new_conserved -> reference != NULL) conserved_rec -> reference = NTL0_strsave (new_conserved -> reference); else conserved_rec -> reference = NULL; if (new_conserved -> corrections != NULL) conserved_rec -> corrections = NTL0_strsave (new_conserved -> corrections); else conserved_rec -> corrections = NULL; if (new_conserved -> contributor != NULL) conserved_rec -> contributor = NTL0_strsave (new_conserved -> contributor); else conserved_rec -> contributor = NULL; if (new_conserved -> consensus != NULL) conserved_rec -> consensus = NTL0_strsave (new_conserved -> consensus); else conserved_rec -> consensus = NULL; conserved_rec -> next = NULL; /* Now link the new conserved record to the list of those already loaded */ new_conserved -> next = *conserved; *conserved = new_conserved; in_region = FALSE; } /* At the end of the loop no conserved was found, so release preallocated */ if (conserved_rec -> origin != NULL) free (conserved_rec -> origin); if (conserved_rec -> description != NULL) free (conserved_rec -> description); if (conserved_rec -> reference != NULL) free (conserved_rec -> reference); if (conserved_rec -> corrections != NULL) free (conserved_rec -> corrections); if (conserved_rec -> contributor != NULL) free (conserved_rec -> contributor); if (conserved_rec -> consensus != NULL) free (conserved_rec -> consensus); free (conserved_rec); return erret; /* Return whatever was the error status from lower level */ } /*****************************************************************************/ /* */ /* Procedure: NTL2_LC_Next_Conserved */ /* */ /* Procedure extracts information about one conserved site at a time from */ /* the file and loads it into a new conserved structure, which coincides */ /* with the structure passed in the procedure (if there were no further */ /* conserved sites block information in the file, that value returns as */ /* NULL); returns the "standard" error structure, NULL if there were no */ /* errors in loading the structure */ errind NTL2_LC_Next_Conserved (FILE **db_file, conserved_ptr conserved_rec, conserved_ptr *new_record) { int next_tok; char *str; errind status; *new_record = NULL; /* Start with assumption that there is no new conserved */ /* Get the next relevant token from the file: if it indicates a start of */ /* new conserved block, reset inherited fields in reserved record */ if ((status = NTL2_LC_Conserved_Token (db_file, &next_tok, &str)) != NULL) { return status; } else if (next_tok == FTOK_CONSERVED) { /* New conserved block - reset */ if (conserved_rec -> origin != NULL) free (conserved_rec -> origin); if (conserved_rec -> description != NULL) free (conserved_rec -> description); if (conserved_rec -> reference != NULL) free (conserved_rec -> reference); if (conserved_rec -> corrections != NULL) free (conserved_rec -> corrections); if (conserved_rec -> contributor != NULL) free (conserved_rec -> contributor); if (conserved_rec -> consensus != NULL) free (conserved_rec -> consensus); conserved_rec -> origin = NULL; conserved_rec -> start = conserved_rec -> stop = 0; conserved_rec -> description = NULL; conserved_rec -> reference = NULL; conserved_rec -> corrections = NULL; conserved_rec -> contributor = NULL; conserved_rec -> consensus = NULL; in_region = FALSE; } else if (next_tok == FTOK_END) { /* There was supposed to be some contents */ *new_record = conserved_rec; return NTL2_LC_Assemble_Error (WARNING, ERR_FILE_FORMAT, "No contents in conserved block", 11); } else if (next_tok == FTOK_EOF) return NULL; /* EOF - no more conserved */ else if (next_tok == FTOK_REGION) in_region = TRUE; else if (next_tok == FTOK_LOCATION) in_region = FALSE; else if ((status = NTL2_LC_Fill_Conserved (conserved_rec, next_tok, &str)) != NULL) return status; /* Conserved contents or error in assembling it */ /* At this point it is impossible that there won't be new conserved - fill */ *new_record = conserved_rec; /* Whatever is now in old gets into new one */ /* Now proceed to get all the attributes of the region that has been seen */ do { status = NTL2_LC_Conserved_Token (db_file, &next_tok, &str); /* Token...*/ if (status != NULL) return status; /* Error in the file layout */ else { switch (next_tok) { case FTOK_CONSERVED: { /* Started again - no other start before "end" */ return NTL2_LC_Assemble_Error (USER_ERROR, ERR_FILE_FORMAT, "Illegal file format - double conserved", 12); } case FTOK_END: { if (in_region) /* Illegal to finish tuple before "closing" region */ return NTL2_LC_Assemble_Error (USER_ERROR, ERR_FILE_FORMAT, "Illegal file format - region not closed", 211); else return NULL; /* So full contents are collected */ } case FTOK_EOF: { /* Any region must complete ("end") before EOF */ return NTL2_LC_Assemble_Error (USER_ERROR, ERR_FILE_FORMAT, "Illegal file format - unterminated", 13); } case FTOK_REGION: { in_region = TRUE; break; } case FTOK_LOCATION: { in_region = FALSE; break; } default: if ((status = NTL2_LC_Fill_Conserved (conserved_rec, next_tok, &str)) != NULL) return status; /* Attribute or error assembling */ } } } while (TRUE); /* The endless loop will be broken when "end" returns */ } /*****************************************************************************/ /* */ /* Procedure: NTL2_LC_Conserved_Token */ /* */ /* Procedure gets the next "token" from the conserved regions file (or file */ /* containing conserved regions data) plus the accompanying information in */ /* the form of a string, if any; returns the error structure, NULL if */ /* there was no error discovered */ errind NTL2_LC_Conserved_Token (FILE **db_file, int *next_tok, char **str) { char ch; int accept_pos; bool pat, reached, in_comment; errind status; /* Skip the heading white spaces and all comments possibly interleaved */ while (TRUE) { ch = ' '; while ((ch == ' ') || (ch == '\n') || (ch == '\t')) ch = fgetc (*db_file); if (ch == EOF) { *str = NULL; *next_tok = FTOK_EOF; return NULL; } else if (ch == '#') { in_comment = TRUE; while (in_comment) { while ((ch != '\n') && (ch != EOF)) ch = fgetc (*db_file); in_comment = FALSE; while ((ch == ' ') || (ch == '\n') || (ch == '\t')) ch = fgetc (*db_file); if (ch == EOF) { *str = NULL; *next_tok = FTOK_EOF; return NULL; } else if (ch == '#') in_comment = TRUE; } } /* At this point some significant text has been seen - investigate */ accept_pos = 0; while ((accept_pos < IN_LIMIT) && (ch != EOF) && (ch != ' ') && (ch != '\n') && (ch != '\t') && (ch != ';') && (ch != '=')) { In_Buff [accept_pos++] = ch; ch = fgetc (*db_file); } if (accept_pos >= IN_LIMIT) { /* Error condition */ return NTL2_LC_Assemble_Error (USER_ERROR, ERR_BUFFER_OVERFLOW, "Text in file too long", 14); } else if (ch == EOF) { /* End-of-file prematurely hit */ return NTL2_LC_Assemble_Error (USER_ERROR, ERR_FILE_FORMAT, "Unexpected end-of-file", 15); } else { /* Text up to first "white space" is placed in accepting buffer */ In_Buff [accept_pos] = '\0'; if ((!strcmp (In_Buff, "begin")) || (!strcmp (In_Buff, "BEGIN"))) { /* Beginning of some block */ while ((ch == ' ') || (ch == '\n') || (ch == '\t')) ch = fgetc (*db_file); accept_pos = 0; while ((accept_pos < IN_LIMIT) && (ch != EOF) && (ch != ' ') && (ch != '\n') && (ch != '\t')) { In_Buff [accept_pos++] = ch; ch = fgetc (*db_file); } if (accept_pos >= IN_LIMIT) { /* Error condition */ return NTL2_LC_Assemble_Error (USER_ERROR, ERR_BUFFER_OVERFLOW, "Text in file too long", 16); } else if (ch == EOF) { /* Error condition */ return NTL2_LC_Assemble_Error (USER_ERROR, ERR_FILE_FORMAT, "Unexpected end-of-file", 17); } else { /* Name of the block collected in acceptance buffer - check */ In_Buff [accept_pos] = '\0'; if (in_region) { return NTL2_LC_Assemble_Error (USER_ERROR, ERR_FILE_FORMAT, "Illegal nesting in conserved item", 212); } else if (!strcmp (In_Buff, "region")) { *str = NULL; *next_tok = FTOK_REGION; /* Start of conserved location */ return NULL; } if (!strcmp (In_Buff, "conserved")) { *str = NULL; *next_tok = FTOK_CONSERVED; /* Beginning of new conserved */ return NULL; } else { /* So this was beginning of something else - find next entry */ reached = FALSE; while ((ch != EOF) && (!reached)) { while ((ch != EOF) && (ch != 'b') && (ch != 'B')) ch = fgetc (*db_file); if (ch != EOF) { pat = TRUE; ch = fgetc (*db_file); if ((ch != 'e') && (ch != 'E')) pat = FALSE; if (pat) { ch = fgetc (*db_file); if ((ch != 'g') && (ch != 'G')) pat = FALSE; } if (pat) { ch = fgetc (*db_file); if ((ch != 'i') && (ch != 'I')) pat = FALSE; } if (pat) { ch = fgetc (*db_file); if ((ch != 'n') && (ch != 'N')) pat = FALSE; } if (pat) { ch = fgetc (*db_file); if ((ch != ' ') && (ch != '\t') && (ch != '\n')) pat = FALSE; if (pat) { /* Skip the "white space" symbols between "begin" and identifier */ while ((ch == ' ') || (ch == '\t') || (ch == '\n')) ch = fgetc (*db_file); /* Now check whether the block identifier is "conserved" */ if ((ch != 'c') && (ch != 'C')) pat = FALSE; if (pat) { ch = fgetc (*db_file); if ((ch != 'o') && (ch != 'O')) pat = FALSE; } if (pat) { ch = fgetc (*db_file); if ((ch != 'n') && (ch != 'N')) pat = FALSE; } if (pat) { ch = fgetc (*db_file); if ((ch != 's') && (ch != 'S')) pat = FALSE; } if (pat) { ch = fgetc (*db_file); if ((ch != 'e') && (ch != 'E')) pat = FALSE; } if (pat) { ch = fgetc (*db_file); if ((ch != 'r') && (ch != 'R')) pat = FALSE; } if (pat) { ch = fgetc (*db_file); if ((ch != 'v') && (ch != 'V')) pat = FALSE; } if (pat) { ch = fgetc (*db_file); if ((ch != 'e') && (ch != 'E')) pat = FALSE; } if (pat) { ch = fgetc (*db_file); if ((ch != 'd') && (ch != 'D')) pat = FALSE; } if (pat) { ch = fgetc (*db_file); if ((ch == ' ') || (ch == '\t') || (ch == '\n')) reached = TRUE; } } } } } /* At this point it is either a beginning of a new region or EOF */ if (ch == EOF) { *str = NULL; *next_tok = FTOK_EOF; return NULL; } else { *str = NULL; *next_tok = FTOK_CONSERVED; return NULL; } } } } /* Since the text seen was not beginning of block, must be in conserved */ else if (in_region) { /* Inside a region record - get the fields */ if (!strcmp (In_Buff, "origin")) { while ((ch == ' ') || (ch == '\t') || (ch == '\n')) ch = fgetc (*db_file); if (ch != '=') { /* Error condition */ return NTL2_LC_Assemble_Error (USER_ERROR, ERR_FILE_FORMAT, "Illegal file format", 213); } else { ch = fgetc (*db_file); while ((ch == ' ') || (ch == '\t') || (ch == '\n')) ch = fgetc (*db_file); if ((status = NTL2_Assemble_String (db_file, ch, str)) == NULL) { *next_tok = FTOK_ORIGIN; return NULL; } } } else if (!strcmp (In_Buff, "start")) { while ((ch == ' ') || (ch == '\t') || (ch == '\n')) ch = fgetc (*db_file); if (ch != '=') { /* Error condition */ return NTL2_LC_Assemble_Error (USER_ERROR, ERR_FILE_FORMAT, "Illegal file format", 214); } else { ch = fgetc (*db_file); while ((ch == ' ') || (ch == '\t') || (ch == '\n')) ch = fgetc (*db_file); if ((status = NTL2_Assemble_String (db_file, ch, str)) == NULL) { *next_tok = FTOK_START; return NULL; } } } if (!strcmp (In_Buff, "stop")) { while ((ch == ' ') || (ch == '\t') || (ch == '\n')) ch = fgetc (*db_file); if (ch != '=') { /* Error condition */ return NTL2_LC_Assemble_Error (USER_ERROR, ERR_FILE_FORMAT, "Illegal file format", 215); } else { ch = fgetc (*db_file); while ((ch == ' ') || (ch == '\t') || (ch == '\n')) ch = fgetc (*db_file); if ((status = NTL2_Assemble_String (db_file, ch, str)) == NULL) { *next_tok = FTOK_STOP; return NULL; } } } else if ((!strcmp (In_Buff, "end")) || (!strcmp (In_Buff, "END"))) { /* The end of the region */ while ((ch == ' ') || (ch == '\t') || (ch == '\n')) ch = fgetc (*db_file); accept_pos = 0; while ((accept_pos < IN_LIMIT) && (ch != EOF) && (ch != ' ') && (ch != '\n') && (ch != '\t')) { In_Buff [accept_pos++] = ch; ch = fgetc (*db_file); } if (accept_pos >= IN_LIMIT) { /* Error condition */ return NTL2_LC_Assemble_Error (USER_ERROR, ERR_BUFFER_OVERFLOW, "Text in file too long", 216); } else if (ch == EOF) { /* Error condition */ return NTL2_LC_Assemble_Error (USER_ERROR, ERR_FILE_FORMAT, "Unexpected end-of-file", 217); } else { /* Name of the block collected in acceptance buffer - check */ In_Buff [accept_pos] = '\0'; if (!strcmp (In_Buff, "region")) { *str = NULL; *next_tok = FTOK_LOCATION; /* End of the region */ return NULL; } else { /* Error condition */ return NTL2_LC_Assemble_Error (USER_ERROR, ERR_FILE_FORMAT, "Illegal region conclusion", 218); } } } else { /* Error condition */ return NTL2_LC_Assemble_Error (USER_ERROR, ERR_FILE_FORMAT, "Illegal token for a region record", 219); } } else if (!strcmp (In_Buff, "description")) { while ((ch == ' ') || (ch == '\t') || (ch == '\n')) ch = fgetc (*db_file); if (ch != '=') { /* Error condition */ return NTL2_LC_Assemble_Error (USER_ERROR, ERR_FILE_FORMAT, "Illegal file format", 22); } else { ch = fgetc (*db_file); while ((ch == ' ') || (ch == '\t') || (ch == '\n')) ch = fgetc (*db_file); if ((status = NTL2_Assemble_String (db_file, ch, str)) == NULL) { *next_tok = FTOK_DESCRIPTION; return NULL; } } } else if (!strcmp (In_Buff, "item_no")) { while ((ch == ' ') || (ch == '\t') || (ch == '\n')) ch = fgetc (*db_file); if (ch != '=') { /* Error condition */ return NTL2_LC_Assemble_Error (USER_ERROR, ERR_FILE_FORMAT, "Illegal file format", 221); } else { ch = fgetc (*db_file); while ((ch == ' ') || (ch == '\t') || (ch == '\n')) ch = fgetc (*db_file); if ((status = NTL2_Assemble_String (db_file, ch, str)) == NULL) { *next_tok = FTOK_NUMBER; return NULL; } } } else if (!strcmp (In_Buff, "reference")) { while ((ch == ' ') || (ch == '\t') || (ch == '\n')) ch = fgetc (*db_file); if (ch != '=') { /* Error condition */ return NTL2_LC_Assemble_Error (USER_ERROR, ERR_FILE_FORMAT, "Illegal file format", 23); } else { ch = fgetc (*db_file); while ((ch == ' ') || (ch == '\t') || (ch == '\n')) ch = fgetc (*db_file); if ((status = NTL2_Assemble_String (db_file, ch, str)) == NULL) { *next_tok = FTOK_REFERENCE; return NULL; } } } else if (!strcmp (In_Buff, "corrections")) { while ((ch == ' ') || (ch == '\t') || (ch == '\n')) ch = fgetc (*db_file); if (ch != '=') { /* Error condition */ return NTL2_LC_Assemble_Error (USER_ERROR, ERR_FILE_FORMAT, "Illegal file format", 24); } else { ch = fgetc (*db_file); while ((ch == ' ') || (ch == '\t') || (ch == '\n')) ch = fgetc (*db_file); if ((status = NTL2_Assemble_String (db_file, ch, str)) == NULL) { *next_tok = FTOK_CORRECTIONS; return NULL; } } } else if (!strcmp (In_Buff, "contributor")) { while ((ch == ' ') || (ch == '\t') || (ch == '\n')) ch = fgetc (*db_file); if (ch != '=') { /* Error condition */ return NTL2_LC_Assemble_Error (USER_ERROR, ERR_FILE_FORMAT, "Illegal file format", 25); } else { ch = fgetc (*db_file); while ((ch == ' ') || (ch == '\t') || (ch == '\n')) ch = fgetc (*db_file); if ((status = NTL2_Assemble_String (db_file, ch, str)) == NULL) { *next_tok = FTOK_CONTRIBUTOR; return NULL; } } } else if (!strcmp (In_Buff, "consensus_seq")) { while ((ch == ' ') || (ch == '\t') || (ch == '\n')) ch = fgetc (*db_file); if (ch != '=') { /* Error condition */ return NTL2_LC_Assemble_Error (USER_ERROR, ERR_FILE_FORMAT, "Illegal file format", 26); } else { ch = fgetc (*db_file); while ((ch == ' ') || (ch == '\t') || (ch == '\n')) ch = fgetc (*db_file); if ((status = NTL2_Assemble_String (db_file, ch, str)) == NULL) { *next_tok = FTOK_CONSENSUS; return NULL; } } } else if ((!strcmp (In_Buff, "end")) || (!strcmp (In_Buff, "END"))) { /* The end of the current region */ while ((ch == ' ') || (ch == '\t') || (ch == '\n')) ch = fgetc (*db_file); accept_pos = 0; while ((accept_pos < IN_LIMIT) && (ch != EOF) && (ch != ' ') && (ch != '\n') && (ch != '\t')) { In_Buff [accept_pos++] = ch; ch = fgetc (*db_file); } if (accept_pos >= IN_LIMIT) { /* Error condition */ return NTL2_LC_Assemble_Error (USER_ERROR, ERR_BUFFER_OVERFLOW, "Text in file too long", 27); } else if (ch == EOF) { /* Error condition */ return NTL2_LC_Assemble_Error (USER_ERROR, ERR_FILE_FORMAT, "Unexpected end-of-file", 28); } else { /* Name of the block collected in acceptance buffer - check */ In_Buff [accept_pos] = '\0'; if (!strcmp (In_Buff, "conserved")) { *str = NULL; *next_tok = FTOK_END; /* End of the conserved block */ return NULL; } else { /* Error condition */ return NTL2_LC_Assemble_Error (USER_ERROR, ERR_FILE_FORMAT, "Illegal conserved block conclusion", 29); } } } else { /* Error condition */ return NTL2_LC_Assemble_Error (USER_ERROR, ERR_FILE_FORMAT, "Illegal token for conserved region in file", 30); } } } } /*****************************************************************************/ /* */ /* Procedure: NTL2_LC_Fill_Conserved */ /* */ /* Procedure fills single received conserved region record with information */ /* passed to it, which depends on the token that caused the record change; */ /* returns NULL if everything was OK, or "standard" error structure */ errind NTL2_LC_Fill_Conserved (conserved_ptr conserved_rec, int next_tok, char **str) { char *scan, *start_str; int len_count; switch (next_tok) { case FTOK_ORIGIN: { scan = *str; while ((*scan == ' ') || (*scan == '\t') || (*scan == '\n')) scan++; if (*scan == '\0') return NTL2_LC_Assemble_Error (USER_ERROR, ERR_FILE_FORMAT, "Illegal location specification in file", 31); start_str = scan; while ((*scan != ' ') && (*scan != '\t') && (*scan != '\n') && (*scan != '\0')) scan++; if (*scan != '\0') { *scan = '\0'; scan++; while ((*scan == ' ') || (*scan == '\t') || (*scan == '\n')) scan++; } if (*scan != '\0') return NTL2_LC_Assemble_Error (USER_ERROR, ERR_FILE_FORMAT, "Illegal location specification in file", 32); else conserved_rec -> origin = NTL0_strsave (start_str); free (*str); *str = NULL; return NULL; } case FTOK_START: { scan = *str; while ((*scan == ' ') || (*scan == '\t') || (*scan == '\n')) scan++; if ((*scan != '-') && ((*scan < '1') || (*scan > '9'))) return NTL2_LC_Assemble_Error (USER_ERROR, ERR_FILE_FORMAT, "Illegal start specification in file", 34); start_str = scan; len_count = 0; scan++; while ((*scan != ' ') && (*scan != '\t') && (*scan != '\n') && (*scan != '\0') && (len_count < MAX_LONG_LEN)) { if ((*scan < '0') || (*scan > '9')) return NTL2_LC_Assemble_Error (USER_ERROR, ERR_FILE_FORMAT, "Illegal start specification in file", 35); scan++; len_count++; } if (len_count >= MAX_LONG_LEN) return NTL2_LC_Assemble_Error (USER_ERROR, ERR_FILE_FORMAT, "Illegal start specification in file", 36); else if (*scan != '\0') { *scan = '\0'; scan++; while ((*scan == ' ') || (*scan == '\t') || (*scan == '\n')) scan++; } if (*scan != '\0') return NTL2_LC_Assemble_Error (USER_ERROR, ERR_FILE_FORMAT, "Illegal start specification in file", 33); else conserved_rec -> start = atol (start_str); free (*str); *str = NULL; return NULL; } case FTOK_STOP: { scan = *str; while ((*scan == ' ') || (*scan == '\t') || (*scan == '\n')) scan++; if ((*scan != '-') && ((*scan < '1') || (*scan > '9'))) return NTL2_LC_Assemble_Error (USER_ERROR, ERR_FILE_FORMAT, "Illegal stop specification in file", 38); start_str = scan; len_count = 0; scan++; while ((*scan != ' ') && (*scan != '\t') && (*scan != '\n') && (*scan != '\0') && (len_count < MAX_LONG_LEN)) { if ((*scan < '0') || (*scan > '9')) return NTL2_LC_Assemble_Error (USER_ERROR, ERR_FILE_FORMAT, "Illegal location specification in file", 39); scan++; len_count++; } if (len_count >= MAX_LONG_LEN) return NTL2_LC_Assemble_Error (USER_ERROR, ERR_FILE_FORMAT, "Illegal stop specification in file", 40); else if (*scan != '\0') { *scan = '\0'; scan++; while ((*scan == ' ') || (*scan == 't') || (*scan == '\n')) scan++; } if (*scan != '\0') return NTL2_LC_Assemble_Error (USER_ERROR, ERR_FILE_FORMAT, "Illegal stop specification in file", 41); else conserved_rec -> stop = atol (start_str); free (*str); *str = NULL; return NULL; } case FTOK_DESCRIPTION: { conserved_rec -> description = *str; *str = NULL; return NULL; } case FTOK_NUMBER: { free (*str); *str = NULL; return NULL; } case FTOK_REFERENCE: { conserved_rec -> reference = *str; *str = NULL; return NULL; } case FTOK_CORRECTIONS: { conserved_rec -> corrections = *str; *str = NULL; return NULL; } case FTOK_CONTRIBUTOR: { conserved_rec -> contributor = *str; *str = NULL; return NULL; } case FTOK_CONSENSUS: { conserved_rec -> consensus = *str; *str = NULL; return NULL; } default: { return NTL2_LC_Assemble_Error (FATAL_ERROR, ERR_CODE_PROBLEM, "Illegal token passed to assembling", 42); } } } /*****************************************************************************/ /* */ /* Procedure: NTL2_LC_Assemble_Error */ /* */ /* Service procedure for assembling and returnning an error report, based on */ /* the values of the input parameters; returns the record with the report */ errind NTL2_LC_Assemble_Error (int severity, int code, char *comment, int description) { char *report; errind assembled; report = (char *) NTL0_ckalloc ( (strlen (comment) + strlen ("_Load_Conserved: ") + 1) * sizeof (char)); sprintf (report, "_Load_Conserved: %s", comment); assembled = NTL1_Error_Record (severity, code, report, description); free (report); return assembled; }