/*****************************************************************************/ /* */ /* UNIT: NTL3_Origin_Sequence (Level 3 library routine) */ /* */ /* Author: Nikola Stojanovic */ /* */ /* Revision: 15 OCT 94 Version 1.0 */ /* */ /* Function: */ /* */ /* Procedure finds the sequence given origin "belongs" to. If the origins */ /* file has not yet been loaded, loads it and forms the list of origin known */ /* origin sites. Returns NULL if everything is OK, "standard" error */ /* structure otherwise */ /* */ /*****************************************************************************/ #include #include #include #include "ntl3.h" /*****************************************************************************/ /* */ /* Definitions section */ /* */ /*****************************************************************************/ /*****************************************************************************/ /* Prototypes of all locally used functions of this unit */ /*****************************************************************************/ errind NTL3_OS_Assemble_Error (int severity, int code, char *comment, int description); /*****************************************************************************/ /* Definitions of global (static) variables of the unit */ /*****************************************************************************/ static int origins_loaded = 0; /* Before first invocation, no origins loaded */ static orgref_ptr origins = NULL; /* List of defined origins in sequences */ /*****************************************************************************/ /* */ /* Code section */ /* */ /*****************************************************************************/ /*****************************************************************************/ /* */ /* Procedure: NTL3_Origin_Sequence */ /* */ /* Main (interface) procedure of this unit */ errind NTL3_Origin_Sequence (char *orig_file, char *origin, char **sequence, long int *offset) { errind load_status; orgref_ptr orig_scan; bool found; /* Check whether this is the first invocation of this routine - if it is, */ /* then load the origins file into internal structure */ if (origins_loaded == 0) { /* This is the first invocation within program */ if ((load_status = NTL2_Load_Origins (orig_file, &origins)) != NULL) return load_status; else origins_loaded = 1; } /* Loop through the origins structure loaded in search for the origin name */ /* that matches the given one */ orig_scan = origins; found = FALSE; while ((!found) && (orig_scan != NULL)) { if (!strcmp (orig_scan -> site_name, origin)) found = TRUE; else orig_scan = orig_scan -> next; } if (!found) return NTL3_OS_Assemble_Error (USER_ERROR, ERR_NO_VALUE, "Given origin site not found in the list", 0); else { *sequence = NTL0_strsave (orig_scan -> in_species); *offset = orig_scan -> location; return NULL; } } /*****************************************************************************/ /* */ /* Procedure: NTL3_OS_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 NTL3_OS_Assemble_Error (int severity, int code, char *comment, int description) { char *report; errind assembled; report = (char *) NTL0_ckalloc ( (strlen (comment) + strlen ("_Origin_Sequence: ") + 1) * sizeof (char)); sprintf (report, "_Origin_Sequence: %s", comment); assembled = NTL1_Error_Record (severity, code, report, description); free (report); return assembled; }