⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 protpars.c

📁 一个神经网络工具箱
💻 C
📖 第 1 页 / 共 4 页
字号:
  do {    p->back = NULL;    p = p->next;  } while (p != (*fork));  (*item)->back = NULL;  if (recompute) {    protpreorder(other);    if (other != root) protpreorder(other->back);  }}  /* protre_move */void evaluate(node *r){  /* determines the number of steps needed for a tree. this is the     minimum number of steps needed to evolve sequences on this tree */  long i, steps, term;  double sum;  sum = 0.0;  for (i = 0; i < (chars); i++) {    steps = r->numsteps[i];    if (steps <= threshwt[i])      term = steps;    else      term = threshwt[i];    sum += term;    if (usertree && which <= maxuser)      fsteps[which - 1][i] = term;  }  if (usertree && which <= maxuser) {    nsteps[which - 1] = sum;    if (which == 1) {      minwhich = 1;      minsteps = sum;    } else if (sum < minsteps) {      minwhich = which;      minsteps = sum;    }  }  like = -sum;}  /* evaluate */void protpostorder(node *p){  /* traverses a binary tree, calling PROCEDURE fillin at a     node's descendants before calling fillin at the node */  if (p->tip)    return;  protpostorder(p->next->back);  protpostorder(p->next->next->back);  protfillin(p, p->next->back, p->next->next->back);}  /* protpostorder */void protreroot(node *outgroup){  /* reorients tree, putting outgroup in desired position. */  node *p, *q;  if (outgroup->back->index == root->index)    return;  p = root->next;  q = root->next->next;  p->back->back = q->back;  q->back->back = p->back;  p->back = outgroup;  q->back = outgroup->back;  outgroup->back->back = q;  outgroup->back = p;}  /* protreroot */void protsavetraverse(node *p, long *pos, boolean *found){  /* sets BOOLEANs that indicate which way is down */  p->bottom = true;  if (p->tip)    return;  p->next->bottom = false;  protsavetraverse(p->next->back, pos,found);  p->next->next->bottom = false;  protsavetraverse(p->next->next->back, pos,found);}  /* protsavetraverse */void protsavetree(long *pos, boolean *found){  /* record in place where each species has to be     added to reconstruct this tree */  long i, j;  node *p;  boolean done;  protreroot(treenode[outgrno - 1]);  protsavetraverse(root, pos,found);  for (i = 0; i < (nonodes); i++)    place[i] = 0;  place[root->index - 1] = 1;  for (i = 1; i <= (spp); i++) {    p = treenode[i - 1];    while (place[p->index - 1] == 0) {      place[p->index - 1] = i;      while (!p->bottom)        p = p->next;      p = p->back;    }    if (i > 1) {      place[i - 1] = place[p->index - 1];      j = place[p->index - 1];      done = false;      while (!done) {        place[p->index - 1] = spp + i - 1;        while (!p->bottom)          p = p->next;        p = p->back;        done = (p == NULL);        if (!done)          done = (place[p->index - 1] != j);      }    }  }}  /* protsavetree */void tryadd(node *p, node **item, node **nufork){  /* temporarily adds one fork and one tip to the tree.     if the location where they are added yields greater     "likelihood" than other locations tested up to that     time, then keeps that location as there */  long pos;  boolean found;  node *rute, *q;  if (p == root)    protfillin(temp, *item, p);  else {    protfillin(temp1, *item, p);    protfillin(temp, temp1, p->back);  }  evaluate(temp);  if (lastrearr) {    if (like < bestlike) {      if ((*item) == (*nufork)->next->next->back) {        q = (*nufork)->next;        (*nufork)->next = (*nufork)->next->next;        (*nufork)->next->next = q;        q->next = (*nufork);      }    }    else if (like >= bstlike2) {      recompute = false;      protadd(p, (*item), (*nufork));      rute = root->next->back;      protsavetree(&pos,&found);      protreroot(rute);      if (like > bstlike2) {        bestlike = bstlike2 = like;        pos = 1;        nextree = 1;        addtree(pos, &nextree, dummy, place, bestrees);      } else {        pos = 0;        findtree(&found, &pos, nextree, place, bestrees);        if (!found) {          if (nextree <= maxtrees)            addtree(pos, &nextree, dummy, place, bestrees);        }      }      protre_move (item, nufork);      recompute = true;    }  }  if (like > bestyet) {    bestyet = like;    there = p;  }}  /* tryadd */void addpreorder(node *p, node *item, node *nufork){  /* traverses a binary tree, calling PROCEDURE tryadd     at a node before calling tryadd at its descendants */  if (p == NULL)    return;  tryadd(p, &item,&nufork);  if (!p->tip) {    addpreorder(p->next->back, item, nufork);    addpreorder(p->next->next->back, item, nufork);  }}  /* addpreorder */void tryrearr(node *p, boolean *success){  /* evaluates one rearrangement of the tree.     if the new tree has greater "likelihood" than the old     one sets success := TRUE and keeps the new tree.     otherwise, restores the old tree */  node *frombelow, *whereto, *forknode, *q;  double oldlike;  if (p->back == NULL)    return;  forknode = treenode[p->back->index - 1];  if (forknode->back == NULL)    return;  oldlike = bestyet;  if (p->back->next->next == forknode)    frombelow = forknode->next->next->back;  else    frombelow = forknode->next->back;  whereto = treenode[forknode->back->index - 1];  if (whereto->next->back == forknode)    q = whereto->next->next->back;  else    q = whereto->next->back;  protfillin(temp1, frombelow, q);  protfillin(temp, temp1, p);  protfillin(temp1, temp, whereto->back);  evaluate(temp1);  if (like <= oldlike) {    if (p == forknode->next->next->back) {      q = forknode->next;      forknode->next = forknode->next->next;      forknode->next->next = q;      q->next = forknode;    }  }  else {    recompute = false;    protre_move(&p, &forknode);    protfillin(whereto, whereto->next->back, whereto->next->next->back);    recompute = true;    protadd(whereto, p, forknode);    *success = true;    bestyet = like;  }}  /* tryrearr */void repreorder(node *p, boolean *success){  /* traverses a binary tree, calling PROCEDURE tryrearr     at a node before calling tryrearr at its descendants */  if (p == NULL)    return;  tryrearr(p,success);  if (!p->tip) {    repreorder(p->next->back,success);    repreorder(p->next->next->back,success);  }}  /* repreorder */void rearrange(node **r){  /* traverses the tree (preorder), finding any local     rearrangement which decreases the number of steps.     if traversal succeeds in increasing the tree's     "likelihood", PROCEDURE rearrange runs traversal again */  boolean success = true;  while (success) {    success = false;    repreorder(*r, &success);  }}  /* rearrange */void protgetch(Char *c){  /* get next nonblank character */  do {    if (eoln(intree))      scan_eoln(intree);    *c = gettc(intree);    if (*c == '\n' || *c == '\t')      *c = ' ';  } while (!(*c != ' ' || eoff(intree)));}  /* protgetch */void protaddelement(node **p,long *nextnode,long *lparens,boolean *names){  /* recursive procedure adds nodes to user-defined tree */  node *q;  long i, n;  boolean found;  Char str[nmlngth];  protgetch(&ch);    if (ch == '(' ) {    if ((*lparens) >= spp - 1) {      printf("\nERROR IN USER TREE: TOO MANY LEFT PARENTHESES\n");      exxit(-1);    }    (*nextnode)++;    (*lparens)++;    q = treenode[(*nextnode) - 1];    protaddelement(&q->next->back, nextnode,lparens,names);    q->next->back->back = q->next;    findch(',', &ch, which);    protaddelement(&q->next->next->back, nextnode,lparens,names);    q->next->next->back->back = q->next->next;    findch(')', &ch, which);    *p = q;    return;  }  for (i = 0; i < nmlngth; i++)    str[i] = ' ';  n = 1;  do {    if (ch == '_')      ch = ' ';    str[n - 1] = ch;    if (eoln(intree))      scan_eoln(intree);    ch = gettc(intree);    n++;  } while (ch != ',' && ch != ')' && ch != ':' && n <= nmlngth);  n = 1;  do {    found = true;    for (i = 0; i < nmlngth; i++)      found = (found && ((str[i] == nayme[n - 1][i]) ||                         ((nayme[n - 1][i] == '_') && (str[i] == ' '))));    if (found) {      if (names[n - 1] == false) {        *p = treenode[n - 1];        names[n - 1] = true;      } else {        printf("\nERROR IN USER TREE: DUPLICATE NAME FOUND -- ");        for (i = 0; i < nmlngth; i++)          putchar(nayme[n - 1][i]);        putchar('\n');        exxit(-1);      }    } else      n++;  } while (!(n > spp || found));  if (n <= spp)    return;  printf("CANNOT FIND SPECIES: ");  for (i = 0; i < nmlngth; i++)    putchar(str[i]);  putchar('\n');}  /* protaddelement */void prottreeread(){  /* read in user-defined tree and set it up */  long nextnode, lparens, i;  root = treenode[spp];  nextnode = spp;  root->back = NULL;  names = (boolean *)Malloc(spp*sizeof(boolean));  for (i = 0; i < (spp); i++)    names[i] = false;  lparens = 0;  protaddelement(&root, &nextnode,&lparens,names);  if (ch == '[') {    do      ch = gettc(intree);    while (ch != ']');    ch = gettc(intree);  }  findch(';', &ch, which);  if (progress)    printf("\n\n");  fscanf(intree, "%*[^\n]");  gettc(intree);  free(names);}  /* prottreeread */void protancestset(long *a, long *b, long *c, long *d, long *k){  /* sets up the aa set array. */  aas aa;  long s, sa, sb;  long i, j, m, n;  boolean counted;  counted = false;  *k = 0;  for (i = 0; i <= 5; i++) {    if (*k < 3) {      s = 0;      if (i > 3)        n = i - 3;      else        n = 0;      for (j = n; j <= (i - n); j++) {        if (j < 3)          sa = a[j];        else          sa = fullset;        for (m = n; m <= (i - j - n); m++) {          if (m < 3)            sb = sa & b[m];          else            sb = sa;          if (i - j - m < 3)            sb &= c[i - j - m];          s |= sb;        }      }      if (counted || s != 0) {        d[*k] = s;        (*k)++;        counted = true;      }    }  }  for (i = 0; i <= 1; i++) {    for (aa = ala; (long)aa <= (long)stop; aa = (aas)((long)aa + 1)) {      if (((1L << ((long)aa)) & d[i]) != 0) {        for (j = i + 1; j <= 2; j++)          d[j] |= translate[(long)aa - (long)ala][j - i];      }    }  }}  /* protancestset */void prothyprint(long b1, long b2, boolean *bottom, node *r,                        boolean *nonzero, boolean *maybe){  /* print out states in sites b1 through b2 at node */  long i;  boolean dot;  Char ch = 0;  aas aa;  if (*bottom) {    if (!outgropt)      fprintf(outfile, "      ");    else      fprintf(outfile, "root  ");  } else    fprintf(outfile, "%3ld   ", r->back->index - spp);  if (r->tip) {    for (i = 0; i < nmlngth; i++)      putc(nayme[r->index - 1][i], outfile);  } else    fprintf(outfile, "%4ld      ", r->index - spp);  if (*bottom)    fprintf(outfile, "          ");  else if (*nonzero)    fprintf(outfile, "   yes    ");  else if (*maybe)    fprintf(outfile, "  maybe   ");  else    fprintf(outfile, "   no     ");  for (i = b1 - 1; i < b2; i++) {    aa = r->seq[i];    switch (aa) {    case ala:      ch = 'A';      break;    case asx:      ch = 'B';      break;    case cys:      ch = 'C';      break;    case asp:      ch = 'D';      break;    case glu:      ch = 'E';      break;    case phe:      ch = 'F';      break;    case gly:      ch = 'G';      break;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -