/* Output from p2c, the Pascal-to-C translator */ /* From input file "meld.p" */ #include "p2c.h" #include #include /*#include */ #define P_imin(x,y) (((x) < (y)) ? (x) : (y)) #define P_imax(x,y) (((x) > (y)) ? (x) : (y)) main(argc, argv) int argc; Char *argv[]; { long status; Char seqt[5000000]; long seqct[600000]; Char namet[20], nameo[20]; long mt, mr, nt, nr, lt, lr, tp; Char base; double rnum, density, atdensity; long densityct, atdensityct, totct, nonrandomct; FILE *ifilt, *ofil; long seqmax, seqmin, lngth, shuffle; double r1, r2, r3; /*dummy variables for turning integers into reals*/ long pos_[80]; long j, n1, n2, period, FORLIM; double erand48(); unsigned short xsubi[3]; int ftime(); /*struct timeb tp;*/ PASCAL_MAIN(argc, argv); /*Need to modify next two lines to read in floating point?*/ /* ftime(&tp); xsubi[0]=tp.millitm */ printf("Please enter a random seed number.\n"); scanf("%ld%*[^\n]", &tp); getchar(); xsubi[0]=tp; xsubi[1]=0; xsubi[2]=0; for (mt=1; mt <=10 ; ++mt) erand48(xsubi); ofil = NULL; ifilt = NULL; printf("Please give the name of the training set file.\n"); gets(namet); printf("Please give the name of the output file.\n"); gets(nameo); printf("Please enter (as a decimal--e.g. .5) the desired proportion of\n"); printf(" sequences from %s to be used in the mix.\n", namet); scanf("%lg%*[^\n]", &density); getchar(); density = 1.0 - density; printf("Please enter (as a decimal--e.g. .65) the desired proportion of\n"); printf(" A-T in the random sequences.\n"); scanf("%lg%*[^\n]", &atdensity); getchar(); atdensity /= 2.0; shuffle = 0; while (shuffle != 1 && shuffle != 2) { printf("Do you want random selection of sequences from %s or shuffling?\n", namet); printf("Enter 1 for random selection, 2 for shuffling, and 0 for more information.\n"); scanf("%ld%*[^\n]", &shuffle); getchar(); if (shuffle == 1 || shuffle == 2) continue; printf("At each step, the program randomly decides whether or not\n"); printf(" to use a sequence from %s.\n", namet); printf("With choice 1, each time a selection is made from %s,\n", namet); printf(" it is made randomly.\n"); printf("With choice 2, the sequences in %s are randomly shuffled\n", namet); printf(" and inserted in that order.\n"); printf("When %s is exhausted, it is reshuffled.\n", namet); printf("This is less random, but ensures the sequences of %s\n", namet); printf( " are used the same number of times.\n"); } printf("How do you want the type of sequence (random or not) designated?\n"); printf("Please enter 0 for non-decimal (e.g. 0 1) or 1 for decimal (e.g. 0.0).\n"); scanf("%ld%*[^\n]", &period); getchar(); printf("Please enter the length of sequence desired.\n"); scanf("%ld%*[^\n]", &lngth); getchar(); printf("Please enter the number of random sequences desired.\n"); scanf("%ld%*[^\n]", &lr); getchar(); ifilt = fopen(namet, "r"); if (ifilt == NULL) _EscIO(FileNotFound); rewind(ifilt); ofil = fopen(nameo, "w"); if (ofil == NULL) _EscIO(FileNotFound); if (ofil != NULL) { rewind(ofil); } else ofil = tmpfile(); if (ofil == NULL) _EscIO(FileNotFound); densityct = 0; atdensityct = 0; totct = 0; nonrandomct = 0; for (nt = 1; nt <= 3200; nt++) seqct[nt - 1] = 0; nt = 0; while (!P_eof(ifilt)) { base = getc(ifilt); if (base == '\n') base = ' '; if (base == 'a') base = 'A'; if (base == 'c') base = 'C'; if (base == 'g') base = 'G'; if (base == 't') base = 'T'; if (base == 'n') base = 'N'; nt++; seqt[nt - 1] = base; if (P_eoln(ifilt)) { fscanf(ifilt, "%*[^\n]"); getc(ifilt); } } lt = (long)((double)nt / lngth); FORLIM = lt; for (j = 1; j <= FORLIM; j++) pos_[j - 1] = j; mr = 1; FORLIM = lngth; while (mr < lr) { totct++; if (erand48(xsubi) < density) { densityct++; for (nr = 1; nr <= lngth; nr++) { rnum = erand48(xsubi); if (rnum < atdensity) { fprintf(ofil, "0 0 0 1 "); atdensityct++; } else if (rnum < 2*atdensity) { fprintf(ofil, "1 0 0 0 "); atdensityct++;} else if (rnum < 0.5 + atdensity) fprintf(ofil, "0 1 0 0 "); else { fprintf(ofil, "0 0 1 0 "); } if (nr % 9 == 0) putc('\n',ofil); } if (lngth % 9 !=0) putc('\n', ofil); if (period == 1) fprintf(ofil, "0.0\n"); else fprintf(ofil, "0\n"); mr++; continue; } nonrandomct++; if (shuffle == 1) { mt = (long)((double)(lt * erand48(xsubi))); seqct[mt]++; mt *= lngth; } else { if (nonrandomct % lt == 1) { FORLIM = lt; for (j = 0; j < FORLIM; j++) { n1 = pos_[lt - j - 1]; n2 = (long)((double)(erand48(xsubi) * (lt - j))) + 1; pos_[lt - j - 1] = pos_[n2 - 1]; pos_[n2 - 1] = n1; } } mt =( lngth * pos_[(nonrandomct - 1) % lt])-(lngth+1); } FORLIM = mt + lngth; printf(" %ld",mt); for (nt = mt + 1; nt <= mt + lngth; nt++) { switch (seqt[nt - 1]) { case 'A': fprintf(ofil, "0 0 0 1 "); break; case 'C': fprintf(ofil, "0 0 1 0 "); break; case 'G': fprintf(ofil, "0 1 0 0 "); break; case 'T': fprintf(ofil, "1 0 0 0 "); break; case 'N': fprintf(ofil,"0 0 0 0 "); break; } if ((nt-mt) % 9 ==0) putc('\n',ofil); } if (lngth % 9 !=0) putc('\n', ofil); if (period == 1) fprintf(ofil, "1.0\n"); else fprintf(ofil, "1\n"); } /*while*/ if (ifilt != NULL) fclose(ifilt); ifilt = NULL; if (ofil != NULL) fclose(ofil); ofil = NULL; printf("Total number of output sequences: %12ld\n", totct); r1 = densityct; r2 = totct; printf("Proportion of sequences from %s:%f\n", namet, 1.0 - r1/ r2); r1 = atdensityct; r2 = lr; printf("Proportion of A-T in random sequences: %f\n", r1 /(lngth * r2)); if (shuffle == 1) { seqmax = 0; seqmin = 100000L; FORLIM = lt; for (nt = 1; nt <= FORLIM; nt++) { seqmax = P_imax(seqmax, seqct[nt - 1]); seqmin = P_imin(seqmin, seqct[nt - 1]); } printf("Number of sequences read from %s: %12ld\n", namet,lt); r1 = seqmin; r3 = nonrandomct; printf("Range of sequences used from %s:\n", namet); printf(" Min: Number: %12ld, Proportion: %f\n",seqmin, r1 / r3); r1 = lt; r2 = (double)(totct - densityct) / lt; printf(" Mean: Number: %12ld, Proportion: %f\n",(long)floor(r2 + 0.5), 1.0 / r1); r2 = seqmax; printf(" Max: Number: %12ld, Proportion: %f\n",seqmax, r2 / r3); } if (ifilt != NULL) fclose(ifilt); if (ofil != NULL) fclose(ofil); exit(0); } /* End. */