static char const rcsid [] = "$Id: maps_raws.c,v 1.1 1998/04/22 10:20:23 stojanov Exp $"; /*****************************************************************************/ /* */ /* Unit: MAPS_RAWS () */ /* */ /* Author: Nikola Stojanovic */ /* */ /* Revision: 15 APR 98 */ /* */ /* Unit contains code for raw processing of the structures based on the */ /* specifications parsing, turning them into intermediate form, before */ /* starting display preparations. */ /* */ /*****************************************************************************/ #include #include #include #include #include "maps.h" #include "maps_vars.h" /*****************************************************************************/ /* */ /* Constants whose values should be known locally in this unit */ /* */ /*****************************************************************************/ #define ORIGIN_OK 0 #define ORIGIN_AMBIGUOUS -1 #define ORIGIN_MISSING -2 #define ORIGIN_WRONG_SEQUENCE -3 #define ERR_RAWS_INIT -1 #define ERR_PLAIN_LOAD -3 #define ERR_LAND_LOAD -4 #define ERR_ORIG_LOAD -5 #define ERR_TEXT_PIVOT -6 /*****************************************************************************/ /* */ /* Types used only locally in this unit */ /* */ /*****************************************************************************/ typedef struct lstore_fields { char *sequence; int seqnum; char *origin; long int start; long int stop; char *reference; bool bulk; int mark_kind; int mark_multiple; char *mark_seq; int mark_seqnum; char *mark_style; bool mark_shade; float mark_intensity; label_ptr label; int label_place; int label_position; struct lstore_fields *next; } Lstore_Struct; typedef Lstore_Struct *lstore_ptr; typedef struct bstore_fields { char *sequence; char *origin; long int start; long int stop; char *style; bool shade; float intensity; label_ptr label; int label_place; int label_position; struct bstore_fields *next; } Bstore_Struct; typedef Bstore_Struct *bstore_ptr; typedef struct ustore_fields { int kind; char *sequence; char *origin; long int start; long int stop; char *style; label_ptr label; int label_place; int label_position; struct ustore_fields *next; } Ustore_Struct; typedef Ustore_Struct *ustore_ptr; typedef struct tstore_fields { int line_number; bool disabled; int banner; char *banner_font; int banner_font_size; long int adjustment; int layout; int pivot; int trailer; char *trailer_font; int trailer_font_size; int started; int ended; struct tstore_fields *next; } Tstore_Struct; typedef Tstore_Struct *tstore_ptr; /*****************************************************************************/ /* */ /* Global Variables Section - module level */ /* */ /*****************************************************************************/ static lstore_ptr land_store; static bstore_ptr box_store; static ustore_ptr under_store; static tstore_ptr text_store; static long int absolute_counter; static long int sequence_counter; static int information_sequences; /*****************************************************************************/ /* */ /* Forward declarations of unit internal procedures - not visible from out. */ /* */ /*****************************************************************************/ int RAWS_Check_Origin (char *origin, char *sequence, long int *offset, int *source); int RAWS_Name_Origin (char *origin, char **sequence, long int *offset, int *source); /*****************************************************************************/ /* */ /* Module routines callable from outside - interface procedures */ /* */ /*****************************************************************************/ /*****************************************************************************/ /* */ /* Procedure: RAWS_Initialize */ /* */ int RAWS_Initialize (void) { seqover_ptr findings; /* Lots of references to the alignment are with respect to the "principal */ /* sequence" - finds its ordinal number within the alignment first */ if ((findings = ALGN_Find_Sequence (principal_sequence, ANY_LIST)) == NULL) { CONT_Error_Report (USER_ERROR, ERR_NO_VALUE, "No principal sequence '", principal_sequence, UNDEFINED, "' in the alignment", 0, FALSE); return ERR_RAWS_INIT; } else if ((findings -> next != NULL) && (findings -> source_list == (findings -> next) -> source_list)) { CONT_Error_Report (USER_ERROR, ERR_NO_VALUE, "Non-unique principal sequence '", principal_sequence, UNDEFINED, "' in the alignment", 0, FALSE); return ERR_RAWS_INIT; } else principal_seqnum = findings -> seq_num; land_store = NULL; established_origins = NULL; box_store = NULL; under_store = NULL; established_top_vector = NULL; established_top_lines = NULL; established_inter_vector = NULL; established_inter_lines = NULL; established_bottom_vector = NULL; established_bottom_lines = NULL; text_store = NULL; established_landmarks = NULL; established_boxes = NULL; established_underlines = NULL; established_text_vector = NULL; established_information = NULL; absolute_counter = 0; sequence_counter = 0; information_sequences = 0; return 0; } /*****************************************************************************/ /* */ /* Procedure: RAWS_Expand_Information */ /* */ int RAWS_Expand_Information (void) { int na, ng, nt, nc, ngap, no, current_size, index; long int scanner; double fa, fg, ft, fc, fgap, da, dg, dt, dc, dgap; /* If the "information contents" is requested for the alignment, calculate */ /* it and store for further use */ established_information = (float *) NTL0_ckalloc (alignment_records -> size * sizeof (float)); for (scanner = 0; scanner < alignment_records -> size; scanner++) established_information [scanner] = (float) UNDEFINED; for (scanner = 0; scanner < alignment_records -> size; scanner++) { na = ng = nt = nc = no = ngap = 0; current_size = alignment_records -> dimension; for (index = 0; index < alignment_records -> dimension; index++) { if (((alignment_records -> segment_code) [index] != VALID_SEGMENT) || (scanner < (alignment_records -> starts) [index]) || (scanner > (alignment_records -> stops) [index])) current_size--; else if ((alignment_records -> texts) [index] [scanner] == GAP_SYMBOL) ngap++; else if ((alignment_records -> texts) [index] [scanner] == 'A') na++; else if ((alignment_records -> texts) [index] [scanner] == 'C') nc++; else if ((alignment_records -> texts) [index] [scanner] == 'G') ng++; else if ((alignment_records -> texts) [index] [scanner] == 'T') nt++; else no++; } if (no == 0) { if ((ngap > 0) && (information_kind == STRICT_CODE)) established_information [scanner] = 0.0; else { if (information_kind == WILDCARD_CODE) { current_size -= ngap; ngap = 0; } if (current_size > 0) { fa = ((double) na) / ((double) current_size); fg = ((double) ng) / ((double) current_size); ft = ((double) nt) / ((double) current_size); fc = ((double) nc) / ((double) current_size); fgap = ((double) ngap) / ((double) current_size); if (pa > EPSILON) da = fa / pa; else da = 0.0; if (pg > EPSILON) dg = fg / pg; else dg = 0.0; if (pt > EPSILON) dt = ft / pt; else dt = 0.0; if (pc > EPSILON) dc = fc / pc; else dc = 0.0; if (pgap > EPSILON) dgap = fgap / pgap; else dgap = 0.0; if (da > FLOAT_LN_LIMIT) da = log (da); else da = 0.0; if (dg > FLOAT_LN_LIMIT) dg = log (dg); else dg = 0.0; if (dt > FLOAT_LN_LIMIT) dt = log (dt); else dt = 0.0; if (dc > FLOAT_LN_LIMIT) dc = log (dc); else dc = 0.0; if (dgap > FLOAT_LN_LIMIT) dgap = log (dgap); else dgap = 0.0; established_information [scanner] = (float) (fa * da + fg * dg + ft * dt + fc * dc + fgap * dgap); } } } } return 0; } /*****************************************************************************/ /* */ /* Procedure: RAWS_Expand_Landmarks */ /* */ int RAWS_Expand_Landmarks (char *file_name, int mark_kind, int mark_multiple, char *mark_seq, char *mark_style, bool mark_shade, float mark_intensity, char *label_font, int font_size) { landmark_ptr loaded, land_scan, dismissed; label_ptr label_scan; lstore_ptr new_landmark; strlist_ptr current_path; char *new_path; errind report; /* Load the landmarks from the specified file into a temporary chain first */ loaded = NULL; /* Open the landmarks input file, check existence and load the data */ if ((registered_paths == NULL) || (file_name [0] == '/') || (file_name [0] == '~')) { if ((report = NTL2_Load_Landmarks (file_name, &loaded)) != NULL) { NTL1_Print_Error (report); return ERR_LAND_LOAD; } } else if ((report = NTL2_Load_Landmarks (file_name, &loaded)) != NULL) { loaded = NULL; current_path = registered_paths; while ((loaded == NULL) && (current_path != NULL)) { new_path = NTL0_ckalloc ((strlen (current_path -> string) + strlen (file_name) + 2) * sizeof (char)); strcpy (new_path, current_path -> string); if (new_path [strlen (current_path -> string) - 1] != '/') strcat (new_path, "/"); strcat (new_path, file_name); if ((report = NTL2_Load_Landmarks (new_path, &loaded)) != NULL) { loaded = NULL; current_path = current_path -> next; } free (new_path); } if (report != NULL) { /* File not found on any path */ NTL1_Print_Error (report); return ERR_LAND_LOAD; } } /* If this point is reached, then the landmarks were successfully loaded */ /* Loop through the list of the loaded landmarks to copy them into internal */ /* landmark structures - all landmarks still to be kept */ land_scan = loaded; while (land_scan != NULL) { new_landmark = (lstore_ptr) NTL0_ckalloc (sizeof (Lstore_Struct)); new_landmark -> sequence = land_scan -> sequence; new_landmark -> seqnum = UNDEFINED; new_landmark -> origin = land_scan -> origin; new_landmark -> start = land_scan -> start; new_landmark -> stop = land_scan -> stop; new_landmark -> reference = land_scan -> reference; new_landmark -> bulk = TRUE; new_landmark -> mark_kind = mark_kind; new_landmark -> mark_multiple = mark_multiple; if (mark_kind == UNDERLINE_CODE) { if (mark_seq == NULL) new_landmark -> mark_seq = NTL0_strsave (new_landmark -> sequence); else new_landmark -> mark_seq = NTL0_strsave (mark_seq); } else new_landmark -> mark_seq = NULL; new_landmark -> mark_style = NTL0_strsave (mark_style); new_landmark -> mark_shade = mark_shade; new_landmark -> mark_intensity = mark_intensity; /* Traverse the received label to set up all eventually undefined fields */ /* of fraction fonts and/or their sizes */ label_scan = land_scan -> label; while (label_scan != NULL) { if (label_scan -> font_name == NULL) label_scan -> font_name = NTL0_strsave (label_font); if ((label_scan -> font_size == 0) || (label_scan -> font_size == UNDEFINED)) label_scan -> font_size = font_size; label_scan = label_scan -> next; } new_landmark -> label = land_scan -> label; new_landmark -> label_place = land_scan -> label_pos; new_landmark -> label_position = land_scan -> label_shift; new_landmark -> next = land_store; land_store = new_landmark; dismissed = land_scan; land_scan = land_scan -> next; if (dismissed -> description != NULL) free (dismissed -> description); if (dismissed -> contributor != NULL) free (dismissed -> contributor); free (dismissed); } return 0; } /*****************************************************************************/ /* */ /* Procedure: RAWS_Record_Landmark */ /* */ int RAWS_Record_Landmark (char *sequence, char *origin, long int start, long int stop, int mark_kind, int mark_multiple, char *mark_seq, char *mark_style, bool mark_shade, float mark_intensity, label_ptr label, int label_place, int label_position) { lstore_ptr new_landmark; new_landmark = (lstore_ptr) NTL0_ckalloc (sizeof (Lstore_Struct)); new_landmark -> sequence = NTL0_strsave (sequence); new_landmark -> seqnum = UNDEFINED; new_landmark -> origin = NTL0_strsave (origin); new_landmark -> start = start; new_landmark -> stop = stop; new_landmark -> reference = NULL; new_landmark -> bulk = FALSE; new_landmark -> mark_kind = mark_kind; new_landmark -> mark_multiple = mark_multiple; new_landmark -> mark_seq = NTL0_strsave (mark_seq); new_landmark -> mark_style = NTL0_strsave (mark_style); new_landmark -> mark_shade = mark_shade; new_landmark -> mark_intensity = mark_intensity; if (label == NULL) { new_landmark -> label = NULL; new_landmark -> label_place = label_place; new_landmark -> label_position = label_position; } else { new_landmark -> label = NTL1_Copy_Label (label); new_landmark -> label_place = label_place; new_landmark -> label_position = label_position; } new_landmark -> next = land_store; land_store = new_landmark; return 0; } /*****************************************************************************/ /* */ /* Procedure: RAWS_Expand_Annotations */ /* */ int RAWS_Expand_Annotations (char *file_name, int counter, int mark_kind, int mark_multiple, char *mark_style, bool mark_shade, float mark_intensity, char *text, char *text_font, int text_size, int field, char *field_font, int field_size, int place, int position) { plain_ptr line_records, plain_scan, dismissed; errind report; bool loaded; char *new_path, *rep_string; strlist_ptr current_path; label_ptr field_record; lstore_ptr new_landmark; /* Load the records from the specified file into a temporary chain first */ line_records = NULL; /* Open the records input file, check existence and load the data */ if ((registered_paths == NULL) || (file_name [0] == '/') || (file_name [0] == '~')) { if ((report = NTL2_Load_Plain (file_name, &line_records)) != NULL) { NTL1_Print_Error (report); return ERR_PLAIN_LOAD; } } else if ((report = NTL2_Load_Plain (file_name, &line_records)) != NULL) { line_records = NULL; loaded = FALSE; current_path = registered_paths; while ((!loaded) && (current_path != NULL)) { new_path = NTL0_ckalloc ((strlen (current_path -> string) + strlen (file_name) + 2) * sizeof (char)); strcpy (new_path, current_path -> string); if (new_path [strlen (current_path -> string) - 1] != '/') strcat (new_path, "/"); strcat (new_path, file_name); if ((report = NTL2_Load_Plain (new_path, &line_records)) != NULL) { line_records = NULL; current_path = current_path -> next; } else loaded = TRUE; free (new_path); } if (!loaded) { /* File not found on any path */ NTL1_Print_Error (report); return ERR_PLAIN_LOAD; } } /* If this point is reached, then the line records have been loaded */ plain_scan = line_records; while (plain_scan != NULL) { new_landmark = (lstore_ptr) NTL0_ckalloc (sizeof (Lstore_Struct)); new_landmark -> sequence = NULL; if (counter == UNDEFINED) new_landmark -> seqnum = principal_seqnum; else new_landmark -> seqnum = counter; new_landmark -> origin = NTL0_strsave ("absolute"); new_landmark -> start = plain_scan -> start; new_landmark -> stop = plain_scan -> stop; new_landmark -> reference = NULL; new_landmark -> bulk = TRUE; new_landmark -> mark_kind = mark_kind; new_landmark -> mark_multiple = mark_multiple; new_landmark -> mark_seq = NULL; new_landmark -> mark_style = NTL0_strsave (mark_style); new_landmark -> mark_shade = mark_shade; new_landmark -> mark_intensity = mark_intensity; /* Assemble the label for the landmark, if any requested */ if (field != UNDEFINED) { field_record = (label_ptr) NTL0_ckalloc (sizeof (Label_Struct)); switch (field) { case 1: { rep_string = (char *) NTL0_ckalloc (80 * sizeof (char)); sprintf (rep_string, "Start address used as landmark label (field 1)"); CONT_Warning (rep_string); sprintf (rep_string, "%ld", plain_scan -> start); field_record -> text = NTL0_strsave (rep_string); free (rep_string); break; } case 2: { rep_string = (char *) NTL0_ckalloc (80 * sizeof (char)); sprintf (rep_string, "End address used as landmark label (field 2)"); CONT_Warning (rep_string); sprintf (rep_string, "%ld", plain_scan -> stop); field_record -> text = NTL0_strsave (rep_string); free (rep_string); break; } case 3: { field_record -> text = NTL0_strsave (plain_scan -> text); break; } case 4: { field_record -> text = NTL0_strsave (plain_scan -> matched); break; } case 5: { field_record -> text = NTL0_strsave (plain_scan -> site); break; } case 6: { field_record -> text = NTL0_strsave (plain_scan -> binding); break; } case 7: { field_record -> text = (char *) NTL0_ckalloc (2 * sizeof (char)); (field_record -> text) [0] = plain_scan -> strand; (field_record -> text) [1] = '\0'; break; } case 8: { field_record -> text = NTL0_strsave (plain_scan -> database); break; } case 9: { field_record -> text = NTL0_strsave (plain_scan -> file); break; } case 10: { field_record -> text = NTL0_strsave (plain_scan -> reference); break; } case 11: { field_record -> text = NTL0_strsave (plain_scan -> c_range); break; } default: { rep_string = (char *) NTL0_ckalloc (80 * sizeof (char)); sprintf (rep_string, "Field selected as landmark label (%d) not legal", field); CONT_Warning (rep_string); sprintf (rep_string, "null"); field_record -> text = NTL0_strsave (rep_string); free (rep_string); } } field_record -> font_name = NTL0_strsave (field_font); field_record -> font_size = field_size; field_record -> next = NULL; } else field_record = NULL; if (text == NULL) new_landmark -> label = field_record; else { new_landmark -> label = (label_ptr) NTL0_ckalloc (sizeof (Label_Struct)); (new_landmark -> label) -> text = NTL0_strsave (text); (new_landmark -> label) -> font_name = NTL0_strsave (text_font); (new_landmark -> label) -> font_size = text_size; (new_landmark -> label) -> next = field_record; } new_landmark -> label_place = place; new_landmark -> label_position = position; new_landmark -> next = land_store; land_store = new_landmark; dismissed = plain_scan; plain_scan = plain_scan -> next; if (dismissed -> text != NULL) free (dismissed -> text); if (dismissed -> matched != NULL) free (dismissed -> matched); if (dismissed -> site != NULL) free (dismissed -> site); if (dismissed -> binding != NULL) free (dismissed -> binding); if (dismissed -> database != NULL) free (dismissed -> database); if (dismissed -> file != NULL) free (dismissed -> file); if (dismissed -> reference != NULL) free (dismissed -> reference); if (dismissed -> c_range != NULL) free (dismissed -> c_range); if (dismissed -> full_ref != NULL) dismissed -> full_ref = UTIL_Release_StrList (dismissed -> full_ref); free (dismissed); } return 0; } /*****************************************************************************/ /* */ /* Procedure: RAWS_Expand_Origins */ /* */ int RAWS_Expand_Origins (char *file_name, long int from, long int to) { errind report; char *rep_string; orgref_ptr loaded, orig_scan, dismissed; originll_ptr new_origin, last_origin, current_origin, trash; strlist_ptr current_path; char *new_path; /* Load the origins from the specified file into a temporary chain first */ loaded = NULL; /* Open the records input file, check existence and load the data */ if ((registered_paths == NULL) || (file_name [0] == '/') || (file_name [0] == '~')) { if ((report = NTL2_Load_Origins (file_name, &loaded)) != NULL) { NTL1_Print_Error (report); return ERR_ORIG_LOAD; } } else if ((report = NTL2_Load_Origins (file_name, &loaded)) != NULL) { loaded = NULL; current_path = registered_paths; while ((loaded == NULL) && (current_path != NULL)) { new_path = NTL0_ckalloc ((strlen (current_path -> string) + strlen (file_name) + 2) * sizeof (char)); strcpy (new_path, current_path -> string); if (new_path [strlen (current_path -> string) - 1] != '/') strcat (new_path, "/"); strcat (new_path, file_name); if ((report = NTL2_Load_Origins (new_path, &loaded)) != NULL) { loaded = NULL; current_path = current_path -> next; } free (new_path); } if (report != NULL) { /* File not found on any path */ NTL1_Print_Error (report); return ERR_ORIG_LOAD; } } /* If this point is reached, then the origins were successfully loaded */ /* Loop through the list of the loaded origins to copy them into internal */ /* origin structures - all origins to be kept */ orig_scan = loaded; while (orig_scan != NULL) { new_origin = (originll_ptr) NTL0_ckalloc (sizeof (OriginLL_Struct)); new_origin -> name = orig_scan -> site_name; new_origin -> sequence = orig_scan -> in_species; new_origin -> aliases = ALGN_Get_Aliases (new_origin -> sequence); new_origin -> species = orig_scan -> species; new_origin -> position = orig_scan -> location; /* Permit the "from-to" range only for the "principal" sequence */ if (!strcmp (new_origin -> sequence, principal_sequence)) { new_origin -> from = from; new_origin -> to = to; } else { new_origin -> from = 0; new_origin -> to = 0; } /* Search the list of the origins so far recorded for possible duplicate */ last_origin = NULL; current_origin = established_origins; while (current_origin != NULL) { if ((!strcmp (new_origin -> name, current_origin -> name)) && (!strcmp (new_origin -> sequence, current_origin -> sequence))) { /* Since this origin is loaded from a file, all alieases are "covered", */ /* so this must be an overlap with already defined one */ rep_string = (char *) NTL0_ckalloc ((60 + strlen (new_origin -> name) + strlen (new_origin -> sequence) + strlen (file_name)) * sizeof (char)); sprintf (rep_string, "Redefinition of file-based origin '%s' in '%s' in file '%s'", new_origin -> name, new_origin -> sequence, file_name); CONT_Warning (rep_string); free (rep_string); if (last_origin == NULL) { trash = established_origins; established_origins = established_origins -> next; current_origin = established_origins; } else { trash = current_origin; last_origin -> next = current_origin -> next; current_origin = current_origin -> next; } if (trash -> name != NULL) free (trash -> name); if (trash -> sequence != NULL) free (trash -> sequence); if (trash -> aliases != NULL) trash -> aliases = UTIL_Release_StrList (trash -> aliases); if (trash -> species != NULL) free (trash -> species); free (trash); } else { last_origin = current_origin; current_origin = current_origin -> next; } } new_origin -> next = established_origins; established_origins = new_origin; dismissed = orig_scan; orig_scan = orig_scan -> next; free (dismissed); } return 0; } /*****************************************************************************/ /* */ /* Procedure: RAWS_Record_Origin */ /* */ int RAWS_Record_Origin (char *name, long int position, char *sequence, long int from, long int to) { originll_ptr last_origin, current_origin, trash, new_origin; char *rep_string; bool alias_overlap; strlist_ptr alias_scan_1, alias_scan_2; /* Create and add the new origin record to the list of known origins */ new_origin = (originll_ptr) NTL0_ckalloc (sizeof (OriginLL_Struct)); new_origin -> name = NTL0_strsave (name); if ((new_origin -> sequence = ALGN_Get_Sequence (sequence)) == NULL) { new_origin -> sequence = NTL0_strsave (sequence); new_origin -> aliases = ALGN_Get_Aliases (sequence); } else { new_origin -> aliases = (strlist_ptr) NTL0_ckalloc (sizeof (StrList_Struct)); (new_origin -> aliases) -> string = NTL0_strsave (sequence); (new_origin -> aliases) -> next = NULL; } new_origin -> species = NULL; new_origin -> position = position; new_origin -> from = from; new_origin -> to = to; if (name != NULL) { /* Loop through the list of established origins to detect any duplicates */ last_origin = NULL; current_origin = established_origins; while (current_origin != NULL) { if ((!strcmp (name, current_origin -> name)) && (!strcmp (sequence, current_origin -> sequence))) { /* Check if these 2 specifications are with respect to different aliases */ if ((new_origin -> aliases == NULL) || (current_origin -> aliases == NULL)) alias_overlap = TRUE; else { alias_overlap = FALSE; for (alias_scan_1 = new_origin -> aliases; alias_scan_1 != NULL; alias_scan_1 = alias_scan_1 -> next) { for (alias_scan_2 = current_origin -> aliases; alias_scan_2 != NULL; alias_scan_2 = alias_scan_2 -> next) { if (!strcmp (alias_scan_1 -> string, alias_scan_2 -> string)) { alias_overlap = TRUE; } } } } if (alias_overlap) { rep_string = (char *) NTL0_ckalloc ((62 + strlen (name) + strlen (sequence)) * sizeof (char)); sprintf (rep_string, "Redefinition of file-based origin '%s' in '%s' by explicit", name, sequence); CONT_Warning (rep_string); free (rep_string); if (last_origin == NULL) { trash = established_origins; established_origins = established_origins -> next; current_origin = established_origins; } else { trash = current_origin; last_origin -> next = current_origin -> next; current_origin = current_origin -> next; } if (trash -> name != NULL) free (trash -> name); if (trash -> sequence != NULL) free (trash -> sequence); if (trash -> aliases != NULL) trash -> aliases = UTIL_Release_StrList (trash -> aliases); if (trash -> species != NULL) free (trash -> species); free (trash); } else { last_origin = current_origin; current_origin = current_origin -> next; } } else current_origin = current_origin -> next; } } new_origin -> next = established_origins; established_origins = new_origin; return 0; } /*****************************************************************************/ /* */ /* Procedure: RAWS_Record_Box */ /* */ int RAWS_Record_Box (char *sequence, char *origin, long int start, long int stop, char *style, bool shade, float intensity, label_ptr label, int label_place, int label_position) { bstore_ptr new_box; new_box = (bstore_ptr) NTL0_ckalloc (sizeof (Bstore_Struct)); new_box -> sequence = NTL0_strsave (sequence); new_box -> origin = NTL0_strsave (origin); new_box -> start = start; new_box -> stop = stop; new_box -> style = NTL0_strsave (style); new_box -> shade = shade; new_box -> intensity = intensity; new_box -> label = NTL1_Copy_Label (label); new_box -> label_place = label_place; new_box -> label_position = label_position; new_box -> next = box_store; box_store = new_box; return 0; } /*****************************************************************************/ /* */ /* Procedure: RAWS_Record_Underline */ /* */ int RAWS_Record_Underline (int kind, char *sequence, char *origin, long int start, long int stop, char *style, label_ptr label, int label_place, int label_position) { ustore_ptr new_underline; new_underline = (ustore_ptr) NTL0_ckalloc (sizeof (Ustore_Struct)); new_underline -> kind = kind; new_underline -> sequence = NTL0_strsave (sequence); new_underline -> origin = NTL0_strsave (origin); new_underline -> start = start; new_underline -> stop = stop; new_underline -> style = NTL0_strsave (style); new_underline -> label = NTL1_Copy_Label (label); new_underline -> label_place = label_place; new_underline -> label_position = label_position; new_underline -> next = under_store; under_store = new_underline; return 0; } /*****************************************************************************/ /* */ /* Procedure: RAWS_Top_Line */ /* */ int RAWS_Top_Line (int number, int previous, int contents, int tick_distance, char *inline_text, int text_repeat) { int index; descll_ptr new_desc_line, scan_top; /* If this is the first invocation of the procedure, create the vector of */ /* lines and initialize the list of the top lines */ if (number == 1) { established_top_vector = (descll_ptr *) NTL0_ckalloc (alignment_records -> dimension * sizeof (descll_ptr)); for (index = 0; index < alignment_records -> dimension; index++) established_top_vector [index] = NULL; established_top_lines = NULL; } /* Now proceed to fill in the corresponding vector entry based on previous */ if (previous > 0) established_top_vector [number - 1] = established_top_vector [previous - 1]; else { /* Create the description record for this line and connect it to the list */ new_desc_line = (descll_ptr) NTL0_ckalloc (sizeof (DescLL_Struct)); new_desc_line -> contents = contents; new_desc_line -> tick_distance = tick_distance; new_desc_line -> inline_text = NTL0_strsave (inline_text); new_desc_line -> text_repeat = text_repeat; new_desc_line -> buffer = NULL; new_desc_line -> counts = NULL; new_desc_line -> next = NULL; if (established_top_lines == NULL) established_top_lines = new_desc_line; else { scan_top = established_top_lines; while (scan_top -> next != NULL) scan_top = scan_top -> next; scan_top -> next = new_desc_line; } established_top_vector [number - 1] = new_desc_line; } return 0; } /*****************************************************************************/ /* */ /* Procedure: RAWS_Intermediate_Line */ /* */ int RAWS_Intermediate_Line (int number, int previous, int contents, int tick_distance, char *inline_text, int text_repeat) { int index; descll_ptr new_desc_line, scan_inter; /* If this is the first invocation of the procedure, create the vector of */ /* lines and initialize the list of the intermediate lines */ if (number == 1) { established_inter_vector = (descll_ptr *) NTL0_ckalloc (alignment_records -> dimension * sizeof (descll_ptr)); for (index = 0; index < alignment_records -> dimension; index++) established_inter_vector [index] = NULL; established_inter_lines = NULL; } /* Now proceed to fill in the corresponding vector entry based on previous */ if (previous > 0) established_inter_vector [number - 1] = established_inter_vector [previous - 1]; else { /* Create the description record for this line and connect it to the list */ new_desc_line = (descll_ptr) NTL0_ckalloc (sizeof (DescLL_Struct)); new_desc_line -> contents = contents; new_desc_line -> tick_distance = tick_distance; new_desc_line -> inline_text = NTL0_strsave (inline_text); new_desc_line -> text_repeat = text_repeat; new_desc_line -> buffer = NULL; new_desc_line -> counts = NULL; new_desc_line -> next = NULL; if (established_inter_lines == NULL) established_inter_lines = new_desc_line; else { scan_inter = established_inter_lines; while (scan_inter -> next != NULL) scan_inter = scan_inter -> next; scan_inter -> next = new_desc_line; } established_inter_vector [number - 1] = new_desc_line; } return 0; } /*****************************************************************************/ /* */ /* Procedure: RAWS_Bottom_Line */ /* */ int RAWS_Bottom_Line (int number, int previous, int contents, int tick_distance, char *inline_text, int text_repeat) { int index; descll_ptr new_desc_line, scan_bottom; /* If this is the first invocation of the procedure, create the vector of */ /* lines and initialize the list of the bottom lines */ if (number == 1) { established_bottom_vector = (descll_ptr *) NTL0_ckalloc (alignment_records -> dimension * sizeof (descll_ptr)); for (index = 0; index < alignment_records -> dimension; index++) established_bottom_vector [index] = NULL; established_bottom_lines = NULL; } /* Now proceed to fill in the corresponding vector entry based on previous */ if (previous > 0) established_bottom_vector [number - 1] = established_bottom_vector [previous - 1]; else { /* Create the description record for this line and connect it to the list */ new_desc_line = (descll_ptr) NTL0_ckalloc (sizeof (DescLL_Struct)); new_desc_line -> contents = contents; new_desc_line -> tick_distance = tick_distance; new_desc_line -> inline_text = NTL0_strsave (inline_text); new_desc_line -> text_repeat = text_repeat; new_desc_line -> buffer = NULL; new_desc_line -> counts = NULL; new_desc_line -> next = NULL; if (established_bottom_lines == NULL) established_bottom_lines = new_desc_line; else { scan_bottom = established_bottom_lines; while (scan_bottom -> next != NULL) scan_bottom = scan_bottom -> next; scan_bottom -> next = new_desc_line; } established_bottom_vector [number - 1] = new_desc_line; } return 0; } /*****************************************************************************/ /* */ /* Procedure: RAWS_Text_Line */ /* */ int RAWS_Text_Line (int number, bool disabled, int banner, char *banner_font, int banner_font_size, long int adjustment, int layout, int pivot, char *pivot_sequence, int trailer, char *trailer_font, int trailer_font_size, int started, int ended) { tstore_ptr new_text, text_scan; seqover_ptr findings, old_find; /* Create a new record for the text line and insert it into the list in a */ /* sorted order */ new_text = (tstore_ptr) NTL0_ckalloc (sizeof (Tstore_Struct)); new_text -> line_number = number; new_text -> disabled = disabled; new_text -> banner = banner; new_text -> banner_font = NTL0_strsave (banner_font); new_text -> banner_font_size = banner_font_size; new_text -> adjustment = adjustment; new_text -> layout = layout; /* If the text layout is "dotted pivot", record the number of the pivot seq */ if (layout == PIVOT_CODE) { if (pivot == UNDEFINED) { /* Pivot sequence given by name */ if ((findings = ALGN_Find_Sequence (pivot_sequence, ANY_LIST)) == NULL) return ERR_TEXT_PIVOT; if ((findings -> next != NULL) && (findings -> source_list == (findings -> next) -> source_list)) CONT_Error_Report (SYSTEM_ERROR, ERR_BAD_STRUCTURE, "Non-unique pivot (", pivot_sequence, UNDEFINED, ")", 0, FALSE); else { new_text -> pivot = (findings -> seq_num) - 1; while (findings != NULL) { old_find = findings; findings = findings -> next; free (old_find); } } } else new_text -> pivot = pivot - 1; } else new_text -> pivot = UNDEFINED; new_text -> trailer = trailer; new_text -> trailer_font = NTL0_strsave (trailer_font); new_text -> trailer_font_size = trailer_font_size; new_text -> started = started; new_text -> ended = ended; new_text -> next = NULL; /* Now find the place in the list of text records to insert the new text */ if (text_store == NULL) text_store = new_text; else if (text_store -> line_number > number) { new_text -> next = text_store; text_store = new_text; } else { text_scan = text_store; while ((text_scan -> next != NULL) && ((text_scan -> next) -> line_number < number)) text_scan = text_scan -> next; new_text -> next = text_scan -> next; text_scan -> next = new_text; } return 0; } /*****************************************************************************/ /* */ /* Procedure: RAWS_Execute */ /* */ int RAWS_Execute (void) { int check_status, source, index, ovr_code; long int offset, abs_start, abs_stop; bool valid; char *rep_string; seqover_ptr findings, current_finding; lstore_ptr current_landmark; landmarkll_ptr new_landmark; bstore_ptr current_box; boxll_ptr new_box; ustore_ptr current_underline; underll_ptr new_underline; tstore_ptr text_scan, trash_text; /* Traverse the list of landmarks, check for consistency in their specif. */ /* with respect to the known origins and convert all addresses to unique */ /* format (numbering within sequences, no origins), eliminating in the */ /* process these which originate from files (bulk), but do not overlap */ /* with the requested region, issue warnings for these not from files */ while (land_store != NULL) { current_landmark = land_store; land_store = land_store -> next; /* Check if everything is OK with the specified origin and species for l. */ if (!strcmp (current_landmark -> origin, "absolute")) { offset = 1; check_status = ORIGIN_OK; } else if (current_landmark -> sequence == NULL) { check_status = RAWS_Name_Origin (current_landmark -> origin, &(current_landmark -> sequence), &offset, &source); if ((check_status == ORIGIN_OK) && (current_landmark -> mark_seq == NULL)) current_landmark -> mark_seq = NTL0_strsave (current_landmark -> sequence); } else check_status = RAWS_Check_Origin (current_landmark -> origin, current_landmark -> sequence, &offset, &source); if (check_status == ORIGIN_OK) { valid = TRUE; if (offset + (current_landmark -> start) <= 0) { rep_string = (char *) NTL0_ckalloc ((62 + strlen (current_landmark -> origin)) * sizeof (char)); sprintf (rep_string, "Landmark (%s,%ld,%ld) starting out of the alignment", current_landmark -> origin, current_landmark -> start, current_landmark -> stop); if (current_landmark -> bulk) { CONT_Warning (rep_string); free (rep_string); valid = FALSE; } else CONT_Error_Report (FATAL_ERROR, ERR_BAD_VALUE, rep_string, NULL, UNDEFINED, NULL, 0, FALSE); } else if (current_landmark -> start < 0) abs_start = offset + (current_landmark -> start); else abs_start = offset + (current_landmark -> start) - 1; if (offset + (current_landmark -> stop) <= 0) { rep_string = (char *) NTL0_ckalloc ((60 + strlen (current_landmark -> origin)) * sizeof (char)); sprintf (rep_string, "Landmark (%s,%ld,%ld) ends out of the alignment", current_landmark -> origin, current_landmark -> start, current_landmark -> stop); if (current_landmark -> bulk) { CONT_Warning (rep_string); free (rep_string); valid = FALSE; } else CONT_Error_Report (FATAL_ERROR, ERR_BAD_VALUE, rep_string, NULL, UNDEFINED, NULL, 0, FALSE); } else if (current_landmark -> stop < 0) abs_stop = offset + (current_landmark -> stop); else abs_stop = offset + (current_landmark -> stop) - 1; if (valid) { if (current_landmark -> seqnum == 0) { /* Absolute addresses in algn. */ if ((abs_start <= 0) || (abs_stop <= 0)) CONT_Error_Report (FATAL_ERROR, ERR_BAD_VALUE, "Illegal absolute landmark boundary", NULL, UNDEFINED, NULL, 0, FALSE); abs_start -= start_trim; abs_stop -= start_trim; if (NTL0_overlaps (1, alignment_records -> size, abs_start, abs_stop)) { new_landmark = (landmarkll_ptr) NTL0_ckalloc (sizeof (LandmarkLL_Struct)); new_landmark -> sequence = UNDEFINED; if ((abs_start >= 1) && (abs_stop <= alignment_records -> size)) { new_landmark -> truncation = FULL_INCLUSION; new_landmark -> start = abs_start; new_landmark -> stop = abs_stop; } else if ((abs_start < 1) && (abs_stop > alignment_records -> size)) { if (!(current_landmark -> bulk)) { rep_string = (char *) (80 * sizeof (char)); sprintf (rep_string, "Absolute landmark [%ld,%ld] truncated to displayed segment", abs_start + start_trim, abs_stop + start_trim); } new_landmark -> truncation = TRUNC_BOTH_SIDES; new_landmark -> start = 1; new_landmark -> stop = alignment_records -> size; } else if (abs_start < 1) { if (!(current_landmark -> bulk)) { rep_string = (char *) (80 * sizeof (char)); sprintf (rep_string, "Absolute landmark [%ld,%ld] truncated from left", abs_start + start_trim, abs_stop + start_trim); } new_landmark -> truncation = START_TRUNCATED; new_landmark -> start = 1; new_landmark -> stop = abs_stop; } else if (abs_stop > alignment_records -> size) { if (!(current_landmark -> bulk)) { rep_string = (char *) (80 * sizeof (char)); sprintf (rep_string, "Absolute landmark [%ld,%ld] truncated from right", abs_start + start_trim, abs_stop + start_trim); } new_landmark -> truncation = END_TRUNCATED; new_landmark -> start = abs_start; new_landmark -> stop = alignment_records -> size; } else CONT_Error_Report (SYSTEM_ERROR, ERR_BAD_VALUE, "Illegaly determined overlap for abs landmark", NULL, UNDEFINED, NULL, 0, FALSE); new_landmark -> reference = NTL0_strsave (current_landmark -> reference); if (current_landmark -> mark_kind != BOX_CODE) { /* ### To be defined ############################################## */ fprintf (stderr, "Sorry, only boxes are permitted to annotate\n"); fprintf (stderr, " absolute landmarks at this time.\n"); exit (1); /* ### To be defined ############################################## */ } else { new_landmark -> mark_kind = current_landmark -> mark_kind; new_landmark -> mark_multiple = current_landmark -> mark_multiple; new_landmark -> mark_number = UNDEFINED; new_landmark -> mark_seq = NTL0_strsave (current_landmark -> mark_seq); new_landmark -> mark_style = NTL0_strsave (current_landmark -> mark_style); new_landmark -> mark_shade = current_landmark -> mark_shade; new_landmark -> mark_intensity = current_landmark -> mark_intensity; new_landmark -> label = NTL1_Copy_Label (current_landmark -> label); new_landmark -> label_place = current_landmark -> label_place; new_landmark -> label_position = current_landmark -> label_position; new_landmark -> next = established_landmarks; established_landmarks = new_landmark; } } else if (!(current_landmark -> bulk)) { rep_string = (char *) (80 * sizeof (char)); sprintf (rep_string, "Absolute landmark [%ld,%ld] out of displayed segment", abs_start + start_trim, abs_stop + start_trim); CONT_Warning (rep_string); free (rep_string); } } else { if (current_landmark -> seqnum != UNDEFINED) { if ((alignment_records -> segment_code) [(current_landmark -> seqnum) - 1] == VALID_SEGMENT) { if (NTL0_overlaps ( (alignment_records -> begin) [(current_landmark -> seqnum) - 1], (alignment_records -> end) [(current_landmark -> seqnum) - 1], abs_start, abs_stop)) { if ((alignment_records -> begin) [(current_landmark -> seqnum) - 1] > abs_start) { if ((alignment_records -> end) [(current_landmark -> seqnum) - 1] < abs_stop) ovr_code = TRUNC_BOTH_SIDES; else ovr_code = START_TRUNCATED; } else if ((alignment_records -> end) [(current_landmark -> seqnum) - 1] < abs_stop) ovr_code = END_TRUNCATED; else ovr_code = FULL_INCLUSION; } else ovr_code = UNDEFINED; } else ovr_code = UNDEFINED; if (ovr_code != UNDEFINED) { findings = (seqover_ptr) NTL0_ckalloc (sizeof (SeqOver_Struct)); findings -> source_list = UNDEFINED; findings -> seq_num = current_landmark -> seqnum; findings -> overlap = ovr_code; findings -> seq_begin = (alignment_records -> begin) [(current_landmark -> seqnum) - 1]; findings -> seq_end = (alignment_records -> end) [(current_landmark -> seqnum) - 1]; findings -> next = NULL; } else findings = NULL; } else findings = ALGN_Get_Sequence_In_Range (current_landmark -> sequence, abs_start, abs_stop, source); if (findings == NULL) { valid = FALSE; if (!(current_landmark -> bulk)) { rep_string = (char *) NTL0_ckalloc ((62 + strlen (current_landmark -> origin)) * sizeof (char)); sprintf (rep_string, "Landmark (%s,%ld,%ld) out of the represented range", current_landmark -> origin, current_landmark -> start, current_landmark -> stop); CONT_Warning (rep_string); free (rep_string); } } else { for (current_finding = findings; current_finding != NULL; current_finding = current_finding -> next) { new_landmark = (landmarkll_ptr) NTL0_ckalloc (sizeof (LandmarkLL_Struct)); new_landmark -> sequence = (current_finding -> seq_num) - 1; new_landmark -> truncation = current_finding -> overlap; if (current_finding -> overlap == FULL_INCLUSION) { new_landmark -> start = abs_start; new_landmark -> stop = abs_stop; } else if (current_finding -> overlap == START_TRUNCATED) { new_landmark -> start = current_finding -> seq_begin; new_landmark -> stop = abs_stop; } else if (current_finding -> overlap == END_TRUNCATED) { new_landmark -> start = abs_start; new_landmark -> stop = current_finding -> seq_end; } else if (current_finding -> overlap == TRUNC_BOTH_SIDES) { new_landmark -> start = current_finding -> seq_begin; new_landmark -> stop = current_finding -> seq_end; } else CONT_Error_Report (SYSTEM_ERROR, ERR_ILLEGAL_CODE, "Unknown code (", NULL, (long int) (current_finding -> overlap), ") for overlap with sequence", 0, FALSE); new_landmark -> reference = NTL0_strsave (current_landmark -> reference); new_landmark -> mark_kind = current_landmark -> mark_kind; new_landmark -> mark_multiple = current_landmark -> mark_multiple; if (current_landmark -> mark_seq != NULL) { if (strcmp (current_landmark -> sequence, current_landmark -> mark_seq)) { rep_string = (char *) NTL0_ckalloc ((50 + strlen (current_landmark -> sequence) + strlen (current_landmark -> mark_seq)) * sizeof (char)); sprintf (rep_string, "Landmark given in '%s', requested underline in '%s'", current_landmark -> sequence, current_landmark -> mark_seq); CONT_Warning (rep_string); free (rep_string); new_landmark -> mark_number = UNDEFINED; } else new_landmark -> mark_number = new_landmark -> sequence; new_landmark -> mark_seq = NTL0_strsave (current_landmark -> mark_seq); } else { new_landmark -> mark_number = new_landmark -> sequence; new_landmark -> mark_seq = NULL; } new_landmark -> mark_style = NTL0_strsave (current_landmark -> mark_style); new_landmark -> mark_shade = current_landmark -> mark_shade; new_landmark -> mark_intensity = current_landmark -> mark_intensity; new_landmark -> label = NTL1_Copy_Label (current_landmark -> label); new_landmark -> label_place = current_landmark -> label_place; new_landmark -> label_position = current_landmark -> label_position; new_landmark -> next = established_landmarks; established_landmarks = new_landmark; } } } } } else if (check_status == ORIGIN_AMBIGUOUS) { CONT_Error_Report (FATAL_ERROR, ERR_BAD_VALUE, "Ambigous origin specification (", current_landmark -> origin, UNDEFINED, ") for landmark", 0, FALSE); } else if (check_status == ORIGIN_MISSING) { if (current_landmark -> bulk) { if (current_landmark -> sequence != NULL) { rep_string = (char *) NTL0_ckalloc ((36 + strlen (current_landmark -> origin) + strlen (current_landmark -> sequence)) * sizeof (char)); sprintf (rep_string, "Unknown origin '%s' in sequence '%s'", current_landmark -> origin, current_landmark -> sequence); } else { rep_string = (char *) NTL0_ckalloc ((20 + strlen (current_landmark -> origin)) * sizeof (char)); sprintf (rep_string, "Unknown origin '%s'", current_landmark -> origin); } CONT_Warning (rep_string); free (rep_string); } else { /* Explicitely provided landmark in the specification file */ CONT_Error_Report (FATAL_ERROR, ERR_NO_VALUE, "Missing origin '", current_landmark -> origin, UNDEFINED, "' for landmark", 0, FALSE); } } else if (check_status == ORIGIN_WRONG_SEQUENCE) { rep_string = (char *) NTL0_ckalloc ((32 + strlen (current_landmark -> origin) + strlen (current_landmark -> sequence)) * sizeof (char)); sprintf (rep_string, "Origin '%s' not in sequence '%s'", current_landmark -> origin, current_landmark -> sequence); CONT_Error_Report (FATAL_ERROR, ERR_BAD_VALUE, rep_string, NULL, UNDEFINED, NULL, 0, FALSE); } if (current_landmark -> sequence != NULL) free (current_landmark -> sequence); if (current_landmark -> origin != NULL) free (current_landmark -> origin); if (current_landmark -> reference != NULL) free (current_landmark -> reference); if (current_landmark -> mark_seq != NULL) free (current_landmark -> mark_seq); if (current_landmark -> mark_style != NULL) free (current_landmark -> mark_style); if (current_landmark -> label != NULL) current_landmark -> label = NTL1_Destroy_Label (current_landmark -> label); free (current_landmark); } /* Check the consistency of the specification of boxes with respect to the */ /* known origins, copy them into global structures, and issue warnings */ /* for these out of the requested range */ while (box_store != NULL) { current_box = box_store; box_store = box_store -> next; /* Check if everything is OK with the specified origin and species for box */ if ((check_status = RAWS_Check_Origin (current_box -> origin, current_box -> sequence, &offset, &source)) == ORIGIN_OK) { if (offset + (current_box -> start) <= 0) { rep_string = (char *) NTL0_ckalloc ((58 + strlen (current_box -> origin)) * sizeof (char)); sprintf (rep_string, "Box (%s,%ld,%ld) starting out of the alignment", current_box -> origin, current_box -> start, current_box -> stop); CONT_Error_Report (FATAL_ERROR, ERR_BAD_VALUE, rep_string, NULL, UNDEFINED, NULL, 0, FALSE); } else if (current_box -> start < 0) abs_start = offset + (current_box -> start); else abs_start = offset + (current_box -> start) - 1; if (offset + (current_box -> stop) <= 0) { rep_string = (char *) NTL0_ckalloc ((56 + strlen (current_box -> origin)) * sizeof (char)); sprintf (rep_string, "Box (%s,%ld,%ld) ends out of the alignment", current_box -> origin, current_box -> start, current_box -> stop); CONT_Error_Report (FATAL_ERROR, ERR_BAD_VALUE, rep_string, NULL, UNDEFINED, NULL, 0, FALSE); } else if (current_box -> stop < 0) abs_stop = offset + (current_box -> stop); else abs_stop = offset + (current_box -> stop) - 1; if ((findings = ALGN_Get_Sequence_In_Range (current_box -> sequence, abs_start, abs_stop, source)) == NULL) { rep_string = (char *) NTL0_ckalloc ((58 + strlen (current_box -> origin)) * sizeof (char)); sprintf (rep_string, "Box (%s,%ld,%ld) out of the represented range", current_box -> origin, current_box -> start, current_box -> stop); CONT_Warning (rep_string); free (rep_string); } else { for (current_finding = findings; current_finding != NULL; current_finding = current_finding -> next) { new_box = (boxll_ptr) NTL0_ckalloc (sizeof (BoxLL_Struct)); new_box -> sequence = (current_finding -> seq_num) - 1; new_box -> truncation = current_finding -> overlap; if (current_finding -> overlap == FULL_INCLUSION) { new_box -> start = abs_start; new_box -> stop = abs_stop; } else if (current_finding -> overlap == START_TRUNCATED) { new_box -> start = current_finding -> seq_begin; new_box -> stop = abs_stop; } else if (current_finding -> overlap == END_TRUNCATED) { new_box -> start = abs_start; new_box -> stop = current_finding -> seq_end; } else if (current_finding -> overlap == TRUNC_BOTH_SIDES) { new_box -> start = current_finding -> seq_begin; new_box -> stop = current_finding -> seq_end; } else CONT_Error_Report (SYSTEM_ERROR, ERR_ILLEGAL_CODE, "Unknown code (", NULL, (long int) (current_finding -> overlap), ") for overlap with sequence", 0, FALSE); new_box -> style = NTL0_strsave (current_box -> style); new_box -> shade = current_box -> shade; new_box -> intensity = current_box -> intensity; new_box -> label = NTL1_Copy_Label (current_box -> label); new_box -> label_place = current_box -> label_place; new_box -> label_position = current_box -> label_position; new_box -> next = established_boxes; established_boxes = new_box; } } } else if (check_status == ORIGIN_AMBIGUOUS) { CONT_Error_Report (FATAL_ERROR, ERR_BAD_VALUE, "Ambigous origin specification (", current_box -> origin, UNDEFINED, ") for box", 0, FALSE); } else if (check_status == ORIGIN_MISSING) { CONT_Error_Report (FATAL_ERROR, ERR_NO_VALUE, "Missing origin '", current_box -> origin, UNDEFINED, "' for box", 0, FALSE); } else if (check_status == ORIGIN_WRONG_SEQUENCE) { rep_string = (char *) NTL0_ckalloc ((32 + strlen (current_box -> origin) + strlen (current_box -> sequence)) * sizeof (char)); sprintf (rep_string, "Origin '%s' not in sequence '%s'", current_box -> origin, current_box -> sequence); CONT_Error_Report (FATAL_ERROR, ERR_BAD_VALUE, rep_string, NULL, UNDEFINED, NULL, 0, FALSE); } if (current_box -> sequence != NULL) free (current_box -> sequence); if (current_box -> origin != NULL) free (current_box -> origin); if (current_box -> style != NULL) free (current_box -> style); if (current_box -> label != NULL) current_box -> label = NTL1_Destroy_Label (current_box -> label); free (current_box); } /* Check the consistency of the specification of underlines with respect to */ /* the known origins, copy them into global structures, and issue */ /* warnings for these out of the requested range */ while (under_store != NULL) { current_underline = under_store; under_store = under_store -> next; /* Check if everything is OK with specified origin & species for underline */ if ((check_status = RAWS_Check_Origin (current_underline -> origin, current_underline -> sequence, &offset, &source)) == ORIGIN_OK) { if (offset + (current_underline -> start) <= 0) { rep_string = (char *) NTL0_ckalloc ((66 + strlen (current_underline -> origin)) * sizeof (char)); sprintf (rep_string, "Underline (%s,%ld,%ld) starting out of the alignment", current_underline -> origin, current_underline -> start, current_underline -> stop); CONT_Error_Report (FATAL_ERROR, ERR_BAD_VALUE, rep_string, NULL, UNDEFINED, NULL, 0, FALSE); } else if (current_underline -> start < 0) abs_start = offset + (current_underline -> start); else abs_start = offset + (current_underline -> start) - 1; if (offset + (current_underline -> stop) <= 0) { rep_string = (char *) NTL0_ckalloc ((62 + strlen (current_underline -> origin)) * sizeof (char)); sprintf (rep_string, "Underline (%s,%ld,%ld) ends out of the alignment", current_underline -> origin, current_underline -> start, current_underline -> stop); CONT_Error_Report (FATAL_ERROR, ERR_BAD_VALUE, rep_string, NULL, UNDEFINED, NULL, 0, FALSE); } else if (current_underline -> stop < 0) abs_stop = offset + (current_underline -> stop); else abs_stop = offset + (current_underline -> stop) - 1; if ((findings = ALGN_Get_Sequence_In_Range (current_underline -> sequence, abs_start, abs_stop, source)) == NULL) { rep_string = (char *) NTL0_ckalloc ((66 + strlen (current_underline -> origin)) * sizeof (char)); sprintf (rep_string, "Underline (%s,%ld,%ld) out of the represented range", current_underline -> origin, current_underline -> start, current_underline -> stop); CONT_Warning (rep_string); free (rep_string); } else { for (current_finding = findings; current_finding != NULL; current_finding = current_finding -> next) { new_underline = (underll_ptr) NTL0_ckalloc (sizeof (UnderLL_Struct)); new_underline -> kind = current_underline -> kind; new_underline -> sequence = (current_finding -> seq_num) - 1; new_underline -> truncation = current_finding -> overlap; if (current_finding -> overlap == FULL_INCLUSION) { new_underline -> start = abs_start; new_underline -> stop = abs_stop; } else if (current_finding -> overlap == START_TRUNCATED) { new_underline -> start = current_finding -> seq_begin; new_underline -> stop = abs_stop; } else if (current_finding -> overlap == END_TRUNCATED) { new_underline -> start = abs_start; new_underline -> stop = current_finding -> seq_end; } else if (current_finding -> overlap == TRUNC_BOTH_SIDES) { new_underline -> start = current_finding -> seq_begin; new_underline -> stop = current_finding -> seq_end; } else CONT_Error_Report (SYSTEM_ERROR, ERR_ILLEGAL_CODE, "Unknown code (", NULL, (long int) (current_finding -> overlap), ") for overlap with sequence", 0, FALSE); new_underline -> style = NTL0_strsave (current_underline -> style); new_underline -> label = NTL1_Copy_Label (current_underline -> label); new_underline -> label_place = current_underline -> label_place; new_underline -> label_position = current_underline -> label_position; new_underline -> next = established_underlines; established_underlines = new_underline; } } } else if (check_status == ORIGIN_AMBIGUOUS) { CONT_Error_Report (FATAL_ERROR, ERR_BAD_VALUE, "Ambigous origin specification (", current_underline -> origin, UNDEFINED, ") for underline", 0, FALSE); } else if (check_status == ORIGIN_MISSING) { CONT_Error_Report (FATAL_ERROR, ERR_NO_VALUE, "Missing origin '", current_underline -> origin, UNDEFINED, "' for underline", 0, FALSE); } else if (check_status == ORIGIN_WRONG_SEQUENCE) { rep_string = (char *) NTL0_ckalloc ((32 + strlen (current_underline -> origin) + strlen (current_underline -> sequence)) * sizeof (char)); sprintf (rep_string, "Origin '%s' not in sequence '%s'", current_underline -> origin, current_underline -> sequence); CONT_Error_Report (FATAL_ERROR, ERR_BAD_VALUE, rep_string, NULL, UNDEFINED, NULL, 0, FALSE); } if (current_underline -> sequence != NULL) free (current_underline -> sequence); if (current_underline -> origin != NULL) free (current_underline -> origin); if (current_underline -> style != NULL) free (current_underline -> style); if (current_underline -> label != NULL) current_underline -> label = NTL1_Destroy_Label (current_underline -> label); free (current_underline); } /* Convert the temporary text line structures into globally known ones */ established_text_vector = (textll_ptr *) NTL0_ckalloc ((alignment_records -> dimension) * sizeof (textll_ptr)); text_scan = text_store; for (index = 0; index < alignment_records -> dimension; index++) { valid = FALSE; if (text_scan -> disabled) established_text_vector [index] = NULL; else if (((text_scan -> started == STARTED_CODE) && ((alignment_records -> segment_code) [index] == NOTYET_STARTED_SEGMENT)) || ((text_scan -> ended == ENDED_CODE) && ((alignment_records -> segment_code) [index] == ALREADY_ENDED_SEGMENT))) established_text_vector [index] = NULL; else { valid = TRUE; established_text_vector [index] = (textll_ptr) NTL0_ckalloc (sizeof (TextLL_Struct)); (established_text_vector [index]) -> banner = text_scan -> banner; (established_text_vector [index]) -> banner_font = text_scan -> banner_font; (established_text_vector [index]) -> banner_font_size = text_scan -> banner_font_size; (established_text_vector [index]) -> adjustment = text_scan -> adjustment; (established_text_vector [index]) -> layout = text_scan -> layout; (established_text_vector [index]) -> pivot = text_scan -> pivot; (established_text_vector [index]) -> trailer = text_scan -> trailer; (established_text_vector [index]) -> trailer_font = text_scan -> trailer_font; (established_text_vector [index]) -> trailer_font_size = text_scan -> trailer_font_size; (established_text_vector [index]) -> started = text_scan -> started; (established_text_vector [index]) -> ended = text_scan -> ended; (established_text_vector [index]) -> buffer = NULL; } trash_text = text_scan; text_scan = text_scan -> next; if (!valid) { if (trash_text -> banner_font != NULL) free (trash_text -> banner_font); if (trash_text -> trailer_font != NULL) free (trash_text -> trailer_font); } free (trash_text); } if (text_scan != NULL) CONT_Error_Report (SYSTEM_ERROR, ERR_BAD_VALUE, "Incorrect count of text lines", NULL, UNDEFINED, NULL, 0, FALSE); return PREP_Execute (); } /*****************************************************************************/ /* */ /* Procedure: RAWS_Check_Origin */ /* */ int RAWS_Check_Origin (char *origin, char *sequence, long int *offset, int *source) { bool origin_found, alias_found, alias_duplicate, seq_found, seq_duplicate; originll_ptr origin_scan, origin_location; strlist_ptr alias_scan; /* Check the list of origins looking into aliases first; check for duplict. */ origin_found = FALSE; alias_found = FALSE; alias_duplicate = FALSE; origin_scan = established_origins; while ((origin_scan != NULL) && ((!origin_found) || (!alias_found))) { if (origin_scan -> name != NULL) { if (!strcmp (origin_scan -> name, origin)) { origin_found = TRUE; alias_scan = origin_scan -> aliases; while ((alias_scan != NULL) && (!alias_found)) { if (!strcmp (alias_scan -> string, sequence)) alias_found = TRUE; else alias_scan = alias_scan -> next; } if (!alias_found) origin_scan = origin_scan -> next; } else origin_scan = origin_scan -> next; } else origin_scan = origin_scan -> next; } if (!origin_found) { *offset = UNDEFINED; *source = UNDEFINED; return ORIGIN_MISSING; } else if (alias_found) { origin_location = origin_scan; origin_scan = origin_scan -> next; while ((origin_scan != NULL) && (!alias_duplicate)) { if (origin_scan -> name != NULL) { if (!strcmp (origin_scan -> name, origin)) { alias_scan = origin_scan -> aliases; while ((alias_scan != NULL) && (!alias_found)) { if (!strcmp (alias_scan -> string, sequence)) alias_duplicate = TRUE; else alias_scan = alias_scan -> next; } } } origin_scan = origin_scan -> next; } if (alias_duplicate) { *offset = UNDEFINED; *source = ALIAS_LIST; return ORIGIN_AMBIGUOUS; } else { *offset = origin_location -> position; *source = ALIAS_LIST; return ORIGIN_OK; } } else { /* Origin found, but not an alias matching the sequence */ /* Check the sequence names and, again, check for duplicates */ origin_scan = established_origins; seq_found = FALSE; seq_duplicate = FALSE; while ((origin_scan != NULL) && (!seq_found)) { if (origin_scan -> name != NULL) { if ((!strcmp (origin_scan -> name, origin)) && (!strcmp (origin_scan -> sequence, sequence))) seq_found = TRUE; else origin_scan = origin_scan -> next; } else origin_scan = origin_scan -> next; } if (!seq_found) { *offset = UNDEFINED; *source = UNDEFINED; return ORIGIN_WRONG_SEQUENCE; } else { origin_location = origin_scan; origin_scan = origin_scan -> next; while ((origin_scan != NULL) && (!seq_duplicate)) { if (origin_scan -> name != NULL) { if ((!strcmp (origin_scan -> name, origin)) && (!strcmp (origin_scan -> sequence, sequence))) seq_duplicate = TRUE; else origin_scan = origin_scan -> next; } else origin_scan = origin_scan -> next; } if (seq_duplicate) { *offset = UNDEFINED; *source = FILE_LIST; return ORIGIN_AMBIGUOUS; } else { *offset = origin_location -> position; *source = FILE_LIST; return ORIGIN_OK; } } } } /*****************************************************************************/ /* */ /* Procedure: RAWS_Name_Origin */ /* */ int RAWS_Name_Origin (char *origin, char **sequence, long int *offset, int *source) { bool found, duplicate; originll_ptr scan, origin_location; /* Check the list of origins looking into aliases first; check for duplict. */ found = FALSE; scan = established_origins; while ((scan != NULL) && (!found)) { if (scan -> name != NULL) { if (!strcmp (scan -> name, origin)) found = TRUE; else scan = scan -> next; } else scan = scan -> next; } if (!found) { *sequence = NULL; *offset = UNDEFINED; *source = UNDEFINED; return ORIGIN_MISSING; } else { origin_location = scan; scan = scan -> next; duplicate = FALSE; while ((scan != NULL) && (!duplicate)) { if (scan -> name != NULL) { if (!strcmp (scan -> name, origin)) duplicate = TRUE; } scan = scan -> next; } if (duplicate) { *sequence = NTL0_strsave (origin_location -> sequence); *offset = UNDEFINED; *source = FILE_LIST; return ORIGIN_AMBIGUOUS; } else { *sequence = NTL0_strsave (origin_location -> sequence); *offset = origin_location -> position; *source = FILE_LIST; return ORIGIN_OK; } } }