Mercurial > repos > nick > duplex
comparison mafft/core/f2cl.c @ 18:e4d75f9efb90 draft
planemo upload commit b'4303231da9e48b2719b4429a29b72421d24310f4\n'-dirty
author | nick |
---|---|
date | Thu, 02 Feb 2017 18:44:31 -0500 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
17:836fa4fe9494 | 18:e4d75f9efb90 |
---|---|
1 #include "mltaln.h" | |
2 | |
3 #define DEBUG 0 | |
4 | |
5 | |
6 static char *comment; | |
7 static char *orderfile; | |
8 static int format; | |
9 static int namelen; | |
10 static int extendedalphabet; | |
11 | |
12 static void fillspace( char *seq, int lenmax ) | |
13 { | |
14 int len = strlen( seq ); | |
15 seq += len; | |
16 lenmax -= len; | |
17 while( lenmax-- ) *seq++ = ' '; | |
18 *seq = 0; | |
19 } | |
20 | |
21 void setmark_clustal( int nlen, int nseq, char **seq, char *mark ) | |
22 { | |
23 int i, j, k, nalpha; | |
24 char firstletter; | |
25 char *strong[9]; | |
26 char *weaker[11]; | |
27 int nstrong, nweaker; | |
28 char s; | |
29 | |
30 if( dorp == 'd' ) | |
31 { | |
32 strong[0] = "TU"; | |
33 nstrong = 1; | |
34 weaker[0] = "AG"; | |
35 weaker[1] = "CT"; | |
36 nweaker = 2; | |
37 nalpha = 10; | |
38 } | |
39 else | |
40 { | |
41 strong[0] = "STA"; | |
42 strong[1] = "NEQK"; | |
43 strong[2] = "NHQK"; | |
44 strong[3] = "NDEQ"; | |
45 strong[4] = "QHRK"; | |
46 strong[5] = "MILV"; | |
47 strong[6] = "MILF"; | |
48 strong[7] = "HY"; | |
49 strong[8] = "FYW"; | |
50 nstrong = 9; | |
51 weaker[0] = "CSA"; | |
52 weaker[1] = "ATV"; | |
53 weaker[2] = "SAG"; | |
54 weaker[3] = "STNK"; | |
55 weaker[4] = "STPA"; | |
56 weaker[5] = "SGND"; | |
57 weaker[6] = "SNDEQK"; | |
58 weaker[7] = "NDEQHK"; | |
59 weaker[8] = "NEQHRK"; | |
60 weaker[9] = "FVLIM"; | |
61 weaker[10] = "HFY"; | |
62 nweaker = 11; | |
63 nalpha = 20; | |
64 } | |
65 | |
66 for( i=0; i<nlen; i++ ) | |
67 { | |
68 mark[i] = ' '; | |
69 for( j=0; j<nseq; j++ ) | |
70 { | |
71 s = seq[j][i]; | |
72 if( '-' == s || ' ' == s ) break; | |
73 } | |
74 if( j != nseq ) | |
75 { | |
76 continue; | |
77 } | |
78 if( extendedalphabet ) | |
79 { | |
80 firstletter = seq[0][i]; | |
81 if( amino_n[(int)firstletter] < 0 ) continue; | |
82 | |
83 for( j=0; j<nseq; j++ ) | |
84 if( seq[j][i] != firstletter ) break; | |
85 if( j == nseq ) | |
86 { | |
87 mark[i] = '*'; | |
88 continue; | |
89 } | |
90 } | |
91 else | |
92 { | |
93 firstletter = toupper( seq[0][i] ); | |
94 if( amino_n[(int)firstletter] >= nalpha || amino_n[(int)firstletter] < 0 ) continue; | |
95 | |
96 for( j=0; j<nseq; j++ ) | |
97 if( toupper( seq[j][i] ) != firstletter ) break; | |
98 if( j == nseq ) | |
99 { | |
100 mark[i] = '*'; | |
101 continue; | |
102 } | |
103 for( k=0; k<nstrong; k++ ) | |
104 { | |
105 for( j=0; j<nseq; j++ ) | |
106 { | |
107 if( !strchr( strong[k], toupper( seq[j][i] ) ) ) break; | |
108 } | |
109 if( j == nseq ) break; | |
110 } | |
111 if( k < nstrong ) | |
112 { | |
113 mark[i] = ':'; | |
114 continue; | |
115 } | |
116 for( k=0; k<nweaker; k++ ) | |
117 { | |
118 for( j=0; j<nseq; j++ ) | |
119 { | |
120 if( !strchr( weaker[k], toupper( seq[j][i] ) ) ) break; | |
121 } | |
122 if( j == nseq ) break; | |
123 } | |
124 if( k < nweaker ) | |
125 { | |
126 mark[i] = '.'; | |
127 continue; | |
128 } | |
129 } | |
130 } | |
131 mark[nlen] = 0; | |
132 } | |
133 | |
134 void setmark( int nlen, int nseq, char **seq, char *mark ) | |
135 { | |
136 int i, j; | |
137 | |
138 for( i=0; i<nlen; i++ ) | |
139 { | |
140 mark[i] = ' '; | |
141 for( j=0; j<nseq; j++ ) | |
142 if( '-' == seq[j][i] ) break; | |
143 if( j != nseq ) | |
144 { | |
145 continue; | |
146 } | |
147 for( j=0; j<nseq; j++ ) | |
148 if( seq[0][i] != seq[j][i] ) break; | |
149 if( j == nseq ) | |
150 { | |
151 mark[i] = '*'; | |
152 continue; | |
153 } | |
154 for( j=0; j<nseq; j++ ) | |
155 if( amino_grp[(int)seq[0][i]] != amino_grp[(int)seq[j][i]] ) break; | |
156 if( j == nseq ) | |
157 { | |
158 mark[i] = '.'; | |
159 continue; | |
160 } | |
161 } | |
162 mark[nlen] = 0; | |
163 } | |
164 | |
165 void arguments( int argc, char *argv[] ) | |
166 { | |
167 int c; | |
168 namelen = -1; | |
169 scoremtx = 1; | |
170 nblosum = 62; | |
171 dorp = NOTSPECIFIED; | |
172 kimuraR = NOTSPECIFIED; | |
173 pamN = NOTSPECIFIED; | |
174 inputfile = NULL; | |
175 comment = NULL; | |
176 orderfile = NULL; | |
177 format = 'c'; | |
178 extendedalphabet = 0; | |
179 | |
180 while( --argc > 0 && (*++argv)[0] == '-' ) | |
181 { | |
182 while ( (c = *++argv[0]) ) | |
183 { | |
184 switch( c ) | |
185 { | |
186 case 'i': | |
187 inputfile = *++argv; | |
188 fprintf( stderr, "inputfile = %s\n", inputfile ); | |
189 --argc; | |
190 goto nextoption; | |
191 case 'c': | |
192 comment = *++argv; | |
193 fprintf( stderr, "comment = %s\n", comment ); | |
194 --argc; | |
195 goto nextoption; | |
196 case 'r': | |
197 orderfile = *++argv; | |
198 fprintf( stderr, "orderfile = %s\n", orderfile ); | |
199 --argc; | |
200 goto nextoption; | |
201 case 'n': | |
202 namelen = myatoi( *++argv ); | |
203 fprintf( stderr, "namelen = %d\n", namelen ); | |
204 --argc; | |
205 goto nextoption; | |
206 case 'f': | |
207 format = 'f'; | |
208 break; | |
209 case 'y': | |
210 format = 'y'; | |
211 break; | |
212 case 'E': | |
213 extendedalphabet = 1; | |
214 nblosum = -2; | |
215 break; | |
216 case 'N': | |
217 extendedalphabet = 0; | |
218 break; | |
219 default: | |
220 fprintf( stderr, "illegal option %c\n", c ); | |
221 argc = 0; | |
222 break; | |
223 } | |
224 } | |
225 nextoption: | |
226 ; | |
227 } | |
228 if( argc != 0 ) | |
229 { | |
230 fprintf( stderr, "options: Check source file !\n" ); | |
231 exit( 1 ); | |
232 } | |
233 } | |
234 | |
235 | |
236 int main( int argc, char *argv[] ) | |
237 { | |
238 static int *nlen; | |
239 static char **name, **seq, *mark; | |
240 static int *order; | |
241 int i; | |
242 FILE *infp; | |
243 FILE *orderfp; | |
244 char gett[B]; | |
245 int nlenmin; | |
246 | |
247 arguments( argc, argv ); | |
248 | |
249 | |
250 if( inputfile ) | |
251 { | |
252 infp = fopen( inputfile, "r" ); | |
253 if( !infp ) | |
254 { | |
255 fprintf( stderr, "Cannot open %s\n", inputfile ); | |
256 exit( 1 ); | |
257 } | |
258 } | |
259 else | |
260 infp = stdin; | |
261 | |
262 getnumlen_casepreserve( infp, &nlenmin ); | |
263 rewind( infp ); | |
264 | |
265 seq = AllocateCharMtx( njob, nlenmax*2+1 ); | |
266 mark = AllocateCharVec( nlenmax*2+1 ); | |
267 order = AllocateIntVec( njob ); | |
268 name = AllocateCharMtx( njob, B+1 ); | |
269 nlen = AllocateIntVec( njob ); | |
270 | |
271 | |
272 if( orderfile ) | |
273 { | |
274 orderfp = fopen( orderfile, "r" ); | |
275 if( !orderfp ) | |
276 { | |
277 fprintf( stderr, "Cannot open %s\n", orderfile ); | |
278 exit( 1 ); | |
279 } | |
280 for( i=0; i<njob; i++ ) | |
281 { | |
282 fgets( gett, B-1, orderfp ); | |
283 order[i] = atoi( gett ); | |
284 } | |
285 fclose( orderfp ); | |
286 } | |
287 else | |
288 { | |
289 for( i=0; i<njob; i++ ) order[i] = i; | |
290 } | |
291 | |
292 readData_pointer_casepreserve( infp, name, nlen, seq ); | |
293 fclose( infp ); | |
294 | |
295 if( format == 'c' || format == 'y' ) for( i=0; i<njob; i++ ) fillspace( seq[i], nlenmax ); | |
296 constants( njob, seq ); | |
297 | |
298 // initSignalSM(); | |
299 | |
300 // initFiles(); | |
301 | |
302 | |
303 | |
304 // setmark( nlenmax, njob, seq, mark ); | |
305 setmark_clustal( nlenmax, njob, seq, mark ); | |
306 | |
307 if( format == 'f' ) | |
308 writeData_reorder_pointer( stdout, njob, name, nlen, seq, order ); | |
309 else if( format == 'c' ) | |
310 clustalout_pointer( stdout, njob, nlenmax, seq, name, mark, comment, order, namelen ); | |
311 else if( format == 'y' ) | |
312 phylipout_pointer( stdout, njob, nlenmax, seq, name, order, namelen ); | |
313 else | |
314 fprintf( stderr, "Unknown format\n" ); | |
315 | |
316 // SHOWVERSION; | |
317 return( 0 ); | |
318 } |