1 | /* |
---|
2 | |
---|
3 | PhyML: a program that computes maximum likelihood phylogenies from |
---|
4 | DNA or AA homologous sequences. |
---|
5 | |
---|
6 | Copyright (C) Stephane Guindon. Oct 2003 onward. |
---|
7 | |
---|
8 | All parts of the source except where indicated are distributed under |
---|
9 | the GNU public licence. See http://www.opensource.org for details. |
---|
10 | |
---|
11 | */ |
---|
12 | |
---|
13 | #include "nexus.h" |
---|
14 | |
---|
15 | void Find_Nexus_Com(char *token, nexcom **found_com, nexparm **default_parm, nexcom **com_list) |
---|
16 | { |
---|
17 | int i,j,tokenlen,ndiff; |
---|
18 | |
---|
19 | For(i,N_MAX_NEX_COM) |
---|
20 | { |
---|
21 | tokenlen = strlen(token); |
---|
22 | ndiff = -1; |
---|
23 | if(tokenlen && (tokenlen == strlen(com_list[i]->name))) |
---|
24 | { |
---|
25 | ndiff = 0; |
---|
26 | For(j,tokenlen) |
---|
27 | { |
---|
28 | Lowercase(token+j); |
---|
29 | Lowercase(com_list[i]->name+j); |
---|
30 | if(token[j] != com_list[i]->name[j]) ndiff++; |
---|
31 | } |
---|
32 | } |
---|
33 | if(!ndiff) { *found_com = com_list[i]; break; } |
---|
34 | } |
---|
35 | |
---|
36 | if(*found_com && (*found_com)->nparm) *default_parm = (*found_com)->parm[0]; |
---|
37 | |
---|
38 | if(*found_com) PhyML_Printf("\n. Found command '%s'.\n",(*found_com)->name); |
---|
39 | } |
---|
40 | |
---|
41 | ////////////////////////////////////////////////////////////// |
---|
42 | ////////////////////////////////////////////////////////////// |
---|
43 | |
---|
44 | |
---|
45 | void Find_Nexus_Parm(char *token, nexparm **found_parm, nexcom *curr_com) |
---|
46 | { |
---|
47 | int i,j; |
---|
48 | int tokenlen; |
---|
49 | int ndiff; |
---|
50 | |
---|
51 | if(!curr_com) |
---|
52 | { |
---|
53 | PhyML_Printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); |
---|
54 | Exit(""); |
---|
55 | } |
---|
56 | |
---|
57 | For(i,curr_com->nparm) |
---|
58 | { |
---|
59 | tokenlen = strlen(token); |
---|
60 | ndiff = -1; |
---|
61 | if(tokenlen == strlen(curr_com->parm[i]->name)) |
---|
62 | { |
---|
63 | ndiff = 0; |
---|
64 | For(j,tokenlen) |
---|
65 | { |
---|
66 | Lowercase(token+j); |
---|
67 | Lowercase(curr_com->parm[i]->name+j); |
---|
68 | if(token[j] != curr_com->parm[i]->name[j]) ndiff++; |
---|
69 | } |
---|
70 | } |
---|
71 | if(!ndiff) { *found_parm = curr_com->parm[i]; break; } |
---|
72 | } |
---|
73 | |
---|
74 | if(*found_parm) PhyML_Printf("\n. Found parameter '%s'.\n",(*found_parm)->name); |
---|
75 | } |
---|
76 | |
---|
77 | ////////////////////////////////////////////////////////////// |
---|
78 | ////////////////////////////////////////////////////////////// |
---|
79 | |
---|
80 | |
---|
81 | int Read_Nexus_Taxa(char *token, nexparm *curr_parm, option *io) |
---|
82 | { |
---|
83 | |
---|
84 | PhyML_Printf("\n. Skipping 'taxa' block"); |
---|
85 | |
---|
86 | do |
---|
87 | { |
---|
88 | Get_Token(io->fp_in_tree,token); |
---|
89 | if(token[0] == ';') break; |
---|
90 | }while(strlen(token) > 0); |
---|
91 | |
---|
92 | fseek(io->fp_in_tree,-1*sizeof(char),SEEK_CUR); |
---|
93 | |
---|
94 | return 1; |
---|
95 | } |
---|
96 | |
---|
97 | ////////////////////////////////////////////////////////////// |
---|
98 | ////////////////////////////////////////////////////////////// |
---|
99 | |
---|
100 | |
---|
101 | int Read_Nexus_Translate(char *token, nexparm *curr_parm, option *io) |
---|
102 | { |
---|
103 | int tax_num; |
---|
104 | char *end; |
---|
105 | |
---|
106 | PhyML_Printf("\n. Reading 'translate' block"); |
---|
107 | io->size_tax_names = 0; |
---|
108 | |
---|
109 | do |
---|
110 | { |
---|
111 | Get_Token(io->fp_in_tree,token); |
---|
112 | if(token[0] == ';') break; |
---|
113 | tax_num = (int)strtol(token,&end,10); |
---|
114 | if(*end =='\0' && token[0]) |
---|
115 | { |
---|
116 | io->size_tax_names++; |
---|
117 | |
---|
118 | io->short_tax_names = (char **)realloc(io->short_tax_names,io->size_tax_names*sizeof(char *)); |
---|
119 | io->short_tax_names[io->size_tax_names-1] = (char *)mCalloc(strlen(token)+1,sizeof(char)); |
---|
120 | sprintf(io->short_tax_names[io->size_tax_names-1],"%d",tax_num); |
---|
121 | |
---|
122 | Get_Token(io->fp_in_tree,token); |
---|
123 | |
---|
124 | io->long_tax_names = (char **)realloc(io->long_tax_names,io->size_tax_names*sizeof(char *)); |
---|
125 | io->long_tax_names[io->size_tax_names-1] = (char *)mCalloc(strlen(token)+1,sizeof(char)); |
---|
126 | strcpy(io->long_tax_names[io->size_tax_names-1],token); |
---|
127 | |
---|
128 | /* printf("\n. Copying %s number %d",io->long_tax_names[io->size_long_tax_names-1],tax_num-1); */ |
---|
129 | } |
---|
130 | }while(strlen(token) > 0); |
---|
131 | |
---|
132 | fseek(io->fp_in_tree,-1*sizeof(char),SEEK_CUR); |
---|
133 | |
---|
134 | return 1; |
---|
135 | } |
---|
136 | |
---|
137 | ////////////////////////////////////////////////////////////// |
---|
138 | ////////////////////////////////////////////////////////////// |
---|
139 | |
---|
140 | |
---|
141 | int Read_Nexus_Matrix(char *token, nexparm *curr_parm, option *io) |
---|
142 | { |
---|
143 | |
---|
144 | if(io->interleaved) io->data = Read_Seq_Interleaved(io); |
---|
145 | else io->data = Read_Seq_Sequential(io); |
---|
146 | |
---|
147 | fseek(io->fp_in_align,-1*sizeof(char),SEEK_CUR); |
---|
148 | |
---|
149 | return 1; |
---|
150 | } |
---|
151 | |
---|
152 | ////////////////////////////////////////////////////////////// |
---|
153 | ////////////////////////////////////////////////////////////// |
---|
154 | |
---|
155 | |
---|
156 | int Read_Nexus_Tree(char *token, nexparm *curr_parm, option *io) |
---|
157 | { |
---|
158 | io->treelist->tree = (t_tree **)realloc(io->treelist->tree,(io->treelist->list_size+1)*sizeof(t_tree *)); |
---|
159 | io->tree = Read_Tree_File_Phylip(io->fp_in_tree); |
---|
160 | if(!(io->treelist->list_size%10) && io->treelist->list_size > 1) |
---|
161 | { |
---|
162 | PhyML_Printf("\n. Reading tree %d",io->treelist->list_size); |
---|
163 | if(io->tree->n_root) PhyML_Printf(" (that is a rooted tree)"); |
---|
164 | else PhyML_Printf(" (that is an unrooted tree)"); |
---|
165 | } |
---|
166 | io->treelist->tree[io->treelist->list_size] = io->tree; |
---|
167 | io->treelist->list_size++; |
---|
168 | fseek(io->fp_in_tree,-1*sizeof(char),SEEK_CUR); |
---|
169 | return 1; |
---|
170 | } |
---|
171 | |
---|
172 | ////////////////////////////////////////////////////////////// |
---|
173 | ////////////////////////////////////////////////////////////// |
---|
174 | |
---|
175 | |
---|
176 | int Read_Nexus_Begin(char *token, nexparm *curr_parm, option *io) |
---|
177 | { |
---|
178 | if(token[0] == '=') return 0; |
---|
179 | |
---|
180 | if(!curr_parm) |
---|
181 | { |
---|
182 | PhyML_Printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); |
---|
183 | Exit(""); |
---|
184 | } |
---|
185 | |
---|
186 | if(!strcmp(curr_parm->name,"data") || !strcmp(curr_parm->name,"trees")) |
---|
187 | PhyML_Printf("\n. Reading '%s' block.\n",curr_parm->value); |
---|
188 | else |
---|
189 | { |
---|
190 | PhyML_Printf("\n. The '%s' block type is not supported by PhyML. Sorry.\n",curr_parm->name); |
---|
191 | PhyML_Printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); |
---|
192 | Exit(""); |
---|
193 | } |
---|
194 | |
---|
195 | return 1; |
---|
196 | } |
---|
197 | |
---|
198 | ////////////////////////////////////////////////////////////// |
---|
199 | ////////////////////////////////////////////////////////////// |
---|
200 | |
---|
201 | |
---|
202 | int Read_Nexus_Dimensions(char *token, nexparm *curr_parm, option *io) |
---|
203 | { |
---|
204 | if(token[0] == '=') return 0; |
---|
205 | |
---|
206 | if(!curr_parm) |
---|
207 | { |
---|
208 | PhyML_Printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); |
---|
209 | Exit(""); |
---|
210 | } |
---|
211 | |
---|
212 | strcpy(curr_parm->value,token); |
---|
213 | |
---|
214 | if(!strcmp(curr_parm->name,"ntax")) |
---|
215 | { |
---|
216 | sscanf(curr_parm->value,"%d",&(io->n_otu)); |
---|
217 | } |
---|
218 | |
---|
219 | if(!strcmp(curr_parm->name,"nchar")) |
---|
220 | { |
---|
221 | sscanf(curr_parm->value,"%d",&(io->init_len)); |
---|
222 | } |
---|
223 | return 1; |
---|
224 | } |
---|
225 | |
---|
226 | ////////////////////////////////////////////////////////////// |
---|
227 | ////////////////////////////////////////////////////////////// |
---|
228 | |
---|
229 | |
---|
230 | int Read_Nexus_Format(char *token, nexparm *curr_parm, option *io) |
---|
231 | { |
---|
232 | int i; |
---|
233 | |
---|
234 | if(token[0] == '=') return 0; |
---|
235 | |
---|
236 | if(!curr_parm) |
---|
237 | { |
---|
238 | PhyML_Printf("\n. Err in file %s at line %d\n",__FILE__,__LINE__); |
---|
239 | Exit(""); |
---|
240 | } |
---|
241 | |
---|
242 | For(i,strlen(token)) Lowercase(token+i); |
---|
243 | |
---|
244 | strcpy(curr_parm->value,token); |
---|
245 | |
---|
246 | if(!strcmp(curr_parm->name,"datatype")) |
---|
247 | { |
---|
248 | if(!strcmp(curr_parm->value,"standard")) |
---|
249 | { |
---|
250 | io->datatype = GENERIC; |
---|
251 | io->mod->whichmodel = JC69; |
---|
252 | io->mod->s_opt->opt_kappa = NO; |
---|
253 | io->mod->s_opt->opt_lambda = NO; |
---|
254 | io->mod->ns = 2; |
---|
255 | io->alphabet[0][0] = '0'; io->alphabet[0][1] = '\0'; |
---|
256 | io->alphabet[1][0] = '1'; io->alphabet[1][1] = '\0'; |
---|
257 | } |
---|
258 | |
---|
259 | else if(!strcmp(curr_parm->value,"dna")) |
---|
260 | { |
---|
261 | io->datatype = NT; |
---|
262 | io->mod->ns = 4; |
---|
263 | } |
---|
264 | |
---|
265 | else if(!strcmp(curr_parm->value,"rna")) |
---|
266 | { |
---|
267 | io->datatype = NT; |
---|
268 | io->mod->ns = 4; |
---|
269 | } |
---|
270 | |
---|
271 | else if(!strcmp(curr_parm->value,"nucleotide")) |
---|
272 | { |
---|
273 | io->datatype = NT; |
---|
274 | io->mod->ns = 4; |
---|
275 | } |
---|
276 | |
---|
277 | else if(!strcmp(curr_parm->value,"protein")) |
---|
278 | { |
---|
279 | io->datatype = AA; |
---|
280 | io->mod->ns = 20; |
---|
281 | } |
---|
282 | |
---|
283 | else if(!strcmp(curr_parm->value,"continuous")) |
---|
284 | { |
---|
285 | PhyML_Printf("\n== The 'continuous' format is not supported by PhyML. Sorry.\n"); |
---|
286 | PhyML_Printf("\n== Err. in file %s at line %d\n",__FILE__,__LINE__); |
---|
287 | Exit(""); |
---|
288 | } |
---|
289 | } |
---|
290 | |
---|
291 | else if(!strcmp(curr_parm->name,"missing")) |
---|
292 | { |
---|
293 | PhyML_Printf("\n== The 'missing' subcommand is not supported by PhyML. Sorry.\n"); |
---|
294 | PhyML_Printf("\n== Err. in file %s at line %d\n",__FILE__,__LINE__); |
---|
295 | Exit(""); |
---|
296 | } |
---|
297 | |
---|
298 | else if(!strcmp(curr_parm->name,"gap")) |
---|
299 | { |
---|
300 | PhyML_Printf("\n== The 'gap' subcommand is not supported by PhyML. Sorry.\n"); |
---|
301 | PhyML_Printf("\n== But the characters 'X', '?' and '-' will be considered as indels by default.\n"); |
---|
302 | PhyML_Printf("\n== Err. in file %s at line %d\n",__FILE__,__LINE__); |
---|
303 | Exit(""); |
---|
304 | } |
---|
305 | |
---|
306 | else if(!strcmp(curr_parm->name,"symbols")) |
---|
307 | { |
---|
308 | if(*token != '"' || *(token+strlen(token)-1) != '"') |
---|
309 | { |
---|
310 | PhyML_Printf("\n== Symbols list is supposed to be displayed between quotation marks (e.g., \"ACTG\").\n"); |
---|
311 | PhyML_Printf("\n== Err. in file %s at line %d\n",__FILE__,__LINE__); |
---|
312 | Exit(""); |
---|
313 | } |
---|
314 | |
---|
315 | |
---|
316 | int i,has_spaces,state_len; |
---|
317 | |
---|
318 | i = 0; |
---|
319 | has_spaces = 0; |
---|
320 | token++; /* Get rid of the first '"' character */ |
---|
321 | while(token[i] != '"') { if(token[i] == ' ') { has_spaces = 1; break; } i++; } |
---|
322 | |
---|
323 | io->mod->ns = 0; |
---|
324 | if(!has_spaces) |
---|
325 | { |
---|
326 | while(token[i] != '"') |
---|
327 | { |
---|
328 | io->alphabet[io->mod->ns][0] = token[i]; |
---|
329 | io->alphabet[io->mod->ns][1] = '\0'; |
---|
330 | io->mod->ns++; |
---|
331 | i++; |
---|
332 | if(io->mod->ns > T_MAX_ALPHABET) |
---|
333 | { |
---|
334 | PhyML_Printf("\n== The alphabet cannot contain more than %d characters. Sorry.",T_MAX_ALPHABET); |
---|
335 | PhyML_Printf("\n== Err. in file %s at line %d\n",__FILE__,__LINE__); |
---|
336 | Exit(""); |
---|
337 | } |
---|
338 | } |
---|
339 | } |
---|
340 | else |
---|
341 | { |
---|
342 | i = 0; |
---|
343 | do |
---|
344 | { |
---|
345 | state_len = 0; |
---|
346 | while(token[i] != ' ' && token[i] != '"') |
---|
347 | { |
---|
348 | io->alphabet[io->mod->ns][state_len] = token[i]; |
---|
349 | state_len++; |
---|
350 | i++; |
---|
351 | if(state_len > T_MAX_STATE) |
---|
352 | { |
---|
353 | PhyML_Printf("\n== A state cannot contain more than %d characters. Sorry.\n",T_MAX_STATE); |
---|
354 | PhyML_Printf("\n== Err. in file %s at line %d\n",__FILE__,__LINE__); |
---|
355 | Exit(""); |
---|
356 | } |
---|
357 | } |
---|
358 | |
---|
359 | io->alphabet[io->mod->ns][state_len] = '\0'; |
---|
360 | io->mod->ns++; |
---|
361 | if(token[i] != '"') i++; |
---|
362 | } |
---|
363 | while(token[i] != '"'); |
---|
364 | } |
---|
365 | |
---|
366 | int len; |
---|
367 | len = strlen(io->alphabet[0]); |
---|
368 | For(i,io->mod->ns) |
---|
369 | { |
---|
370 | if(strlen(io->alphabet[i]) != len) |
---|
371 | { |
---|
372 | PhyML_Printf("\n== All character states defined in the symbol list are supposed to have the same length.\n"); |
---|
373 | PhyML_Printf("\n== Er.r in file %s at line %d\n",__FILE__,__LINE__); |
---|
374 | Exit(""); |
---|
375 | } |
---|
376 | } |
---|
377 | io->state_len = len; |
---|
378 | |
---|
379 | /* For(i,io->mod->ns) PhyML_Printf("\n. '%s'",io->alphabet[i]); */ |
---|
380 | } |
---|
381 | |
---|
382 | else if(!strcmp(curr_parm->name,"equate")) |
---|
383 | { |
---|
384 | PhyML_Printf("\n== PhyML does not recognize the command '%s' yet. Sorry.",curr_parm->name); |
---|
385 | PhyML_Printf("\n== Err. in file %s at line %d\n",__FILE__,__LINE__); |
---|
386 | Exit(""); |
---|
387 | } |
---|
388 | |
---|
389 | else if(!strcmp(curr_parm->name,"matchchar")) |
---|
390 | { |
---|
391 | PhyML_Printf("\n== PhyML does not recognize the command '%s' yet. Sorry.",curr_parm->name); |
---|
392 | PhyML_Printf("\n== Err. in file %s at line %d\n",__FILE__,__LINE__); |
---|
393 | Exit(""); |
---|
394 | } |
---|
395 | |
---|
396 | else if(!strcmp(curr_parm->name,"items")) |
---|
397 | { |
---|
398 | PhyML_Printf("\n== PhyML does not recognize the command '%s' yet. Sorry.",curr_parm->name); |
---|
399 | PhyML_Printf("\n== Err. in file %s at line %d\n",__FILE__,__LINE__); |
---|
400 | Exit(""); |
---|
401 | } |
---|
402 | |
---|
403 | else if(!strcmp(curr_parm->name,"interleave")) |
---|
404 | { |
---|
405 | io->interleaved = YES; |
---|
406 | } |
---|
407 | |
---|
408 | return 1; |
---|
409 | } |
---|
410 | |
---|
411 | ////////////////////////////////////////////////////////////// |
---|
412 | ////////////////////////////////////////////////////////////// |
---|
413 | |
---|
414 | |
---|
415 | int Read_Nexus_Eliminate(char *token, nexparm *curr_parm, option *io) |
---|
416 | { |
---|
417 | if(token[0] == '=') return 0; |
---|
418 | |
---|
419 | PhyML_Printf("\n== 'Eliminate' command is not supported by PhyML. Sorry."); |
---|
420 | PhyML_Printf("\n== Err. in file %s at line %d\n",__FILE__,__LINE__); |
---|
421 | Exit(""); |
---|
422 | |
---|
423 | return 1; |
---|
424 | } |
---|
425 | |
---|
426 | ////////////////////////////////////////////////////////////// |
---|
427 | ////////////////////////////////////////////////////////////// |
---|
428 | |
---|
429 | |
---|
430 | int Read_Nexus_Taxlabel(char *token, nexparm *curr_parm, option *io) |
---|
431 | { |
---|
432 | if(token[0] == '=') return 0; |
---|
433 | |
---|
434 | PhyML_Printf("\n== 'Taxlabels' command is not supported by PhyML. Sorry."); |
---|
435 | PhyML_Printf("\n== Err. in file %s at line %d\n",__FILE__,__LINE__); |
---|
436 | Exit(""); |
---|
437 | |
---|
438 | return 1; |
---|
439 | } |
---|
440 | |
---|
441 | ////////////////////////////////////////////////////////////// |
---|
442 | ////////////////////////////////////////////////////////////// |
---|
443 | |
---|
444 | |
---|
445 | int Read_Nexus_Charstatelabels(char *token, nexparm *curr_parm, option *io) |
---|
446 | { |
---|
447 | |
---|
448 | if(token[0] == '=') return 0; |
---|
449 | |
---|
450 | PhyML_Printf("\n== 'CharStateLabels' command is not supported by PhyML. Sorry."); |
---|
451 | PhyML_Printf("\n== Err. in file %s at line %d\n",__FILE__,__LINE__); |
---|
452 | Exit(""); |
---|
453 | |
---|
454 | return 1; |
---|
455 | } |
---|
456 | |
---|
457 | ////////////////////////////////////////////////////////////// |
---|
458 | ////////////////////////////////////////////////////////////// |
---|
459 | |
---|
460 | |
---|
461 | int Read_Nexus_Charlabels(char *token, nexparm *curr_parm, option *io) |
---|
462 | { |
---|
463 | if(token[0] == '=') return 0; |
---|
464 | |
---|
465 | PhyML_Printf("\n== 'CharLabels' command is not supported by PhyML. Sorry."); |
---|
466 | PhyML_Printf("\n== Err. in file %s at line %d\n",__FILE__,__LINE__); |
---|
467 | Exit(""); |
---|
468 | |
---|
469 | return 1; |
---|
470 | } |
---|
471 | |
---|
472 | ////////////////////////////////////////////////////////////// |
---|
473 | ////////////////////////////////////////////////////////////// |
---|
474 | |
---|
475 | |
---|
476 | int Read_Nexus_Statelabels(char *token, nexparm *curr_parm, option *io) |
---|
477 | { |
---|
478 | if(token[0] == '=') return 0; |
---|
479 | |
---|
480 | PhyML_Printf("\n== 'StateLabels' command is not supported by PhyML. Sorry."); |
---|
481 | PhyML_Printf("\n== Err. in file %s at line %d\n",__FILE__,__LINE__); |
---|
482 | Exit(""); |
---|
483 | |
---|
484 | return 1; |
---|
485 | } |
---|
486 | |
---|
487 | ////////////////////////////////////////////////////////////// |
---|
488 | ////////////////////////////////////////////////////////////// |
---|
489 | |
---|