27 #include "compareFiles.h" 38 int compareFiles::algorithm(alignment **vectAlignments,
char **fileNames,
float *columnsValue,
int numAlignments,
bool verbosity) {
40 int *numResiduesAlig, *correspNames, *columnSeqMatrix, *columnSeqMatrixAux;
41 int i, j, k, l, m, numSeqs, pairRes, hits, alig = 0;
42 float max = 0, value = 0, **vectHits;
43 bool appearErrors =
false;
49 numSeqs = vectAlignments[0] -> getNumSpecies();
54 names =
new string[numSeqs];
55 correspNames =
new int[numSeqs];
56 numResiduesAlig =
new int[numAlignments];
57 columnSeqMatrix =
new int[numSeqs];
58 vectHits =
new float*[numAlignments];
59 columnSeqMatrixAux =
new int[numSeqs];
66 for(i = 1; i < numAlignments; i++) {
68 if(numSeqs != vectAlignments[i] -> getNumSpecies()) {
69 cerr << endl <<
"ERROR: The files to compare do not have " 70 <<
"the same number of sequences" << endl << endl;
77 vectAlignments[i] -> getSequences(names);
78 if(!vectAlignments[0] -> getSeqNameOrder(names, correspNames)) {
79 cerr << endl <<
"ERROR: The files to compare do not" 80 <<
" have the sequence names" << endl << endl;
90 for(i = 1; ((i < numAlignments) && (!appearErrors)); i++) {
91 vectAlignments[i] -> getSequences(names);
92 vectAlignments[0] -> getSeqNameOrder(names, correspNames);
93 vectAlignments[i] -> setSeqMatrixOrder(correspNames);
99 for(i = 0; ((i < numAlignments) && (!appearErrors)); i++)
100 numResiduesAlig[i] = vectAlignments[i] -> getNumAminos();
105 for(i = 0; ((i < numAlignments) && (!appearErrors)); i++, value = 0) {
115 vectHits[i] =
new float[numResiduesAlig[i]];
116 utils::initlVect(vectHits[i], numResiduesAlig[i], 0);
120 for(j = 0, pairRes = 0, hits = 0; j < numResiduesAlig[i]; j++, pairRes = 0, hits = 0) {
125 vectAlignments[i] -> getColumnSeqMatrix(j, columnSeqMatrix);
132 for(k = 0; k < numSeqs; k++) {
137 if(columnSeqMatrix[k] != 0) {
139 for(l = 0; l < i; l++) {
141 vectAlignments[l] -> getColumnSeqMatrix(columnSeqMatrix[k], k, columnSeqMatrixAux);
144 for(m = k + 1; m < numSeqs; m++)
145 if(columnSeqMatrix[m] != 0) {
146 if(columnSeqMatrix[m] == columnSeqMatrixAux[m])
154 for(l = i + 1; l < numAlignments; l++) {
156 vectAlignments[l] -> getColumnSeqMatrix(columnSeqMatrix[k], k, columnSeqMatrixAux);
159 for(m = k + 1; m < numSeqs; m++)
160 if(columnSeqMatrix[m] != 0) {
161 if(columnSeqMatrix[m] == columnSeqMatrixAux[m])
175 vectHits[i][j] += ((1.0 * hits)/pairRes);
176 value += vectHits[i][j];
185 cout <<
"File:\t\t" << fileNames[i] << endl <<
"Values:\t\tSequences: " << numSeqs
186 <<
"\tResidues: " << numResiduesAlig[i] <<
"\tPond. Hits: " << setw(8)
187 << value <<
"\t%Consistency: " << value/numResiduesAlig[i] << endl;
192 if((value/numResiduesAlig[i]) > max) {
194 max = value/numResiduesAlig[i];
201 if((verbosity) && (!appearErrors)) {
202 cout <<
"\t\t\t\t\t--------------" << endl;
203 cout << endl <<
"File Selected:\t" << fileNames[alig] << endl <<
"Value:\t\t" << max << endl << endl;
210 if((columnsValue != NULL) && (!appearErrors)) {
211 utils::initlVect(columnsValue, numResiduesAlig[alig], -1);
212 for(i = 0; i < numResiduesAlig[alig]; i++)
213 columnsValue[i] = vectHits[alig][i];
219 for(i = 0; ((i < numAlignments) && (!appearErrors)); i++)
220 delete [] vectHits[i];
224 delete [] correspNames;
225 delete [] numResiduesAlig;
226 delete [] columnSeqMatrix;
227 delete [] columnSeqMatrixAux;
233 if(appearErrors)
return -1;
242 bool compareFiles::forceComparison(alignment **vectAlignments,
int numAlignments, alignment *selected,
float *columnsValue) {
244 int *correspNames, *columnSeqMatrix, *columnSeqMatrixAux;
245 int i, j, k, ll, numResidues, numSeqs, pairRes, hit;
246 bool appearErrors =
false;
252 numResidues = selected -> getNumAminos();
253 numSeqs = selected -> getNumSpecies();
260 utils::initlVect(columnsValue, numResidues, 0);
265 names =
new string[numSeqs];
266 correspNames =
new int[numSeqs];
267 columnSeqMatrix =
new int[numSeqs];
268 columnSeqMatrixAux =
new int[numSeqs];
275 for(i = 0; i < numAlignments; i++) {
277 if(numSeqs != vectAlignments[i] -> getNumSpecies()) {
278 cerr << endl <<
"ERROR: The files to compare do not have " 279 <<
"the same number of sequences" << endl << endl;
286 vectAlignments[i] -> getSequences(names);
287 if(!selected -> getSeqNameOrder(names, correspNames)) {
288 cerr << endl <<
"ERROR: The files to compare do not" 289 <<
" have the sequence names" << endl << endl;
300 for(i = 0; i < numAlignments; i++) {
301 vectAlignments[i] -> getSequences(names);
302 selected -> getSeqNameOrder(names, correspNames);
303 vectAlignments[i] -> setSeqMatrixOrder(correspNames);
309 for(i = 0, pairRes = 0, hit = 0; ((i < numResidues) && (!appearErrors)); i++, pairRes = 0, hit = 0) {
314 utils::initlVect(columnSeqMatrix, numSeqs, 0);
315 selected -> getColumnSeqMatrix(i, columnSeqMatrix);
321 for(j = 0; j < numSeqs; j++) {
326 if(columnSeqMatrix[j] != 0) {
327 for(k = 0; k < numAlignments; k++) {
332 utils::initlVect(columnSeqMatrixAux, numSeqs, 0);
333 vectAlignments[k] -> getColumnSeqMatrix(columnSeqMatrix[j], j, columnSeqMatrixAux);
339 for(ll = j + 1; ll < numSeqs; ll++)
340 if(columnSeqMatrix[ll] != 0) {
341 if(columnSeqMatrix[ll] == columnSeqMatrixAux[ll])
353 if(pairRes != 0) columnsValue[i] += ((1.0 * hit)/pairRes);
361 delete [] correspNames;
362 delete [] columnSeqMatrix;
363 delete [] columnSeqMatrixAux;
369 if(appearErrors)
return false;
377 bool compareFiles::applyWindow(
int columns,
int halfWindow,
float *columnsValue) {
385 if(halfWindow > columns/4)
return false;
386 else window = (2 * halfWindow + 1);
392 vectAux =
new float[columns];
393 utils::copyVect(columnsValue, vectAux, columns);
399 for(i = 0; i < columns; i++) {
403 for(j = i - halfWindow, columnsValue[i] = 0; j <= i + halfWindow; j++) {
404 if(j < 0) columnsValue[i] += vectAux[-j];
405 else if(j >= columns)
406 columnsValue[i] += vectAux[((2 * columns - j) - 2)];
407 else columnsValue[i] += vectAux[j];
414 columnsValue[i] /= window;
432 void compareFiles::printStatisticsFileColumns(
int numAminos,
float *compareVect) {
436 cout <<
"| Residue\tConsistency |" << endl;
437 cout <<
"| Number \t Value |" << endl;
438 cout <<
"+---------------------------+" << endl;
445 for(
int i = 0; i < numAminos; i++)
446 cout <<
" " << setw(5) << i + 1 <<
"\t" 447 <<
"\t" << compareVect[i] << endl;
455 void compareFiles::printStatisticsFileAcl(
int numAminos,
float *compareVect) {
457 float refer, *vectAux;
463 vectAux =
new float[numAminos];
464 utils::copyVect(compareVect, vectAux, numAminos);
465 utils::quicksort(vectAux, 0, numAminos-1);
470 cout <<
"| Number of\t \t|\t Cumulative \t% " 471 <<
"Cumulative\t| Consistency |" << endl;
472 cout <<
"| Residues \t% Length\t|\tNumberResid.\t " 473 <<
"Length \t| Value |" << endl;
474 cout <<
"+-------------------------------+------------" 475 <<
"---------------------------+-----------------+" 489 for(i = 1; i < numAminos; i++) {
495 if(refer != vectAux[i]) {
496 cout <<
" " << num <<
"\t\t" << setw(10) << ((
float) num/numAminos * 100.0)
497 <<
"\t\t" << i <<
"\t\t" << setw(10) << ((
float) i/numAminos * 100.0)
498 <<
"\t" << setw(15) << refer << endl;
509 cout <<
" " << num <<
"\t\t" << setw(10) << ((
float) num/numAminos * 100.0)
510 <<
"\t\t" << i <<
"\t\t" << setw(10) << ((
float) i/numAminos * 100.0)
511 <<
"\t" << setw(15) << refer << endl;