/* Output from p2c 1.21alpha-07.Dec.93, the Pascal-to-C translator */ /* From input file "transpose.p" */ #include /* transpose: transpose a matrix of integers Dr. Thomas D. Schneider National Institutes of Health National Cancer Institute Center for Cancer Research Nanobiology Program Molecular Information Theory Group Frederick, Maryland 21702-1201 toms@ncifcrf.gov permanent email: toms@alum.mit.edu (use only if first address fails) http://www.ccrnp.ncifcrf.gov/~toms/ */ /* end of program */ /* begin module version */ #define version 1.02 /* of transpose.p 2007 Oct 13 2007 Oct 13, 1.02: match freb better 2007 Oct 12, 1.01: functional but not quite 2007 Oct 12, 1.00: origin */ #define updateversion 1.00 /* defines lowest acceptable current parameter file */ /* end module version */ /* begin module describe.transpose */ /* name transpose: transpose a matrix of integers synopsis transpose(fin: in, transposep: in, fout: out, output: out) files fin: A file containing fivei lines. The first line is the name of the site. The remaining four lines are the numbers of A, C, G and T at each position in an aligned set of sequences. Words in the file that do not begin with a number are dropped fout: The transpose of the file with numbering in the first colum. This output is ready for conversion to a Delila book by the freb program. transposep: parameters to control the program. The file must contain the following parameters, one per line: parameterversion: The version number of the program. This allows the user to be warned if an old parameter file is used. output: messages to the user description The purpose and use of the program. examples documentation see also freb.p author Thomas Dana Schneider bugs technical notes The largest number of items in a row is given by constant maxstore. */ /* end module describe.transpose */ #define maxstore 1000 /* maximum storage */ Static _TEXT fin; /* file used by this program */ Static _TEXT transposep; /* file used by this program */ Static _TEXT fout; /* 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); } #define tab 9 /* tab character */ /* end module halt version = 5.38; (@ of prgmod.p 2007 May 15 */ /* begin module skipblanks */ /* 2003 July 31: tab is considered a blank character */ Static boolean isblank(c) Char c; { /* is the character c blank or tab? */ return (c == ' ' || c == tab); } #undef tab Static Void skipblanks(thefile) _TEXT *thefile; { /* skip over blanks until a non-blank, or end of line, is found */ while (isblank(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 ((!isblank(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 = 5.38; (@ of prgmod.p 2007 May 15 */ /* 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 */ /* Local variables for themain: */ struct LOC_themain { long store[4][maxstore]; long count; /* the number of initial columns read */ } ; Local Void writeout(f, LINK) _TEXT *f; struct LOC_themain *LINK; { /* write out the data */ long base; /* count of the 4 bases */ long c; /* counter for output */ long FORLIM; FORLIM = LINK->count; /* write out the data */ /* for c := count downto 1 do begin */ for (c = 0; c < FORLIM; c++) { fprintf(f->f, "%4ld", c); for (base = 0; base <= 3; base++) fprintf(f->f, " %4ld", LINK->store[base][c]); putc('\n', f->f); } } /* writeout */ /* end module copyaline version = 5.38; (@ of prgmod.p 2007 May 15 */ /* begin module transpose.themain */ Static Void themain(fin, transposep, fout) _TEXT *fin, *transposep, *fout; { /* the main procedure of the program */ struct LOC_themain V; double parameterversion; /* parameter version number */ long base; /* count of the 4 bases */ long c; /* counter for output */ long FORLIM1; _TEXT TEMP; printf("transpose %4.2f\n", version); if (*transposep->name != '\0') { if (transposep->f != NULL) transposep->f = freopen(transposep->name, "r", transposep->f); else transposep->f = fopen(transposep->name, "r"); } else rewind(transposep->f); if (transposep->f == NULL) _EscIO2(FileNotFound, transposep->name); RESETBUF(transposep->f, Char); fscanf(transposep->f, "%lg%*[^\n]", ¶meterversion); getc(transposep->f); if ((long)floor(100 * parameterversion + 0.5) < (long)floor(100.0 + 0.5)) { printf("You have an old parameter file!\n"); halt(); } if (*fin->name != '\0') { if (fin->f != NULL) fin->f = freopen(fin->name, "r", fin->f); else fin->f = fopen(fin->name, "r"); } else rewind(fin->f); if (fin->f == NULL) _EscIO2(FileNotFound, fin->name); RESETBUF(fin->f, Char); 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); /* copy the name line */ copyaline(fin, fout); /* read in the data */ printf("Reading data. \"+\" = accepted number, \"-\" = not a number\n"); for (base = 0; base <= 3; base++) { V.count = 0; while (!P_eoln(fin->f)) { skipblanks(fin); if (P_peek(fin->f) == '9' || P_peek(fin->f) == '8' || P_peek(fin->f) == '7' || P_peek(fin->f) == '6' || P_peek(fin->f) == '5' || P_peek(fin->f) == '4' || P_peek(fin->f) == '3' || P_peek(fin->f) == '2' || P_peek(fin->f) == '1' || P_peek(fin->f) == '0') { V.count++; fscanf(fin->f, "%ld", &V.store[base][V.count-1]); putchar('+'); } else { putchar('-'); skipcolumn(fin); } } printf("base %ld\n", base + 1); fscanf(fin->f, "%*[^\n]"); getc(fin->f); } printf("\nnumber of columns read: %ld\n", V.count); for (base = 1; base <= 4; base++) { printf("base %ld |", base); FORLIM1 = V.count; for (c = 0; c < FORLIM1; c++) printf(" %4ld", V.store[base-1][c]); putchar('\n'); } TEMP.f = stdout; *TEMP.name = '\0'; writeout(&TEMP, &V); writeout(fout, &V); } /* end module transpose.themain */ main(argc, argv) int argc; Char *argv[]; { PASCAL_MAIN(argc, argv); if (setjmp(_JL1)) goto _L1; fout.f = NULL; strcpy(fout.name, "fout"); transposep.f = NULL; strcpy(transposep.name, "transposep"); fin.f = NULL; strcpy(fin.name, "fin"); themain(&fin, &transposep, &fout); _L1: if (fin.f != NULL) fclose(fin.f); if (transposep.f != NULL) fclose(transposep.f); if (fout.f != NULL) fclose(fout.f); exit(EXIT_SUCCESS); } /* End. */