Mac binaries
[jabaws.git] / website / archive / binaries / mac / src / tcoffee / t_coffee_source / io_lib_header.h
1 /*DEBUGGING*/
2 /*#include "mshell.h"*/
3 /*MEMORY MANAGEMENT*/
4 #include <float.h>
5 #define MY_EPS 1000*DBL_EPSILON
6 //Maximum number of tries for interactibve things
7 #define MAX_N_TRIES 3
8
9 //Maximum CACHE and Temporary file size and age (Mb and days, 0: unlimited)
10 #define TMP_MAX_SIZE  0
11 #define TMP_MAX_KEEP  10
12 #define CACHE_MAX_SIZE  2000
13 #define CACHE_MAX_KEEP  180
14 #define MAX_N_PID       260000
15 //Importnat Values Affecting the Program Behavior
16 #define O2A_BYTE         50
17 #define SCORE_K          10
18 #define NORM_F           1000
19 #define PAVIE_MAT_FACTOR 1000
20 #define MAXID            100
21 #define CLEAN_FUNCTION   NULL
22 #define MINSIM_4_TCOFFEE 25 //The minimum similarity between a sequence and its PDB template
23 #define MINCOV_4_TCOFFEE 25 //The minimum similarity between a sequence and its PDB template
24
25
26 #define TRACE_TYPE       int
27 #define MAX_LEN_FOR_DP   600
28
29
30 #define GIVE_MEMORY_BACK 0
31 #define MEMSET0   1
32 #define NO_MEMSET0 0
33 /*OUTPUT DEFINITIONS*/
34 #define  NO_COLOR_RESIDUE 127
35 #define  NO_COLOR_GAP 126
36 #define  CLOSE_HTML_SPAN -1
37 /*SPECIAL_CODES*/
38 #define GAP_CODE 60
39 /*TYPE DEFINITIONS*/
40
41 //Formats
42 #define BLAST_XML 100
43 #define BLAST_TXT 101
44
45 /*SWITCHES*/
46
47
48 #define USED 1
49 #define UNUSED 2
50
51
52 #define TEMPLATES 1
53 #define NOTEMPLATES 0
54
55 #define EXTEND 1
56 #define RESIZE 2
57
58 #define SEN                0 
59 #define SPE                1 
60 #define REC                2 
61 #define SEN2              2 
62
63 #define ALL               1
64 #define SEGMENTS          2
65 #define DIAGONALS         3
66
67 #define START_STATE       0
68 #define END_STATE         1
69
70 #define KEEP_CASE         2 /*Hard set in several places*/
71 #define LOWER_CASE        0
72 #define UPPER_CASE        1
73 #define CHANGE_CASE       3
74 #define KEEP_GAP          0
75 #define RM_GAP            1
76
77 #define KEEP_NAME         1
78
79 #define CHECK             0
80 #define NO_CHECK          1
81 #define FORCE             2
82 #define STORE             3
83 #define FLUSH             4
84 #define DUMP              5
85
86
87 #define ON                8
88 #define OFF               9
89 #define LOCKED_ON         10
90 #define LOCKED_OFF        11
91
92 #define YES               12
93 #define NO                13
94 #define MAYBE             14
95
96 #define NEVER             15
97 #define ALWAYS            16
98 #define SOMETIMES         17
99
100 #define UPPER             18
101 #define LOWER             19
102 #define DELETE            20
103 #define SWITCHCASE        21 
104
105 #define VECTOR            22
106 #define NON_VECTOR        23
107 #define NON_PROFILE       24
108 #define BOOTSTRAP         25
109
110 #define HEADER            26
111 #define NO_HEADER         27
112
113 #define VERY_VERBOSE      28
114 #define VERBOSE           29
115 #define SHORT             30
116 #define VERY_SHORT        31
117
118 #define OVERLAP           32
119 #define NO_OVERLAP        33
120
121 #define PRINT             34
122 #define NO_PRINT          35
123
124 #define FREE_ALN              36
125 #define DECLARE_ALN           37
126 #define EXTRACT_ALN           38
127 #define CLEAN                 39
128 #define INTERACTIVE           40
129 #define NON_INTERACTIVE       41
130 #define PAD                   42
131 #define NO_PAD                43
132
133 #define SET               44
134 #define UNSET             45
135 #define RESET             48
136 #define ISSET             49
137 #define GET               50
138
139 #define ENV               52
140 #define LLOCK             53
141 #define LERROR            54
142 #define LWARNING          55
143 #define LSET              56
144 #define LRESET            57
145 #define LCHECK            58
146 #define LREAD             59
147 #define LRELEASE          60
148
149 #define RETURN_ON_FAILURE    61
150 #define EXIT_ON_FAILURE    62
151 #define IGNORE_FAILURE     63
152
153 #define _START 64
154 #define _TERM  65
155
156 #define GOP               0
157 #define GCP               1
158 #define GEP               2
159
160 #define BOTTOM             0
161 #define TOP                1
162
163 #define FORWARD            -1
164 #define BACKWARD            1
165
166 #define GO_LEFT            -1
167 #define GO_RIGHT            1
168
169 #define LOCAL            1
170 #define GLOBAL           2
171 #define LALIGN           3
172 #define MOCCA            4
173
174 #define TRUE             1
175 #define FALSE            0
176
177 #define NEW              1
178 #define OLD              0
179
180 #define RANDOM           0
181 #define DETERMINISTIC    1
182
183 #define GREEDY           1
184 #define NON_GREEDY       0
185
186 #define IS_FATAL         1
187 #define IS_NOT_FATAL     0
188 #define NO_REPORT        2
189 #define INSTALL          3
190 #define INSTALL_OR_DIE   4
191
192 #define OPTIONAL         1
193 #define NON_OPTIONAL     0
194
195 #define GV_MAXIMISE      1
196 #define GV_MINIMISE      0
197
198 #define MAXIMISE      1
199 #define MINIMISE      0
200
201 #define ALLOWED          0
202 #define FORBIDEN         -99999999
203 #define END_ARRAY        -99999990
204 #define SOFT_COPY 1
205 #define HARD_COPY 2
206
207 #define VERY_SLOW 0
208 #define SLOW 1
209 #define FAST 2
210 #define VERY_FAST 3
211 #define SUPER_FAST 4
212 #define ULTRA_FAST 5
213
214 #define CODE 1
215 #define DECODE 2
216 #define CODELIST 3
217
218 /*Identity measure*/
219 #define UNGAPED_POSITIONS 1
220 #define ALIGNED_POSITIONS 2
221 #define AVERAGE_POSITIONS 3
222 #define NOMATRIX         NULL
223 #define NOGROUP          NULL
224 #define NOALN            NULL
225
226 /*SIZE DEFINITIONS*/
227 #define SIZE_OF_INT      10
228 #define UNDEFINED        FORBIDEN
229 #define UNDEFINED_INT    UNDEFINED
230 #define UNDEFINED_FLOAT  UNDEFINED
231 #define UNDEFINED_DOUBLE UNDEFINED
232 #define UNDEFINED_CHAR   125
233 #define UNDEFINED_SHORT  -125
234 #define UNDEFINED_2      0
235 #define UNDEFINED_RESIDUE '>'
236
237
238
239 #define FACTOR           1
240 #define MAX_N_SEQ        1
241 #define MAX_N_ALN        1
242 #define MAX_LEN_ALN      1
243 #define MAX_N_LIST       100
244
245 #define COMMENT_SIZE     1000
246 #define MAXNAMES         100
247 #define FILENAMELEN      500            /* Max. file name length */
248 #define MAX_N_PARAM      2000
249 #define MAX_PARAM_LEN    200
250 #define MAX_LINE_LENGTH  10000
251 #define ALN_LINE_LENGTH  50
252 #define SHORT_STRING     10
253 #define STRING           300
254 #define LONG_STRING      1000
255 #define VERY_LONG_STRING 10000
256
257 #define AA_ALPHABET            "acdefghiklmnpqrstvwy-ACDEFGHIKLMNPQRSTVWY"
258 #define DNA_ALPHABET           "AGCTUNRYMKSWHBVD-agctunrymkswhbvd"
259 #define RNAONLY_ALPHABET       "Uu"
260 #define BLAST_AA_ALPHABET      "arndcqeghilkmfpstwyvbzx*"
261 #define NAMES_ALPHABET         "1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_|�-!%@&#-+=."
262
263 #define SIZEOF_AA_MAT   60
264 #define GAP_LIST         "-.#*~"
265 #define SSPACE           "   "
266
267 #define MATCH            1
268 #define UNALIGNED        2
269 #define GAP              3
270
271 #define MNE 3
272 #define CODE4PROTEINS  10
273 #define CODE4DNA       20
274
275 #define STOCKHOLM_CHAR 'z'
276 #define STOCKHOLM_STRING "z"
277
278
279 /*CODE SHORT CUTS*/
280
281 /*1-COMMAND LINE PROCESSING*/
282 #define GET_COMMAND_LINE_INFO ((strncmp ( argv[1], "-h",2)==0)||(strncmp ( argv[1], "-man",4)==0)||(strncmp ( argv[1], "-",1)!=0))
283 #define NEXT_ARG_IS_FLAG ((argc<=(a+1)) ||(( argv[a+1][0]=='-') && !(is_number(argv[a+1]))))
284
285
286 /*UTIL MACROS*/
287 #define BORDER(p1,l1,p2,l2) ((p1==0 || p2==0 || p1==l1 || p2==l2)?1:0) 
288 #define GET_CASE(f,c) ((f==UPPER_CASE)?toupper(c):((f==LOWER_CASE)?tolower(c):c))
289
290 #define SWAP(x,y) {x=x+y;y=x+y; x=y-x; y=y-2*x;}
291 #define SWAPP(x,y,tp) {tp=y;y=x;x=tp;}
292
293 #define MAX(x, y) (((x) >(y)) ? (x):(y))
294 #define MAX2(x, y) (((x) >(y)) ? (x):(y))
295 #define MAX3(x,y,z) (MAX(MAX(x,y),z))
296 #define MAX4(a,b,c,d) (MAX(MAX(a,b),MAX(c,d)))
297 #define MAX5(a,b,c,d,e) (MAX2((MAX3(a,b,c)),(MAX2(d,e))))
298 #define MAX6(a,b,c,d,e,f) (MAX2((MAX3(a,b,c)),(MAX3(c,d,e))))
299
300 #define MIN(x, y) (((x) <(y)) ? (x):(y))
301 #define FABS(x) ((x<0)?(-x):(x))
302 #define is_defined(x) ((x==UNDEFINED)?0:1)
303 #define a_better_than_b(x,y,m) ((m==1)?(((x)>(y))?1:0):(((x)<(y))?1:0))
304 #define is_in_range(x,min,max) ((x>=min && x<=max)?1:0)
305 /*#define bod_a_b(x,y,m)   ((m==1)?(MAX((x),(y))):(MIN((x),(y))))
306 #define bo_a_b(x,y,m)    ((x==UNEFINED)?y:((y==UNDEFINED)?x:bod_a_b(y,y,m)))
307 #define best_of_a_b(x,y,m)   ((x==UNDEFINED && y==UNDEFINED)?(UNDEFINED):(bo_a_b(x,y,m)))
308 */
309
310
311 #define DIE(x)  HERE(x);exit(0);
312 #define best_of_a_b(x,y,m) ((m==1)?(MAX((x),(y))):(MIN((x),(y))))
313
314 #define strm(x,y)            ((vstrcmp((x),(y))==0)?1:0)
315 #define strnm(x,y,n)           ((vstrncmp((x),(y),(n))==0)?1:0)
316 #define strm2(a,b,c)         (strm(a,b) || strm(a,c))
317 #define strm3(a,b,c,d)       (strm2(a,b,c) || strm(a,d))
318 #define strm4(a,b,c,d,e)     (strm2(a,b,c) || strm2(a,d,e))
319 #define strm5(a,b,c,d,e,f)   (strm2(a,b,c) || strm3(a,d,e,f))
320 #define strm6(a,b,c,d,e,f,g) (strm3(a,b,c,d) || strm3(a,e,f,g))
321 #define declare_name(x) (x=vcalloc (MAX(FILENAMELEN,L_tmpnam)+1, sizeof (char))) 
322 #define is_parameter(x) (x[0]=='-' && !isdigit(x[1])) 
323
324 /*Freing functions*/
325 #define free_2(a, b)            free(a);free(b)
326 #define free_1(a)               free(a)
327 #define free_3(a, b, c)         free_2(a,b);free_1(c)
328 #define free_4(a, b, c,d)       free_2(a,b);free_2(c,d)
329 #define free_5(a, b, c,d,e)     free_3(a,b,e);free_2(c,d)
330 #define free_6(a, b, c,d,e,f)   free_3(a,b,e);free_3(c,d,f)
331 #define free_7(a, b, c,d,e,f,g) free_3(a,b,e);free_4(c,d,f,g)
332 /*2-FILE PARSING*/
333 #define SEPARATORS "\n \t,;"
334 #define LINE_SEPARATOR "\n#TC_LINE_SEPARATOR\n"
335 #define TC_REC_SEPARATOR "#### TC REC SEPARATOR ###"
336
337 /*END 1-*/
338
339
340 /*WIDOWS/UNIX DISTINCTIONS
341 #if defined(_WIN32) || defined(__WIN32__) ||  defined(__WINDOWS__) || defined(__MSDOS__) || defined(__DOS__) || defined(__NT__) || defined(__WIN32__)
342 #define WIN32
343 #define TO_NULL_DEVICE " >nul"
344 #define    NULL_DEVICE "nul"
345 #define CWF "/" 
346 #else
347 #define TO_NULL_DEVICE " >/dev/null 2>&1"
348 #define    NULL_DEVICE "/dev/null"
349 */
350
351 #if defined(_WIN32) || defined(__WIN32__) ||  defined(__WINDOWS__) || defined(__MSDOS__) || defined(__DOS__) || defined(__NT__) || defined(__WIN32__)
352 #define WIN32
353 #define TO_NULL_DEVICE " >>t_coffee.log"
354 #define    NULL_DEVICE "t_coffee.log"
355 #define CWF "/" /*ClustalW Flag*/
356 #else
357 #define TO_NULL_DEVICE " >>/dev/null 2>&1"
358 #define    NULL_DEVICE "/dev/null"
359
360
361 #define CWF "-" /*ClustaW Flag*/
362 #endif
363
364 /*Generic Data*/
365 #define EMAIL "cedric.notredame@europe.com"
366 #define URL "http://www.tcoffee.org"
367
368 #define PERL_HEADER "#!/usr/bin/env perl"
369
370 //Optimize the Score Computation in DP
371 #define TC_SCORE_2(x,y) (SCORE_K*CL->M[Aln->seq_al[l_s[0][0]][x]-'A'][Aln->seq_al[l_s[1][0]][y]-'A']-SCORE_K*CL->nomatch) 
372 #define TC_SCORE_N(x,y) ((CL->get_dp_cost)(Aln, pos, ns[0], l_s[0], x, pos, ns[1], l_s[1], y, CL))
373 #define TC_SCORE(x,y)  ((CL->get_dp_cost==slow_get_dp_cost && CL->evaluate_residue_pair==evaluate_matrix_score && ns[0]+ns[1]==2 && x>=0 && j>=0)? (TC_SCORE_2(x,y)):(TC_SCORE_N(x,y)))
374
375 #define NULL_2 NULL,NULL
376 #define NULL_3 NULL_2,NULL
377 #define NULL_4 NULL_2,NULL_2
378 #define NULL_5 NULL_3,NULL_2
379 #define NULL_6 NULL_4,NULL_2
380 #define NULL_7 NULL_5,NULL_2
381 typedef struct
382     {
383     char *mode;
384     char *comments;
385     int nseq;
386     char **seq_name;
387     float **PW_SD;
388     float **PW_ID;
389     float *SEQ_W;
390     }Weights;
391
392 typedef struct
393     {
394     int **list;
395     int tot_list;
396     int **stem;
397     int tot_stem;
398     int n_fields;
399     int nseq;
400     int *len;
401     int ***struc;
402     struct Sequence *S;  
403     }Structure;
404
405 struct Sequence
406     {
407       char **file;          /* file[Nseq][FILENAMELEN] name of the file that contributed each sequence*/
408       char **seq_comment;     /* seq_comment[Nseq][LONG_STRING] comment read in the file */
409       char **aln_comment;  /*id*/
410       char **seq;          /*seq[Nseq][sequence] sequences*/
411       int *len;            /*len[Nseq] length of each sequence*/
412       int max_len;         /*Lenght of the longest seq */
413       int min_len;         /*Length of the shortest seq*/
414       int nseq;            /*nseq*/
415       int max_nseq;        /*Maximum number of sequences in the datastruct*/
416       char **name;         /*name[Nseq][MAXNAMELEN]*/
417       int **dc;         /*coordinates on the disk. Coordinates set if seq[i]==NULL*/
418 /*Constraint list*/
419       struct Constraint_list *CL;
420       int contains_gap;   /*set to 1 if gaps are to be kept*/
421       char *type;         /*PROTEIN, DNA*/
422       Weights *W;         /*Associated weights*/
423       char template_file[FILENAMELEN+1];
424       struct Template **T;
425       
426       
427 };
428 typedef struct Sequence Sequence;
429
430 //_E_
431 struct Template
432 {
433   char seq_type[10];
434   struct X_template *P;//PDB structure
435   struct X_template *F;//RNA secondary structure
436   struct X_template *S;//sequence
437   struct X_template *R;//Profile
438   struct X_template *G;//Genomic structure
439   struct X_template *T;//transmembrane
440   struct X_template *E;//secondary structure
441   struct X_template *U;//Unicode, strings
442   
443   struct X_template *RB;
444 };
445 typedef struct Template Template;
446 //_E_
447 struct X_template 
448 {
449   char seq_name[FILENAMELEN+1];
450   char template_type[FILENAMELEN+1];
451   char template_format[100];
452   char template_name[FILENAMELEN+1];
453   char template_file[FILENAMELEN+1];
454   
455   struct P_template *VP; 
456   struct F_template *VF;
457   struct S_template *VS;
458   struct R_template *VR;
459   struct G_template *VG;
460   struct T_template *VT;
461   struct E_template *VE;
462   struct U_template *VU;
463   
464   
465 };
466 typedef struct X_template X_template;
467
468 //
469 struct P_template
470 {
471   char pdb_id[100];
472 };
473 typedef struct P_template P_template;
474
475 //RNA secondary Structure
476 struct F_template
477 {
478   int l;
479 };
480 typedef struct F_template F_template;
481
482
483 struct S_template
484 {
485   Sequence *S;
486 };
487 typedef struct S_template S_template;
488
489 //Prile associated with a sequence
490 struct R_template
491 {
492   struct Alignment *A;
493 };
494 typedef struct R_template R_template;
495
496 //Genomic Information
497 struct G_template
498 {
499   Sequence *S;
500 };
501 typedef struct G_template G_template;
502
503
504 struct T_template
505 {
506   Sequence *S;
507 };
508 typedef struct T_template T_template;
509
510 //_E_
511 struct E_template
512 {
513   Sequence *S;
514 };
515 typedef struct E_template E_template;
516
517 struct U_template
518 {
519   int *list;
520 };
521 typedef struct U_template U_template;
522
523
524 typedef struct
525     {
526     int max_len;
527     int alp_size;
528     char *alphabet;
529     int **count3;  
530     int **count;
531     int **count2;  
532     }Profile;
533
534 struct Alignment
535     {
536 /*Size*/
537     int max_len;
538     int min_len;   
539     int *  len;
540       //int *weight;  
541     int declared_len;
542     int max_n_seq;
543     int nseq;
544     int len_aln;
545 /*Generic Information*/
546       char *generic_comment;
547 /*Sequence Information*/
548     char **file;
549     char **seq_comment;
550     char **aln_comment;
551     char **name;
552       
553     char **expanded_order;
554     char **tree_order;
555     char **seq_al;
556     
557     int  **order;
558     Profile *P;
559     Sequence *S;
560     struct Dp_Result *Dp_result;
561     struct Constraint_list *CL;
562
563     int **seq_cache; /*Contains the index of the residues:
564                        The sequence Numbering is relative to the sequences, and not to the alignmnent
565                        
566                        seq_cache[0][1]=3
567                        indicates that in the aln residue (0)1 corresponds to [order[0][0]][3]
568                        residues: 1...N
569                        Sequences 0...M
570                      */
571     int **cdna_cache; /*Contains the information about wheather a nucleotide is coding or not*/
572                      /*Only defined if used */
573
574
575 /*Weight*/   
576       float *col_weight;
577       float *seq_weight;
578       float **res_weight;
579 /*Score*/
580     int *  score_seq;
581     int ** score_res;
582     int score_aln;
583     int score;
584     int ibit;  
585     int cpu;
586     int finished;
587
588 /*Input/Output Options*/
589     int output_res_num;
590     int residue_case; /*1 for lower, 0 for Upper, 2 for keeping unchanged*/
591       int expand;
592     int output_tm;
593 /*Must Not be copied*/
594      int used;
595      int num;     
596      int **pos; 
597 /*For linked lists*/      
598     struct Alignment * A;  
599       /*Misc*/
600     int random_tag;
601      
602     };
603     
604 typedef struct Alignment Alignment;
605 typedef struct
606     {
607     int in_seq; 
608     FILE *fp;
609     int font;
610     int x0;
611     int y0;
612     int x;
613     int y;
614     int n_pages;
615     int max_line_ppage;
616     int n_line;
617     int line;
618     int eop;
619     int in_html_span;
620     char previous_html_color[100];
621    
622     }
623 FILE_format;
624
625 typedef struct
626     {
627     float r;
628     float g;
629     float b;
630     char html_color[30];
631     char html_color_class[30]; 
632     int ascii_value;
633     }
634 Color;
635
636
637 Sequence * fill_sequence_struc ( int nseq, char **sequences, char **seq_name);
638 Sequence * cw_read_sequences ( char *seq_name);
639 Sequence * get_sequence_type (Sequence *S);
640 char     * get_array_type (int n, char **s);
641 Alignment* get_aln_type (Alignment *A);
642
643 char     * get_string_type   (char *string);
644
645 char *store_mode (char *val);
646 char *retrieve_mode ();
647 char *unset_mode ();
648 char *set_mode (int mode, char *val);
649
650 char *store_seq_type (char *val);
651 char *retrieve_seq_type ();
652 char *unset_seq_type ();
653 char *set_seq_type (int mode, char *val);
654
655 void get_sequence (char *seq_file,int *NSEQ, char ***SEQ, char ***SN, int **sl, int *min, int *max);
656
657 int ** get_matrix   ( char *name, char *format);
658 int ** read_matrice (char *mat_name);
659 int **neg_matrix2pos_matrix ( int **matrix);   
660
661
662 void   print_aln ( Alignment *B);
663
664 int       output_reliability_ps     ( Alignment *B,Alignment *S, char *name);
665 int       output_reliability_pdf    ( Alignment *B,Alignment *S, char *name);
666 int       output_reliability_html   ( Alignment *B,Alignment *S, char *name);
667 int       output_color_ps     ( Alignment *B,Alignment *S, char *name);
668 int       output_color_pdf    ( Alignment *B,Alignment *S, char *name);
669 int       output_color_html   ( Alignment *B,Alignment *S, char *name);
670 int       output_hit_color_html   (Alignment *B, float **ffPScoreTable, int nl, char *name);    //JM_ADD
671 void      output_hit_matrix(char *fileName, float **ffpHitScoreMatrix, int nl);         //JM_ADD
672 void      get_rgb_values(int val, Color *C);
673 int       output_reliability_format ( Alignment *B,Alignment *S, char *name, \
674 FILE_format *(*vfopen_format)          ( char *),\
675 FILE_format *(*print_format_string)    ( char * ,Color *, Color *, FILE_format*),\
676 FILE_format *(*print_format_char)      ( int    ,Color *, Color *, FILE_format*),\
677 void         (*get_rgb_values_format)  ( int    ,Color *),\
678 FILE_format* (*vfclose_format)         ( FILE_format *));
679 int       output_score_format ( Alignment *B,Alignment *S, char *name, \
680 FILE_format *(*vfopen_format)          ( char *),\
681 FILE_format *(*print_format_string)    ( char * ,Color *, Color *, FILE_format*),\
682 FILE_format *(*print_format_char)      ( int    ,Color *, Color *, FILE_format*),\
683 void         (*get_rgb_values_format)  ( int    ,Color *),\
684 FILE_format* (*vfclose_format)         ( FILE_format *));
685
686
687 FILE_format * print_ps_string      ( char *s , Color *box, Color *ink, FILE_format *f);
688 FILE_format * print_ps_char        ( int   c,    Color *box, Color *ink, FILE_format *f);
689
690
691
692 void get_rgb_values_ps ( int val, Color *C);
693 FILE_format* vfopen_ps ( char *name);
694 FILE_format* vfclose_ps ( FILE_format *fps);
695
696 FILE_format *print_html_string( char *s, Color *box, Color *ink, FILE_format *fhtml);
697 FILE_format * print_html_char ( int c, Color *box, Color *ink, FILE_format *f);
698 void get_rgb_values_html ( int val, Color *C);
699 FILE_format* vfopen_html ( char *name);
700 FILE_format* vfclose_html ( FILE_format *fhtml);
701
702 int       output_reliability_ascii     ( Alignment *B,Alignment *S, char *name);
703 int       output_color_ascii           ( Alignment *B,Alignment *S, char *name);
704
705 FILE_format *print_ascii_string( char *s, Color *box, Color *ink, FILE_format *fascii);
706 FILE_format * print_ascii_char ( int c, Color *box, Color *ink, FILE_format *f);
707 void get_rgb_values_ascii ( int val, Color *C);
708
709 FILE_format* vfopen_ascii ( char *name);
710 FILE_format* vfclose_ascii ( FILE_format *fascii);
711 int       output_seq_reliability_ascii     ( Alignment *B,Alignment *S, char *name);
712 /*********************CLUSTALW.H*********************************************/
713 /****************************************************************************/
714
715    /*
716    Main header file for ClustalW.  Uncomment ONE of the following 4 lines
717    depending on which compiler you wish to use.
718    */
719
720 #define VMS 1                 /*VAX or ALPHA VMS */
721
722 /*#define MAC 1                 Think_C for MacIntosh */
723
724 /*#define MSDOS 1               Turbo C for PC's */
725
726 /*#define UNIX 1                Ultrix/Decstation, Gnu C for 
727                                 Sun, IRIX/SGI, OSF1/ALPHA */
728
729 /***************************************************************************/
730 /***************************************************************************/
731
732
733
734
735
736 #define MAXTITLES               60      /* Title length */
737
738         
739 #define UNKNOWN   0
740 #define EMBLSWISS 1
741 #define PIR       2
742 #define PEARSON   3
743 #define GDE       4
744 #define CLUSTAL   5     /* DES */
745 #define MSF       6 /* DES */
746 #define USER      7     /* DES */
747
748 #define PAGE_LEN       22   /* Number of lines of help sent to screen */
749
750 #ifdef VMS                                              /* Defaults for VAX VMS */
751 #define DIRDELIM ']'            /* Last character before file name in full file 
752                                                            specs */
753 #define SEQ_MAX_LEN             10000   /* Max Sequence Length */
754 #define MAXN            500             /* Max Number of Sequences */
755 #define FSIZE       25000   /* Work space for pairwise alignments */
756 #define MAXTREE         5000    /* Max Nodes for phylogenetic tree */
757 #define LINELENGTH      60  /* Output line length */
758 #define GCG_LINELENGTH  50  /* Output line length for GCG output */
759
760 #elif MAC
761 #define DIRDELIM ':'
762 #define SEQ_MAX_LEN             1000
763 #define MAXN            30
764 #define FSIZE       5000
765 #define MAXTREE         1000
766 #define LINELENGTH      50
767 #define GCG_LINELENGTH  50
768
769
770 #elif MSDOS
771 #define DIRDELIM '\\'
772 #define SEQ_MAX_LEN             1300
773 #define MAXN            30
774 #define FSIZE           5000
775 #define MAXTREE         1000
776 #define LINELENGTH      50
777 #define GCG_LINELENGTH  50
778
779 #elif UNIX
780 #define DIRDELIM '/'
781 #define SEQ_MAX_LEN             10000
782 #define MAXN            500
783 #define FSIZE           25000
784 #define MAXTREE         5000
785 #define LINELENGTH      60
786 #define GCG_LINELENGTH  50
787 #endif
788
789 #define NUMRES 26               /* max size of comparison matrix */
790
791 #define INPUT 0
792 #define ALIGNED 1
793
794 #define LEFT 1
795 #define RIGHT 2
796
797 #define NODE 0
798 #define LEAF 1
799
800 #define GAPCOL 32               /* position of gap open penalty in profile */
801 #define LENCOL 33               /* position of gap extension penalty in profile */
802
803 typedef struct node {           /* phylogenetic tree structure */
804         struct node *left;
805         struct node *right;
806         struct node *parent;
807         float dist;
808         int  leaf;
809         int order;
810         char name[64];
811 } stree, *treeptr;
812
813 void            *ckalloc(size_t);
814 void            * ckvrealloc(void *,size_t);
815 void            ckfree(void *);
816
817 int readseqs(char *saga_file,char ***SAGA_SEQ, char*** SAGA_NAMES, int ***SAGA_LEN) ;/*first_seq is the #no. of the first seq. to read */
818
819
820 typedef struct treesim{
821   float w;
822   float uw;
823   float d;
824   
825   float max_w;
826   float max_uw;
827   float max_d;
828   
829   int rf;
830   int n;//n nodes;
831   int nseq;// nseq in the common subset
832     }Tree_sim;
833
834
835 typedef struct tnode *NT_node;
836
837 /**
838 * Node of a tree
839 */
840 typedef struct tnode{
841   int visited;
842   char *name;
843   char *file;
844   
845   ///The parent node
846   NT_node parent;
847   ///Left child node
848   NT_node left;
849   ///Right child node
850   NT_node right;
851   NT_node bot;
852   /// is leaf?
853   int isseq;
854   int seq;
855   int maxnseq;
856   int nseq;
857   
858   ///contains a list of the sequences
859   int *lseq; 
860   ///contains a coded version of the node: 10010101
861   int *lseq2;
862   ///contains distances to the root, in nodes
863   int *idist;
864   ///contains real distances *1000
865   int *ldist;
866   float dist;
867   float bootstrap;
868   float dp;
869   int order;
870   int aligned;
871   ///Number of leave below the considered node
872   int leaf;
873   ///Number of nodes below the considered node
874   int node;
875   int group;
876   float score;
877   int align;
878   char *seqal;
879   int index;
880   int fork;
881     }Treenode;
882
883 typedef struct split_struc Split;
884
885 typedef struct split_struc{
886   char *split;
887   int n;
888   int tot;
889   float score;
890   char **tlist;//Not used yet
891   Sequence *S;
892   NT_node *L;
893 }Split_struc;
894
895 NT_node main_prune_tree ( NT_node T, Sequence *S);
896 NT_node prune_tree ( NT_node T, Sequence *S);
897 /*********************************************************************/
898 /*                                                                   */
899 /*                                   dpa_tree_manipulation           */
900 /*                                                                   */
901 /*                                                                   */
902 /*********************************************************************/
903 char *tree2Ngroup (Alignment *A, NT_node T, int max_n, char *fname, char *mat4dist);
904 int tree2group_file ( NT_node T,Sequence *S, int maxnseq, int minsim, char *name);
905
906 NT_node seq2dpa_tree  (Sequence *S, char *align_mode);
907 NT_node tree2dpa_tree (NT_node T, Alignment *A, char *matrix4distance);
908 FILE * tree2group ( NT_node T,Sequence *S,int maxnseq, int mindist,char *name, FILE *fp);
909
910
911 NT_node  tree2collapsed_tree (NT_node T, int n, char **string);
912
913 /*********************************************************************/
914 /*                                                                   */
915 /*                                   tree comparison                 */
916 /*                                                                   */
917 /*                                                                   */
918 /*********************************************************************/
919 int main_compare_cog_tree (NT_node T1, char *cogfile);
920 int main_compare_aln_tree (NT_node T1, Alignment *A, FILE *fp);
921 int compare_aln_tree (NT_node T, Alignment *A, int *n, FILE *fp);
922
923 int main_compare_splits (NT_node T1, NT_node T2, char *mode, FILE *fp);
924 Tree_sim * tree_cmp( NT_node T1, NT_node T2);
925 NT_node tree_scan (Alignment *A,NT_node RT, char *pscan, char *ptree);
926
927 int print_node_list (NT_node T, Sequence *S);
928 NT_node main_compare_trees ( NT_node T1, NT_node T2, FILE *fp);
929 NT_node main_compare_trees_list ( NT_node T1, Sequence *S, FILE *fp);
930
931 float compare_trees ( NT_node T1, NT_node T2, int nseq, int mode);
932 float search_node ( NT_node B, NT_node T, int nseq, int mode);
933 float evaluate_node_similarity ( NT_node B, NT_node T, int nseq, int mode);
934
935 int compare_node ( int *b1, int *b2, int n);
936 void display_node (NT_node N, char *string,int nseq);
937 NT_node index_tree_node    (NT_node T);
938 NT_node simple_recode_tree (NT_node T, int nseq);
939 NT_node recode_tree ( NT_node T, Sequence *S);
940 int compare_branch2 ( int *b1, int *b2, int n);
941
942 /*********************************************************************/
943 /*                                                                   */
944 /*                                   FJ_tree Computation             */
945 /*                                                                   */
946 /*                                                                   */
947 /*********************************************************************/
948 NT_node similarities_file2tree (char *mat);
949 NT_node tree_compute ( Alignment *A, int n, char ** arg_list);
950 static NT_node compute_std_tree (Alignment *A, int n, char **arg_list);
951 NT_node compute_std_tree_2 (Alignment *A, int **s, char *arg_list);
952 NT_node aln2fj_tree(NT_node T, Alignment *A, int limit,char* mode);
953 Alignment * filter_aln4tree (Alignment *A, int n,int fg,char* mode);
954
955 /*********************************************************************/
956 /*                                                                   */
957 /*                                   Tree Filters and MAnipulation   */
958 /*                                                                   */
959 /*                                                                   */
960 /*********************************************************************/
961 int  tree2star_nodes (NT_node R, int n_max);
962 NT_node aln2tree (Alignment *A);
963 NT_node reset_boot_tree ( NT_node R, int n);
964 NT_node tree_dist2normalized_tree_dist ( NT_node R, float max);
965 NT_node reset_dist_tree ( NT_node R, float n);
966 NT_node* free_treelist  ( NT_node *R);
967 NT_node free_tree  ( NT_node R);
968 NT_node realloc_tree( NT_node R, int n);
969 NT_node free_tree_node ( NT_node R);
970
971 Sequence * tree2seq    (NT_node R, Sequence *S);
972 NT_node  rename_seq_in_tree ( NT_node R, char ***list);
973
974 NT_node balance_tree (NT_node);
975 int tree2nseq ( NT_node R);
976 int tree_file2nseq ( char *file);
977
978 int tree2nleaf ( NT_node R);
979 int tree2nnode ( NT_node R);
980 int tree2_nnode_unresolved (NT_node R, int *l);
981
982 FILE* display_tree ( NT_node R, int n, FILE *fp);
983 void clear_tree (NT_node T);
984 int display_leaf ( NT_node T, FILE *fp);
985 int display_leaf_below_node ( NT_node T, FILE *fp);
986 NT_node display_leaf_nb (NT_node T, int n, FILE *fp, char *name);
987 NT_node display_splits (NT_node T,Sequence *S, FILE *fp);
988 int tree2split_list (NT_node T, int nseq, int **split_list, int *n);
989
990 NT_node reroot_tree ( NT_node TREE, NT_node T);
991 NT_node straighten_tree ( NT_node P, NT_node C, float new_dist);
992 NT_node unroot_tree ( NT_node T);
993 FILE* print_tree_list ( NT_node *T,char *format, FILE *fp);
994 FILE* print_tree ( NT_node T,char *format, FILE *fp);
995 char *tree2string (NT_node T);
996 char *tree2file   (NT_node T, char *name, char *mode);
997
998 int print_newick_tree ( NT_node T, char *name);
999 FILE * rec_print_tree ( NT_node T, FILE *fp);
1000
1001
1002 NT_node find_longest_branch ( NT_node T, NT_node L);
1003 NT_node shift_root ( NT_node R);
1004
1005 int ** tree2cluster (NT_node T, float thres);
1006 int ** make_sub_tree_list ( NT_node **T, int nseq, int n_node);
1007 void make_all_sub_tree_list ( NT_node N, int **list, int *n);
1008 void make_one_sub_tree_list ( NT_node T, int *list);
1009 NT_node main_read_tree(char *treefile);
1010
1011 NT_node new_read_tree ( char *teefile);
1012 NT_node new_get_node (NT_node T, FILE *fp);
1013
1014
1015 NT_node** simple_read_tree(char *treefile);
1016 void free_read_tree (NT_node **BT);
1017 NT_node** read_tree(char *treefile, int *nnodes,int nseq, char **seq_names);
1018 FILE * create_linear_tree ( char **name, int n, FILE *fp);
1019 FILE * create_tree(NT_node ptree, NT_node parent,int *numseq,int  *ntotal,int  *nnodes,NT_node **lu, FILE *fp);
1020 NT_node declare_tree_node (int nseq);
1021 void set_info(NT_node p, NT_node parent, int pleaf, char *pname, float pdist, float bootstrap);
1022 NT_node insert_tree_node(NT_node pptr);
1023 FILE * skip_space(FILE *fd);
1024 void create_tree_node(NT_node pptr, NT_node parent);
1025 float calc_mean(NT_node nptr, float *maxdist, int nseq,NT_node **lu);
1026 NT_node insert_root(NT_node p, float diff);
1027 float calc_root_mean(NT_node root, float *maxdist, int neq, NT_node **lu);
1028 NT_node reroot(NT_node ptree, int nseq, int ntotal, int nnodes, NT_node **lu);
1029
1030
1031 Alignment *seq2seq_chain (Alignment *A,Alignment *B, char *arg);
1032
1033 float display_avg_bootstrap ( NT_node T);
1034 float tree2tot_dist ( NT_node T, int mode);
1035 int tree2n_branches(NT_node T, int mode);
1036 int **display_tree_from_node (NT_node T, int up, int down, int **array);
1037 NT_node tree2node ( char *name, NT_node T);
1038 NT_node * tree2node_list (NT_node T, NT_node *L);
1039 NT_node tree2root ( NT_node T);
1040 int new_tree_sort ( char *name, NT_node T);
1041
1042
1043 NT_node split2tree ( NT_node RT,Sequence *LIST, char *param);
1044 NT_node * read_tree_list (Sequence *S);
1045
1046 int count_groups( Sequence *S, char *s);
1047
1048 Split ** count_splits( NT_node RT, Sequence *S, char *s);
1049 NT_node *treelist2prune_treelist (Sequence *S, Sequence *TS, FILE *out);
1050 int** treelist2groups (Sequence *S, Sequence *ST, char *depth, FILE *out);
1051 int treelist2splits (Sequence *S, Sequence *ST);
1052 int treelist2leafgroup ( Sequence *S, Sequence *TS, char *taxon);
1053 int ***tree2dist ( NT_node T, Sequence *S, int ***d);
1054 int treelist2frame (Sequence *S, Sequence *TS);
1055 int** treelist2lti ( Sequence *S, Sequence *TS, int nb, FILE *out);
1056
1057 float simple_tree_cmp (NT_node T1, NT_node T2,Sequence *S, int mode);
1058
1059 int treelist2dmat ( Sequence *S);
1060 NT_node new_declare_tree_node ();
1061 int count_tree_groups( Sequence *LIST, char *group_file);
1062 int node_sort ( char *name, NT_node T);
1063 int    treelist2n (NT_node *L);
1064 int ** treelist2avg_treecmp (NT_node *L, char *file);
1065 NT_node treelist2bootstrap ( NT_node *L, char *file);
1066 NT_node treelist2filtered_bootstrap ( NT_node *L, char *file, int **score,float f);
1067
1068 Sequence * treelist2seq ( Sequence *S);
1069 Sequence * treelist2sub_seq ( Sequence *S, int f);
1070
1071 int treelist_file2consense (char *tree_file, char *outtree, char *outfile);
1072 /* General purpose header file - rf 12/90 */
1073
1074 #ifndef _H_general
1075 #define _H_general
1076
1077
1078
1079 #define pint int                        /* cast ints in printf statements as pint */
1080 typedef int Boolean;                    /* Is already defined in THINK_C */
1081
1082 #undef TRUE                                             
1083 #undef FALSE
1084 #define TRUE 1
1085 #define FALSE 0
1086
1087 #define EOS '\0'                                /* End-Of-String */
1088 #define MAXLINE 512                     /* Max. line length */
1089
1090
1091 #endif /* ifndef _H_general */
1092 /******************************COPYRIGHT NOTICE*******************************/
1093 /*© Centro de Regulacio Genomica */
1094 /*and */
1095 /*Cedric Notredame */
1096 /*Fri Feb 18 08:27:45 CET 2011 - Revision 596. */
1097 /*All rights reserved.*/
1098 /*This file is part of T-COFFEE.*/
1099 /**/
1100 /*    T-COFFEE is free software; you can redistribute it and/or modify*/
1101 /*    it under the terms of the GNU General Public License as published by*/
1102 /*    the Free Software Foundation; either version 2 of the License, or*/
1103 /*    (at your option) any later version.*/
1104 /**/
1105 /*    T-COFFEE is distributed in the hope that it will be useful,*/
1106 /*    but WITHOUT ANY WARRANTY; without even the implied warranty of*/
1107 /*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the*/
1108 /*    GNU General Public License for more details.*/
1109 /**/
1110 /*    You should have received a copy of the GNU General Public License*/
1111 /*    along with Foobar; if not, write to the Free Software*/
1112 /*    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA*/
1113 /*...............................................                                                                                      |*/
1114 /*  If you need some more information*/
1115 /*  cedric.notredame@europe.com*/
1116 /*...............................................                                                                                                                                     |*/
1117 /**/
1118 /**/
1119 /*      */
1120 /******************************COPYRIGHT NOTICE*******************************/