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