1 | #include "mltaln.h" |
---|
2 | |
---|
3 | #define DEBUG 0 |
---|
4 | |
---|
5 | char *alignmentfile; |
---|
6 | |
---|
7 | static void fillorichar( int nseq, int *oripos, char **a, char **s ) |
---|
8 | { |
---|
9 | int i; |
---|
10 | char *pta, *pts; |
---|
11 | for( i=0; i<nseq; i++ ) |
---|
12 | { |
---|
13 | pta = a[i]; |
---|
14 | pts = s[oripos[i]]; |
---|
15 | while( *pta ) |
---|
16 | { |
---|
17 | if( *pta != '-' ) *pta = *pts++; |
---|
18 | if( *pta++ == 0 ) |
---|
19 | { |
---|
20 | fprintf( stderr, "ERROR!!\n" ); |
---|
21 | fprintf( stderr, "alignment is inconsistent with the original sequences\n" ); |
---|
22 | exit( 1 ); |
---|
23 | } |
---|
24 | } |
---|
25 | if( *pts != 0 ) |
---|
26 | { |
---|
27 | fprintf( stderr, "ERROR!!\n" ); |
---|
28 | fprintf( stderr, "alignment is inconsistent with the original sequences\n" ); |
---|
29 | exit( 1 ); |
---|
30 | } |
---|
31 | } |
---|
32 | } |
---|
33 | |
---|
34 | void arguments( int argc, char *argv[] ) |
---|
35 | { |
---|
36 | int c; |
---|
37 | |
---|
38 | while( --argc > 0 && (*++argv)[0] == '-' ) |
---|
39 | { |
---|
40 | while ( (c = *++argv[0]) ) |
---|
41 | { |
---|
42 | switch( c ) |
---|
43 | { |
---|
44 | case 'i': |
---|
45 | inputfile = *++argv; |
---|
46 | --argc; |
---|
47 | goto nextoption; |
---|
48 | case 'a': |
---|
49 | alignmentfile = *++argv; |
---|
50 | --argc; |
---|
51 | goto nextoption; |
---|
52 | default: |
---|
53 | fprintf( stderr, "illegal option %c\n", c ); |
---|
54 | argc = 0; |
---|
55 | break; |
---|
56 | } |
---|
57 | } |
---|
58 | nextoption: |
---|
59 | ; |
---|
60 | } |
---|
61 | if( argc != 0 ) |
---|
62 | { |
---|
63 | fprintf( stderr, "options: Check source file !\n" ); |
---|
64 | exit( 1 ); |
---|
65 | } |
---|
66 | } |
---|
67 | |
---|
68 | |
---|
69 | |
---|
70 | int main( int argc, char *argv[] ) |
---|
71 | { |
---|
72 | FILE *infp; |
---|
73 | FILE *alfp; |
---|
74 | char **name; |
---|
75 | char **aname; |
---|
76 | char **oname; |
---|
77 | char **seq; |
---|
78 | char **aseq; |
---|
79 | int *nlen; |
---|
80 | int *oripos; |
---|
81 | char *npt, *npt0, *npt2, *pt, *pt2; |
---|
82 | int i, o, prelen; |
---|
83 | int nlenmin; |
---|
84 | int njobs, njoba; |
---|
85 | |
---|
86 | arguments( argc, argv ); |
---|
87 | |
---|
88 | if( inputfile ) |
---|
89 | { |
---|
90 | infp = fopen( inputfile, "r" ); |
---|
91 | if( !infp ) |
---|
92 | { |
---|
93 | fprintf( stderr, "Cannot open %s\n", inputfile ); |
---|
94 | exit( 1 ); |
---|
95 | } |
---|
96 | } |
---|
97 | else |
---|
98 | infp = stdin; |
---|
99 | |
---|
100 | if( alignmentfile ) |
---|
101 | { |
---|
102 | alfp = fopen( alignmentfile, "r" ); |
---|
103 | if( !alfp ) |
---|
104 | { |
---|
105 | fprintf( stderr, "Cannot open %s\n", alignmentfile ); |
---|
106 | exit( 1 ); |
---|
107 | } |
---|
108 | } |
---|
109 | else |
---|
110 | { |
---|
111 | fprintf( stderr, "No alignment is given.\n" ); |
---|
112 | exit( 1 ); |
---|
113 | } |
---|
114 | |
---|
115 | dorp = NOTSPECIFIED; |
---|
116 | getnumlen_casepreserve( infp, &nlenmin ); |
---|
117 | njobs = njob; |
---|
118 | // fprintf( stderr, "in infp, %d x %d - %d %c\n", njob, nlenmin, nlenmax, dorp ); |
---|
119 | |
---|
120 | seq = AllocateCharMtx( njob, nlenmax+1 ); |
---|
121 | name = AllocateCharMtx( njob, B+1 ); |
---|
122 | nlen = AllocateIntVec( njob ); |
---|
123 | oripos = AllocateIntVec( njob ); |
---|
124 | readData_pointer_casepreserve( infp, name, nlen, seq ); |
---|
125 | |
---|
126 | dorp = NOTSPECIFIED; |
---|
127 | getnumlen( alfp ); |
---|
128 | njoba = njob; |
---|
129 | // fprintf( stderr, "in alfp, %d x %d %c\n", njob, nlenmax, dorp ); |
---|
130 | aseq = AllocateCharMtx( njob, nlenmax+1 ); |
---|
131 | aname = AllocateCharMtx( njob, B+1 ); |
---|
132 | oname = AllocateCharMtx( njob, B+1 ); |
---|
133 | readData_pointer( alfp, aname, nlen, aseq ); |
---|
134 | |
---|
135 | for( i=0; i<njob; i++ ) gappick_samestring( seq[i] ); |
---|
136 | |
---|
137 | if( njoba != njobs ) |
---|
138 | { |
---|
139 | fprintf( stderr, "ERROR!!\n" ); |
---|
140 | fprintf( stderr, "In input file,\n" ); |
---|
141 | fprintf( stderr, "njob = %d\n", njobs ); |
---|
142 | fprintf( stderr, "but in alignment file,\n" ); |
---|
143 | fprintf( stderr, "njob = %d\n", njoba ); |
---|
144 | exit( 1 ); |
---|
145 | } |
---|
146 | |
---|
147 | for( i=0; i<njob; i++ ) |
---|
148 | { |
---|
149 | #if 0 |
---|
150 | if( strstr( aname[i], "_seed_" ) ) |
---|
151 | { |
---|
152 | npt2 = aname[i] + 7; |
---|
153 | strcpy( oname[i], "=_seed_" ); |
---|
154 | } |
---|
155 | else |
---|
156 | { |
---|
157 | npt2 = aname[i] + 1; |
---|
158 | strcpy( oname[i], "=" ); |
---|
159 | } |
---|
160 | |
---|
161 | fprintf( stderr, "npt2 = %s\n", npt2 ); |
---|
162 | |
---|
163 | o = oripos[i] = atoi( npt2 ); |
---|
164 | npt = strstr( npt2, "_oe_" ); |
---|
165 | if( npt == NULL ) |
---|
166 | { |
---|
167 | fprintf( stderr, "Format error!\n" ); |
---|
168 | exit( 1 ); |
---|
169 | } |
---|
170 | npt += 4; |
---|
171 | strcat( oname[i], npt+1 ); |
---|
172 | #endif |
---|
173 | npt0 = strstr( aname[i], "_os_" ); |
---|
174 | if( npt0 == NULL ) |
---|
175 | { |
---|
176 | fprintf( stderr, "Format error!\n" ); |
---|
177 | exit( 1 ); |
---|
178 | } |
---|
179 | npt2 = npt0 + 4; |
---|
180 | o = oripos[i] = atoi( npt2 ); |
---|
181 | |
---|
182 | npt = strstr( aname[i], "_oe_" ); |
---|
183 | if( npt == NULL ) |
---|
184 | { |
---|
185 | fprintf( stderr, "Format error!\n" ); |
---|
186 | exit( 1 ); |
---|
187 | } |
---|
188 | npt += 4; |
---|
189 | |
---|
190 | pt2 = npt; |
---|
191 | pt = npt2 - 4; |
---|
192 | while( *pt ) *pt++ = *pt2++; // okashii |
---|
193 | |
---|
194 | prelen = npt0-aname[i]; |
---|
195 | strncpy( oname[i], aname[i], prelen ); oname[i][prelen] = 0; |
---|
196 | strcat( oname[i], npt0 ); |
---|
197 | |
---|
198 | pt = strstr( aname[i], "_numo_e" ); |
---|
199 | if( pt ) pt += 8; |
---|
200 | else pt = aname[i] + 1; |
---|
201 | |
---|
202 | // fprintf( stderr, "aname[i] = :%s:\n", aname[i] ); |
---|
203 | // fprintf( stderr, "pt = :%s:\n", pt ); |
---|
204 | // fprintf( stderr, "oname[i] = :%s:\n", oname[i] ); |
---|
205 | // fprintf( stderr, "name[o] = :%s:\n", name[o] ); |
---|
206 | |
---|
207 | if( strncmp( pt, name[o]+1, 10 ) ) |
---|
208 | { |
---|
209 | fprintf( stderr, "ERROR!!\n" ); |
---|
210 | fprintf( stderr, "In input file,\n" ); |
---|
211 | fprintf( stderr, "name[%d] = %s\n", o, name[o] ); |
---|
212 | fprintf( stderr, "but in alignment file,\n" ); |
---|
213 | fprintf( stderr, "pt = %s\n", pt ); |
---|
214 | fprintf( stderr, "name[%d] = %s\n", i, aname[i] ); |
---|
215 | exit( 1 ); |
---|
216 | } |
---|
217 | #if 0 |
---|
218 | else |
---|
219 | { |
---|
220 | fprintf( stderr, "OK!!\n" ); |
---|
221 | fprintf( stderr, "In input file,\n" ); |
---|
222 | fprintf( stderr, "name[%d] = %s\n", o, name[o] ); |
---|
223 | fprintf( stderr, "and in alignment file,\n" ); |
---|
224 | fprintf( stderr, "name[%d] = %s\n", i, aname[i] ); |
---|
225 | fprintf( stderr, "\n" ); |
---|
226 | } |
---|
227 | #endif |
---|
228 | } |
---|
229 | // fprintf( stderr, "seq[0] = %s\n", seq[0] ); |
---|
230 | // fprintf( stderr, "aseq[0] = %s\n", aseq[0] ); |
---|
231 | |
---|
232 | fillorichar( njob, oripos, aseq, seq ); |
---|
233 | |
---|
234 | |
---|
235 | writeData_pointer( stdout, njob, oname, nlen, aseq ); |
---|
236 | |
---|
237 | FreeCharMtx( seq ); |
---|
238 | FreeCharMtx( aseq ); |
---|
239 | FreeCharMtx( name ); |
---|
240 | FreeCharMtx( aname ); |
---|
241 | FreeCharMtx( oname ); |
---|
242 | free( nlen ); |
---|
243 | free( oripos ); |
---|
244 | |
---|
245 | return( 0 ); |
---|
246 | } |
---|