| 1 | #include <stdio.h> |
|---|
| 2 | #include <string.h> |
|---|
| 3 | #include <stdlib.h> |
|---|
| 4 | #ifdef THINK_C |
|---|
| 5 | #include <console.h> |
|---|
| 6 | #endif |
|---|
| 7 | #include "clustalv.h" |
|---|
| 8 | #include "matrices.h" |
|---|
| 9 | |
|---|
| 10 | /* |
|---|
| 11 | * Prototypes |
|---|
| 12 | */ |
|---|
| 13 | |
|---|
| 14 | extern void *ckalloc(size_t); |
|---|
| 15 | extern void init_show_pair(void); |
|---|
| 16 | extern void init_upgma(void); |
|---|
| 17 | extern void init_myers(void); |
|---|
| 18 | extern void init_amenu(void); |
|---|
| 19 | extern void init_trees(void); |
|---|
| 20 | extern void fill_chartab(void); |
|---|
| 21 | extern void parse_params(void); |
|---|
| 22 | extern void main_menu(void); |
|---|
| 23 | |
|---|
| 24 | void make_pamo(int); |
|---|
| 25 | Boolean read_tree(int *,double *,int *,int *,int *); |
|---|
| 26 | |
|---|
| 27 | static void alloc_mem(void); |
|---|
| 28 | |
|---|
| 29 | |
|---|
| 30 | /* |
|---|
| 31 | * Global variables |
|---|
| 32 | */ |
|---|
| 33 | |
|---|
| 34 | extern Boolean usemenu; |
|---|
| 35 | |
|---|
| 36 | char **seq_array; |
|---|
| 37 | int *seqlen_array; |
|---|
| 38 | char **names,**titles; |
|---|
| 39 | char *params; |
|---|
| 40 | FILE *fin,*tree; |
|---|
| 41 | FILE *clustal_outfile, *gcg_outfile, *nbrf_outfile, *phylip_outfile; |
|---|
| 42 | char *matptr; |
|---|
| 43 | int xover,big_pam,little_pam; |
|---|
| 44 | int pamo[210]; |
|---|
| 45 | Boolean dnaflag; |
|---|
| 46 | char seqname[FILENAMELEN+1],mtrxname[FILENAMELEN+1],treename[FILENAMELEN+1]; |
|---|
| 47 | int nblocks,nseqs,next; |
|---|
| 48 | double **tmat; |
|---|
| 49 | |
|---|
| 50 | |
|---|
| 51 | static void alloc_mem() |
|---|
| 52 | { |
|---|
| 53 | register int i; |
|---|
| 54 | |
|---|
| 55 | seqlen_array = (int *)ckalloc( (MAXN+1) * sizeof (int)); |
|---|
| 56 | |
|---|
| 57 | seq_array = (char **)ckalloc( (MAXN + 1) * sizeof (char *) ); |
|---|
| 58 | for(i=0;i<MAXN+1;i++) |
|---|
| 59 | seq_array[i]=(char *)ckalloc( (MAXLEN +2) * sizeof (char)); |
|---|
| 60 | |
|---|
| 61 | names = (char **)ckalloc( (MAXN+1) * sizeof (char *) ); |
|---|
| 62 | for(i=0;i<MAXN+1;i++) |
|---|
| 63 | names[i] = (char *)ckalloc(MAXNAMES+1 * sizeof (char)); |
|---|
| 64 | |
|---|
| 65 | titles = (char **)ckalloc( (MAXN) * sizeof (char *) ); |
|---|
| 66 | for(i=0;i<MAXN;i++) |
|---|
| 67 | titles[i] = (char *)ckalloc(MAXTITLES+1 * sizeof (char)); |
|---|
| 68 | |
|---|
| 69 | tmat = (double **) ckalloc( (MAXN+1) * sizeof (double *) ); |
|---|
| 70 | for(i=0;i<MAXN+1;i++) |
|---|
| 71 | tmat[i] = (double *)ckalloc( (MAXN+1) * sizeof (double) ); |
|---|
| 72 | |
|---|
| 73 | params = (char *)ckalloc(1024 * sizeof(char)); |
|---|
| 74 | } |
|---|
| 75 | |
|---|
| 76 | |
|---|
| 77 | Boolean read_tree(int *n,double *s,int *a,int *b,int *ptr) |
|---|
| 78 | { |
|---|
| 79 | char line[MAXLINE+1]; |
|---|
| 80 | int i,seq_no; |
|---|
| 81 | /* Reads one entry from the tree file */ |
|---|
| 82 | |
|---|
| 83 | |
|---|
| 84 | for(i=0; i<=MAXLINE; i++) line[i] = ' '; |
|---|
| 85 | |
|---|
| 86 | if(fgets(line,MAXLINE+1,tree)==NULL) return FALSE; |
|---|
| 87 | |
|---|
| 88 | sscanf(line,"%lf%d%d%d",s,a,b,n); |
|---|
| 89 | for(i=MAXLINE, seq_no=nseqs; seq_no>0; i--) { |
|---|
| 90 | if(line[i] == '0') { |
|---|
| 91 | ptr[seq_no] = 0; |
|---|
| 92 | --seq_no; |
|---|
| 93 | } |
|---|
| 94 | else if(line[i] == '1') { |
|---|
| 95 | ptr[seq_no] = 1; |
|---|
| 96 | --seq_no; |
|---|
| 97 | } |
|---|
| 98 | else if(line[i] == '2') { |
|---|
| 99 | ptr[seq_no] = 2; |
|---|
| 100 | --seq_no; |
|---|
| 101 | } |
|---|
| 102 | } |
|---|
| 103 | return TRUE; |
|---|
| 104 | } |
|---|
| 105 | |
|---|
| 106 | |
|---|
| 107 | void make_pamo(int nv) |
|---|
| 108 | { |
|---|
| 109 | register int i,c; |
|---|
| 110 | |
|---|
| 111 | little_pam=big_pam=matptr[0]; |
|---|
| 112 | for(i=0;i<210;++i) { |
|---|
| 113 | c=matptr[i]; |
|---|
| 114 | little_pam=(little_pam<c) ? little_pam : c; |
|---|
| 115 | big_pam=(big_pam>c) ? big_pam : c; |
|---|
| 116 | } |
|---|
| 117 | for(i=0;i<210;++i) |
|---|
| 118 | pamo[i]= matptr[i]-little_pam; |
|---|
| 119 | nv -= little_pam; |
|---|
| 120 | big_pam -= little_pam; |
|---|
| 121 | xover = big_pam - nv; |
|---|
| 122 | /* |
|---|
| 123 | fprintf(stdout,"\n\nxover= %d, big_pam = %d, little_pam=%d, nv = %d\n\n" |
|---|
| 124 | ,xover,big_pam,little_pam,nv); |
|---|
| 125 | */ |
|---|
| 126 | } |
|---|
| 127 | |
|---|
| 128 | |
|---|
| 129 | |
|---|
| 130 | int main(int argc,char **argv) |
|---|
| 131 | { |
|---|
| 132 | int i; |
|---|
| 133 | |
|---|
| 134 | #ifdef THINK_C |
|---|
| 135 | argc=ccommand(&argv); |
|---|
| 136 | #endif |
|---|
| 137 | |
|---|
| 138 | matptr=pam250mt; |
|---|
| 139 | |
|---|
| 140 | alloc_mem(); |
|---|
| 141 | init_show_pair(); |
|---|
| 142 | init_upgma(); |
|---|
| 143 | init_myers(); |
|---|
| 144 | init_amenu(); |
|---|
| 145 | init_trees(); |
|---|
| 146 | |
|---|
| 147 | fill_chartab(); |
|---|
| 148 | make_pamo(0); |
|---|
| 149 | if(argc>1) { |
|---|
| 150 | params[0]=EOS; |
|---|
| 151 | for(i=1;i<argc;++i) |
|---|
| 152 | strcat(params,argv[i]); |
|---|
| 153 | usemenu=FALSE; |
|---|
| 154 | parse_params(); |
|---|
| 155 | } |
|---|
| 156 | else { |
|---|
| 157 | usemenu=TRUE; |
|---|
| 158 | main_menu(); |
|---|
| 159 | } |
|---|
| 160 | } |
|---|