1906cdb9ad89c6854ac1b468325ef89f4485c29a
[jabaws.git] / binaries / src / mafft / core / score.c
1 #include "mltaln.h"
2
3 #define DEBUG 0
4
5 void arguments( int argc, char *argv[] )
6 {
7     int c;
8
9         ppenalty = NOTSPECIFIED;
10         ppenalty_ex = NOTSPECIFIED;
11         poffset = NOTSPECIFIED;
12         kimuraR = NOTSPECIFIED;
13         pamN = NOTSPECIFIED;
14         scoremtx = NOTSPECIFIED;
15
16     while( --argc > 0 && (*++argv)[0] == '-' )
17         {
18         while ( ( c = *++argv[0] ) )
19                 {
20             switch( c )
21             {
22                                 case 'f':
23                                         ppenalty = (int)( atof( *++argv ) * 1000 - 0.5 );
24                                         fprintf( stderr, "ppenalty = %d\n", ppenalty );
25                                         --argc;
26                                         goto nextoption;
27                                 case 'g':
28                                         ppenalty_ex = (int)( atof( *++argv ) * 1000 - 0.5 );
29                                         fprintf( stderr, "ppenalty_ex = %d\n", ppenalty_ex );
30                                         --argc;
31                                         goto nextoption;
32                                 case 'h':
33                                         poffset = (int)( atof( *++argv ) * 1000 - 0.5 );
34                                         fprintf( stderr, "poffset = %d\n", poffset );
35                                         --argc;
36                                         goto nextoption;
37                                 case 'k':
38                                         kimuraR = atoi( *++argv );
39                                         fprintf( stderr, "kimuraR = %d\n", kimuraR );
40                                         --argc;
41                                         goto nextoption;
42                                 case 'D':
43                                         scoremtx = -1;
44                                         break;
45                                 case 'P':
46                                         scoremtx = 0;
47                                         break;
48                 default:
49                     fprintf( stderr, "illegal option %c\n", c );
50                     argc = 0;
51                     break;
52             }
53                 }
54                 nextoption:
55                         ;
56         }
57     if( argc == 1 )
58     {
59         cut = atof( (*argv) );
60         argc--;
61     }
62 }
63
64
65 int main( int ac, char **av )
66 {
67         int nlen[M];
68         static char name[M][B], **seq;
69         double score;
70         extern double score_calc_for_score( int, char ** );
71
72         arguments( ac, av );
73
74         getnumlen( stdin );
75         rewind( stdin );
76
77         seq = AllocateCharMtx( njob, nlenmax );
78
79         readData( stdin, name, nlen, seq );
80
81         if( !isaligned( njob, seq ) ) ErrorExit( "Not aligned." );
82
83         constants( njob, seq );
84
85         score = score_calc_for_score( njob, seq );
86         if( scoremtx == 0 ) score += offset;
87
88         fprintf( stdout, "score = %f\n", score );
89         if     ( scoremtx ==  0 ) fprintf( stdout, "JTT %dPAM\n", pamN );
90         else if( scoremtx ==  1 ) fprintf( stdout, "Dayhoff( machigai ga aru )\n" );
91         else if( scoremtx ==  2 ) fprintf( stdout, "M-Y\n" );
92         else if( scoremtx == -1 ) fprintf( stdout, "DNA 1:%d\n", kimuraR );
93
94         fprintf( stdout, "gap penalty = %+6.2f, %+6.2f, %+6.2f\n", (double)ppenalty/1000, (double)ppenalty_ex/1000, (double)poffset/1000 );
95         exit( 0 );
96 }