Next version of JABA
[jabaws.git] / binaries / src / tcoffee / t_coffee_source / dev1.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <math.h>
4 #include <stdarg.h>
5 #include <string.h>
6
7 #include "io_lib_header.h"
8 #include "util_lib_header.h"
9 #include "define_header.h"
10 #include "dp_lib_header.h"
11 #include "dev1_lib_header.h"
12
13 //Insert functions here
14 void aln2hitMat_help()
15 {
16         fprintf ( stdout, "\n+aln2hitMat| _MODE_    : how to compare the two positions of the alignment (default:id)");
17         fprintf ( stdout, "\n.................id    : the sequence identity of those two positions");
18         fprintf ( stdout, "\n.............pairscore : the pairwise score of the residues of those two positions");
19         fprintf ( stdout, "\n+aln2hitMat| _MATRIX_  : matrix used for the comparison (idmat, blosum62mt, pam250mt.. default:blosum62mt)\n");
20         exit (EXIT_SUCCESS);
21 }
22
23 void aln2hitMat (Alignment *A, char *phitmat)
24 {
25         float **ffpHitScoreMatrix;
26         int i, j, k, l, s;
27         int nl = A->len_aln;
28         int inseq = A->nseq;
29         int itmpScore;
30         char matrix[100];
31         char mode[100];
32         int isim_count, itotal_count, r1, r2;
33
34 //Initialization for files      
35         char *pcFileName = A->file[0];
36         char prefix[200] ={0};
37         char *hit_matrix_file = vcalloc(200, sizeof (char));
38         char *hit_html_file = vcalloc(200, sizeof (char));
39         int len = (strrchr(pcFileName,'.')?strrchr(pcFileName,'.')-pcFileName:strlen(pcFileName));
40
41         strncpy(prefix, pcFileName, len);       
42         sprintf(hit_matrix_file, "%s%s", prefix, "_aln.hit_matrix");
43         sprintf(hit_html_file, "%s%s", prefix, ".alnhit_html");
44
45         if ( phitmat && strstr ( phitmat, "help"))
46                 aln2hitMat_help();
47
48         if(phitmat == NULL) phitmat = vcalloc(1, sizeof(char)); //such that program could get default value
49
50         strget_param (phitmat, "_MODE_", "id", "%s", mode);
51         strget_param (phitmat, "_MATRIX_", "blosum62mt", "%s", matrix);
52
53         fprintf ( stdout, "[START] aln to hit matrix\n");
54         fprintf ( stdout, "        Mode:%s\n", mode);
55         fprintf ( stdout, "        Matrix:%s\n", matrix);
56
57         int **mat = read_matrice(matrix);
58
59         ffpHitScoreMatrix=vcalloc (nl, sizeof (float*));
60         for(i = 0; i < nl; i++)
61                 ffpHitScoreMatrix[i]=vcalloc (nl-i, sizeof (float));
62
63         fprintf (stdout, "Process positions\n", i);
64         for(i = 0; i < nl; i++)
65         {
66                 fprintf (stdout, "%d, ", i);
67                 for(j = i; j < nl; j++)
68                 {
69                         if(strm (mode, "id"))
70                                 ffpHitScoreMatrix[i][j-i]=generic_get_seq_sim (aln_column2string(A, i), aln_column2string(A, j), (A->cdna_cache)?A->cdna_cache[0]:NULL, matrix);
71                         else if(strm (mode, "pairscore"))
72                         {
73                                 isim_count = itotal_count = 0;
74                                 for (k=0; k< inseq; k++)
75                                 {
76                                         r1=tolower(A->seq_al[k][i]);
77                                         if (is_gap(r1))continue;
78                                         for (l=0; l< inseq; l++)
79                                         {
80                                                 r2=tolower(A->seq_al[l][j]);
81                                                 if (is_gap (r2))continue;                                               
82                                                 s=mat[r2-'A'][r1-'A'];
83                                                 s=(s<=0)?0:1;
84                                                 isim_count += s;
85                                                 itotal_count++;
86                                         }
87                                 }
88                                 r1=(isim_count*100)/itotal_count;
89                                 ffpHitScoreMatrix[i][j-i] = r1;
90                         }
91                         else
92                                 aln2hitMat_help();
93                 }
94         }
95         fprintf (stdout, "\n");
96         output_hit_matrix(hit_matrix_file, ffpHitScoreMatrix, nl);
97
98 //Output Hit Score into color html
99         output_hit_color_html  (A, ffpHitScoreMatrix, nl, hit_html_file);
100         vfree(ffpHitScoreMatrix);
101         vfree(hit_matrix_file);
102         vfree(hit_html_file);
103         fprintf ( stdout, "[END] aln to hit matrix\n");
104 }
105 /*********************************COPYRIGHT NOTICE**********************************/
106 /*© Centro de Regulacio Genomica */
107 /*and */
108 /*Cedric Notredame */
109 /*Tue Oct 27 10:12:26 WEST 2009. */
110 /*All rights reserved.*/
111 /*This file is part of T-COFFEE.*/
112 /**/
113 /*    T-COFFEE is free software; you can redistribute it and/or modify*/
114 /*    it under the terms of the GNU General Public License as published by*/
115 /*    the Free Software Foundation; either version 2 of the License, or*/
116 /*    (at your option) any later version.*/
117 /**/
118 /*    T-COFFEE is distributed in the hope that it will be useful,*/
119 /*    but WITHOUT ANY WARRANTY; without even the implied warranty of*/
120 /*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the*/
121 /*    GNU General Public License for more details.*/
122 /**/
123 /*    You should have received a copy of the GNU General Public License*/
124 /*    along with Foobar; if not, write to the Free Software*/
125 /*    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA*/
126 /*...............................................                                                                                      |*/
127 /*  If you need some more information*/
128 /*  cedric.notredame@europe.com*/
129 /*...............................................                                                                                                                                     |*/
130 /**/
131 /**/
132 /*      */
133 /*********************************COPYRIGHT NOTICE**********************************/