/* \input cnoweb Program: weighbor \hfill\break Version: II File: weighbor.c \hfill\break Author: N. D. Socci \hfill\break \title{weighbor.c} \job{Weighbor} \synopsis{\"Weigh"ted neigh\"bor"-joining. This program will created a evolutionary tree based on distance between sequences. The tree built attempts to minimize the distances in it versus the actually distances inputted to the program. The output is the tree built along with the branch lengths.} */ /*__* *__* *__* WEIGHBOR 1.2 [21-Jun-01] *__* *__* Copyright (c) 1997-2001 *__* Los Alamos National Laboratories *__* The Rockefeller University *__* *__* This file is part of the WEIGHBOR program that can be used free of *__* charge in academic research and teaching. Any commercial use of *__* this software requires prior permission and possibly a license. For *__* commercial use contact: W. Bruno at billb@t10.lanl.gov Los Alamos *__* National Laboratories makes no representations about the *__* suitability of this software for any purpose. It is provided *__* "as is" without express or implied warranty *__* *__* For those using this program for research please use the following *__* citation for this program: *__* *__* Bruno, W. J., Socci, N. D. and Halpern, A. L., ``Weighted *__* Neighbor Joining: A Fast Approximation to Maximum-Likelihood *__* Phylogeny Reconstruction,'' Molecular Biology and Evolution, *__* 17(1): 189-197, (2000). *__* *__* *__*/ /* \section{Introduction} The default input file is: \|infile| The default output file is \|treefile| The algorithm used is a weighted neighbor-joining one from W. Bruno (\'refs'). The weights are computed by the function \|weight(d1,d2)|. Important note. Array indices are from $0\ldots N-1$ in contrast to the first version which went from $1\ldots N$ */ #define __WEIGHBOR_C #include #include #include #include "tree.h" #include "matrix.h" #include "io.h" #include "weighbor.h" static char version[] __attribute__ ((unused)) = "$Id: weighbor.c,v 1.7 2001/06/22 19:05:45 nds Exp $"; BooleanT expertMode=False; #ifdef OFF void getInput(char *buf, int SIZE) { int i=0; char ch; do { ch=getc(stdin); if(ch=='\n'||ch==EOF) buf[i++]=(char)NULL; else buf[i++] = ch; }while(ch!='\n' && ch!=EOF && i<(SIZE-1)); buf[SIZE-1] = 0; } #endif void usage() { fprintf(stderr, VERSION_INFO); fprintf(stderr, "usage: weighbor [-L num] [-b num] [-i name] [-o name] [-v[v[v]]] [-V]\n"); fprintf(stderr, " -L num set the sequence length to num (default %g)\n", DEFAULT_LENGTH); fprintf(stderr, " -b num set number of bases (default %g)\n", DEFAULT_B); fprintf(stderr, " -i name read input from file\n"); fprintf(stderr, " -o name write output to file\n"); fprintf(stderr, " -v turn on logfile and dump level 1 info\n"); fprintf(stderr, " -vv turn on logfile and dump level 2 info\n"); fprintf(stderr, " -vvv turn on logfile and dump level 3 info\n"); fprintf(stderr, " -V print version information\n"); fprintf(stderr, "\nFor those using this program for research please use the following\n"); fprintf(stderr, "citation for this program:\n\n"); fprintf(stderr, " Bruno, W. J., Socci, N. D. and Halpern, A. L., ``Weighted\n"); fprintf(stderr, " Neighbor Joining: A Fast Approximation to Maximum-Likelihood\n"); fprintf(stderr, " Phylogeny Reconstruction,'' Molecular Biology and Evolution,\n" ); fprintf(stderr, " 17(1): 189-197, (2000).\n"); if(expertMode) { fprintf(stderr, "\n Advance (expert) options [-XqrzSTeZ]\n"); fprintf(stderr, " -X turn on expert mode (allows use of these options)\n"); fprintf(stderr, " n change normalization of R(i,j,j')\n"); fprintf(stderr, " q turn off q[q[i]]==i checking\n"); fprintf(stderr, " r turn on recalculation of Delta B\n"); fprintf(stderr, " z use the old (N^3) method to calculate z(i,j)\n"); fprintf(stderr, " S use barred version of sigma for R(i,j,j')\n"); fprintf(stderr, " T use unbarred versions of d, Delta B and S for R(i,j,j')\n"); fprintf(stderr, " e extended tournament option\n"); fprintf(stderr, " w turn on non-deterministic warnings\n"); fprintf(stderr, " x change normaliztion of R(i,j)\n"); fprintf(stderr, " Z Calculate PQNew and sigmaNew for z-score\n"); } exit(0); } int main(int argc, char *argv[]) { int i; FILE *fp=stdout, *inputfp=stdin; int N; /* Number of taxa */ MatrixT D; /* Distance Matrix */ char **taxon; /* names of taxa */ BooleanT lengthFlag = False; /* set if the -L option was given */ RootNodeT *tree; RootNodeT *buildTree(int, MatrixT, char **); #ifdef MENUIO char inputbuf[256]; #endif #ifndef MENUIO for(i=1;i0) { outfile = fopen("weighbor.out", "w"); if(!outfile) printError("weighbor::main::open(outfile)"); } else outfile = NULL; while(readPhylipFile(inputfp, &N, &D, &taxon)) { int i; if(printLevel>0) { fprintf(outfile, "\n============================================"); if(printLevel>1) { fprintf(outfile, "\nL = %g, b = %g\n", L, B); fprintf(outfile,"\nInput Distance Matrix = \n"); for(i=0;i0) fprintf(outfile, "\n(%s)\n\n", taxon[0]); break; case 2: /* 2 taxon; trivial tree with each branch $=D_{0,1}/2$ */ fprintf(fp, "(%s:%f,%s:%f)\n", taxon[0], .5*D[0][1], taxon[1], .5*D[0][1]); if(printLevel>0) fprintf(outfile, "\n(%s:%f,%s:%f)\n\n", taxon[0], .5*D[0][1], taxon[1], .5*D[0][1]); break; default: /* 3 or more need to build the tree */ tree = buildTree(N, D, taxon); printTree(fp, tree); if(printLevel>0) { fprintf(outfile, "\n"); printTree(outfile, tree); } deleteTree(tree); /* Now free the memory used by the name strings */ for(i=0;i0) fclose(outfile); fclose(fp); #ifdef MENUIO printf("done\n"); #endif return(0); } /* \endc */