Next version of JABA
[jabaws.git] / binaries / src / mafft / core / dndpre.c
1 #include "mltaln.h"
2
3 #define TEST 0
4
5 static int treeout = 0;
6
7
8 void arguments( int argc, char *argv[] )
9 {
10     int c;
11
12         alg = 'X';
13         fmodel = 0;
14         treeout = 0;
15         scoremtx = 1;
16         nblosum = 62;
17         dorp = NOTSPECIFIED;
18         inputfile = NULL;
19         ppenalty = NOTSPECIFIED; //?
20         ppenalty_ex = NOTSPECIFIED; //?
21         poffset = NOTSPECIFIED; //?
22         kimuraR = NOTSPECIFIED;
23         pamN = NOTSPECIFIED;
24
25     while( --argc > 0 && (*++argv)[0] == '-' )
26         {
27         while ( (c = *++argv[0]) )
28                 {
29             switch( c )
30             {
31                                 case 't':
32                                         treeout = '1';
33                                         break;
34                                 case 'D':
35                                         dorp = 'd';
36                                         break;
37                                 case 'a':
38                                         fmodel = 1;
39                                         break;
40                                 case 'P':
41                                         dorp = 'p';
42                                         break;
43                                 case 'i':
44                                         inputfile = *++argv;
45                                         fprintf( stderr, "inputfile = %s\n", inputfile );
46                                         --argc;
47                                         goto nextoption;
48             }
49                 }
50                 nextoption:
51                         ;
52         }
53     if( argc != 0 ) 
54         {
55                 fprintf( stderr, "options: Check source file !\n" );
56                 exit( 1 );
57         }
58 }
59
60 int main( int argc, char **argv )
61 {
62         int i, j;
63         char **seq;
64         static char name[M][B];
65         static int nlen[M];
66         float *selfscore;
67         double **mtx;
68         FILE *fp;
69         FILE *infp;
70         float ssi, ssj, bunbo;
71
72
73         arguments( argc, argv );
74
75         if( inputfile )
76         {
77                 infp = fopen( inputfile, "r" );
78                 if( !infp )
79                 {
80                         fprintf( stderr, "Cannot open %s\n", inputfile );
81                         exit( 1 );
82                 }
83         }
84         else
85                 infp = stdin;
86
87 #if 0
88         PreRead( stdin, &njob, &nlenmax );
89 #else
90         getnumlen( infp );
91 #endif
92         rewind( infp );
93
94         seq = AllocateCharMtx( njob, nlenmax+1 );
95         mtx = AllocateDoubleMtx( njob, njob );
96         selfscore = AllocateFloatVec( njob );
97
98 #if 0
99         FRead( stdin, name, nlen, seq );
100 #else
101         readData( infp, name, nlen, seq );
102 #endif
103         fclose( infp );
104
105         constants( njob, seq );
106
107 #if 0
108         for( i=0; i<njob-1; i++ ) 
109         {
110                 fprintf( stderr, "%4d/%4d\r", i+1, njob );
111                 for( j=i+1; j<njob; j++ ) 
112                         mtx[i][j] = (double)substitution_hosei( seq[i], seq[j] );
113 //                      fprintf( stderr, "i=%d,j=%d, l=%d &&&  %f\n", i, j, nlen[0], mtx[i][j] );
114         }
115 #else // 061003
116         for( i=0; i<njob; i++ )
117         {
118                 selfscore[i] = (float)naivepairscore11( seq[i], seq[i], penalty );
119
120         }
121         for( i=0; i<njob-1; i++ )
122         {
123                 ssi = selfscore[i];
124                 fprintf( stderr, "%4d/%4d\r", i+1, njob );
125                 for( j=i+1; j<njob; j++ )
126                 {
127                         ssj = selfscore[j];
128                         bunbo = MIN( ssi, ssj );
129                         if( bunbo == 0.0 )
130                                 mtx[i][j] = 1.0;
131                         else
132                                 mtx[i][j] = 1.0 - (double)naivepairscore11( seq[i], seq[j], penalty ) / bunbo;
133 //                              mtx[i][j] = 1.0 - (double)naivepairscore11( seq[i], seq[j], penalty ) / MIN( selfscore[i], selfscore[j] );
134 //                      fprintf( stderr, "i=%d,j=%d, l=%d### %f, score = %d\n", i, j, nlen[0], mtx[i][j], naivepairscore11( seq[i], seq[j], penalty )  );
135                 }
136         }
137 #endif
138         
139 #if TEST
140         for( i=0; i<njob-1; i++ ) for( j=i+1; j<njob; j++ ) 
141                 fprintf( stdout, "i=%d, j=%d, mtx[][] = %f\n", i, j, mtx[i][j] );
142 #endif
143
144         fp = fopen( "hat2", "w" );
145         WriteHat2( fp, njob, name, mtx );
146         fclose( fp );
147 #if 0
148         if( treeout )
149         {
150                 int ***topol;
151                 double **len;
152
153                 topol = AllocateIntCub( njob, 2, njob );
154                 len = AllocateDoubleMtx( njob, njob );
155                 veryfastsupg_double_outtree( njob, mtx, topol, len );
156         }
157 #endif
158         SHOWVERSION;
159         exit( 0 );
160 /*
161         res = system( ALNDIR "/spgsdl < hat2"  );
162         if( res ) exit( 1 );
163         else exit( 0 );
164 */
165 }