#include #include #include #include #include #include #include "io_lib_header.h" #include "util_lib_header.h" #include "define_header.h" #include "matrices.h" #define DEFAULT_COLOR -1 #define GAP_COLOR -2 #define INK_COLOR -3 Sequence * cw_read_sequences ( char *seq_name) { Sequence *S; char **seq=NULL; char **name=NULL; int *len=NULL; int nseq=0; int min_len=0; int max_len=0; int a; get_sequence ( seq_name, &nseq, &seq, &name, &len, &min_len, &max_len); S=declare_sequence ( min_len, max_len, nseq); for ( a=0; a< nseq; a++)sprintf ( S->file[a], "%s", seq_name); for ( a=0; anseq; a++) { S->len[a]=len[a]; sprintf ( S->name[a],"%s", name[a]); vfree ( name[a]); sprintf ( S->seq[a], "%s", seq[a]); vfree ( seq[a]); } vfree (seq); vfree (name); vfree (len); S=get_sequence_type ( S); return S; } char * get_string_type (char *S) { int a, l; int protein=0, dna=0,rna=0, tot=0; char *type; static char *ltype; static int warning; if ( !ltype) declare_name(ltype); declare_name(type); l=(int)strlen (S); if (l==0) { sprintf ( type, "UNKNOWN"); return type; } for ( a=0; a98 && rna>0)sprintf ( type, "RNA"); else if ( dna>98)sprintf ( type, "DNA"); else sprintf ( type, "PROTEIN"); sprintf ( ltype, "%s", type); return type; } Alignment* get_aln_type (Alignment *A) { if ( !A) return A; if ( A->S && !(A->S)->type)(A->S)->type=vcalloc (30, sizeof (char)); if ( A->S && (A->S)->type[0]!='\0') { ; } else if (A->S!=NULL && (A->S)->type[0]=='\0') { A->S=get_sequence_type (A->S); } else if (A->S==NULL) { A->S=aln2seq (A); A->S=get_sequence_type(A->S); } return A; } char *unset_mode () { return set_mode (UNSET, NULL); } char *store_mode (char *val) { return set_mode (SET, val); } char *retrieve_mode () { return set_mode (GET,NULL); } char *set_mode (int mode, char *val) { static char type[100]; if (mode==SET) { if (!val)printf_exit (EXIT_FAILURE, stderr, "Error: programme mode unset in io_func.c:set_seq_type"); sprintf ( type,"%s", val); } else if ( mode==GET) { ; } else if ( mode==UNSET) { type[0]='\0'; } else { printf_exit (EXIT_FAILURE, stderr, "Error: unknown mode in function io_func.c:set_seq_type, use SET, GET or UNSET"); } return type; } /************************************************************/ char *unset_seq_type () { return set_seq_type (UNSET, NULL); } char *store_seq_type (char *val) { return set_seq_type (SET, val); } char *retrieve_seq_type () { return set_seq_type (GET,NULL); } char *set_seq_type (int mode, char *val) { static char type[100]; if (mode==SET) { if (!val)printf_exit (EXIT_FAILURE, stderr, "Error: sequence type unset in io_func.c:set_seq_type"); sprintf ( type,"%s", val); } else if ( mode==GET) { ; } else if ( mode==UNSET) { type[0]='\0'; } else { printf_exit (EXIT_FAILURE, stderr, "Error: unknown mode in function io_func.c:set_seq_type, use SET, GET or UNSET"); } return type; } char * get_array_type (int n, char **seq) { char *buf, *buf2; int a, tot=0; buf2=vcalloc ( 100, sizeof (char)); for ( tot=0,a=0; atype, "%s", get_array_type (S->nseq, S->seq)); return S; } void get_sequence (char *seq_file,int *NSEQ, char ***SEQ, char ***SN, int **sl, int *min, int *max) { int a,b; int min_len; int max_len; int nseq; int **SL; nseq=NSEQ[0]= readseqs ( seq_file, SEQ, SN, &SL); sl[0]=vcalloc ( nseq, sizeof (int)); min_len= max_len= (SL)[0][0]; for ( a=0; a (SL)[a][0])?(SL)[a][0]:min_len; max_len= ( max_len < (SL)[a][0])?(SL)[a][0]:max_len; } min[0]=min_len; max[0]=max_len; } int ** get_matrix ( char *name, char *format) { if ( strm ( "blast", format))return read_blast_matrix ( name); else if ( strm ( "clustalw", format))return read_matrice(name); else { fprintf ( stderr, "\nError:\nUnknowm Format %s for Matrix %s[FATAL]", format, name); myexit (EXIT_FAILURE); } return NULL; } void display_matrix (int **mat); int ** read_matrice (char *mat_name_in) { int a,b,c, l; char *AA; FILE *fp; int **matrice; int **matrix2; char mat_name[200]; int *vector=NULL; AA=vcalloc (256, sizeof (char)); sprintf (AA, "abcdefghiklmnpqrstvwxyz"); l=strlen(AA); if ( strm2 (mat_name_in, "pam", "PAM"))sprintf ( mat_name, "pam250mt"); else if (strm2 (mat_name_in, "blosum", "BLOSUM"))sprintf ( mat_name, "blosum62mt"); else if (strm3 (mat_name_in, "id", "ID", "idmat"))sprintf ( mat_name, "idmat"); else sprintf ( mat_name, "%s", mat_name_in); /*Read Header Matrices*/ if (strm(mat_name, "pam250mt"))vector=pam250mt; else if (strm(mat_name, "idmat"))vector=idmat; else if (strm(mat_name, "dna_idmat"))vector=idmat; else if (strm(mat_name, "est_idmat"))vector=est_idmat; else if (strm(mat_name, "md_350mt"))vector=md_350mt; else if (strm(mat_name, "md_250mt"))vector=md_250mt; else if (strm(mat_name, "md_120mt"))vector=md_120mt; else if (strm(mat_name, "md_40mt" ))vector= md_40mt; else if (strm(mat_name, "pam350mt" ))vector=pam350mt; else if (strm(mat_name, "pam160mt" ))vector=pam160mt; else if (strm(mat_name, "pam120mt" ))vector=pam120mt; else if (strm(mat_name, "blosum80mt" ))vector=blosum80mt; else if (strm(mat_name, "blosum62mt" ))vector=blosum62mt; else if (strm(mat_name, "exon2mt" ))vector=blosum62mt; else if (strm(mat_name, "blosum62mt3" ))vector=blosum62mt3; else if (strm(mat_name, "blosum62mt2" ))vector=blosum62mt2; else if (strm(mat_name, "blosum55mt" ))vector=blosum55mt; else if (strm(mat_name, "blosum50mt" ))vector=blosum50mt; else if (strm(mat_name, "blosum45mt" ))vector=blosum45mt; else if (strm(mat_name, "blosum40mt" ))vector=blosum40mt; else if (strm(mat_name, "blosum30mt" ))vector=blosum30mt; else if (strm(mat_name, "beta_mat" ))vector=beta_mat; else if (strm(mat_name, "alpha_mat" ))vector=alpha_mat; else if (strm(mat_name, "coil_mat" ))vector=coil_mat; else if (strm(mat_name, "rblosum80mt" ))vector=rblosum80mt; else if (strm(mat_name, "rblosum62mt" ))vector=rblosum62mt; else if (strm(mat_name, "rblosum30mt" ))vector=rblosum30mt; else if (strm(mat_name, "rpam250mt" ))vector=rpam250mt; else if (strm(mat_name, "rpam350mt" ))vector=rpam350mt; else if (strm(mat_name, "rpam160mt" ))vector=rpam160mt; else if (strm(mat_name, "rpam120mt" ))vector=rpam120mt; else if (strm(mat_name, "tmpam250mt" ))vector=tmpam250mt; else if (strm(mat_name, "rtmpam250mt" ))vector=rtmpam250mt; else if (strm(mat_name, "rbeta_mat" ))vector=rbeta_mat; else if (strm(mat_name, "ralpha_mat" ))vector=ralpha_mat; else if (strm(mat_name, "rcoil_mat" ))vector=rcoil_mat; else if (strm (mat_name, "jtttm250mt"))vector=jtttm250mt; else if (strm (mat_name, "promoter_tf1"))vector=promoter_tf1; else if (strm (mat_name, "blosumR"))vector=blosumR; /*Header Matrices*/ if(vector) { matrice=declare_int ( 256, 256); for (a=0; a0)return matrix; else { for ( b=0; br; g=&C->g; b=&C->b; if ( val==10)val--; sprintf ( C->html_color_class, "value%d",val); if (val<=9 && val>=0) { sprintf ( C->html_color, "%s", html_code[val]); r[0]=ps_code[val][0]; g[0]=ps_code[val][1]; b[0]=ps_code[val][2]; } else if (val==DEFAULT_COLOR || val==NO_COLOR_RESIDUE || val==NO_COLOR_GAP || (val>'A' && val<'z')) { C->html_color[0]='\0'; sprintf ( C->html_color_class, "valuedefault"); r[0]=1.; g[0]=1; b[0]=1; } else if (val==GAP_COLOR) { C->html_color[0]='\0'; sprintf ( C->html_color_class, "valuegap"); r[0]=1.; g[0]=1; b[0]=1; } else if (val==INK_COLOR ) { sprintf ( C->html_color, "000000"); sprintf ( C->html_color_class, "valueink"); r[0]=0.; g[0]=0; b[0]=0; } return; } // void output_tm_mark(FILE_format *fps) // { // Color *box_c=vcalloc ( 1, sizeof (Color)); // Color *ink; // get_rgb_values_format (INK_COLOR, (ink =vcalloc ( 1, sizeof (Color)))); // // get_rgb_values_format ( 5, box_c); // fps=print_format_char ( " IN ", box_c,ink,fps); // // get_rgb_values_format ( 9, box_c); // fps=print_format_char ( " HEL ", box_c,ink,fps); // // get_rgb_values_format ( 0, box_c); // fps=print_format_char ( "OUT", box_c,ink,fps); // } int output_color_format ( Alignment *B,Alignment *Sin,char *name, \ FILE_format *(*vfopen_format) ( char *),\ FILE_format *(*print_format_string) ( char * ,Color *, Color *, FILE_format*),\ FILE_format *(*print_format_char) ( int ,Color *, Color *, FILE_format*),\ void (*get_rgb_values_format) ( int ,Color *),\ FILE_format* (*vfclose_format) ( FILE_format *)) { int a, b, c; int max_name_len=15; int max_len=0; char *buf2, *buf3; static char *buf; int s; int *n_residues; static FILE_format *fps; Color *ink; Color *box_c; Color *white; Alignment *S; S=copy_aln (B, NULL); buf2=vcalloc (Sin->len_aln+1, sizeof (char)); buf3=vcalloc ( B->len_aln+1, sizeof (char)); for ( a=0; anseq; a++) { int i,n, r; i=name_is_in_list ( B->name[a], Sin->name, Sin->nseq, -1); if (i==-1)continue; sprintf (buf2, "%s", Sin->seq_al[i]);ungap(buf2); sprintf (buf3, "%s", S->seq_al[a]);ungap(buf3); if ( strlen (buf2) !=strlen(buf3)) { fprintf ( stderr, "\nERROR: Incompatible cache ON sEQ: %s\n", S->name[a]); fprintf ( stderr, "\n%s\n%s", buf2, buf3); fprintf ( stderr, "\n\n%s\n%s", Sin->seq_al[i],S->seq_al[a]); exit (EXIT_FAILURE); } for (n=0,b=0;blen_aln; b++) { r=S->seq_al[a][b]; if (!is_gap(r)) { S->seq_al[a][b]=buf2[n++]; } } } S=aln2number(S); vfree (buf2); box_c=vcalloc ( 1, sizeof (Color)); get_rgb_values_format (DEFAULT_COLOR, (white=vcalloc ( 1, sizeof (Color)))); get_rgb_values_format (INK_COLOR, (ink =vcalloc ( 1, sizeof (Color)))); n_residues=vcalloc ( B->nseq+1, sizeof (int)); for ( a=0; anseq; a++)n_residues[a]=B->order[a][1]; fps=vfopen_format( name); if ( buf==NULL) { buf=vcalloc (10000, sizeof (int)); } if ( max_len==0) { for ( a=0; a< B->nseq; a++) {if ( strlen (B->name[a])>max_len) max_len= strlen ( (B->name[a])); } } if ( max_len>max_name_len)max_len=max_name_len; sprintf (buf, "\n%s, %s(%s)\n%s\n",PROGRAM,VERSION,DATE, AUTHOR); fps=print_format_string ( buf,white, ink, fps); if(B->output_tm == 1) { fps=print_format_char ( '\n', white, ink, fps); get_rgb_values_format ( 5, box_c); fps=print_format_string ( " IN ", box_c,ink,fps); get_rgb_values_format ( 9, box_c); fps=print_format_string ( " HEL ", box_c,ink,fps); get_rgb_values_format ( 0, box_c); fps=print_format_string ( " OUT ", box_c,ink,fps); } fps=print_format_string ( "\n\n",white,ink, fps); fps->line-=max_len; fps->line=fps->line-fps->line%3; for (a=0; alen_aln; a+=fps->line) { if ( (fps->n_line+(B->nseq+4))>fps->max_line_ppage && !((B->nseq+4)>fps->max_line_ppage)) { fps=print_format_char ( fps->eop,white, ink, fps); } for (b=0; b<=B->nseq; b++) { sprintf (buf,"%-*.*s ",max_len+2, max_len,(b==B->nseq)?"":S->name[b]); fps=print_format_string ( buf,white, ink, fps); if(B->output_res_num) { sprintf (buf, " %4d ", n_residues[b]+1); fps=print_format_string ( buf,white, ink, fps); } for (fps->in_seq=1,c=a;cline && clen_aln;c++) { if (b==B->nseq) { n_residues[b]++; get_rgb_values_format (DEFAULT_COLOR,box_c); s=analyse_aln_column ( B, c); } else { n_residues[b]+=!is_gap(B->seq_al[b][c]); s=B->seq_al[b][c]; if (!is_gap(s) && S->seq_al[b][c]!=NO_COLOR_RESIDUE ) { get_rgb_values_format ( S->seq_al[b][c], box_c); } else { get_rgb_values_format (GAP_COLOR, box_c); } } fps=print_format_char ( s,box_c, ink,fps); } fps->in_seq=0; if(B->output_res_num) { sprintf (buf, " %4d ", n_residues[b]); fps=print_format_string ( buf,white, ink, fps); } fps=print_format_char ( '\n', white, ink, fps); } fps=print_format_string ( "\n\n",white, ink, fps); } fps=print_format_string ( "\n\n\n",white, ink,fps); vfclose_format( fps); free_aln (S); vfree (n_residues); return 1; } int output_reliability_format ( Alignment *B,Alignment *S,char *name, \ FILE_format *(*vfopen_format) ( char *),\ FILE_format *(*print_format_string) ( char * ,Color *, Color *, FILE_format*),\ FILE_format *(*print_format_char) ( int ,Color *, Color *, FILE_format*),\ void (*get_rgb_values_format) ( int ,Color *),\ FILE_format* (*vfclose_format) ( FILE_format *)) { int a, b, c,l; int max_name_len=15; int max_len=0; static char *buf,*buf2; int s; static FILE_format *fps; Color *ink; Color *box_c; Color *white; int *n_residues; box_c=vcalloc ( 1, sizeof (Color)); get_rgb_values_format (DEFAULT_COLOR, (white=vcalloc ( 1, sizeof (Color)))); get_rgb_values_format (INK_COLOR, (ink =vcalloc ( 1, sizeof (Color)))); n_residues=vcalloc ( B->nseq+1, sizeof (int)); for ( a=0; anseq; a++)n_residues[a]=B->order[a][1]; fps=vfopen_format( name); if ( buf==NULL) { buf=vcalloc (10000, sizeof (int)); buf2=vcalloc (10000, sizeof (int)); } if ( max_len==0) { for ( a=0; a< B->nseq; a++) {if ( strlen (B->name[a])>max_len) max_len= strlen ( (B->name[a])); } } if ( vfopen_format==vfopen_ascii) { fps->line+= max_len; } else if ( max_len>max_name_len)max_len=max_name_len; 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:""); fps=print_format_string ( buf,white, ink, fps); sprintf (buf, "SCORE=%d\n*\n", S->score_aln); fps=print_format_string ( buf,white, ink, fps); sprintf ( buf2, " BAD AVG GOOD"); l=strlen(buf2); get_rgb_values_format ( DEFAULT_COLOR, box_c); fps=print_format_char ( buf2[0],box_c, ink, fps); for ( a=1; ascore_seq && a< B->nseq; a++) { get_rgb_values_format (S->score_seq[a]/10, box_c); sprintf ( buf, "%-*.*s ", max_len+2,max_len, S->name[a]); fps=print_format_string ( buf,box_c, ink,fps); sprintf ( buf, ": %3d\n", S->score_seq[a]); fps=print_format_string ( buf,white, ink,fps); } //Print the Consensus score get_rgb_values_format (S->score_aln/10, box_c); sprintf ( buf, "%-*.*s ", max_len+2,max_len, S->name[S->nseq]); fps=print_format_string ( buf,box_c, ink,fps); sprintf ( buf, ": %3d\n", S->score_aln); fps=print_format_string ( buf,white, ink,fps); fps=print_format_string ( "\n",white, ink,fps); fps->line-=max_len; fps->line=fps->line-(fps->line%3); for (a=0; alen_aln; a+=fps->line) { if ( (fps->n_line+(B->nseq+4))>fps->max_line_ppage && !((B->nseq+4)>fps->max_line_ppage)) { fps=print_format_char ( fps->eop,white, ink, fps); } for (b=0; b<=S->nseq; b++) { if ( b==S->nseq && print_format_string !=print_ascii_string) fps=print_format_string ( "\n",white, ink, fps); sprintf (buf,"%-*.*s ",max_len+2,max_len,S->name[b]); fps=print_format_string ( buf,white, ink, fps); if(B->output_res_num) { sprintf (buf, " %4d ", n_residues[b]+1); fps=print_format_string ( buf,white, ink, fps); } for (fps->in_seq=1,c=a;cline && clen_aln;c++) { if (b==S->nseq) { if (S->score_seq) { int s; s=S->seq_al[b][c]; if ( s>='0' && s<='9')s-='0'; get_rgb_values_format (s,box_c); } else get_rgb_values_format (DEFAULT_COLOR,box_c); n_residues[b]++; s=analyse_aln_column ( B, c); } else { n_residues[b]+=!is_gap(B->seq_al[b][c]); //s=toupper(B->seq_al[b][c]); s=B->seq_al[b][c]; if (!is_gap(s) && S->seq_al[b][c]!=NO_COLOR_RESIDUE ) { get_rgb_values_format ( S->seq_al[b][c], box_c); } else { get_rgb_values_format (GAP_COLOR, box_c); } } fps=print_format_char ( s,box_c, ink,fps); } fps->in_seq=0; if(B->output_res_num) { sprintf (buf, " %4d ",n_residues[b]); fps=print_format_string ( buf,white, ink, fps); } fps=print_format_char ( '\n', white, ink, fps); } fps=print_format_string ( "\n\n",white, ink, fps); } fps=print_format_string ( "\n\n\n",white, ink,fps); vfclose_format( fps); return 1; } /*****************************************************************************/ /* PDF FUNCTIONS */ /* */ /*****************************************************************************/ int output_color_pdf ( Alignment *B,Alignment *S, char *name) { char *tmp_name; char command[LONG_STRING]; #ifndef PS2PDF fprintf (stderr, "\nPDF FORMAT IS NOT SUPPORTED: INSTALL THE PROGRAM PS2PDF\n"); myexit (EXIT_FAILURE); #else tmp_name=vtmpnam(NULL); output_color_ps (B, S, tmp_name); sprintf ( command, "%s %s %s", PS2PDF, tmp_name, name); my_system ( command); vremove ( tmp_name); #endif return 1; } int output_reliability_pdf ( Alignment *B,Alignment *S, char *name) { char *tmp_name; char command[LONG_STRING]; #ifndef PS2PDF fprintf (stderr, "\nPDF FORMAT IS NOT SUPPORTED: INSTALL THE PROGRAM PS2PDF\n"); myexit (EXIT_FAILURE); #else tmp_name=vtmpnam(NULL); output_reliability_ps (B, S, tmp_name); sprintf ( command, "%s %s %s", PS2PDF, tmp_name, name); my_system ( command); vremove ( tmp_name); #endif return 1; } /*****************************************************************************/ /* POST SCRIPT FUNCTIONS */ /* */ /*****************************************************************************/ int output_color_ps ( Alignment *B,Alignment *S, char *name) { output_color_format (B, S, name, vfopen_ps,print_ps_string,print_ps_char,get_rgb_values_ps, vfclose_ps); return 1; } int output_reliability_ps ( Alignment *B,Alignment *S, char *name) { output_reliability_format (B, S, name, vfopen_ps,print_ps_string,print_ps_char,get_rgb_values_ps, vfclose_ps); return 1; } FILE_format *print_ps_string( char *s, Color *box, Color *ink, FILE_format *fps) { int l; int a; l=strlen (s); for ( a=0; a< l; a++) { fps=print_ps_char (s[a], box, ink, fps); } return fps; } FILE_format * print_ps_char ( int c, Color *box, Color *ink, FILE_format *f) { int ch; int cw; ch=f->font+3; cw=f->font-2; if ( c=='(' || c==')')return f; else if (c!='\n' && c!=f->eop) { fprintf(f->fp,"%d %d moveto\n", f->x,f->y); fprintf(f->fp,"0 %d rlineto\n%d 0 rlineto\n0 -%d rlineto\nclosepath\n",ch,cw,ch ); 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); fprintf(f->fp,"%d %d moveto\n(%c) show\n", f->x+1,f->y+3, c); f->x+=cw; } else { f->n_line++; if ( f->n_line==f->max_line_ppage || c==f->eop) { f->n_line=0; f->x=f->x0; f->y=f->y0; fprintf(f->fp,"showpage\n"); f->n_pages++; fprintf ( f->fp, "%c%cPage: %d %d\n",'%', '%', f->n_pages, f->n_pages); } else { f->x=f->x0; f->y-=ch; } } return f; } void get_rgb_values_ps ( int val, Color *C) { get_rgb_values ( val, C); } FILE_format* vfopen_ps ( char *name) { FILE_format*fps; fps=vcalloc ( 1, sizeof ( FILE_format)); fps->font=9; fps->max_line_ppage=60; fps->line=get_msa_line_length (0, 0);/*N char per line*/ fps->x0=15; fps->y0=750; fps->eop='^'; fps->fp=vfopen ( name, "w"); fprintf(fps->fp,"%%!PS-Adobe-2.0\n/Courier findfont\n%d scalefont\nsetfont\n",fps->font); fprintf(fps->fp, "%%%%Pages: (atend)\n"); fprintf(fps->fp,"newpath\n"); ++(fps->n_pages); fprintf (fps->fp, "%%%%Page: %d %d\n", fps->n_pages, fps->n_pages); fprintf (fps->fp,"%d %d translate\n",fps->x0, fps->y0); return fps; } FILE_format* vfclose_ps ( FILE_format *fps) { fprintf(fps->fp,"showpage\n"); fprintf ( fps->fp, "%%%%Pages: %d\n", fps->n_pages); fprintf(fps->fp,"%%%%EOF"); fprintf(fps->fp,"%%%%\n"); vfclose ( fps->fp); vfree (fps); return NULL; } /*****************************************************************************/ /* HTML FUNCTIONS */ /* */ /*****************************************************************************/ /*****************************************************************************/ //JM_ADD /*****************************************************************************/ void output_hit_matrix(char *fileName, float **ffpHitScoreMatrix, int nl) { int i, j; FILE *fp; fp=vfopen(fileName, "w"); for(i = 0; i < nl; i++) { for(j = 0; j < i; j++) fprintf(fp, "%6.2f ", ffpHitScoreMatrix[j][i-j]); for(j = i; j < nl; j++) fprintf(fp, "%6.2f ", ffpHitScoreMatrix[i][j-i]); fprintf(fp, "\n"); } vfclose(fp); } int output_hit_color_format (Alignment *B, float **ffPScoreTable, int nl, char *name, \ FILE_format *(*vfopen_format) ( char *),\ FILE_format *(*print_format_string) ( char * ,Color *, Color *, FILE_format*),\ FILE_format *(*print_format_char) ( int ,Color *, Color *, FILE_format*),\ void (*get_rgb_values_format) ( int ,Color *),\ FILE_format* (*vfclose_format) ( FILE_format *)); int output_hit_color_html (Alignment *B, float **ffPScoreTable, int nl, char *name) { output_hit_color_format (B, ffPScoreTable, nl, name, vfopen_html,print_html_string,print_html_char,get_rgb_values_html, vfclose_html); return 1; } int output_hit_color_format (Alignment *B, float **ffPScoreTable, int nl, char *name, \ FILE_format *(*vfopen_format) ( char *),\ FILE_format *(*print_format_string) ( char * ,Color *, Color *, FILE_format*),\ FILE_format *(*print_format_char) ( int ,Color *, Color *, FILE_format*),\ void (*get_rgb_values_format) ( int ,Color *),\ FILE_format* (*vfclose_format) ( FILE_format *)) { int a, b; int max_name_len=15; int max_len=0; static char *buf; static FILE_format *fps; Color *ink; Color *box_c; Color *white; box_c=vcalloc ( 1, sizeof (Color)); get_rgb_values_format (DEFAULT_COLOR, (white=vcalloc ( 1, sizeof (Color)))); get_rgb_values_format (INK_COLOR, (ink =vcalloc ( 1, sizeof (Color)))); if ( max_len==0) { for ( a=0; a< B->nseq; a++) { if ( strlen (B->name[a])>max_len) max_len= strlen ( (B->name[a])); } } if ( max_len>max_name_len)max_len=max_name_len; if ( buf==NULL) buf=vcalloc (10000, sizeof (int)); int iEmptyChr = 32; //SPACE ASCIICODE int iColorValue; fps=vfopen_format(name); for (a=0; a < nl; a++) { sprintf (buf,"%*d ", max_len+2, a); fps=print_format_string ( buf,white, ink, fps); for(b = 0; b < a; b++) { iColorValue = (int)((ffPScoreTable[b][a-b]*9)/100); get_rgb_values_format (iColorValue, box_c); fps=print_format_char (iEmptyChr,box_c, ink,fps); } for(b = a; b < nl; b++) { iColorValue = (int)((ffPScoreTable[a][b-a]*9)/100); get_rgb_values_format (iColorValue, box_c); fps=print_format_char (iEmptyChr,box_c, ink,fps); } fps=print_format_char ('\n', white, ink, fps); } vfclose_format(fps); vfree(buf); vfree(box_c); return 1; } /*****************************************************************************/ int output_color_html ( Alignment *B,Alignment *S, char *name) { output_color_format (B, S, name, vfopen_html,print_html_string,print_html_char,get_rgb_values_html, vfclose_html); return 1; } int output_reliability_html ( Alignment *B,Alignment *S, char *name) { output_reliability_format (B, S, name, vfopen_html,print_html_string,print_html_char,get_rgb_values_html, vfclose_html); return 1; } FILE_format *print_html_string( char *s, Color *box, Color *ink, FILE_format *fhtml) { int l; int a; l=strlen (s); for ( a=0; a< l; a++) { fhtml=print_html_char (s[a], box, ink, fhtml); } fhtml=print_html_char (CLOSE_HTML_SPAN,NULL,NULL,fhtml); return fhtml; } FILE_format * print_html_char ( int c, Color *box, Color *ink, FILE_format *f) { char html_color[100]; int in_span, new_color; char string[1000]; if (c==CLOSE_HTML_SPAN) { if (f->in_html_span)fprintf ( f->fp, ""); f->in_html_span=0; return f; } in_span=f->in_html_span; new_color=1-(strm (box->html_color_class, f->previous_html_color)); sprintf (f->previous_html_color, "%s", box->html_color_class); sprintf ( html_color, "class=%s", box->html_color_class); if ( c!=' ')sprintf ( string, "%c", c); else sprintf ( string, " "); if ( !in_span && c!='\n' && c!=f->eop) { fprintf ( f->fp, "%s",html_color,string ); f->in_html_span=1; } else if (in_span && !new_color && c!='\n' && c!=f->eop) { fprintf ( f->fp, "%s",string); } else if (in_span && new_color && c!='\n' && c!=f->eop) { fprintf ( f->fp, "%s",html_color,string); } else if ( c=='\n') { if ( f->in_html_span)fprintf ( f->fp, ""); fprintf ( f->fp, "
"); sprintf ( f->previous_html_color, "no_color_set"); f->in_html_span=0; f->n_line++; } return f; } void get_rgb_values_html ( int val, Color *C) { get_rgb_values ( val, C); } FILE_format* vfopen_html ( char *name) { FILE_format*fhtml; Color *color; int a; color=vcalloc ( 1, sizeof (Color)); fhtml=vcalloc ( 1, sizeof ( FILE_format)); fhtml->font=11; fhtml->max_line_ppage=100000; fhtml->line=get_msa_line_length (0, 0);/*N char per line*/ fhtml->x0=15; fhtml->y0=800; fhtml->eop='^'; sprintf ( fhtml->previous_html_color, "no_value_set"); fhtml->fp=vfopen ( name, "w"); fprintf(fhtml->fp,"\n"); fprintf(fhtml->fp,""); return fhtml; } FILE_format* vfclose_html ( FILE_format *fhtml) { if ( fhtml->in_html_span)fprintf(fhtml->fp,""); fprintf(fhtml->fp,"\n"); vfclose ( fhtml->fp); vfree (fhtml); return NULL; } /*****************************************************************************/ /* ascii FUNCTIONS */ /* */ /*****************************************************************************/ int output_color_ascii ( Alignment *B,Alignment *S, char *name) { output_color_format (B, S, name, vfopen_ascii,print_ascii_string,print_ascii_char,get_rgb_values_ascii, vfclose_ascii); return 1; } int output_reliability_ascii ( Alignment *B,Alignment *S, char *name) { output_reliability_format (B, S, name, vfopen_ascii,print_ascii_string,print_ascii_char,get_rgb_values_ascii, vfclose_ascii); return 1; } FILE_format *print_ascii_string( char *s, Color *box, Color *ink, FILE_format *fascii) { int l; int a; l=strlen (s); for ( a=0; a< l; a++) { fascii=print_ascii_char (s[a], box, ink, fascii); } return fascii; } FILE_format * print_ascii_char ( int c, Color *box, Color *ink, FILE_format *f) { if (box->ascii_value>=0 && f->in_seq)fprintf ( f->fp, "%c", box->ascii_value); else fprintf ( f->fp, "%c",c); return f; } void get_rgb_values_ascii ( int val, Color *C) { if ( val==NO_COLOR_RESIDUE)C->ascii_value='-'; else if ( val==NO_COLOR_GAP)C->ascii_value='*'; else if ( val>9)C->ascii_value='#'; else if ( val>=0 && val<=9) C->ascii_value=val+'0'; else C->ascii_value=val; } FILE_format* vfopen_ascii ( char *name) { FILE_format*fascii; fascii=vcalloc ( 1, sizeof ( FILE_format)); fascii->font=11; fascii->max_line_ppage=100000; fascii->line=get_msa_line_length (0,0);/*N char per line*/ fascii->x0=15; fascii->y0=800; fascii->eop='^'; fascii->fp=vfopen ( name, "w"); return fascii; } FILE_format* vfclose_ascii ( FILE_format *fascii) { vfclose ( fascii->fp); vfree (fascii); return NULL; } /*****************************************************************************/ /* seq_score output */ /* */ /*****************************************************************************/ int output_seq_reliability_ascii ( Alignment *B,Alignment *S, char *name) { FILE *fp; int a; int max_len=0; for ( a=0; a< B->nseq; a++) {if ( strlen (B->name[a])>max_len) max_len= strlen ( (B->name[a])); } fp=vfopen ( name, "w"); fprintf ( fp, "ALN_SCORE %d\n", S->score_aln); 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]); vfclose (fp); return 1; } /******************************COPYRIGHT NOTICE*******************************/ /*© Centro de Regulacio Genomica */ /*and */ /*Cedric Notredame */ /*Fri Feb 18 08:27:45 CET 2011 - Revision 596. */ /*All rights reserved.*/ /*This file is part of T-COFFEE.*/ /**/ /* T-COFFEE is free software; you can redistribute it and/or modify*/ /* it under the terms of the GNU General Public License as published by*/ /* the Free Software Foundation; either version 2 of the License, or*/ /* (at your option) any later version.*/ /**/ /* T-COFFEE is distributed in the hope that it will be useful,*/ /* but WITHOUT ANY WARRANTY; without even the implied warranty of*/ /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the*/ /* GNU General Public License for more details.*/ /**/ /* You should have received a copy of the GNU General Public License*/ /* along with Foobar; if not, write to the Free Software*/ /* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA*/ /*............................................... |*/ /* If you need some more information*/ /* cedric.notredame@europe.com*/ /*............................................... |*/ /**/ /**/ /* */ /******************************COPYRIGHT NOTICE*******************************/