File: tester.c

package info (click to toggle)
codonw 1.4.4-4
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 1,060 kB
  • sloc: ansic: 11,227; makefile: 209; sh: 170; perl: 36
file content (239 lines) | stat: -rwxr-xr-x 10,118 bytes parent folder | download | duplicates (2)
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
/**************************************************************************/
/* CodonW codon usage analysis package                                    */
/* Copyright (C) 2005            John F. Peden                            */
/* This program is free software; you can redistribute                    */
/* it and/or modify it under the terms of the GNU General Public License  */
/* as published by the Free Software Foundation; version 2 of the         */
/* License,                                                               */
/*                                                                        */
/* This program is distributed in the hope that it will be useful, but    */
/* WITHOUT ANY WARRANTY; without even the implied warranty of             */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the           */
/* GNU General Public License for more details.                           */
/* You should have received a copy of the GNU General Public License along*/
/* with this program; if not, write to the Free Software Foundation, Inc.,*/
/* 675 Mass Ave, Cambridge, MA 02139, USA.                                */
/*                                                                        */
/*                                                                        */
/* The author can be contacted by email (jfp#hanson-codonw@yahoo.com Anti-*/
/* Spam please change the # in my email to an _)                          */
/*                                                                        */
/* For the latest version and information see                             */
/* http://codonw.sourceforge.net 					  */
/******** Tester      *****************************************************/
/* This function is used to teach the genetic code, it generates a random */
/* series of questions about the selected genetic code.                   */
/* The questions include                                                  */
/*  1 and 3 letter amino acid names                                       */
/*  The translation of each codon                                         */
/*  The size of each amino acid family                                    */
/**************************************************************************/

#define rand_num(z) (int)((((float)rand()/((long)RAND_MAX))*(float)z)+1)

#ifdef _WINDOWS
#define beeep Beep(150,150)
#include <time.h>
#include <conio.h>
#else
#define beeep printf("\007")
#endif

#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <string.h>  
#include <time.h>
#include <ctype.h>
#include "codonW.h"

/* The accuracy of the answers are recorded using these three variable     */
int num_questions = 0;                      
int num_cheats = 0;
int num_wrong = 0;


