/* Output from p2c 1.21alpha-07.Dec.93, the Pascal-to-C translator */ /* From input file "difri.p" */ #include /* difri: difference in Ri values in a scan data file Tom Schneider NCI/FCRDC Bldg 469. Room 144 P.O. Box B Frederick, MD 21702-1201 (301) 846-5581 (-5532 for messages) network address: toms@ncifcrf.gov National Cancer Institute Laboratory of Mathematical Biology */ /* end of program */ /* begin module version */ #define version 1.08 /* of difri.p 1995 April 17 origin 1995 April 17 */ /* end module version */ /* begin module describe.difri */ /* name difri: difference in Ri values in a scan data file synopsis difri(data: in, difrip: in, xyin: in, output: out) files data: output data file from the scan program. difrip: parameter file to control the program. first line: one integer, the distance between Ri values. second line: If the first character is: r: Ri values are used p: probability values are used z: Z values are used xyin: input data file to the xyplop program. output: messages to the user description examples documentation This program the data file, extracts sites "distance" bases apart and puts their Ri values into a xyin file for plotting with xyplo. see also scan.p, xyplo.p author Thomas Dana Schneider bugs technical notes */ /* end module describe.difri */ /* begin module Ri.const */ #define defnegativeinfinity (-1000) /* default for negative infinity for the Ri(b,l) table */ #define maxribl 2000 /* maximum size of Ri(b,l) table */ #define infofield 12 /* size of field for printing information in bits */ #define infodecim 6 /* number of decimal places for printing information */ /* these are used for conlist only */ #define nfield 6 /* size of field for printing n, the number of sites */ /* end module Ri.const from ri.p 2.02 */ Static _TEXT data, difrip; /* file used by this program */ Static _TEXT xyin; /* file used by this program */ Static jmp_buf _JL1; /* 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 = 4.15; (@ of prgmod.p 1994 November 12 */ /* 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 = 4.15; (@ of prgmod.p 1994 November 12 */ /* begin module skipblanks */ Static Void skipblanks(thefile) _TEXT *thefile; { /* skip over blanks until a non-blank, or end of line, is found */ while ((P_peek(thefile->f) == ' ') & (!P_eoln(thefile->f))) getc(thefile->f); } Static Void skipnonblanks(thefile) _TEXT *thefile; { /* skip over nonblanks until a blank, or end of line, is found */ while ((P_peek(thefile->f) != ' ') & (!P_eoln(thefile->f))) getc(thefile->f); } Static Void skipcolumn(thefile) _TEXT *thefile; { /* skip over a data column */ skipblanks(thefile); skipnonblanks(thefile); } /* end module skipblanks version = 4.15; (@ of prgmod.p 1994 November 12 */ /* begin module difri.themain */ Static Void themain(data, difrip, xyin) _TEXT *data, *difrip, *xyin; { /* the main procedure of the program */ long distance; /* distance between sites to use */ Char selector; /* select Ri (r), probability (p) or Z value (z) to report */ long coordinate; /* coordinate of a site */ long orientation; /* orientation of a site */ double p; /* probability of a site */ double Ri; /* Ri of a site */ double Z; /* Z of a site */ long oldcoordinate = 0; /* coordinate of the previous site */ long oldorientation = 0; /* orientation of the previous site */ double oldp = 0.0; /* probability of the previous site */ double oldRi = 0.0; /* Ri of the previous site */ double oldZ = 0.0; /* Z of the previous site */ printf("difri %4.2f\n", version); /* get parameters */ if (*difrip->name != '\0') { if (difrip->f != NULL) difrip->f = freopen(difrip->name, "r", difrip->f); else difrip->f = fopen(difrip->name, "r"); } else rewind(difrip->f); if (difrip->f == NULL) _EscIO2(FileNotFound, difrip->name); RESETBUF(difrip->f, Char); fscanf(difrip->f, "%ld%*[^\n]", &distance); getc(difrip->f); if (distance < 1) { printf("distance between sites must be positive\n"); halt(); } fscanf(difrip->f, "%c%*[^\n]", &selector); getc(difrip->f); if (selector == '\n') selector = ' '; if (selector != 'z' && selector != 'p' && selector != 'r') { printf("selector must be one of: rpz\n"); halt(); } if (*data->name != '\0') { if (data->f != NULL) data->f = freopen(data->name, "r", data->f); else data->f = fopen(data->name, "r"); } else rewind(data->f); if (data->f == NULL) _EscIO2(FileNotFound, data->name); RESETBUF(data->f, Char); if (*xyin->name != '\0') { if (xyin->f != NULL) xyin->f = freopen(xyin->name, "w", xyin->f); else xyin->f = fopen(xyin->name, "w"); } else { if (xyin->f != NULL) rewind(xyin->f); else xyin->f = tmpfile(); } if (xyin->f == NULL) _EscIO2(FileNotFound, xyin->name); SETUPBUF(xyin->f, Char); fprintf(xyin->f, "* difri %4.2f\n", version); fprintf(xyin->f, "************************************\n"); fprintf(xyin->f, "* DEFINITION OF THE DATA COLUMNS: *\n"); fprintf(xyin->f, "* 1: "); switch (selector) { case 'r': fprintf(xyin->f, "Ri(n) "); break; case 'p': fprintf(xyin->f, "probability(n)"); break; case 'z': fprintf(xyin->f, "Z(n) "); break; } fprintf(xyin->f, " *\n"); fprintf(xyin->f, "* 2: "); switch (selector) { case 'r': fprintf(xyin->f, "Ri(n+%2ld) ", distance); break; case 'p': fprintf(xyin->f, "probability(n+%2ld)", distance); break; case 'z': fprintf(xyin->f, "Z(n+%ld) ", distance); break; } fprintf(xyin->f, " *\n"); fprintf(xyin->f, "* 3: n *\n"); fprintf(xyin->f, "* 4: n+%ld *\n", distance); fprintf(xyin->f, "************************************\n"); while (!BUFEOF(data->f)) { if (P_peek(data->f) == '*') { copyaline(data, xyin); continue; } skipcolumn(data); /* piece number */ skipcolumn(data); /* piece length */ skipcolumn(data); /* piece name */ fscanf(data->f, "%ld", &coordinate); fscanf(data->f, "%ld", &orientation); fscanf(data->f, "%lg", &Ri); fscanf(data->f, "%lg", &Z); fscanf(data->f, "%lg", &p); fscanf(data->f, "%*[^\n]"); getc(data->f); if (coordinate - oldcoordinate == distance) { switch (selector) { case 'r': fprintf(xyin->f, "%*.*f", infofield, infodecim, oldRi); fprintf(xyin->f, " %*.*f", infofield, infodecim, Ri); break; case 'p': fprintf(xyin->f, "%*.*f", infofield, infodecim, oldp); fprintf(xyin->f, " %*.*f", infofield, infodecim, p); break; case 'z': fprintf(xyin->f, "%*.*f", infofield, infodecim, oldZ); fprintf(xyin->f, " %*.*f", infofield, infodecim, Z); break; } fprintf(xyin->f, " %*ld", nfield, oldcoordinate); fprintf(xyin->f, " %*ld\n", nfield, coordinate); } oldcoordinate = coordinate; oldorientation = orientation; oldp = p; oldRi = Ri; oldZ = Z; /*zzz*/ } } /* end module difri.themain */ main(argc, argv) int argc; Char *argv[]; { PASCAL_MAIN(argc, argv); if (setjmp(_JL1)) goto _L1; xyin.f = NULL; strcpy(xyin.name, "xyin"); difrip.f = NULL; strcpy(difrip.name, "difrip"); data.f = NULL; strcpy(data.name, "data"); themain(&data, &difrip, &xyin); _L1: if (data.f != NULL) fclose(data.f); if (difrip.f != NULL) fclose(difrip.f); if (xyin.f != NULL) fclose(xyin.f); exit(EXIT_SUCCESS); } /* End. */