1 /***********************************************
2 * # Copyright 2009-2010. Liu Yongchao
3 * # Contact: Liu Yongchao, School of Computer Engineering,
4 * # Nanyang Technological University.
5 * # Emails: liuy0039@ntu.edu.sg; nkcslyc@hotmail.com
7 * # GPL version 3.0 applies.
9 * ************************************************/
15 #include "MSAReadMatrix.h"
19 ////////////////////////////////////////////////////////////
20 // extern variables for scoring matrix data
21 ////////////////////////////////////////////////////////////
22 extern float g_gap_open1, g_gap_open2, g_gap_ext1, g_gap_ext2;
23 extern char *aminos, *bases, matrixtype[20];
24 extern int subst_index[26];
26 extern double sub_matrix[26][26];
27 extern double normalized_matrix[26][26];
29 extern float TEMPERATURE;
30 extern int MATRIXTYPE;
41 char opt; //can be 'P' or 'M'
47 extern argument_decl argument;
49 /////////////////////////////////////////////////////////
50 //sets substitution matrix type
51 ////////////////////////////////////////////////////////
52 void setmatrixtype(int le) {
55 strcpy(matrixtype, "gonnet_160");
58 strcpy(matrixtype, "nuc_simple");
61 strcpy(matrixtype, "CUSTOM");
68 ///////////////////////////////////////////////////////////////////
70 ///////////////////////////////////////////////////////////////////
71 inline int matrixtype_to_int() {
73 if (!strcmp(matrixtype, "nuc_simple"))
75 else if (!strcmp(matrixtype, "gonnet_160"))
82 /////////////////////////////////////////////////////////////////
84 // Can read any scoring matrix as long as it is defined in Matrix.h
85 // AND it is a lower triangular
86 // AND the order of amino acids/bases is mentioned
87 /////////////////////////////////////////////////////////////////
89 inline void read_matrix(score_matrix matrx) {
90 int i, j, basecount, position = 0;
92 bases = (char *) matrx.monomers;
94 basecount = strlen(bases);
96 for (i = 0; i < basecount; i++)
99 for (i = 0; i < basecount; i++)
100 subst_index[bases[i] - 'A'] = i;
103 printf("\nbases read: %d\n", basecount);
105 for (i = 0; i < basecount; i++)
106 for (j = 0; j <= i; j++) {
108 double value = exp(argument.beta * matrx.matrix[position++]);
109 sub_matrix[i][j] = value;
110 sub_matrix[j][i] = value;
114 for (i = 0; i < basecount; i++) {
115 for (j = 0; j < basecount; j++)
116 printf(" %g ", sub_matrix[i][j]);
122 /////////////////////////////////////////////////////////////////
123 // read normalized residue exchange matrix
124 // compute sequence similarity
126 /////////////////////////////////////////////////////////////////
128 inline void read_normalized_matrix(score_matrix matrx) {
129 int i, j, basecount, position = 0;
131 bases = (char *) matrx.monomers;
133 basecount = strlen(bases);
135 for (i = 0; i < basecount; i++)
138 for (i = 0; i < basecount; i++)
139 subst_index[bases[i] - 'A'] = i;
142 printf("\nbases read: %d\n", basecount);
144 for (i = 0; i < basecount; i++)
145 for (j = 0; j <= i; j++) {
147 double value = matrx.matrix[position++];
148 normalized_matrix[i][j] = value;
149 normalized_matrix[j][i] = value;
153 for (i = 0; i < basecount; i++) {
154 for (j = 0; j < basecount; j++)
155 printf(" %g ", normalized_matrix[i][j]);
160 //////////////////////////////////////////////////////////////////////////////////
161 //intialize the arguments (default values)
162 //////////////////////////////////////////////////////////////////////////////////
163 void init_arguments() {
164 float gap_open = 0, gap_ext = 0;
167 le = matrixtype_to_int();
170 strcpy(argument.input, "tempin");
171 argument.matrix = le;
172 argument.gapopen = GAPOPEN;
173 argument.gapext = GAPEXT;
174 argument.T = TEMPERATURE;
175 argument.beta = 1.0 / TEMPERATURE;
178 if (le == 4) //NUC OPTION :default is nuc_simple
180 read_matrix(nuc_simple);
185 else if (le == 160) //PROT option: default is gonnet_160
188 printf("read matrix\n");
189 read_matrix(gonnet_160);
193 read_normalized_matrix(normalized_blosum_30); // add by YE Yongtao
194 } else if (le == 1000) { //Error handling
195 printf("Error: enter a valid matrix type\n");
197 //additional matrices can only be lower triangular
200 //now override the gapopen and gapext
201 if (argument.gapopen != 0.0 || argument.gapext != 0.00)
204 gap_open = -argument.gapopen;
205 gap_ext = -argument.gapext;
209 printf("%f %f %f %d\n", argument.T, gap_open, gap_ext, le);
211 argument.gapopen = gap_open;
212 argument.gapext = gap_ext;