예제 #1
0
void help(const char *letters)
{
    /* display help information */
    char input[100];

    printf("\n\nR Rearrange a tree by moving a node or group\n");
    printf("# Show the states of the next %s that doesn't fit tree\n", letters);
    printf("+ Show the states of the next %s\n", letters);
    printf("-         ...     of the previous %s\n", letters);
    printf("S Show the states of a given %s\n", letters);
    printf(". redisplay the same tree again\n");
    printf("T Try all possible positions of a node or group\n");
    printf("U Undo the most recent rearrangement\n");
    printf("W Write tree to a file\n");
    printf("O select an Outgroup for the tree\n");
    printf("F Flip (rotate) branches at a node\n");
    printf("H Move viewing window to the left\n");
    printf("J Move viewing window downward\n");
    printf("K Move viewing window upward\n");
    printf("L Move viewing window to the right\n");
    printf("C show only one Clade (subtree) (useful if tree is too big)\n");
    printf("? Help (this screen)\n");
    printf("Q (Quit) Exit from program\n");
    printf("X Exit from program\n\n\n");
    printf("TO CONTINUE, PRESS ON THE Return OR Enter KEY");
#ifdef WIN32
    phyFillScreenColor();
#endif
    fflush(stdout);
    getstryng(input);
}  /* help */
예제 #2
0
void makedists()
{
  /* compute distance matrix */
  long i, j;
  double v;

  if (progress) {
    printf("Distances calculated for species\n");
#ifdef WIN32
    phyFillScreenColor();
#endif
  }
  for (i = 0; i < spp; i++)
    d[i][i] = 0.0;
  for (i = 1; i < spp; i++) {
    if (progress) {
      printf("    ");
      for (j = 0; j < nmlngth; j++)
        putchar(nayme[i - 1][j]);
      printf("   ");
    }
    for (j = i + 1; j <= spp; j++) {
      makev(i, j, &v);
      d[i - 1][j - 1] = v;
      d[j - 1][i - 1] = v;
      if (progress)
        putchar('.');
    }
    if (progress) {
      putchar('\n');
#ifdef WIN32
      phyFillScreenColor();
#endif
    }
  }
  if (progress) {
    printf("    ");
    for (j = 0; j < nmlngth; j++)
      putchar(nayme[spp - 1][j]);
    putchar('\n');
#ifdef WIN32
    phyFillScreenColor();
#endif
  }
}  /* makedists */
예제 #3
0
void bootwrite()
{ /* does bootstrapping and writes out data sets */
  long i, j, rr, repdiv10;

  if (!(bootstrap || jackknife || permute || ild || lockhart))
    reps = 1;
  repdiv10 = reps / 10;
  if (repdiv10 < 1)
    repdiv10 = 1;
  if (progress)
    putchar('\n');
  for (rr = 1; rr <= (reps); rr++) {
    for (i = 0; i < spp; i++)
      for (j = 0; j < maxnewsites; j++)
        charorder[i][j] = j;
    if(rr==1)
      firstrep = true;
    else
      firstrep = false;
    if (ild) {
      charpermute(0, maxnewsites);
      for (i = 1; i < spp; i++)
        for (j = 0; j < maxnewsites; j++)
          charorder[i][j] = charorder[0][j];
    }
    if (lockhart)
      for (i = 0; i < spp; i++)
        charpermute(i, maxnewsites);
    bootweights();
    if (!justwts || permute || ild || lockhart)
      writedata();
    if (justwts && !(permute || ild || lockhart))
      writeweights();
    if (categories)
      writecategories();
    if (factors)
      writefactors();
    if (mixture)
      writeauxdata(mixdata, outmixfile);
    if (ancvar)
      writeauxdata(ancdata, outancfile);
    if (progress && (bootstrap || jackknife || permute || ild || lockhart)
          && ((reps < 10) || rr % repdiv10 == 0)) {
      printf("completed replicate number %4ld\n", rr);
#ifdef WIN32
      phyFillScreenColor();
#endif
    }
  }
  if (progress) {
    if (justwts)
      printf("\nOutput weights written to file \"%s\"\n\n", outweightfilename);
    else
      printf("\nOutput written to file \"%s\"\n\n", outfilename);
  }
}  /* bootwrite */
예제 #4
0
void treeoptions(boolean waswritten, Char *ch, FILE **outtree,
                 Char *outtreename, Char *progname)
{   /* interactively get options for writing a tree */
    char input[100];

    if (waswritten) {
        printf("\nTree file already was open.\n");
        printf("   A   Add to this tree to tree file\n");
        printf("   R   Replace tree file contents by this tree\n");
        printf("   F   Write out tree to a different tree file\n");
        printf("   N   Do Not write out this tree\n");
        do {
            printf("Which should we do? ");
#ifdef WIN32
            phyFillScreenColor();
#endif
            fflush(stdout);
            getstryng(input);
            *ch  = input[0];
            uppercase(ch);
        } while (*ch != 'A' && *ch != 'R' && *ch != 'N' && *ch != 'F');
    }
    if (*ch == 'F') {
        outtreename[0] = '\0';
        while (outtreename[0] =='\0') {
            printf("Please enter a tree file name>");
#ifdef MAC
            fixmacfile(outtreename);
#endif
#ifdef WIN32
            phyFillScreenColor();
#endif
            fflush(stdout);
            getstryng(outtreename);
        }
        FClose(*outtree);
    }
    if (*ch == 'R' || *ch == 'A' || *ch == 'F' || !waswritten) {
        openfile(outtree,outtreename,"output tree file",
                 (*ch == 'A' && waswritten) ? "a" : "w",
                 progname,outtreename);
    }
}  /* treeoptions */
예제 #5
0
void inpnum(long *n, boolean *success)
{
    /* used by dnamove, dolmove, move, & retree */
    int fields;
    char line[100];

#ifdef WIN32
    phyFillScreenColor();
#endif
    fflush(stdout);
    getstryng(line);
    *n = atof(line);
    fields = sscanf(line,"%ld",n);
    *success = (fields == 1);
}  /* inpnum */
예제 #6
0
파일: penny.c 프로젝트: uw-loci/ome-server
void addtraverse(node2 *a, node2 *b, node2 *c, long *m, long *n,
                 valptr valyew, placeptr place)
{
    /* traverse all places to add b */
    if (done)
        return;
    if ((*m) <= 2 || !(noroot && (a == root || a == root->next->back))) {
        add3(a, b, c, &root, treenode);
        (*n)++;
        evaluate(root);
        examined++;
        if (examined == howoften) {
            examined = 0;
            mults++;
            if (mults == howmanny)
                done = true;
            if (progress) {
                printf("%6ld", mults);
                if (bestyet >= 0)
                    printf("%18.5f", bestyet);
                else
                    printf("         -        ");
                printf("%17ld%20.2f\n", nextree - 1, fracdone * 100);
#ifdef WIN32
                phyFillScreenColor();
#endif
            }
        }
        valyew[(*n) - 1] = like;
        place[(*n) - 1] = a->index;
        re_move3(&b, &c, &root, treenode);
    }
    if (!a->tip) {
        addtraverse(a->next->back, b, c, m,n,valyew,place);
        addtraverse(a->next->next->back, b, c, m,n,valyew,place);
    }
}  /* addtraverse */
예제 #7
0
void maketree()
{
  /* contruct the tree */
  long nextsp,numtrees;
  boolean succeeded=false;
  long i, j, which;

  if (usertree) {
    inputdata(replicates, printdata, lower, upper, x, reps);
    setuptree(&curtree, nonodes2);
    for (which = 1; which <= spp; which++)
      setuptipf(which, &curtree);
    if (eoln(infile)) {
      fscanf(infile, "%*[^\n]");
      getc(infile);
    }
    openfile(&intree,INTREE,"input tree file","r",progname,intreename);
    fscanf(intree, "%ld%*[^\n]", &numtrees);
    getc(intree);
    if (numtrees > MAXNUMTREES) {
      printf("\nERROR: number of input trees is read incorrectly from %s\n",
        intreename);
      exxit(-1);
    }
    if (treeprint) {
      fprintf(outfile, "User-defined tree");
      if (numtrees > 1)
        putc('s', outfile);
      fprintf(outfile, ":\n\n");
    }
    first = true;
    which = 1;
    while (which <= numtrees) {
      treeread2 (intree, &curtree.start, curtree.nodep,
        lengths, &trweight, &goteof, intreename, "Fitch",
        &haslengths, &spp);
      nums = spp;
      curtree.start = curtree.nodep[outgrno - 1]->back;
      treevaluate();
      printree(&curtree, curtree.start, treeprint, false, false);
      summarize(numtrees);
      which++;
    }
    FClose(intree);
  } else {
    if (jumb == 1) {
      inputdata(replicates, printdata, lower, upper, x, reps);
      setuptree(&curtree, nonodes2);
      setuptree(&priortree, nonodes2);
      setuptree(&bestree, nonodes2);
      if (njumble > 1) setuptree(&bestree2, nonodes2);
    }
    for (i = 1; i <= spp; i++)
      enterorder[i - 1] = i;
    if (jumble)
      randumize(seed, enterorder);
    nextsp = 3;
    buildsimpletree(&curtree, nextsp);
    curtree.start = curtree.nodep[enterorder[0] - 1]->back;
    if (jumb == 1) numtrees = 1;
    nextsp = 4;
    if (progress) {
      printf("Adding species:\n");
      writename(0, 3, enterorder);
#ifdef WIN32
      phyFillScreenColor();
#endif
    }
    while (nextsp <= spp) {
      nums = nextsp;
      buildnewtip(enterorder[nextsp - 1], &curtree, nextsp);
      copy_(&curtree, &priortree);
      bestree.likelihood = -99999.0;
      addtraverse(curtree.nodep[enterorder[nextsp - 1] - 1]->back,
                  curtree.start, true, &numtrees,&succeeded);
      copy_(&bestree, &curtree);
      if (progress) {
        writename(nextsp  - 1, 1, enterorder);
#ifdef WIN32
        phyFillScreenColor();
#endif
      }
      if (global && nextsp == spp) {
        if (progress) {
          printf("Doing global rearrangements\n");
          printf("  !");
          for (j = 1; j <= (spp - 2); j++)
            putchar('-');
          printf("!\n");
          printf("   ");
        }
      }
      succeeded = true;
      while (succeeded) {
        succeeded = false;
        rearrange(curtree.start,
                  &numtrees,&nextsp,&succeeded);
        if (global && ((nextsp) == spp) && progress)
          printf("\n   ");
      }
      if (global && nextsp == spp) {
        putc('\n', outfile);
        if (progress)
          putchar('\n');
      }
      if (njumble > 1) {
        if (jumb == 1 && nextsp == spp)
          copy_(&bestree, &bestree2);
        else if (nextsp == spp) {
          if (bestree2.likelihood < bestree.likelihood)
            copy_(&bestree, &bestree2);
        }
      }
      if (nextsp == spp && jumb == njumble) {
        if (njumble > 1) copy_(&bestree2, &curtree);
        curtree.start = curtree.nodep[outgrno - 1]->back;
        printree(&curtree, curtree.start, treeprint, true, false);
        summarize(numtrees);
      }
      nextsp++;
    }
  }
  if (jumb == njumble && progress) {
    printf("\nOutput written to output file\n\n");
    if (trout) {
      printf("Tree also written onto file\n");
      putchar('\n');
    }
  }
}  /* maketree */
예제 #8
0
void getoptions()
{
  /* interactively set options */
  long inseed0=0;
  Char ch;
  boolean done=false;

  putchar('\n');
  minev = false;
  global = false;
  jumble = false;
  njumble = 1;
  lengths = false;
  lower = false;
  negallowed = false;
  outgrno = 1;
  outgropt = false;
  power = 2.0;
  replicates = false;
  trout = true;
  upper = false;
  usertree = false;
  printdata = false;
  progress = true;
  treeprint = true;
  do {
    cleerhome();
    printf("\nFitch-Margoliash method version %s\n\n",VERSION);
    printf("Settings for this run:\n");
    printf("  D      Method (F-M, Minimum Evolution)?  %s\n",
	     (minev ? "Minimum Evolution" : "Fitch-Margoliash"));
    printf("  U                 Search for best tree?  %s\n",
	   (usertree ? "No, use user trees in input file" : "Yes"));
    if (usertree) {
      printf("  N          Use lengths from user trees?  %s\n",
	     (lengths ? "Yes" : "No"));
    }
    printf("  P                                Power?%9.5f\n",power);
    printf("  -      Negative branch lengths allowed?  %s\n",
	   negallowed ? "Yes" : "No");
    printf("  O                        Outgroup root?");
    if (outgropt)
      printf("  Yes, at species number%3ld\n", outgrno);
    else
      printf("  No, use as outgroup species%3ld\n", outgrno);
    printf("  L         Lower-triangular data matrix?");
    if (lower)
      printf("  Yes\n");
    else
      printf("  No\n");
    printf("  R         Upper-triangular data matrix?");
    if (upper)
      printf("  Yes\n");
    else
      printf("  No\n");
    printf("  S                        Subreplicates?");
    if (replicates)
      printf("  Yes\n");
    else
      printf("  No\n");
    if (!usertree) {
      printf("  G                Global rearrangements?");
      if (global)
        printf("  Yes\n");
      else
        printf("  No\n");
      printf("  J     Randomize input order of species?");
      if (jumble)
        printf("  Yes (seed =%8ld,%3ld times)\n", inseed0, njumble);
      else
        printf("  No. Use input order\n");
    }
    printf("  M           Analyze multiple data sets?");
    if (mulsets)
      printf("  Yes, %2ld sets\n", datasets);
    else
      printf("  No\n");
    printf("  0   Terminal type (IBM PC, ANSI, none)?");
    if (ibmpc)
      printf("  IBM PC\n");
    if (ansi)
      printf("  ANSI\n");
    if (!(ibmpc || ansi))
      printf("  (none)\n");
    printf("  1    Print out the data at start of run");
    if (printdata)
      printf("  Yes\n");
    else
      printf("  No\n");
    printf("  2  Print indications of progress of run");
    if (progress)
      printf("  Yes\n");
    else
      printf("  No\n");
    printf("  3                        Print out tree");
    if (treeprint)
      printf("  Yes\n");
    else
      printf("  No\n");
    printf("  4       Write out trees onto tree file?");
    if (trout)
      printf("  Yes\n");
    else
      printf("  No\n");
    printf(
   "\n  Y to accept these or type the letter for one to change\n");
#ifdef WIN32
    phyFillScreenColor();
#endif
    scanf("%c%*[^\n]", &ch);
    getchar();
    uppercase(&ch);
    done = (ch == 'Y');
   if (!done) {
      if (strchr("DJOUNPG-LRSM01234",ch) != NULL) {
        switch (ch) {

        case 'D':
          minev = !minev;
          if (minev && (!negallowed))
            negallowed = true;
          break;

        case '-':
          negallowed = !negallowed;
          break;

        case 'G':
          global = !global;
          break;

        case 'J':
          jumble = !jumble;
          if (jumble)
	    initjumble(&inseed, &inseed0, seed, &njumble);
          else njumble = 1;
          break;

        case 'L':
          lower = !lower;
          break;

 	case 'N':
 	  lengths = !lengths;
 	  break;

        case 'O':
          outgropt = !outgropt;
          if (outgropt)
	    initoutgroup(&outgrno, spp);
          break;

        case 'P':
          initpower(&power);
          break;

        case 'R':
          upper = !upper;
          break;

        case 'S':
          replicates = !replicates;
          break;

        case 'U':
          usertree = !usertree;
          break;

        case 'M':
          mulsets = !mulsets;
          if (mulsets)
	    initdatasets(&datasets);
          break;

        case '0':
	  initterminal(&ibmpc, &ansi);
          break;

        case '1':
          printdata = !printdata;
          break;

        case '2':
          progress = !progress;
          break;

        case '3':
          treeprint = !treeprint;
          break;

        case '4':
          trout = !trout;
          break;
        }
      } else
        printf("Not a possible option!\n");
    }
  } while (!done);
}  /* getoptions */
예제 #9
0
void getoptions()
{
  /* interactively set options */
  long i;
  long inseed0 = 0;
  Char ch;

  fprintf(outfile, "\nNeighbor-Joining/UPGMA method version %s\n\n",VERSION);
  putchar('\n');
  jumble = false;
  lower = false;
  outgrno = 1;
  outgropt = false;
  replicates = false;
  trout = true;
  upper = false;
  printdata = false;
  progress = true;
  treeprint = true;
  njoin = true;
  for(;;) {
    printf(ansi ? "\033[2J\033[H" : "\n");
    printf("\nNeighbor-Joining/UPGMA method version %s\n\n",VERSION);
    printf("Settings for this run:\n");
    printf("  N       Neighbor-joining or UPGMA tree?  %s\n",
           (njoin ? "Neighbor-joining" : "UPGMA"));
    if (njoin) {
      printf("  O                        Outgroup root?");
      if (outgropt)
        printf("  Yes, at species number%3ld\n", outgrno);
      else
        printf("  No, use as outgroup species%3ld\n", outgrno);
    }
    printf("  L         Lower-triangular data matrix?  %s\n",
           (lower ? "Yes" : "No"));
    printf("  R         Upper-triangular data matrix?  %s\n",
           (upper ? "Yes" : "No"));
    printf("  S                        Subreplicates?  %s\n",
           (replicates ? "Yes" : "No"));
    printf("  J     Randomize input order of species?");
    if (jumble)
      printf("  Yes (random number seed =%8ld)\n", inseed0);
    else
      printf("  No. Use input order\n");
    printf("  M           Analyze multiple data sets?");
    if (mulsets)
      printf("  Yes, %2ld sets\n", datasets);
    else
      printf("  No\n");
    printf("  0   Terminal type (IBM PC, ANSI, none)?  %s\n",
           (ibmpc ? "IBM PC" : ansi ? "ANSI" : "(none)"));
    printf("  1    Print out the data at start of run  %s\n",
           (printdata ? "Yes" : "No"));
    printf("  2  Print indications of progress of run  %s\n",
           (progress ? "Yes" : "No"));
    printf("  3                        Print out tree  %s\n",
           (treeprint ? "Yes" : "No"));
    printf("  4       Write out trees onto tree file?  %s\n",
           (trout ? "Yes" : "No"));
    printf("\n\n  Y to accept these or type the letter for one to change\n");
#ifdef WIN32
    phyFillScreenColor();
#endif
    scanf("%c%*[^\n]", &ch);
    getchar();
    if (ch == '\n')
      ch = ' ';
    uppercase(&ch);
    if  (ch == 'Y')
      break;
    if (strchr("NJOULRSM01234",ch) != NULL){
      switch (ch) {
	
      case 'J':
	jumble = !jumble;
 	if (jumble) {
 	  do {
 	    printf("Random number seed (must be odd)?\n");
#ifdef WIN32
            phyFillScreenColor();
#endif
 	    scanf("%ld%*[^\n]", &inseed);
 	    getchar();
 	  } while (!(inseed & 1));
 	  inseed0 = inseed;
 	  for (i = 0; i <= 5; i++)
 	    seed[i] = 0;
 	  i = 0;
 	  do {
 	    seed[i] = inseed & 63;
 	    inseed /= 64;
 	    i++;
 	  } while (inseed != 0);
 	}
	break;
	
      case 'L':
	lower = !lower;
	break;
	
      case 'O':
	outgropt = !outgropt;
	if (outgropt)
	  initoutgroup(&outgrno, spp);
        else
          outgrno = 1;
	break;
	
      case 'R':
	upper = !upper;
	break;
	
      case 'S':
	replicates = !replicates;
	break;
	
      case 'N':
	njoin = !njoin;
	break;
	
      case 'M':
	mulsets = !mulsets;
	if (mulsets)
	  initdatasets(&datasets);
	break;
	
      case '0':
	initterminal(&ibmpc, &ansi);
	break;
	
      case '1':
	printdata = !printdata;
	break;
	
      case '2':
	progress = !progress;
	break;
	
      case '3':
	treeprint = !treeprint;
	break;
	
      case '4':
	trout = !trout;
	break;
      }
    } else
      printf("Not a possible option!\n");
  }
}  /* getoptions */
예제 #10
0
void jointree()
{
  /* calculate the tree */
  long nc, nextnode, mini=0, minj=0, i, j, ia, ja, ii, jj, nude, iter;
  double fotu2, total, tmin, dio, djo, bi, bj, bk, dmin=0, da;
  long el[3];
  vector av;
  intvector oc;

  /* for Y. Ina speedups */
  double *R;
  R = (double *)calloc(spp,sizeof(double));

  for (i = 0; i <= spp - 2; i++) {
    for (j = i + 1; j < spp; j++) {
      da = (x[i][j] + x[j][i]) / 2.0;
      x[i][j] = da;
      x[j][i] = da;
    }
  }
  /* First initialization */
  fotu2 = spp - 2.0;
  nextnode = spp + 1;
  av = (vector)Malloc(spp*sizeof(double));
  oc = (intvector)Malloc(spp*sizeof(long));
  for (i = 0; i < spp; i++) {
    av[i] = 0.0;
    oc[i] = 1;
  }
  /* Enter the main cycle */
  if (njoin)
    iter = spp - 3;
  else
    iter = spp - 1;
  for (nc = 1; nc <= iter; nc++) {
    for (j = 2; j <= spp; j++) {
      for (i = 0; i <= j - 2; i++)
        x[j - 1][i] = x[i][j - 1];
    }
    tmin = 99999.0;
    /* Compute sij and minimize */
    if (njoin) { /* Y. Ina */
      for (i = 0; i < spp; i++) { /* Y. Ina */
          R[i] = 0.0; /* Y. Ina */
      } /* Y. Ina */
      for (ja = 2; ja <= spp; ja++) { /* Y. Ina */
        jj = enterorder[ja - 1]; /* Y. Ina */
        if (cluster[jj - 1] != NULL) { /* Y. Ina */
          for (ia = 0; ia <= ja - 2; ia++) { /* Y. Ina */
            ii = enterorder[ia]; /* Y. Ina */
            if (cluster[ii - 1] != NULL) { /* Y. Ina */
              R[ii - 1] += x[ii - 1][jj - 1]; /* Y. Ina */
              R[jj - 1] += x[ii - 1][jj - 1]; /* Y. Ina */
            } /* Y. Ina */
          } /* Y. Ina */
        } /* Y. Ina */
      } /* Y. Ina */
    } /* Y. Ina */
    for (ja = 2; ja <= spp; ja++) {
      jj = enterorder[ja - 1];
      if (cluster[jj - 1] != NULL) {
        for (ia = 0; ia <= ja - 2; ia++) {
          ii = enterorder[ia];
          if (cluster[ii - 1] != NULL) {
            if (njoin) {
      /*      diq = 0.0;
              djq = 0.0;
              dij = x[ii - 1][jj - 1];
              for (i = 0; i < spp; i++) {
                diq += x[i][ii - 1];
                djq += x[i][jj - 1];
              }
              total = fotu2 * dij - diq - djq; */ /* deleted by Y. Ina */
              total = fotu2 * x[ii - 1][jj - 1] - R[ii - 1] - R[jj - 1]; /* Y. Ina */
            } else
              total = x[ii - 1][jj - 1];
            if (total < tmin) {
              tmin = total;
              mini = ii;
              minj = jj;
            }
          }
        }
      }
    }
    /* compute lengths and print */
    if (njoin) {
      dio = 0.0;
      djo = 0.0;
      for (i = 0; i < spp; i++) {
        dio += x[i][mini - 1];
        djo += x[i][minj - 1];
      }
      dmin = x[mini - 1][minj - 1];
      dio = (dio - dmin) / fotu2;
      djo = (djo - dmin) / fotu2;
      bi = (dmin + dio - djo) * 0.5;
      bj = dmin - bi;
      bi -= av[mini - 1];
      bj -= av[minj - 1];
    } else {
      bi = x[mini - 1][minj - 1] / 2.0 - av[mini - 1];
      bj = x[mini - 1][minj - 1] / 2.0 - av[minj - 1];
      av[mini - 1] += bi;
    }
    if (progress) {
      printf("Cycle %3ld: ", iter - nc + 1);
      if (njoin)
        nodelabel(av[mini - 1] > 0.0);
      else
        nodelabel(oc[mini - 1] > 1.0);
      printf("%3ld (%10.5f) joins ", mini, bi);
      if (njoin)
        nodelabel(av[minj - 1] > 0.0);
      else
        nodelabel(oc[minj - 1] > 1.0);
      printf("%3ld (%10.5f)\n", minj, bj);
#ifdef WIN32
      phyFillScreenColor();
#endif
    }
    hookup(curtree.nodep[nextnode - 1]->next, cluster[mini - 1]);
    hookup(curtree.nodep[nextnode - 1]->next->next, cluster[minj - 1]);
    cluster[mini - 1]->v = bi;
    cluster[minj - 1]->v = bj;
    cluster[mini - 1]->back->v = bi;
    cluster[minj - 1]->back->v = bj;
    cluster[mini - 1] = curtree.nodep[nextnode - 1];
    cluster[minj - 1] = NULL;
    nextnode++;
    if (njoin)
      av[mini - 1] = dmin * 0.5;
    /* re-initialization */
    fotu2 -= 1.0;
    for (j = 0; j < spp; j++) {
      if (cluster[j] != NULL) {
        if (njoin) {
          da = (x[mini - 1][j] + x[minj - 1][j]) * 0.5;
          if (mini - j - 1 < 0)
            x[mini - 1][j] = da;
          if (mini - j - 1 > 0)
            x[j][mini - 1] = da;
        } else {
          da = x[mini - 1][j] * oc[mini - 1] + x[minj - 1][j] * oc[minj - 1];
          da /= oc[mini - 1] + oc[minj - 1];
          x[mini - 1][j] = da;
          x[j][mini - 1] = da;
        }
      }
    }
    for (j = 0; j < spp; j++) {
      x[minj - 1][j] = 0.0;
      x[j][minj - 1] = 0.0;
    }
    oc[mini - 1] += oc[minj - 1];
  }
  /* the last cycle */
  nude = 1;
  for (i = 1; i <= spp; i++) {
    if (cluster[i - 1] != NULL) {
      el[nude - 1] = i;
      nude++;
    }
  }
  if (!njoin) {
    curtree.start = cluster[el[0] - 1];
    curtree.start->back = NULL;
    free(av);
    free(oc);
    return;
  }
  bi = (x[el[0] - 1][el[1] - 1] + x[el[0] - 1][el[2] - 1] - x[el[1] - 1]
        [el[2] - 1]) * 0.5;
  bj = x[el[0] - 1][el[1] - 1] - bi;
  bk = x[el[0] - 1][el[2] - 1] - bi;
  bi -= av[el[0] - 1];
  bj -= av[el[1] - 1];
  bk -= av[el[2] - 1];
  if (progress) {
    printf("last cycle:\n");
    putchar(' ');
    nodelabel(av[el[0] - 1] > 0.0);
    printf("%3ld  (%10.5f) joins ", el[0], bi);
    nodelabel(av[el[1] - 1] > 0.0);
    printf("%3ld  (%10.5f) joins ", el[1], bj);
    nodelabel(av[el[2] - 1] > 0.0);
    printf("%3ld  (%10.5f)\n", el[2], bk);
#ifdef WIN32
    phyFillScreenColor();
#endif
  }
  hookup(curtree.nodep[nextnode - 1], cluster[el[0] - 1]);
  hookup(curtree.nodep[nextnode - 1]->next, cluster[el[1] - 1]);
  hookup(curtree.nodep[nextnode - 1]->next->next, cluster[el[2] - 1]);
  cluster[el[0] - 1]->v = bi;
  cluster[el[1] - 1]->v = bj;
  cluster[el[2] - 1]->v = bk;
  cluster[el[0] - 1]->back->v = bi;
  cluster[el[1] - 1]->back->v = bj;
  cluster[el[2] - 1]->back->v = bk;
  curtree.start = cluster[el[0] - 1]->back;
  free(av);
  free(oc);
}  /* jointree */
예제 #11
0
void makedists()
{
  /* compute distance matrix */
  long i, j;
  double v;

  inittable();
  for (i = 0; i < endsite; i++)
    weightrat[i] = weight[i] * rate[category[alias[i] - 1] - 1];
  if (progress) {
    printf("Distances calculated for species\n");
#ifdef WIN32
    phyFillScreenColor();
#endif
  }
  for (i = 0; i < spp; i++)
    if (similarity)
      d[i][i] = 1.0;
    else
      d[i][i] = 0.0;
  baddists = false;
  
  float cur_prog = 0;
  int total = (spp*spp / 2) + 1;
  float step = (1.0f / total) * 100.0f;

  for (i = 1; i < spp; i++) {
    if (progress) {
      printf("    ");
      for (j = 0; j < nmlngth; j++)
        putchar(nayme[i - 1][j]);
      printf("   ");
    }
    for (j = i + 1; j <= spp; j++) {
      makev(i, j, &v);
      v = fabs(v);     
      if ( baddists == true ) {
        v = -1;
        baddists = false;
      }
      d[i - 1][j - 1] = v;
      d[j - 1][i - 1] = v;
      
      U2::TaskStateInfo* ts = U2::getTaskInfo();
      if (ts->cancelFlag != 0) {
          ugene_exit("Task canceled!");
      } else if(!U2::isBootstr()){
          cur_prog += step;
          ts->progress = int (cur_prog);   
      }
      
      if (progress) {
        putchar('.');
        fflush(stdout);
      }
    }
    if (progress) {
      putchar('\n');
#ifdef WIN32
      phyFillScreenColor();
#endif
    }
  }
  if (progress) {
    printf("    ");
    for (j = 0; j < nmlngth; j++)
      putchar(nayme[spp - 1][j]);
    putchar('\n');
  }
}  /* makedists */
예제 #12
0
void getoptions()
{ /* interactively set options */
  long inseed0, loopcount;
  Char ch;
  boolean done;

  fprintf(outfile, "\nContinuous character Maximum Likelihood");
  fprintf(outfile, " method version %s\n\n",VERSION);
  putchar('\n');
  global = false;
  jumble = false;
  njumble = 1;
  lengths = false;
  outgrno = 1;
  outgropt = false;
  all = false;
  contchars = false;
  trout = true;
  usertree = false;
  printdata = false;
  progress = true;
  treeprint = true;
  loopcount = 0;
  do {
    cleerhome();
    printf("\nContinuous character Maximum Likelihood");
    printf(" method version %s\n\n",VERSION);
    printf("Settings for this run:\n");
    printf("  U                       Search for best tree?  %s\n",
           (usertree ? "No, use user trees in input" : "Yes"));
    if (usertree) {
      printf("  L                Use lengths from user trees?%s\n",
             (lengths ? "  Yes" : "  No"));
    }
    printf("  C  Gene frequencies or continuous characters?  %s\n",
           (contchars ? "Continuous characters" : "Gene frequencies"));
    if (!contchars)
      printf("  A   Input file has all alleles at each locus?  %s\n",
             (all ? "Yes" : "No, one allele missing at each"));
    printf("  O                              Outgroup root?  %s %ld\n",
           (outgropt ? "Yes, at species number" :
                       "No, use as outgroup species"),outgrno);
    if (!usertree) {
      printf("  G                      Global rearrangements?  %s\n",
             (global ? "Yes" : "No"));
      printf("  J           Randomize input order of species?");
      if (jumble)
        printf("  Yes (seed=%8ld,%3ld times)\n", inseed0, njumble);
      else
        printf("  No. Use input order\n");
    }
    printf("  M                 Analyze multiple data sets?");
    if (mulsets)
      printf("  Yes, %2ld sets\n", datasets);
    else
      printf("  No\n");
    printf("  0         Terminal type (IBM PC, ANSI, none)?  %s\n",
           ibmpc ? "IBM PC" : ansi  ? "ANSI" : "(none)");
    printf("  1          Print out the data at start of run  %s\n",
           (printdata ? "Yes" : "No"));
    printf("  2        Print indications of progress of run  %s\n",
           (progress ? "Yes" : "No"));
    printf("  3                              Print out tree  %s\n",
           (treeprint ? "Yes" : "No"));
    printf("  4             Write out trees onto tree file?  %s\n",
           (trout ? "Yes" : "No"));
    printf("\n  Y to accept these or type the letter for one to change\n");
#ifdef WIN32
    phyFillScreenColor();
#endif
    fflush(stdout);
    scanf("%c%*[^\n]", &ch);
    getchar();
    uppercase(&ch);
    done = (ch == 'Y');
    if (!done) {
      if (((!usertree) && (strchr("JOUGACM12340", ch) != NULL))
          || (usertree && ((strchr("LOUACM12340", ch) != NULL)))){
        switch (ch) {

        case 'A':
          if (!contchars)
            all = !all;
          break;

        case 'C':
          contchars = !contchars;
          break;

        case 'G':
          global = !global;
          break;

        case 'J':
          jumble = !jumble;
          if (jumble)
            initjumble(&inseed, &inseed0, seed, &njumble);
          else njumble = 1;
          break;

         case 'L':
           lengths = !lengths;
           break;

        case 'O':
          outgropt = !outgropt;
          if (outgropt)
            initoutgroup(&outgrno, spp);
          break;

        case 'U':
          usertree = !usertree;
          break;

        case 'M':
          mulsets = !mulsets;
          if (mulsets)
            initdatasets(&datasets);
          break;

        case '0':
          initterminal(&ibmpc, &ansi);
          break;

        case '1':
          printdata = !printdata;
          break;

        case '2':
          progress = !progress;
          break;

        case '3':
          treeprint = !treeprint;
          break;

        case '4':
          trout = !trout;
          break;
        }
      } else
        printf("Not a possible option!\n");
    }
    countup(&loopcount, 100);
  } while (!done);
}  /* getoptions */
예제 #13
0
void getoptions()
{
  /* interactively set options */
  long reps0;
  long inseed, inseed0, loopcount, loopcount2;
  Char ch;
  boolean done1;

  data = seqs;
  seq = dna;
  bootstrap = true;
  jackknife = false;
  permute = false;
  ild = false;
  lockhart = false;
  blocksize = 1;
  regular = true;
  fracsample = 1.0;
  all = false;
  reps = 100;
  weights = false;
  mixture = false;
  ancvar = false;
  categories = false;
  justwts = false;
  printdata = false;
  dotdiff = true;
  progress = true;
  interleaved = true;
  xml = false;
  nexus = false;
  factors = false;
  loopcount = 0;
  for (;;) {
    cleerhome();
    printf("\nBootstrapping algorithm, version %s\n\n",VERSION);
    printf("Settings for this run:\n");
    printf("  D      Sequence, Morph, Rest., Gene Freqs?  %s\n",
           (data == seqs       ) ? "Molecular sequences"      :
           (data == morphology ) ? "Discrete Morphology"      :
           (data == restsites)   ? "Restriction Sites"        :
           (data == genefreqs)   ? "Gene Frequencies" : "");
    if (data == restsites)
      printf("  E                       Number of enzymes?  %s\n",
             enzymes ? "Present in input file" :
                       "Not present in input file");
    if (data == genefreqs)
      printf("  A       All alleles present at each locus?  %s\n",
             all ? "Yes" : "No, one absent at each locus");
    if ((!lockhart) && (data == morphology))
      printf("  F                 Use factors information?  %s\n",
           factors ? "Yes" : "No");

    printf("  J  Bootstrap, Jackknife, Permute, Rewrite?  %s\n",
           regular && jackknife ? "Delete-half jackknife" :
           (!regular) && jackknife ? "Delete-fraction jackknife" :
           permute   ? "Permute species for each character" :
           ild ? "Permute character order" :
           lockhart ? "Permute within species" :
           regular && bootstrap ? "Bootstrap" :
           (!regular) && bootstrap ? "Partial bootstrap" :
           rewrite ? "Rewrite data" : "(unknown)" );
    
    if (bootstrap || jackknife) {
      printf("  %%    Regular or altered sampling fraction?  ");
      if (regular)
        printf("regular\n");
      else {
        if (fabs(fracsample*100 - (int)(fracsample*100)) > 0.01) {
          printf("%.1f%% sampled\n", 100.0*fracsample);
        } else { 
          printf("%.0f%% sampled\n", 100.0*fracsample);
        }
      }
    }
    if ((data == seqs) && rewrite) {
      printf("  P     PHYLIP, NEXUS, or XML output format?  %s\n",
           nexus ? "NEXUS" : xml ? "XML" : "PHYLIP");
      if (xml || ((data == seqs) && nexus)) {
        printf("  S             Type of molecular sequences?  " );
        switch (seq) {
          case (dna) : printf("DNA\n"); break;
          case (rna) : printf("RNA\n"); break;
          case (protein) : printf("Protein\n"); break;
        }
      }
    }
    if ((data == morphology) && rewrite)
      printf("  P           PHYLIP or NEXUS output format?  %s\n",
                                         nexus ? "NEXUS" : "PHYLIP");
    if (bootstrap) {
      if (blocksize > 1)
      printf("  B      Block size for block-bootstrapping?  %ld\n", blocksize);
      else
        printf("  B      Block size for block-bootstrapping?  %ld (regular bootstrap)\n", blocksize);
    }
    if (!rewrite)
      printf("  R                     How many replicates?  %ld\n", reps);
    if (jackknife || bootstrap || permute || ild) {
      printf("  W              Read weights of characters?  %s\n",
          (weights ? "Yes" : "No"));
      if (data == morphology) {
        printf("  X                       Read mixture file?  %s\n",
               (mixture ? "Yes" : "No"));
        printf("  N                     Read ancestors file?  %s\n",
               (ancvar ? "Yes" : "No"));
      }
      if (data == seqs)
        printf("  C                Read categories of sites?  %s\n",
          (categories ? "Yes" : "No"));
      if ((!permute)) {
        printf("  S     Write out data sets or just weights?  %s\n",
          (justwts ? "Just weights" : "Data sets"));
      }
    }
    if (data == seqs || data == restsites)
      printf("  I             Input sequences interleaved?  %s\n",
             interleaved ? "Yes" : "No, sequential");
    printf("  0      Terminal type (IBM PC, ANSI, none)?  %s\n",
           ibmpc ? "IBM PC" : ansi  ? "ANSI" : "(none)");
    printf("  1       Print out the data at start of run  %s\n",
           printdata ? "Yes" : "No");
    if (printdata)
      printf("  .     Use dot-differencing to display them  %s\n",
           dotdiff ? "Yes" : "No");
    printf("  2     Print indications of progress of run  %s\n",
           progress ? "Yes" : "No");
    printf("\n  Y to accept these or type the letter for one to change\n");
#ifdef WIN32
    phyFillScreenColor();
#endif
    fflush(stdout);
    scanf("%c%*[^\n]", &ch);
    getchar();
    uppercase(&ch);
    if (ch == 'Y')
           break;
    if (
        (bootstrap && (strchr("ABCDEFSJPRWXNI%1.20",ch) != NULL)) ||
        (jackknife && (strchr("ACDEFSJPRWXNI%1.20",ch) != NULL)) ||
        (permute && (strchr("ACDEFSJPRWXNI%1.20",ch) != NULL)) ||
        ((ild || lockhart) && (strchr("ACDESJPRXNI%1.20",ch) != NULL)) ||
        ((!(bootstrap || jackknife || permute || ild || lockhart)) &&
         ((!xml) && (strchr("ADEFJPI1.20",ch) != NULL))) ||
        (((data == morphology) || (data == seqs))
         && (nexus || xml) && (strchr("ADEFJPSI1.20",ch) != NULL))
        ) {
      switch (ch) {
        
      case 'D':
        if (data == genefreqs)
          data = seqs;
        else
          data = (datatype)((long)data + 1);
        break;
        
      case 'A':
        all = !all;
        break;
        
      case 'E':
        enzymes = !enzymes;
        break;
        
    case 'J':
      if (bootstrap) {
        bootstrap = false;
        jackknife = true;
      } else if (jackknife) {
        jackknife = false;
        permute = true;
      } else if (permute) {
        permute = false;
        ild = true;
      } else if (ild) {
        ild = false;
        lockhart = true;
      } else if (lockhart) {
        lockhart = false;
        rewrite = true;
      } else if (rewrite) {
        rewrite = false;
        bootstrap = true;
      } else {
        assert(0); /* Shouldn't happen */
        bootstrap
          = true;
        jackknife = permute = ild = lockhart = rewrite
          = false;
      }
      break;
        
      case '%':
        regular = !regular;
        if (!regular) {
          loopcount2 = 0;
          do {
            printf("Samples as percentage of");
            if ((data == seqs) || (data == restsites))
              printf(" sites?\n");
            if (data == morphology)
            printf(" characters?\n");
            if (data == genefreqs)
              printf(" loci?\n");
            fflush(stdout);
            scanf("%lf%*[^\n]", &fracsample);
            getchar();
            done1 = (fracsample > 0.0);
            if (!done1) {
              printf("BAD NUMBER: must be positive\n");
            }
            fracsample = fracsample/100.0;
            countup(&loopcount2, 10);
          } while (done1 != true);
        }
        break;

      case 'P':
        if (data == seqs) {
          if (!xml && !nexus)
            nexus = true;
          else {
            if (nexus) {
              nexus = false;
              xml = true;
              }
            else xml = false;
            }
          }
        if (data == morphology) {
          nexus = !nexus;
          xml = false;
          }
        break;
        
      case 'S':
        if(!rewrite){
          justwts = !justwts;          
        } else {
          switch (seq) {
          case (dna): seq = rna; break;
          case (rna): seq = protein; break;
          case (protein): seq = dna; break;
          }
        }
        break;
        
      case 'B':
        loopcount2 = 0;
        do {
          printf("Block size?\n");
#ifdef WIN32
          phyFillScreenColor();
#endif
          fflush(stdout);
          scanf("%ld%*[^\n]", &blocksize);
          getchar();
          done1 = (blocksize > 0);
          if (!done1) {
            printf("BAD NUMBER: must be positive\n");
          }
          countup(&loopcount2, 10);
        } while (done1 != true);
        break;

      case 'R':
        reps0 = reps;
        loopcount2 = 0;
        do {
          printf("Number of replicates?\n");
#ifdef WIN32
          phyFillScreenColor();
#endif
          fflush(stdout);
          scanf("%ld%*[^\n]", &reps);
          getchar();
          done1 = (reps > 0);
          if (!done1) {
            printf("BAD NUMBER: must be positive\n");
            reps = reps0;
          }
          countup(&loopcount2, 10);
        } while (done1 != true);
        break;

      case 'W':
        weights = !weights;
        break;

      case 'X':
        mixture = !mixture;
        break;

      case 'N':
        ancvar = !ancvar;
        break;

      case 'C':
        categories = !categories;
        break;

      case 'F':
        factors = !factors;
        break;

      case 'I':
        interleaved = !interleaved;
        break;
        
      case '0':
        initterminal(&ibmpc, &ansi);
        break;
        
      case '1':
        printdata = !printdata;
        break;
        
      case '.':
        dotdiff = !dotdiff;
        break;
        
      case '2':
        progress = !progress;
        break;
      }
    } else
      printf("Not a possible option!\n");
    countup(&loopcount, 100);
  }
  if (bootstrap || jackknife) {
    if (jackknife && regular)
      fracsample = 0.5;
    if (bootstrap && regular)
      fracsample = 1.0;
  }
  if (!rewrite)
    initseed(&inseed, &inseed0, seed);

  /* These warnings only appear when user has changed an option that
   * subsequently became inapplicable */
  if (factors && lockhart) {
    printf("Warning: Cannot use factors when permuting within species.\n");
    factors = false;
  }
  if (data != seqs) {
    if (xml) {
      printf("warning: XML output not available for this type of data\n");
      xml = false;
    }
    if (categories) {
      printf("warning: cannot use categories file with this type of data\n");
      categories = false;
    }
  }
  if (data != morphology) {
    if (mixture) {
      printf("warning: cannot use mixture file with this type of data\n");
      mixture = false;
    }
    if (ancvar) {
      printf("warning: cannot use ancestors file with this type of data\n");
      ancvar = false;
    }
  }
}  /* getoptions */
예제 #14
0
void getoptions()
{
  /* interactively set options */
  long loopcount;
  Char ch;
  boolean done, gotopt;
  char input[100];

  how = arb;
  usertree = false;
  goteof = false;
  thresh = false;
  threshold = spp;
  weights = false;
  ancvar = false;
  factors = false;
  dollo = true;
  loopcount = 0;
  do {
    cleerhome();
    printf("\nInteractive Dollo or polymorphism parsimony,");
    printf(" version %s\n\n",VERSION);
    printf("Settings for this run:\n");
    printf("  P                        Parsimony method?");
    printf("  %s\n",(dollo ? "Dollo" : "Polymorphism"));
    printf("  A                    Use ancestral states?  %s\n",
           ancvar ? "Yes" : "No");
    printf("  F                 Use factors information?  %s\n",
           factors ? "Yes" : "No");
    printf("  W                          Sites weighted?  %s\n",
           (weights ? "Yes" : "No"));
    printf("  T                 Use Threshold parsimony?");
    if (thresh)
      printf("  Yes, count steps up to%4.1f\n", threshold);
    else
      printf("  No, use ordinary parsimony\n");
    printf("  A      Use ancestral states in input file?");
    printf("  %s\n",(ancvar ? "Yes" : "No"));
    printf("  U Initial tree (arbitrary, user, specify)?");
    printf("  %s\n",(how == arb) ? "Arbitrary" :
                    (how == use) ? "User tree from tree file" :
                                   "Tree you specify");
    printf("  0      Graphics type (IBM PC, ANSI, none)?  %s\n",
           ibmpc ? "IBM PC" : ansi  ? "ANSI"   : "(none)");
    printf("  L               Number of lines on screen?%4ld\n",screenlines);
    printf("  S                Width of terminal screen?%4ld\n",screenwidth);
    printf(
      "\n\nAre these settings correct? (type Y or the letter for one to change)\n");
#ifdef WIN32
    phyFillScreenColor();
#endif
    getstryng(input);
    ch = input[0];
    uppercase(&ch);
    done = (ch == 'Y');
    gotopt = (strchr("SFTPULA0W",ch) != NULL) ? true : false;
    if (gotopt) {
      switch (ch) {

      case 'A':
        ancvar = !ancvar;
        break;

      case 'F':
        factors = !factors;
        break;

      case 'W':
        weights = !weights;
        break;
        
      case 'P':
        dollo = !dollo;
        break;

      case 'T':
        thresh = !thresh;
        if (thresh)
          initthreshold(&threshold);
        break;

      case 'U':
        if (how == arb)
          how = use;
        else if (how == use)
            how = spec;
          else
            how = arb;
        break;

      case '0':
        initterminal(&ibmpc, &ansi);
        break;

      case 'L':
        initnumlines(&screenlines);
        break;

      case 'S':
        screenwidth = readlong("Width of terminal screen (in characters)?\n");
      }
    }
    else  
      printf("Not a possible option!\n");
    countup(&loopcount, 100);
  } while (!done);
  if (scrollinc < screenwidth / 2.0)
    hscroll = scrollinc;
  else
    hscroll = screenwidth / 2;
  if (scrollinc < screenlines / 2.0)
    vscroll = scrollinc;
  else
    vscroll = screenlines / 2;
}  /* getoptions */
예제 #15
0
void maketree()
{
  /* constructs a binary tree from the pointers in treenode.
     adds each node at location which yields highest "likelihood"
     then rearranges the tree for greatest "likelihood" */
  long i, j, nextnode;
  double gotlike;
  node *item, *nufork, *dummy, *p;
  char *treestr;

  fullset = (1L << (bits + 1)) - (1L << 1);
  if (!usertree) {
    for (i = 1; i <= (spp); i++)
      enterorder[i - 1] = i;
    if (jumble)
      randumize(seed, enterorder);
    root = treenode[enterorder[0] - 1];
    add(treenode[enterorder[0] - 1], treenode[enterorder[1] - 1],
        treenode[spp], &root, treenode);
    if (progress) {
      printf("Adding species:\n");
      writename(0, 2, enterorder);
#ifdef WIN32
      phyFillScreenColor();
#endif
    }
    lastrearr = false;
    for (i = 3; i <= (spp); i++) {
      bestyet = -350.0 * spp * chars;
      item = treenode[enterorder[i - 1] - 1];
      nufork = treenode[spp + i - 2];
      addpreorder(root, item, nufork);
      add(there, item, nufork, &root, treenode);
      like = bestyet;
      rearrange(&root);
      if (progress) {
        writename(i - 1, 1, enterorder);
#ifdef WIN32
        phyFillScreenColor();
#endif
      }
      lastrearr = (i == spp);
      if (lastrearr) {
        if (progress) {
          printf("\nDoing global rearrangements\n");
          printf("  !");
          for (j = 1; j <= (nonodes); j++)
            if ( j % (( nonodes / 72 ) + 1 ) == 0 )
              putchar('-');
          printf("!\n");
#ifdef WIN32
          phyFillScreenColor();
#endif
        }
        bestlike = bestyet;
        if (jumb == 1) {
          bstlike2 = bestlike;
          nextree = 1;
        }
        do {
          if (progress)
            printf("   ");
          gotlike = bestlike;
          for (j = 0; j < (nonodes); j++) {
            bestyet = - 350.0 * spp * chars;
            item = treenode[j];
            if (item != root) {
              nufork = treenode[j]->back;
              re_move(&item, &nufork, &root, treenode);
              there = root;
              addpreorder(root, item, nufork);
              add(there, item, nufork, &root, treenode);
            }
            if (progress) {
              if ( j % (( nonodes / 72 ) + 1 ) == 0 )
                putchar('.');
              fflush(stdout);
            }
          }
          if (progress) {
            putchar('\n');
#ifdef WIN32
            phyFillScreenColor();
#endif

          }
        } while (bestlike > gotlike);
      }
    }
    if (progress)
      putchar('\n');
    for (i = spp - 1; i >= 1; i--)
      re_move(&treenode[i], &dummy, &root, treenode);
    if (jumb == njumble) {
      if (treeprint) {
        putc('\n', outfile);
        if (nextree == 2)
          fprintf(outfile, "One most parsimonious tree found:\n");
        else
          fprintf(outfile, "%6ld trees in all found\n", nextree - 1);
      }
      if (nextree > maxtrees + 1) {
        if (treeprint)
          fprintf(outfile, "here are the first%4ld of them\n", (long)maxtrees);
        nextree = maxtrees + 1;
      }
      if (treeprint)
        putc('\n', outfile);
      for (i = 0; i <= (nextree - 2); i++) {
        root = treenode[0];
        add(treenode[0], treenode[1], treenode[spp], &root, treenode);
        for (j = 3; j <= spp; j++) {
          add(treenode[bestrees[i].btree[j - 1] - 1], treenode[j - 1],
              treenode[spp + j - 2], &root, treenode);}
        evaluate(root);
        printree(1.0, treeprint, root);
        describe();
        for (j = 1; j < (spp); j++)
          re_move(&treenode[j], &dummy, &root, treenode);
      }
    }
  } else {
    
    if (numtrees > 2) {
      emboss_initseed(inseed, &inseed0, seed);
      printf("\n");
    }
    if (treeprint) {
      fprintf(outfile, "User-defined tree");
      if (numtrees > 1)
        putc('s', outfile);
      fprintf(outfile, ":\n");
    }
    names = (boolean *)Malloc(spp*sizeof(boolean));
    which = 1;
    firsttree = true;                       /**/
    nodep = NULL;                           /**/
    nextnode = 0;                           /**/
    haslengths = 0;                         /**/
    phirst = 0;                             /**/
    zeros = (long *)Malloc(chars*sizeof(long));         /**/
    for (i = 0; i < chars; i++)             /**/
      zeros[i] = 0;                         /**/
    while (which <= numtrees) {
      treestr = ajStrGetuniquePtr(&phylotrees[which-1]->Tree);
      treeread(&treestr, &root, treenode, &goteof, &firsttree,
                nodep, &nextnode, &haslengths,
                &grbg, initdollopnode,false,nonodes);

      for (i = spp; i < (nonodes); i++) {
        p = treenode[i];
        for (j = 1; j <= 3; j++) {
          p->stateone = (bitptr)Malloc(words*sizeof(long));
          p->statezero = (bitptr)Malloc(words*sizeof(long));
          p = p->next;
        }
      } /* debug: see comment at initdollopnode() */
      if (treeprint)
        fprintf(outfile, "\n\n");
      evaluate(root);
      printree(1.0, treeprint, root);
      describe();
      which++;
    }
    FClose(intree);
    fprintf(outfile, "\n\n");
    if (numtrees > 1 && chars > 1)
      standev(numtrees, minwhich, minsteps, nsteps, fsteps, seed);
    free(names);
  }
  if (jumb == njumble) {
    if (progress) {
      printf("Output written to file \"%s\"\n\n", outfilename);
      if (trout)
        printf("Trees also written onto file \"%s\"\n\n", outtreename);
    }
    if (ancseq)
      freegarbage(&garbage);
  }
}  /* maketree */
예제 #16
0
void maketree()
{ /* construct the tree */
  long i;

  if (usertree) {
    /* Open in binary: ftell() is broken for UNIX line-endings under WIN32 */
    openfile(&intree,INTREE,"input tree file", "rb",progname,intreename);
    numtrees = countsemic(&intree);
    if(numtrees > MAXSHIMOTREES)
      shimotrees = MAXSHIMOTREES;
    else
      shimotrees = numtrees;
    if (numtrees > 2)
      initseed(&inseed, &inseed0, seed);
    if (treeprint) {
      fprintf(outfile, "User-defined tree");
      if (numtrees > 1)
        putc('s', outfile);
      putc('\n', outfile);
    }
    setuptree(&curtree, nonodes2);
    for (which = 1; which <= spp; which++)
      inittip(which, &curtree);
    which = 1;
    while (which <= numtrees) {
      for (i = 0 ; i < nonodes2 ; i++) {
        if ( i > spp) {
          /* must do this since not all nodes may be used if an 
             unrooted tree is read in after a rooted one */
          curtree.nodep[i]->back = NULL;
          curtree.nodep[i]->next->back = NULL;
          curtree.nodep[i]->next->next->back = NULL;
        }
        else curtree.nodep[i]->back = NULL;
      }
      treeread2 (intree, &curtree.start, curtree.nodep,
        lengths, &trweight, &goteof, &haslengths, &spp,false,nonodes2);
      curtree.start = curtree.nodep[outgrno - 1]->back;
      treevaluate();
      printree();
      summarize();
      which++;
    }
    FClose(intree);
    if (numtrees > 1 && loci > 1 ) {
      weight = (long *)Malloc(loci*sizeof(long));
      for (i = 0; i < loci; i++)
        weight[i] = 1;
      standev2(numtrees, maxwhich, 0, loci-1, maxlogl, l0gl, l0gf, seed);
      free(weight);
      fprintf(outfile, "\n\n");
    }
  } else { /* if ( !usertree ) */
    if (jumb == 1) {
      setuptree(&curtree, nonodes2);
      setuptree(&priortree, nonodes2);
      setuptree(&bestree, nonodes2);
      if (njumble > 1) 
        setuptree(&bestree2, nonodes2);
    }
    for (i = 1; i <= spp; i++)
      enterorder[i - 1] = i;
    if (jumble)
      randumize(seed, enterorder);
    nextsp = 3;
    buildsimpletree(&curtree);
    curtree.start = curtree.nodep[enterorder[0] - 1]->back;
    if (jumb == 1) numtrees = 1;
    nextsp = 4;
    if (progress) {
      printf("Adding species:\n");
      writename(0, 3, enterorder);
#ifdef WIN32
      phyFillScreenColor();
#endif
    }
    while (nextsp <= spp) {
      buildnewtip(enterorder[nextsp - 1], &curtree, nextsp);
      copy_(&curtree, &priortree);
      bestree.likelihood = -DBL_MAX;
      addtraverse(curtree.nodep[enterorder[nextsp - 1] - 1]->back,
                  curtree.start, true );
      copy_(&bestree, &curtree);
      if (progress) {
        writename(nextsp - 1, 1, enterorder);
#ifdef WIN32
        phyFillScreenColor();
#endif
      }
      if (global && nextsp == spp) {
        if (progress) {
          printf("\nDoing global rearrangements\n");
          printf("  !");
          for (i = 1; i <= spp - 2; i++)
            if ( (i - spp) % (( nonodes2 / 72 ) + 1 ) == 0 )
              putchar('-');
          printf("!\n");
          printf("   ");
        }
      }
      succeeded = true;
      while (succeeded) {
        succeeded = false;
        if ( global && nextsp == spp )
          globrearrange();
        else 
          rearrange(curtree.start);
        if (global && nextsp == spp)
          putc('\n', outfile);
      }
      if (global && nextsp == spp && progress)
        putchar('\n');
      if (njumble > 1) {
        if (jumb == 1 && nextsp == spp)
          copy_(&bestree, &bestree2);
        else if (nextsp == spp) {
          if (bestree2.likelihood < bestree.likelihood)
            copy_(&bestree, &bestree2);
        }
      }
      if (nextsp == spp && jumb == njumble) {
        if (njumble > 1) copy_(&bestree2, &curtree);
        curtree.start = curtree.nodep[outgrno - 1]->back;
        printree();
        summarize();
      }
      nextsp++;
    }
  }
  if ( jumb < njumble)
    return;
  if (progress) {
    printf("\nOutput written to file \"%s\"\n", outfilename);
    if (trout)
      printf("\nTree also written onto file \"%s\"\n", outtreename);
  }
  freeview(&curtree, nonodes2);
  if (!usertree) {
    freeview(&bestree, nonodes2);
    freeview(&priortree, nonodes2);
  }
  for (i = 0; i < spp; i++)
    free(x[i]);
  if (!contchars) {
    free(locus);
    free(pbar);
  }
}  /* maketree */
예제 #17
0
파일: penny.c 프로젝트: uw-loci/ome-server
void getoptions()
{
    /* interactively set options */
    long loopcount, loopcount2;
    Char ch, ch2;

    fprintf(outfile, "\nPenny algorithm, version %s\n",VERSION);
    fprintf(outfile, " branch-and-bound to find all");
    fprintf(outfile, " most parsimonious trees\n\n");
    howoften = often;
    howmanny = many;
    outgrno = 1;
    outgropt = false;
    simple = true;
    thresh = false;
    threshold = spp;
    trout = true;
    weights = false;
    justwts = false;
    ancvar = false;
    allsokal = false;
    allwagner = true;
    mixture = false;
    printdata = false;
    progress = true;
    treeprint = true;
    stepbox = false;
    ancseq = false;
    loopcount = 0;
    for(;;) {
        cleerhome();
        printf("\nPenny algorithm, version %s\n",VERSION);
        printf(" branch-and-bound to find all most parsimonious trees\n\n");
        printf("Settings for this run:\n");
        printf("  X                     Use Mixed method?  %s\n",
               mixture ? "Yes" : "No");
        printf("  P                     Parsimony method?  %s\n",
               (allwagner && !mixture)  ? "Wagner"       :
               (!(allwagner || mixture)) ? "Camin-Sokal"  : "(methods in mixture)");
        printf("  F        How often to report, in trees:%5ld\n",howoften);
        printf("  H        How many groups of%5ld trees:%6ld\n",howoften,howmanny);
        printf("  O                        Outgroup root?");
        if (outgropt)
            printf("  Yes, at species number%3ld\n", outgrno);
        else
            printf("  No, use as outgroup species%3ld\n", outgrno);
        printf("  S           Branch and bound is simple?  %s\n",
               simple ? "Yes" : "No. reconsiders order of species");
        printf("  T              Use Threshold parsimony?");
        if (thresh)
            printf("  Yes, count steps up to%4.1f per char.\n", threshold);
        else
            printf("  No, use ordinary parsimony\n");
        printf("  A   Use ancestral states in input file?  %s\n",
               ancvar ? "Yes" : "No");
        printf("  W                       Sites weighted?  %s\n",
               (weights ? "Yes" : "No"));
        printf("  M           Analyze multiple data sets?");
        if (mulsets)
            printf("  Yes, %2ld %s\n", msets,
                   (justwts ? "sets of weights" : "data sets"));
        else
            printf("  No\n");
        printf("  0   Terminal type (IBM PC, ANSI, none)?  %s\n",
               ibmpc ? "IBM PC" : ansi  ? "ANSI" : "(none)");
        printf("  1    Print out the data at start of run  %s\n",
               printdata ? "Yes" : "No");
        printf("  2  Print indications of progress of run  %s\n",
               progress ? "Yes" : "No");
        printf("  3                        Print out tree  %s\n",
               treeprint ? "Yes" : "No");
        printf("  4     Print out steps in each character  %s\n",
               stepbox ? "Yes" : "No");
        printf("  5     Print states at all nodes of tree  %s\n",
               ancseq ? "Yes" : "No");
        printf("  6       Write out trees onto tree file?  %s\n",
               trout ? "Yes" : "No");
        if(weights && justwts) {
            printf(
                "WARNING:  W option and Multiple Weights options are both on.  ");
            printf(
                "The W menu option is unnecessary and has no additional effect. \n");
        }
        printf("\nAre these settings correct?");
        printf(" (type Y or the letter for one to change)\n");
#ifdef WIN32
        phyFillScreenColor();
#endif
        scanf("%c%*[^\n]", &ch);
        getchar();
        uppercase(&ch);
        if (ch == 'Y')
            break;
        if (strchr("WHFSOMPATX1234560",ch) != NULL) {
            switch (ch) {

            case 'X':
                mixture = !mixture;
                break;

            case 'P':
                allwagner = !allwagner;
                break;

            case 'A':
                ancvar = !ancvar;
                break;

            case 'H':
                inithowmany(&howmanny, howoften);
                break;

            case 'F':
                inithowoften(&howoften);
                break;

            case 'S':
                simple = !simple;
                break;

            case 'O':
                outgropt = !outgropt;
                if (outgropt)
                    initoutgroup(&outgrno, spp);
                else outgrno = 1;
                break;

            case 'T':
                thresh = !thresh;
                if (thresh)
                    initthreshold(&threshold);
                break;

            case 'W':
                weights = !weights;
                break;

            case 'M':
                mulsets = !mulsets;
                if (mulsets) {
                    printf("Multiple data sets or multiple weights?");
                    loopcount2 = 0;
                    do {
                        printf(" (type D or W)\n");
#ifdef WIN32
                        phyFillScreenColor();
#endif
                        scanf("%c%*[^\n]", &ch2);
                        getchar();
                        if (ch2 == '\n')
                            ch2 = ' ';
                        uppercase(&ch2);
                        countup(&loopcount2, 10);
                    } while ((ch2 != 'W') && (ch2 != 'D'));
                    justwts = (ch2 == 'W');
                    if (justwts)
                        justweights(&msets);
                    else
                        initdatasets(&msets);
                }
                break;

            case '0':
                initterminal(&ibmpc, &ansi);
                break;

            case '1':
                printdata = !printdata;
                break;

            case '2':
                progress = !progress;
                break;

            case '3':
                treeprint = !treeprint;
                break;

            case '4':
                stepbox = !stepbox;
                break;

            case '5':
                ancseq = !ancseq;
                break;

            case '6':
                trout = !trout;
                break;
            }
        } else
            printf("Not a possible option!\n");
        countup(&loopcount, 100);
    }
    allsokal = (!allwagner && !mixture);
}  /* getoptions */
예제 #18
0
파일: penny.c 프로젝트: uw-loci/ome-server
void maketree()
{
    /* tree construction recursively by branch and bound */
    long i, j, k;
    node2 *dummy;

    fullset = (1L << (bits + 1)) - (1L << 1);
    if (progress) {
        printf("\nHow many\n");
        printf("trees looked                                       Approximate\n");
        printf("at so far      Length of        How many           percentage\n");
        printf("(multiples     shortest tree    trees this long    searched\n");
        printf("of %4ld):      found so far     found so far       so far\n",
               howoften);
        printf("----------     ------------     ------------       ------------\n");
#ifdef WIN32
        phyFillScreenColor();
#endif
    }
    done = false;
    mults = 0;
    examined = 0;
    nextree = 1;
    root = treenode[0];
    firsttime = true;
    for (i = 0; i < (spp); i++)
        added[i] = false;
    added[0] = true;
    order[0] = 1;
    k = 2;
    fracdone = 0.0;
    fracinc = 1.0;
    bestyet = -1.0;
    addit(k);
    if (done) {
        if (progress) {
            printf("Search broken off!  Not guaranteed to\n");
            printf(" have found the most parsimonious trees.\n");
        }
        if (treeprint) {
            fprintf(outfile, "Search broken off!  Not guaranteed to\n");
            fprintf(outfile, " have found the most parsimonious\n");
            fprintf(outfile, " trees, but here is what we found:\n");
        }
    }
    if (treeprint) {
        fprintf(outfile, "\nrequires a total of %18.3f\n\n", bestyet);
        if (nextree == 2)
            fprintf(outfile, "One most parsimonious tree found:\n");
        else
            fprintf(outfile, "%5ld trees in all found\n", nextree - 1);
    }
    if (nextree > maxtrees + 1) {
        if (treeprint)
            fprintf(outfile, "here are the first%4ld of them\n", (long)maxtrees);
        nextree = maxtrees + 1;
    }
    if (treeprint)
        putc('\n', outfile);
    for (i = 0; i < (spp); i++)
        added[i] = true;
    for (i = 0; i <= (nextree - 2); i++) {
        for (j = k; j <= (spp); j++)
            add3(treenode[bestrees[i][j - 1] - 1],
                 treenode[bestorders[i][j - 1] - 1], treenode[spp + j - 2],
                 &root, treenode);
        if (noroot)
            reroot(treenode[outgrno - 1]);
        didreroot = (outgropt && noroot);
        evaluate(root);
        printree(treeprint, noroot, didreroot, root);
        describe();
        for (j = k - 1; j < (spp); j++)
            re_move3(&treenode[bestorders[i][j] - 1], &dummy, &root, treenode);
    }
    if (progress) {
        printf("\nOutput written to file \"%s\"\n\n", outfilename);
        if (trout)
            printf("Trees also written onto file \"%s\"\n\n", outtreename);
    }
    if (ancseq)
        freegarbage(&garbage);
}  /* maketree */
예제 #19
0
void getoptions()
{
  /* interactively set options */
  Char ch;

  putchar('\n');
  sitelength = 6.0;
  neili = false;
  gama = false;
  cvi = 0.0;
  weights = false;
  lower = false;
  printdata = false;
  progress = true;
  restsites = true;
  interleaved = true;
  ttratio = 2.0;
  for (;;) {
    printf("%s", (ansi ? ("\033[2J\033[H") : "\n"));
    printf("\nRestriction site or fragment distances, ");
    printf("version %s\n\n",VERSION);
    printf("Settings for this run:\n");
    printf("  R           Restriction sites or fragments?  %s\n",
           (restsites ? "Sites" : "Fragments"));
    if (!restsites)
      printf("  N        Original or modified Nei/Li model?  %s\n",
             (neili ? "Original" : "Modified"));
    if (restsites || !neili) {
      printf("  G  Gamma distribution of rates among sites?");
      if (!gama)
        printf("  No\n");
      else
        printf("  Yes\n");
      printf("  T            Transition/transversion ratio?  %f\n", ttratio);
    }
    printf("  S                              Site length? %4.1f\n",sitelength);
    printf("  L                  Form of distance matrix?  %s\n",
           (lower ? "Lower-triangular" : "Square"));
    printf("  M               Analyze multiple data sets?");
    if (mulsets)
      printf("  Yes, %2ld sets\n", datasets);
    else
      printf("  No\n");
    printf("  I              Input sequences interleaved?  %s\n",
           (interleaved ? "Yes" : "No, sequential"));
    printf("  0       Terminal type (IBM PC, ANSI, none)?  %s\n",
           ibmpc ? "IBM PC" : ansi  ? "ANSI" : "(none)");
    printf("  1       Print out the data at start of run?  %s\n",
           (printdata ? "Yes" : "No"));
    printf("  2     Print indications of progress of run?  %s\n",
           (progress ? "Yes" : "No"));
    printf("\n  Y to accept these or type the letter for one to change\n");
#ifdef WIN32
    phyFillScreenColor();
#endif
    scanf("%c%*[^\n]", &ch);
    getchar();
    if (ch == '\n')
      ch = ' ';
    uppercase(&ch);
    if (ch == 'Y')
      break;
    if (strchr("RDNGTSLMI012",ch) != NULL){
      switch (ch) {
        
      case 'R':
        restsites = !restsites;
        break;
        
      case 'G':
        if (restsites || !neili)
          gama = !gama;
        break;

      case 'N':
        if (!restsites)
          neili = !neili;
        break;

      case 'T':
        if (restsites || !neili)
          initratio(&ttratio);
        break;

      case 'S':
        do {
          printf("New Sitelength?\n");
#ifdef WIN32
          phyFillScreenColor();
#endif
          scanf("%lf%*[^\n]", &sitelength);
          getchar();
          if (sitelength < 1.0)
            printf("BAD RESTRICTION SITE LENGTH: %f\n", sitelength); 
        } while (sitelength < 1.0);
        break;
        
      case 'L':
        lower = !lower;
        break;

      case 'M':
        mulsets = !mulsets;
        if (mulsets)
          initdatasets(&datasets);
        break;
        
      case 'I':
        interleaved = !interleaved;
        break;
        
      case '0':
        initterminal(&ibmpc, &ansi);
        break;
        
      case '1':
        printdata = !printdata;
        break;
        
      case '2':
        progress = !progress;
        break;
        
      }
    } else
      printf("Not a possible option!\n");
  }
  if (gama) {
    do {
      printf(
"\nCoefficient of variation of substitution rate among sites (must be positive)?\n");
#ifdef WIN32
      phyFillScreenColor();
#endif
      scanf("%lf%*[^\n]", &cvi);
      getchar();
    } while (cvi <= 0.0);
    cvi = 1.0 / (cvi * cvi);
    printf("\n");
  }
  xi = (ttratio - 0.5)/(ttratio + 0.5);
  xv = 1.0 - xi;
  fracchange = xi*0.5 + xv*0.75;
}  /* getoptions */