/* Output from p2c 1.21alpha-07.Dec.93, the Pascal-to-C translator */ /* From input file "rep.p" */ #include /* rep: repeated sequences in two books Britta Singer and Lane Wyatt copyright (c) 1985 module libraries required: delman, delmods, auxmods, prgmods */ /* end of program */ /* begin module version */ #define version 1.75 /* of rep.p 1995 July 26 last major change: 1985 apr 26 date of origin: september 1983 */ /* end module version */ /* begin module describe.rep */ /* name rep: records repeats between sequences in two books synopsis rep(hlist: in, xbook: in, ybook: in, fout: out, pout: out, repp: in, output: out) files hlist: a list of helices for xbook and ybook generated by the program helix. xbook: a book from the delila system. ybook: a book from the delila system. fout: a file containing the following information about each repeated sequence that satisfies the criteria of repp: * the 5 prime ends of the two occurrences of the repeat. * rlength, length of the repeated sequence. * distance: if direct repeats, the number of bases from five prime end to five prime end of each repeat; if inverted repeats, the number of bases from three prime end to five prime end (i.e., pseudo-loop distance). in every case, the smallest possible distance is given. pout: a file containing information about palindromes (only filled when inverted repeats are found in related sequences, see below). repp: input parameter file, must contain 3 characters, one per line. this may be followed by 4 integers, one per line. * mode of repeat: d = direct repeat (xbook and ybook have opposite directions) i = inverted repeat (xbook and ybook are in the same direction) * the types of xbook and ybook used in helix program: u = unrelated (any two sequences - no distances are calculated) r = related (sequences derived from the same piece of dna. the coordinate numbering of both books must be the same in order to calculate distances.) * the energies of hlist reflect the composition of the repeat e = "energies" are to be reported n = no "energies" are to be reported * minimum number of bases in a repeat to be recorded. * maximum number of bases in a repeat to be recorded. * minimum distance between repeated sequences to be recorded. * maximum distance between repeated sequences to be recorded. output: messages to the user. description rep uses information generated by the helix program to record the occurrences of repeated sequences of dna. helices are interpreted as repeats, direct or inverted depending upon the input sequences. repeats that meet the criteria of minimum length and minimum and/or maximum distance between half repeats are reported in fout. palindromes are reported in pout. see also helix.p, matrix.p, keymat.p author Britta Singer and Lane Wyatt bugs 1. when xbook and ybook have sequence in common, hlist reports each "helix" twice. rep is able to eliminate duplicates only when xbook and ybook overlap completely. thus in cases of partial overlap, some repeats may be duplicated. 2. rep uses external coordinates to calculate distances and will bomb with complicated coordinates. */ /* end module describe.rep */ /* begin module rep.const */ #define headerlines 7 /* the number of lines of the header in hlist */ #define defdmin 0 /* default value for minimum distance between the five prime ends of the two repeated sequences */ #define defdmax LONG_MAX /* default value for maximum distance between the five prime ends of the two repeated sequences */ #define defminlength 3 /* default value for minimum length of repeated sequences */ #define defmaxlength LONG_MAX /* default value for maximum length of repeated sequences */ #define debugging true /* allows one to trace bugs in program */ #define prime '"' /* allows one to write five prime in symbols */ /* end module rep.const version = 1.63; (* of rep 1984 june 5 */ /* begin module book.const */ /* constants needed for book manipulations */ #define dnamax 3000 /* length of dna arrays */ #define namelength 20 /* maximum key name length */ #define linelength 80 /* maximum line readable in book */ /* end module book.const version = 'delmod 6.51 85 apr 17 tds/gds' */ /* begin module rep.type */ typedef struct prec { /* parameters from repp */ Char mode; /* type of repeat */ Char typbk; /* relation of books in hlist */ Char energy; /* indicates if energies (so-called) of repeats (helices) are to be recorded */ long minlength; /* minimum number of bases in repeat */ long maxlength; /* maximum number of bases in repeat */ long dmax; /* maximum distance between repeats */ long dmin; /* minimum distance between repeats */ } prec; /* prec */ typedef struct reprec { /* contains processed information about repeat */ long x5p; /* location of the first base in the first occurance of the repeated sequence */ long y5p; /* location of the first base in the second occurance of repeated sequence */ long rlength; /* number of bases in repeated sequence */ long distance; /* distance in bases between five prime ends of direct repeats or between the closest three prime and five prime ends of inverted repeats */ /* "energies" of helices from hlist */ double deltagee; /* reprec */ } reprec; /* end module rep.type version = 1.63; (* of rep 1984 june 5 */ /* begin module book.type */ /* types needed for book manipulations */ typedef long chset[5]; /* types defined in book definition */ typedef Char alpha[namelength]; /* this is not alfa */ /* name is a left justified string with blanks following the characters */ typedef struct name { alpha letters; /* zero means an unspecified structure */ char length; } name; typedef struct line { /* a line of characters */ Char letters[linelength]; char length; struct line *next; } line; typedef enum { plus, minus, dircomplement, dirhomologous } direction; typedef enum { linear, circular } configuration; typedef enum { on, off } state; typedef struct header { /* header of key */ name keynam; /* key name of structure */ line *fulnam; /* full name of structure */ /* note key */ line *note; } header; /* base types */ typedef enum { a, c, g, t } base; typedef short dnarange; /* p2c: rep.p, line 170: * Note: Field width for seq assumes enum base has 4 elements [105] */ typedef uchar seq[(dnamax + 3) / 4]; typedef struct dnastring { seq part; dnarange length; struct dnastring *next; } dnastring; typedef struct orgkey { /* organism key */ header hea; /* genetic map units */ line *mapunit; } orgkey; typedef struct chrkey { /* chromosome key */ header hea; double mapbeg; /* number of genetic map beginning */ /* number of genetic map ending */ double mapend; } chrkey; typedef struct piekey { /* piece key */ header hea; double mapbeg; /* genetic map beginning */ configuration coocon; /* configruation (circular/linear) */ direction coodir; /* direction (+/-) relative to genetic map */ long coobeg; /* beginning nucleotide */ long cooend; /* ending nucleotide */ configuration piecon; /* configruation (circular/linear) */ direction piedir; /* direction (+/-) relative to coordinates */ long piebeg; /* beginning nucleotide */ long pieend; /* ending nucleotide */ } piekey; typedef struct piece { piekey key; dnastring *dna; } piece; typedef struct reference { name pienam; /* name of piece referred to */ double mapbeg; /* genetic map beginning */ direction refdir; /* direction relative to coordinates */ long refbeg; /* beginning nucleotide */ long refend; /* ending nucleotide */ } reference; typedef struct genkey { /* gene key */ header hea; reference ref; } genkey; typedef struct trakey { /* transcript key */ header hea; reference ref; } trakey; typedef struct markey { /* marker key */ header hea; reference ref; state sta; line *phenotype; struct marker *next; } markey; typedef struct marker { markey key; dnastring *dna; } marker; /* end module book.type version = 'delmod 6.51 85 apr 17 tds/gds' */ /* begin module rep.var */ /* files for rep program */ Static _TEXT xbook; /* one book */ Static _TEXT ybook; /* the other book */ Static _TEXT hlist; /* a list of helices from program helix */ Static _TEXT fout; /* a list of repeated sequences */ Static _TEXT pout; /* a list of palindromes */ /* parameters for the program */ Static _TEXT repp; /* end module rep.var version = 1.63; (* of rep 1984 june 5 */ /* begin module book.var */ /* ************************************************************************ */ /* global variables needed for book manipulations */ /* free storage: */ Static line *freeline; /* unused lines */ Static dnastring *freedna; /* unused dnas */ Static boolean readnumber; /* whether to read a number from the notes, or to read in the notes */ Static long number; /* the number of the item just read */ Static boolean numbered; /* true when the item just read is numbered */ Static boolean skipunnum; Static jmp_buf _JL1; /* a control variable to allow skipping of un-numbered items in the book */ /* ************************************************************************ */ /* end module book.var version = 'delmod 6.51 85 apr 17 tds/gds' */ /* begin module package.primitive */ /* ************************************************************************ */ /* begin module halt */ Static Void halt() { /* stop the program. the procedure performs a goto to the end of the program. you must have a label: label 1; declared, and also the end of the program must have this label: 1: end. examples are in the module libraries. this is the only goto in the delila system. */ printf(" program halt.\n"); longjmp(_JL1, 1); } /* end module halt version = 'delmod 6.51 85 apr 17 tds/gds' */ /* begin module copyaline */ Static Void copyaline(fin, fout) _TEXT *fin, *fout; { /* copy a line from file fin to file fout */ while (!P_eoln(fin->f)) { putc(P_peek(fin->f), fout->f); getc(fin->f); } fscanf(fin->f, "%*[^\n]"); getc(fin->f); putc('\n', fout->f); } /* copyaline */ /* end module copyaline version = 'delmod 6.51 85 apr 17 tds/gds' */ /* begin module copylines */ Static long copylines(fin, fout, n) _TEXT *fin, *fout; long n; { /* copy n lines of file fin to file fout. the actual number of lines copied is returned. */ long index = 0; /* the current line number */ while (!BUFEOF(fin->f) && index < n) { copyaline(fin, fout); index++; } return index; } /* copylines */ /* end module copylines version = 'delmod 6.51 85 apr 17 tds/gds' */ /* ************************************************************************ */ /* end module package.primitive version = 'delmod 6.51 85 apr 17 tds/gds' */ /* begin module package.getpiece */ /* ************************************************************************ */ /* begin module package.brpiece */ /* ************************************************************************ */ /* begin module book.basis */ /* procedures needed for book manipulations */ /* get procedures should be used for all linked lists of records */ Static Void getline(l) line **l; { /* obtain a line from the free line list or by making a new one */ if (freeline != NULL) { *l = freeline; freeline = freeline->next; } else *l = (line *)Malloc(sizeof(line)); (*l)->length = 0; (*l)->next = NULL; } Static Void getdna(l) dnastring **l; { if (freedna != NULL) { *l = freedna; freedna = freedna->next; } else *l = (dnastring *)Malloc(sizeof(dnastring)); (*l)->length = 0; (*l)->next = NULL; } /* clear procedures should be called each time the records are no longer needed failure to do this may result in a stack overflow. */ Static Void clearline(l) line **l; { /* return a line to the free line list */ line *lptr; if (*l == NULL) return; lptr = *l; *l = (*l)->next; lptr->next = freeline; freeline = lptr; } Static Void cleardna(l) dnastring **l; { dnastring *lptr; if (*l == NULL) return; lptr = *l; *l = (*l)->next; lptr->next = freedna; freedna = lptr; } Static Void clearheader(h) header *h; { /* clear the header h (remove lines to free storage) */ clearline(&h->fulnam); while (h->note != NULL) clearline(&h->note); } Static Void clearpiece(p) piece **p; { /* clear the dna of the piece */ while ((*p)->dna != NULL) cleardna(&(*p)->dna); clearheader(&(*p)->key.hea); } Static base chartobase(ch) Char ch; { /* convert a character into a base */ base Result; switch (ch) { case 'a': Result = a; break; case 'c': Result = c; break; case 'g': Result = g; break; case 't': Result = t; break; } return Result; } Static Char basetochar(ba) base ba; { /* convert a base into a character */ Char Result; switch (ba) { case a: Result = 'a'; break; case c: Result = 'c'; break; case g: Result = 'g'; break; case t: Result = 't'; break; } return Result; } Static base complement(ba) base ba; { /* take the complement of ba */ base Result; switch (ba) { case a: Result = t; break; case c: Result = g; break; case g: Result = c; break; case t: Result = a; break; } return Result; } Static long pietoint(p, pie) long p; piece *pie; { /* p is a coordinate on the piece. we want to transform p into a number from 1 to n: an internal coordinate system for easy manipulation of piece coordinates */ long i; /* an intermediate value */ piekey *WITH; WITH = &pie->key; switch (WITH->piedir) { case plus: if (p >= WITH->piebeg) i = p - WITH->piebeg + 1; else i = p - WITH->coobeg + WITH->cooend - WITH->piebeg + 2; break; case minus: if (p <= WITH->piebeg) i = WITH->piebeg - p + 1; else i = WITH->cooend - p + WITH->piebeg - WITH->coobeg + 2; break; } return i; } Static long inttopie(i, pie) long i; piece *pie; { /* i is in the range 1 to some maximum. it is an internal coordinate system for the program. we want to do a coordinate transformation to obtain a value in the range of the piece called pie: i=1 corresponds to piebeg and i=its maximum corresponds to pieend */ long p; /* an intermediate value */ piekey *WITH; WITH = &pie->key; switch (WITH->piedir) { case plus: p = WITH->piebeg + i - 1; if (p > WITH->cooend) { if (WITH->coocon == circular) p += WITH->coobeg - WITH->cooend - 1; } break; case minus: p = WITH->piebeg - i + 1; if (p < WITH->coobeg) { if (WITH->coocon == circular) p += WITH->cooend - WITH->coobeg + 1; } break; } return p; } Static long piecelength(pie) piece *pie; { /* return the length of the dna in pie */ return (pietoint(pie->key.pieend, pie)); } /* end module book.basis version = 'delmod 6.51 85 apr 17 tds/gds' */ /* begin module book.getto */ Static Char getto(thefile, ch) _TEXT *thefile; long *ch; { /* search the file for a character in the first line which is a member of the set ch. */ Char achar = ' '; while ((!P_inset(achar, ch)) & (!BUFEOF(thefile->f))) { fscanf(thefile->f, "%c%*[^\n]", &achar); getc(thefile->f); if (achar == '\n') achar = ' '; } if (P_inset(achar, ch)) return achar; else return ' '; } /* end module book.getto version = 'delmod 6.51 85 apr 17 tds/gds' */ /* begin module book.skipstar */ Static Void skipstar(thefile) _TEXT *thefile; { /* skip start of line (or star = '*'). */ if (P_peek(thefile->f) != '*') { printf(" procedure skipstar: bad book\n"); printf(" \"*\" expected as first character on the line, but \"%c\" was found\n", P_peek(thefile->f)); halt(); } getc(thefile->f); /* skip the star */ if (P_peek(thefile->f) != ' ') { /* skip the blank */ printf(" procedure skipstar: bad book\n"); printf(" \"* \" expected on a line but \"*%c\" was found\n", P_peek(thefile->f)); halt(); } getc(thefile->f); } /* skipstar */ /* end module book.skipstar version = 'delmod 6.51 85 apr 17 tds/gds' */ /* begin module book.brreanum */ Static Void brreanum(thefile, reanum) _TEXT *thefile; double *reanum; { /* read a real number from the file */ skipstar(thefile); fscanf(thefile->f, "%lg%*[^\n]", reanum); getc(thefile->f); } /* end module book.brreanum version = 'delmod 6.51 85 apr 17 tds/gds' */ /* begin module book.brnumber */ Static Void brnumber(thefile, num) _TEXT *thefile; long *num; { /* read a number from the file */ skipstar(thefile); fscanf(thefile->f, "%ld%*[^\n]", num); getc(thefile->f); } /* end module book.brnumber version = 'delmod 6.51 85 apr 17 tds/gds' */ /* begin module book.brname */ Static Void brname(thefile, nam) _TEXT *thefile; name *nam; { /* read a name from the file */ long i; /* an index to the name */ Char c_; /* a character read */ skipstar(thefile); nam->length = 0; do { nam->length++; c_ = getc(thefile->f); if (c_ == '\n') c_ = ' '; nam->letters[nam->length - 1] = c_; } while (!(P_eoln(thefile->f) || nam->length >= namelength || nam->letters[nam->length - 1] == ' ')); if (nam->letters[nam->length - 1] == ' ') nam->length--; if (nam->length < namelength) { for (i = nam->length; i < namelength; i++) nam->letters[i] = ' '; } fscanf(thefile->f, "%*[^\n]"); getc(thefile->f); } /* brname */ /* end module book.brname version = 'delmod 6.51 85 apr 17 tds/gds' */ /* begin module book.brline */ Static Void brline(thefile, l) _TEXT *thefile; line **l; { /* read a line from the file */ long i = 0; long j; Char acharacter; long FORLIM; skipstar(thefile); while (!P_eoln(thefile->f)) { i++; acharacter = getc(thefile->f); if (acharacter == '\n') acharacter = ' '; (*l)->letters[i-1] = acharacter; } if (i < (*l)->length) { FORLIM = (*l)->length; for (j = i; j < FORLIM; j++) (*l)->letters[j] = ' '; } (*l)->length = i; (*l)->next = NULL; fscanf(thefile->f, "%*[^\n]"); getc(thefile->f); } /* end module book.brline version = 'delmod 6.51 85 apr 17 tds/gds' */ /* begin module book.brdirect */ Static Void brdirect(thefile, direct) _TEXT *thefile; direction *direct; { /* read a direction */ Char ch; skipstar(thefile); fscanf(thefile->f, "%c%*[^\n]", &ch); getc(thefile->f); if (ch == '\n') ch = ' '; if (ch == '+') *direct = plus; else *direct = minus; } /* end module book.brdirect version = 'delmod 6.51 85 apr 17 tds/gds' */ /* begin module book.brconfig */ Static Void brconfig(thefile, config) _TEXT *thefile; configuration *config; { /* read a configuration */ Char ch; skipstar(thefile); fscanf(thefile->f, "%c%*[^\n]", &ch); getc(thefile->f); if (ch == '\n') ch = ' '; if (ch == 'l') *config = linear; else *config = circular; } /* end module book.brconfig version = 'delmod 6.51 85 apr 17 tds/gds' */ /* begin module book.brnotenumber */ Static Void brnotenumber(thefile, note) _TEXT *thefile; line **note; { /* book note reading to obtain the number of the object. the procedure returns the value of the number as a global. (this is not such a good practice, but we are stuck with it for now.) */ *note = NULL; numbered = false; number = 0; /* force number to zero if there is no number at all */ /* the next character is n or * depending on whether there are notes */ if (P_peek(thefile->f) != 'n') return; fscanf(thefile->f, "%*[^\n]"); getc(thefile->f); if (P_peek(thefile->f) == 'n') { fscanf(thefile->f, "%*[^\n]"); getc(thefile->f); return; } skipstar(thefile); if (!P_eoln(thefile->f)) { if (P_peek(thefile->f) == '#') { numbered = true; getc(thefile->f); /* move past the number symbol */ fscanf(thefile->f, "%ld", &number); } } do { fscanf(thefile->f, "%*[^\n]"); getc(thefile->f); } while (P_peek(thefile->f) != 'n'); fscanf(thefile->f, "%*[^\n]"); getc(thefile->f); } /* brnotenumber */ /* end module book.brnotenumber version = 'delmod 6.51 85 apr 17 tds/gds' */ /* begin module book.brnote */ Static Void brnote(thefile, note) _TEXT *thefile; line **note; { /* read note key */ line *newnote; /* the new note */ line *previousnote; /* the last line of the notes */ *note = NULL; if (P_peek(thefile->f) != 'n') /* enter note */ return; fscanf(thefile->f, "%*[^\n]"); getc(thefile->f); if (P_peek(thefile->f) == 'n') { /* abort null note (n/n) */ fscanf(thefile->f, "%*[^\n]"); getc(thefile->f); return; } getline(note); newnote = *note; while (P_peek(thefile->f) != 'n') { /* wait until end of note */ brline(thefile, &newnote); previousnote = newnote; /* get next note */ getline(&newnote->next); newnote = newnote->next; } /* last note was not used, so: */ clearline(&newnote); previousnote->next = NULL; fscanf(thefile->f, "%*[^\n]"); getc(thefile->f); } /* brnote */ /* end module book.brnote version = 'delmod 6.51 85 apr 17 tds/gds' */ /* begin module book.brheader */ Static Void brheader(thefile, hea) _TEXT *thefile; header *hea; { /* read the header of a key. */ /* read key name */ brname(thefile, &hea->keynam); /* read full name */ getline(&hea->fulnam); brline(thefile, &hea->fulnam); /* read note key */ if (readnumber) brnotenumber(thefile, &hea->note); else brnote(thefile, &hea->note); } /* end module book.brheader version = 'delmod 6.51 85 apr 17 tds/gds' */ /* begin module book.brpiekey */ Static Void brpiekey(thefile, pie) _TEXT *thefile; piekey *pie; { /* read piece key */ brheader(thefile, &pie->hea); brreanum(thefile, &pie->mapbeg); brconfig(thefile, &pie->coocon); brdirect(thefile, &pie->coodir); brnumber(thefile, &pie->coobeg); brnumber(thefile, &pie->cooend); brconfig(thefile, &pie->piecon); brdirect(thefile, &pie->piedir); brnumber(thefile, &pie->piebeg); brnumber(thefile, &pie->pieend); } /* end module book.brpiekey version = 'delmod 6.51 85 apr 17 tds/gds' */ /* begin module book.brdna */ Static Void brdna(thefile, dna) _TEXT *thefile; dnastring **dna; { /* read in dna from thefile */ /* note: if the dna were circularized, by linking the last dnastring to the first, then the cleardna routine could not clear properly, and would loop forever... there is no reason to do that, since a simple mod function will allow one to access the circle. */ Char ch; dnastring *workdna; long SET[5]; long TEMP; getdna(dna); workdna = *dna; ch = getto(thefile, P_addset(P_expset(SET, 0L), 'd')); ch = getc(thefile->f); /* skipstar */ if (ch == '\n') ch = ' '; while (ch == '*') { ch = getc(thefile->f); /* skip blank */ if (ch == '\n') ch = ' '; do { ch = getc(thefile->f); if (ch == '\n') ch = ' '; if (ch == 't' || ch == 'g' || ch == 'c' || ch == 'a') { if (workdna->length == dnamax) { getdna(&workdna->next); workdna = workdna->next; } workdna->length++; TEMP = workdna->length - 1; P_clrbits_B(workdna->part, TEMP, 1, 3); P_putbits_UB(workdna->part, TEMP, (int)chartobase(ch), 1, 3); } } while (!P_eoln(thefile->f)); fscanf(thefile->f, "%*[^\n]"); getc(thefile->f); /* go to next line */ ch = getc(thefile->f); /* ch is either '*' or 'd' */ if (ch == '\n') ch = ' '; } fscanf(thefile->f, "%*[^\n]"); getc(thefile->f); } /* end module book.brdna version = 'delmod 6.51 85 apr 17 tds/gds' */ /* begin module book.brpiece */ Static Void brpiece(thefile, pie) _TEXT *thefile; piece **pie; { /* read in a piece */ brpiekey(thefile, &(*pie)->key); if (numbered || !skipunnum) brdna(thefile, &(*pie)->dna); } /* end module book.brpiece version = 'delmod 6.51 85 apr 17 tds/gds' */ /* begin module book.brinit */ Static Void brinit(book) _TEXT *book; { /* check that the book is ok to read, and set up the global variables for br routines */ /* halt if the book is bad (first word is 'halt') or the first character is not * */ if (*book->name != '\0') { if (book->f != NULL) book->f = freopen(book->name, "r", book->f); else book->f = fopen(book->name, "r"); } else rewind(book->f); if (book->f == NULL) _EscIO2(FileNotFound, book->name); RESETBUF(book->f, Char); if (!BUFEOF(book->f)) { /* check for the date line */ if (P_peek(book->f) != '*') { if (P_peek(book->f) != 'h') printf(" this is not the first line of a book:\n"); else printf(" bad book:\n"); putchar(' '); while (!(P_eoln(book->f) | BUFEOF(book->f))) { putchar(P_peek(book->f)); getc(book->f); } putchar('\n'); halt(); } } else { printf(" book is empty\n"); halt(); } /* initialize free storage */ freeline = NULL; freedna = NULL; readnumber = true; /* usually we read in numbers for items */ number = 0; /* arbitrary value */ numbered = false; /* the piece has no number (none yet read in) */ skipunnum = false; } /* brinit */ /* end module book.brinit version = 'delmod 6.51 85 apr 17 tds/gds' */ /* ************************************************************************ */ /* end module package.brpiece version = 'delmod 6.51 85 apr 17 tds/gds' */ /* begin module book.getpiece */ Static Void getpiece(thefile, pie) _TEXT *thefile; piece **pie; { /* move to and read in the next piece in the book */ Char ch; long SET[5]; ch = getto(thefile, P_addset(P_expset(SET, 0L), 'p')); /* get to the next p(iece) in the book */ if (ch != ' ') { brpiece(thefile, pie); ch = getto(thefile, P_addset(P_expset(SET, 0L), 'p')); /* read past closing p */ } } Local Void die() { printf(" no helix list data\n"); halt(); } /* end module book.getpiece version = 'delmod 6.51 85 apr 17 tds/gds' */ /* ************************************************************************ */ /* end module package.getpiece version = 'delmod 6.51 85 apr 17 tds/gds' */ /* begin module findcolon */ Static Void findcolon(thefile) _TEXT *thefile; { /* move the file to the characters just past ': ' (colon, space) */ boolean found = false; while (!found) { if (BUFEOF(thefile->f)) { die(); continue; } if (P_peek(thefile->f) != ':') { getc(thefile->f); continue; } getc(thefile->f); if (BUFEOF(thefile->f)) die(); else if (P_peek(thefile->f) == ' ') { getc(thefile->f); found = true; } } } /* end module findcolon version = 'auxmod 1.37 85 apr 4 gds/tds'; */ /* begin module gethelix */ Static Void gethelix(hlist, x, y, length, getenergy, energy, done) _TEXT *hlist; long *x, *y, *length; boolean getenergy; double *energy; boolean *done; { /* get the (x,y,length) info on some helix listed in hlist. if the x,y pair changes, then done is true and no values are returned. checknames may be used at this point to start the next pair. if getenergy is true, then the routine expects that there will be an energy on the helix line */ if (BUFEOF(hlist->f)) { *done = true; return; } getc(hlist->f); /* skip the blank */ if (P_peek(hlist->f) != ' ') { *done = true; return; } *done = false; findcolon(hlist); fscanf(hlist->f, "%ld", x); findcolon(hlist); fscanf(hlist->f, "%ld", y); findcolon(hlist); fscanf(hlist->f, "%ld", length); if (getenergy) fscanf(hlist->f, "%lg", energy); else *energy = 0.0; fscanf(hlist->f, "%*[^\n]"); getc(hlist->f); } /* gethelix */ /* end module gethelix version = 'auxmod 1.37 85 apr 4 gds/tds'; */ /* begin module rep.initbook */ Static Void initbook(xbook, ybook, xseq, yseq) _TEXT *xbook, *ybook; piece **xseq, **yseq; { /* two delila books */ /* pointers for pieces in the books */ /* initialize the books and the pointers for pieces */ brinit(xbook); brinit(ybook); *xseq = (piece *)Malloc(sizeof(piece)); *yseq = (piece *)Malloc(sizeof(piece)); } /* initbook */ /* end module rep.initbook version = 1.63; (* of rep 1984 june 5 */ /* begin module complines */ Static boolean complines(a_, b) _TEXT *a_, *b; { /* compare one line from each of files a and b starting at the current file positions. both lines are compared up to and including the end-of-line mark (i.e., they are both readln-ed). return true if the lines are identical and false if they are not. ignore trailing blanks. this is done by letting chara or charb assume the value of a blank when eoln is true. when both lines are eoln, the next line is inspected. if one line is at end-of-file and the other is not, 'false' is returned. if both lines are at eof, 'true' is returned. */ boolean Result; Char chara, charb; /* characters in files a and b */ boolean done = false; /* stop looking for identity */ if (BUFEOF(a_->f) & BUFEOF(b->f)) return true; if (BUFEOF(a_->f) | BUFEOF(b->f)) return false; while (!done) { if (P_eoln(a_->f)) chara = ' '; else { chara = getc(a_->f); if (chara == '\n') chara = ' '; } if (P_eoln(b->f)) charb = ' '; else { charb = getc(b->f); if (charb == '\n') charb = ' '; } if (P_eoln(a_->f) & P_eoln(b->f)) { done = true; Result = true; } else if (chara != charb) { done = true; Result = false; } } fscanf(a_->f, "%*[^\n]"); getc(a_->f); fscanf(b->f, "%*[^\n]"); getc(b->f); /* neither file is eof. */ return Result; } /* complines */ Local Void gettitleline(xbook, ybook, hlist) _TEXT *xbook, *ybook, *hlist; { /* gets to the lines in the xbook, ybook, and hlist input files that contain the titles and thus are to be compared */ if (*xbook->name != '\0') { if (xbook->f != NULL) xbook->f = freopen(xbook->name, "r", xbook->f); else xbook->f = fopen(xbook->name, "r"); } else rewind(xbook->f); if (xbook->f == NULL) _EscIO2(FileNotFound, xbook->name); RESETBUF(xbook->f, Char); if (*ybook->name != '\0') { if (ybook->f != NULL) ybook->f = freopen(ybook->name, "r", ybook->f); else ybook->f = fopen(ybook->name, "r"); } else rewind(ybook->f); if (ybook->f == NULL) _EscIO2(FileNotFound, ybook->name); RESETBUF(ybook->f, Char); if (*hlist->name != '\0') { if (hlist->f != NULL) hlist->f = freopen(hlist->name, "r", hlist->f); else hlist->f = fopen(hlist->name, "r"); } else rewind(hlist->f); if (hlist->f == NULL) _EscIO2(FileNotFound, hlist->name); RESETBUF(hlist->f, Char); fscanf(hlist->f, "%*[^\n]"); getc(hlist->f); } /* gettitleline */ Local Void findtitle(hlist) _TEXT *hlist; { /* places the cursor at the beginning of the title in hlist */ long n; /* counter for skipping characters */ for (n = 1; n <= 4; n++) getc(hlist->f); } /* findtitle */ /* end module complines version = 'prgmod 3.96 85 mar 18 tds'; */ /* begin module hlistvsbooks */ Static Void hlistvsbooks(hlist, xbook, ybook) _TEXT *hlist, *xbook, *ybook; { /* list of helices from helix */ /* the delila books */ /* checks the title line in xbook with the corresponding line in hlist, ditto ybook. if they are not identical, error messages are sent to output and the program halts. written by britta singer */ boolean xasx; /* true if xbook input file corresponds to xbook in hlist */ boolean yasy; /* true if ybook input file corresponds to ybook in hlist */ boolean xasy; /* true if xbook input file corresponds to ybook in hlist */ boolean yasx; /* true if ybook input file corresponds to xbook in hlist */ gettitleline(xbook, ybook, hlist); findtitle(hlist); xasx = complines(xbook, hlist); findtitle(hlist); yasy = complines(ybook, hlist); gettitleline(xbook, ybook, hlist); findtitle(hlist); yasx = complines(ybook, hlist); findtitle(hlist); xasy = complines(xbook, hlist); if (!xasx) printf(" xbook input file does not correspond to xbook in hlist.\n"); if (!yasy) printf(" ybook input file does not correspond to ybook in hlist.\n"); if (xasy && !xasx) printf(" xbook input file corresponds to ybook in hlist.\n"); if (yasx && !yasy) printf(" ybook input file corresponds to xbook in hlist.\n"); if (xasy && yasx && !xasx && !yasy) printf(" xbook and ybook input files are reversed. try again.\n"); if (!(xasx && yasy)) halt(); } /* hlistvsbooks */ /* end module hlistvsbooks version = 'auxmod 1.37 85 apr 4 gds/tds'; */ /* begin module rep.readparameters */ Static Void readparameters(repp, para) _TEXT *repp; prec *para; { /* parameter file */ /* parameters from repp */ /* read in parameters, set default values */ if (*repp->name != '\0') { if (repp->f != NULL) repp->f = freopen(repp->name, "r", repp->f); else repp->f = fopen(repp->name, "r"); } else rewind(repp->f); if (repp->f == NULL) _EscIO2(FileNotFound, repp->name); RESETBUF(repp->f, Char); if (BUFEOF(repp->f)) { /* is repp file empty */ printf(" the repp input file is empty.\n"); halt(); } fscanf(repp->f, "%c%*[^\n]", ¶->mode); getc(repp->f); /* type of repeat */ if (para->mode == '\n') para->mode = ' '; if (para->mode != 'd' && para->mode != 'i') { /* direct or inverted */ printf(" the mode parameter in repp should be d(irect) or i(nverted)\n"); halt(); } fscanf(repp->f, "%c%*[^\n]", ¶->typbk); getc(repp->f); /* relation of xbook to ybook in hlist */ if (para->typbk == '\n') para->typbk = ' '; if (para->typbk != 'r' && para->typbk != 'u') { /* related or unrelated */ printf(" type of book parameter in repp should be r(elated) or u(nrelated)\n"); halt(); } fscanf(repp->f, "%c%*[^\n]", ¶->energy); getc(repp->f); /* will energies be recorded in fout? */ if (para->energy == '\n') para->energy = ' '; if (para->energy != 'e' && para->energy != 'n') { /* energies reported */ printf(" the third line of repp should have\n"); printf(" e(nergies reported) or n(o energies reported)\n"); halt(); } /* read minimum helix length, maximum length, minimum distance, and maximum distance if specified by repp. otherwise, assign default values. */ if (BUFEOF(repp->f)) para->minlength = defminlength; else { fscanf(repp->f, "%ld%*[^\n]", ¶->minlength); getc(repp->f); } if (BUFEOF(repp->f)) para->maxlength = defmaxlength; else { fscanf(repp->f, "%ld%*[^\n]", ¶->maxlength); getc(repp->f); } if (BUFEOF(repp->f)) para->dmin = defdmin; else { fscanf(repp->f, "%ld%*[^\n]", ¶->dmin); getc(repp->f); } if (BUFEOF(repp->f)) para->dmax = defdmax; else { fscanf(repp->f, "%ld%*[^\n]", ¶->dmax); getc(repp->f); } } /* readparameters */ /* end module rep.readparameters version = 1.63; (* of rep 1984 june 5 */ /* begin module rep.checkhlistparams */ Static Void checkhlistparams(hlist, para, getenergy) _TEXT *hlist; prec *para; boolean *getenergy; { /* list of helices from helix */ /* parameters from repp */ /* will energies be recorded? */ /* skips text in header of helix program until it gets to the minimum length. reads in minlength, compares it to the desired minimum length from repp, keeps the larger. it evaluates whether gu pairs are allowed and if energies are called for by repp. it returns a value for getenergy for use in gethelix. */ long i; /* loop control variable */ long helminlength; /* minimum length of repeat from helix program */ Char blank; /* for skipping the blank at the beginning of the line */ Char gupairs; /* 'g' if gu pairs are allowed in hlist */ Char energycalculated; /* were energies calculated in hlist? */ if (*hlist->name != '\0') { if (hlist->f != NULL) hlist->f = freopen(hlist->name, "r", hlist->f); else hlist->f = fopen(hlist->name, "r"); } else rewind(hlist->f); if (hlist->f == NULL) _EscIO2(FileNotFound, hlist->name); RESETBUF(hlist->f, Char); for (i = 1; i <= 3; i++) { fscanf(hlist->f, "%*[^\n]"); getc(hlist->f); } fscanf(hlist->f, "%ld", &helminlength); if (helminlength > para->minlength) { printf(" the minimum length in repp is less than in hlist\n"); printf(" program will continue with minlength equal to the\n"); printf(" minimum length from the helix program.\n"); para->minlength = helminlength; } fscanf(hlist->f, "%*[^\n]"); getc(hlist->f); blank = getc(hlist->f); if (blank == '\n') blank = ' '; gupairs = getc(hlist->f); if (gupairs == '\n') gupairs = ' '; if (gupairs == 'g') { if (para->mode == 'i') { printf(" gu pairs are allowed in hlist.\n"); printf(" is that what you intended?\n"); printf(" the program will run even if that is not what you wanted. \n"); } else { printf(" your hlist has gu pairs. analysis of direct\n"); printf(" repeats cannot use an hlist that allows gupairs.\n"); /* this is because the helices do not necessarily come in pairs when gu pairs are allowed, because of the asymmetry of the gu pair. that is, g in one strand can form a gu pair, but c in the complement cannot. */ halt(); } } fscanf(hlist->f, "%*[^\n]"); getc(hlist->f); blank = getc(hlist->f); if (blank == '\n') blank = ' '; energycalculated = getc(hlist->f); if (energycalculated == '\n') energycalculated = ' '; if (energycalculated == 'e' && para->energy == 'e') *getenergy = true; else *getenergy = false; fscanf(hlist->f, "%*[^\n]"); getc(hlist->f); } /* end module rep.checkhlistparams version = 1.63; (* of rep 1984 june 5 */ /* begin module rep.foutheading */ Static Void foutheading(hlist, fout, getenergy, para) _TEXT *hlist, *fout; boolean *getenergy; prec *para; { /* a list of helices from helix */ /* output file*/ /* true if 'energies' will be reported */ /* parameters from repp */ /* heading for fout file that contains repeat information */ long line_; /* loop control variable */ if (*fout->name != '\0') { if (fout->f != NULL) fout->f = freopen(fout->name, "w", fout->f); else fout->f = fopen(fout->name, "w"); } else { if (fout->f != NULL) rewind(fout->f); else fout->f = tmpfile(); } if (fout->f == NULL) _EscIO2(FileNotFound, fout->name); SETUPBUF(fout->f, Char); if (*hlist->name != '\0') { if (hlist->f != NULL) hlist->f = freopen(hlist->name, "r", hlist->f); else hlist->f = fopen(hlist->name, "r"); } else rewind(hlist->f); if (hlist->f == NULL) _EscIO2(FileNotFound, hlist->name); RESETBUF(hlist->f, Char); fprintf(fout->f, " rep %4.2f\n", version); for (line_ = 1; line_ <= headerlines; line_++) { putc(' ', fout->f); copyaline(hlist, fout); } switch (para->mode) { case 'i': fprintf(fout->f, " i : mode, inverted repeats found\n"); break; case 'd': fprintf(fout->f, " d : mode, direct repeats found\n"); break; } switch (para->typbk) { case 'u': fprintf(fout->f, " u : xbook and ybook are unrelated\n"); break; case 'r': fprintf(fout->f, " r : xbook and ybook are related\n"); break; } switch (para->energy) { case 'e': if (*getenergy) fprintf(fout->f, " e : \"energies\" reported in fout\n"); else fprintf(fout->f, " \"energies\" requested but not available from hlist\n"); break; case 'n': fprintf(fout->f, " n : no \"energies\" reported in fout\n"); break; } fprintf(fout->f, " %3ld = minimum repeat length\n", para->minlength); fprintf(fout->f, " %3ld = maximum repeat length\n", para->maxlength); fprintf(fout->f, " %3ld = minimum distance between repeats\n", para->dmin); fprintf(fout->f, " %3ld = maximum distance between repeats\n\n", para->dmax); } /* foutheading */ /* end module rep.foutheading version = 1.63; (* of rep 1984 june 5 */ /* begin module rep.poutheading */ Static Void poutheading(hlist, pout, getenergy, para) _TEXT *hlist, *pout; boolean *getenergy; prec *para; { /* a list of helices from helix */ /* output file*/ /* true if 'energies' will be reported */ /* parameters from repp */ /* heading for pout file that contains palindrome information */ long line_; /* loop control variable */ if (*pout->name != '\0') { if (pout->f != NULL) pout->f = freopen(pout->name, "w", pout->f); else pout->f = fopen(pout->name, "w"); } else { if (pout->f != NULL) rewind(pout->f); else pout->f = tmpfile(); } if (pout->f == NULL) _EscIO2(FileNotFound, pout->name); SETUPBUF(pout->f, Char); if (*hlist->name != '\0') { if (hlist->f != NULL) hlist->f = freopen(hlist->name, "r", hlist->f); else hlist->f = fopen(hlist->name, "r"); } else rewind(hlist->f); if (hlist->f == NULL) _EscIO2(FileNotFound, hlist->name); RESETBUF(hlist->f, Char); fprintf(pout->f, " rep %4.2f\n", version); for (line_ = 1; line_ <= headerlines; line_++) { putc(' ', pout->f); copyaline(hlist, pout); } switch (para->energy) { case 'e': if (*getenergy) fprintf(pout->f, " e: \"energies\" reported in pout\n"); else fprintf(pout->f, " \"energies\" requested but not available from hlist\n"); break; case 'n': fprintf(pout->f, " n: no \"energies\" reported in pout\n"); break; } fprintf(pout->f, "\n %3ld = minimum palindrome length\n", para->minlength); fprintf(pout->f, " %3ld = maximum palindrome length\n\n", para->maxlength); fprintf(pout->f, " note that the half-repeat length of a palindrome\n"); fprintf(pout->f, " is half that of an inverted repeat. thus if the\n"); fprintf(pout->f, " minimum repeat length is 4, agct will be reported\n"); fprintf(pout->f, " in pout but agnnnct will not be reported in fout\n\n"); } /* poutheading */ /* end module rep.poutheading version = 1.63; (* of rep 1984 june 5 */ /* begin module rep.checkseqdata */ Static Void checkseqdata(para, xseq, yseq, fout) prec para; piece *xseq, *yseq; _TEXT *fout; { /* parameters from repp */ /* for getting information */ /* about coordinates in xbook and ybook */ /* output file */ /* checks to make sure that the book coordinates are consistent with */ /* the parameters designated by the user in repp */ if (para.typbk == 'r' && (xseq->key.mapbeg != yseq->key.mapbeg || xseq->key.coocon != yseq->key.coocon || xseq->key.coodir != yseq->key.coodir || xseq->key.coobeg != yseq->key.coobeg || xseq->key.cooend != yseq->key.cooend)) { printf(" book coordinates indicate that xbook and ybook\n"); printf(" do not meet the criteria of relatedness,\n"); printf(" although the parameter file calls\n"); printf(" for them to be treated as related.\n"); printf(" please see the explanation of\n"); printf(" *related* in delman.describe.rep.\n"); halt(); } if (para.typbk == 'r' && para.mode == 'i' && xseq->key.piedir != yseq->key.piedir) { printf(" analysis of inverted repeats with\n"); printf(" rep requires that the books have the \n"); printf(" same orientation\n"); halt(); } if (para.typbk == 'r' && para.mode == 'd' && xseq->key.piedir == yseq->key.piedir) { printf(" analysis of direct repeats with rep\n"); printf(" requires that the books have opposite\n"); printf(" directions.\n"); halt(); } /* note below that when the books are not related, the user is */ /* allowed latitude in assignment of parameters. that is because */ /* when the books are unrelated, the parameter 'i' vs 'd' is essentially */ /* meaningless. the warning is to alert the user to the possibility */ /* that the file fout may contain something other than what was */ /* intended. */ if (para.typbk == 'u' && para.mode == 'd' && xseq->key.piedir == yseq->key.piedir) { printf(" generally speaking, analysis of direct repeats\n"); printf(" requires that xbook and ybook have\n"); printf(" different directions. here xbook and\n"); printf(" ybook have the same direction. are you\n"); printf(" sure that no mistake has been made?\n"); printf(" the program continues, but caution is urged\n"); fprintf(fout->f, " * * * warning * * * \n\n"); fprintf(fout->f, " generally speaking, analysis of direct repeats\n"); fprintf(fout->f, " requires that xbook and ybook have\n"); fprintf(fout->f, " different directions. here xbook and\n"); fprintf(fout->f, " ybook have the same direction. are you\n"); fprintf(fout->f, " sure that no mistake has been made?\n"); fprintf(fout->f, " the program continues, but caution is urged\n\n"); fprintf(fout->f, " note also: this warning adds an additional\n"); fprintf(fout->f, " 19 lines of text to the body of the file fout\n"); fprintf(fout->f, " from the program rep. should you wish to\n"); fprintf(fout->f, " use a fout file that contains this warning\n"); fprintf(fout->f, " as input for a program designed to use as input\n"); fprintf(fout->f, " the standard fout file from program rep,\n"); fprintf(fout->f, " it may be necessary first to delete 19 lines\n"); fprintf(fout->f, " beginning with * * * warning * * *\n\n\n"); } if (para.typbk != 'u' || para.mode != 'i' || xseq->key.piedir == yseq->key.piedir) return; printf(" generally speaking, analysis of inverted \n"); printf(" repeats requires that xbook and ybook have the\n"); printf(" same direction. here xbook and ybook have \n"); printf(" different directions. are you sure that no \n"); printf(" mistake has been made? the program continues,\n"); printf(" but caution is urged.\n"); fprintf(fout->f, " * * * warning * * * \n\n"); fprintf(fout->f, " generally speaking, analysis of inverted \n"); fprintf(fout->f, " repeats requires that xbook and ybook have the \n"); fprintf(fout->f, " same direction. here xbook and ybook have \n"); fprintf(fout->f, " different directions. are you sure that no \n"); fprintf(fout->f, " mistake has been made? the program continues,\n"); fprintf(fout->f, " but caution is urged.\n\n"); fprintf(fout->f, " note also: this warning adds an additional\n"); fprintf(fout->f, " 19 lines of text to the body of the file fout\n"); fprintf(fout->f, " from the program rep. should you wish to\n"); fprintf(fout->f, " use a fout file that contains this warning\n"); fprintf(fout->f, " as input for a program designed to use as input\n"); fprintf(fout->f, " the standard fout file from program rep,\n"); fprintf(fout->f, " it may be necessary first to delete 19 lines\n"); fprintf(fout->f, " beginning with * * * warning * * *\n\n\n"); } /* checkseqdata */ /* end module rep.checkseqdata version = 1.63; (* of rep 1984 june 5 */ /* begin module rep.anarep */ Static Void anarep(para, xseq, yseq, length, energy, coextensive, xout, yout, rout, palindrome, finished) prec para; piece *xseq, *yseq; long length; double energy; boolean coextensive; long *xout, *yout; reprec *rout; boolean *palindrome, *finished; { /* input parameters */ /* info about coordinates, etc. */ /* length of the repeat */ /* "energy" from hlist */ /*do the sequences overlap completely?*/ /* 5 prime external coordinates */ /* record of repeat information */ /* is the "repeat" a palindrome? */ /* is the repeat to be discarded? */ /* this procedure corrects xout or yout, if necessary. it calculates the distance between half repeats and recognizes palindromes. it throws out duplicates only when the two sequences examined overlap completely. it returns finished as true if the repeat does not meet the criteria of repp. */ long dist; /* distance between repeats */ long cirdist; /* if the sequence is circular, this is the distance going around the circle the other way. */ *palindrome = false; *finished = false; /* the next statement adjusts xout or yout: for direct repeats, one of the books must be in the minus direction. thus what is generally thought of as the 3 prime end is reported in hlist as the five prime end. the next statement makes xout and yout be at the same end of the half repeats when the sequences are viewed in the same direction. */ if (para.mode == 'd') { if (xseq->key.piedir == minus) *xout += 1 - length; else if (yseq->key.piedir == minus) *yout += 1 - length; /* if the configuration is circular, the above statement could put xout or yout off the map, hence the following: */ if (*xout < xseq->key.coobeg) *xout += xseq->key.cooend - xseq->key.coobeg + 1; else if (*yout < yseq->key.coobeg) *yout += yseq->key.cooend - yseq->key.coobeg + 1; } if (para.typbk == 'r' && *xout == *yout) { if (para.mode == 'i') { *palindrome = true; /* the "repeat" is a palindrome. */ } else *finished = true; } /* if para.mode = "d" and xout = yout, then the "repeat" spans the entire sequence and should be ignored. */ if (para.typbk == 'u') dist = 0; else if (!*finished && !*palindrome) { if (para.mode == 'd') { /* calculate distance of direct repeats */ dist = *yout - *xout; /*calculates dist assuming linearity*/ if (xseq->key.coocon == circular) { /* determines the shorter distance around the circle */ cirdist = xseq->key.cooend - *yout + *xout - xseq->key.coobeg + 1; if (cirdist < dist) dist = cirdist; } } else { /* as above */ /* calculate distance from 5 prime end to 3 prime end of inverted repeats - pseudo-loop distances */ dist = *yout - *xout - length + 1; if (xseq->key.coocon == circular) { cirdist = xseq->key.cooend - xseq->key.coobeg - dist - length * 2 + 3; if (cirdist < dist) { dist = cirdist; /* para.mode = i */ } } } } /* before putting the stuff we want into rout, we get rid of the stuff we do not want. */ if (coextensive && dist < 0 && !*palindrome) *finished = true; if (length < para.minlength || length > para.maxlength) *finished = true; if (para.typbk == 'r' && !*palindrome) { if (dist < para.dmin || dist > para.dmax) *finished = true; } if (*finished) return; /* at last we put data into rout */ rout->x5p = *xout; rout->y5p = *yout; rout->rlength = length; rout->distance = dist; rout->deltagee = energy; } /* anarep */ /* end module rep.anarep version = 1.63; (* of rep 1984 june 5 */ /* begin module rep.writetofile */ Static Void writetofile(para, rout, bout, getenergy, palindrome) prec *para; reprec *rout; _TEXT *bout; boolean getenergy, palindrome; { /* input parameters */ /* record of repeat info */ /* output file */ /* true if "energy" is reported */ /* is it a palindrome ? */ /* writes repeat information to bout, which can be either fout or pout, depending on how writetofile is called */ fprintf(bout->f, " %7ld", rout->x5p); if (!palindrome) fprintf(bout->f, " %8ld", rout->y5p); fprintf(bout->f, " %8ld", rout->rlength); if (para->typbk == 'r' && !palindrome) fprintf(bout->f, " %9ld ", rout->distance); if (getenergy) fprintf(bout->f, " %9.2f kcal", rout->deltagee); putc('\n', bout->f); } /* writetofile */ Local boolean overlap(xseq, yseq, para) piece **xseq, **yseq; prec *para; { /*info about where the pieces start and end */ /* has parameters from repp */ /* returns true if the two sequences overlap completely and false otherwise */ boolean Result = false; /* except as below */ if (para->typbk != 'r') return false; switch (para->mode) { case 'd': if ((*xseq)->key.piebeg == (*yseq)->key.pieend && (*xseq)->key.pieend == (*yseq)->key.piebeg) Result = true; break; case 'i': if ((*xseq)->key.piebeg == (*yseq)->key.piebeg && (*xseq)->key.pieend == (*yseq)->key.pieend) Result = true; break; } return Result; } /* overlap */ /* end module rep.writetofile version = 1.63; (* of rep 1984 june 5 */ /* begin module rep.procrep */ Static Void procrep(hlist, para, getenergy, xseq, yseq, fout, pout) _TEXT *hlist; prec *para; boolean *getenergy; piece **xseq, **yseq; _TEXT *fout, *pout; { /* list of helices from helix */ /* input parameters */ /* true if "energies` are reported */ /* the sequences in the books */ /* output file for repeats */ /* output file for palindromes */ /* procedure uses gethelix to get the information from hlist. then it analyzes the data with anarep which also tosses out data if necessary (see anarep). next it uses writetofile to put palindromes into pout and repeats into fout. */ double energy; /* the "energy" of the repeat */ boolean done; /* done with book comparisons */ long xout, yout; /* 5 prime ends of repeat from procedure gethelix */ long length; /* length of repeat */ reprec rout; /* info about repeat in a record */ boolean palindrome; /* true if the "repeat" is a palindrome */ boolean finished; /* true if the repeat is not to be reported */ boolean coextensive; /* true if the sequences overlap completely */ coextensive = overlap(xseq, yseq, para); if (coextensive || para->typbk == 'u') putc('\n', fout->f); else fprintf(fout->f, " repeats (or parts of repeats) may be duplicated in regions of sequence overlap\n"); putc(' ', fout->f); if (BUFEOF(hlist->f)) { printf("premature end of hlist\n"); halt(); } else copyaline(hlist, fout); fprintf(fout->f, "%6c%cx:%6c%cy:%9s", '5', prime, '5', prime, "length:"); if (para->typbk == 'r') fprintf(fout->f, "%10s", "distance:"); if (*getenergy) fprintf(fout->f, "%13s", "energy:"); putc('\n', fout->f); if (para->mode == 'i' && para->typbk == 'r') { /* put stuff into pout */ putc(' ', pout->f); fprintf(pout->f, "%2c%c end:", '5', prime); fprintf(pout->f, "%9s", "length:"); if (*getenergy) fprintf(pout->f, "%13s", "energy:"); putc('\n', pout->f); } else { if (*pout->name != '\0') { if (pout->f != NULL) pout->f = freopen(pout->name, "w", pout->f); else pout->f = fopen(pout->name, "w"); } else { if (pout->f != NULL) rewind(pout->f); else pout->f = tmpfile(); } if (pout->f == NULL) _EscIO2(FileNotFound, pout->name); SETUPBUF(pout->f, Char); } /* empties pout if no palindromes */ do { gethelix(hlist, &xout, &yout, &length, *getenergy, &energy, &done); if (!done) { anarep(*para, *xseq, *yseq, length, energy, coextensive, &xout, &yout, &rout, &palindrome, &finished); if (!palindrome && !finished) writetofile(para, &rout, fout, *getenergy, palindrome); else if (!finished) /* palindrome is true */ writetofile(para, &rout, pout, *getenergy, palindrome); } } while (!done); /* procrep */ } /* end module rep.procrep version = 1.63; (* of rep 1984 june 5 */ /* begin module rep.themain */ Static Void themain(hlist, xbook, ybook, fout, repp) _TEXT *hlist, *xbook, *ybook, *fout, *repp; { /* listing from program "helix" */ /* books from delila */ /* output of repeated sequences */ /* input parameters */ /* this procedure first checks that the parameters requested in repp are consistent with the input files, hlist, xbook, and ybook. the program will halt with error messages to output if the inconsistency is unacceptable. other inconsistencies, e.g. gupairs in hlist if inverted repeats are requested, may actually be what the user intended. on the other hand, they may not. here again, error messages appear in output and sometimes in fout. finally, the procedure sets up fout (output file for repeats) and pout (output file for palindromes) and processes the repeats. it compares the first piece in xbook to each piece in ybook, then the second piece in xbook to each piece in ybook, and so on. repeats and palindromes that meet the criteria of repp are put into the appropriate files. if the two sequences inspected overlap completely, duplicate entries in hlist are recognized and not reported. */ piece *xseq, *yseq; /* sequences in the book */ prec para; /* a record of the parameter variables */ boolean getenergy; /* are energies reported? */ printf(" rep %4.2f\n", version); initbook(xbook, ybook, &xseq, &yseq); hlistvsbooks(hlist, xbook, ybook); readparameters(repp, ¶); checkhlistparams(hlist, ¶, &getenergy); foutheading(hlist, fout, &getenergy, ¶); poutheading(hlist, &pout, &getenergy, ¶); while (!BUFEOF(xbook->f)) { getpiece(xbook, &xseq); if (!BUFEOF(xbook->f)) { if (*ybook->name != '\0') { if (ybook->f != NULL) ybook->f = freopen(ybook->name, "r", ybook->f); else ybook->f = fopen(ybook->name, "r"); } else rewind(ybook->f); if (ybook->f == NULL) _EscIO2(FileNotFound, ybook->name); RESETBUF(ybook->f, Char); while (!BUFEOF(ybook->f)) { getpiece(ybook, &yseq); if (!BUFEOF(ybook->f)) { checkseqdata(para, xseq, yseq, fout); procrep(hlist, ¶, &getenergy, &xseq, &yseq, fout, &pout); } clearpiece(&yseq); } } clearpiece(&xseq); } } /* themain */ /* end module rep.themain version = 1.63; (* of rep 1984 june 5 */ main(argc, argv) int argc; Char *argv[]; { PASCAL_MAIN(argc, argv); if (setjmp(_JL1)) goto _L1; repp.f = NULL; strcpy(repp.name, "repp"); pout.f = NULL; strcpy(pout.name, "pout"); fout.f = NULL; strcpy(fout.name, "fout"); hlist.f = NULL; strcpy(hlist.name, "hlist"); ybook.f = NULL; strcpy(ybook.name, "ybook"); xbook.f = NULL; strcpy(xbook.name, "xbook"); themain(&hlist, &xbook, &ybook, &fout, &repp); _L1: if (xbook.f != NULL) fclose(xbook.f); if (ybook.f != NULL) fclose(ybook.f); if (hlist.f != NULL) fclose(hlist.f); if (fout.f != NULL) fclose(fout.f); if (pout.f != NULL) fclose(pout.f); if (repp.f != NULL) fclose(repp.f); exit(EXIT_SUCCESS); } /* rep */ /* End. */