1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896
|
/**
* Author: Mark Larkin
*
* Copyright (c) 2007 Des Higgins, Julie Thompson and Toby Gibson.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <exception>
#include <iostream>
#include <sstream>
#include "SubMatrix.h"
#include "matrices.h"
#include "../general/InvalidCombination.cpp"
#include "../general/debuglogObject.h"
namespace clustalw
{
using namespace std;
/**
*
* @param log
*/
SubMatrix::SubMatrix()
: sizenAAMatrix(276),
sizeDNAMatrix(153),
matrixAvgScore(0),
QTDNAHistMatNum(DNAIUB),
QTAAHistMatNum(AAHISTGONNETPAM250),
QTsegmentDNAMatNum(DNAIUB),
QTsegmentAAMatNum(QTAASEGGONNETPAM250)
{
userSeries = false;
setUpCrossReferences();
#if DEBUGFULL
if(logObject && DEBUGLOG)
{
logObject->logMsg("Creating the SubMatrix object\n");
}
#endif
try
{
/* Set up the vectors with the matrices defined in matrices.h
* The matrices are intially defined as a short array, as there is no way
* to intiailize a vector with a {....} list.
*/
blosum30mtVec = new Matrix(blosum30mt, blosum30mt + sizenAAMatrix);
blosum40mtVec = new Matrix(blosum40mt, blosum40mt + sizenAAMatrix);
blosum45mtVec = new Matrix(blosum45mt, blosum45mt + sizenAAMatrix);
blosum62mt2Vec = new Matrix(blosum62mt2, blosum62mt2 + sizenAAMatrix);
blosum80mtVec = new Matrix(blosum80mt, blosum80mt + sizenAAMatrix);
pam20mtVec = new Matrix(pam20mt, pam20mt + sizenAAMatrix);
pam60mtVec = new Matrix(pam60mt, pam60mt + sizenAAMatrix);
pam120mtVec = new Matrix(pam120mt, pam120mt + sizenAAMatrix);
pam350mtVec = new Matrix(pam350mt, pam350mt + sizenAAMatrix);
idmatVec = new Matrix(idmat, idmat + sizenAAMatrix);
gon40mtVec = new Matrix(gon40mt, gon40mt + sizenAAMatrix);
gon80mtVec = new Matrix(gon80mt, gon80mt + sizenAAMatrix);
gon120mtVec = new Matrix(gon120mt, gon120mt + sizenAAMatrix);
gon160mtVec = new Matrix(gon160mt, gon160mt + sizenAAMatrix);
gon250mtVec = new Matrix(gon250mt, gon250mt + sizenAAMatrix);
gon350mtVec = new Matrix(gon350mt, gon350mt + sizenAAMatrix);
clustalvdnamtVec = new Matrix(clustalvdnamt, clustalvdnamt + sizeDNAMatrix);
swgapdnamtVec = new Matrix(swgapdnamt, swgapdnamt + sizeDNAMatrix);
/*
* Set up the vectors for user defined types.
* Probably dont need to do this, as they may not be used. It would be better
* to initialise their size if thye are used.
*/
userMat.resize(NUMRES * NUMRES);
pwUserMat.resize(NUMRES * NUMRES);
userDNAMat.resize(NUMRES * NUMRES);
pwUserDNAMat.resize(NUMRES * NUMRES);
QTscoreUserMatrix.resize(NUMRES * NUMRES);
QTscoreUserDNAMatrix.resize(NUMRES * NUMRES);
QTsegmentDNAMatrix.resize(NUMRES * NUMRES);
QTsegmentAAMatrix.resize(NUMRES * NUMRES);
userMatSeries.resize(MAXMAT); // Maximum number of matrices
vector<Matrix>::iterator firstM = userMatSeries.begin();
vector<Matrix>::iterator lastM = userMatSeries.end();
while(firstM != lastM)
{
firstM->resize(NUMRES * NUMRES);
firstM++;
}
// Maybe I should put this in with the other xref intialisations!
AAXrefseries.resize(MAXMAT);
vector<Xref>::iterator firstX = AAXrefseries.begin();
vector<Xref>::iterator lastX = AAXrefseries.end();
while(firstX != lastX)
{
firstX->resize(NUMRES + 1);
firstX++;
}
// Set the defaults.
matrixNum = 3;
matrixName = new string("gonnet");
DNAMatrixNum = 1;
DNAMatrixName = new string("iub");
pwMatrixNum = 3;
pwMatrixName = new string("gonnet");
pwDNAMatrixNum = 1;
pwDNAMatrixName = new string("iub");
}
catch(const exception &ex)
{
cerr << ex.what() << endl;
cerr << "Terminating program. Cannot continue\n";
exit(1);
}
}
void SubMatrix::setValuesToDefault()
{
matrixAvgScore = 0;
QTDNAHistMatNum = DNAIUB;
QTAAHistMatNum = AAHISTGONNETPAM250;
QTsegmentDNAMatNum = DNAIUB;
QTsegmentAAMatNum = QTAASEGGONNETPAM250;
userSeries = false;
matrixNum = 3;
DNAMatrixNum = 1;
pwMatrixNum = 3;
pwDNAMatrixNum = 1;
}
/**
* The destructor frees up any dynamically allocated memory.
*/
SubMatrix::~SubMatrix()
{
delete blosum30mtVec;
delete blosum40mtVec;
delete blosum45mtVec;
delete blosum62mt2Vec;
delete blosum80mtVec;
delete pam20mtVec;
delete pam60mtVec;
delete pam120mtVec;
delete pam350mtVec;
delete idmatVec;
delete gon40mtVec;
delete gon80mtVec;
delete gon120mtVec;
delete gon160mtVec;
delete gon250mtVec;
delete gon350mtVec;
delete clustalvdnamtVec;
delete swgapdnamtVec;
delete matrixName;
delete DNAMatrixName;
delete pwMatrixName;
delete pwDNAMatrixName;
}
/**
* This function sets up the initial cross references.
*/
void SubMatrix::setUpCrossReferences()
{
char c1, c2;
short i, j, maxRes;
defaultAAXref.resize(NUMRES + 1);
defaultDNAXref.resize(NUMRES + 1);
string aminoAcidOrder = "ABCDEFGHIKLMNPQRSTVWXYZ";
string nucleicAcidOrder = "ABCDGHKMNRSTUVWXY";
/*
* I also need to resize the user defined xrefs.
*/
DNAXref.resize(NUMRES + 1);
AAXref.resize(NUMRES + 1);
pwAAXref.resize(NUMRES + 1);
pwDNAXref.resize(NUMRES + 1);
QTscoreXref.resize(NUMRES + 1);
QTscoreDNAXref.resize(NUMRES + 1);
QTsegmentDNAXref.resize(NUMRES + 1);
QTsegmentAAXref.resize(NUMRES + 1);
/*
* set up cross-reference for default matrices hard-coded in matrices.h
*/
for (i = 0; i < NUMRES; i++)
{
defaultAAXref[i] = -1;
}
for (i = 0; i < NUMRES; i++)
{
defaultDNAXref[i] = -1;
}
maxRes = 0;
for (i = 0; (c1 = aminoAcidOrder[i]); i++)
{
for (j = 0; (c2 = userParameters->getAminoAcidCode(j)); j++)
{
if (c1 == c2)
{
defaultAAXref[i] = j;
maxRes++;
break;
}
}
if ((defaultAAXref[i] == - 1) && (aminoAcidOrder[i] != '*'))
{
utilityObject->error("residue %c in matrices.h is not recognised",
aminoAcidOrder[i]);
}
}
maxRes = 0;
for (i = 0; (c1 = nucleicAcidOrder[i]); i++)
{
for (j = 0; (c2 = userParameters->getAminoAcidCode(j)); j++)
{
if (c1 == c2)
{
defaultDNAXref[i] = j;
maxRes++;
break;
}
}
if ((defaultDNAXref[i] == - 1) && (nucleicAcidOrder[i] != '*'))
{
utilityObject->error("nucleic acid %c in matrices.h is not recognised",
nucleicAcidOrder[i]);
}
}
}
/**
* The function getPairwiseMatrix is called by the user to get the correct sub matrix for the
* pairwise alignment stage. It calls getMatrix to actually calculate the matrix.
* This function provides an interface for the user. It allows the user to get the matrix
* they wish to use for the pairwise alignment part.
* @param matrix[][]
* @param scale
* @param matAvg
* @return
*/
int SubMatrix::getPairwiseMatrix(int matrix[NUMRES][NUMRES], PairScaleValues& scale,
int& matAvg)
{
int _maxRes; // Local copy.
/* Pointers to Matrix and xref to use in calculation */
Matrix* _matPtr;
Xref* _matXref;
#if DEBUGFULL
if(logObject && DEBUGLOG)
{
logObject->logMsg("In the function getPairwiseMatrix: \n");
}
#endif
string matrixPointer;
string xrefPointer;
#ifdef OS_MAC
scale.intScale = 10;
#else
scale.intScale = 100;
#endif
scale.gapOpenScale = scale.gapExtendScale = 1.0;
if (userParameters->getDNAFlag())
{
#if DEBUGFULL
if(logObject && DEBUGLOG)
{
string msg = " (DNA AND Pairwise) " + *pwDNAMatrixName + "\n";
logObject->logMsg(msg);
}
#endif
if (pwDNAMatrixName->compare("iub") == 0)
{
matrixPointer = "swgapdnamtVec"; xrefPointer = "defaultDNAXref";
_matPtr = swgapdnamtVec;
_matXref = &defaultDNAXref;
}
else if (pwDNAMatrixName->compare("clustalw") == 0)
{
matrixPointer = "clustalvdnamtVec"; xrefPointer = "defaultDNAXref";
_matPtr = clustalvdnamtVec;
_matXref = &defaultDNAXref;
scale.gapOpenScale = 0.6667;
scale.gapExtendScale = 0.751;
}
else
{
matrixPointer = "pwUserDNAMat"; xrefPointer = "pwDNAXref";
_matPtr = &pwUserDNAMat;
_matXref = &pwDNAXref;
}
_maxRes = getMatrix(_matPtr, _matXref, matrix, true, scale.intScale);
if (_maxRes == 0)
{
return ((int) -1);
}
float _transitionWeight = userParameters->getTransitionWeight();
// Mark change 17-5-07
matrix[0][4] = static_cast<int>(_transitionWeight * matrix[0][0]);
matrix[4][0] = static_cast<int>(_transitionWeight * matrix[0][0]);
matrix[2][11] = static_cast<int>(_transitionWeight * matrix[0][0]);
matrix[11][2] = static_cast<int>(_transitionWeight * matrix[0][0]);
matrix[2][12] = static_cast<int>(_transitionWeight * matrix[0][0]);
matrix[12][2] = static_cast<int>(_transitionWeight * matrix[0][0]);
}
else
{
#if DEBUGFULL
if(logObject && DEBUGLOG)
{
string msg = " (Protein AND Pairwise) " + *pwMatrixName + "\n";
logObject->logMsg(msg);
}
#endif
if (pwMatrixName->compare("blosum") == 0)
{
matrixPointer = "blosum30mtVec"; xrefPointer = "defaultAAXref";
_matPtr = blosum30mtVec;
_matXref = &defaultAAXref;
}
else if (pwMatrixName->compare("pam") == 0)
{
matrixPointer = "pam350mtVec"; xrefPointer = "defaultAAXref";
_matPtr = pam350mtVec;
_matXref = &defaultAAXref;
}
else if (pwMatrixName->compare("gonnet") == 0)
{
matrixPointer = "gon250mtVec"; xrefPointer = "defaultAAXref";
_matPtr = gon250mtVec;
scale.intScale /= 10;
_matXref = &defaultAAXref;
}
else if (pwMatrixName->compare("id") == 0)
{
matrixPointer = "idmatVec"; xrefPointer = "defaultAAXref";
_matPtr = idmatVec;
_matXref = &defaultAAXref;
}
else
{
matrixPointer = "pwUserMat"; xrefPointer = "pwAAXref";
_matPtr = &pwUserMat;
_matXref = &pwAAXref;
}
_maxRes = getMatrix(_matPtr, _matXref, matrix, true, scale.intScale);
if (_maxRes == 0)
{
return ((int) -1);
}
}
#if DEBUGFULL
if(logObject && DEBUGLOG)
{
ostringstream outs;
outs << " Called getMatrix with "
<< matrixPointer << " and " << xrefPointer << ".\n"
<< " intScale = " << scale.intScale << ", gapOpenScale = "
<< scale.gapOpenScale << ", gapExtendScale = " << scale.gapExtendScale
<< "\n\n";
logObject->logMsg(outs.str());
}
#endif
matAvg = matrixAvgScore;
return _maxRes;
}
/**
* The function getProfileAlignMatrix provides an interface for the user to get
* the matrix to be used in the profile alignment. This depends on the matrix series
* that was chosen, and also on the percent identity.
* @param matrix[][]
* @param pcid
* @param minLen
* @param scaleParam
* @param matAvg
* @return
*/
int SubMatrix::getProfileAlignMatrix(int matrix[NUMRES][NUMRES], double pcid, int minLen,
PrfScaleValues& scaleParam, int& matAvg)
{
bool found = false;
bool errorGiven = false;
bool _negMatrix = userParameters->getUseNegMatrix();
int i = 0, j = 0;
int _maxRes = 0;
scaleParam.intScale = 100;
string matrixPointer;
string xrefPointer;
#if DEBUGFULL
if(logObject && DEBUGLOG)
{
logObject->logMsg("In the function getProfileAlignMatrix: \n");
}
#endif
if (userParameters->getDNAFlag())
{
#if DEBUGFULL
if(logObject && DEBUGLOG)
{
ostringstream outs;
outs << " (DNA AND Multiple align) "<< DNAMatrixName->c_str() << "\n";
logObject->logMsg(outs.str());
}
#endif
scaleParam.scale = 1.0;
if (DNAMatrixName->compare("iub") == 0)
{
_matPtr = swgapdnamtVec;
_matXref = &defaultDNAXref;
matrixPointer = "swgapdnamtVec"; xrefPointer = "defaultDNAXref";
}
else if (DNAMatrixName->compare("clustalw") == 0)
{
_matPtr = clustalvdnamtVec;
_matXref = &defaultDNAXref;
scaleParam.scale = 0.66;
matrixPointer = "clustalvdnamtVec"; xrefPointer = "defaultDNAXref";
}
else
{
_matPtr = &userDNAMat;
_matXref = &DNAXref;
matrixPointer = "userDNAMat"; xrefPointer = "DNAXref";
}
_maxRes = getMatrix(_matPtr, _matXref, matrix, _negMatrix,
static_cast<int>(scaleParam.intScale)); // Mark change 17-5-07
if (_maxRes == 0)
{
return ((int) - 1);
}
float _transitionWeight = userParameters->getTransitionWeight();
// fix suggested by Chanan Rubin at Compugen
matrix[(*_matXref)[0]][(*_matXref)[4]] =
static_cast<int>(_transitionWeight * matrix[0][0]);
matrix[(*_matXref)[4]][(*_matXref)[0]] =
static_cast<int>(_transitionWeight * matrix[0][0]);
matrix[(*_matXref)[2]][(*_matXref)[11]] =
static_cast<int>(_transitionWeight * matrix[0][0]);
matrix[(*_matXref)[11]][(*_matXref)[2]] =
static_cast<int>(_transitionWeight * matrix[0][0]);
matrix[(*_matXref)[2]][(*_matXref)[12]] =
static_cast<int>(_transitionWeight * matrix[0][0]);
matrix[(*_matXref)[12]][(*_matXref)[2]] =
static_cast<int>(_transitionWeight * matrix[0][0]);
}
else // Amino acid alignment!!!!
{
#if DEBUGFULL
if(logObject && DEBUGLOG)
{
ostringstream outs;
outs << " (Protein AND Multiple align) "<< matrixName->c_str() << "\n";
logObject->logMsg(outs.str());
}
#endif
scaleParam.scale = 0.75;
if (matrixName->compare("blosum") == 0)
{
scaleParam.scale = 0.75;
if (_negMatrix || userParameters->getDistanceTree() == false)
{
_matPtr = blosum40mtVec;
matrixPointer = "blosum40mtVec";
}
else if (pcid > 80.0)
{
_matPtr = blosum80mtVec;
matrixPointer = "blosum80mtVec";
}
else if (pcid > 60.0)
{
_matPtr = blosum62mt2Vec;
matrixPointer = "blosum62mt2Vec";
}
else if (pcid > 40.0)
{
_matPtr = blosum45mtVec;
matrixPointer = "blosum45mtVec";
}
else if (pcid > 30.0)
{
scaleParam.scale = 0.5;
_matPtr = blosum45mtVec;
matrixPointer = "blosum45mtVec";
}
else if (pcid > 20.0)
{
scaleParam.scale = 0.6;
_matPtr = blosum45mtVec;
matrixPointer = "blosum45mtVec";
}
else
{
scaleParam.scale = 0.6;
_matPtr = blosum30mtVec;
matrixPointer = "blosum30mtVec";
}
_matXref = &defaultAAXref;
xrefPointer = "defaultAAXref";
}
else if (matrixName->compare("pam") == 0)
{
scaleParam.scale = 0.75;
if (_negMatrix || userParameters->getDistanceTree() == false)
{
_matPtr = pam120mtVec;
matrixPointer = "pam120mtVec";
}
else if (pcid > 80.0)
{
_matPtr = pam20mtVec;
matrixPointer = "pam20mtVec";
}
else if (pcid > 60.0)
{
_matPtr = pam60mtVec;
matrixPointer = "pam60mtVec";
}
else if (pcid > 40.0)
{
_matPtr = pam120mtVec;
matrixPointer = "pam120mtVec";
}
else
{
_matPtr = pam350mtVec;
matrixPointer = "pam350mtVec";
}
_matXref = &defaultAAXref;
xrefPointer = "defaultAAXref";
}
else if (matrixName->compare("gonnet") == 0)
{
scaleParam.scale /= 2.0;
if (_negMatrix || userParameters->getDistanceTree() == false)
{
_matPtr = gon250mtVec;
matrixPointer = "gon250mtVec";
}
else if (pcid > 35.0)
{
_matPtr = gon80mtVec;
scaleParam.scale /= 2.0;
matrixPointer = "gon80mtVec";
}
else if (pcid > 25.0)
{
if (minLen < 100)
{
_matPtr = gon250mtVec;
matrixPointer = "gon250mtVec";
}
else
{
_matPtr = gon120mtVec;
matrixPointer = "gon120mtVec";
}
}
else
{
if (minLen < 100)
{
_matPtr = gon350mtVec;
matrixPointer = "gon350mtVec";
}
else
{
_matPtr = gon160mtVec;
matrixPointer = "gon160mtVec";
}
}
_matXref = &defaultAAXref;
xrefPointer = "defaultAAXref";
scaleParam.intScale /= 10;
}
else if (matrixName->compare("id") == 0)
{
_matPtr = idmatVec;
_matXref = &defaultAAXref;
xrefPointer = "defaultAAXref";
matrixPointer = "idmatVec";
}
else if (userSeries)
{
_matPtr = NULL;
found = false;
for (i = 0; i < matSeries.nmat; i++)
{
if (pcid >= matSeries.mat[i].llimit && pcid <=
matSeries.mat[i].ulimit)
{
j = i;
found = true;
break;
}
}
if (found == false)
{
if (!errorGiven)
{
utilityObject->warning(
"\nSeries matrix not found for sequence percent identity = %d.\n""(Using first matrix in series as a default.)\n""This alignment may not be optimal!\n""SUGGESTION: Check your matrix series input file and try again.", (int)pcid);
}
errorGiven = true;
j = 0;
}
_matPtr = matSeries.mat[j].matptr;
_matXref = matSeries.mat[j].AAXref;
// this gives a scale of 0.5 for pcid=llimit and 1.0 for pcid=ulimit
scaleParam.scale = 0.5 + (pcid - matSeries.mat[j].llimit) / (
(matSeries.mat[j].ulimit - matSeries.mat[j].llimit) *2.0);
xrefPointer = "matSeries.mat[j].AAXref";
matrixPointer = "matSeries.mat[j].matptr";
}
else
{
_matPtr = &userMat;
_matXref = &AAXref;
xrefPointer = "AAXref";
matrixPointer = "userMat";
}
_maxRes = getMatrix(_matPtr, _matXref, matrix, _negMatrix,
static_cast<int>(scaleParam.intScale));
if (_maxRes == 0)
{
cerr << "Error: matrix " << matrixName << " not found\n";
return ( - 1);
}
}
#if DEBUGFULL
if(logObject && DEBUGLOG)
{
ostringstream outs;
outs << " Called getMatrix with "
<< matrixPointer << " and " << xrefPointer << ".\n"
<< " intScale = " << scaleParam.intScale << ", scale = "
<< scaleParam.scale << ", pcid = " << pcid << "\n\n";
logObject->logMsg(outs.str());
}
#endif
matAvg = matrixAvgScore;
return _maxRes;
}
/**
* The function getMatrix is what the other parts of the code call to get a useable
* substitution matrix. This is stored in matrix[NUMRES][NUMRES].
* @param matptr
* @param xref
* @param matrix[][]
* @param negFlag
* @param scale
* @return
*/
int SubMatrix::getMatrix(Matrix* matptr, Xref* xref, int matrix[NUMRES][NUMRES],
bool negFlag, int scale, bool minimise)
{
int ggScore = 0;
int grScore = 0;
int i, j, k, ix = 0;
int ti, tj;
int maxRes;
int av1, av2, av3, min, max;
for (i = 0; i < NUMRES; i++)
{
for (j = 0; j < NUMRES; j++)
{
matrix[i][j] = 0;
}
}
ix = 0;
maxRes = 0;
for (i = 0; i <= userParameters->getMaxAA(); i++)
{
ti = (*xref)[i];
for (j = 0; j <= i; j++)
{
tj = (*xref)[j];
if ((ti != - 1) && (tj != - 1))
{
k = (*matptr)[ix];
if (ti == tj)
{
matrix[ti][ti] = k * scale;
maxRes++;
}
else
{
matrix[ti][tj] = k * scale;
matrix[tj][ti] = k * scale;
}
ix++;
}
}
}
--maxRes;
av1 = av2 = av3 = 0;
for (i = 0; i <= userParameters->getMaxAA(); i++)
{
for (j = 0; j <= i; j++)
{
av1 += matrix[i][j];
if (i == j)
{
av2 += matrix[i][j];
}
else
{
av3 += matrix[i][j];
}
}
}
av1 /= (maxRes * maxRes) / 2;
av2 /= maxRes;
av3 = static_cast<int>(av3 / (((float)(maxRes * maxRes - maxRes)) / 2));
matrixAvgScore = - av3;
min = max = matrix[0][0];
for (i = 0; i <= userParameters->getMaxAA(); i++)
for (j = 1; j <= i; j++)
{
if (matrix[i][j] < min)
{
min = matrix[i][j];
}
if (matrix[i][j] > max)
{
max = matrix[i][j];
}
}
//cout << "MAX = " << max << "\n";
if(!minimise)
{
/*
if requested, make a positive matrix - add -(lowest score) to every entry
*/
if (negFlag == false)
{
if (min < 0)
{
for (i = 0; i <= userParameters->getMaxAA(); i++)
{
ti = (*xref)[i];
if (ti != - 1)
{
for (j = 0; j <= userParameters->getMaxAA(); j++)
{
tj = (*xref)[j];
if (tj != - 1)
{
matrix[ti][tj] -= min;
}
}
}
}
}
}
// local copies of the gap positions
int _gapPos1 = userParameters->getGapPos1();
int _gapPos2 = userParameters->getGapPos2();
for (i = 0; i < userParameters->getGapPos1(); i++)
{
matrix[i][_gapPos1] = grScore;
matrix[_gapPos1][i] = grScore;
matrix[i][_gapPos2] = grScore;
matrix[_gapPos2][i] = grScore;
}
matrix[_gapPos1][_gapPos1] = ggScore;
matrix[_gapPos2][_gapPos2] = ggScore;
matrix[_gapPos2][_gapPos1] = ggScore;
matrix[_gapPos1][_gapPos2] = ggScore;
}
else
{
// DO THE SAGA MATRIX
for (i = 0; i <= userParameters->getMaxAA(); i++)
{
for (j = 0; j <= userParameters->getMaxAA(); j++)
{
matrix[i][j] = max - matrix[i][j];
}
}
}
maxRes += 2;
return (maxRes);
}
/**
* The function getUserMatFromFile is used to read in a user defined matrix.
* @param str
* @param alignResidueType
* @param alignType
* @return
*/
bool SubMatrix::getUserMatFromFile(char *str, int alignResidueType, int alignType)
{
int maxRes;
FILE *infile;
// Need to check if the values are a valid combination!
checkResidueAndAlignType(alignResidueType, alignType);
if(userParameters->getMenuFlag())
{
utilityObject->getStr(string("Enter name of the matrix file"), line2);
}
else
{
line2 = string(str);
}
if(line2.size() == 0)
{
return false;
}
if((infile = fopen(line2.c_str(), "r")) == NULL)
{
utilityObject->error("Cannot find matrix file [%s]", line2.c_str());
return false;
}
strcpy(str, line2.c_str());
// Find out which part of the code we are reading the matrix in for.
mat = getUserMatAddress(alignResidueType, alignType);
xref = getUserXrefAddress(alignResidueType, alignType);
if ((alignResidueType == Protein) && (alignType == MultipleAlign))
{
// Try read in a matrix series.
maxRes = readMatrixSeries(str, userMat, AAXref);
}
else // Read in a single matrix!!!
{
maxRes = readUserMatrix(str, *mat, *xref);
}
if (maxRes <= 0) return false;
return true;
}
/**
* The function compareMatrices is used to compare 2 matrices that have been read in.
* It will compare them in a given region. It will not compare all of them, as some of it
* will be random memory.
* @param mat1[][]
* @param mat2[][]
*/
void SubMatrix::compareMatrices(int mat1[NUMRES][NUMRES], int mat2[NUMRES][NUMRES])
{
int same = 1;
for(int row = 0; row < NUMRES; row++)
{
for(int col = 0; col < NUMRES; col++)
{
if(mat1[row][col] != mat2[row][col])
{
same = 0;
cout << "The row is " << row << ". The column is " << col << endl;
break; // It is not the same. End the loop.
}
}
}
if(same == 0)
{
cout << "It was not the same\n";
}
else
{
cout << "It is the same\n";
}
}
/**
* This function is simply to display the results of the getMatrix function.
* This is so that I can compare it to the original clustal version of it.
* @param mat[][]
*/
void SubMatrix::printGetMatrixResults(int mat[NUMRES][NUMRES])
{
ofstream outfile("getmatrix.out");
if(!outfile)
cerr<<"oops failed to open !!!\n";
for(int row = 0; row < NUMRES; row++)
{
for(int col = 0; col < NUMRES; col++)
{
if((mat[row][col] > 9) || (mat[row][col] < 0))
{
outfile <<" "<< mat[row][col]<<",";
}
else
{
outfile <<" "<< mat[row][col]<<",";
}
}
outfile<<"\n";
}
}
/**
* This function is from the old interface. It simply calls the readMatrixSeries
* function. It seems to only be called from the commandline part.
* @param str
* @return
*/
bool SubMatrix::getUserMatSeriesFromFile(char *str)
{
int maxRes;
FILE *infile;
if(userParameters->getMenuFlag()) // Check if we are using menu!
{
utilityObject->getStr(string("Enter name of the matrix file"), line2);
}
else
{
//strcpy(lin2,str);
line2 = string(str);
}
if(line2.size() == 0) return false;
if((infile = fopen(line2.c_str(), "r"))==NULL)
{
utilityObject->error("Cannot find matrix file [%s]",line2.c_str());
return false;
}
strcpy(str, line2.c_str());
maxRes = readMatrixSeries(str, userMat, AAXref);
if (maxRes <= 0) return false;
return true;
}
/*
* The function readMatrixSeries is used to read in a series of matrices from a file.
* It calls readUserMatrix to read in the individual matrices. The matrices are stored
* in userMatSeries.
*/
int SubMatrix::readMatrixSeries(const char *fileName, Matrix& userMat, Xref& xref)
{
FILE *fd = NULL;
char mat_fileName[FILENAMELEN];
char inline1[1024];
int maxRes = 0;
int nmat;
int n, llimit, ulimit;
if (fileName[0] == '\0')
{
utilityObject->error("comparison matrix not specified");
return ((int)0);
}
if ((fd = fopen(fileName, "r")) == NULL)
{
utilityObject->error("cannot open %s", fileName);
return ((int)0);
}
/* check the first line to see if it's a series or a single matrix */
while (fgets(inline1, 1024, fd) != NULL)
{
if (commentline(inline1))
{
continue;
}
if (utilityObject->lineType(inline1, "CLUSTAL_SERIES"))
{
userSeries = true;
}
else
{
userSeries = false;
}
break;
}
/* it's a single matrix */
if (userSeries == false)
{
fclose(fd);
maxRes = readUserMatrix(fileName, userMat, xref);
return (maxRes);
}
/* it's a series of matrices, find the next MATRIX line */
nmat = 0;
matSeries.nmat = 0;
while (fgets(inline1, 1024, fd) != NULL)
{
if (commentline(inline1))
{
continue;
}
if (utilityObject->lineType(inline1, "MATRIX")) // Have found a matrix
{
if (sscanf(inline1 + 6, "%d %d %s", &llimit, &ulimit, mat_fileName)
!= 3)
{
utilityObject->error("Bad format in file %s\n", fileName);
fclose(fd);
return ((int)0);
}
if (llimit < 0 || llimit > 100 || ulimit < 0 || ulimit > 100)
{
utilityObject->error("Bad format in file %s\n", fileName);
fclose(fd);
return ((int)0);
}
if (ulimit <= llimit)
{
utilityObject->error("in file %s: lower limit is greater than upper (%d-%d)\n",
fileName, llimit, ulimit);
fclose(fd);
return ((int)0);
}
n = readUserMatrix(mat_fileName, userMatSeries[nmat],
AAXrefseries[nmat]);
//cout << "Read in matrix number " << nmat << "\n"; // NOTE Testing!!!!!
char nameOfFile[] = "matrix";
printInFormat(userMatSeries[nmat], nameOfFile);
if (n <= 0)
{
utilityObject->error("Bad format in matrix file %s\n", mat_fileName);
fclose(fd);
return ((int)0);
}
matSeries.mat[nmat].llimit = llimit;
matSeries.mat[nmat].ulimit = ulimit;
matSeries.mat[nmat].matptr = &userMatSeries[nmat];
matSeries.mat[nmat].AAXref = &AAXrefseries[nmat];
nmat++;
if(nmat >= MAXMAT)
{
// We have read in all the matrices that we can read into this vector
// Write a message to the screen, and break out of loop.
cerr << "The matrix series file has more entries than allowed in \n"
<< "a user defined series. The most that are allowed is "
<< MAXMAT << ".\n"
<< "The first " << MAXMAT << " have been read in and will be used.\n";
break; // Get out of the loop!
}
}
}
fclose(fd);
matSeries.nmat = nmat;
maxRes = n;
return (maxRes);
}
/*
* This function is used to read a single user matrix from a file.
* It can be called repeatedly if there are multiple matrices in the file.
*/
int SubMatrix::readUserMatrix(const char *fileName, Matrix& userMat, Xref& xref)
{
double f;
FILE *fd;
int numargs, farg;
int i, j, k = 0;
char codes[NUMRES];
char inline1[1024];
char *args[NUMRES + 4];
char c1, c2;
int ix1, ix = 0;
int maxRes = 0;
float scale;
if (fileName[0] == '\0')
{
utilityObject->error("comparison matrix not specified");
return ((int)0);
}
if ((fd = fopen(fileName, "r")) == NULL)
{
utilityObject->error("cannot open %s", fileName);
return ((int)0);
}
maxRes = 0;
while (fgets(inline1, 1024, fd) != NULL)
{
if (commentline(inline1))
{
continue;
}
if (utilityObject->lineType(inline1, "CLUSTAL_SERIES"))
{
utilityObject->error("in %s - single matrix expected.", fileName);
fclose(fd);
return ((int)0);
}
/*
read residue characters.
*/
k = 0;
for (j = 0; j < (int)strlen(inline1); j++)
{
if (isalpha((int)inline1[j]))
{
codes[k++] = inline1[j];
}
if (k > NUMRES)
{
utilityObject->error("too many entries in matrix %s", fileName);
fclose(fd);
return ((int)0);
}
}
codes[k] = '\0';
break;
}
if (k == 0)
{
utilityObject->error("wrong format in matrix %s", fileName);
fclose(fd);
return ((int)0);
}
/*
cross-reference the residues
*/
for (i = 0; i < NUMRES; i++)
{
xref[i] = - 1;
}
maxRes = 0;
for (i = 0; (c1 = codes[i]); i++)
{
for (j = 0; (c2 = userParameters->getAminoAcidCode(j)); j++)
if (c1 == c2)
{
xref[i] = j;
maxRes++;
break;
}
if ((xref[i] == - 1) && (codes[i] != '*'))
{
utilityObject->warning("residue %c in matrix %s not recognised", codes[i],
fileName);
}
}
/*
get the weights
*/
ix = ix1 = 0;
while (fgets(inline1, 1024, fd) != NULL)
{
if (inline1[0] == '\n')
{
continue;
}
if (inline1[0] == '#' || inline1[0] == '!')
{
break;
}
numargs = getArgs(inline1, args, (int)(k + 1));
if (numargs < maxRes)
{
utilityObject->error("wrong format in matrix %s", fileName);
fclose(fd);
return ((int)0);
}
if (isalpha(args[0][0]))
{
farg = 1;
}
else
{
farg = 0;
}
/* decide whether the matrix values are float or decimal */
scale = 1.0;
for (i = 0; i < (int)strlen(args[farg]); i++)
if (args[farg][i] == '.')
{
/* we've found a float value */
scale = 10.0;
break;
}
for (i = 0; i <= ix; i++)
{
if (xref[i] != - 1)
{
f = atof(args[i + farg]);
userMat[ix1++] = (short)(f *scale);
}
}
ix++;
}
if (ix != k + 1)
{
utilityObject->error("wrong format in matrix %s", fileName);
fclose(fd);
return ((int)0);
}
userMat.resize(ix1 + 1);
maxRes += 2;
fclose(fd);
return (maxRes);
}
/**
*
* @param inline1
* @param args[]
* @param max
* @return
*/
int SubMatrix::getArgs(char *inline1,char *args[],int max)
{
char *inptr;
int i;
inptr = inline1;
for (i = 0; i <= max; i++)
{
if ((args[i] = strtok(inptr, " \t\n")) == NULL)
{
break;
}
inptr = NULL;
}
return (i);
}
/**
*
* @return
*/
int SubMatrix::getMatrixNum()
{
return matrixNum;
}
/**
*
* @return
*/
int SubMatrix::getDNAMatrixNum()
{
return DNAMatrixNum;
}
/**
*
* @return
*/
int SubMatrix::getPWMatrixNum()
{
return pwMatrixNum;
}
/**
*
* @return
*/
int SubMatrix::getPWDNAMatrixNum()
{
return pwDNAMatrixNum;
}
/**
* The function setCurrentNameAndNum is used to select a matrix series.
* This will then be used for the alignment. The matrices will change, but the
* series remains the same. We can set the series for pairwise/full for both
* protein and DNA. NOTE: The default can be set to user defined matrices.
* @param _matrixName
* @param _matrixNum
* @param alignResidueType
* @param alignType
*/
void SubMatrix::setCurrentNameAndNum(string _matrixName, int _matrixNum,
int alignResidueType,int alignType)
{
// Check if the values are valid.
checkResidueAndAlignType(alignResidueType, alignType);
string residue;
string align;
if((alignResidueType == Protein) && (alignType == Pairwise))
{
residue = "Protein"; align = "Pairwise";
pwMatrixNum = _matrixNum;
pwMatrixName = new string(_matrixName);
}
else if((alignResidueType == Protein) && (alignType == MultipleAlign))
{
residue = "Protein"; align = "MultipleAlign";
matrixNum = _matrixNum;
matrixName = new string(_matrixName);
}
else if((alignResidueType == DNA) && (alignType == Pairwise))
{
residue = "DNA"; align = "Pairwise";
pwDNAMatrixNum = _matrixNum;
pwDNAMatrixName = new string(_matrixName);
}
else if((alignResidueType == DNA) && (alignType == MultipleAlign))
{
residue = "DNA"; align = "MultipleAlign";
DNAMatrixNum = _matrixNum;
DNAMatrixName = new string(_matrixName);
}
#if DEBUGFULL
if(logObject && DEBUGLOG)
{
ostringstream outs;
outs << "The matrix/matrix series has been changed for "
<< "(" << residue << " AND " << align << ")."
<< " New value: " << _matrixName << "\n\n";
logObject->logMsg(outs.str());
}
#endif
}
/**
*
* @param alignResidueType
* @param alignType
* @return
*/
int SubMatrix::getMatrixNumForMenu(int alignResidueType, int alignType)
{
checkResidueAndAlignType(alignResidueType, alignType);
if((alignResidueType == Protein) && (alignType == Pairwise))
{
return pwMatrixNum;
}
else if((alignResidueType == Protein) && (alignType == MultipleAlign))
{
return matrixNum;
}
else if((alignResidueType == DNA) && (alignType == Pairwise))
{
return pwDNAMatrixNum;
}
else if((alignResidueType == DNA) && (alignType == MultipleAlign))
{
return DNAMatrixNum;
}
else
return -100; // NOTE NONE of these. I need to put in better error checking
}
/**
*
* @param line
* @return
*/
bool SubMatrix::commentline(char* line)
{
int i;
if (line[0] == '#')
{
return true;
}
for (i = 0; line[i] != '\n' && line[i] != EOS; i++)
{
if (!isspace(line[i]))
{
return false;
}
}
return true;
}
/**
* This function prints out the vector to the file specified by name.
* The vector is printed out in a triangular format, the same as the way
* the arrays are displayed in matrices.h. This function is for testing purposes.
* @param temp
* @param name
*/
void SubMatrix::printInFormat(vector<short>& temp, char* name)
{
char nameOfFile[30];
strcpy(nameOfFile, name);
strcat(nameOfFile, ".out");
ofstream outfile(nameOfFile);
if(!outfile)
cerr<<"oops failed to open !!!\n";
outfile<<"short "<<name<<"[]{\n";
int numOnCurrentLine = 1;
int soFar = 0;
for(int i = 0; i < (int)temp.size(); i++)
{
if(soFar == numOnCurrentLine)
{
outfile<<"\n";
soFar = 0;
numOnCurrentLine++;
}
if((temp[i] > 9) || (temp[i] < 0))
{
outfile <<" "<< temp[i]<<",";
}
else
{
outfile <<" "<< temp[i]<<",";
}
// Now increment so far
soFar++;
// Check to see if the next element is the last element
if((i + 1) == (int)temp.size() - 1)
{
// Print out the last element. Then a curly brace, and break.
if((temp[i+1] > 9) || (temp[i+1] < 0))
{
outfile <<" "<< temp[i + 1]<<"};\n";
}
else
{
outfile <<" "<< temp[i + 1]<<"};\n";
}
break;
}
}
ofstream outfile2("temp.out");
for(int i = 0; i < (int)temp.size(); i++)
{
outfile2 << temp[i] << " ";
}
}
/**
*
* @param temp
* @param name
*/
void SubMatrix::printVectorToFile(vector<short>& temp, char* name)
{
char nameOfFile[30];
strcpy(nameOfFile, name);
strcat(nameOfFile, ".out");
ofstream outfile(nameOfFile);
if(!outfile)
cerr<<"oops failed to open !!!\n";
for(int i = 0; i < (int)temp.size(); i++)
{
if((temp[i] > 9) || (temp[i] < 0))
{
outfile <<" "<< temp[i]<<",";
}
else
{
outfile <<" "<< temp[i]<<",";
}
}
outfile.close();
}
/**
*
* @param alignResidueType
* @param alignType
* @return
*/
Matrix* SubMatrix::getUserMatAddress(int alignResidueType, int alignType)
{
if((alignResidueType == Protein) && (alignType == Pairwise))
{
return &pwUserMat;
}
else if((alignResidueType == Protein) && (alignType == MultipleAlign))
{
return &userMat;
}
else if((alignResidueType == DNA) && (alignType == Pairwise))
{
return &pwUserDNAMat;
}
else if((alignResidueType == DNA) && (alignType == MultipleAlign))
{
return &userDNAMat;
}
return NULL;
}
/**
*
* @param alignResidueType
* @param alignType
* @return
*/
Xref* SubMatrix::getUserXrefAddress(int alignResidueType, int alignType)
{
if((alignResidueType == Protein) && (alignType == Pairwise))
{
return &pwAAXref;
}
else if((alignResidueType == Protein) && (alignType == MultipleAlign))
{
return &AAXref;
}
else if((alignResidueType == DNA) && (alignType == Pairwise))
{
return &pwDNAXref;
}
else if((alignResidueType == DNA) && (alignType == MultipleAlign))
{
return &DNAXref;
}
return NULL;
}
/**
* This is an error handling routine. If an incorrect combination of values
* is given, it will terminate the program.
* @param alignResidueType
* @param alignType
*/
void SubMatrix::checkResidueAndAlignType(int alignResidueType, int alignType)
{
if(((alignResidueType != 0) && (alignResidueType != 1))
|| ((alignType != 0) && (alignType != 1)))
{
InvalidCombination ex(alignResidueType, alignType);
ex.whatHappened();
exit(1);
}
}
/**
* The function tempInterface is used to call the SubMatrix in the way it is
* supposed to be used. It is for testing purposes.
* @param alignResidueType
* @param alignType
*/
void SubMatrix::tempInterface(int alignResidueType, int alignType)
{
char userFile[FILENAMELEN + 1];
userParameters->setDNAFlag(true);
strcpy(userFile, "mat1");
userParameters->setMenuFlag(false);
getUserMatFromFile(userFile, DNA, Pairwise);
setCurrentNameAndNum(userFile, 4, 3, Pairwise);
setCurrentNameAndNum("gonnet", 4, Protein, Pairwise);
}
/**
* A single matrix is used in scoring the alignment. This is Blosum45. This is the
* function to get it.
* @param matrix[][]
* @return
*/
int SubMatrix::getAlnScoreMatrix(int matrix[NUMRES][NUMRES])
{
int _maxNumRes;
/*
//_maxNumRes = getMatrix(blosum45mtVec, &defaultAAXref, matrix, true, 100);
_maxNumRes = getMatrix(blosum45mtVec, &defaultAAXref, matrix, false, 1, true);
//_maxNumRes = getMatrix(blosum62mt2Vec, &defaultAAXref, matrix, true, 100);
*/
// 1.83 style
_maxNumRes = getMatrix(blosum45mtVec, &defaultAAXref, matrix, true, 100);
return _maxNumRes;
}
/**
* This function is used to get the matrix that will be used for the calculation of
* the histogram. The histogram values are used in ClustalQt.
* @param matrix[][]
* @param matNum
* @param dnaMatNum
*/
void SubMatrix::getQTMatrixForHistogram(int matrix[NUMRES][NUMRES])
{
Matrix* _matPtrLocal;
Xref* _matXrefLocal;
int maxRes;
if(userParameters->getDNAFlag())
{
if (QTDNAHistMatNum == DNAUSERDEFINED)
{
_matPtrLocal = &QTscoreUserDNAMatrix;
_matXrefLocal = &QTscoreDNAXref;
}
else if (QTDNAHistMatNum == DNACLUSTALW)
{
_matPtrLocal = clustalvdnamtVec;
_matXrefLocal = &defaultDNAXref;
}
else
{
_matPtrLocal = swgapdnamtVec;
_matXrefLocal = &defaultDNAXref;
}
}
else
{
if (QTAAHistMatNum == AAHISTIDENTITY)
{
_matPtrLocal = idmatVec;
_matXrefLocal = &defaultAAXref;
}
else if (QTAAHistMatNum == AAHISTGONNETPAM80)
{
_matPtrLocal = gon80mtVec;
_matXrefLocal = &defaultAAXref;
}
else if (QTAAHistMatNum == AAHISTGONNETPAM120)
{
_matPtrLocal = gon120mtVec;
_matXrefLocal = &defaultAAXref;
}
else if (QTAAHistMatNum == AAHISTUSER)
{
_matPtrLocal = &QTscoreUserMatrix;
_matXrefLocal = &QTscoreXref;
}
else if (QTAAHistMatNum == AAHISTGONNETPAM350)
{
_matPtrLocal = gon350mtVec;
_matXrefLocal = &defaultAAXref;
}
else // Default
{
_matPtrLocal = gon250mtVec;
_matXrefLocal = &defaultAAXref;
}
}
maxRes = getMatrix(_matPtrLocal, _matXrefLocal, matrix, false, 100);
}
void SubMatrix::getQTMatrixForLowScoreSeg(int matrix[NUMRES][NUMRES])
{
Matrix* _matPtrLocal;
Xref* _matXrefLocal;
int maxRes;
int _maxAA = userParameters->getMaxAA();
int max = 0;
int offset;
if(userParameters->getDNAFlag())
{
if (QTsegmentDNAMatNum == DNAUSERDEFINED)
{
_matPtrLocal = &QTsegmentDNAMatrix;
_matXrefLocal = &QTsegmentDNAXref;
}
else if (QTsegmentDNAMatNum == DNACLUSTALW)
{
_matPtrLocal = clustalvdnamtVec;
_matXrefLocal = &defaultDNAXref;
}
else
{
_matPtrLocal = swgapdnamtVec;
_matXrefLocal = &defaultDNAXref;
}
/* get a positive matrix - then adjust it according to scale */
maxRes = getMatrix(_matPtrLocal, _matXrefLocal, matrix, false, 100);
/* find the maximum value */
for(int i = 0; i <= _maxAA; i++)
{
for(int j = 0; j <= _maxAA; j++)
{
if(matrix[i][j] > max)
{
max = matrix[i][j];
}
}
}
/* subtract max * scale / 2 from each matrix value */
offset = static_cast<int>(static_cast<float>(max *
userParameters->getQTlowScoreDNAMarkingScale()) / 20.0);
for(int i = 0; i <= _maxAA; i++)
{
for(int j = 0; j <= _maxAA; j++)
{
matrix[i][j] -= offset;
}
}
}
else
{
if (QTsegmentAAMatNum == QTAASEGGONNETPAM80)
{
_matPtrLocal = gon80mtVec;
_matXrefLocal = &defaultAAXref;
}
else if (QTsegmentAAMatNum == QTAASEGGONNETPAM120)
{
_matPtrLocal = gon120mtVec;
_matXrefLocal = &defaultAAXref;
}
else if (QTsegmentAAMatNum == QTAASEGUSER)
{
_matPtrLocal = &QTsegmentAAMatrix;
_matXrefLocal = &QTsegmentAAXref;
}
else if (QTsegmentAAMatNum == QTAASEGGONNETPAM350)
{
_matPtrLocal = gon350mtVec;
_matXrefLocal = &defaultAAXref;
}
else
{
_matPtrLocal = gon250mtVec;
_matXrefLocal = &defaultAAXref;
}
/* get a negative matrix */
maxRes = getMatrix(_matPtrLocal, _matXrefLocal, matrix, true, 100);
}
}
bool SubMatrix::getQTLowScoreMatFromFile(char* fileName, bool dna)
{
int maxRes;
FILE *infile;
line2 = string(fileName);
if(line2.size() == 0)
{
return false;
}
if((infile = fopen(line2.c_str(), "r")) == NULL)
{
utilityObject->error("Cannot find matrix file [%s]", line2.c_str());
return false;
}
strcpy(fileName, line2.c_str());
if(dna)
{
maxRes = readUserMatrix(fileName, QTsegmentDNAMatrix, QTsegmentDNAXref);
}
else
{
maxRes = readUserMatrix(fileName, QTsegmentAAMatrix, QTsegmentAAXref);
}
if (maxRes <= 0)
{
return false;
}
return true;
}
bool SubMatrix::getAAScoreMatFromFile(char *str)
{
int maxRes;
FILE *infile;
line2 = string(str);
if(line2.size() == 0)
{
return false;
}
if((infile = fopen(line2.c_str(), "r")) == NULL)
{
utilityObject->error("Cannot find matrix file [%s]", line2.c_str());
return false;
}
strcpy(str, line2.c_str());
maxRes = readUserMatrix(str, QTscoreUserMatrix, QTscoreXref);
if (maxRes <= 0)
{
return false;
}
return true;
}
bool SubMatrix::getDNAScoreMatFromFile(char *str)
{
int maxRes;
FILE *infile;
line2 = string(str);
if(line2.size() == 0)
{
return false;
}
if((infile = fopen(line2.c_str(), "r")) == NULL)
{
utilityObject->error("Cannot find matrix file [%s]", line2.c_str());
return false;
}
strcpy(str, line2.c_str());
maxRes = readUserMatrix(str, QTscoreUserDNAMatrix, QTscoreDNAXref);
if (maxRes <= 0)
{
return false;
}
return true;
}
}
|