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>10)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)
271 char AA[]="abcdefghiklmnpqrstvwxyz";
283 if ( strm2 (mat_name_in, "pam", "PAM"))sprintf ( mat_name, "pam250mt");
284 else if (strm2 (mat_name_in, "blosum", "BLOSUM"))sprintf ( mat_name, "blosum62mt");
285 else if (strm3 (mat_name_in, "id", "ID", "idmat"))sprintf ( mat_name, "idmat");
286 else sprintf ( mat_name, "%s", mat_name_in);
288 /*Read Header Matrices*/
289 if (strm(mat_name, "pam250mt"))vector=pam250mt;
290 else if (strm(mat_name, "idmat"))vector=idmat;
291 else if (strm(mat_name, "dna_idmat"))vector=idmat;
292 else if (strm(mat_name, "est_idmat"))vector=est_idmat;
293 else if (strm(mat_name, "md_350mt"))vector=md_350mt;
294 else if (strm(mat_name, "md_250mt"))vector=md_250mt;
295 else if (strm(mat_name, "md_120mt"))vector=md_120mt;
296 else if (strm(mat_name, "md_40mt" ))vector= md_40mt;
297 else if (strm(mat_name, "pam350mt" ))vector=pam350mt;
298 else if (strm(mat_name, "pam160mt" ))vector=pam160mt;
299 else if (strm(mat_name, "pam120mt" ))vector=pam120mt;
301 else if (strm(mat_name, "blosum80mt" ))vector=blosum80mt;
302 else if (strm(mat_name, "blosum62mt" ))vector=blosum62mt;
303 else if (strm(mat_name, "exon2mt" ))vector=blosum62mt;
304 else if (strm(mat_name, "blosum62mt3" ))vector=blosum62mt3;
306 else if (strm(mat_name, "blosum62mt2" ))vector=blosum62mt2;
307 else if (strm(mat_name, "blosum55mt" ))vector=blosum55mt;
308 else if (strm(mat_name, "blosum50mt" ))vector=blosum50mt;
309 else if (strm(mat_name, "blosum45mt" ))vector=blosum45mt;
311 else if (strm(mat_name, "blosum40mt" ))vector=blosum40mt;
312 else if (strm(mat_name, "blosum30mt" ))vector=blosum30mt;
313 else if (strm(mat_name, "beta_mat" ))vector=beta_mat;
314 else if (strm(mat_name, "alpha_mat" ))vector=alpha_mat;
315 else if (strm(mat_name, "coil_mat" ))vector=coil_mat;
317 else if (strm(mat_name, "rblosum80mt" ))vector=rblosum80mt;
318 else if (strm(mat_name, "rblosum62mt" ))vector=rblosum62mt;
319 else if (strm(mat_name, "rblosum30mt" ))vector=rblosum30mt;
321 else if (strm(mat_name, "rpam250mt" ))vector=rpam250mt;
322 else if (strm(mat_name, "rpam350mt" ))vector=rpam350mt;
323 else if (strm(mat_name, "rpam160mt" ))vector=rpam160mt;
324 else if (strm(mat_name, "rpam120mt" ))vector=rpam120mt;
326 else if (strm(mat_name, "tmpam250mt" ))vector=tmpam250mt;
327 else if (strm(mat_name, "rtmpam250mt" ))vector=rtmpam250mt;
329 else if (strm(mat_name, "rbeta_mat" ))vector=rbeta_mat;
330 else if (strm(mat_name, "ralpha_mat" ))vector=ralpha_mat;
331 else if (strm(mat_name, "rcoil_mat" ))vector=rcoil_mat;
332 else if (strm (mat_name, "jtttm250mt"))vector=jtttm250mt;
337 matrice=declare_int ( 256, 256);
342 matrice[a][b]=matrice[b][a]=(vector[(a*a+a)/2+b]);
347 /*Hard coded Matrices*/
349 else if ( strm (mat_name, "exon_mt"))
351 matrice=declare_int ( 256, 256);
352 sprintf (AA, "bojx");
354 for ( a=0; a<l-1; a++)
357 for ( b=a+1; b< l-2; b++)
359 matrice[a][b]=matrice[b][a]=5;
364 else if ( strm ( mat_name, "tdamat"))
367 matrice=declare_int ( 256, 256);
368 sprintf ( AA, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
371 for ( y=0; y<l; y++)matrice[x][y]=-10;
372 for ( x=0; x<l; x++) {matrice[x][x]=0; matrice[x][GAP_CODE]=-3;}
376 else if ( check_file_exists(mat_name) && is_blast_matrix (mat_name))
379 matrice=read_blast_matrix ( mat_name);
382 else if ( check_file_exists(mat_name) && is_pavie_matrix (mat_name))
385 matrice=read_pavie_matrix ( mat_name);
389 else if ( check_file_exists(mat_name) && is_clustalw_matrix (mat_name))
392 fp=vfopen ( mat_name, "r");
393 while ( (c=fgetc (fp))!='$' && c!=EOF);
394 if ( c==EOF){vfclose (fp);return NULL;};
396 matrice=declare_int ( 256, 256);
400 for ( b=0; b<=a; b++)
401 if (fscanf ( fp, "%d,", &matrice[a][b])==0){vfclose (fp);free_int (matrice, -1);return NULL;};
409 matrix2=declare_int ( 256, 256);
414 matrix2[toupper(AA[b])-'A'][toupper(AA[c])-'A']=matrice[b][c];
415 matrix2[toupper(AA[b])-'A'][tolower(AA[c])-'A']=matrice[b][c];
416 matrix2[tolower(AA[b])-'A'][toupper(AA[c])-'A']=matrice[b][c];
417 matrix2[tolower(AA[b])-'A'][tolower(AA[c])-'A']=matrice[b][c];
419 if ( strm ( "exon2mt", mat_name))
422 int v=(getenv ("EXONVALUE_4_TCOFFEE"))?atoi("EXONVALUE_4_TCOFFEE"):100;
424 for (a=0; a<strlen (EE); a++)
426 matrix2[toupper(EE[a])-'A'][toupper(EE[a])-'A']=v;
427 matrix2[tolower(EE[a])-'A'][toupper(EE[a])-'A']=v;
428 matrix2[toupper(EE[a])-'A'][tolower(EE[a])-'A']=v;
429 matrix2[tolower(EE[a])-'A'][tolower(EE[a])-'A']=v;
433 /*Correct for RNA: Add the U cost*/
437 matrix2['U'-'A'][toupper(AA[b])-'A']=matrix2['T'-'A'][toupper(AA[b])-'A'];
438 matrix2[toupper(AA[b])-'A']['U'-'A']=matrix2[toupper(AA[b])-'A']['T'-'A'];
439 matrix2['U'-'A'][toupper(AA[b])-'A']=matrix2['t'-'A'][tolower(AA[b])-'A'];
440 matrix2[tolower(AA[b])-'A']['u'-'A']=matrix2[tolower(AA[b])-'A']['t'-'A'];
443 matrix2['U'-'A']['U'-'A']=matrix2['T'-'A']['T'-'A'];
444 matrix2['u'-'A']['U'-'A']=matrix2['t'-'A']['T'-'A'];
445 matrix2['U'-'A']['u'-'A']=matrix2['T'-'A']['t'-'A'];
446 matrix2['u'-'A']['u'-'A']=matrix2['t'-'A']['t'-'A'];
448 free_int (matrice, -1);
453 void display_matrix (int **mat)
457 for ( a=0; a< 26; a++)
459 fprintf ( stderr, "\n%c ", a+'a');
460 for ( b=0; b< 26; b++)
461 fprintf ( stderr, " %2d", mat[a][b]);
465 int **neg_matrix2pos_matrix ( int **matrix)
468 char AA[]="abcdefghiklmnpqrstvwxyzABCDEFGHIKLMNPQRSTVWXYZ";
470 min=max=matrix[AA[0]-'A'][AA[0]-'A'];
474 min=(matrix[AA[b]-'A'][AA[c]-'A']<min)?matrix[AA[b]-'A'][AA[c]-'A']:min;
475 max=(matrix[AA[b]-'A'][AA[c]-'A']<max)?matrix[AA[b]-'A'][AA[c]-'A']:max;
477 if (min>0)return matrix;
483 matrix[b][c]=matrix[b][c]-min;
491 /*****************************************************************/
492 void get_rgb_values ( int val, Color *C)
495 /*Colors can be modified, see the definition of
496 COLOR_FILE in prgogrammes_define.h
499 static char **html_code;
500 static float **ps_code;
509 html_code=declare_char(10, 10);
510 ps_code=declare_float (10, 3);
514 sprintf (html_code[n], "#6666FF");
520 sprintf (html_code[n], "#00FF00");
527 sprintf (html_code[n], "#66FF00");
534 sprintf (html_code[n], "#CCFF00");
541 sprintf (html_code[n], "#FFFF00");
548 sprintf (html_code[n], "#FFCC00");
555 sprintf (html_code[n], "#FF9900");
562 sprintf (html_code[n], "#FF6600");
569 sprintf (html_code[n], "#FF3300");
577 sprintf (html_code[n], "#FF2000");
587 if ( check_file_exists(COLOR_FILE))
589 fp=vfopen( COLOR_FILE, "r");
591 while ((c=fgetc(fp))!='*');
592 while ((c=fgetc(fp))!='\n');
595 while ((c=fgetc(fp))!=EOF)
598 if ( fscanf (fp, "%d", &class)==0)break;
599 fscanf (fp, "%s %f %f %f", html_code[class], &ps_code[class][0], &ps_code[class][1],&ps_code[class][2]);
600 while ((c=fgetc(fp))!='\n' && c!=EOF);
601 if ( c==EOF)ungetc(c, fp);
617 sprintf ( C->html_color_class, "value%d",val);
620 if (val<=9 && val>=0)
623 sprintf ( C->html_color, "%s", html_code[val]);
624 r[0]=ps_code[val][0];
625 g[0]=ps_code[val][1];
626 b[0]=ps_code[val][2];
629 else if (val==DEFAULT_COLOR || val==NO_COLOR_RESIDUE || val==NO_COLOR_GAP || (val>'A' && val<'z'))
631 C->html_color[0]='\0';
632 sprintf ( C->html_color_class, "valuedefault");
638 else if (val==GAP_COLOR)
640 C->html_color[0]='\0';
641 sprintf ( C->html_color_class, "valuegap");
646 else if (val==INK_COLOR )
648 sprintf ( C->html_color, "000000");
649 sprintf ( C->html_color_class, "valueink");
658 int output_color_format ( Alignment *B,Alignment *Sin,char *name, \
659 FILE_format *(*vfopen_format) ( char *),\
660 FILE_format *(*print_format_string) ( char * ,Color *, Color *, FILE_format*),\
661 FILE_format *(*print_format_char) ( int ,Color *, Color *, FILE_format*),\
662 void (*get_rgb_values_format) ( int ,Color *),\
663 FILE_format* (*vfclose_format) ( FILE_format *))
673 static FILE_format *fps;
680 S=copy_aln (B, NULL);
682 buf2=vcalloc (Sin->len_aln+1, sizeof (char));
683 buf3=vcalloc ( B->len_aln+1, sizeof (char));
684 for ( a=0; a<B->nseq; a++)
688 i=name_is_in_list ( B->name[a], Sin->name, Sin->nseq, -1);
690 sprintf (buf2, "%s", Sin->seq_al[i]);ungap(buf2);
691 sprintf (buf3, "%s", S->seq_al[a]);ungap(buf3);
693 if ( strlen (buf2) !=strlen(buf3))
696 fprintf ( stderr, "\nERROR: Incompatible cache ON sEQ: %s\n", S->name[a]);
697 fprintf ( stderr, "\n%s\n%s", buf2, buf3);
698 fprintf ( stderr, "\n\n%s\n%s", Sin->seq_al[i],S->seq_al[a]); exit (EXIT_FAILURE);
701 for (n=0,b=0;b<B->len_aln; b++)
706 S->seq_al[a][b]=buf2[n++];
714 box_c=vcalloc ( 1, sizeof (Color));
715 get_rgb_values_format (DEFAULT_COLOR, (white=vcalloc ( 1, sizeof (Color))));
716 get_rgb_values_format (INK_COLOR, (ink =vcalloc ( 1, sizeof (Color))));
718 n_residues=vcalloc ( B->nseq+1, sizeof (int));
719 for ( a=0; a<B->nseq; a++)n_residues[a]=B->order[a][1];
721 fps=vfopen_format( name);
724 buf=vcalloc (10000, sizeof (int));
729 for ( a=0; a< B->nseq; a++)
730 {if ( strlen (B->name[a])>max_len)
731 max_len= strlen ( (B->name[a]));
734 if ( max_len>max_name_len)max_len=max_name_len;
736 sprintf (buf, "\n%s, %s(%s)\n%s\n",PROGRAM,VERSION,DATE, AUTHOR);
737 fps=print_format_string ( buf,white, ink, fps);
739 fps=print_format_string ( "\n\n",white,ink, fps);
742 fps->line=fps->line-fps->line%3;
747 for (a=0; a<B->len_aln; a+=fps->line)
750 if ( (fps->n_line+(B->nseq+4))>fps->max_line_ppage && !((B->nseq+4)>fps->max_line_ppage))
752 fps=print_format_char ( fps->eop,white, ink, fps);
755 for (b=0; b<=B->nseq; b++)
757 sprintf (buf,"%-*.*s ",max_len+2, max_len,(b==B->nseq)?"":S->name[b]);
758 fps=print_format_string ( buf,white, ink, fps);
759 if(B->output_res_num)
761 sprintf (buf, " %4d ", n_residues[b]+1);
762 fps=print_format_string ( buf,white, ink, fps);
765 for (fps->in_seq=1,c=a;c<a+fps->line && c<B->len_aln;c++)
770 get_rgb_values_format (DEFAULT_COLOR,box_c);
771 s=analyse_aln_column ( B, c);
775 n_residues[b]+=!is_gap(B->seq_al[b][c]);
777 if (!is_gap(s) && S->seq_al[b][c]!=NO_COLOR_RESIDUE )
779 get_rgb_values_format ( S->seq_al[b][c], box_c);
783 get_rgb_values_format (GAP_COLOR, box_c);
786 fps=print_format_char ( s,box_c, ink,fps);
790 if(B->output_res_num)
792 sprintf (buf, " %4d ", n_residues[b]);
793 fps=print_format_string ( buf,white, ink, fps);
796 fps=print_format_char ( '\n', white, ink, fps);
799 fps=print_format_string ( "\n\n",white, ink, fps);
801 fps=print_format_string ( "\n\n\n",white, ink,fps);
804 vfclose_format( fps);
811 int output_reliability_format ( Alignment *B,Alignment *S,char *name, \
812 FILE_format *(*vfopen_format) ( char *),\
813 FILE_format *(*print_format_string) ( char * ,Color *, Color *, FILE_format*),\
814 FILE_format *(*print_format_char) ( int ,Color *, Color *, FILE_format*),\
815 void (*get_rgb_values_format) ( int ,Color *),\
816 FILE_format* (*vfclose_format) ( FILE_format *))
821 static char *buf,*buf2;
823 static FILE_format *fps;
830 box_c=vcalloc ( 1, sizeof (Color));
831 get_rgb_values_format (DEFAULT_COLOR, (white=vcalloc ( 1, sizeof (Color))));
832 get_rgb_values_format (INK_COLOR, (ink =vcalloc ( 1, sizeof (Color))));
834 n_residues=vcalloc ( B->nseq+1, sizeof (int));
835 for ( a=0; a<B->nseq; a++)n_residues[a]=B->order[a][1];
838 fps=vfopen_format( name);
841 buf=vcalloc (10000, sizeof (int));
842 buf2=vcalloc (10000, sizeof (int));
847 for ( a=0; a< B->nseq; a++)
848 {if ( strlen (B->name[a])>max_len)
849 max_len= strlen ( (B->name[a]));
853 if ( vfopen_format==vfopen_ascii)
857 else if ( max_len>max_name_len)max_len=max_name_len;
861 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:"");
862 fps=print_format_string ( buf,white, ink, fps);
863 sprintf (buf, "SCORE=%d\n*\n", S->score_aln);
864 fps=print_format_string ( buf,white, ink, fps);
866 sprintf ( buf2, " BAD AVG GOOD");
868 get_rgb_values_format ( DEFAULT_COLOR, box_c);
869 fps=print_format_char ( buf2[0],box_c, ink, fps);
870 for ( a=1; a<l-1; a++)
872 get_rgb_values_format ( MIN(9,a-1), box_c);
873 fps=print_format_char ( buf2[a],box_c,ink,fps);
875 fps=print_format_char ( buf2[a], box_c, ink, fps);
878 fps=print_format_string ( "\n*\n",white,ink, fps);
880 for ( a=0;S->score_seq && a< B->nseq; a++)
882 get_rgb_values_format (S->score_seq[a]/10, box_c);
883 sprintf ( buf, "%-*.*s ", max_len+2,max_len, S->name[a]);
884 fps=print_format_string ( buf,box_c, ink,fps);
885 sprintf ( buf, ": %3d\n", S->score_seq[a]);
886 fps=print_format_string ( buf,white, ink,fps);
888 //Print the Consensus score
889 get_rgb_values_format (S->score_aln/10, box_c);
890 sprintf ( buf, "%-*.*s ", max_len+2,max_len, S->name[S->nseq]);
891 fps=print_format_string ( buf,box_c, ink,fps);
892 sprintf ( buf, ": %3d\n", S->score_aln);
893 fps=print_format_string ( buf,white, ink,fps);
895 fps=print_format_string ( "\n",white, ink,fps);
900 fps->line=fps->line-(fps->line%3);
902 for (a=0; a<B->len_aln; a+=fps->line)
905 if ( (fps->n_line+(B->nseq+4))>fps->max_line_ppage && !((B->nseq+4)>fps->max_line_ppage))
907 fps=print_format_char ( fps->eop,white, ink, fps);
910 for (b=0; b<=S->nseq; b++)
912 if ( b==S->nseq && print_format_string !=print_ascii_string) fps=print_format_string ( "\n",white, ink, fps);
913 sprintf (buf,"%-*.*s ",max_len+2,max_len,S->name[b]);
914 fps=print_format_string ( buf,white, ink, fps);
915 if(B->output_res_num)
917 sprintf (buf, " %4d ", n_residues[b]+1);
918 fps=print_format_string ( buf,white, ink, fps);
921 for (fps->in_seq=1,c=a;c<a+fps->line && c<B->len_aln;c++)
930 if ( s>='0' && s<='9')s-='0';
931 get_rgb_values_format (s,box_c);
933 else get_rgb_values_format (DEFAULT_COLOR,box_c);
935 s=analyse_aln_column ( B, c);
939 n_residues[b]+=!is_gap(B->seq_al[b][c]);
940 //s=toupper(B->seq_al[b][c]);
942 if (!is_gap(s) && S->seq_al[b][c]!=NO_COLOR_RESIDUE )
944 get_rgb_values_format ( S->seq_al[b][c], box_c);
949 get_rgb_values_format (GAP_COLOR, box_c);
954 fps=print_format_char ( s,box_c, ink,fps);
958 if(B->output_res_num)
960 sprintf (buf, " %4d ",n_residues[b]);
961 fps=print_format_string ( buf,white, ink, fps);
964 fps=print_format_char ( '\n', white, ink, fps);
967 fps=print_format_string ( "\n\n",white, ink, fps);
969 fps=print_format_string ( "\n\n\n",white, ink,fps);
970 vfclose_format( fps);
976 /*****************************************************************************/
979 /*****************************************************************************/
980 int output_color_pdf ( Alignment *B,Alignment *S, char *name)
983 char command[LONG_STRING];
987 fprintf (stderr, "\nPDF FORMAT IS NOT SUPPORTED: INSTALL THE PROGRAM PS2PDF\n");
988 myexit (EXIT_FAILURE);
990 tmp_name=vtmpnam(NULL);
992 output_color_ps (B, S, tmp_name);
993 sprintf ( command, "%s %s %s", PS2PDF, tmp_name, name);
994 my_system ( command);
1001 int output_reliability_pdf ( Alignment *B,Alignment *S, char *name)
1004 char command[LONG_STRING];
1009 fprintf (stderr, "\nPDF FORMAT IS NOT SUPPORTED: INSTALL THE PROGRAM PS2PDF\n");
1010 myexit (EXIT_FAILURE);
1012 tmp_name=vtmpnam(NULL);
1014 output_reliability_ps (B, S, tmp_name);
1015 sprintf ( command, "%s %s %s", PS2PDF, tmp_name, name);
1016 my_system ( command);
1017 vremove ( tmp_name);
1023 /*****************************************************************************/
1024 /* POST SCRIPT FUNCTIONS */
1026 /*****************************************************************************/
1027 int output_color_ps ( Alignment *B,Alignment *S, char *name)
1029 output_color_format (B, S, name, vfopen_ps,print_ps_string,print_ps_char,get_rgb_values_ps, vfclose_ps);
1032 int output_reliability_ps ( Alignment *B,Alignment *S, char *name)
1034 output_reliability_format (B, S, name, vfopen_ps,print_ps_string,print_ps_char,get_rgb_values_ps, vfclose_ps);
1037 FILE_format *print_ps_string( char *s, Color *box, Color *ink, FILE_format *fps)
1044 for ( a=0; a< l; a++)
1046 fps=print_ps_char (s[a], box, ink, fps);
1052 FILE_format * print_ps_char ( int c, Color *box, Color *ink, FILE_format *f)
1061 if ( c=='(' || c==')')return f;
1062 else if (c!='\n' && c!=f->eop)
1064 fprintf(f->fp,"%d %d moveto\n", f->x,f->y);
1065 fprintf(f->fp,"0 %d rlineto\n%d 0 rlineto\n0 -%d rlineto\nclosepath\n",ch,cw,ch );
1066 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);
1067 fprintf(f->fp,"%d %d moveto\n(%c) show\n", f->x+1,f->y+3, c);
1074 if ( f->n_line==f->max_line_ppage || c==f->eop)
1080 fprintf(f->fp,"showpage\n");
1082 fprintf ( f->fp, "%c%cPage: %d %d\n",'%', '%', f->n_pages, f->n_pages);
1092 void get_rgb_values_ps ( int val, Color *C)
1094 get_rgb_values ( val, C);
1099 FILE_format* vfopen_ps ( char *name)
1103 fps=vcalloc ( 1, sizeof ( FILE_format));
1105 fps->max_line_ppage=60;
1106 fps->line=get_msa_line_length (0, 0);/*N char per line*/
1111 fps->fp=vfopen ( name, "w");
1112 fprintf(fps->fp,"%%!PS-Adobe-2.0\n/Courier findfont\n%d scalefont\nsetfont\n",fps->font);
1113 fprintf(fps->fp, "%%%%Pages: (atend)\n");
1114 fprintf(fps->fp,"newpath\n");
1116 fprintf (fps->fp, "%%%%Page: %d %d\n", fps->n_pages, fps->n_pages);
1117 fprintf (fps->fp,"%d %d translate\n",fps->x0, fps->y0);
1121 FILE_format* vfclose_ps ( FILE_format *fps)
1124 fprintf(fps->fp,"showpage\n");
1125 fprintf ( fps->fp, "%%%%Pages: %d\n", fps->n_pages);
1126 fprintf(fps->fp,"%%%%EOF");
1127 fprintf(fps->fp,"%%%%\n");
1132 /*****************************************************************************/
1133 /* HTML FUNCTIONS */
1135 /*****************************************************************************/
1137 /*****************************************************************************/
1139 /*****************************************************************************/
1140 void output_hit_matrix(char *fileName, float **ffpHitScoreMatrix, int nl)
1145 fp=vfopen(fileName, "w");
1146 for(i = 0; i < nl; i++)
1148 for(j = 0; j < i; j++)
1149 fprintf(fp, "%6.2f ", ffpHitScoreMatrix[j][i-j]);
1150 for(j = i; j < nl; j++)
1151 fprintf(fp, "%6.2f ", ffpHitScoreMatrix[i][j-i]);
1157 int output_hit_color_html (Alignment *B, float **ffPScoreTable, int nl, char *name)
1159 output_hit_color_format (B, ffPScoreTable, nl, name, vfopen_html,print_html_string,print_html_char,get_rgb_values_html, vfclose_html);
1163 int output_hit_color_format (Alignment *B, float **ffPScoreTable, int nl, char *name, \
1164 FILE_format *(*vfopen_format) ( char *),\
1165 FILE_format *(*print_format_string) ( char * ,Color *, Color *, FILE_format*),\
1166 FILE_format *(*print_format_char) ( int ,Color *, Color *, FILE_format*),\
1167 void (*get_rgb_values_format) ( int ,Color *),\
1168 FILE_format* (*vfclose_format) ( FILE_format *))
1171 int max_name_len=15;
1175 static FILE_format *fps;
1180 box_c=vcalloc ( 1, sizeof (Color));
1181 get_rgb_values_format (DEFAULT_COLOR, (white=vcalloc ( 1, sizeof (Color))));
1182 get_rgb_values_format (INK_COLOR, (ink =vcalloc ( 1, sizeof (Color))));
1186 for ( a=0; a< B->nseq; a++)
1188 if ( strlen (B->name[a])>max_len)
1189 max_len= strlen ( (B->name[a]));
1192 if ( max_len>max_name_len)max_len=max_name_len;
1195 buf=vcalloc (10000, sizeof (int));
1196 int iEmptyChr = 32; //SPACE ASCIICODE
1198 fps=vfopen_format(name);
1199 for (a=0; a < nl; a++)
1201 sprintf (buf,"%*d ", max_len+2, a);
1202 fps=print_format_string ( buf,white, ink, fps);
1203 for(b = 0; b < a; b++)
1205 iColorValue = (int)((ffPScoreTable[b][a-b]*9)/100);
1206 get_rgb_values_format (iColorValue, box_c);
1207 fps=print_format_char (iEmptyChr,box_c, ink,fps);
1209 for(b = a; b < nl; b++)
1211 iColorValue = (int)((ffPScoreTable[a][b-a]*9)/100);
1212 get_rgb_values_format (iColorValue, box_c);
1213 fps=print_format_char (iEmptyChr,box_c, ink,fps);
1215 fps=print_format_char ('\n', white, ink, fps);
1217 vfclose_format(fps);
1223 /*****************************************************************************/
1225 int output_color_html ( Alignment *B,Alignment *S, char *name)
1227 output_color_format (B, S, name, vfopen_html,print_html_string,print_html_char,get_rgb_values_html, vfclose_html);
1230 int output_reliability_html ( Alignment *B,Alignment *S, char *name)
1232 output_reliability_format (B, S, name, vfopen_html,print_html_string,print_html_char,get_rgb_values_html, vfclose_html);
1235 FILE_format *print_html_string( char *s, Color *box, Color *ink, FILE_format *fhtml)
1242 for ( a=0; a< l; a++)
1244 fhtml=print_html_char (s[a], box, ink, fhtml);
1246 fhtml=print_html_char (CLOSE_HTML_SPAN,NULL,NULL,fhtml);
1251 FILE_format * print_html_char ( int c, Color *box, Color *ink, FILE_format *f)
1253 char html_color[100];
1254 int in_span, new_color;
1258 if (c==CLOSE_HTML_SPAN)
1260 if (f->in_html_span)fprintf ( f->fp, "</span>");
1266 in_span=f->in_html_span;
1267 new_color=1-(strm (box->html_color_class, f->previous_html_color));
1271 sprintf (f->previous_html_color, "%s", box->html_color_class);
1272 sprintf ( html_color, "class=%s", box->html_color_class);
1275 if ( c!=' ')sprintf ( string, "%c", c);
1276 else sprintf ( string, " ");
1278 if ( !in_span && c!='\n' && c!=f->eop)
1280 fprintf ( f->fp, "<span %s>%s",html_color,string );
1283 else if (in_span && !new_color && c!='\n' && c!=f->eop)
1286 fprintf ( f->fp, "%s",string);
1288 else if (in_span && new_color && c!='\n' && c!=f->eop)
1290 fprintf ( f->fp, "</span><span %s>%s",html_color,string);
1294 if ( f->in_html_span)fprintf ( f->fp, "</span>");
1295 fprintf ( f->fp, "<br>");
1296 sprintf ( f->previous_html_color, "no_color_set");
1308 void get_rgb_values_html ( int val, Color *C)
1310 get_rgb_values ( val, C);
1313 FILE_format* vfopen_html ( char *name)
1319 color=vcalloc ( 1, sizeof (Color));
1321 fhtml=vcalloc ( 1, sizeof ( FILE_format));
1323 fhtml->max_line_ppage=100000;
1324 fhtml->line=get_msa_line_length (0, 0);/*N char per line*/
1328 sprintf ( fhtml->previous_html_color, "no_value_set");
1329 fhtml->fp=vfopen ( name, "w");
1331 fprintf(fhtml->fp,"<html>\n<style>\n");
1333 fprintf(fhtml->fp,"SPAN { font-family: courier new, courier-new, courier; font-weight: bold; font-size: %dpt;}\n", fhtml->font);
1334 fprintf(fhtml->fp,"SPAN { line-height:100%%}\n");
1335 fprintf(fhtml->fp,"SPAN { white-space: pre}\n");
1337 for ( a=0; a< 10; a++)
1339 get_rgb_values_html ( a, color);
1340 if ( !strm (color->html_color, ""))fprintf (fhtml->fp, "SPAN.%s {background: %s}\n", color->html_color_class, color->html_color );
1341 else fprintf (fhtml->fp, "SPAN.%s {}\n", color->html_color_class );
1343 get_rgb_values_html (DEFAULT_COLOR, color);
1344 if ( !strm (color->html_color, ""))fprintf (fhtml->fp, "SPAN.%s {background: %s}\n", color->html_color_class, color->html_color );
1345 else fprintf (fhtml->fp, "SPAN.%s {}\n", color->html_color_class );
1347 get_rgb_values_html (GAP_COLOR, color);
1348 if ( !strm (color->html_color, ""))fprintf (fhtml->fp, "SPAN.%s {background: %s}\n", color->html_color_class, color->html_color );
1349 else fprintf (fhtml->fp, "SPAN.%s {}\n", color->html_color_class );
1351 get_rgb_values_html (INK_COLOR, color);
1352 if ( !strm (color->html_color, ""))fprintf (fhtml->fp, "SPAN.%s {background: %s}\n", color->html_color_class, color->html_color );
1353 else fprintf (fhtml->fp, "SPAN.%s {}\n", color->html_color_class );
1357 fprintf(fhtml->fp,"</style>");
1358 fprintf(fhtml->fp,"<body>");
1362 FILE_format* vfclose_html ( FILE_format *fhtml)
1364 if ( fhtml->in_html_span)fprintf(fhtml->fp,"</span>");
1365 fprintf(fhtml->fp,"</body></html>\n");
1366 vfclose ( fhtml->fp);
1370 /*****************************************************************************/
1371 /* ascii FUNCTIONS */
1373 /*****************************************************************************/
1374 int output_color_ascii ( Alignment *B,Alignment *S, char *name)
1376 output_color_format (B, S, name, vfopen_ascii,print_ascii_string,print_ascii_char,get_rgb_values_ascii, vfclose_ascii);
1379 int output_reliability_ascii ( Alignment *B,Alignment *S, char *name)
1381 output_reliability_format (B, S, name, vfopen_ascii,print_ascii_string,print_ascii_char,get_rgb_values_ascii, vfclose_ascii);
1385 FILE_format *print_ascii_string( char *s, Color *box, Color *ink, FILE_format *fascii)
1392 for ( a=0; a< l; a++)
1394 fascii=print_ascii_char (s[a], box, ink, fascii);
1400 FILE_format * print_ascii_char ( int c, Color *box, Color *ink, FILE_format *f)
1402 if (box->ascii_value>=0 && f->in_seq)fprintf ( f->fp, "%c", box->ascii_value);
1403 else fprintf ( f->fp, "%c",c);
1408 void get_rgb_values_ascii ( int val, Color *C)
1411 if ( val==NO_COLOR_RESIDUE)C->ascii_value='-';
1412 else if ( val==NO_COLOR_GAP)C->ascii_value='*';
1413 else if ( val>9)C->ascii_value='#';
1414 else if ( val>=0 && val<=9) C->ascii_value=val+'0';
1415 else C->ascii_value=val;
1418 FILE_format* vfopen_ascii ( char *name)
1421 fascii=vcalloc ( 1, sizeof ( FILE_format));
1423 fascii->max_line_ppage=100000;
1424 fascii->line=get_msa_line_length (0,0);/*N char per line*/
1428 fascii->fp=vfopen ( name, "w");
1433 FILE_format* vfclose_ascii ( FILE_format *fascii)
1435 vfclose ( fascii->fp);
1441 /*****************************************************************************/
1442 /* seq_score output */
1444 /*****************************************************************************/
1446 int output_seq_reliability_ascii ( Alignment *B,Alignment *S, char *name)
1451 for ( a=0; a< B->nseq; a++)
1452 {if ( strlen (B->name[a])>max_len)
1453 max_len= strlen ( (B->name[a]));
1456 fp=vfopen ( name, "w");
1457 fprintf ( fp, "ALN_SCORE %d\n", S->score_aln);
1458 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]);
1464 /*********************************COPYRIGHT NOTICE**********************************/
1465 /*© Centro de Regulacio Genomica */
1467 /*Cedric Notredame */
1468 /*Tue Oct 27 10:12:26 WEST 2009. */
1469 /*All rights reserved.*/
1470 /*This file is part of T-COFFEE.*/
1472 /* T-COFFEE is free software; you can redistribute it and/or modify*/
1473 /* it under the terms of the GNU General Public License as published by*/
1474 /* the Free Software Foundation; either version 2 of the License, or*/
1475 /* (at your option) any later version.*/
1477 /* T-COFFEE is distributed in the hope that it will be useful,*/
1478 /* but WITHOUT ANY WARRANTY; without even the implied warranty of*/
1479 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the*/
1480 /* GNU General Public License for more details.*/
1482 /* You should have received a copy of the GNU General Public License*/
1483 /* along with Foobar; if not, write to the Free Software*/
1484 /* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA*/
1485 /*............................................... |*/
1486 /* If you need some more information*/
1487 /* cedric.notredame@europe.com*/
1488 /*............................................... |*/
1492 /*********************************COPYRIGHT NOTICE**********************************/