void    tester ( void ) {
    char    loop;
    char    main_loop=TRUE;
    char    tmp_AA [4];
    char    tmp_AA2[4];

    srand( (unsigned)time( NULL ) );          /* initialise random num gen */

    printf(" Welcome to TESTER \n(which just tests your "
	     "knowledge of the Genetic code)\n"
           " The genetic code used is dependent on\n what"
	     " code is selected in menu 3\n"
           " The current code is %s %s\n"
           "\n If you get stuck try typing ? for a hint\n"
           " To leave type exit or quit\n", pcu->des, pcu->typ);

    /*******************  main loop            ****************************/
    while ( main_loop )   {
      int i,x;

        i = rand_num(10);           /*  random number to between 1 and 10 */

        printf("Type Help for help:");
        /* the switch biases the questions so their freq is not equal     */
        switch (i) {
        case 1: 
        case 2:                     /*  amino acid question               */
            i = rand_num(21);
            loop = TRUE;
            while ( loop ) {
                printf("\nWhat is the three letter equivalent for the AA"
                    " %s ", paa->aa1[i]);
                gets( pm->junk ) ;
                strcpy ( tmp_AA, paa->aa3[i] );
                for ( x = 0 ; x < (int)strlen(tmp_AA); x++) 
                    tmp_AA[x] = (char) toupper( (int) tmp_AA[x]);
                for ( x = 0 ; x < (int)strlen(pm->junk  ); x++) 
                    pm->junk  [x] =  (char) toupper(  (int) pm->junk[x]);
                if ( !strcmp ( pm->junk, "QUIT" ) || 
                     !strcmp ( pm->junk, "EXIT" )) {
                    asummary();                 
                    main_loop = FALSE;
                    break;
                }

                if ( !strcmp ( pm->junk,"HELP")) {
                    chelp("fun");
                    continue;
                    }

                if ( !strcmp (pm->junk, "?" ) ) {
                    printf( "Cheat %s", paa->aa3[i]);
                    num_cheats++;             /*     The user cheated     */
                    continue; 
                }
                if ( !strcmp (pm->junk  , tmp_AA )) {
                    loop = FALSE;
                } else {
                    num_wrong++;              /*     Wrong answer       */
                    printf("Wrong answer (try ?)\n");
                }
            }
            break;
        case 3:                             /* How big is this AA family*/
            i = rand_num(21);
            loop = TRUE;
            while ( loop ) {
                printf("\nHow many codons encode the Amino Acid %s ",
                        paa->aa1[i]);
                gets( pm->junk ) ;
                for ( x = 0 ; x < (int)strlen(pm->junk); x++) 
                    pm->junk[x] = (char) toupper( (int) pm->junk[x]);
  
                if ( !strcmp ( pm->junk, "QUIT" ) || 
                     !strcmp ( pm->junk, "EXIT" )) {
                    asummary();
                    main_loop = FALSE;
                    break;
                }
  
                if ( !strcmp ( pm->junk,"HELP")) {
                    chelp("fun");
                    continue;
                    }

                if ( !strcmp (pm->junk, "?" ) ) {
                    printf( "Cheat %i\n", *(da + i) );
                    num_cheats++;
                    continue;

               }
                
               

                if ( atoi(pm->junk) == *(da + i) )
                    loop = FALSE;
                
                else {
                    num_wrong++;
                    printf("Wrong answer (try ?)\n");
                }
            }
            break;
        case 4:                                 /* 60% of the time ask    */
        case 5:                                 /* ask questions about    */     
        case 6:                                 /* codon to aa translation*/ 
        case 7: 
        case 8:
        case 9: 
        case 10:
            i = rand_num(64);
            loop = TRUE;
            while ( loop ) {
                printf("\nName the Amino Acid encoded by the codon %s ", paa->cod[i]);
                gets( pm->junk );
                for ( x = 0 ; x < (int)strlen(pm->junk ); x++) 
                    pm->junk[x] = (char) toupper( (int) pm->junk[x]);
                if ( !strcmp ( pm->junk, "QUIT" ) || 
                     !strcmp ( pm->junk, "EXIT" )) {
                    asummary();
                    main_loop = FALSE;
                    break;
                }

                
                if ( !strcmp ( pm->junk,"HELP")) {
                    chelp("fun");
                    continue;
                    }

                if ( !strcmp (pm->junk, "?" ) ) {
                    printf( "Cheat %s (%s)", paa->aa1[pcu->ca[i]]
                        , paa->aa3[pcu->ca[i]]);
                    num_cheats++;             /* tell me the answer      */
                    continue;
                }
                /* allow 1 or 3 letter amino acid code as the ans        */
                strcpy ( tmp_AA, paa->aa1[pcu->ca[i]] );
                strcpy ( tmp_AA2, paa->aa3[pcu->ca[i]] );

                /* uppercase everything, the AA names and the answer     */
                for ( x = 0 ; x < (int)strlen(tmp_AA); x++) 
                    tmp_AA[x] = (char)toupper( (int) tmp_AA[x]);
                for ( x = 0 ; x < (int)strlen(tmp_AA2); x++) 
                    tmp_AA2[x] = (char)toupper((int) tmp_AA2[x]);
                for ( x = 0 ; x < (int)strlen(pm->junk  ); x++) 
                    pm->junk  [x] = (char)toupper((int) pm->junk[x]);

                if ( !strcmp(tmp_AA, pm->junk) || 
                     !strcmp(tmp_AA2,pm->junk)  ) {         
                    loop = FALSE;
                } else {
                    printf("Wrong answer (try ?)\n");
                    num_wrong++;
                }
            }
            break;
        default:
            printf("mistake == %i \n", i);
            exit(0);                             /* error catch            */ 
            break;
        }                                        /* end of switch          */
        num_questions++;

    }                                            /* end of while           */

    return;
}                                                /* end of main            */

/*********** Asummary ******************************************************/
/* Write out a summary of the users results                                */
/***************************************************************************/
void    asummary (void) {
    printf ( " You answered\n \t %5i questions\n", num_questions);
    printf ( " \t %5i answers were wrong\n", num_wrong);
    printf ( " \t %5i times you had to ask for a hint\n", num_cheats);
    printf ( " \t  %3.0f%c accuracy \n", (float) ( (num_questions) ?                 
        (float)100 * (num_questions - num_wrong) / 
        (float)num_questions : 0 ),'%');
    pause;
    return;
}