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
|
/**
* Author: Mark Larkin
*
* Copyright (c) 2007 Des Higgins, Julie Thompson and Toby Gibson.
*/
/**
* Changes:
*
* 10-02-07,Nigel Brown(EMBL): changed ifstream to InFileStream to handle
* cross-platform end-of-lines (for dendrograms, not for help file). Remerged
* this change 13-04-07.
*
* Mark 10-5-2007: Bug fix # 42. call getWeightsForQtLowScore function in
* QTcalcWeightsForLowScoreSeg instead of getWeightsFromDistMat.
*
* Mark 22-5-07, changed the distmatrix to be the size of alignObject.numSeqs
* Mark Change 20-6-07, added call to calculateMaxLengths()
* Mark, 3-7-07, Changed getHelp.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <iostream>
#include <fstream>
#include <cstdio>
#include "Clustal.h"
#include "pairwise/FullPairwiseAlign.h"
#include "pairwise/FastPairwiseAlign.h"
#include "multipleAlign/MSA.h"
#include "multipleAlign/LowScoreSegProfile.h"
#include "multipleAlign/Iteration.h"
#include "tree/TreeInterface.h"
#include "general/debuglogObject.h"
#include "general/statsObject.h"
#include "alignment/ObjectiveScore.h"
#include "general/ClustalWResources.h"
#include "Help.h"
#include <ctime>
using namespace std;
namespace clustalw
{
Clustal::Clustal()
{
#ifdef WINDOWS
helpFileName = string("clustalw.hlp");
#else
helpFileName = string("clustalw_help");
#endif
checkTree = true;
newSeq = 0;
sequencesMsg = "\nUse the existing GUIDE TREE file, ";
profile1Msg = "\nUse the existing GUIDE TREE file for Profile 1, " ;
profile2Msg = "\nUse the existing GUIDE TREE file for Profile 2, ";
newProfile1TreePrompt = "\nEnter name for new GUIDE TREE file for profile 1 [";
newProfile2TreePrompt = "\nEnter name for new GUIDE TREE file for profile 2 [";
initInterface();
}
/** ***********************************************************************
* The function align is used to do a full multiple sequence alignment. *
**************************************************************************/
// FIXME: merge doAlignUseOldTree in here
void Clustal::align(string* phylipName, bool createOutput)
{
//time_t start, end;
//double dif;
//start = time (NULL);
//ObjectiveScore score;
//double _score = score.getSagaScore(&alignmentObj);
//cout << "SAGA score " << _score << "\n";
string path;
int count;
AlignmentOutput alignOutput;
if(userParameters->getEmpty() && userParameters->getMenuFlag())
{
utilityObject->error("No sequences in memory. Load sequences first.");
return;
}
userParameters->setStructPenalties1(NONE);
userParameters->setStructPenalties2(NONE);
alignmentObj.clearSecStruct1();
alignmentObj.clearSecStruct2();
utilityObject->getPath(userParameters->getSeqName(), &path);
if(createOutput && (userParameters->getMenuFlag() || !userParameters->getInteractive()))
{
if(!alignOutput.openAlignmentOutput(path))
{
return;
}
}
else if(createOutput)
{
// We are using clustalQT.
// Open all the files.
if(!alignOutput.QTOpenFilesForOutput(QTFileNames))
{
return; // could not open the files.
}
}
if (userParameters->getSaveParameters())
{
userParameters->createParameterOutput();
}
if(userParameters->getResetAlignmentsNew() || userParameters->getResetAlignmentsAll())
{
alignmentObj.resetAlign();
}
if(userParameters->getDisplayInfo())
{
cout << "Start of Pairwise alignments\n";
cout << "Aligning...\n";
}
if(userParameters->getDNAFlag())
{
userParameters->setDNAParams();
}
else
{
userParameters->setProtParams();
}
if (statsObject->isEnabled()) {
statsObject->logInputSeqStats(&alignmentObj);
}
/// STEP 1: PAIRWISE ALIGNMENT TO GENERATE DISTANCE MATRIX
SymMatrix distMat;
int _numSeqs = alignmentObj.getNumSeqs();
distMat.ResizeRect(_numSeqs + 1);
PairwiseAlignBase* pairwiseDist;
if (userParameters->getQuickPairAlign())
{
pairwiseDist = new FastPairwiseAlign();
}
else
{
pairwiseDist = new FullPairwiseAlign();
}
// Generate distance matrix!
pairwiseDist->pairwiseAlign(&alignmentObj, &distMat, 0, _numSeqs, 0, _numSeqs);
delete pairwiseDist;
bool success = false;
auto_ptr<AlignmentSteps> progSteps;
vector<int> seqWeight(_numSeqs + 1);
#if DEBUGFULL
if(logObject && DEBUGLOG)
{
logObject->logMsg("Calling getWeightsAndStepsFromDistMat\n");
}
#endif
TreeInterface calcSteps;
progSteps = calcSteps.getWeightsAndStepsFromDistMat(&seqWeight, &distMat, &alignmentObj,
1, _numSeqs, phylipName, &success);
//cout << "weights and steps calculated!\n";
//end = time (NULL);
//dif = difftime(end, start);
//cout << "It took " << dif << " seconds so Far\n";
if(!success)
{
#if DEBUGFULL
if(logObject && DEBUGLOG)
{
logObject->logMsg("Unsuccessful!!!\n");
}
#endif
return;
}
#if DEBUGFULL
if(logObject && DEBUGLOG)
{
logObject->logMsg("doing multiSeqAlign\n");
}
#endif
MSA* msaObj = new MSA();
count = msaObj->multiSeqAlign(&alignmentObj, &distMat, &seqWeight, progSteps.get(), 0);
delete msaObj;
//cout << "alignment finished!\n";
//end = time (NULL);
//dif = difftime(end, start);
//cout << "It took " << dif << " seconds so Far\n";
if (count <= 0)
{
return;
}
if (userParameters->getMenuFlag())
{
cout << "\n\n\n";
}
/// Do iteration to improve alignment!!!
if(userParameters->getDoRemoveFirstIteration() == ALIGNMENT)
{
//userParameters->setNumIterations(_numSeqs * 2);
Iteration iterateObj;
iterateObj.removeFirstIterate(&alignmentObj);
alignmentObj.calculateMaxLengths(); // Mark Change 20-6-07
if(userParameters->getDisplayInfo())
cout << "Finished iteration\n";
}
if (statsObject->isEnabled()) {
statsObject->logAlignedSeqStats(&alignmentObj);
}
/// STEP 4: OUTPUT THE ALIGNMENT
if(createOutput)
{
alignOutput.createAlignmentOutput(&alignmentObj, 1, _numSeqs);
}
(*phylipName) = "";
//end = time (NULL);
//dif = difftime(end, start);
//cout << "It took " << dif << " seconds\n";
}
/** ****************************************************************************
* The function sequencesAlignToProfile is used to align a set of sequences to *
* a profile *
*******************************************************************************/
void Clustal::sequencesAlignToProfile(string* phylipName)
{
string path;
string treeName;
bool useTree;
int i, j, count;
float dscore;
bool saveSS2;
AlignmentOutput alignOutput;
if(userParameters->getProfile1Empty() && userParameters->getMenuFlag())
{
utilityObject->error("No profile in memory. Input 1st profile first.\n");
return;
}
if(userParameters->getProfile2Empty() && userParameters->getMenuFlag())
{
utilityObject->error("No sequences in memory. Input sequences first.\n");
return;
}
utilityObject->getPath(userParameters->getProfile2Name(), &path);
if(userParameters->getMenuFlag() || !userParameters->getInteractive())
{
if(!alignOutput.openAlignmentOutput(path))
{
return;
}
}
else
{
// We are using clustalQT.
// Open all the files.
if(!alignOutput.QTOpenFilesForOutput(QTFileNames))
{
return; // could not open the files.
}
}
newSeq = alignmentObj.getProfile1NumSeqs() + 1;
// check for secondary structure information for list of sequences
saveSS2 = userParameters->getUseSS2();
if (userParameters->getStructPenalties2() != NONE && userParameters->getUseSS2() == true
&& (alignmentObj.getNumSeqs() - alignmentObj.getProfile1NumSeqs() > 1))
{
if (userParameters->getStructPenalties2() == SECST)
{
utilityObject->warning("\n\nWARNING: ignoring secondary structure for a list of sequences\n\n");
}
else if (userParameters->getStructPenalties2() == GMASK)
{
utilityObject->warning("\n\nWARNING: ignoring gap penalty mask for a list of sequences\n\n");
}
userParameters->setUseSS2(false);
}
DistMatrix distMat;
int _numSeqs = alignmentObj.getNumSeqs();
distMat.ResizeRect(_numSeqs + 1);
//
// Convert to similarities!!!!!!!!
// This is calcualting the similarities of the sequences in the profile part
//
for (i = 1; i <= newSeq; i++)
{
for (j = i + 1; j <= newSeq; j++)
{
dscore = alignmentObj.countid(i,j);
distMat(i, j) = ((double)100.0 - (double)dscore)/(double)100.0;
distMat(j, i) = distMat(i, j);
}
}
//distMat.printArray();
InFileStream _treeFile; //nige
useTree = false;
//
// Note put this into a separate function!!!!!
//
if (_numSeqs >= 2)
{
useTree = useExistingGuideTree(Sequences, phylipName, path);
}
if (userParameters->getSaveParameters())
{
userParameters->createParameterOutput();
}
if(userParameters->getResetAlignmentsNew() || userParameters->getResetAlignmentsAll())
{
alignmentObj.resetProfile2();
}
else
{
alignmentObj.fixGaps();
}
int _length = 0;
if (userParameters->getStructPenalties1() == SECST)
{
_length = alignmentObj.getSeqLength(1);
calcGapPenaltyMask(_length, alignmentObj.getSecStructMask1(),
alignmentObj.getGapPenaltyMask1());
}
if (userParameters->getStructPenalties2() == SECST)
{
_length = alignmentObj.getSeqLength(alignmentObj.getProfile1NumSeqs() + 1);
calcGapPenaltyMask(_length, alignmentObj.getSecStructMask2(),
alignmentObj.getGapPenaltyMask2());
}
// PROGRESSIVE ALIGNMENT ALGORITHM //
vector<int> seqWeights(_numSeqs + 1);
bool success = false;
if (useTree == false) // create the new tree file, if necessary
{
if(userParameters->getDisplayInfo())
{
cout << "Start of Pairwise alignments\n";
cout << "Aligning...\n";
}
if(userParameters->getDNAFlag())
{
userParameters->setDNAParams();
}
else
{
userParameters->setProtParams();
}
// STEP 1: CALCULATE DISTANCE MATRIX USING PAIRWISE ALIGNMENT //
PairwiseAlignBase* pairwiseDist;
if (userParameters->getQuickPairAlign())
{
pairwiseDist = new FastPairwiseAlign();
}
else
{
pairwiseDist = new FullPairwiseAlign();
}
// Generate distance matrix!
pairwiseDist->pairwiseAlign(&alignmentObj, &distMat, 0, _numSeqs, newSeq-2, _numSeqs);
delete pairwiseDist;
if(userParameters->getDisplayInfo())
cout << "\n\n";
TreeInterface calcSeqWeights;
calcSeqWeights.getWeightsFromDistMat(&seqWeights, &distMat, &alignmentObj, 1,
_numSeqs, phylipName, &success);
}
else
{
TreeInterface calcSeqWeights;
calcSeqWeights.getWeightsFromGuideTree(&alignmentObj, &distMat, phylipName,
&seqWeights, 1, _numSeqs, &success);
}
if(!success)
{
return;
}
// If it is true, call the function here to get the seqweights etc from it.
// if users request only the guide tree, return
if (userParameters->getNewTreeFile())
{
return;
}
MSA* msaObj = new MSA();
count = msaObj->seqsAlignToProfile(&alignmentObj, &distMat, &seqWeights, newSeq - 2,
*phylipName);
delete msaObj;
userParameters->setUseSS2(saveSS2);
if (count <= 0)
{
return;
}
if (userParameters->getMenuFlag())
{
cout << "\n\n\n";
}
/// STEP 4: OUTPUT THE ALIGNMENT //
alignOutput.createAlignmentOutput(&alignmentObj, 1, _numSeqs);
(*phylipName) = "";
}
/** ****************************************************************************
* The function profileAlign is used to align two profiles *
*******************************************************************************/
void Clustal::profileAlign(string* p1TreeName, string* p2TreeName)
{
string path;
//string treeName;
bool useTree1, useTree2;
int count, i, j, dscore;
int _profile1NumSeqs = alignmentObj.getProfile1NumSeqs();
AlignmentOutput alignOutput;
if(userParameters->getProfile1Empty() || userParameters->getProfile2Empty())
{
utilityObject->error("No sequences in memory. Load sequences first.\n\n");
return;
}
utilityObject->getPath(userParameters->getProfile1Name(), &path);
if(userParameters->getMenuFlag() || !userParameters->getInteractive())
{
if(!alignOutput.openAlignmentOutput(path))
{
return;
}
}
else
{
// We are using clustalQT.
// Open all the files.
if(!alignOutput.QTOpenFilesForOutput(QTFileNames))
{
return; // could not open the files.
}
}
if(userParameters->getResetAlignmentsNew() || userParameters->getResetAlignmentsAll())
{
alignmentObj.resetProfile1();
alignmentObj.resetProfile2();
}
else
{
alignmentObj.fixGaps();
}
// Check if there exists a tree for profile1
useTree1 = false;
if (_profile1NumSeqs >= 2)
{
useTree1 = useExistingGuideTree(Profile1, p1TreeName, path);
}
// Check if there exists a tree for profile2
useTree2 = false;
utilityObject->getPath(userParameters->getProfile2Name(), &path);
if (alignmentObj.getNumSeqs() - _profile1NumSeqs >= 2)
{
useTree2 = useExistingGuideTree(Profile2, p2TreeName, path);
}
if (userParameters->getSaveParameters())
{
userParameters->createParameterOutput();
}
int _length = 0;
if (userParameters->getStructPenalties1() == SECST)
{
_length = alignmentObj.getSeqLength(1);
calcGapPenaltyMask(_length, alignmentObj.getSecStructMask1(),
alignmentObj.getGapPenaltyMask1());
}
if (userParameters->getStructPenalties2() == SECST)
{
_length = alignmentObj.getSeqLength(_profile1NumSeqs + 1);
calcGapPenaltyMask(_length, alignmentObj.getSecStructMask2(),
alignmentObj.getGapPenaltyMask2());
}
// Declare the distance matrix
DistMatrix distMat;
int _numSeqs = alignmentObj.getNumSeqs();
distMat.ResizeRect(_numSeqs + 1);
if (useTree1 == false)
{
if (_profile1NumSeqs >= 2)
{
for (i = 1; i <= _profile1NumSeqs; i++)
{
for (j = i + 1; j <= _profile1NumSeqs; j++)
{
dscore = static_cast<int>(alignmentObj.countid(i,j));
distMat(i, j) = (100.0 - dscore)/100.0;
distMat(j, i) = distMat(i, j);
}
}
utilityObject->getPath(userParameters->getProfile1Name(), &path);
// We need to get the name of the file first because the message is different!
if(userParameters->getMenuFlag())
{
promptForNewGuideTreeName(Profile1, p1TreeName, path);
}
else
{
string treeName;
treeName = path + "dnd";
p1TreeName = new string(treeName);
}
}
if (useTree2 == false)
{
if(_numSeqs - _profile1NumSeqs >= 2)
{
for (i = 1 + _profile1NumSeqs; i <= _numSeqs; i++)
{
for (j = i + 1; j <= _numSeqs; j++)
{
dscore = static_cast<int>(alignmentObj.countid(i,j));
distMat(i, j) = (100.0 - dscore) / 100.0;
distMat(j, i) = distMat(i, j);
}
}
utilityObject->getPath(userParameters->getProfile2Name(), &path);
if(userParameters->getMenuFlag())
{
promptForNewGuideTreeName(Profile2, p2TreeName, path);
}
else
{
string treeName;
treeName = path + "dnd";
p2TreeName = new string(treeName);
}
}
}
}
bool success = false;
vector<int> prof1Weight, prof2Weight;
prof1Weight.resize(_profile1NumSeqs);
prof2Weight.resize(_numSeqs);
TreeInterface tree;
tree.getWeightsForProfileAlign(&alignmentObj, &distMat, p1TreeName, &prof1Weight,
p2TreeName, &prof2Weight, _numSeqs, _profile1NumSeqs,
useTree1, useTree2, &success);
if(!success)
{
return;
}
// do an initial alignment to get the pairwise identities between the two
// profiles - used to set parameters for the final alignment
MSA* msaObj = new MSA();
alignmentObj.resetProfile1();
alignmentObj.resetProfile2();
count = msaObj->doProfileAlign(&alignmentObj, &distMat, &prof1Weight, &prof2Weight);
delete msaObj;
if (count == 0)
{
return;
}
if(userParameters->getMenuFlag())
{
cout << "\n\n\n";
}
alignOutput.createAlignmentOutput(&alignmentObj, 1, _numSeqs);
(*p1TreeName) = "";
(*p2TreeName) = "";
}
void Clustal::doGuideTreeOnly(string* phylipName)
{
string path;
if(userParameters->getEmpty())
{
utilityObject->error("No sequences in memory. Load sequences first.\n");
return;
}
userParameters->setStructPenalties1(NONE);
userParameters->setStructPenalties2(NONE);
alignmentObj.clearSecStruct1();
alignmentObj.clearSecStruct2();
if(userParameters->getResetAlignmentsNew() || userParameters->getResetAlignmentsAll())
{
alignmentObj.resetAlign();
}
utilityObject->getPath(userParameters->getSeqName(), &path);
int _numSeqs = alignmentObj.getNumSeqs();
if (_numSeqs < 2)
{
utilityObject->error("Less than 2 sequences in memory. Phylogenetic tree cannot be built.\n");
return;
}
if (userParameters->getSaveParameters())
{
userParameters->createParameterOutput();
}
if(userParameters->getDisplayInfo())
{
cout << "Start of Pairwise alignments\n";
cout << "Aligning...\n";
}
if(userParameters->getDNAFlag())
{
userParameters->setDNAParams();
}
else
{
userParameters->setProtParams();
}
///STEP 1: PAIRWISE ALIGNMENT TO GENERATE DISTANCE MATRIX //
DistMatrix distMat;
distMat.ResizeRect(_numSeqs + 1);
PairwiseAlignBase* pairwiseDist;
if (userParameters->getQuickPairAlign())
{
pairwiseDist = new FastPairwiseAlign();
}
else
{
pairwiseDist = new FullPairwiseAlign();
}
// Generate distance matrix!
pairwiseDist->pairwiseAlign(&alignmentObj, &distMat, 0, _numSeqs, 0, _numSeqs);
delete pairwiseDist;
/* AW DEBUG
fprintf(stdout, "\nDEBUG: distance matrix following...\n");
distMat.printArray();
*/
bool success = false;
TreeInterface tree;
tree.generateTreeFromDistMat(&distMat, &alignmentObj, 1, _numSeqs, phylipName, &success);
if(userParameters->getResetAlignmentsNew() || userParameters->getResetAlignmentsAll())
{
alignmentObj.resetAlign();
}
(*phylipName) = "";
}
// FIXME this is to 90% identical with align(), please merge
void Clustal::doAlignUseOldTree(string* phylipName)
{
string path;
int count;
AlignmentOutput alignOutput;
if(userParameters->getEmpty())
{
utilityObject->error("No sequences in memory. Load sequences first.\n");
return;
}
userParameters->setStructPenalties1(NONE);
userParameters->setStructPenalties2(NONE);
alignmentObj.clearSecStruct1();
alignmentObj.clearSecStruct2();
utilityObject->getPath(userParameters->getSeqName(), &path);
if(userParameters->getMenuFlag() || !userParameters->getInteractive())
{
if(!alignOutput.openAlignmentOutput(path))
{
return;
}
}
else
{
// We are using clustalQT.
// Open all the files.
if(!alignOutput.QTOpenFilesForOutput(QTFileNames))
{
return; // could not open the files.
}
}
if(userParameters->getResetAlignmentsNew() || userParameters->getResetAlignmentsAll())
{
alignmentObj.resetAlign();
}
int _numSeqs = alignmentObj.getNumSeqs();
DistMatrix distMat;
distMat.ResizeRect(_numSeqs + 1);
utilityObject->getPath(userParameters->getSeqName(), &path);
if (_numSeqs >= 2)
{
if(userParameters->getMenuFlag())
{
phylipName = new string(path);
*phylipName = *phylipName + "dnd";
string message, answer;
message = "\nEnter a name for the guide tree file [" + *phylipName + "]";
utilityObject->getStr(message, answer);
if(!answer.empty())
{
phylipName = new string(answer);
}
}
if(userParameters->getMenuFlag() || !userParameters->getInteractive())
{
InFileStream _treeFile; //nige
_treeFile.open(phylipName->c_str());
if(!_treeFile.is_open())
{
utilityObject->error("Cannot open tree file [%s]\n", phylipName->c_str());
return;
}
_treeFile.close();
}
}
else
{
if(userParameters->getDisplayInfo())
{
cout << "Start of Pairwise alignments\n";
cout << "Aligning...\n";
}
if(userParameters->getDNAFlag())
{
userParameters->setDNAParams();
}
else
{
userParameters->setProtParams();
}
PairwiseAlignBase* pairwiseDist;
if (userParameters->getQuickPairAlign())
{
pairwiseDist = new FastPairwiseAlign();
}
else
{
pairwiseDist = new FullPairwiseAlign();
}
// Generate distance matrix!
pairwiseDist->pairwiseAlign(&alignmentObj, &distMat, 0, _numSeqs, 0, _numSeqs);
delete pairwiseDist;
}
if (userParameters->getSaveParameters())
{
userParameters->createParameterOutput();
}
auto_ptr<AlignmentSteps> progSteps;
vector<int> seqWeights(_numSeqs + 1);
bool success = false;
TreeInterface tree;
progSteps = tree.getWeightsAndStepsFromTree(&alignmentObj, &distMat, phylipName,
&seqWeights, 1, _numSeqs, &success);
if(!success)
{
return;
}
MSA* msaObj = new MSA();
count = msaObj->multiSeqAlign(&alignmentObj, &distMat, &seqWeights, progSteps.get(), 0);
delete msaObj;
if (count <= 0)
{
return;
}
if (userParameters->getMenuFlag())
{
cout << "\n\n\n";
}
// same as in align()
if(userParameters->getDoRemoveFirstIteration() == ALIGNMENT)
{
//userParameters->setNumIterations(_numSeqs * 2);
Iteration iterateObj;
iterateObj.removeFirstIterate(&alignmentObj);
alignmentObj.calculateMaxLengths(); // Mark Change 20-6-07
if(userParameters->getDisplayInfo())
cout << "Finished iteration\n";
}
alignOutput.createAlignmentOutput(&alignmentObj, 1, _numSeqs);
phylipName = new string("");
}
void Clustal::getFullHelp()
{
vector<string> markers;
Help myhelp;
bool showtitle = true;
markers = myhelp.ListSectionMarkers();
for (unsigned int i=0; i<markers.size(); i++) {
string m = markers[i];
getHelp(m, showtitle);
}
}
void Clustal::getHelp(char helpPointer, bool printTitle)
{
string s = "";
s += helpPointer;
Clustal::getHelp(s, printTitle);
}
/*
* Andreas Wilm (UCD): edited to support new help system (separate
* file now which is compiled in)
*
* Author?
* The clustal help file is called clustalw_help. Should be in the same
* directory. I have changed it to a C++ style implementation. I am taking
* out support for VMS until later. We will see if we are still supporting that platform.
*/
void Clustal::getHelp(string helpPointer, bool printTitle)
{
Help myhelp;
string helpString;
helpString = myhelp.GetSection(helpPointer);
if (printTitle) {
helpString = "\n\n>> HELP " +
helpPointer +
" << " +
myhelp.GetSectionTitle(helpPointer) +
"\n\n" +
helpString;
}
if(! userParameters->getMenuFlag())
{
cout << helpString;
}
else
{
string::size_type lastPos = 0;
string::size_type pos = helpString.find_first_of("\n", lastPos);
int nlines = 0;
while (pos != string::npos)
{
cout << helpString.substr(lastPos, pos - lastPos);
nlines++;
if(nlines >= PAGE_LEN)
{
char tempChar;
cout << "\nPress [RETURN] to continue or X to stop ";
cin.get(tempChar);
if(toupper(tempChar) == 'X')
{
return;
}
else
{
nlines = 0;
}
}
lastPos = pos; //helpString.find_first_not_of("\n", pos);
pos = helpString.find_first_of("\n", lastPos+1);
//cerr << "DEBUG: pos=" << pos << " lastPos=" << lastPos << "/" << helpString.length() << "\n";
}
}
}
/**
* The wrap functions will be used with interface classes to perform the tasks
* that were previously done there.
*/
int Clustal::sequenceInput(bool append, string *offendingSeq)
{
int code;
// If we are not appending, we need to clear the Alignment object.
if(!append)
{
alignmentObj.clearAlignment();
}
FileReader readSeqFile;
code = readSeqFile.seqInput(&alignmentObj, append, offendingSeq);
return code;
}
/**
* profile1Input is a wrapper function for the profileInput. This is because the
* other classes dont have access to FileReader
*/
int Clustal::profile1Input(string profile1Name)
{
int code;
// I need to clear out the Alignment object.
alignmentObj.clearAlignment();
userParameters->setProfileNum(1);
userParameters->setSeqName(profile1Name);
userParameters->setProfile1Name(profile1Name);
FileReader readProfileFile;
code = readProfileFile.profileInput(&alignmentObj);
// If we are using the commandline check if there are seqs!
if(!userParameters->getInteractive())
{
// AW: FIXME code should be handled higher up the stack and check all codes
// also, shouldnt we use utilityObject->error()?
if(code != OK)
{
if (code==NOSEQUENCESINFILE)
cerr << "ERROR: There are no sequences in profile2 file." << std::endl;
else if (code==ALLNAMESNOTDIFFERENT)
cerr << "ERROR: Not all sequence names are different" << std::endl;
else
cerr << "ERROR: Unhandled error code (" << code << ") returned from profileInput.\n";
// AW: should we really exit here? What if called from clustalx?
exit(2);
}
}
return code;
}
/**
* profile2Input is a wrapper function for the profileInput. This is because the
* other classes dont have access to FileReader
*/
int Clustal::profile2Input(string profile2Name)
{
int code;
if(userParameters->getProfileNum() == 2)
{
// Remove the sequences from the previous one.
int numSeqsProfile1 = alignmentObj.getProfile1NumSeqs();
alignmentObj.resizeSeqArray(numSeqsProfile1 + 1);
// Clear anything from profile2 in alignment.
alignmentObj.clearSecStruct2();
}
userParameters->setProfileNum(2);
userParameters->setSeqName(profile2Name);
userParameters->setProfile2Name(profile2Name);
FileReader readProfileFile;
cout << "before profileInput\n";
code = readProfileFile.profileInput(&alignmentObj);
cout << "after profileInput\n";
if(!userParameters->getInteractive())
{
// AW: FIXME code should be handled higher up the stack and check all codes
// also, shouldnt we use utilityObject->error()?
if(code != OK) {
if (code==NOSEQUENCESINFILE)
cerr << "ERROR: There are no sequences in profile2 file." << std::endl;
else if (code==ALLNAMESNOTDIFFERENT)
cerr << "ERROR: Not all sequence names are different" << std::endl;
else
cerr << "ERROR: Unhandled error code (" << code << ") returned from profileInput.\n";
// AW: should we really exit here? What if called from clustalx?
// DD: fixed
if(!userParameters->getGui())
exit(2);
}
}
return code;
}
/**
* The function commandline_readseq is called by the command line to
* read in the sequences. It also prints out the names. This was
* previously done by the command line parser.
*/
int Clustal::commandLineReadSeq(int firstSeq)
{
// Clear the alignment, although obviously there shouldnt be anything in it.
alignmentObj.clearAlignment();
userParameters->setProfileNum(0);
int code = 0;
string offendingSeq;
FileReader readInputFile;
code = readInputFile.readSeqs(&alignmentObj, firstSeq, &offendingSeq);
if(code != OK)
{
if(code == CANNOTOPENFILE)
{
utilityObject->error("Cannot open input file. No alignment!\n");
}
else if(code == NOSEQUENCESINFILE)
{
utilityObject->error("No sequences in file. No alignment!\n");
}
else if(code == ALLNAMESNOTDIFFERENT)
{
utilityObject->error("Multiple sequences found with same name (found %s at least twice)!", offendingSeq.c_str());
}
else if(code == EMPTYSEQUENCE)
{
utilityObject->error("Empty sequences found: %s\n", offendingSeq.c_str());
}
else if(code == SEQUENCETOOBIG)
{
utilityObject->error("Sequence(s) too big: %s\n", offendingSeq.c_str());
}
else if(code == BADFORMAT)
{
utilityObject->error("Sequences are badly formatted!\n");
}
else
{
utilityObject->error("\nThere was a problem reading in the file. No alignment!\n");
}
exit(-1);
}
alignmentObj.printSequencesAddedInfo();
userParameters->setEmpty(false);
return code;
}
/*
* The function outputNow is used to output the alignment. It can be called by the
* menu or command line parser.
*/
void Clustal::outputNow()
{
if(alignmentObj.getNumSeqs() > 0)
{
string path = "";
if(!userParameters->getMenuFlag())
{
string _seqName = userParameters->getSeqName();
utilityObject->getPath(_seqName, &path);
}
AlignmentOutput alignmentOutput;
alignmentOutput.openAlignmentOutput(path);
alignmentOutput.createAlignmentOutput(&alignmentObj, 1, alignmentObj.getNumSeqs());
}
else
{
utilityObject->error("No sequences have been loaded\n");
}
}
void Clustal::phylogeneticTree(string* phylipName, string* clustalName, string* distName,
string* nexusName, string pimName)
{
TreeNames treeNames;
treeNames.clustalName = *clustalName;
treeNames.distName = *distName;
treeNames.nexusName = *nexusName;
treeNames.phylipName = *phylipName;
treeNames.pimName = pimName;
TreeInterface tree;
tree.treeFromAlignment(&treeNames, &alignmentObj);
}
void Clustal::bootstrapTree(string* phylipName, string* clustalName, string* nexusName)
{
TreeNames treeNames;
treeNames.clustalName = *clustalName;
treeNames.nexusName = *nexusName;
treeNames.phylipName = *phylipName;
TreeInterface tree;
tree.bootstrapTree(&treeNames, &alignmentObj);
}
void Clustal::initInterface()
{
userParameters->setEmpty(true);
userParameters->setProfile1Empty(true);
userParameters->setProfile2Empty(true);
}
/**
* The function calcGapPenaltyMask is used to calculate the gapMask from the secondary
* structure information.
*/
void Clustal::calcGapPenaltyMask(int prfLength, vector<char>* mask, vector<char>* gapMask)
{
int i,j;
vector<char> structMask;
structMask.resize(prfLength + 1);
int _helixEndPlus = userParameters->getHelixEndPlus();
int _helixEndMinus = userParameters->getHelixEndMinus();
int _strandEndPlus = userParameters->getStrandEndPlus();
int _strandEndMinus = userParameters->getStrandEndMinus();
i = 0;
while (i < prfLength)
{
if (tolower((*mask)[i]) == 'a' || (*mask)[i] == '$')
{
for (j = -_helixEndPlus; j < 0; j++)
{
if(i + j < (int)structMask.size())
{
if ((i + j >= 0) && (tolower(structMask[i + j]) != 'a') &&
(tolower(structMask[i + j]) != 'b'))
{
structMask[i + j] = 'a';
}
}
}
for (j = 0; j < _helixEndMinus; j++)
{
if (i + j >= prfLength || (tolower((*mask)[i + j]) != 'a'
&& (*mask)[i + j] != '$'))
{
break;
}
structMask[i + j] = 'a';
}
i += j;
while (tolower((*mask)[i]) == 'a' || (*mask)[i] == '$')
{
if (i >= prfLength)
{
break;
}
if ((*mask)[i] == '$')
{
structMask[i] = 'A';
i++;
break;
}
else
{
structMask[i] = (*mask)[i];
}
i++;
}
for (j = 0; j < _helixEndMinus; j++)
{
if ((i - j - 1 >= 0) && (tolower((*mask)[i - j - 1]) == 'a'
|| (*mask)[i - j - 1] == '$'))
{
structMask[i - j - 1] = 'a';
}
}
for (j = 0; j < _helixEndPlus; j++)
{
if (i + j >= prfLength)
{
break;
}
structMask[i+j] = 'a';
}
}
else if (tolower((*mask)[i]) == 'b' || (*mask)[i] == '%')
{
for (j = -_strandEndPlus; j < 0; j++)
{
if ((i + j >= 0) && (tolower(structMask[i + j]) != 'a')
&& (tolower(structMask[i + j]) != 'b'))
{
structMask[i + j] = 'b';
}
}
for (j = 0; j < _strandEndPlus; j++)
{
if (i + j >= prfLength || (tolower((*mask)[i + j]) != 'b'
&& (*mask)[i + j] != '%'))
{
break;
}
structMask[i+j] = 'b';
}
i += j;
while (tolower((*mask)[i]) == 'b' || (*mask)[i] == '%')
{
if (i >= prfLength)
{
break;
}
if ((*mask)[i] == '%')
{
structMask[i] = 'B';
i++;
break;
}
else
{
structMask[i] = (*mask)[i];
}
i++;
}
for (j = 0; j < _strandEndMinus; j++)
{
if ((i-j-1>=0) && (tolower((*mask)[i-j-1]) == 'b' || (*mask)[i-j-1] == '%'))
{
structMask[i - j - 1] = 'b';
}
}
for (j = 0; j < _strandEndPlus; j++)
{
if (i + j >= prfLength)
{
break;
}
structMask[i+j] = 'b';
}
}
else
{
i++;
}
}
for(i = 0; i < prfLength;i++)
{
switch (structMask[i])
{
case 'A':
(*gapMask)[i] = userParameters->getHelixPenalty() + '0';
break;
case 'a':
(*gapMask)[i] = userParameters->getHelixEndPenalty() + '0';
break;
case 'B':
(*gapMask)[i] = userParameters->getStrandPenalty() +'0';
break;
case 'b':
(*gapMask)[i] = userParameters->getStrandEndPenalty() + '0';
break;
default:
(*gapMask)[i] = userParameters->getLoopPenalty() + '0';
break;
}
}
}
/**
* The function QTcalcLowScoreSegments is used to calculate the residues in the sequences
* that score badly.
* @param firstSeq first seq in the alignment or profile
* @param nSeqs the number of sequences
* @param nCols the length of the longest seq
* @param seqWeight a vector to hold the sequence weights
* @param lowScoreRes
* @param seqWeightCalculated
*/
void Clustal::QTcalcLowScoreSegments(LowScoreSegParams* params)
{
int i, j;
float sum, prevSum;
float gscale;
vector<int> weight;
int sweight;
vector<int> gaps;
int matrix[NUMRES][NUMRES];
vector<float> fsum;
vector<float> bsum;
vector<float> pscore;
int _maxAA = userParameters->getMaxAA();
// STEP 1: Calculate the sequence weights
QTcalcWeightsForLowScoreSeg(params);
subMatrix->getQTMatrixForLowScoreSeg(matrix);
const SeqArray* seqArray = alignmentObj.getSeqArray();
gaps.resize(params->nCols + 1);
for (j = 1; j <= params->nCols; j++)
{
gaps[j - 1] = 0;
for(i = params->firstSeq + 1; i < params->firstSeq + params->nSeqs; i++)
{
if (j < alignmentObj.getSeqLength(i))
{
if (((*seqArray)[i][j] < 0) || ((*seqArray)[i][j] > _maxAA))
{
gaps[j-1]++;
}
}
}
}
// STEP 2: Calculate the profile
LowScoreSegProfile lowScoreProfile(params->nCols, params->firstSeq,
params->firstSeq + params->nSeqs);
weight.resize(params->firstSeq + params->nSeqs + 1);
for(i = params->firstSeq;i < params->firstSeq + params->nSeqs;i++)
{
weight[i] = (*(params->seqWeight))[i - params->firstSeq];
}
lowScoreProfile.calcLowScoreSegProfile(seqArray, matrix, &weight);
const SeqArray* profile = lowScoreProfile.getProfilePtr();
sweight = 0;
for(i = params->firstSeq; i < params->firstSeq + params->nSeqs; i++)
{
sweight += weight[i];
}
//Now, use the profile scores to mark segments of each sequence which score badly.
fsum.resize(params->nCols + 2);
bsum.resize(params->nCols + 2);
pscore.resize(params->nCols + 2);
for(i = params->firstSeq + 1; i < params->firstSeq + params->nSeqs + 1; i++)
{
// In a forward phase, sum the profile scores. Mark negative sums as exceptions.
//If the sum is positive, then it gets reset to 0.
sum = 0.0;
for(j = 1; j <= alignmentObj.getSeqLength(i); j++)
{
gscale = (float)(params->nSeqs - gaps[j - 1]) / (float)params->nSeqs;
if((*seqArray)[i][j] < 0 || (*seqArray)[i][j] >= _maxAA)
{
pscore[j - 1] = 0.0;
sum = 0.0;
}
else
{
pscore[j-1]=((*profile)[j][(*seqArray)[i][j]]- weight[i - 1] *
matrix[(*seqArray)[i][j]][(*seqArray)[i][j]]) * gscale / sweight;
}
sum += pscore[j - 1];
if(sum > 0.0)
{
sum = 0.0;
}
fsum[j - 1] = sum;
}
// trim off any positive scoring residues from the end of the segments
prevSum = 0;
for(j = alignmentObj.getSeqLength(i) - 1; j >= 0; j--)
{
if(prevSum >= 0.0 && fsum[j] < 0.0 && pscore[j] >= 0.0)
{
fsum[j] = 0.0;
}
prevSum = fsum[j];
}
// Now, in a backward phase, do the same summing process.
sum = 0.0;
for(j = alignmentObj.getSeqLength(i); j >= 1; j--)
{
if((*seqArray)[i][j] < 0 || (*seqArray)[i][j] >= _maxAA)
{
sum = 0;
}
else
{
sum += pscore[j - 1];
}
if(sum > 0.0)
{
sum = 0.0;
}
bsum[j - 1] = sum;
}
// trim off any positive scoring residues from the start of the segments
prevSum = 0;
for(j = 0; j < alignmentObj.getSeqLength(i); j++)
{
if(prevSum >= 0.0 && bsum[j] < 0.0 && pscore[j] >= 0.0)
{
bsum[j] = 0.0;
}
prevSum = bsum[j];
}
//Mark residues as exceptions if they score negative in the forward AND backward directions.
for(j = 1; j <= alignmentObj.getSeqLength(i); j++)
{
if(fsum[j - 1] < 0.0 && bsum[j - 1] < 0.0)
{
if((*seqArray)[i][j] >= 0 && (*seqArray)[i][j] < _maxAA)
{
(*(params->lowScoreRes))[i - params->firstSeq - 1][j - 1] = -1;
}
}
}
}
// Finally, apply the length cutoff to the segments - removing segments shorter
//than the cutoff
QTremoveShortSegments(params);
}
void Clustal::QTremoveShortSegments(LowScoreSegParams* params)
{
int i,j,k,start;
//panel_data data;
//GetPanelExtra(p,&data);
if(params->nSeqs <= 0)
return;
// Reset all the exceptions - a value of 1 indicates an exception that
// will be displayed. A value of -1 is used to remember exceptions that
// are temporarily hidden in the display
for(i = 0; i < params->nSeqs; i++)
{
for(j = 0; j < params->nCols; j++)
{
if((*(params->lowScoreRes))[i][j] == -1)
{
(*(params->lowScoreRes))[i][j] = 1;
}
}
}
for(i = 0; i < params->nSeqs; i++)
{
start = -1;
for(j = 0; j <= params->nCols; j++)
{
if(start == -1)
{
if((*(params->lowScoreRes))[i][j] == 1)
start = j;
}
else
{
if(j == params->nCols || (*(params->lowScoreRes))[i][j] == 0)
{
if(j - start < userParameters->getQTminLenLowScoreSegment())
{
for(k = start; k < j; k++)
{
(*(params->lowScoreRes))[i][k] = -1;
}
}
start = -1;
}
}
}
}
}
/**
* Change: Mark 22-5-07, changed the distmatrix to be the size of alignObject.numSeqs
*/
void Clustal::QTcalcWeightsForLowScoreSeg(LowScoreSegParams* params)
{
int i, j;
vector<int> weight;
float dscore;
DistMatrix distMat(alignmentObj.getNumSeqs() + 1); // Mark: changed size
// Aw potential trouble here: what if we don't have write
// permission to current directory?
#ifdef UNIX
char treeName[FILENAMELEN]=".score.ph";
#else
char treeName[FILENAMELEN]="tmp.ph";
#endif
if(params->nSeqs <= 0)
{
return;
}
// if sequence weights have been calculated before - don't bother
//doing it again (it takes too long). data.seqweight is set to NULL when
// new sequences are loaded. /
if(params->seqWeightCalculated == true)
{
return;
}
utilityObject->info("Calculating sequence weights...");
// count pairwise percent identities to make a phylogenetic tree //
if(params->nSeqs >= 2)
{ //i=firstSeq + 1; i <= firstSeq + nSeqs
for (i = params->firstSeq + 1; i <= params->firstSeq + params->nSeqs; i++)
{ //j=i + 1; i <= firstSeq + nSeqs
for (j = i + 1; j <= params->firstSeq + params->nSeqs; j++) // Mark 22-5-07
{
dscore = alignmentObj.countid(i, j); // Mark 22-5-07
distMat(i, j) = (100.0 - dscore) / 100.0;
distMat(j, i) = distMat(i, j);
}
}
string name = string(treeName);
bool success = false;
weight.resize(params->firstSeq + params->nSeqs + 1);
TreeInterface tree;
tree.getWeightsForQtLowScore(&weight, &distMat, &alignmentObj, params->firstSeq + 1,
params->nSeqs, &name, &success); // Mark change 10-5-07
if(!success)
{
return;
}
for(i = params->firstSeq;i < params->firstSeq + params->nSeqs;i++)
{
(*(params->seqWeight))[i - params->firstSeq] = weight[i];
}
utilityObject->info("Done.");
}
}
void Clustal::QTSetFileNamesForOutput(AlignmentFileNames fileNames)
{
QTFileNames = fileNames;
}
bool Clustal::QTRealignSelectedRange(AlignmentFileNames fileNames, int beginPos, int endPos, bool realignEndGapPen)
{
bool alignEndGapPen = userParameters->getEndGapPenalties();
Alignment saveOldAlign = alignmentObj; // Take a copy of it. Note provided copy
// constructor is ok.
bool ok;
ok = alignmentObj.removeAllOutsideRange(beginPos, endPos);
if(!ok)
{
alignmentObj = saveOldAlign;
return false;
}
// Temporarily set the alignment output to be input
int saveOutOrder = userParameters->getOutputOrder();
userParameters->setOutputOrder(INPUT);
//set end gap penalties to be realignEndGapPenalties
userParameters->setEndGapPenalties(realignEndGapPen);
//do the alignment
if(alignmentObj.getNumSeqs() <= 0)
{
alignmentObj = saveOldAlign;
return false;
}
QTSetFileNamesForOutput(fileNames);
string phylipName = fileNames.treeFile;
align(&phylipName, false);
userParameters->setOutputOrder(saveOutOrder);
// reset the end gap penalties
userParameters->setEndGapPenalties(alignEndGapPen);
// remove postions that only contain gaps
int nSeqs = alignmentObj.getNumSeqs();
alignmentObj.removeAllGapOnlyColumns(1, nSeqs, 0);
// save it to a temporary area.
SeqArray realignedArea = *(alignmentObj.getSeqArray());
// Paste it back into the original alignment.
alignmentObj = saveOldAlign;
bool result;
result = alignmentObj.updateRealignedRange(realignedArea, beginPos, endPos);
if(result == false)
{
utilityObject->error("something went wrong while updating the realigned range\n");
}
// output the alignments
AlignmentOutput alignOutput;
if(!alignOutput.QTOpenFilesForOutput(QTFileNames))
{
return false; // could not open the files.
}
alignOutput.createAlignmentOutput(&alignmentObj, 1, nSeqs);
return true;
}
void Clustal::test()
{
cout << "RUNNING TEST\n";
AlignmentOutput alignOutput;
string path;
utilityObject->getPath(userParameters->getSeqName(), &path);
if(!alignOutput.openAlignmentOutput(path))
{
cerr << "could not open the file\n";
return;
}
vector<int> selected;
int nSeqs = alignmentObj.getNumSeqs();
selected.resize(nSeqs + 1, 0);
selected[9] = 1;
selected[10] = 1;
//selected[1] = 1;
alignmentObj.removeGapOnlyColsFromSelectedSeqs(&selected);
alignOutput.createAlignmentOutput(&alignmentObj, 1, nSeqs);
}
/**
* This function is used to ask the user if they would like to use an existing guide tree.
* Note: It expects that phylipName actually points to a string that has been allocated.
*/
bool Clustal::useExistingGuideTree(int type, string* phylipName, const string& path)
{
bool useTree = false;
string treeName;
InFileStream _treeFile; //nige
bool paramUseTree;
string* ptrToMsg;
if(type == Sequences)
{
ptrToMsg = &sequencesMsg;
paramUseTree = userParameters->getUseTreeFile();
}
else if(type == Profile1)
{
ptrToMsg = &profile1Msg;
paramUseTree = userParameters->getUseTree1File();;
}
else if(type == Profile2)
{
ptrToMsg = &profile2Msg;
paramUseTree = userParameters->getUseTree2File();;
}
else
{
ptrToMsg = &sequencesMsg;
paramUseTree = userParameters->getUseTreeFile();
}
if (checkTree && userParameters->getMenuFlag())
{
treeName = path + "dnd";
_treeFile.open(treeName.c_str());
_treeFile.seekg(0, std::ios::beg);
if(_treeFile.is_open())
{
string message = *ptrToMsg + treeName + " (y/n) ? [y]";
string answer;
utilityObject->getStr(message, answer);
if(answer[0] != 'n' && answer[0] != 'N')
{
if(!phylipName)
{
phylipName = new string(treeName);
}
else
{
*phylipName = treeName;
}
useTree = true;
}
_treeFile.close();
}
}
else if (!userParameters->getMenuFlag() && paramUseTree)
{
useTree = true;
}
return useTree;
}
void Clustal::promptForNewGuideTreeName(int type, string* treeName, const string& path)
{
string* ptrToMsg;
if(type == Profile1)
{
ptrToMsg = &newProfile1TreePrompt;
}
else if(type == Profile2)
{
ptrToMsg = &newProfile2TreePrompt;
}
else
{
ptrToMsg = &newProfile1TreePrompt;
}
if(!treeName)
{
treeName = new string("");
}
while(treeName->empty())
{
string message = *ptrToMsg + path + "dnd]";
string answer;
utilityObject->getStr(message, answer);
if(answer.empty())
{
answer = path + "dnd";
*treeName = answer;
}
else
{
*treeName = answer;
}
}
}
}
|