/* Program From Progressive Alignment of Amino Acid Sequences and Construction of Phylogenetic Trees from Them, by D. F. Feng and R. F. Doolittle, Methods of Enzymology, v266, p368 (1996) 2/7/1996 Read "readme.doc" before using. */ #include char InputString[300], dist[1300][8]; main(ac,av) int ac; char *av[]; { FILE *fd, *fd1, *fopen(); double atof(); int i,j,k,length,nseq,index; int lstrng,bracket,one,two,three; char c,c1,c2,c3,code[25],newcode[60][10]; char strng[1000],split[10]; float x1,x2,x3,lsplit,rsplit; if(ac<2) { fprintf(stderr,"\nPurpose: Convert Information to a"); fprintf(stderr," Format Recognized by Treedrawing Program.\n"); fprintf(stderr,"usage: %s rf > wf\n",av[0]); fprintf(stderr,"\trf: Use `tomac' (an output file"); fprintf(stderr," of blen or noneg.)\n"); fprintf(stderr,"\twf: File for tree drawing.\n\n"); exit(0); } fprintf(stderr,"If you want to use the four letter code, hit , otherwise\n"); fprintf(stderr,"enter a new name with no more than 20 characters\n\n"); fd = fopen(av[1],"r"); fscanf(fd,"%s",InputString); /* printf("%s\n",InputString); */ i=0; while(fscanf(fd,"%s",dist[i++]) != EOF) ; fclose(fd); fd1 = fopen("algr","r"); nseq = 0; while(fscanf(fd,"%s",newcode[nseq++])!=EOF); ; fclose(fd1); fd1 = fopen("dontneed","w"); fclose(fd1); fd1 = fopen("dontneed","a"); i=k=0; fprintf(fd1,"("); while(InputString[i] != '\0') { c1 = InputString[i]; c2 = InputString[i+1]; c3 = InputString[i+2]; if(c3 == '\0' && ((c2>='A' && c2<='Z')||(c2>='a'&&c2<='z'))) { x1 = atof(dist[k]); x2 = x1*0.2; x3 = x1*0.8; j=0; if(c2>='A' && c2<='Z') index = c2-'A'; else if(c2>='a' && c2<='z') index = c2-'a' + 26; fprintf(stderr,"Change %s to ...",newcode[index]); while((c=getchar())!='\n') code[j++]=c; code[j] = '\0'; if(j>0) fprintf(fd1,"):%3.1f,%s:%3.1f",x2,code,x3); else fprintf(fd1,"):%3.1f,%s:%3.1f",x2,newcode[index],x3); goto out; } else { /* ( */ if(c1=='(') fprintf(fd1,"%c",c1); /* XY */ else if((c1>='A' && c1<='Z') && (c2>='A' && c2<='Z')) { j=0; if(c1>='A' && c1<='Z') index = c1-'A'; else if(c1>='a' && c1<='z') index = c1-'a' + 26; fprintf(stderr,"Change %s to ...",newcode[index]); while((c=getchar())!='\n') code[j++]=c; code[j] = '\0'; if(j>0) fprintf(fd1,"%s:%s,",code,dist[k++]); else fprintf(fd1,"%s:%s,",newcode[index],dist[k++]); } /* xy */ else if((c1>='a' && c1<='z') && (c2>='a' && c2<='z')) { j=0; if(c1>='A' && c1<='Z') index = c1-'A'; else if(c1>='a' && c1<='z') index = c1-'a' + 26; fprintf(stderr,"Change %s to ...",newcode[index]); while((c=getchar())!='\n') code[j++]=c; code[j] = '\0'; if(j>0) fprintf(fd1,"%s:%s,",code,dist[k++]); else fprintf(fd1,"%s:%s,",newcode[index],dist[k++]); } /* Xy */ else if((c1>='A' && c1<='Z') && (c2>='a' && c2<='z')) { j=0; if(c1>='A' && c1<='Z') index = c1-'A'; else if(c1>='a' && c1<='z') index = c1-'a' + 26; fprintf(stderr,"Change %s to ...",newcode[index]); while((c=getchar())!='\n') code[j++]=c; code[j] = '\0'; if(j>0) fprintf(fd1,"%s:%s,",code,dist[k++]); else fprintf(fd1,"%s:%s,",newcode[index],dist[k++]); } /* xY */ else if((c1>='a' && c1<='z') && (c2>='A' && c2<='Z')) { j=0; if(c1>='A' && c1<='Z') index = c1-'A'; else if(c1>='a' && c1<='z') index = c1-'a' + 26; fprintf(stderr,"Change %s to ...",newcode[index]); while((c=getchar())!='\n') code[j++]=c; code[j] = '\0'; if(j>0) fprintf(fd1,"%s:%s,",code,dist[k++]); else fprintf(fd1,"%s:%s,",newcode[index],dist[k++]); } /* X) */ else if((c1>='A' && c1<='Z') && c2==')') { j=0; if(c1>='A' && c1<='Z') index = c1-'A'; else if(c1>='a' && c1<='z') index = c1-'a' + 26; fprintf(stderr,"Change %s to ...",newcode[index]); while((c=getchar())!='\n') code[j++]=c; code[j] = '\0'; if(j>0) fprintf(fd1,"%s:%s",code,dist[k++]); else fprintf(fd1,"%s:%s",newcode[index],dist[k++]); } /* x) */ else if((c1>='a' && c1<='z') && c2==')') { j=0; if(c1>='A' && c1<='Z') index = c1-'A'; else if(c1>='a' && c1<='z') index = c1-'a' + 26; fprintf(stderr,"Change %s to ...",newcode[index]); while((c=getchar())!='\n') code[j++]=c; code[j] = '\0'; if(j>0) fprintf(fd1,"%s:%s",code,dist[k++]); else fprintf(fd1,"%s:%s",newcode[index],dist[k++]); } /* )Y */ else if(c1==')' && (c2>='A' && c2<='Z')) fprintf(fd1,"%c:%s,",c1,dist[k++]); /* )z */ else if(c1==')' && (c2>='a' && c2<='z')) fprintf(fd1,"%c:%s,",c1,dist[k++]); /* )) */ else if(c1==')' && c2==')') fprintf(fd1,"%c:%s",c1,dist[k++]); /* )( */ else if(c1==')' && c2=='(') fprintf(fd1,"%c:%s,",c1,dist[k++]); /* )\0 */ else if(c1==')' && c2=='\0') fprintf(fd1,")"); /* X\0 */ else if((c1>='A' && c1<='Z') && c2=='\0') { j=0; if(c1>='A' && c1<='Z') index = c1-'A'; else if(c1>='a' && c1<='z') index = c1-'a' + 26; fprintf(stderr,"Change %s to ...",newcode[index]); while((c=getchar())!='\n') code[j++]=c; code[j] = '\0'; if(j>0) fprintf(fd1,"%s",code); else fprintf(fd1,"%s",newcode[index]); } /* x\0 */ else if((c1>='a' && c1<='z') && c2=='\0') { j=0; if(c1>='A' && c1<='Z') index = c1-'A'; else if(c1>='a' && c1<='z') index = c1-'a' + 26; fprintf(stderr,"Change %s to ...",newcode[index]); while((c=getchar())!='\n') code[j++]=c; code[j] = '\0'; if(j>0) fprintf(fd1,"%s",code); else fprintf(fd1,"%s",newcode[index]); } } i++; } out: fprintf(fd1,");\n"); fclose(fd1); fd1 = fopen("dontneed","r"); fscanf(fd1,"%s",strng); fclose(fd1); lstrng = strlen(strng); three = lstrng-2; if(strng[lstrng-3]!=')') { remove("dontneed"); exit(printf("%s\n",strng)); } else { lstrng = lstrng-4; bracket = 1; for(;;) { if(strng[lstrng]==')') bracket++; else if (strng[lstrng]=='(') bracket--; else ; lstrng--; if(bracket==0) break; } } two = lstrng; while(strng[lstrng]!=':') lstrng--; lstrng++; one = lstrng; i=0; while(strng[lstrng]!=',') split[i++] = strng[lstrng++]; split[i]='\0'; lsplit = rsplit = atof(split)*0.50; for(i=0; i