/* Output from p2c 1.21alpha-07.Dec.93, the Pascal-to-C translator */ /* From input file "asciidna.p" */ #include /* asciidna: draw ASCII DNA 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 1994 */ /* end of program */ /* begin module version */ #define version 1.09 /* of asciidna.p 1994 May 25 origin 1994 January 27 */ /* end module version */ /* begin module describe.asciidna */ /* name asciidna: draw ASCII DNA synopsis asciidna(asciidnap: in, plot: out, output: out) files asciidnap: parameters to control the program linewidth: integer, length in characters of the line to create wavelength: real, wavelength in characters amplitude: real, height of the waves incharacters phase1: real, phase shift in characters of first wave phase2: real, phase shift in characters of second wave Watson: character, the character for one strand Crick: character, the character for the other strand (that one's a REAL character!) barmajor: character, the character for the major groove barminor: character, the character for the minor groove bargap: integer, distance between bars in characters plot: plot of spiral dna output: messages to the user description The program draws a spiral DNA in ASCII characters. It was inspired by: // \\ // \\ // \\ // \\ // \\ // \\ // \\ Jim Sloan // | :,\\': | \\ // | :,\\': | \\ // | :,\\': | \\ jsloan@u.washington.edu \\ | | \\ // | | // \\ | | \\ // | | // \\ | | \\ | :,\\': | // \\ | :,\\': | // \\ | :,\\': | // \\ | \\ // \\ // \\ // \\ // \\ // \\ // \\ The Pascal code may be obtained by anonymous ftp from ncifcrf.gov in pub/delila/asciidna.p.Z and pub/delila/asciidnap. examples if asciidnap contains: *********************************************************** 80 linewidth: integer, length in characters of the line to create 24 wavelength: real, wavelength in characters 8 amplitude: real, height of the waves incharacters -1 phase1: real, phase shift in characters of first wave 4 phase2: real, phase shift in characters of second wave W watson: character, the character for one strand C crick: character, the character for the other strand | barmajor: character, the character for the major groove : barminor: character, the character for the minor groove 3 bargap: integer, distance between bars in characters asciidnap: parematers to control the asciidna program *********************************************************** one obtains: *********************************************************** asciidna 1.08 CCC WWW CCC WWW CCC WWW CC :CC| WW CC :CC| WW CC :CC| WW C : W C | W C : W C | W C : W C | W W C : W C | W C : W C | W C : W C | W |W C: :W C| |W C: :W C| |W C: :W C| |W | W C : W C | W C : W C | W C : W C | W C | W C : W C | W C : W C | W C : W C | W C C |WW: WW CC |WW: WW CC |WW: WW CC |WW: CCC WWW CCC WWW CCC WWW CCC WW *********************************************************** documentation see also dnag.p author Thomas Dana Schneider bugs technical notes */ /* end module describe.asciidna */ Static _TEXT asciidnap, plot; /* files 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 pi 3.1415926535 /* ratio of circle circumfrence to diameter */ #define xmax 80 /* largest horizontal size */ #define ymax 30 /* largest vertical size */ /* Local variables for themain: */ struct LOC_themain { double amplitude; /* height of sinewave */ double multiplier; /* pre calculated value for speed */ } ; Local long outer(x, LINK) double x; struct LOC_themain *LINK; { /* outer part of the function */ return ((long)floor(LINK->amplitude * (x + 1) / 2 + 0.5)); } Local double inner(x, phase, LINK) long x; double phase; struct LOC_themain *LINK; { /* inner part of the function */ return (LINK->multiplier * (x + phase)); } /* end module halt version = 'delmod 6.16 84 mar 12 tds/gds'; */ /* begin module asciidna.themain */ Static Void themain(asciidnap, plot) _TEXT *asciidnap, *plot; { /* the main procedure of the program */ struct LOC_themain V; Char barmajor, barminor; /* characters to fill in major and minor grooves */ long bargap; /* distance between bars in characters */ Char field[xmax + 1][xmax + 1]; /* a field of characters */ double phase1; /* phase difference of first wave, characters */ double phase2; /* phase difference of second wave, characters */ long x; /* x position */ long y; /* y position */ long y1; /* first wave y position */ long y2; /* second wave y position */ long z1; /* first wave y position in 3 space */ long z2; /* second wave y position in 3 space */ long linewidth; /* width of line on paper */ double wavelength; /* characters per wavelength */ Char Watson, Crick; /* characters involved with DNA */ long FORLIM1; printf("asciidna %4.2f\n", version); if (*plot->name != '\0') { if (plot->f != NULL) plot->f = freopen(plot->name, "w", plot->f); else plot->f = fopen(plot->name, "w"); } else { if (plot->f != NULL) rewind(plot->f); else plot->f = tmpfile(); } if (plot->f == NULL) _EscIO2(FileNotFound, plot->name); SETUPBUF(plot->f, Char); fprintf(plot->f, " asciidna %4.2f\n", version); if (*asciidnap->name != '\0') { if (asciidnap->f != NULL) asciidnap->f = freopen(asciidnap->name, "r", asciidnap->f); else asciidnap->f = fopen(asciidnap->name, "r"); } else rewind(asciidnap->f); if (asciidnap->f == NULL) _EscIO2(FileNotFound, asciidnap->name); RESETBUF(asciidnap->f, Char); fscanf(asciidnap->f, "%ld%*[^\n]", &linewidth); getc(asciidnap->f); fscanf(asciidnap->f, "%lg%*[^\n]", &wavelength); getc(asciidnap->f); fscanf(asciidnap->f, "%lg%*[^\n]", &V.amplitude); getc(asciidnap->f); fscanf(asciidnap->f, "%lg%*[^\n]", &phase1); getc(asciidnap->f); fscanf(asciidnap->f, "%lg%*[^\n]", &phase2); getc(asciidnap->f); fscanf(asciidnap->f, "%c%*[^\n]", &Watson); getc(asciidnap->f); if (Watson == '\n') Watson = ' '; fscanf(asciidnap->f, "%c%*[^\n]", &Crick); getc(asciidnap->f); if (Crick == '\n') Crick = ' '; fscanf(asciidnap->f, "%c%*[^\n]", &barmajor); getc(asciidnap->f); if (barmajor == '\n') barmajor = ' '; fscanf(asciidnap->f, "%c%*[^\n]", &barminor); getc(asciidnap->f); if (barminor == '\n') barminor = ' '; fscanf(asciidnap->f, "%ld%*[^\n]", &bargap); getc(asciidnap->f); if (linewidth > xmax) { printf("linewidth > %ld\n", (long)xmax); halt(); } if (V.amplitude > ymax) { printf("amplitude > %ld\n", (long)ymax); halt(); } V.multiplier = 2 * pi / wavelength; linewidth--; /* redefine to save calculation */ for (x = 0; x <= linewidth; x++) { FORLIM1 = (long)floor(V.amplitude + 0.5); for (y = 0; y <= FORLIM1; y++) field[x][y] = ' '; } for (x = 0; x <= linewidth; x++) { y1 = outer(sin(inner(x, phase1, &V)), &V); y2 = outer(sin(inner(x, phase2, &V)), &V); z1 = outer(cos(inner(x, phase1, &V)), &V); z2 = outer(cos(inner(x, phase2, &V)), &V); /* fill in bases */ if (x % bargap == 0) { /* p2c: asciidna.p, line 210: * Note: Using % for possibly-negative arguments [317] */ if (y1 < y2) { for (y = y1; y <= y2; y++) field[x][y] = barmajor; } else { for (y = y2; y <= y1; y++) field[x][y] = barminor; } } /* do crossover here */ if (z1 > z2) { field[x][y2] = Crick; field[x][y1] = Watson; } else { field[x][y1] = Watson; field[x][y2] = Crick; } } /* the code does the following, but is implemented efficiently y1 := round(amplitude*(sin(multiplier*(x+phase1)) + 1)/2); y2 := round(amplitude*(sin(multiplier*(x+phase2)) + 1)/2); z1 := round(amplitude*(cos(multiplier*(x+phase1)) + 1)/2); z2 := round(amplitude*(cos(multiplier*(x+phase2)) + 1)/2); */ FORLIM1 = (long)floor(V.amplitude + 0.5); /* plot the graph */ for (y = 0; y <= FORLIM1; y++) { for (x = 0; x <= linewidth; x++) putc(field[x][y], plot->f); putc('\n', plot->f); } } #undef pi #undef xmax #undef ymax /* end module asciidna.themain */ main(argc, argv) int argc; Char *argv[]; { PASCAL_MAIN(argc, argv); if (setjmp(_JL1)) goto _L1; plot.f = NULL; strcpy(plot.name, "plot"); asciidnap.f = NULL; strcpy(asciidnap.name, "asciidnap"); themain(&asciidnap, &plot); _L1: if (asciidnap.f != NULL) fclose(asciidnap.f); if (plot.f != NULL) fclose(plot.f); exit(EXIT_SUCCESS); } /* End. */