📄 dnaml.c
字号:
#include "phylip.h"#include "seq.h"/* version 3.6. (c) Copyright 1993-2002 by the University of Washington. Written by Joseph Felsenstein, Akiko Fuseki, Sean Lamont, Andrew Keeffe, Dan Fineman, and Patrick Colacurcio. Permission is granted to copy and use this program provided no fee is charged for it and provided that this copyright notice is not removed. */typedef struct valrec { double rat, ratxi, ratxv, orig_zz, z1, y1, z1zz, z1yy, xiz1, xiy1xv; double *ww, *zz, *wwzz, *vvzz; } valrec;typedef long vall[maxcategs];typedef double contribarr[maxcategs];#ifndef OLDC/* function prototypes */void dnamlcopy(tree *, tree *, long, long);void getoptions(void);void allocrest(void);void doinit(void);void inputoptions(void);void makeweights(void);void getinput(void);void inittable_for_usertree(FILE *);void inittable(void);double evaluate(node *, boolean);void alloc_nvd (long, nuview_data *);void free_nvd (nuview_data *);void nuview(node *);void slopecurv(node *, double, double *, double *, double *);void makenewv(node *);void update(node *);void smooth(node *);void insert_(node *, node *, boolean);void dnaml_re_move(node **, node **);void buildnewtip(long, tree *);void buildsimpletree(tree *);void addtraverse(node *, node *, boolean);void rearrange(node *, node *);void initdnamlnode(node **, node **, node *, long, long, long *, long *, initops, pointarray, pointarray, Char *, Char *, FILE *);void dnaml_coordinates(node *, double, long *, double *);void dnaml_printree(void);void sigma(node *, double *, double *, double *);void describe(node *);void reconstr(node *, long);void rectrav(node *, long, long);void summarize(void);void dnaml_treeout(node *);void inittravtree(node *);void treevaluate(void);void maketree(void);void clean_up(void);void reallocsites(void);/* function prototypes */#endifextern sequence y;double fracchange;long rcategs;boolean haslengths;Char infilename[FNMLNGTH], outfilename[FNMLNGTH], intreename[FNMLNGTH], outtreename[FNMLNGTH], catfilename[FNMLNGTH], weightfilename[FNMLNGTH];double *rate, *rrate, *probcat;long nonodes2, sites, weightsum, categs, datasets, ith, njumble, jumb;long parens;boolean freqsfrom, global, jumble, weights, trout, usertree, reconsider, ctgry, rctgry, auto_, hypstate, ttr, progress, mulsets, justwts, firstset, improve, smoothit, polishing, lngths, gama, invar;tree curtree, bestree, bestree2, priortree;node *qwhere, *grbg;double xi, xv, ttratio, ttratio0, freqa, freqc, freqg, freqt, freqr, freqy, freqar, freqcy, freqgr, freqty, cv, alpha, lambda, invarfrac, bestyet;long *enterorder, inseed, inseed0;steptr aliasweight;contribarr *contribution, like, nulike, clai;double **term, **slopeterm, **curveterm;longer seed;Char* progname;char basechar[16]="acmgrsvtwyhkdbn";/* Local variables for maketree, propagated globally for c version: */long k, nextsp, numtrees, maxwhich, mx, mx0, mx1;double dummy, maxlogl;boolean succeeded, smoothed;double **l0gf;double *l0gl;valrec ***tbl;Char ch, ch2;long col;vall *mp=NULL;void dnamlcopy(tree *a, tree *b, long nonodes, long categs){ /* used in dnaml & dnamlk */ long i, j; node *p, *q; for (i = 0; i < spp; i++) { copynode(a->nodep[i], b->nodep[i], categs); if (a->nodep[i]->back) { if (a->nodep[i]->back == a->nodep[a->nodep[i]->back->index - 1]) b->nodep[i]->back = b->nodep[a->nodep[i]->back->index - 1]; else if (a->nodep[i]->back == a->nodep[a->nodep[i]->back->index - 1]->next) b->nodep[i]->back = b->nodep[a->nodep[i]->back->index - 1]->next; else b->nodep[i]->back = b->nodep[a->nodep[i]->back->index - 1]->next->next; } else b->nodep[i]->back = NULL; } for (i = spp; i < nonodes; i++) { p = a->nodep[i]; q = b->nodep[i]; for (j = 1; j <= 3; j++) { copynode(p, q, categs); if (p->back) { if (p->back == a->nodep[p->back->index - 1]) q->back = b->nodep[p->back->index - 1]; else if (p->back == a->nodep[p->back->index - 1]->next) q->back = b->nodep[p->back->index - 1]->next; else q->back = b->nodep[p->back->index - 1]->next->next; } else q->back = NULL; p = p->next; q = q->next; } } b->likelihood = a->likelihood; b->start = a->start; /* start used in dnaml only */ b->root = a->root; /* root used in dnamlk only */} /* dnamlcopy plc*/void getoptions(){ /* interactively set options */ long i, loopcount, loopcount2; Char ch; boolean didchangecat, didchangercat; double probsum; fprintf(outfile, "\nNucleic acid sequence Maximum Likelihood"); fprintf(outfile, " method, version %s\n\n",VERSION); putchar('\n'); didchangecat = false; didchangercat = false; reconsider = false; trout = true; usertree = false; weights = false; printdata = false; progress = true; treeprint = true; interleaved = false; loopcount = 0; for (;;){ cleerhome(); printf("Nucleic acid sequence 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 file" : "Yes")); if (usertree) { printf(" L Use lengths from user trees? %s\n", (lngths ? "Yes" : "No")); } printf(" T Transition/transversion ratio:%8.4f\n", (ttr ? ttratio : 2.0)); printf(" F Use empirical base frequencies? %s\n", (freqsfrom ? "Yes" : "No")); printf(" C One category of sites?"); if (!ctgry || categs == 1) printf(" Yes\n"); else printf(" %ld categories of sites\n", categs); printf(" R Rate variation among sites?"); if (!rctgry) printf(" constant rate\n"); else { if (gama) printf(" Gamma distributed rates\n"); else { if (invar) printf(" Gamma+Invariant sites\n"); else printf(" user-defined HMM of rates\n"); } printf(" A Rates at adjacent sites correlated?"); if (!auto_) printf(" No, they are independent\n"); else printf(" Yes, mean block length =%6.1f\n", 1.0 / lambda); } printf(" W Sites weighted? %s\n", (weights ? "Yes" : "No")); if ((!usertree) || reconsider) { printf(" S Speedier but rougher analysis? %s\n", (improve ? "No, not rough" : "Yes")); printf(" G Global rearrangements? %s\n", (global ? "Yes" : "No")); } if (!usertree) { printf(" J Randomize input order of sequences?"); if (jumble) printf(" Yes (seed =%8ld,%3ld times)\n", inseed0, njumble); else printf(" No. Use input order\n"); } else printf(" V Rearrange starting with user tree? %s\n", (reconsider ? "Yes" : "No")); printf(" O Outgroup root? %s%3ld\n", (outgropt ? "Yes, at sequence number" : "No, use as outgroup species"),outgrno); printf(" M Analyze multiple data sets?"); if (mulsets) printf(" Yes, %2ld %s\n", datasets, (justwts ? "sets of weights" : "data sets")); 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(" 3 Print out tree %s\n", (treeprint ? "Yes" : "No")); printf(" 4 Write out trees onto tree file? %s\n", (trout ? "Yes" : "No")); printf(" 5 Reconstruct hypothetical sequences? %s\n", (hypstate ? "Yes" : "No"));// printf("\n Y to accept these or type the letter for one to change\n"); printf("\n\n");#ifdef WIN32 phyFillScreenColor();#endif //scanf("%c%*[^\n]", &ch); //getchar(); //if (ch == '\n') // ch = ' '; //uppercase(&ch); ch='Y'; if (ch == 'Y') break; if (strchr("ULTFCRAWSGJVOMI012345",ch) != NULL){ switch (ch) { case 'F': freqsfrom = !freqsfrom; if (!freqsfrom) { initfreqs(&freqa, &freqc, &freqg, &freqt); } break; case 'C': ctgry = !ctgry; if (ctgry) { printf("\nSitewise user-assigned categories:\n\n"); initcatn(&categs); if (rate){ free(rate); } rate = (double *) Malloc(categs * sizeof(double)); didchangecat = true; initcategs(categs, rate); } break; case 'R': if (!rctgry) { rctgry = true; gama = true; } else { if (gama) { gama = false; invar = true; } else { if (invar) invar = false; else rctgry = false; } } break; case 'A': auto_ = !auto_; if (auto_) initlambda(&lambda); break; case 'W': weights = !weights; break; case 'S': improve = !improve; break; case 'G': global = !global; break; case 'J': jumble = !jumble; if (jumble) initjumble(&inseed, &inseed0, seed, &njumble); else njumble = 1; break; case 'L': lngths = !lngths; break; case 'O': outgropt = !outgropt; if (outgropt) initoutgroup(&outgrno, spp); break; case 'T': ttr = !ttr; if (ttr) { initratio(&ttratio); } break; case 'U': usertree = !usertree; break; case 'V': reconsider = !reconsider; break; case 'M': mulsets = !mulsets; if (mulsets) { printf("Multiple data sets or multiple weights?"); loopcount2 = 0; do { printf(" (type D or W)\n"); 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(&datasets); else initdatasets(&datasets); if (!jumble) { jumble = true; initjumble(&inseed, &inseed0, seed, &njumble); } } break; case 'I': interleaved = !interleaved; 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; case '5': hypstate = !hypstate; break; } } else printf("Not a possible option!\n"); countup(&loopcount, 100); } if (gama || invar) { loopcount = 0; if (alpha){ printf("-p%3.2f given, so alpha=1/(%3.2f)^2=%3.2f\n",sqrt(1.0/alpha),sqrt(1.0/alpha),alpha);}else{ do { printf( "\nCoefficient of variation of substitution rate among sites (must be positive)\n"); printf( " In gamma distribution parameters, this is 1/(square root of alpha)\n"); #ifdef WIN32 phyFillScreenColor(); #endif scanf("%lf%*[^\n]", &cv); getchar(); countup(&loopcount, 10); } while (cv <= 0.0); alpha = 1.0 / (cv * cv); printf("alpha=%3.2f\n",alpha); }} if (!rctgry) auto_ = false; if (rctgry) { printf("\nRates in HMM"); if (invar) printf(" (including one for invariant sites)"); printf(":\n"); if (rcategs){ printf("-c%d given, so rcategs=%d\n",rcategs,rcategs); }else{ initcatn(&rcategs); } if (probcat){ free(probcat); free(rrate); } probcat = (double *) Malloc(rcategs * sizeof(double)); rrate = (double *) Malloc(rcategs * sizeof(double)); didchangercat = true; if (gama) initgammacat(rcategs, alpha, rrate, probcat); else { if (invar) { loopcount = 0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -