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

📄 phylip.c

📁 一个神经网络工具箱
💻 C
📖 第 1 页 / 共 5 页
字号:
{  /* go to new line if i is a multiple of j, indent k spaces */  long m;  if ((i - 1) % j != 0 || i <= 1)    return;  putc('\n', filename);  for (m = 1; m <= k; m++)    putc(' ', filename);}  /* newline */void inputnumbersold(long *spp, long *chars, long *nonodes, long n){  /* input the numbers of species and of characters */  if (fscanf(infile, "%ld%ld", spp, chars) != 2 || *spp <= 0 || *chars <= 0) {    printf(    "ERROR: Unable to read the number of species or characters in data set\n");    printf(      "The input file is incorrect (perhaps it was not saved text only).\n");  }  *nonodes = *spp * 2 - n;}  /* inputnumbersold */void inputnumbers(long *spp, long *chars, long *nonodes, long n){  /* input the numbers of species and of characters */  if (fscanf(infile, "%ld%ld", spp, chars) != 2 || *spp <= 0 || *chars <= 0) {    printf(    "ERROR: Unable to read the number of species or characters in data set\n");    printf(      "The input file is incorrect (perhaps it was not saved text only).\n");  }  fscanf(infile, "%*[^\n]");  *nonodes = *spp * 2 - n;}  /* inputnumbers */void inputnumbers2(long *spp, long *nonodes, long n){  /* read species number */  if (fscanf(infile, "%ld", spp) != 1 || *spp <= 0) {    printf("ERROR: Unable to read the number of species in data set\n");    printf(      "The input file is incorrect (perhaps it was not saved text only).\n");  }  fscanf(infile, "%*[^\n]");  fprintf(outfile, "\n%4ld Populations\n", *spp);  *nonodes = *spp * 2 - n;}  /* inputnumbers2 */void inputnumbers3(long *spp, long *chars){  /* input the numbers of species and of characters */  if (fscanf(infile, "%ld%ld", spp, chars) != 2 || *spp <= 0 || *chars <= 0) {    printf(    "ERROR: Unable to read the number of species or characters in data set\n");    printf(       "The input file is incorrect (perhaps it was not saved text only).\n");    exxit(-1);  }}  /* inputnumbers3 */void samenumsp(long *chars, long ith){  /* check if spp is same as the first set in other data sets */  long cursp, curchs;  if (eoln(infile))     scan_eoln(infile);  fscanf(infile, "%ld%ld", &cursp, &curchs);  if (cursp != spp) {    printf(         "\n\nERROR: Inconsistent number of species in data set %ld\n\n", ith);    exxit(-1);  }  *chars = curchs;} /* samenumsp */void samenumsp2(long ith){  /* check if spp is same as the first set in other data sets */  long cursp;  if (eoln(infile))     scan_eoln(infile);  if (fscanf(infile, "%ld", &cursp) != 1) {    printf("\n\nERROR: Unable to read number of species in data set %ld\n",      ith);    printf(      "The input file is incorrect (perhaps it was not saved text only).\n");    exxit(-1);  }  if (cursp != spp) {    printf(      "\n\nERROR: Inconsistent number of species in data set %ld\n\n", ith);    exxit(-1);  }} /* samenumsp2 */void readoptions(long *extranum, const char *options){ /* read option characters from input file */  Char ch;  while (!(eoln(infile))) {    ch = gettc(infile);    uppercase(&ch);    if (strchr(options, ch) != NULL)     (* extranum)++;    else if (!(ch == ' ' || ch == '\t')) {      printf("BAD OPTION CHARACTER: %c\n", ch);      exxit(-1);    }  }  scan_eoln(infile);}  /* readoptions */void matchoptions(Char *ch, const char *options){  /* match option characters to those in auxiliary options line */  *ch = gettc(infile);  uppercase(ch);  if (strchr(options, *ch) == NULL) {    printf("ERROR: Incorrect auxiliary options line");    printf(" which starts with %c\n", *ch);    exxit(-1);  }}  /* matchoptions */void inputweightsold(long chars, steptr weight, boolean *weights){  Char ch;  int i;  for (i = 1; i < nmlngth ; i++)    getc(infile);   for (i = 0; i < chars; i++) {    do {      if (eoln(infile))         scan_eoln(infile);      ch = gettc(infile);      if (ch == '\n')        ch = ' ';    } while (ch == ' ');    weight[i] = 1;    if (isdigit(ch))      weight[i] = ch - '0';    else if (isalpha(ch)) {      uppercase(&ch);      weight[i] = ch - 'A' + 10;    } else {      printf("\n\nERROR: Bad weight character: %c\n\n", ch);      exxit(-1);    }  }  scan_eoln(infile);  *weights = true;} /*inputweightsold*/void inputweights(long chars, steptr weight, boolean *weights){  /* input the character weights, 0-9 and A-Z for weights 0 - 35 */  Char ch;  long i;  for (i = 0; i < chars; i++) {    do {      if (eoln(weightfile))         scan_eoln(weightfile);      ch = gettc(weightfile);      if (ch == '\n')        ch = ' ';    } while (ch == ' ');    weight[i] = 1;    if (isdigit(ch))      weight[i] = ch - '0';    else if (isalpha(ch)) {      uppercase(&ch);      weight[i] = ch - 'A' + 10;    } else {      printf("\n\nERROR: Bad weight character: %c\n\n", ch);      exxit(-1);    }  }  scan_eoln(weightfile);  *weights = true;}  /* inputweights */void inputweights2(long a, long b, long *weightsum,        steptr weight, boolean *weights, const char *prog){  /* input the character weights, 0 or 1 */  Char ch;  long i;  *weightsum = 0;  for (i = a; i < b; i++) {    do {      if (eoln(weightfile))        scan_eoln(weightfile);      ch = gettc(weightfile);    } while (ch == ' ');    weight[i] = 1;    if (ch == '0' || ch == '1')      weight[i] = ch - '0';    else {      printf("\n\nERROR: Bad weight character: %c -- ", ch);      printf("weights in %s must be 0 or 1\n", prog);      exxit(-1);    }    *weightsum += weight[i];  }  *weights = true;  scan_eoln(weightfile);}  /* inputweights2 */void printweights(FILE *filename, long inc, long chars,        steptr weight, const char *letters){  /* print out the weights of sites */  long i, j;  boolean letterweights;  letterweights = false;  for (i = 0; i < chars; i++)    if (weight[i] > 9)      letterweights = true;  fprintf(filename, "\n    %s are weighted as follows:",letters);  if (letterweights)    fprintf(filename, " (A = 10, B = 11, etc.)\n");  else    putc('\n', filename);  for (i = 0; i < chars; i++) {    if (i % 60 == 0) {      putc('\n', filename);      for (j = 1; j <= nmlngth + 3; j++)        putc(' ', filename);    }    if (weight[i+inc] < 10)      fprintf(filename, "%ld", weight[i + inc]);    else      fprintf(filename, "%c", 'A'-10+(int)weight[i + inc]);    if ((i+1) % 5 == 0 && (i+1) % 60 != 0)      putc(' ', filename);  }  fprintf(filename, "\n\n");}  /* printweights */void inputcategs(long a, long b, steptr category, long categs,const char *prog){  /* input the categories, 1-9 */  Char ch;  long i;  for (i = a; i < b; i++) {    do {      if (eoln(catfile))         scan_eoln(catfile);      ch = gettc(catfile);    } while (ch == ' ');    if ((ch >= '1') && (ch <= ('0'+categs)))      category[i] = ch - '0';    else {      printf("\n\nERROR: Bad category character: %c", ch);      printf(" -- categories in %s are currently 1-%ld\n", prog, categs);      exxit(-1);    }  }  scan_eoln(catfile);}  /* inputcategs */void printcategs(FILE *filename, long chars, steptr category,                 const char *letters){  /* print out the sitewise categories */  long i, j;  fprintf(filename, "\n    %s are:\n",letters);  for (i = 0; i < chars; i++) {    if (i % 60 == 0) {      putc('\n', filename);      for (j = 1; j <= nmlngth + 3; j++)        putc(' ', filename);    }    fprintf(filename, "%ld", category[i]);    if ((i+1) % 10 == 0 && (i+1) % 60 != 0)      putc(' ', filename);  }  fprintf(filename, "\n\n");}  /* printcategs */void inputfactors(long chars, Char *factor, boolean *factors){  /* reads the factor symbols */  long i;  for (i = 1; i < nmlngth; i++)    gettc(infile);  for (i = 0; i < (chars); i++) {    if (eoln(infile))       scan_eoln(infile);    factor[i] = gettc(infile);    if (factor[i] == '\n')      factor[i] = ' ';  }  scan_eoln(infile);  *factors = true;}  /* inputfactors */void inputfactorsnew(long chars, Char *factor, boolean *factors){  /* reads the factor symbols */  long i;  for (i = 0; i < (chars); i++) {    if (eoln(factfile))       scan_eoln(factfile);    factor[i] = gettc(factfile);    if (factor[i] == '\n')      factor[i] = ' ';  }  scan_eoln(factfile);  *factors = true;}  /* inputfactorsnew */void printfactors(FILE *filename, long chars, Char *factor, const char *letters){  /* print out list of factor symbols */  long i;  fprintf(filename, "Factors%s:\n\n", letters);  for (i = 1; i <= nmlngth - 5; i++)    putc(' ', filename);  for (i = 1; i <= (chars); i++) {    newline(filename, i, 55, nmlngth + 3);    putc(factor[i - 1], filename);    if (i % 5 == 0)      putc(' ', filename);  }  putc('\n', filename);}  /* printfactors */void headings(long chars, const char *letters1, const char *letters2){  long i, j;  putc('\n', outfile);  j = nmlngth + (chars + (chars - 1) / 10) / 2 - 5;  if (j < nmlngth - 1)    j = nmlngth - 1;  if (j > 37)    j = 37;  fprintf(outfile, "Name");  for (i = 1; i <= j; i++)    putc(' ', outfile);  fprintf(outfile, "%s\n", letters1);  fprintf(outfile, "----");  for (i = 1; i <= j; i++)    putc(' ', outfile);  fprintf(outfile, "%s\n\n", letters2);}  /* headings */void initname(long i){  /* read in species name */  long j;  for (j = 0; j < nmlngth; j++) {    if (eoff(infile) | eoln(infile)){      printf("\n\nERROR: end-of-line or end-of-file");      printf(" in the middle of species name for species %ld\n\n", i+1);      exxit(-1);    }    nayme[i][j] = gettc(infile);    if ((nayme[i][j] == '(') || (nayme[i][j] == ')') || (nayme[i][j] == ':')        || (nayme[i][j] == ',') || (nayme[i][j] == ';') || (nayme[i][j] == '[')        || (nayme[i][j] == ']')) {      printf("\nERROR: Species name may not contain characters ( ) : ; , [ ] \n");      printf("       In name of species number %ld there is character %c\n\n",              i+1, nayme[i][j]);      exxit(-1);    }  }} /* initname */void findtree(boolean *found,long *pos,long nextree,long *place,bestelm *bestrees){  /* finds tree given by array place in array bestrees by binary search */  /* used by dnacomp, dnapars, dollop, mix, & protpars */  long i, lower, upper;  boolean below, done;  below = false;  lower = 1;  upper = nextree - 1;  (*found) = false;  while (!(*found) && lower <= upper) {    (*pos) = (lower + upper) / 2;    i = 3;    done = false;    while (!done) {      done = (i > spp);      if (!done)        done = (place[i - 1] != bestrees[(*pos) - 1].btree[i - 1]);      if (!done)        i++;    }    (*found) = (i > spp);    if (*found)      break;    below = (place[i - 1] <  bestrees[(*pos )- 1].btree[i - 1]);    if (below)      upper = (*pos) - 1;    else      lower = (*pos) + 1;  }  if (!(*found) && !below)    (*pos)++;}  /* findtree */void addtree(long pos,long *nextree,boolean collapse,long *place,bestelm *bestrees){  /* puts tree from array place in its proper position in array bestrees */  /* used by dnacomp, dnapars, dollop, mix, & protpars */  long i;  for (i = *nextree - 1; i >= pos; i--){    memcpy(bestrees[i].btree, bestrees[i - 1].btree, spp * sizeof(long));    bestrees[i].gloreange = bestrees[i - 1].gloreange;    bestrees[i - 1].gloreange = false;    bestrees[i].locreange = bestrees[i - 1].locreange;    bestrees[i - 1].locreange = false;    bestrees[i].collapse = bestrees[i - 1].collapse;  }  for (i = 0; i < spp; i++)    bestrees[pos - 1].btree[i] = place[i];    bestrees[pos - 1].collapse = collapse;  (*nextree)++;}  /* addtree */long findunrearranged(bestelm *bestrees, long nextree, boolean glob){  /* finds bestree with either global or local field false */  long i;  if (glob) {    for (i = 0; i < nextree - 1; i++)      if (!bestrees[i].gloreange)        return i;  } else {    for (i = 0; i < nextree - 1; i++)      if (!bestrees[i].locreange)        return i;  }  return -1;} /* findunrearranged */boolean torearrange(bestelm *bestrees, long nextree){ /* sees if any best tree is yet to be rearranged */  if (findunrearranged(bestrees, nextree, true) >= 0)    return true;  else if (findunrearranged(bestrees, nextree, false) >= 0)    return true;  else    return false;} /* torearrange */void reducebestrees(bestelm *bestrees, long *nextree){  /* finds best trees with collapsible branches and deletes them */  long i, j;  i = 0;  j = *nextree - 2;  do {    while (!bestrees[i].collapse && i < *nextree - 1) i++;    while (bestrees[j].collapse && j >= 0) j--;    if (i < j) {      memcpy(bestrees[i].btree, bestrees[j].btree, spp * sizeof(long));      bestrees[i].gloreange = bestrees[j].gloreange;      bestrees[i].locreange = bestrees[j].locreange;      bestrees[i].collapse = false;      bestrees[j].collapse = true;    }  } while (i < j);  *nextree = i + 1;

⌨️ 快捷键说明

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