4 /* version 3.6. (c) Copyright 1993-2005 by the University of Washington.
5 Written by Joseph Felsenstein, Akiko Fuseki, Sean Lamont, Andrew Keeffe,
7 Permission is granted to copy and use this program provided no fee is
8 charged for it and provided that this copyright notice is not removed. */
11 seqs, morphology, restsites, genefreqs
20 /* function prototypes */
21 void getoptions(void);
22 void seqboot_inputnumbers(void);
23 void seqboot_inputfactors(void);
24 void inputoptions(void);
25 void seqboot_inputdata(void);
28 void doinput(int argc, Char *argv[]);
29 void bootweights(void);
31 void charpermute(long, long);
33 void writeweights(void);
34 void writecategories(void);
35 void writeauxdata(steptr, FILE*);
36 void writefactors(void);
38 void seqboot_inputaux(steptr, FILE*);
39 /* function prototypes */
43 FILE *outcatfile, *outweightfile, *outmixfile, *outancfile, *outfactfile;
44 Char infilename[FNMLNGTH], outfilename[FNMLNGTH], catfilename[FNMLNGTH], outcatfilename[FNMLNGTH],
45 weightfilename[FNMLNGTH], outweightfilename[FNMLNGTH], mixfilename[FNMLNGTH], outmixfilename[FNMLNGTH], ancfilename[FNMLNGTH], outancfilename[FNMLNGTH],
46 factfilename[FNMLNGTH], outfactfilename[FNMLNGTH];
47 long sites, loci, maxalleles, groups, newsites, newersites,
48 newgroups, newergroups, nenzymes, reps, ws, blocksize, categs, maxnewsites;
49 boolean bootstrap, permute, ild, lockhart, jackknife, regular, xml, nexus,
50 weights, categories, factors, enzymes, all, justwts, progress, mixture,
55 steptr oldweight, where, how_many, newwhere, newhowmany,
56 newerwhere, newerhowmany, factorr, newerfactor, mixdata, ancdata;
68 /* interactively set options */
70 long inseed, inseed0, loopcount, loopcount2;
101 printf("\nBootstrapping algorithm, version %s\n\n",VERSION);
102 printf("Settings for this run:\n");
103 printf(" D Sequence, Morph, Rest., Gene Freqs? %s\n",
104 (data == seqs ) ? "Molecular sequences" :
105 (data == morphology ) ? "Discrete Morphology" :
106 (data == restsites) ? "Restriction Sites" :
107 (data == genefreqs) ? "Gene Frequencies" : "");
108 if (data == restsites)
109 printf(" E Number of enzymes? %s\n",
110 enzymes ? "Present in input file" :
111 "Not present in input file");
112 if (data == genefreqs)
113 printf(" A All alleles present at each locus? %s\n",
114 all ? "Yes" : "No, one absent at each locus");
115 if (data == morphology)
116 printf(" F Use factors information? %s\n",
117 factors ? "Yes" : "No");
119 printf(" J Bootstrap, Jackknife, Permute, Rewrite? %s\n",
120 regular && jackknife ? "Delete-half jackknife" :
121 (!regular) && jackknife ? "Delete-fraction jackknife" :
122 permute ? "Permute species for each character" :
123 ild ? "Permute character order" :
124 lockhart ? "Permute within species" :
125 regular && bootstrap ? "Bootstrap" :
126 (!regular) && bootstrap ? "Partial bootstrap" :
128 if (bootstrap || jackknife) {
131 printf(" Regular or altered sampling fraction? ");
135 if (fabs(fracsample*100 - (int)(fracsample*100)) > 0.01) {
137 printf("%2.1lf", 100.0*fracsample);
139 printf("%3.1lf", 100.0*fracsample);
140 } else { if (fracsample < 1)
141 printf("%2.0lf", 100.0*fracsample);
143 printf("%3.0lf", 100.0*fracsample);
146 printf(" sampled\n");
150 && !(jackknife || permute || bootstrap || ild || lockhart)) {
151 printf(" P PHYLIP, NEXUS, or XML output format? %s\n",
152 nexus ? "NEXUS" : xml ? "XML" : "PHYLIP");
153 if (xml || ((data == seqs) && nexus)) {
154 printf(" S Type of molecular sequences? " );
156 case (dna) : printf("DNA\n"); break;
157 case (rna) : printf("RNA\n"); break;
158 case (protein) : printf("Protein\n"); break;
162 if ((data == morphology) && !(jackknife || permute || ild
163 || lockhart || bootstrap))
164 printf(" P PHYLIP or NEXUS output format? %s\n",
165 nexus ? "NEXUS" : "PHYLIP");
168 printf(" B Block size for block-bootstrapping? %ld\n", blocksize);
170 printf(" B Block size for block-bootstrapping? %ld (regular bootstrap)\n", blocksize);
172 if (bootstrap || jackknife || permute || ild || lockhart)
173 printf(" R How many replicates? %ld\n", reps);
174 if (jackknife || bootstrap || permute) {
175 printf(" W Read weights of characters? %s\n",
176 (weights ? "Yes" : "No"));
177 if(data == morphology){
178 printf(" X Read mixture file? %s\n",
179 (mixture ? "Yes" : "No"));
180 printf(" N Read ancestors file? %s\n",
181 (ancvar ? "Yes" : "No"));
184 printf(" C Read categories of sites? %s\n",
185 (categories ? "Yes" : "No"));
187 printf(" S Write out data sets or just weights? %s\n",
188 (justwts ? "Just weights" : "Data sets"));
191 if (data == seqs || data == restsites)
192 printf(" I Input sequences interleaved? %s\n",
193 interleaved ? "Yes" : "No, sequential");
194 printf(" 0 Terminal type (IBM PC, ANSI, none)? %s\n",
195 ibmpc ? "IBM PC" : ansi ? "ANSI" : "(none)");
196 printf(" 1 Print out the data at start of run %s\n",
197 printdata ? "Yes" : "No");
199 printf(" . Use dot-differencing to display them %s\n",
200 dotdiff ? "Yes" : "No");
201 printf(" 2 Print indications of progress of run %s\n",
202 progress ? "Yes" : "No");
203 printf("\n Y to accept these or type the letter for one to change\n");
205 phyFillScreenColor();
207 scanf("%c%*[^\n]", &ch);
213 (bootstrap && (strchr("ABCDEFSJPRWXNI%1.20",ch) != NULL)) ||
214 (jackknife && (strchr("ACDEFSJPRWXNI%1.20",ch) != NULL)) ||
215 ((permute || ild || lockhart)
216 && (strchr("ACDEFSJPRXNI%1.20",ch) != NULL)) ||
217 ((!(bootstrap || jackknife || permute || ild || lockhart)) &&
218 ((!xml) && (strchr("ADEFJPI1.20",ch) != NULL))) ||
219 (((data == morphology) || (data == seqs))
220 && (nexus || xml) && (strchr("ADEFJPSI1.20",ch) != NULL))
225 if (data == genefreqs)
228 data = (datatype)((long)data + 1);
248 else if (jackknife) {
251 } else if (bootstrap) {
263 printf("Samples as percentage of");
264 if ((data == seqs) || (data == restsites))
266 if (data == morphology)
267 printf(" characters?\n");
268 if (data == genefreqs)
270 scanf("%lf%*[^\n]", &fracsample);
272 done1 = (fracsample > 0.0);
274 printf("BAD NUMBER: must be positive\n");
276 fracsample = fracsample/100.0;
277 countup(&loopcount2, 10);
278 } while (done1 != true);
294 if (data == morphology) {
301 if(jackknife || permute || bootstrap || ild || lockhart){
305 case (dna): seq = rna; break;
306 case (rna): seq = protein; break;
307 case (protein): seq = dna; break;
315 printf("Block size?\n");
317 phyFillScreenColor();
319 scanf("%ld%*[^\n]", &blocksize);
321 done1 = (blocksize > 0);
323 printf("BAD NUMBER: must be positive\n");
325 countup(&loopcount2, 10);
326 } while (done1 != true);
333 printf("Number of replicates?\n");
335 phyFillScreenColor();
337 scanf("%ld%*[^\n]", &reps);
341 printf("BAD NUMBER: must be positive\n");
344 countup(&loopcount2, 10);
345 } while (done1 != true);
361 categories = !categories;
369 interleaved = !interleaved;
373 initterminal(&ibmpc, &ansi);
377 printdata = !printdata;
385 progress = !progress;
389 printf("Not a possible option!\n");
390 countup(&loopcount, 100);
392 if (bootstrap || jackknife) {
393 if (jackknife && regular)
395 if (bootstrap && regular)
398 if (bootstrap || jackknife || permute || ild || lockhart)
399 initseed(&inseed, &inseed0, seed);
400 xml = xml && (data == seqs);
401 categories = categories && (data == seqs);
402 mixture = mixture && (data == morphology);
403 ancvar = ancvar && (data == morphology);
407 void seqboot_inputnumbers()
409 /* read numbers of species and of sites */
412 fscanf(infile, "%ld%ld", &spp, &sites);
415 if (data == restsites && enzymes)
416 fscanf(infile, "%ld", &nenzymes);
417 if (data == genefreqs) {
418 alleles = (long *)Malloc(sites*sizeof(long));
421 for (i = 0; i < (loci); i++) {
424 fscanf(infile, "%ld", &alleles[i]);
425 if (alleles[i] > maxalleles)
426 maxalleles = alleles[i];
430 sites += alleles[i] - 1;
436 } /* seqboot_inputnumbers */
439 void seqboot_inputfactors()
446 for (i = 0; i < (sites); i++) {
450 ch = gettc(factfile);
458 } /* seqboot_inputfactors */
463 /* input the information on the options */
464 long weightsum, maxfactsize, i, j, k, l, m;
466 if (data == genefreqs) {
469 for (i = 0; i < (loci); i++) {
475 for (j = 1; j <= m; j++) {
481 for (i = 1; i <= (sites); i++)
485 seqboot_inputfactors();
487 for (i = 0; i < (sites); i++)
490 inputweights2(0, sites, &weightsum, oldweight, &weights, "seqboot");
491 if (factors && printdata) {
492 for(i = 0; i < sites; i++)
493 factor[i] = (char)('0' + (factorr[i]%10));
494 printfactors(outfile, sites, factor, " (least significant digit)");
496 if (weights && printdata)
497 printweights(outfile, 0, sites, oldweight, "Sites");
498 for (i = 0; i < (loci); i++)
500 for (i = 0; i < (loci); i++)
502 for (i = 1; i <= (sites); i++) {
503 how_many[factorr[i - 1] - 1]++;
504 if (where[factorr[i - 1] - 1] == 0)
505 where[factorr[i - 1] - 1] = i;
507 groups = factorr[sites - 1];
511 for(i = 0 ; i < loci ; i++){
512 if(how_many[i] > maxfactsize){
513 maxfactsize = how_many[i];
516 maxnewsites = groups * maxfactsize;
518 for (i = 0; i < (groups); i++) {
519 if (oldweight[where[i] - 1] > 0) {
521 newsites += how_many[i];
522 newwhere[newgroups - 1] = where[i];
523 newhowmany[newgroups - 1] = how_many[i];
529 void seqboot_inputdata()
531 /* input the names and sequences for each species */
532 long i, j, k, l, m, n, basesread, basesnew=0;
535 boolean allread, done;
537 if (data == genefreqs) {
538 nodef = (double **)Malloc(spp*sizeof(double *));
539 for (i = 0; i < (spp); i++)
540 nodef[i] = (double *)Malloc(sites*sizeof(double));
542 nodep = (Char **)Malloc(spp*sizeof(Char *));
543 for (i = 0; i < (spp); i++)
544 nodep[i] = (Char *)Malloc(sites*sizeof(Char));
546 j = nmlngth + (sites + (sites - 1) / 10) / 2 - 5;
552 fprintf(outfile, "\nBootstrapping algorithm, version %s\n\n\n",VERSION);
556 fprintf(outfile, "Block-bootstrap with block size %ld\n\n", blocksize);
558 fprintf(outfile, "Partial (%2.0f%%) block-bootstrap with block size %ld\n\n",
559 100*fracsample, blocksize);
562 fprintf(outfile, "Bootstrap\n\n");
564 fprintf(outfile, "Partial (%2.0f%%) bootstrap\n\n", 100*fracsample);
569 fprintf(outfile, "Delete-half Jackknife\n\n");
571 fprintf(outfile, "Delete-%2.0f%% Jackknife\n\n", 100*(1.0-fracsample));
574 fprintf(outfile, "Species order permuted separately for each");
575 if (data == genefreqs)
576 fprintf(outfile, " locus\n\n");
578 fprintf(outfile, " site\n\n");
579 if (data == morphology)
580 fprintf(outfile, " character\n\n");
581 if (data == restsites)
582 fprintf(outfile, " site\n\n");
586 if (data == genefreqs)
587 fprintf(outfile, "Locus");
589 fprintf(outfile, "Site");
590 if (data == morphology)
591 fprintf(outfile, "Character");
592 if (data == restsites)
593 fprintf(outfile, "Site");
594 fprintf(outfile, " order permuted\n\n");
597 if (data == genefreqs)
598 fprintf(outfile, "Locus");
600 fprintf(outfile, "Site");
601 if (data == morphology)
602 fprintf(outfile, "Character");
603 if (data == restsites)
604 fprintf(outfile, "Site");
605 fprintf(outfile, " order permuted separately for each species\n\n");
610 if (data == genefreqs)
611 fprintf(outfile, "%3ld species, %3ld loci\n\n", spp, loci);
613 fprintf(outfile, "%3ld species, ", spp);
615 fprintf(outfile, "%3ld sites\n\n", sites);
616 else if (data == morphology)
617 fprintf(outfile, "%3ld characters\n\n", sites);
618 else if (data == restsites)
619 fprintf(outfile, "%3ld sites\n\n", sites);
621 fprintf(outfile, "Name");
622 for (i = 1; i <= j; i++)
624 fprintf(outfile, "Data\n");
625 fprintf(outfile, "----");
626 for (i = 1; i <= j; i++)
628 fprintf(outfile, "----\n\n");
630 interleaved = (interleaved && ((data == seqs) || (data == restsites)));
631 if (data == genefreqs) {
632 for (i = 1; i <= (spp); i++) {
635 while (j <= sites && !eoff(infile)) {
638 fscanf(infile, "%lf", &x);
639 if ((unsigned)x > 1.0) {
640 printf("GENE FREQ OUTSIDE [0,1] in species %ld\n", i);
643 nodef[i - 1][j - 1] = x;
654 /* eat white space -- if the separator line has spaces on it*/
656 charstate = gettc(infile);
657 } while (charstate == ' ' || charstate == '\t');
658 ungetc(charstate, infile);
663 if ((interleaved && basesread == 0) || !interleaved)
665 j = interleaved ? basesread : 0;
667 while (!done && !eoff(infile)) {
670 while (j < sites && !(eoln(infile) ||eoff(infile))) {
671 charstate = gettc(infile);
672 if (charstate == '\n' || charstate == '\t')
674 if (charstate == ' ' ||
675 (data == seqs && charstate >= '0' && charstate <= '9'))
677 uppercase(&charstate);
679 if (charstate == '.')
680 charstate = nodep[0][j-1];
681 nodep[i-1][j-1] = charstate;
690 if (interleaved && i == 1)
693 if ((interleaved && j != basesnew) || ((!interleaved) && j != sites)){
694 printf("\n\nERROR: sequences out of alignment at site %ld", j+1);
695 printf(" of species %ld\n\n", i);
700 basesread = basesnew;
701 allread = (basesread == sites);
707 if (data == genefreqs)
708 m = (sites - 1) / 8 + 1;
710 m = (sites - 1) / 60 + 1;
711 for (i = 1; i <= m; i++) {
712 for (j = 0; j < spp; j++) {
713 for (k = 0; k < nmlngth; k++)
714 putc(nayme[j][k], outfile);
715 fprintf(outfile, " ");
716 if (data == genefreqs)
722 if (data == genefreqs)
726 for (k = n; k < l; k++) {
727 if (data == genefreqs)
728 fprintf(outfile, "%8.5f", nodef[j][k]);
730 if (j + 1 > 1 && nodep[j][k] == nodep[0][k])
733 charstate = nodep[j][k];
734 putc(charstate, outfile);
735 if ((k + 1) % 10 == 0 && (k + 1) % 60 != 0)
745 } /* seqboot_inputdata */
749 { /* allocate memory for bookkeeping arrays */
751 oldweight = (steptr)Malloc(sites*sizeof(long));
752 weight = (steptr)Malloc(sites*sizeof(long));
754 category = (steptr)Malloc(sites*sizeof(long));
756 mixdata = (steptr)Malloc(sites*sizeof(long));
758 ancdata = (steptr)Malloc(sites*sizeof(long));
759 where = (steptr)Malloc(loci*sizeof(long));
760 how_many = (steptr)Malloc(loci*sizeof(long));
761 factor = (Char *)Malloc(sites*sizeof(Char));
762 factorr = (steptr)Malloc(sites*sizeof(long));
763 nayme = (naym *)Malloc(spp*sizeof(naym));
767 { /* allocate memory for arrays that depend on the lenght of the
771 newwhere = (steptr)Malloc(loci*sizeof(long));
772 newhowmany = (steptr)Malloc(loci*sizeof(long));
773 newerwhere = (steptr)Malloc(loci*sizeof(long));
774 newerhowmany = (steptr)Malloc(loci*sizeof(long));
775 newerfactor = (steptr)Malloc(maxnewsites*maxalleles*sizeof(long));
776 charorder = (steptr *)Malloc(spp*sizeof(steptr));
777 for (i = 0; i < spp; i++)
778 charorder[i] = (steptr)Malloc(maxnewsites*sizeof(long));
781 void doinput(int argc, Char *argv[])
782 { /* reads the input data */
784 seqboot_inputnumbers();
787 openfile(&weightfile,WEIGHTFILE,"input weight file",
788 "r",argv[0],weightfilename);
790 openfile(&mixfile,MIXFILE,"mixture file", "r",argv[0],mixfilename);
791 openfile(&outmixfile,"outmixture","output mixtures file","w",argv[0],
793 seqboot_inputaux(mixdata, mixfile);
796 openfile(&ancfile,ANCFILE,"ancestor file", "r",argv[0],ancfilename);
797 openfile(&outancfile,"outancestors","output ancestors file","w",argv[0],
799 seqboot_inputaux(ancdata, ancfile);
802 openfile(&catfile,CATFILE,"input category file","r",argv[0],catfilename);
803 openfile(&outcatfile,"outcategories","output category file","w",argv[0],
805 inputcategs(0, sites, category, 9, "SeqBoot");
808 openfile(&factfile,FACTFILE,"factors file","r",argv[0],factfilename);
809 openfile(&outfactfile,"outfactors","output factors file","w",argv[0],
812 if (justwts && !permute)
813 openfile(&outweightfile,"outweights","output weight file",
814 "w",argv[0],outweightfilename);
816 openfile(&outfile,OUTFILE,"output data file","w",argv[0],outfilename);
824 { /* sets up weights by resampling data */
825 long i, j, k, blocks;
829 for (i = 0; i < (ws); i++)
832 if (fabs(newgroups*fracsample - (long)(newgroups*fracsample+0.5))
835 < (newgroups*fracsample - (long)(newgroups*fracsample))
836 /((long)(newgroups*fracsample+1.0)-(long)(newgroups*fracsample)))
837 q = (long)(newgroups*fracsample)+1;
839 q = (long)(newgroups*fracsample);
841 q = (long)(newgroups*fracsample+0.5);
845 for (i = 0; i < (newgroups); i++) {
846 if (randum(seed) < p) {
852 if (i + 1 < newgroups)
855 } else if (permute) {
856 for (i = 0; i < (newgroups); i++)
858 } else if (bootstrap) {
859 blocks = fracsample * newgroups / blocksize;
860 for (i = 1; i <= (blocks); i++) {
861 j = (long)(newgroups * randum(seed)) + 1;
862 for (k = 0; k < blocksize; k++) {
869 } else /* case of rewriting data */
870 for (i = 0; i < (newgroups); i++)
872 for (i = 0; i < (newgroups); i++)
874 for (i = 0; i < (newgroups); i++)
878 for (i = 0; i < (newgroups); i++) {
879 for (j = 1; j <= (weight[i]); j++) {
881 for (k = 1; k <= (newhowmany[i]); k++) {
883 newerfactor[newersites - 1] = newergroups;
885 newerwhere[newergroups - 1] = newwhere[i];
886 newerhowmany[newergroups - 1] = newhowmany[i];
892 void sppermute(long n)
893 { /* permute the species order as given in array sppord */
896 for (i = 1; i <= (spp - 1); i++) {
897 k = (long)((i+1) * randum(seed));
898 j = sppord[n - 1][i];
899 sppord[n - 1][i] = sppord[n - 1][k];
900 sppord[n - 1][k] = j;
905 void charpermute(long m, long n)
906 { /* permute the n+1 characters of species m+1 */
909 for (i = 1; i <= (n-1); i++) {
910 k = (long)((i+1) * randum(seed));
912 charorder[m][i] = charorder[m][k];
920 /* write out one set of bootstrapped sequences */
921 long i, j, k, l, m, n, n2;
925 sppord = (long **)Malloc(newergroups*sizeof(long *));
926 for (i = 0; i < (newergroups); i++)
927 sppord[i] = (long *)Malloc(spp*sizeof(long));
928 for (j = 1; j <= spp; j++)
929 sppord[0][j - 1] = j;
930 for (i = 1; i < newergroups; i++) {
931 for (j = 1; j <= (spp); j++)
932 sppord[i][j - 1] = sppord[i - 1][j - 1];
934 if (!justwts || permute) {
935 if (data == restsites && enzymes)
936 fprintf(outfile, "%5ld %5ld% 4ld\n", spp, newergroups, nenzymes);
937 else if (data == genefreqs)
938 fprintf(outfile, "%5ld %5ld\n", spp, newergroups);
941 && !(bootstrap || jackknife || permute || ild || lockhart) && xml)
942 fprintf(outfile, "<alignment>\n");
944 if (!(bootstrap || jackknife || permute || ild || lockhart) && nexus) {
945 fprintf(outfile, "#NEXUS\n");
946 fprintf(outfile, "BEGIN DATA;\n");
947 fprintf(outfile, " DIMENSIONS NTAX=%ld NCHAR=%ld;\n",
949 fprintf(outfile, " FORMAT");
951 fprintf(outfile, " interleave=yes");
953 fprintf(outfile, " interleave=no");
954 fprintf(outfile, " DATATYPE=");
957 case (dna): fprintf(outfile, "DNA missing=N gap=-"); break;
958 case (rna): fprintf(outfile, "RNA missing=N gap=-"); break;
960 fprintf(outfile, "protein missing=? gap=-");
964 if (data == morphology)
965 fprintf(outfile, "STANDARD");
966 fprintf(outfile, ";\n MATRIX\n");
968 else fprintf(outfile, "%5ld %5ld\n", spp, newersites);
970 if (data == genefreqs) {
971 for (i = 0; i < (newergroups); i++)
972 fprintf(outfile, " %3ld", alleles[factorr[newerwhere[i] - 1] - 1]);
977 if ((!(bootstrap || jackknife || permute || ild || lockhart | nexus))
978 && ((data == seqs) || (data == restsites))) {
979 interleaved = !interleaved;
980 if (!(bootstrap || jackknife || permute || ild || lockhart) && xml)
990 for (j = 0; j < spp; j++) {
992 if ((l == 1) || (interleaved && nexus)) {
993 if (!(bootstrap || jackknife || permute || ild || lockhart) && xml) {
994 fprintf(outfile, " <sequence");
996 case (dna): fprintf(outfile, " type=\"dna\""); break;
997 case (rna): fprintf(outfile, " type=\"rna\""); break;
998 case (protein): fprintf(outfile, " type=\"protein\""); break;
1000 fprintf(outfile, ">\n");
1001 fprintf(outfile, " <name>");
1004 if (!(bootstrap || jackknife || permute || ild || lockhart)
1005 && (xml || nexus)) {
1006 while (nayme[j][n2-1] == ' ')
1010 fprintf(outfile, " ");
1011 for (k = 0; k < n2; k++)
1012 if (nexus && (nayme[j][k] == ' ') && (k < n2))
1015 putc(nayme[j][k], outfile);
1016 if (!(bootstrap || jackknife || permute || ild || lockhart) && xml)
1017 fprintf(outfile, "</name>\n <data>");
1019 if (!(bootstrap || jackknife || permute || ild || lockhart) && xml) {
1020 fprintf(outfile, " ");
1023 for (k = 1; k <= nmlngth; k++)
1028 for (k = 0; k < nmlngth-n2; k++)
1029 fprintf(outfile, " ");
1030 fprintf(outfile, " ");
1032 for (k = l - 1; k < m; k++) {
1033 if (permute && j + 1 == 1)
1034 sppermute(newerfactor[n]); /* we can assume chars not permuted */
1035 for (n2 = -1; n2 <= (newerhowmany[k] - 2); n2++) {
1037 if (data == genefreqs) {
1038 if (n > 1 && (n & 7) == 1)
1039 fprintf(outfile, "\n ");
1040 x = nodef[sppord[newerfactor[charorder[j][n - 1]] - 1][j] - 1]
1041 [newerwhere[charorder[j][k]] + n2];
1042 fprintf(outfile, "%8.5f", x);
1044 if (!(bootstrap || jackknife || permute || ild || lockhart) && xml
1045 && (n > 1) && (n % 60 == 1))
1046 fprintf(outfile, "\n ");
1047 else if (!nexus && !interleaved && (n > 1) && (n % 60 == 1))
1048 fprintf(outfile, "\n ");
1049 charstate = nodep[sppord[newerfactor[charorder[j][n - 1]] - 1]
1050 [j] - 1][newerwhere[charorder[j][k]] + n2];
1051 putc(charstate, outfile);
1052 if (n % 10 == 0 && n % 60 != 0)
1057 if (!(bootstrap || jackknife || permute || ild || lockhart ) && xml) {
1058 fprintf(outfile, "</data>\n </sequence>\n");
1060 putc('\n', outfile);
1063 if ((m <= newersites) && (newersites > 60))
1064 putc('\n', outfile);
1068 } while (interleaved && l <= newersites);
1069 if ((data == seqs) &&
1070 (!(bootstrap || jackknife || permute || ild || lockhart) && xml))
1071 fprintf(outfile, "</alignment>\n");
1072 if (!(bootstrap || jackknife || permute || ild || lockhart) && nexus)
1073 fprintf(outfile, " ;\nEND;\n");
1074 for (i = 0; i < (newergroups); i++)
1081 { /* write out one set of post-bootstrapping weights */
1082 long j, k, l, m, n, o;
1094 for (k = l - 1; k < m; k++) {
1095 for(o = 0 ; o < how_many[k] ; o++){
1096 if(oldweight[k]==0){
1097 fprintf(outweightfile, "0");
1101 if (weight[k-j] < 10)
1102 fprintf(outweightfile, "%c", (char)('0'+weight[k-j]));
1104 fprintf(outweightfile, "%c", (char)('A'+weight[k-j]-10));
1106 if (!interleaved && n > 1 && n % 60 == 1) {
1107 fprintf(outweightfile, "\n");
1108 if (n % 10 == 0 && n % 60 != 0)
1109 putc(' ', outweightfile);
1114 putc('\n', outweightfile);
1119 } while (interleaved && l <= sites);
1120 } /* writeweights */
1123 void writecategories()
1125 /* write out categories for the bootstrapped sequences */
1126 long k, l, m, n, n2;
1138 for(k=l-1 ; k < m ; k++){
1140 if (!interleaved && n > 1 && n % 60 == 1)
1141 fprintf(outcatfile, "\n ");
1142 charstate = '0' + category[k];
1143 putc(charstate, outcatfile);
1149 }while(interleaved && l <= sites);
1150 fprintf(outcatfile, "\n");
1160 if (m > newergroups)
1163 for (k = l - 1; k < m; k++) {
1164 for (n2 = -1; n2 <= (newerhowmany[k] - 2); n2++) {
1166 if (!interleaved && n > 1 && n % 60 == 1)
1167 fprintf(outcatfile, "\n ");
1168 charstate = '0' + category[newerwhere[k] + n2];
1169 putc(charstate, outcatfile);
1170 if (n % 10 == 0 && n % 60 != 0)
1171 putc(' ', outcatfile);
1178 } while (interleaved && l <= newersites);
1179 fprintf(outcatfile, "\n");
1180 } /* writecategories */
1183 void writeauxdata(steptr auxdata, FILE *outauxfile)
1185 /* write out auxiliary option data (mixtures, ancestors, ect) to
1186 appropriate file. Samples parralel to data, or just gives one
1187 output entry if justwts is true */
1188 long k, l, m, n, n2;
1191 /* if we just output weights (justwts), and this is first set
1192 just output the data unsampled */
1204 for(k=l-1 ; k < m ; k++){
1206 if (!interleaved && n > 1 && n % 60 == 1)
1207 fprintf(outauxfile, "\n ");
1208 charstate = auxdata[k];
1209 putc(charstate, outauxfile);
1215 }while(interleaved && l <= sites);
1216 fprintf(outauxfile, "\n");
1227 if (m > newergroups)
1230 for (k = l - 1; k < m; k++) {
1231 for (n2 = -1; n2 <= (newerhowmany[k] - 2); n2++) {
1233 if (!interleaved && n > 1 && n % 60 == 1)
1234 fprintf(outauxfile, "\n ");
1235 charstate = auxdata[newerwhere[k] + n2];
1236 putc(charstate, outauxfile);
1237 if (n % 10 == 0 && n % 60 != 0)
1238 putc(' ', outauxfile);
1245 } while (interleaved && l <= newersites);
1246 fprintf(outauxfile, "\n");
1247 } /* writeauxdata */
1249 void writefactors(void)
1251 long k, l, m, n, prevfact, writesites;
1255 if(!justwts || firstrep){
1260 writesites = newersites;
1261 wfactor = newerfactor;
1263 prevfact = wfactor[0];
1274 for(k=l-1 ; k < m ; k++){
1276 if (!interleaved && n > 1 && n % 60 == 1)
1277 fprintf(outfactfile, "\n ");
1278 if(prevfact != wfactor[k]){
1279 symbol = (symbol == '+') ? '-' : '+';
1280 prevfact = wfactor[k];
1282 putc(symbol, outfactfile);
1283 if (n % 10 == 0 && n % 60 != 0)
1284 putc(' ', outfactfile);
1290 }while(interleaved && l <= writesites);
1291 fprintf(outfactfile, "\n");
1293 } /* writefactors */
1297 { /* does bootstrapping and writes out data sets */
1298 long i, j, rr, repdiv10;
1300 if (!(bootstrap || jackknife || permute || ild || lockhart))
1302 repdiv10 = reps / 10;
1307 for (rr = 1; rr <= (reps); rr++) {
1308 for (i = 0; i < spp; i++)
1309 for (j = 0; j < maxnewsites; j++)
1310 charorder[i][j] = j;
1316 charpermute(0, maxnewsites);
1317 for (i = 1; i < spp; i++)
1318 for (j = 0; j < maxnewsites; j++)
1319 charorder[i][j] = charorder[0][j];
1322 for (i = 0; i < spp; i++)
1323 charpermute(i, maxnewsites);
1325 if (!justwts || permute || ild || lockhart)
1327 if (justwts && !(permute || ild || lockhart))
1334 writeauxdata(mixdata, outmixfile);
1336 writeauxdata(ancdata, outancfile);
1337 if (progress && (bootstrap || jackknife || permute || ild || lockhart)
1338 && ((reps < 10) || rr % repdiv10 == 0)) {
1339 printf("completed replicate number %4ld\n", rr);
1341 phyFillScreenColor();
1347 printf("\nOutput weights written to file \"%s\"\n\n", outweightfilename);
1349 printf("\nOutput written to file \"%s\"\n\n", outfilename);
1354 void seqboot_inputaux(steptr dataptr, FILE* auxfile)
1355 { /* input auxiliary option data (mixtures, ancestors, ect) for
1356 new style input, assumes that data is correctly formated
1363 for (i = 0; i < (sites); i++) {
1367 ch = gettc(auxfile);
1370 } while (ch == ' ');
1374 } /* seqboot_inputaux */
1377 int main(int argc, Char *argv[])
1378 { /* Read in sequences or frequencies and bootstrap or jackknife them */
1380 argc = 1; /* macsetup("SeqBoot",""); */
1381 argv[0] = "SeqBoot";
1384 openfile(&infile, INFILE, "input file", "r", argv[0], infilename);
1387 doinput(argc, argv);
1400 if (justwts && !permute) {
1401 FClose(outweightfile);
1406 fixmacfile(outfilename);
1407 if (justwts && !permute)
1408 fixmacfile(outweightfilename);
1410 fixmacfile(outcatfilename);
1412 fixmacfile(outmixfilename);
1414 printf("Done.\n\n");
1416 phyRestoreConsoleAttributes();