-
Notifications
You must be signed in to change notification settings - Fork 1
/
translate.c
87 lines (76 loc) · 2.41 KB
/
translate.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include <stdio.h>
#include <stdlib.h>
void translate()
{
int i;
char dna[3];
int base[3];
char amino;
fflush(stdin);
printf("please input a whole sequence:");
dna[0]=getchar();
dna[1]=getchar();
dna[2]=getchar();
for(i=0;i<=2;++i){
if (transla(dna[i])==-1) {
printf("\n");
printf("error\n");
exit (1);
}
}
while(1){
while((dna[0] == 'G' || dna[0] == 'g') || (dna[1] != 'T' && dna[1] != 't')|| (dna[2] != 'G' && dna[2] != 'g')){
dna[0]=dna[1];
dna[1]=dna[2];
dna[2]=getchar();
if (dna[2]=='\n') exit (0);
if (transla(dna[2])==-1) {
printf("\n");
printf("error\n");
exit (1);
}
}
while(1){
for(i=0;i<=2;++i) {
if (transla(dna[i])!=-1) base[i]=transla(dna[i]);
else {
printf("\n");
printf("error\n");
exit (1);
}
}
amino = codon(base[0],base[1],base[2]);
printf("%c",amino);
if (amino == '*') break;
dna[0]=getchar();
if(dna[0]=='\n') {printf(" It's the end of the sequence."); exit(0);}
dna[1]=getchar();
if(dna[1]=='\n') {printf(" It's the end of the sequence."); exit(0);}
dna[2]=getchar();
if(dna[2]=='\n') {printf(" It's the end of the sequence."); exit(0);}
}
dna[0]=getchar();
if(dna[0]=='\n') {printf("\n"); exit(0);}
if (transla(dna[2])==-1) {
printf("\n");
printf("error\n");
exit (1);
}
dna[1]=getchar();
if(dna[1]=='\n') {printf("\n"); exit(0);}
if (transla(dna[2])==-1) {
printf("\n");
printf("error\n");
exit (1);
}
dna[2]=getchar();
if(dna[2]=='\n') {printf("\n"); exit(0);}
if (transla(dna[2])==-1) {
printf("\n");
printf("error\n");
exit (1);
}
printf("\n");
}
exit (0);
}