7 #include "io_lib_header.h"
8 #include "util_lib_header.h"
9 #include "define_header.h"
12 #define DEFAULT_COLOR -1
16 Sequence * cw_read_sequences ( char *seq_name)
29 get_sequence ( seq_name, &nseq, &seq, &name, &len, &min_len, &max_len);
31 S=declare_sequence ( min_len, max_len, nseq);
32 for ( a=0; a< nseq; a++)sprintf ( S->file[a], "%s", seq_name);
34 for ( a=0; a<S->nseq; a++)
37 sprintf ( S->name[a],"%s", name[a]);
39 sprintf ( S->seq[a], "%s", seq[a]);
45 S=get_sequence_type ( S);
48 char * get_string_type (char *S)
51 int protein=0, dna=0,rna=0, tot=0;
64 sprintf ( type, "UNKNOWN");
72 protein+=( is_aa (S[a]) && !is_dna(S[a]));
73 dna+= ( is_dna(S[a]));
74 rna+= ( is_rna(S[a]));
79 protein=(protein*100)/tot;
83 if ( l<20 && warning==0)
85 /*add_warning ( stderr, "WARNING: short sequences, use -type=DNA or PROTEIN");*/
88 if ( l<20 && ltype && ltype[0])
92 sprintf ( type, "%s", ltype);
96 sprintf ( type, "PROTEIN");
99 else if ( dna>98 && rna>0)sprintf ( type, "RNA");
100 else if ( dna>98)sprintf ( type, "DNA");
101 else sprintf ( type, "PROTEIN");
103 sprintf ( ltype, "%s", type);
107 Alignment* get_aln_type (Alignment *A)
111 if ( A->S && !(A->S)->type)(A->S)->type=vcalloc (30, sizeof (char));
113 if ( A->S && (A->S)->type[0]!='\0')
117 else if (A->S!=NULL && (A->S)->type[0]=='\0')
119 A->S=get_sequence_type (A->S);
124 A->S=get_sequence_type(A->S);
133 return set_mode (UNSET, NULL);
135 char *store_mode (char *val)
137 return set_mode (SET, val);
139 char *retrieve_mode ()
141 return set_mode (GET,NULL);
143 char *set_mode (int mode, char *val)
145 static char type[100];
148 if (!val)printf_exit (EXIT_FAILURE, stderr, "Error: programme mode unset in io_func.c:set_seq_type");
149 sprintf ( type,"%s", val);
155 else if ( mode==UNSET)
161 printf_exit (EXIT_FAILURE, stderr, "Error: unknown mode in function io_func.c:set_seq_type, use SET, GET or UNSET");
165 /************************************************************/
169 char *unset_seq_type ()
171 return set_seq_type (UNSET, NULL);
173 char *store_seq_type (char *val)
175 return set_seq_type (SET, val);
177 char *retrieve_seq_type ()
179 return set_seq_type (GET,NULL);
181 char *set_seq_type (int mode, char *val)
183 static char type[100];
186 if (!val)printf_exit (EXIT_FAILURE, stderr, "Error: sequence type unset in io_func.c:set_seq_type");
187 sprintf ( type,"%s", val);
193 else if ( mode==UNSET)
199 printf_exit (EXIT_FAILURE, stderr, "Error: unknown mode in function io_func.c:set_seq_type, use SET, GET or UNSET");
203 char * get_array_type (int n, char **seq)
207 buf2=vcalloc ( 100, sizeof (char));
210 for ( tot=0,a=0; a<n; a++)tot+=strlen (seq[a]);
211 buf=vcalloc (tot+1, sizeof (char));
212 for ( a=0; a<n; a++)strcat (buf, seq[a]);
213 sprintf ( buf2, "%s", get_string_type(buf));
217 Sequence *get_sequence_type (Sequence *S)
219 if ( !S) return NULL;
220 else sprintf ( S->type, "%s", get_array_type (S->nseq, S->seq));
225 void get_sequence (char *seq_file,int *NSEQ, char ***SEQ, char ***SN, int **sl, int *min, int *max)
234 nseq=NSEQ[0]= readseqs ( seq_file, SEQ, SN, &SL);
235 sl[0]=vcalloc ( nseq, sizeof (int));
238 min_len= max_len= (SL)[0][0];
239 for ( a=0; a<NSEQ[0]; a++)
242 for ( b=0; b<(SL)[a][0]; b++)
243 (SEQ[0])[a][b]=tolower ((SEQ[0])[a][b]);
245 for ( a=1; a<NSEQ[0]; a++)
247 min_len= ( min_len > (SL)[a][0])?(SL)[a][0]:min_len;
248 max_len= ( max_len < (SL)[a][0])?(SL)[a][0]:max_len;
254 int ** get_matrix ( char *name, char *format)
257 if ( strm ( "blast", format))return read_blast_matrix ( name);
258 else if ( strm ( "clustalw", format))return read_matrice(name);
261 fprintf ( stderr, "\nError:\nUnknowm Format %s for Matrix %s[FATAL]", format, name);
262 myexit (EXIT_FAILURE);
266 void display_matrix (int **mat);
267 int ** read_matrice (char *mat_name_in)
278 AA=vcalloc (256, sizeof (char));
279 sprintf (AA, "abcdefghiklmnpqrstvwxyz");
285 if ( strm2 (mat_name_in, "pam", "PAM"))sprintf ( mat_name, "pam250mt");
286 else if (strm2 (mat_name_in, "blosum", "BLOSUM"))sprintf ( mat_name, "blosum62mt");
287 else if (strm3 (mat_name_in, "id", "ID", "idmat"))sprintf ( mat_name, "idmat");
288 else sprintf ( mat_name, "%s", mat_name_in);
290 /*Read Header Matrices*/
291 if (strm(mat_name, "pam250mt"))vector=pam250mt;
292 else if (strm(mat_name, "idmat"))vector=idmat;
293 else if (strm(mat_name, "dna_idmat"))vector=idmat;
294 else if (strm(mat_name, "est_idmat"))vector=est_idmat;
295 else if (strm(mat_name, "md_350mt"))vector=md_350mt;
296 else if (strm(mat_name, "md_250mt"))vector=md_250mt;
297 else if (strm(mat_name, "md_120mt"))vector=md_120mt;
298 else if (strm(mat_name, "md_40mt" ))vector= md_40mt;
299 else if (strm(mat_name, "pam350mt" ))vector=pam350mt;
300 else if (strm(mat_name, "pam160mt" ))vector=pam160mt;
301 else if (strm(mat_name, "pam120mt" ))vector=pam120mt;
303 else if (strm(mat_name, "blosum80mt" ))vector=blosum80mt;
304 else if (strm(mat_name, "blosum62mt" ))vector=blosum62mt;
305 else if (strm(mat_name, "exon2mt" ))vector=blosum62mt;
306 else if (strm(mat_name, "blosum62mt3" ))vector=blosum62mt3;
308 else if (strm(mat_name, "blosum62mt2" ))vector=blosum62mt2;
309 else if (strm(mat_name, "blosum55mt" ))vector=blosum55mt;
310 else if (strm(mat_name, "blosum50mt" ))vector=blosum50mt;
311 else if (strm(mat_name, "blosum45mt" ))vector=blosum45mt;
313 else if (strm(mat_name, "blosum40mt" ))vector=blosum40mt;
314 else if (strm(mat_name, "blosum30mt" ))vector=blosum30mt;
315 else if (strm(mat_name, "beta_mat" ))vector=beta_mat;
316 else if (strm(mat_name, "alpha_mat" ))vector=alpha_mat;
317 else if (strm(mat_name, "coil_mat" ))vector=coil_mat;
319 else if (strm(mat_name, "rblosum80mt" ))vector=rblosum80mt;
320 else if (strm(mat_name, "rblosum62mt" ))vector=rblosum62mt;
321 else if (strm(mat_name, "rblosum30mt" ))vector=rblosum30mt;
323 else if (strm(mat_name, "rpam250mt" ))vector=rpam250mt;
324 else if (strm(mat_name, "rpam350mt" ))vector=rpam350mt;
325 else if (strm(mat_name, "rpam160mt" ))vector=rpam160mt;
326 else if (strm(mat_name, "rpam120mt" ))vector=rpam120mt;
328 else if (strm(mat_name, "tmpam250mt" ))vector=tmpam250mt;
329 else if (strm(mat_name, "rtmpam250mt" ))vector=rtmpam250mt;
331 else if (strm(mat_name, "rbeta_mat" ))vector=rbeta_mat;
332 else if (strm(mat_name, "ralpha_mat" ))vector=ralpha_mat;
333 else if (strm(mat_name, "rcoil_mat" ))vector=rcoil_mat;
334 else if (strm (mat_name, "jtttm250mt"))vector=jtttm250mt;
336 else if (strm (mat_name, "promoter_tf1"))vector=promoter_tf1;
337 else if (strm (mat_name, "blosumR"))vector=blosumR;
342 matrice=declare_int ( 256, 256);
347 matrice[a][b]=matrice[b][a]=(vector[(a*a+a)/2+b]);
352 /*Hard coded Matrices*/
354 else if ( strm (mat_name, "exon_mt"))
356 matrice=declare_int ( 256, 256);
357 sprintf (AA, "bojx");
359 for ( a=0; a<l-1; a++)
362 for ( b=a+1; b< l-2; b++)
364 matrice[a][b]=matrice[b][a]=5;
369 else if ( strm ( mat_name, "tdamat"))
372 matrice=declare_int ( 256, 256);
373 sprintf ( AA, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
376 for ( y=0; y<l; y++)matrice[x][y]=-10;
377 for ( x=0; x<l; x++) {matrice[x][x]=0; matrice[x][GAP_CODE]=-3;}
381 else if ( check_file_exists(mat_name) && is_blast_matrix (mat_name))
384 matrice=read_blast_matrix ( mat_name);
387 else if ( check_file_exists(mat_name) && is_pavie_matrix (mat_name))
390 matrice=read_pavie_matrix ( mat_name);
394 else if ( check_file_exists(mat_name) && is_clustalw_matrix (mat_name))
397 fp=vfopen ( mat_name, "r");
398 while ( (c=fgetc (fp))!='$' && c!=EOF);
399 if ( c==EOF){vfclose (fp);return NULL;};
401 matrice=declare_int ( 256, 256);
405 for ( b=0; b<=a; b++)
406 if (fscanf ( fp, "%d,", &matrice[a][b])==0){vfclose (fp);free_int (matrice, -1);return NULL;};
414 matrix2=declare_int ( 256, 256);
419 matrix2[toupper(AA[b])-'A'][toupper(AA[c])-'A']=matrice[b][c];
420 matrix2[toupper(AA[b])-'A'][tolower(AA[c])-'A']=matrice[b][c];
421 matrix2[tolower(AA[b])-'A'][toupper(AA[c])-'A']=matrice[b][c];
422 matrix2[tolower(AA[b])-'A'][tolower(AA[c])-'A']=matrice[b][c];
424 if ( strm ( "exon2mt", mat_name))
427 int v=(getenv ("EXONVALUE_4_TCOFFEE"))?atoi("EXONVALUE_4_TCOFFEE"):100;
429 for (a=0; a<strlen (EE); a++)
431 matrix2[toupper(EE[a])-'A'][toupper(EE[a])-'A']=v;
432 matrix2[tolower(EE[a])-'A'][toupper(EE[a])-'A']=v;
433 matrix2[toupper(EE[a])-'A'][tolower(EE[a])-'A']=v;
434 matrix2[tolower(EE[a])-'A'][tolower(EE[a])-'A']=v;
438 /*Correct for RNA: Add the U cost*/
442 matrix2['U'-'A'][toupper(AA[b])-'A']=matrix2['T'-'A'][toupper(AA[b])-'A'];
443 matrix2[toupper(AA[b])-'A']['U'-'A']=matrix2[toupper(AA[b])-'A']['T'-'A'];
444 matrix2['U'-'A'][toupper(AA[b])-'A']=matrix2['t'-'A'][tolower(AA[b])-'A'];
445 matrix2[tolower(AA[b])-'A']['u'-'A']=matrix2[tolower(AA[b])-'A']['t'-'A'];
448 matrix2['U'-'A']['U'-'A']=matrix2['T'-'A']['T'-'A'];
449 matrix2['u'-'A']['U'-'A']=matrix2['t'-'A']['T'-'A'];
450 matrix2['U'-'A']['u'-'A']=matrix2['T'-'A']['t'-'A'];
451 matrix2['u'-'A']['u'-'A']=matrix2['t'-'A']['t'-'A'];
453 free_int (matrice, -1);
458 void display_matrix (int **mat)
462 for ( a=0; a< 26; a++)
464 fprintf ( stderr, "\n%c ", a+'a');
465 for ( b=0; b< 26; b++)
466 fprintf ( stderr, " %2d", mat[a][b]);
470 int **neg_matrix2pos_matrix ( int **matrix)
473 char AA[]="abcdefghiklmnpqrstvwxyzABCDEFGHIKLMNPQRSTVWXYZ";
475 min=max=matrix[AA[0]-'A'][AA[0]-'A'];
479 min=(matrix[AA[b]-'A'][AA[c]-'A']<min)?matrix[AA[b]-'A'][AA[c]-'A']:min;
480 max=(matrix[AA[b]-'A'][AA[c]-'A']<max)?matrix[AA[b]-'A'][AA[c]-'A']:max;
482 if (min>0)return matrix;
488 matrix[b][c]=matrix[b][c]-min;
496 /*****************************************************************/
497 void get_rgb_values ( int val, Color *C)
500 /*Colors can be modified, see the definition of
501 COLOR_FILE in prgogrammes_define.h
504 static char **html_code;
505 static float **ps_code;
514 html_code=declare_char(10, 10);
515 ps_code=declare_float (10, 3);
519 sprintf (html_code[n], "#6666FF");
525 sprintf (html_code[n], "#00FF00");
532 sprintf (html_code[n], "#66FF00");
539 sprintf (html_code[n], "#CCFF00");
546 sprintf (html_code[n], "#FFFF00");
553 sprintf (html_code[n], "#FFCC00");
560 sprintf (html_code[n], "#FF9900");
567 sprintf (html_code[n], "#FF6600");
574 sprintf (html_code[n], "#FF3300");
582 sprintf (html_code[n], "#FF2000");
592 if ( check_file_exists(COLOR_FILE))
594 fp=vfopen( COLOR_FILE, "r");
596 while ((c=fgetc(fp))!='*');
597 while ((c=fgetc(fp))!='\n');
600 while ((c=fgetc(fp))!=EOF)
603 if ( fscanf (fp, "%d", &class)==0)break;
604 fscanf (fp, "%s %f %f %f", html_code[class], &ps_code[class][0], &ps_code[class][1],&ps_code[class][2]);
605 while ((c=fgetc(fp))!='\n' && c!=EOF);
606 if ( c==EOF)ungetc(c, fp);
622 sprintf ( C->html_color_class, "value%d",val);
625 if (val<=9 && val>=0)
628 sprintf ( C->html_color, "%s", html_code[val]);
629 r[0]=ps_code[val][0];
630 g[0]=ps_code[val][1];
631 b[0]=ps_code[val][2];
634 else if (val==DEFAULT_COLOR || val==NO_COLOR_RESIDUE || val==NO_COLOR_GAP || (val>'A' && val<'z'))
636 C->html_color[0]='\0';
637 sprintf ( C->html_color_class, "valuedefault");
643 else if (val==GAP_COLOR)
645 C->html_color[0]='\0';
646 sprintf ( C->html_color_class, "valuegap");
651 else if (val==INK_COLOR )
653 sprintf ( C->html_color, "000000");
654 sprintf ( C->html_color_class, "valueink");
664 // void output_tm_mark(FILE_format *fps)
666 // Color *box_c=vcalloc ( 1, sizeof (Color));
668 // get_rgb_values_format (INK_COLOR, (ink =vcalloc ( 1, sizeof (Color))));
670 // get_rgb_values_format ( 5, box_c);
671 // fps=print_format_char ( " IN ", box_c,ink,fps);
673 // get_rgb_values_format ( 9, box_c);
674 // fps=print_format_char ( " HEL ", box_c,ink,fps);
676 // get_rgb_values_format ( 0, box_c);
677 // fps=print_format_char ( "OUT", box_c,ink,fps);
680 int output_color_format ( Alignment *B,Alignment *Sin,char *name, \
681 FILE_format *(*vfopen_format) ( char *),\
682 FILE_format *(*print_format_string) ( char * ,Color *, Color *, FILE_format*),\
683 FILE_format *(*print_format_char) ( int ,Color *, Color *, FILE_format*),\
684 void (*get_rgb_values_format) ( int ,Color *),\
685 FILE_format* (*vfclose_format) ( FILE_format *))
695 static FILE_format *fps;
702 S=copy_aln (B, NULL);
704 buf2=vcalloc (Sin->len_aln+1, sizeof (char));
705 buf3=vcalloc ( B->len_aln+1, sizeof (char));
706 for ( a=0; a<B->nseq; a++)
710 i=name_is_in_list ( B->name[a], Sin->name, Sin->nseq, -1);
712 sprintf (buf2, "%s", Sin->seq_al[i]);ungap(buf2);
713 sprintf (buf3, "%s", S->seq_al[a]);ungap(buf3);
715 if ( strlen (buf2) !=strlen(buf3))
718 fprintf ( stderr, "\nERROR: Incompatible cache ON sEQ: %s\n", S->name[a]);
719 fprintf ( stderr, "\n%s\n%s", buf2, buf3);
720 fprintf ( stderr, "\n\n%s\n%s", Sin->seq_al[i],S->seq_al[a]); exit (EXIT_FAILURE);
723 for (n=0,b=0;b<B->len_aln; b++)
728 S->seq_al[a][b]=buf2[n++];
736 box_c=vcalloc ( 1, sizeof (Color));
737 get_rgb_values_format (DEFAULT_COLOR, (white=vcalloc ( 1, sizeof (Color))));
738 get_rgb_values_format (INK_COLOR, (ink =vcalloc ( 1, sizeof (Color))));
740 n_residues=vcalloc ( B->nseq+1, sizeof (int));
741 for ( a=0; a<B->nseq; a++)n_residues[a]=B->order[a][1];
743 fps=vfopen_format( name);
746 buf=vcalloc (10000, sizeof (int));
751 for ( a=0; a< B->nseq; a++)
752 {if ( strlen (B->name[a])>max_len)
753 max_len= strlen ( (B->name[a]));
756 if ( max_len>max_name_len)max_len=max_name_len;
758 sprintf (buf, "\n%s, %s(%s)\n%s\n",PROGRAM,VERSION,DATE, AUTHOR);
759 fps=print_format_string ( buf,white, ink, fps);
761 if(B->output_tm == 1)
763 fps=print_format_char ( '\n', white, ink, fps);
764 get_rgb_values_format ( 5, box_c);
765 fps=print_format_string ( " IN ", box_c,ink,fps);
767 get_rgb_values_format ( 9, box_c);
768 fps=print_format_string ( " HEL ", box_c,ink,fps);
770 get_rgb_values_format ( 0, box_c);
771 fps=print_format_string ( " OUT ", box_c,ink,fps);
774 fps=print_format_string ( "\n\n",white,ink, fps);
777 fps->line=fps->line-fps->line%3;
782 for (a=0; a<B->len_aln; a+=fps->line)
785 if ( (fps->n_line+(B->nseq+4))>fps->max_line_ppage && !((B->nseq+4)>fps->max_line_ppage))
787 fps=print_format_char ( fps->eop,white, ink, fps);
790 for (b=0; b<=B->nseq; b++)
792 sprintf (buf,"%-*.*s ",max_len+2, max_len,(b==B->nseq)?"":S->name[b]);
793 fps=print_format_string ( buf,white, ink, fps);
794 if(B->output_res_num)
796 sprintf (buf, " %4d ", n_residues[b]+1);
797 fps=print_format_string ( buf,white, ink, fps);
800 for (fps->in_seq=1,c=a;c<a+fps->line && c<B->len_aln;c++)
805 get_rgb_values_format (DEFAULT_COLOR,box_c);
806 s=analyse_aln_column ( B, c);
810 n_residues[b]+=!is_gap(B->seq_al[b][c]);
812 if (!is_gap(s) && S->seq_al[b][c]!=NO_COLOR_RESIDUE )
814 get_rgb_values_format ( S->seq_al[b][c], box_c);
818 get_rgb_values_format (GAP_COLOR, box_c);
821 fps=print_format_char ( s,box_c, ink,fps);
825 if(B->output_res_num)
827 sprintf (buf, " %4d ", n_residues[b]);
828 fps=print_format_string ( buf,white, ink, fps);
831 fps=print_format_char ( '\n', white, ink, fps);
834 fps=print_format_string ( "\n\n",white, ink, fps);
836 fps=print_format_string ( "\n\n\n",white, ink,fps);
839 vfclose_format( fps);
846 int output_reliability_format ( Alignment *B,Alignment *S,char *name, \
847 FILE_format *(*vfopen_format) ( char *),\
848 FILE_format *(*print_format_string) ( char * ,Color *, Color *, FILE_format*),\
849 FILE_format *(*print_format_char) ( int ,Color *, Color *, FILE_format*),\
850 void (*get_rgb_values_format) ( int ,Color *),\
851 FILE_format* (*vfclose_format) ( FILE_format *))
856 static char *buf,*buf2;
858 static FILE_format *fps;
865 box_c=vcalloc ( 1, sizeof (Color));
866 get_rgb_values_format (DEFAULT_COLOR, (white=vcalloc ( 1, sizeof (Color))));
867 get_rgb_values_format (INK_COLOR, (ink =vcalloc ( 1, sizeof (Color))));
869 n_residues=vcalloc ( B->nseq+1, sizeof (int));
870 for ( a=0; a<B->nseq; a++)n_residues[a]=B->order[a][1];
873 fps=vfopen_format( name);
876 buf=vcalloc (10000, sizeof (int));
877 buf2=vcalloc (10000, sizeof (int));
882 for ( a=0; a< B->nseq; a++)
883 {if ( strlen (B->name[a])>max_len)
884 max_len= strlen ( (B->name[a]));
888 if ( vfopen_format==vfopen_ascii)
892 else if ( max_len>max_name_len)max_len=max_name_len;
896 sprintf (buf, "%s, %s(%s)\n%s\nCPU TIME:%d sec.\n%s",PROGRAM,VERSION,DATE, AUTHOR, (B->cpu+get_time())/1000, (S->generic_comment)?S->generic_comment:"");
897 fps=print_format_string ( buf,white, ink, fps);
898 sprintf (buf, "SCORE=%d\n*\n", S->score_aln);
899 fps=print_format_string ( buf,white, ink, fps);
901 sprintf ( buf2, " BAD AVG GOOD");
903 get_rgb_values_format ( DEFAULT_COLOR, box_c);
904 fps=print_format_char ( buf2[0],box_c, ink, fps);
905 for ( a=1; a<l-1; a++)
907 get_rgb_values_format ( MIN(9,a-1), box_c);
908 fps=print_format_char ( buf2[a],box_c,ink,fps);
910 fps=print_format_char ( buf2[a], box_c, ink, fps);
913 fps=print_format_string ( "\n*\n",white,ink, fps);
915 for ( a=0;S->score_seq && a< B->nseq; a++)
917 get_rgb_values_format (S->score_seq[a]/10, box_c);
918 sprintf ( buf, "%-*.*s ", max_len+2,max_len, S->name[a]);
919 fps=print_format_string ( buf,box_c, ink,fps);
920 sprintf ( buf, ": %3d\n", S->score_seq[a]);
921 fps=print_format_string ( buf,white, ink,fps);
923 //Print the Consensus score
924 get_rgb_values_format (S->score_aln/10, box_c);
925 sprintf ( buf, "%-*.*s ", max_len+2,max_len, S->name[S->nseq]);
926 fps=print_format_string ( buf,box_c, ink,fps);
927 sprintf ( buf, ": %3d\n", S->score_aln);
928 fps=print_format_string ( buf,white, ink,fps);
930 fps=print_format_string ( "\n",white, ink,fps);
935 fps->line=fps->line-(fps->line%3);
937 for (a=0; a<B->len_aln; a+=fps->line)
940 if ( (fps->n_line+(B->nseq+4))>fps->max_line_ppage && !((B->nseq+4)>fps->max_line_ppage))
942 fps=print_format_char ( fps->eop,white, ink, fps);
945 for (b=0; b<=S->nseq; b++)
947 if ( b==S->nseq && print_format_string !=print_ascii_string) fps=print_format_string ( "\n",white, ink, fps);
948 sprintf (buf,"%-*.*s ",max_len+2,max_len,S->name[b]);
949 fps=print_format_string ( buf,white, ink, fps);
950 if(B->output_res_num)
952 sprintf (buf, " %4d ", n_residues[b]+1);
953 fps=print_format_string ( buf,white, ink, fps);
956 for (fps->in_seq=1,c=a;c<a+fps->line && c<B->len_aln;c++)
965 if ( s>='0' && s<='9')s-='0';
966 get_rgb_values_format (s,box_c);
968 else get_rgb_values_format (DEFAULT_COLOR,box_c);
970 s=analyse_aln_column ( B, c);
974 n_residues[b]+=!is_gap(B->seq_al[b][c]);
975 //s=toupper(B->seq_al[b][c]);
977 if (!is_gap(s) && S->seq_al[b][c]!=NO_COLOR_RESIDUE )
979 get_rgb_values_format ( S->seq_al[b][c], box_c);
984 get_rgb_values_format (GAP_COLOR, box_c);
989 fps=print_format_char ( s,box_c, ink,fps);
993 if(B->output_res_num)
995 sprintf (buf, " %4d ",n_residues[b]);
996 fps=print_format_string ( buf,white, ink, fps);
999 fps=print_format_char ( '\n', white, ink, fps);
1002 fps=print_format_string ( "\n\n",white, ink, fps);
1004 fps=print_format_string ( "\n\n\n",white, ink,fps);
1005 vfclose_format( fps);
1011 /*****************************************************************************/
1014 /*****************************************************************************/
1015 int output_color_pdf ( Alignment *B,Alignment *S, char *name)
1018 char command[LONG_STRING];
1022 fprintf (stderr, "\nPDF FORMAT IS NOT SUPPORTED: INSTALL THE PROGRAM PS2PDF\n");
1023 myexit (EXIT_FAILURE);
1025 tmp_name=vtmpnam(NULL);
1027 output_color_ps (B, S, tmp_name);
1028 sprintf ( command, "%s %s %s", PS2PDF, tmp_name, name);
1029 my_system ( command);
1030 vremove ( tmp_name);
1036 int output_reliability_pdf ( Alignment *B,Alignment *S, char *name)
1039 char command[LONG_STRING];
1044 fprintf (stderr, "\nPDF FORMAT IS NOT SUPPORTED: INSTALL THE PROGRAM PS2PDF\n");
1045 myexit (EXIT_FAILURE);
1047 tmp_name=vtmpnam(NULL);
1049 output_reliability_ps (B, S, tmp_name);
1050 sprintf ( command, "%s %s %s", PS2PDF, tmp_name, name);
1051 my_system ( command);
1052 vremove ( tmp_name);
1058 /*****************************************************************************/
1059 /* POST SCRIPT FUNCTIONS */
1061 /*****************************************************************************/
1062 int output_color_ps ( Alignment *B,Alignment *S, char *name)
1064 output_color_format (B, S, name, vfopen_ps,print_ps_string,print_ps_char,get_rgb_values_ps, vfclose_ps);
1067 int output_reliability_ps ( Alignment *B,Alignment *S, char *name)
1069 output_reliability_format (B, S, name, vfopen_ps,print_ps_string,print_ps_char,get_rgb_values_ps, vfclose_ps);
1072 FILE_format *print_ps_string( char *s, Color *box, Color *ink, FILE_format *fps)
1079 for ( a=0; a< l; a++)
1081 fps=print_ps_char (s[a], box, ink, fps);
1087 FILE_format * print_ps_char ( int c, Color *box, Color *ink, FILE_format *f)
1096 if ( c=='(' || c==')')return f;
1097 else if (c!='\n' && c!=f->eop)
1099 fprintf(f->fp,"%d %d moveto\n", f->x,f->y);
1100 fprintf(f->fp,"0 %d rlineto\n%d 0 rlineto\n0 -%d rlineto\nclosepath\n",ch,cw,ch );
1101 fprintf(f->fp,"%3.1f %3.1f %3.1f setrgbcolor\nfill\n%3.1f %3.1f %3.1f setrgbcolor\n", box->r,box->g,box->b, ink->r, ink->g, ink->b);
1102 fprintf(f->fp,"%d %d moveto\n(%c) show\n", f->x+1,f->y+3, c);
1109 if ( f->n_line==f->max_line_ppage || c==f->eop)
1115 fprintf(f->fp,"showpage\n");
1117 fprintf ( f->fp, "%c%cPage: %d %d\n",'%', '%', f->n_pages, f->n_pages);
1127 void get_rgb_values_ps ( int val, Color *C)
1129 get_rgb_values ( val, C);
1134 FILE_format* vfopen_ps ( char *name)
1138 fps=vcalloc ( 1, sizeof ( FILE_format));
1140 fps->max_line_ppage=60;
1141 fps->line=get_msa_line_length (0, 0);/*N char per line*/
1146 fps->fp=vfopen ( name, "w");
1147 fprintf(fps->fp,"%%!PS-Adobe-2.0\n/Courier findfont\n%d scalefont\nsetfont\n",fps->font);
1148 fprintf(fps->fp, "%%%%Pages: (atend)\n");
1149 fprintf(fps->fp,"newpath\n");
1151 fprintf (fps->fp, "%%%%Page: %d %d\n", fps->n_pages, fps->n_pages);
1152 fprintf (fps->fp,"%d %d translate\n",fps->x0, fps->y0);
1156 FILE_format* vfclose_ps ( FILE_format *fps)
1159 fprintf(fps->fp,"showpage\n");
1160 fprintf ( fps->fp, "%%%%Pages: %d\n", fps->n_pages);
1161 fprintf(fps->fp,"%%%%EOF");
1162 fprintf(fps->fp,"%%%%\n");
1167 /*****************************************************************************/
1168 /* HTML FUNCTIONS */
1170 /*****************************************************************************/
1172 /*****************************************************************************/
1174 /*****************************************************************************/
1175 void output_hit_matrix(char *fileName, float **ffpHitScoreMatrix, int nl)
1180 fp=vfopen(fileName, "w");
1181 for(i = 0; i < nl; i++)
1183 for(j = 0; j < i; j++)
1184 fprintf(fp, "%6.2f ", ffpHitScoreMatrix[j][i-j]);
1185 for(j = i; j < nl; j++)
1186 fprintf(fp, "%6.2f ", ffpHitScoreMatrix[i][j-i]);
1191 int output_hit_color_format (Alignment *B, float **ffPScoreTable, int nl, char *name, \
1192 FILE_format *(*vfopen_format) ( char *),\
1193 FILE_format *(*print_format_string) ( char * ,Color *, Color *, FILE_format*),\
1194 FILE_format *(*print_format_char) ( int ,Color *, Color *, FILE_format*),\
1195 void (*get_rgb_values_format) ( int ,Color *),\
1196 FILE_format* (*vfclose_format) ( FILE_format *));
1197 int output_hit_color_html (Alignment *B, float **ffPScoreTable, int nl, char *name)
1199 output_hit_color_format (B, ffPScoreTable, nl, name, vfopen_html,print_html_string,print_html_char,get_rgb_values_html, vfclose_html);
1203 int output_hit_color_format (Alignment *B, float **ffPScoreTable, int nl, char *name, \
1204 FILE_format *(*vfopen_format) ( char *),\
1205 FILE_format *(*print_format_string) ( char * ,Color *, Color *, FILE_format*),\
1206 FILE_format *(*print_format_char) ( int ,Color *, Color *, FILE_format*),\
1207 void (*get_rgb_values_format) ( int ,Color *),\
1208 FILE_format* (*vfclose_format) ( FILE_format *))
1211 int max_name_len=15;
1215 static FILE_format *fps;
1220 box_c=vcalloc ( 1, sizeof (Color));
1221 get_rgb_values_format (DEFAULT_COLOR, (white=vcalloc ( 1, sizeof (Color))));
1222 get_rgb_values_format (INK_COLOR, (ink =vcalloc ( 1, sizeof (Color))));
1226 for ( a=0; a< B->nseq; a++)
1228 if ( strlen (B->name[a])>max_len)
1229 max_len= strlen ( (B->name[a]));
1232 if ( max_len>max_name_len)max_len=max_name_len;
1235 buf=vcalloc (10000, sizeof (int));
1236 int iEmptyChr = 32; //SPACE ASCIICODE
1238 fps=vfopen_format(name);
1239 for (a=0; a < nl; a++)
1241 sprintf (buf,"%*d ", max_len+2, a);
1242 fps=print_format_string ( buf,white, ink, fps);
1243 for(b = 0; b < a; b++)
1245 iColorValue = (int)((ffPScoreTable[b][a-b]*9)/100);
1246 get_rgb_values_format (iColorValue, box_c);
1247 fps=print_format_char (iEmptyChr,box_c, ink,fps);
1249 for(b = a; b < nl; b++)
1251 iColorValue = (int)((ffPScoreTable[a][b-a]*9)/100);
1252 get_rgb_values_format (iColorValue, box_c);
1253 fps=print_format_char (iEmptyChr,box_c, ink,fps);
1255 fps=print_format_char ('\n', white, ink, fps);
1257 vfclose_format(fps);
1263 /*****************************************************************************/
1265 int output_color_html ( Alignment *B,Alignment *S, char *name)
1267 output_color_format (B, S, name, vfopen_html,print_html_string,print_html_char,get_rgb_values_html, vfclose_html);
1270 int output_reliability_html ( Alignment *B,Alignment *S, char *name)
1272 output_reliability_format (B, S, name, vfopen_html,print_html_string,print_html_char,get_rgb_values_html, vfclose_html);
1275 FILE_format *print_html_string( char *s, Color *box, Color *ink, FILE_format *fhtml)
1282 for ( a=0; a< l; a++)
1284 fhtml=print_html_char (s[a], box, ink, fhtml);
1286 fhtml=print_html_char (CLOSE_HTML_SPAN,NULL,NULL,fhtml);
1291 FILE_format * print_html_char ( int c, Color *box, Color *ink, FILE_format *f)
1293 char html_color[100];
1294 int in_span, new_color;
1298 if (c==CLOSE_HTML_SPAN)
1300 if (f->in_html_span)fprintf ( f->fp, "</span>");
1306 in_span=f->in_html_span;
1307 new_color=1-(strm (box->html_color_class, f->previous_html_color));
1311 sprintf (f->previous_html_color, "%s", box->html_color_class);
1312 sprintf ( html_color, "class=%s", box->html_color_class);
1315 if ( c!=' ')sprintf ( string, "%c", c);
1316 else sprintf ( string, " ");
1318 if ( !in_span && c!='\n' && c!=f->eop)
1320 fprintf ( f->fp, "<span %s>%s",html_color,string );
1323 else if (in_span && !new_color && c!='\n' && c!=f->eop)
1326 fprintf ( f->fp, "%s",string);
1328 else if (in_span && new_color && c!='\n' && c!=f->eop)
1330 fprintf ( f->fp, "</span><span %s>%s",html_color,string);
1334 if ( f->in_html_span)fprintf ( f->fp, "</span>");
1335 fprintf ( f->fp, "<br>");
1336 sprintf ( f->previous_html_color, "no_color_set");
1348 void get_rgb_values_html ( int val, Color *C)
1350 get_rgb_values ( val, C);
1353 FILE_format* vfopen_html ( char *name)
1359 color=vcalloc ( 1, sizeof (Color));
1361 fhtml=vcalloc ( 1, sizeof ( FILE_format));
1363 fhtml->max_line_ppage=100000;
1364 fhtml->line=get_msa_line_length (0, 0);/*N char per line*/
1368 sprintf ( fhtml->previous_html_color, "no_value_set");
1369 fhtml->fp=vfopen ( name, "w");
1371 fprintf(fhtml->fp,"<html>\n<style>\n");
1373 fprintf(fhtml->fp,"SPAN { font-family: courier new, courier-new, courier, monospace; font-weight: bold; font-size: %dpt;}\n", fhtml->font);
1374 fprintf(fhtml->fp,"SPAN { line-height:100%%}\n");
1375 fprintf(fhtml->fp,"SPAN { white-space: pre}\n");
1377 for ( a=0; a< 10; a++)
1379 get_rgb_values_html ( a, color);
1380 if ( !strm (color->html_color, ""))fprintf (fhtml->fp, "SPAN.%s {background: %s}\n", color->html_color_class, color->html_color );
1381 else fprintf (fhtml->fp, "SPAN.%s {}\n", color->html_color_class );
1383 get_rgb_values_html (DEFAULT_COLOR, color);
1384 if ( !strm (color->html_color, ""))fprintf (fhtml->fp, "SPAN.%s {background: %s}\n", color->html_color_class, color->html_color );
1385 else fprintf (fhtml->fp, "SPAN.%s {}\n", color->html_color_class );
1387 get_rgb_values_html (GAP_COLOR, color);
1388 if ( !strm (color->html_color, ""))fprintf (fhtml->fp, "SPAN.%s {background: %s}\n", color->html_color_class, color->html_color );
1389 else fprintf (fhtml->fp, "SPAN.%s {}\n", color->html_color_class );
1391 get_rgb_values_html (INK_COLOR, color);
1392 if ( !strm (color->html_color, ""))fprintf (fhtml->fp, "SPAN.%s {background: %s}\n", color->html_color_class, color->html_color );
1393 else fprintf (fhtml->fp, "SPAN.%s {}\n", color->html_color_class );
1397 fprintf(fhtml->fp,"</style>");
1398 fprintf(fhtml->fp,"<body>");
1402 FILE_format* vfclose_html ( FILE_format *fhtml)
1404 if ( fhtml->in_html_span)fprintf(fhtml->fp,"</span>");
1405 fprintf(fhtml->fp,"</body></html>\n");
1406 vfclose ( fhtml->fp);
1410 /*****************************************************************************/
1411 /* ascii FUNCTIONS */
1413 /*****************************************************************************/
1414 int output_color_ascii ( Alignment *B,Alignment *S, char *name)
1416 output_color_format (B, S, name, vfopen_ascii,print_ascii_string,print_ascii_char,get_rgb_values_ascii, vfclose_ascii);
1419 int output_reliability_ascii ( Alignment *B,Alignment *S, char *name)
1421 output_reliability_format (B, S, name, vfopen_ascii,print_ascii_string,print_ascii_char,get_rgb_values_ascii, vfclose_ascii);
1425 FILE_format *print_ascii_string( char *s, Color *box, Color *ink, FILE_format *fascii)
1432 for ( a=0; a< l; a++)
1434 fascii=print_ascii_char (s[a], box, ink, fascii);
1440 FILE_format * print_ascii_char ( int c, Color *box, Color *ink, FILE_format *f)
1442 if (box->ascii_value>=0 && f->in_seq)fprintf ( f->fp, "%c", box->ascii_value);
1443 else fprintf ( f->fp, "%c",c);
1448 void get_rgb_values_ascii ( int val, Color *C)
1451 if ( val==NO_COLOR_RESIDUE)C->ascii_value='-';
1452 else if ( val==NO_COLOR_GAP)C->ascii_value='*';
1453 else if ( val>9)C->ascii_value='#';
1454 else if ( val>=0 && val<=9) C->ascii_value=val+'0';
1455 else C->ascii_value=val;
1458 FILE_format* vfopen_ascii ( char *name)
1461 fascii=vcalloc ( 1, sizeof ( FILE_format));
1463 fascii->max_line_ppage=100000;
1464 fascii->line=get_msa_line_length (0,0);/*N char per line*/
1468 fascii->fp=vfopen ( name, "w");
1473 FILE_format* vfclose_ascii ( FILE_format *fascii)
1475 vfclose ( fascii->fp);
1481 /*****************************************************************************/
1482 /* seq_score output */
1484 /*****************************************************************************/
1486 int output_seq_reliability_ascii ( Alignment *B,Alignment *S, char *name)
1491 for ( a=0; a< B->nseq; a++)
1492 {if ( strlen (B->name[a])>max_len)
1493 max_len= strlen ( (B->name[a]));
1496 fp=vfopen ( name, "w");
1497 fprintf ( fp, "ALN_SCORE %d\n", S->score_aln);
1498 for ( a=0; a< S->nseq; a++)fprintf (fp, "SEQ_SCORE %*.*s %3d\n", max_len+2,max_len,S->name[a],S->score_seq[a]);
1504 /******************************COPYRIGHT NOTICE*******************************/
1505 /*© Centro de Regulacio Genomica */
1507 /*Cedric Notredame */
1508 /*Fri Feb 18 08:27:45 CET 2011 - Revision 596. */
1509 /*All rights reserved.*/
1510 /*This file is part of T-COFFEE.*/
1512 /* T-COFFEE is free software; you can redistribute it and/or modify*/
1513 /* it under the terms of the GNU General Public License as published by*/
1514 /* the Free Software Foundation; either version 2 of the License, or*/
1515 /* (at your option) any later version.*/
1517 /* T-COFFEE is distributed in the hope that it will be useful,*/
1518 /* but WITHOUT ANY WARRANTY; without even the implied warranty of*/
1519 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the*/
1520 /* GNU General Public License for more details.*/
1522 /* You should have received a copy of the GNU General Public License*/
1523 /* along with Foobar; if not, write to the Free Software*/
1524 /* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA*/
1525 /*............................................... |*/
1526 /* If you need some more information*/
1527 /* cedric.notredame@europe.com*/
1528 /*............................................... |*/
1532 /******************************COPYRIGHT NOTICE*******************************/