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 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680
|
#ifdef _cplusplus
extern "C" {
#endif
#include "threestatemodel.h"
char * std_alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
/* Function: information_from_ThreeStateUnit(tsu,rm)
*
* Descrip: Gets the information content (K-L divergence) vs a background for a position
*
*
* Arg: tsu [UNKN ] Undocumented argument [ThreeStateUnit *]
* Arg: rm [UNKN ] Undocumented argument [RandomModel *]
*
* Return [UNKN ] Undocumented return value [double]
*
*/
# line 117 "threestatemodel.dy"
double information_from_ThreeStateUnit(ThreeStateUnit * tsu,RandomModel * rm)
{
int i;
double info = 0.0;
double p;
for(i=0;i<ALPHABET_SIZE;i++) {
if( rm->aminoacid[i] < 1.0 ) {
p = rm->aminoacid[i]*Probability2Bits(rm->aminoacid[i]/tsu->match_emission[i]);
info += p;
/* fprintf(stderr,"For amino acid %d, adding %f %f\n",i,p,rm->aminoacid[i]); */
}
}
return info;
}
/* Function: threestatemodel_mode_from_string(mode)
*
* Descrip: gets out the mode from a string
*
*
* Arg: mode [UNKN ] Undocumented argument [char *]
*
* Return [UNKN ] Undocumented return value [int]
*
*/
# line 137 "threestatemodel.dy"
int threestatemodel_mode_from_string(char * mode)
{
int t;
t = get_number_from_slashed_string(mode,"default/global/local/wing/endbias");
switch (t) {
case 0 : return TSM_default;
case 1 : return TSM_global;
case 2 : return TSM_local;
case 3 : return TSM_wing;
case 4 : return TSM_endbiased;
default : warn("%s is not a valid TSM mode!",mode); return TSM_unknown;
}
return TSM_unknown;
}
/* Function: set_startend_policy_ThreeStateModel(tsm,mode,wing_length,internal_bias)
*
* Descrip: Sets the start/end policy on the basis of the mode
*
*
* Arg: tsm [UNKN ] Undocumented argument [ThreeStateModel *]
* Arg: mode [UNKN ] Undocumented argument [TSM_StartEndMode]
* Arg: wing_length [UNKN ] Undocumented argument [int]
* Arg: internal_bias [UNKN ] Undocumented argument [Probability]
*
*/
# line 158 "threestatemodel.dy"
void set_startend_policy_ThreeStateModel(ThreeStateModel * tsm,TSM_StartEndMode mode,int wing_length,Probability internal_bias)
{
switch(mode) {
case TSM_default : return;
case TSM_global : force_weighted_local_model(tsm,1.0,1.0,1.0); return;
case TSM_local : force_hmmfs_ThreeStateModel(tsm); return;
case TSM_wing : force_wing_local_model(tsm,0.75,wing_length); return;
case TSM_endbiased : force_endbias_model(tsm,1.0,internal_bias); return;
case TSM_unknown :
default :
warn("No valid mode passed into set_startend_policy");
}
}
/* Function: force_endbias_model(tsm,startend,internal)
*
* Descrip: Makes start/end on probability and
* internal another
*
* not probabilistically correct
*
*
* Arg: tsm [UNKN ] Undocumented argument [ThreeStateModel *]
* Arg: startend [UNKN ] Undocumented argument [double]
* Arg: internal [UNKN ] Undocumented argument [double]
*
*/
# line 180 "threestatemodel.dy"
void force_endbias_model(ThreeStateModel * tsm,double startend,double internal)
{
int i;
if( tsm == NULL ) {
warn("In force_endbias_model, got a NULL threestate model! Problem!");
return;
}
for(i=0;i<tsm->len;i++) {
tsm->unit[i]->transition[TSM_START2MATCH] = internal;
tsm->unit[i]->transition[TSM_START2DELETE] = internal;
tsm->unit[i]->transition[TSM_START2INSERT] = internal;
tsm->unit[i]->transition[TSM_MATCH2END] = internal;
tsm->unit[i]->transition[TSM_INSERT2END] = internal;
tsm->unit[i]->transition[TSM_DELETE2END] = internal;
}
tsm->unit[0]->transition[TSM_START2MATCH] = startend;
tsm->unit[0]->transition[TSM_START2DELETE] = startend;
tsm->unit[tsm->len-1]->transition[TSM_MATCH2END] = startend;
tsm->unit[tsm->len-1]->transition[TSM_DELETE2END] = startend;
}
/* Function: force_global_model(tsm,prob_into_model)
*
* Descrip: Makes start at position 0 and end at position end,
* no other positions being valid
*
*
*
* Arg: tsm [UNKN ] ThreeStateModel to be 'forced' [ThreeStateModel *]
* Arg: prob_into_model [UNKN ] Probability to start the model: for true global will be 1.0 [double]
*
*/
# line 214 "threestatemodel.dy"
void force_global_model(ThreeStateModel * tsm,double prob_into_model)
{
force_weighted_local_model(tsm,prob_into_model,1.0,1.0);
}
/* Function: force_wing_local_model(tsm,terminus_prob,wing_length)
*
* Descrip: Places the balanace of the start probability
* at the start and then the rest spread evenly
* descending over the wing stretch of sequences
*
* Same with the end probability
*
*
* Arg: tsm [UNKN ] Undocumented argument [ThreeStateModel *]
* Arg: terminus_prob [UNKN ] the amount of probability to put on the real start and end [double]
* Arg: wing_length [UNKN ] the rest of the probability spread over this distance into the wing [int]
*
*/
# line 229 "threestatemodel.dy"
void force_wing_local_model(ThreeStateModel * tsm,double terminus_prob,int wing_length)
{
int i;
double k;
/*
* k is the amount to take off for each step along the wing
*
* it comes from solving sum_(terminus_prob - nk) = 1.0
* with n going from 0 to wing_length
*
* I make this k = 2(terminus_prob)/wing_length - 2/(wing_length+1)wing_length
*
*/
k = (2.0 * terminus_prob / wing_length) - 2.0 / ((wing_length + 1)*wing_length);
if( k < 0.0 ) {
warn("Weird - got k less than zero in force wing model");
return;
}
if( tsm == NULL ) {
warn("In force_wing_local_model, got a NULL threestate model! Problem!");
return;
}
for(i=0;i<tsm->len && i < wing_length ;i++) {
tsm->unit[i]->transition[TSM_START2MATCH] = (terminus_prob) - (i * k) ;
tsm->unit[i]->transition[TSM_START2DELETE] = (terminus_prob) - (i * k) ;
tsm->unit[i]->transition[TSM_START2INSERT] = (terminus_prob) - ( i * k) ;
tsm->unit[tsm->len-1-i]->transition[TSM_MATCH2END] = (terminus_prob) - (i * k) ;
tsm->unit[tsm->len-1-i]->transition[TSM_INSERT2END] = (terminus_prob) - ( i * k) ;
tsm->unit[tsm->len-1-i]->transition[TSM_DELETE2END] = (terminus_prob) - (i * k) ;
}
}
/* Function: force_weighted_local_model(tsm,prob_into_model,ratio_start,ratio_end)
*
* Descrip: places the ratio of probability to start/end,
* and then distributes the rest over the start/end
*
*
*
* Arg: tsm [UNKN ] ThreeStateModel to be 'forced' [ThreeStateModel *]
* Arg: prob_into_model [UNKN ] Probability to start the model: for true global will be 1.0 [double]
* Arg: ratio_start [UNKN ] ratio of prob to unit 0 to the rest (1.0 means all goes to start) [double]
* Arg: ratio_end [UNKN ] ratio of prob to unit (last) to the rest (1.0 means all goes to the end) [double]
*
*/
# line 284 "threestatemodel.dy"
void force_weighted_local_model(ThreeStateModel * tsm,double prob_into_model,double ratio_start,double ratio_end)
{
int i;
if( tsm == NULL ) {
warn("In force_weighted_local_model, got a NULL threestate model! Problem!");
return;
}
for(i=0;i<tsm->len;i++) {
tsm->unit[i]->transition[TSM_START2MATCH] = prob_into_model * (1.0 - ratio_start) / (tsm->len-1) ;
tsm->unit[i]->transition[TSM_START2DELETE] = prob_into_model * (1.0 - ratio_start) / (tsm->len-1);
tsm->unit[i]->transition[TSM_START2INSERT] = prob_into_model * (1.0 - ratio_start)/ (tsm->len-1) ;
tsm->unit[i]->transition[TSM_MATCH2END] = (1.0 - ratio_end) / (tsm->len-1);
tsm->unit[i]->transition[TSM_INSERT2END] = (1.0 - ratio_end) / (tsm->len-1);
tsm->unit[i]->transition[TSM_DELETE2END] = (1.0 - ratio_end)/ (tsm->len-1);
}
tsm->unit[0]->transition[TSM_START2MATCH] = prob_into_model * (ratio_start);
tsm->unit[0]->transition[TSM_START2DELETE] = prob_into_model * (ratio_start);
/* tsm->unit[0]->transition[TSM_START2INSERT] = prob_into_model * (ratio_start); */
tsm->unit[tsm->len-1]->transition[TSM_MATCH2END] = (ratio_end);
tsm->unit[tsm->len-1]->transition[TSM_DELETE2END] = (ratio_end);
}
/* Function: force_hmmfs_ThreeStateModel(tsm)
*
* Descrip: places the probability at start end to precisely match
* hmmfs code.
*
*
*
* Arg: tsm [UNKN ] ThreeStateModel to be 'forced' [ThreeStateModel *]
*
*/
# line 316 "threestatemodel.dy"
void force_hmmfs_ThreeStateModel(ThreeStateModel * tsm)
{
int i;
double prob;
prob = 1.0 - (1000. / 1001. );
for(i=0;i<tsm->len;i++) {
tsm->unit[i]->transition[TSM_START2MATCH] = prob*0.5/(2.0 * (tsm->len-1)) ;
tsm->unit[i]->transition[TSM_START2DELETE] = 0.0;
tsm->unit[i]->transition[TSM_START2INSERT] = 0.0;
tsm->unit[i]->transition[TSM_MATCH2END] = 1.0 / (tsm->len-1);
tsm->unit[i]->transition[TSM_INSERT2END] = 0.0;
tsm->unit[i]->transition[TSM_DELETE2END] = 0.0;
}
tsm->unit[0]->transition[TSM_START2MATCH] = prob*0.5/2.0;
tsm->unit[tsm->len-1]->transition[TSM_MATCH2END] = 1.0;
}
/* Function: ThreeStateScore_from_ThreeStateModel(tsm)
*
* Descrip: Converts the three probability form to the score form.
*
* There is real complications to this due to the fact that the prob
* model is a "push" model, that is MATCH2MATCH[i] means the match from i
* to i+1, whereas the DP routines rely on a "pull" model, ie
* MATCH2MATCH[i] is i-1 to i.
*
* This routines does the conversion from push to pull, essentially offsetting
* the Match2 and Delete2 movements.
*
*
* Arg: tsm [READ ] ThreeStateModel probability form [ThreeStateModel *]
*
* Return [UNKN ] Undocumented return value [ThreeStateScore *]
*
*/
# line 350 "threestatemodel.dy"
ThreeStateScore * ThreeStateScore_from_ThreeStateModel(ThreeStateModel * tsm)
{
register int i;
ThreeStateScore * tss;
tss = ThreeStateScore_alloc_len(tsm->len);
add_ThreeStateScore(tss,ThreeStateScoreUnit_from_ThreeStateUnit(NULL,tsm->unit[0]));
for(i=1;i<tsm->len;i++)
add_ThreeStateScore(tss,ThreeStateScoreUnit_from_ThreeStateUnit(tsm->unit[i-1],tsm->unit[i]));
tss->name = stringalloc(tsm->name);
if( tsm->accession != NULL )
tss->accession = stringalloc(tsm->accession);
return tss;
}
/* Function: ThreeStateScoreUnit_from_ThreeStateUnit(prev,tsu)
*
* Descrip: Converts a three state model unit to a score unit
*
* becuase of the push to pull conversion needed, it needs the previous
* unit. for the first unit this is NULL and 0s are placed in the correct
* places in the transitions
*
*
* Arg: prev [UNKN ] Undocumented argument [ThreeStateUnit *]
* Arg: tsu [UNKN ] Undocumented argument [ThreeStateUnit *]
*
* Return [UNKN ] Undocumented return value [ThreeStateScoreUnit *]
*
*/
# line 376 "threestatemodel.dy"
ThreeStateScoreUnit * ThreeStateScoreUnit_from_ThreeStateUnit(ThreeStateUnit * prev,ThreeStateUnit * tsu)
{
ThreeStateScoreUnit * out;
out = ThreeStateScoreUnit_alloc();
if( out == NULL )
return NULL;
Probability2Score_move(tsu->match_emission,out->match,ALPHABET_SIZE);
Probability2Score_move(tsu->insert_emission,out->insert,ALPHABET_SIZE);
if( prev != NULL ) {
out->trans[TSM_MATCH2MATCH] = Probability2Score(prev->transition[TSM_MATCH2MATCH]);
out->trans[TSM_INSERT2MATCH] = Probability2Score(prev->transition[TSM_INSERT2MATCH]);
out->trans[TSM_DELETE2MATCH] = Probability2Score(prev->transition[TSM_DELETE2MATCH]);
out->trans[TSM_MATCH2DELETE] = Probability2Score(prev->transition[TSM_MATCH2DELETE]);
out->trans[TSM_INSERT2DELETE] = Probability2Score(prev->transition[TSM_INSERT2DELETE]);
out->trans[TSM_DELETE2DELETE] = Probability2Score(prev->transition[TSM_DELETE2DELETE]);
} else {
out->trans[TSM_MATCH2MATCH] = NEGI;
out->trans[TSM_INSERT2MATCH] = NEGI;
out->trans[TSM_DELETE2MATCH] = NEGI;
out->trans[TSM_MATCH2DELETE] = NEGI;
out->trans[TSM_INSERT2DELETE] = NEGI;
out->trans[TSM_DELETE2DELETE] = NEGI;
}
out->trans[TSM_MATCH2INSERT] = Probability2Score(tsu->transition[TSM_MATCH2INSERT]);
out->trans[TSM_INSERT2INSERT] = Probability2Score(tsu->transition[TSM_INSERT2INSERT]);
out->trans[TSM_DELETE2INSERT] = Probability2Score(tsu->transition[TSM_DELETE2INSERT]);
out->trans[TSM_START2MATCH] = Probability2Score(tsu->transition[TSM_START2MATCH]);
out->trans[TSM_START2INSERT] = Probability2Score(tsu->transition[TSM_START2INSERT]);
out->trans[TSM_START2DELETE] = Probability2Score(tsu->transition[TSM_START2DELETE]);
out->trans[TSM_MATCH2END] = Probability2Score(tsu->transition[TSM_MATCH2END]);
out->trans[TSM_INSERT2END] = Probability2Score(tsu->transition[TSM_INSERT2END]);
out->trans[TSM_DELETE2END] = Probability2Score(tsu->transition[TSM_DELETE2END]);
return out;
}
/* Function: show_ThreeStateModel(tsm,ofp)
*
* Descrip: shows pretty ugly debugging type format.
*
* Pretty useless
*
*
* Arg: tsm [UNKN ] Undocumented argument [ThreeStateModel *]
* Arg: ofp [UNKN ] Undocumented argument [FILE *]
*
*/
# line 428 "threestatemodel.dy"
void show_ThreeStateModel(ThreeStateModel * tsm,FILE * ofp)
{
register int i;
for(i=0;i<tsm->len;i++) {
fprintf(ofp,"Position %d %c\n",i,tsm->unit[i]->display_char);
show_ThreeStateUnit(tsm->unit[i],ofp);
}
}
/* Function: show_ThreeStateUnit(tsu,ofp)
*
* Descrip: for debugging problems
*
*
* Arg: tsu [UNKN ] Undocumented argument [ThreeStateUnit *]
* Arg: ofp [UNKN ] Undocumented argument [FILE *]
*
*/
# line 442 "threestatemodel.dy"
void show_ThreeStateUnit(ThreeStateUnit * tsu,FILE * ofp)
{
fprintf(ofp,"Match ");
show_Probability_array(tsu->match_emission,26,ofp);
fprintf(ofp,"\nInsert ");
show_Probability_array(tsu->insert_emission,26,ofp);
fprintf(ofp,"\nTransition ");
show_Probability_array(tsu->transition,TRANSITION_LEN,ofp);
fprintf(ofp,"\n");
}
/* Function: pseudo_Protein_from_ThreeStateModel(tsm)
*
* Descrip: Makes a protein sequence out of the display characters.
* Not very useful!
*
*
*
* Arg: tsm [UNKN ] Undocumented argument [ThreeStateModel *]
*
* Return [UNKN ] Undocumented return value [Protein *]
*
*/
# line 459 "threestatemodel.dy"
Protein * pseudo_Protein_from_ThreeStateModel(ThreeStateModel * tsm)
{
int i;
Sequence * seq;
seq = Sequence_alloc();
seq->name = stringalloc(tsm->name);
seq->seq = ckcalloc(tsm->len+1,sizeof(char));
for(i=0;i<tsm->len;i++) {
seq->seq[i] = tsm->unit[i]->display_char;
}
seq->seq[i]='\0';
make_len_type_Sequence(seq);
seq->type = SEQUENCE_PROTEIN;
return Protein_from_Sequence(seq);
}
/* Function: ThreeStateModel_from_half_bit_Sequence(pro,mat,rm,gap,ext)
*
* Descrip: Makes a local three-state-model from a sequence. this is scary
* hackery, assumming that the matrix is half-bits and normalising in a
* *very* wrong way to get "probabilities" out.
*
* Works though
*
*
* Arg: pro [READ ] protein sequence [Protein *]
* Arg: mat [READ ] comparison matrix to use [CompMat *]
* Arg: rm [READ ] random model which you assumme the matrix was built with [RandomModel *]
* Arg: gap [READ ] gap open penalty [int]
* Arg: ext [READ ] gap ext penalty [int]
*
* Return [UNKN ] Undocumented return value [ThreeStateModel *]
*
*/
# line 494 "threestatemodel.dy"
ThreeStateModel * ThreeStateModel_from_half_bit_Sequence(Protein * pro,CompMat * mat,RandomModel * rm,int gap,int ext)
{
Sequence * seq;
register int i;
ThreeStateModel * out;
if( pro == NULL || mat == NULL || rm == NULL ) {
warn("you have passed through NULL objects in trying to make TSM from sequence");
return NULL;
}
if( gap > 0 || ext > 0 ) {
warn("You have passed in gap and extension penalties of > 0 Gap %d Ext %d. Expecting them to be negated. Giving you back an error!",gap,ext);
return NULL;
}
seq = pro->baseseq;
out = ThreeStateModel_alloc_len(seq->len);
if( seq->name != NULL )
out->name = stringalloc(seq->name);
else out->name = stringalloc("NoName");
out->rm = hard_link_RandomModel(rm);
for(i=0;i<seq->len;i++) {
add_ThreeStateModel(out,ThreeStateUnit_from_half_bit_aminoacid(seq->seq[i],mat,rm,gap,ext));
}
return out;
}
/* Function: ThreeStateUnit_from_half_bit_aminoacid(aa,mat,rm,gap,ext)
*
* Descrip: The internal protein->hmm conversion routine.
*
*
* Arg: aa [UNKN ] Undocumented argument [char]
* Arg: mat [UNKN ] Undocumented argument [CompMat *]
* Arg: rm [UNKN ] Undocumented argument [RandomModel *]
* Arg: gap [UNKN ] Undocumented argument [int]
* Arg: ext [UNKN ] Undocumented argument [int]
*
* Return [UNKN ] Undocumented return value [ThreeStateUnit *]
*
*/
# line 536 "threestatemodel.dy"
ThreeStateUnit * ThreeStateUnit_from_half_bit_aminoacid(char aa,CompMat * mat,RandomModel * rm,int gap,int ext)
{
ThreeStateUnit * tsu;
register int i;
Probability go;
Probability ge;
Probability rnd_error;
tsu = ThreeStateUnit_alloc();
aa = toupper((int)aa);
/* maybe do more checking on aa? */
for(i=0;i<26;i++) {
tsu->match_emission[i] = halfbit2Probability(fail_safe_CompMat_access(mat,aa-'A',i)) * rm->aminoacid[i];
tsu->insert_emission[i] = rm->aminoacid[i];
}
rnd_error = renormalise_Probability_array(tsu->match_emission,26);
if( fabs(rnd_error) > 0.5 ) {
warn("Very bad problem - got a stupid error %.2f after renormalisation from the null model with the match state on aa %c\n",rnd_error,aa);
}
rnd_error = renormalise_Probability_array(tsu->insert_emission,26);
if( fabs(rnd_error) > 0.5 ) {
warn("Very bad problem - got a stupid error %.2f after renormalisation from the null model\n",rnd_error);
}
ge = halfbit2Probability(ext);
go = halfbit2Probability(gap);
/** 1-ge is the gap closing penalty. So we have to remove that from the go **/
go = go / (1-ge);
tsu->transition[TSM_MATCH2INSERT] = tsu->transition[TSM_MATCH2DELETE] = go;
tsu->transition[TSM_INSERT2MATCH] = tsu->transition[TSM_DELETE2MATCH] = 1-ge;
tsu->transition[TSM_INSERT2INSERT] = tsu->transition[TSM_DELETE2DELETE] = ge;
tsu->transition[TSM_INSERT2DELETE] = tsu->transition[TSM_DELETE2INSERT] = 0.0;
tsu->transition[TSM_MATCH2MATCH] = 1-(2*go);
tsu->transition[TSM_START2MATCH] = 1.0;
tsu->transition[TSM_MATCH2END] = 1.0;
tsu->display_char = aa;
return tsu;
}
/* Function: global_ThreeStateModel_from_half_bit_Sequence(pro,mat,rm,gap,ext)
*
* Descrip: Makes a global three-state-model from a sequence.
* Like the local version, this is scary hackery, assumming
* that the matrix is half-bits and normalising in a *very*
* wrong way to get "probabilities" out.
*
* Works though
*
*
* Arg: pro [READ ] protein sequence [Protein *]
* Arg: mat [READ ] comparison matrix to use [CompMat *]
* Arg: rm [READ ] random model which you assumme the matrix was built with [RandomModel *]
* Arg: gap [READ ] gap open penalty [int]
* Arg: ext [READ ] gap ext penalty [int]
*
* Return [UNKN ] Undocumented return value [ThreeStateModel *]
*
*/
# line 602 "threestatemodel.dy"
ThreeStateModel * global_ThreeStateModel_from_half_bit_Sequence(Protein * pro,CompMat * mat,RandomModel * rm,int gap,int ext)
{
register int i;
ThreeStateModel * out;
ThreeStateUnit * temp;
Sequence * seq;
if( pro == NULL || mat == NULL || rm == NULL ) {
warn("you have passed through NULL objects in trying to make TSM from sequence");
return NULL;
}
seq = pro->baseseq;
out = ThreeStateModel_alloc_len(seq->len);
if( seq->name != NULL )
out->name = stringalloc(seq->name);
else out->name = stringalloc("NoName");
for(i=0;i<seq->len;i++) {
temp = ThreeStateUnit_from_half_bit_aminoacid(seq->seq[i],mat,rm,gap,ext);
temp->transition[TSM_START2MATCH] = 0.0;
temp->transition[TSM_MATCH2END] = 0.0;
add_ThreeStateModel(out,temp);
}
out->unit[0]->transition[TSM_START2MATCH] = 1.0;
out->unit[out->len-1]->transition[TSM_MATCH2END] = 1.0;
out->rm = hard_link_RandomModel(rm);
return out;
}
/* Function: display_char_for_ThreeStateUnit(tsu)
*
* Descrip: Makes a display character for
* this threestateunit by finding the
* most probable match emission
*
*
* Arg: tsu [UNKN ] Undocumented argument [ThreeStateUnit *]
*
* Return [UNKN ] Undocumented return value [char]
*
*/
# line 646 "threestatemodel.dy"
char display_char_for_ThreeStateUnit(ThreeStateUnit * tsu)
{
register int i;
Probability p;
int c;
p = tsu->match_emission[0];
c = 0;
for(i=1;i<ALPHABET_SIZE;i++)
if( tsu->match_emission[i] > p ) {
p = tsu->match_emission[i];
c = i;
}
return c + 'A';
}
/* Function: display_char_in_ThreeStateModel(tsm)
*
* Descrip: Makes the display chars in the tsm come from
* the most likely amino acid in the match position
*
*
* Arg: tsm [UNKN ] Undocumented argument [ThreeStateModel *]
*
*/
# line 668 "threestatemodel.dy"
void display_char_in_ThreeStateModel(ThreeStateModel * tsm)
{
register int i;
for(i=0;i<tsm->len;i++)
tsm->unit[i]->display_char = display_char_for_ThreeStateUnit(tsm->unit[i]);
}
/* Function: fold_RandomModel_into_ThreeStateModel(tsm,rm)
*
* Descrip: divides the emission and insertion scores
* by the random model for use in log-odd
* implementations
*
*
* Arg: tsm [UNKN ] Undocumented argument [ThreeStateModel *]
* Arg: rm [UNKN ] Undocumented argument [RandomModel *]
*
*/
# line 681 "threestatemodel.dy"
void fold_RandomModel_into_ThreeStateModel(ThreeStateModel * tsm,RandomModel * rm)
{
register int i;
register int j;
assert(tsm);
assert(rm);
for(i=0;i<tsm->len;i++) {
auto ThreeStateUnit * tsu;
tsu = tsm->unit[i];
for(j=0;j<26;j++) {
if( rm->aminoacid[j] < 0.00000001 ) {
warn("While trying to fold in random model, amino acid %d [%c] was below zero, ignoring",j,'A'+j);
continue;
}
tsu->match_emission[j] = tsu->match_emission[j] / rm->aminoacid[j];
tsu->insert_emission[j] = tsu->insert_emission[j] / rm->aminoacid[j];
}
}
}
/* Function: add_sensible_start_end_global_for_HMMer(tsm)
*
* Descrip: added start 0.5, 0.25,0.25 for hmmls type
*
* Deprecated
*
*
* Arg: tsm [UNKN ] Undocumented argument [ThreeStateModel *]
*
*/
# line 709 "threestatemodel.dy"
void add_sensible_start_end_global_for_HMMer(ThreeStateModel * tsm)
{
ThreeStateUnit * end;
tsm->unit[0]->transition[TSM_START2MATCH] = 0.5;
tsm->unit[0]->transition[TSM_START2INSERT] = 0.25;
tsm->unit[0]->transition[TSM_START2DELETE] = 0.25;
/*** these should not add to one due to sum in states ***/
end = tsm->unit[tsm->len-1];
end->transition[TSM_MATCH2END] = (1 - end->transition[TSM_MATCH2INSERT]) ;
end->transition[TSM_DELETE2END] = (1 - end->transition[TSM_DELETE2INSERT]) ;
end->transition[TSM_INSERT2END] = (1 - end->transition[TSM_INSERT2INSERT]);
}
/* Function: add_sensible_start_end_looping_for_HMMer(tsm,loop)
*
* Descrip: adds start/end for loop probabilities coming
* in
*
* Deprecated
*
*
* Arg: tsm [UNKN ] Undocumented argument [ThreeStateModel *]
* Arg: loop [UNKN ] Undocumented argument [Probability]
*
*/
# line 734 "threestatemodel.dy"
void add_sensible_start_end_looping_for_HMMer(ThreeStateModel * tsm,Probability loop)
{
tsm->unit[0]->transition[TSM_START2MATCH] = loop * 0.5;
tsm->unit[0]->transition[TSM_START2INSERT] = loop * 0.25;
tsm->unit[0]->transition[TSM_START2DELETE] = loop * 0.25;
/*** these should not add to one due to sum in states ***/
tsm->unit[tsm->len-1]->transition[TSM_MATCH2END] = 0.5;
tsm->unit[tsm->len-1]->transition[TSM_DELETE2END] = 0.25;
tsm->unit[tsm->len-1]->transition[TSM_INSERT2END] = 0.25;
}
/**** I/O *****/
/* Function: write_HMF_ThreeStateModel(tsm,ofp)
*
* Descrip: writes the HMF format
*
*
* Arg: tsm [UNKN ] Undocumented argument [ThreeStateModel *]
* Arg: ofp [UNKN ] Undocumented argument [FILE *]
*
*/
# line 757 "threestatemodel.dy"
void write_HMF_ThreeStateModel(ThreeStateModel * tsm,FILE * ofp)
{
int i;
fprintf(ofp,"ID %s\n",tsm->name != NULL ? tsm->name : "NoName");
fprintf(ofp,"TR %4.2f\n",tsm->threshold);
fprintf(ofp,"CC HMF format for HMM, each three state block starts UN after MO line\n");
fprintf(ofp,"CC Alphabet A-Z\n");
fprintf(ofp,"MO\n");
for(i=0;i<tsm->len;i++)
write_HMF_ThreeStateUnit(tsm->unit[i],ofp);
fprintf(ofp,"//\n");
}
/* Function: write_HMF_ThreeStateUnit(tsu,ofp)
*
* Descrip: writes each Unit line
*
*
* Arg: tsu [UNKN ] Undocumented argument [ThreeStateUnit *]
* Arg: ofp [UNKN ] Undocumented argument [FILE *]
*
*/
# line 778 "threestatemodel.dy"
void write_HMF_ThreeStateUnit(ThreeStateUnit * tsu,FILE * ofp)
{
fprintf(ofp,"UN %c\n",tsu->display_char);
fprintf(ofp,"MA ");
show_Probability_array_exp(tsu->match_emission,ALPHABET_SIZE,ofp);
fprintf(ofp,"\nIN ");
show_Probability_array_exp(tsu->insert_emission,ALPHABET_SIZE,ofp);
fprintf(ofp,"\nTR ");
show_Probability_array_exp(tsu->transition,TRANSITION_LEN,ofp);
fprintf(ofp,"\n");
}
/* Function: read_HMF_ThreeStateModel(ifp)
*
* Descrip: reads the HMF format. Leaves the file ready
* to read the next format
*
*
* Arg: ifp [UNKN ] Undocumented argument [FILE *]
*
* Return [UNKN ] Undocumented return value [ThreeStateModel *]
*
*/
# line 794 "threestatemodel.dy"
ThreeStateModel * read_HMF_ThreeStateModel(FILE * ifp)
{
ThreeStateUnit * temp;
ThreeStateModel * out;
char buffer[MAXLINE];
char * name = NULL;
char * runner;
if( feof(ifp) || ferror(ifp) )
return NULL;
while( fgets(buffer,MAXLINE,ifp) != NULL ) {
chop_newline(buffer);
if( buffer[0] == '#' ) {
continue;
}
if( strstartcmp(buffer,"ID") == 0 ) {
name = stringalloc(strtok(buffer+3,spacestr));
break;
}
warn("In reading HMF format, before ID line, ignoring [%s]",buffer);
}
if( feof(ifp) || ferror(ifp) || name == NULL)
return NULL;
out = ThreeStateModel_alloc_std();
out->name = name;
while( fgets(buffer,MAXLINE,ifp) != NULL ) {
chop_newline(buffer);
if( buffer[0] == '#' ) {
continue;
}
if( strstartcmp(buffer,"MO") == 0 )
break;
else if( strstartcmp(buffer,"CC") == 0 )
continue;
else if( strstartcmp(buffer,"TR") == 0 ) {
runner = strtok(buffer+2,spacestr);
if( is_double_string(runner,&out->threshold) == FALSE) {
warn("Could not interpret [%s] as a threshold",runner);
}
}
else if( strstartcmp(buffer,"ID") == 0 ) {
warn("Already got a name for [%s], ignoring [%s]",out->name,buffer);
} else {
warn("Did not understand %s",buffer);
}
}
while( fgets(buffer,MAXLINE,ifp) != NULL ) {
if( strstartcmp(buffer,"UN") == 0 )
break;
chop_newline(buffer);
warn("You have a problem here: [%s] between MO and UN lines",buffer);
}
while( (temp = read_HMF_ThreeStateUnit(buffer,ifp)) != NULL ) {
add_ThreeStateModel(out,temp);
if( strstartcmp(buffer,"//") == 0 )
break;
}
display_char_in_ThreeStateModel(out);
return out;
}
/* Function: read_HMF_ThreeStateUnit(line,ifp)
*
* Descrip: reads a unit set of lines:
*
* Line is used as the buffer, so should be MAXLINE length. At the
* end, it will have a different characters (probably the next unit
* line) in the line buffer, so you should test that
*
*
* Arg: line [WRITE] pointer to a MAXLINE length buffer. [char *]
* Arg: ifp [UNKN ] input file [FILE *]
*
* Return [UNKN ] Undocumented return value [ThreeStateUnit *]
*
*/
# line 877 "threestatemodel.dy"
ThreeStateUnit * read_HMF_ThreeStateUnit(char * line,FILE * ifp)
{
ThreeStateUnit * out;
char * runner;
if( strstartcmp(line,"UN") != 0 ) {
warn("Attempting to read a ThreeStateUnit with a non UN line: [%s]",line);
return NULL;
}
out = blank_ThreeStateUnit();
/* display char */
runner = strtok(line+2,spacestr);
if( runner != NULL ) {
out->display_char = *runner;
}
while ( fgets(line,MAXLINE,ifp) != NULL ) {
if( strstartcmp(line,"//") == 0 )
break;
if( strstartcmp(line,"UN") == 0 )
break;
if( strstartcmp(line,"MA") == 0 ) {
if( read_Probability_array(out->match_emission,ALPHABET_SIZE,line+3) == FALSE ) {
warn("Unable to read Match emission line");
}
} else if ( strstartcmp(line,"IN") == 0) {
if( read_Probability_array(out->insert_emission,ALPHABET_SIZE,line+3) == FALSE ) {
warn("Unable to read Insert emission line");
}
} else if ( strstartcmp(line,"TR") == 0 ) {
if( read_Probability_array(out->transition,TRANSITION_LEN,line+3) == FALSE ) {
warn("Unable to read Insert emission line");
}
} else {
chop_newline(line);
warn("Could not understand line [%s] in reading threestateunit",line);
}
}
return out;
}
/* Function: write_HMMer_1_7_ascii_ThreeStateModel(tsm,ofp)
*
* Descrip: writes a HMMer version 1.7 (also ok with 1.8) file
*
*
* Arg: tsm [UNKN ] Undocumented argument [ThreeStateModel *]
* Arg: ofp [UNKN ] Undocumented argument [FILE *]
*
*/
# line 925 "threestatemodel.dy"
void write_HMMer_1_7_ascii_ThreeStateModel(ThreeStateModel * tsm,FILE * ofp)
{
register int i;
fprintf(ofp,"# HMM v1.7\n");
fprintf(ofp,"%d # Length of model\n",tsm->len);
fprintf(ofp,"%d # length of alphabet\n",26);
fprintf(ofp,"3 # alphabet type\n");
fprintf(ofp,"%s # alphabet\n",std_alphabet);
fprintf(ofp,"no # optional\nno # optional \n");
for(i=0;i<tsm->len;i++)
write_HMMer_1_7_ascii_ThreeStateUnit(tsm->unit[i],i,ofp);
}
/* Function: write_HMMer_1_7_ascii_ThreeStateUnit(tsu,no,ofp)
*
* Descrip: the internal for the ThreeStateModel write
*
*
* Arg: tsu [UNKN ] Undocumented argument [ThreeStateUnit *]
* Arg: no [UNKN ] Undocumented argument [int]
* Arg: ofp [UNKN ] Undocumented argument [FILE *]
*
*/
# line 944 "threestatemodel.dy"
void write_HMMer_1_7_ascii_ThreeStateUnit(ThreeStateUnit * tsu,int no,FILE * ofp)
{
register int i;
fprintf(ofp,"###MATCH_STATE %d ( ) ( )\n",no);
fprintf(ofp,"%f\t# t_m%d\n",tsu->transition[TSM_MATCH2MATCH],no+1);
fprintf(ofp,"%f\t# t_d%d\n",tsu->transition[TSM_MATCH2DELETE],no+1);
fprintf(ofp,"%f\t# t_i%d\n",tsu->transition[TSM_MATCH2INSERT],no);
for(i=0;i<26;i++) {
fprintf(ofp,"%f\t# Symbol %c probability\n",tsu->match_emission[i],'A'+i);
}
fprintf(ofp,"###DELETE_STATE %d\n",no);
fprintf(ofp,"%f\t# t_m%d\n",tsu->transition[TSM_DELETE2MATCH],no+1);
fprintf(ofp,"%f\t# t_d%d\n",tsu->transition[TSM_DELETE2DELETE],no+1);
fprintf(ofp,"%f\t# t_i%d\n",tsu->transition[TSM_DELETE2INSERT],no);
fprintf(ofp,"###INSERT_STATE %d\n",no);
fprintf(ofp,"%f\t# t_m%d\n",tsu->transition[TSM_INSERT2MATCH],no+1);
fprintf(ofp,"%f\t# t_d%d\n",tsu->transition[TSM_INSERT2DELETE],no+1);
fprintf(ofp,"%f\t# t_i%d\n",tsu->transition[TSM_INSERT2INSERT],no);
for(i=0;i<26;i++) {
fprintf(ofp,"%f\t# Symbol %c probability\n",tsu->insert_emission[i],'A'+i);
}
}
/* Function: read_HMMer_1_7_ascii_file(filename)
*
* Descrip: reads a HMMer ascii version 1.7 (1.8) file from filename.
*
*
*
* Arg: filename [UNKN ] the name fo the hmmer file [char *]
*
* Return [UNKN ] Undocumented return value [ThreeStateModel *]
*
*/
# line 977 "threestatemodel.dy"
ThreeStateModel * read_HMMer_1_7_ascii_file(char * filename)
{
FILE * ifp;
ThreeStateModel * out;
ifp = openfile(filename,"r");
if( ifp == NULL ) {
warn("Could not open file %s for read HMMer 17 ",filename);
return NULL;
}
out = read_HMMer_1_7_ascii(ifp);
ckfree(out->name);
if( strcmp(filename,"-") == 0 ) {
/* comes from stdin, we're fucked to find the name */
out->name = stringalloc("HMMerModel");
} else {
if( strchr(filename,'/') != NULL) {
filename = filename + strlen(filename) -1;
for(;*filename != '/';filename--)
;
filename++;
}
out->name = stringalloc(filename);
}
fclose(ifp);
return out;
}
/* Function: convert_push_model_to_pull_model(tsm)
*
* Descrip: Not sure if this is needed now, as score model will be pull, and
* probability model will be push.
*
*
*
* Arg: tsm [UNKN ] Undocumented argument [ThreeStateModel *]
*
* Return [UNKN ] Undocumented return value [ThreeStateModel *]
*
*/
# line 1016 "threestatemodel.dy"
ThreeStateModel * convert_push_model_to_pull_model(ThreeStateModel * tsm)
{
register int i;
ThreeStateModel * out;
out = ThreeStateModel_alloc_len(tsm->len-1);
for(i=1;i<tsm->len;i++)
add_ThreeStateModel(out,convert_push_unit_to_pull_unit(tsm->unit[i-1],tsm->unit[i]));
if( tsm->name != NULL)
out->name = stringalloc(tsm->name);
return out;
}
/* Function: convert_push_unit_to_pull_unit(prev,this)
*
* Descrip: Not sure if this is needed now, as score model will be pull, and
* probability model will be push.
*
*
*
* Arg: prev [UNKN ] Undocumented argument [ThreeStateUnit *]
* Arg: this [UNKN ] Undocumented argument [ThreeStateUnit *]
*
* Return [UNKN ] Undocumented return value [ThreeStateUnit *]
*
*/
# line 1039 "threestatemodel.dy"
ThreeStateUnit * convert_push_unit_to_pull_unit(ThreeStateUnit * prev,ThreeStateUnit * this)
{
ThreeStateUnit * out;
out = ThreeStateUnit_alloc();
Probability_move(this->match_emission ,out->match_emission ,ALPHABET_SIZE);
Probability_move(this->insert_emission,out->insert_emission,ALPHABET_SIZE);
set_Probability_array(out->transition,0.0,TRANSITION_LEN);
out->transition[TSM_MATCH2MATCH] = prev->transition[TSM_MATCH2MATCH];
out->transition[TSM_DELETE2MATCH] = prev->transition[TSM_DELETE2MATCH];
out->transition[TSM_INSERT2MATCH] = prev->transition[TSM_INSERT2MATCH];
out->transition[TSM_MATCH2INSERT] = this->transition[TSM_MATCH2INSERT];
out->transition[TSM_INSERT2INSERT] = this->transition[TSM_INSERT2INSERT];
out->transition[TSM_DELETE2INSERT] = this->transition[TSM_DELETE2INSERT];
out->transition[TSM_MATCH2DELETE] = prev->transition[TSM_MATCH2DELETE];
out->transition[TSM_INSERT2DELETE] = prev->transition[TSM_INSERT2DELETE];
out->transition[TSM_DELETE2DELETE] = prev->transition[TSM_DELETE2DELETE];
/*** not dealing with start/end things here ***/
return out;
}
/* Function: read_HMMer_1_7_ascii(ifp)
*
* Descrip: Basic function to read HMMer version 1.7(1.8) files.
*
*
* Arg: ifp [UNKN ] Undocumented argument [FILE *]
*
* Return [UNKN ] Undocumented return value [ThreeStateModel *]
*
*/
# line 1071 "threestatemodel.dy"
ThreeStateModel * read_HMMer_1_7_ascii(FILE * ifp)
{
char buffer[MAXLINE];
char * runner;
char * alphabet;
int length;
int count;
ThreeStateModel * out;
ThreeStateUnit * temp;
/*** read top of model ***/
/*** then we will loop ***/
/*** over all the states ***/
if( fgets(buffer,MAXLINE,ifp) == NULL ) {
warn("Trying to read HMMer ascii file, but no first line!");
return NULL;
}
if( strstartcmp(buffer,"# HMM") != 0 ) {
warn("In reading HMMer ascii file, expecting first line to start [# HMM], starts as [%s]... can't handle",buffer);
return NULL;
}
if( strstartcmp(buffer,"# HMM v1.7") != 0) {
warn("In reading HMMer ascii file, expecting a version 1.7 file, got a version [%s] file... trying to read",buffer);
}
/*** length next ***/
if( fgets(buffer,MAXLINE,ifp) == NULL ) {
warn("Trying to read HMMer ascii file, length line (2nd line) not there");
return NULL;
}
if( (runner=strtok(buffer,spacestr)) == NULL ) {
warn("Trying to read HMMer ascii file, length line (2nd line) has no length!");
return NULL;
}
length = atoi(runner);
if( length <= 0 || length > 4000 ) {
warn("Picked up length [%s] which was interpreted as the number [%d], which seems unfeasible. S'ok... can work without the length",runner,length);
length = 100;
}
/*** get the alphabet length... no point in checking ***/
if( fgets(buffer,MAXLINE,ifp) == NULL ) {
warn("Trying to read HMMer ascii file, length of alphabet (3rd line) not there");
return NULL;
}
if( fgets(buffer,MAXLINE,ifp) == NULL ) {
warn("Trying to read HMMer ascii file, type of alphabet (4th line) not there");
return NULL;
}
if( fgets(buffer,MAXLINE,ifp) == NULL ) {
warn("Trying to read HMMer ascii file, alphabet (5th line) not there");
return NULL;
}
if( (runner=strtok(buffer,spacestr)) == NULL ) {
warn("HMMer ascii read, alphabet line (5th line) has no alphabet!");
return NULL;
}
alphabet = stringalloc(runner);
if( fgets(buffer,MAXLINE,ifp) == NULL ) {
warn("Trying to read HMMer ascii file, reference (6th line) not there");
return NULL;
}
if( fgets(buffer,MAXLINE,ifp) == NULL ) {
warn("Trying to read HMMer ascii file, reference (7th line) not there");
return NULL;
}
/*** ok, ready to rock, we have the length and alphabet, ***/
/*** now loop over the states ... ***/
out = ThreeStateModel_alloc_len(length);
for(count=0;count < length+1 && !feof(ifp) && !(ferror(ifp));count++ ) {
temp = read_HMMer_1_7_ThreeStateUnit(alphabet,ifp);
if( temp == NULL ) {
warn("In HMMer read, On unit number [%d], unable to get unit...",count);
break;
}
if( count == 0 )
continue; /** skip first "dummy" state **/
else add_ThreeStateModel(out,temp);
}
out->name = stringalloc("HMMer Model");
out->alphabet = alphabet;
/*** by default, make it a global model ***/
force_global_model(out,1.0);
return out;
}
/* Function: read_HMMer_1_7_ThreeStateUnit(alphabet,ifp)
*
* Descrip: Function to read a single unit from a 1.7(1.8) file
*
*
*
* Arg: alphabet [UNKN ] Undocumented argument [char *]
* Arg: ifp [UNKN ] Undocumented argument [FILE *]
*
* Return [UNKN ] Undocumented return value [ThreeStateUnit *]
*
*/
# line 1190 "threestatemodel.dy"
ThreeStateUnit * read_HMMer_1_7_ThreeStateUnit(char * alphabet,FILE * ifp)
{
char buffer[MAXLINE];
char * runner;
char * al;
ThreeStateUnit * out;
if( fgets(buffer,MAXLINE,ifp) == NULL ) {
/*** could be the end of the model. Return silently for the next stage ***/
return NULL;
}
if( strstartcmp(buffer,"###MATCH_STATE") != 0 ) {
warn("Start of ThreeStateUnit HMMr read... does not match [###MATCH_STATE], instead... [%s]",buffer);
return NULL;
}
out = blank_ThreeStateUnit();
if( out == NULL )
return NULL; /** warning already issued **/
/*** ok read in the first three transitions ***/
/*** transitions for MATCH ***/
if( fgets(buffer,MAXLINE,ifp) == NULL ) {
warn("In reading HMMr ThreeStateUnit, got no m2m line");
free_ThreeStateUnit(out);
return NULL;
}
if( (runner = strtok(buffer,spacestr)) == NULL ) {
warn("In reading HMMr ThreeStateUnit, got m2m line, but no transition worked out");
return NULL;
}
out->transition[TSM_MATCH2MATCH] = atof(runner);
if( fgets(buffer,MAXLINE,ifp) == NULL ) {
warn("In reading HMMr ThreeStateUnit, got no m2d line");
free_ThreeStateUnit(out);
return NULL;
}
if( (runner = strtok(buffer,spacestr)) == NULL ) {
warn("In reading HMMr ThreeStateUnit, got m2d line, but no transition worked out");
return NULL;
}
out->transition[TSM_MATCH2DELETE] = atof(runner);
if( fgets(buffer,MAXLINE,ifp) == NULL ) {
warn("In reading HMMr ThreeStateUnit, got no m2i line");
free_ThreeStateUnit(out);
return NULL;
}
if( (runner = strtok(buffer,spacestr)) == NULL ) {
warn("In reading HMMr ThreeStateUnit, got m2i line, but no transition worked out");
return NULL;
}
out->transition[TSM_MATCH2INSERT] = atof(runner);
/*** match emission probs ***/
for(al=alphabet;*al;al++) {
if( fgets(buffer,MAXLINE,ifp) == NULL ) {
warn("In reading HMMr threestateunit, the file ended on the match emission of %c",*al);
free_ThreeStateUnit(out);
return NULL;
}
runner = strtok(buffer,spacestr);
/**** ASSUMMING a 26 alphabet now... Aaaaah ****/
out->match_emission[ toupper((int)*al)-'A'] = atof(runner);
}
/*** now to delete probabilities ***/
if( fgets(buffer,MAXLINE,ifp) == NULL ) {
warn("In reading HMMr ThreeStateUnit, got no start line!");
return NULL;
}
if( strstartcmp(buffer,"###DELETE_STATE") != 0 ) {
warn("Start of delete ThreeStateUnit HMMr read... does not match [###DELETE_STATE], instead... [%s]",buffer);
return NULL;
}
/*** ok read in the first three transitions ***/
/*** transitions for DELETE ***/
if( fgets(buffer,MAXLINE,ifp) == NULL ) {
warn("In reading HMMr ThreeStateUnit, got no d2m line");
free_ThreeStateUnit(out);
return NULL;
}
if( (runner = strtok(buffer,spacestr)) == NULL ) {
warn("In reading HMMr ThreeStateUnit, got d2m line, but no transition worked out");
return NULL;
}
out->transition[TSM_DELETE2MATCH] = atof(runner);
if( fgets(buffer,MAXLINE,ifp) == NULL ) {
warn("In reading HMMr ThreeStateUnit, got no d2d line");
free_ThreeStateUnit(out);
return NULL;
}
if( (runner = strtok(buffer,spacestr)) == NULL ) {
warn("In reading HMMr ThreeStateUnit, got d2d line, but no transition worked out");
return NULL;
}
out->transition[TSM_DELETE2DELETE] = atof(runner);
if( fgets(buffer,MAXLINE,ifp) == NULL ) {
warn("In reading HMMr ThreeStateUnit, got no d2i line");
free_ThreeStateUnit(out);
return NULL;
}
if( (runner = strtok(buffer,spacestr)) == NULL ) {
warn("In reading HMMr ThreeStateUnit, got d2i line, but no transition worked out");
return NULL;
}
out->transition[TSM_DELETE2INSERT] = atof(runner);
/***** now insert probs *****/
if( fgets(buffer,MAXLINE,ifp) == NULL ) {
warn("In reading HMMr ThreeStateUnit, got no start line!");
return NULL;
}
if( strstartcmp(buffer,"###INSERT_STATE") != 0 ) {
warn("Start of ThreeStateUnit HMMr read... does not match [###INSERT_STATE], instead... [%s]",buffer);
return NULL;
}
/*** ok read in the first three transitions ***/
/*** transitions for INSERT ***/
if( fgets(buffer,MAXLINE,ifp) == NULL ) {
warn("In reading HMMr ThreeStateUnit, got no i2m line");
free_ThreeStateUnit(out);
return NULL;
}
if( (runner = strtok(buffer,spacestr)) == NULL ) {
warn("In reading HMMr ThreeStateUnit, got i2m line, but no transition worked out");
return NULL;
}
out->transition[TSM_INSERT2MATCH] = atof(runner);
if( fgets(buffer,MAXLINE,ifp) == NULL ) {
warn("In reading HMMr ThreeStateUnit, got no i2d line");
free_ThreeStateUnit(out);
return NULL;
}
if( (runner = strtok(buffer,spacestr)) == NULL ) {
warn("In reading HMMr ThreeStateUnit, got i2d line, but no transition worked out");
return NULL;
}
out->transition[TSM_INSERT2DELETE] = atof(runner);
if( fgets(buffer,MAXLINE,ifp) == NULL ) {
warn("In reading HMMr ThreeStateUnit, got no i2i line");
free_ThreeStateUnit(out);
return NULL;
}
if( (runner = strtok(buffer,spacestr)) == NULL ) {
warn("In reading HMMr ThreeStateUnit, got i2i line, but no transition worked out");
return NULL;
}
out->transition[TSM_INSERT2INSERT] = atof(runner);
/*** insert emission probs ***/
for(al=alphabet;*al;al++) {
if( fgets(buffer,MAXLINE,ifp) == NULL ) {
warn("In reading HMMr threestateunit, the file ended on the insert emission of %c",*al);
free_ThreeStateUnit(out);
return NULL;
}
runner = strtok(buffer,spacestr);
/**** ASSUMMING a 26 alphabet now... Aaaaah ****/
out->insert_emission[ toupper((int)*al)-'A'] = atof(runner);
}
return out;
}
/* Function: blank_ThreeStateUnit(void)
*
* Descrip: Makes a set to 0.0 unit
*
*
*
* Return [UNKN ] Undocumented return value [ThreeStateUnit *]
*
*/
# line 1404 "threestatemodel.dy"
ThreeStateUnit * blank_ThreeStateUnit(void)
{
ThreeStateUnit * out;
register int i;
out = ThreeStateUnit_alloc();
if(out == NULL )
return NULL;
for(i=0;i<26;i++)
out->match_emission[i] = out->insert_emission[i] = 0.0;
for(i=0;i<TRANSITION_LEN;i++)
out->transition[i] = 0.0;
return out;
}
# line 1476 "threestatemodel.c"
/* Function: hard_link_ThreeStateUnit(obj)
*
* Descrip: Bumps up the reference count of the object
* Meaning that multiple pointers can 'own' it
*
*
* Arg: obj [UNKN ] Object to be hard linked [ThreeStateUnit *]
*
* Return [UNKN ] Undocumented return value [ThreeStateUnit *]
*
*/
ThreeStateUnit * hard_link_ThreeStateUnit(ThreeStateUnit * obj)
{
if( obj == NULL ) {
warn("Trying to hard link to a ThreeStateUnit object: passed a NULL object");
return NULL;
}
obj->dynamite_hard_link++;
return obj;
}
/* Function: ThreeStateUnit_alloc(void)
*
* Descrip: Allocates structure: assigns defaults if given
*
*
*
* Return [UNKN ] Undocumented return value [ThreeStateUnit *]
*
*/
ThreeStateUnit * ThreeStateUnit_alloc(void)
{
ThreeStateUnit * out; /* out is exported at end of function */
/* call ckalloc and see if NULL */
if((out=(ThreeStateUnit *) ckalloc (sizeof(ThreeStateUnit))) == NULL) {
warn("ThreeStateUnit_alloc failed ");
return NULL; /* calling function should respond! */
}
out->dynamite_hard_link = 1;
#ifdef PTHREAD
pthread_mutex_init(&(out->dynamite_mutex),NULL);
#endif
/* match_emission[ALPHABET_SIZE] is an array: no default possible */
/* insert_emission[ALPHABET_SIZE] is an array: no default possible */
/* transition[TRANSITION_LEN] is an array: no default possible */
out->display_char = 'u';
return out;
}
/* Function: free_ThreeStateUnit(obj)
*
* Descrip: Free Function: removes the memory held by obj
* Will chain up to owned members and clear all lists
*
*
* Arg: obj [UNKN ] Object that is free'd [ThreeStateUnit *]
*
* Return [UNKN ] Undocumented return value [ThreeStateUnit *]
*
*/
ThreeStateUnit * free_ThreeStateUnit(ThreeStateUnit * obj)
{
int return_early = 0;
if( obj == NULL) {
warn("Attempting to free a NULL pointer to a ThreeStateUnit obj. Should be trappable");
return NULL;
}
#ifdef PTHREAD
assert(pthread_mutex_lock(&(obj->dynamite_mutex)) == 0);
#endif
if( obj->dynamite_hard_link > 1) {
return_early = 1;
obj->dynamite_hard_link--;
}
#ifdef PTHREAD
assert(pthread_mutex_unlock(&(obj->dynamite_mutex)) == 0);
#endif
if( return_early == 1)
return NULL;
ckfree(obj);
return NULL;
}
/* Function: swap_ThreeStateModel(list,i,j)
*
* Descrip: swap function: an internal for qsort_ThreeStateModel
* swaps two positions in the array
*
*
* Arg: list [UNKN ] List of structures to swap in [ThreeStateUnit **]
* Arg: i [UNKN ] swap position [int]
* Arg: j [UNKN ] swap position [int]
*
*/
/* swap function for qsort function */
void swap_ThreeStateModel(ThreeStateUnit ** list,int i,int j)
{
ThreeStateUnit * temp;
temp=list[i];
list[i]=list[j];
list[j]=temp;
}
/* Function: qsort_ThreeStateModel(list,left,right,comp)
*
* Descrip: qsort - lifted from K&R
* sorts the array using quicksort
* Probably much better to call sort_ThreeStateModel which sorts from start to end
*
*
* Arg: list [UNKN ] List of structures to swap in [ThreeStateUnit **]
* Arg: left [UNKN ] left position [int]
* Arg: right [UNKN ] right position [int]
* Arg: comp [FUNCP] Function which returns -1 or 1 to sort on [int (*comp]
*
*/
void qsort_ThreeStateModel(ThreeStateUnit ** list,int left,int right,int (*comp)(ThreeStateUnit * ,ThreeStateUnit * ))
{
int i,last;
if( left >= right )
return;
swap_ThreeStateModel(list,left,(left+right)/2);
last = left;
for ( i=left+1; i <= right;i++) {
if( (*comp)(list[i],list[left]) < 0)
swap_ThreeStateModel (list,++last,i);
}
swap_ThreeStateModel (list,left,last);
qsort_ThreeStateModel(list,left,last-1,comp);
qsort_ThreeStateModel(list,last+1,right,comp);
}
/* Function: sort_ThreeStateModel(obj,comp)
*
* Descrip: sorts from start to end using comp
* sorts the array using quicksort by calling qsort_ThreeStateModel
*
*
* Arg: obj [UNKN ] Object containing list [ThreeStateModel *]
* Arg: comp [FUNCP] Function which returns -1 or 1 to sort on [int (*comp]
*
*/
void sort_ThreeStateModel(ThreeStateModel * obj,int (*comp)(ThreeStateUnit *, ThreeStateUnit *))
{
qsort_ThreeStateModel(obj->unit,0,obj->len-1,comp);
return;
}
/* Function: expand_ThreeStateModel(obj,len)
*
* Descrip: Really an internal function for add_ThreeStateModel
*
*
* Arg: obj [UNKN ] Object which contains the list [ThreeStateModel *]
* Arg: len [UNKN ] Length to add one [int]
*
* Return [UNKN ] Undocumented return value [boolean]
*
*/
boolean expand_ThreeStateModel(ThreeStateModel * obj,int len)
{
if( obj->maxlen > obj->len ) {
warn("expand_ThreeStateModel called with no need");
return TRUE;
}
if( (obj->unit = (ThreeStateUnit ** ) ckrealloc (obj->unit,sizeof(ThreeStateUnit *)*len)) == NULL) {
warn("ckrealloc failed for expand_ThreeStateModel, returning FALSE");
return FALSE;
}
obj->maxlen = len;
return TRUE;
}
/* Function: add_ThreeStateModel(obj,add)
*
* Descrip: Adds another object to the list. It will expand the list if necessary
*
*
* Arg: obj [UNKN ] Object which contains the list [ThreeStateModel *]
* Arg: add [OWNER] Object to add to the list [ThreeStateUnit *]
*
* Return [UNKN ] Undocumented return value [boolean]
*
*/
/* will expand function if necessary */
boolean add_ThreeStateModel(ThreeStateModel * obj,ThreeStateUnit * add)
{
if( obj->len >= obj->maxlen) {
if( expand_ThreeStateModel(obj,obj->len + ThreeStateModelLISTLENGTH) == FALSE)
return FALSE;
}
obj->unit[obj->len++]=add;
return TRUE;
}
/* Function: flush_ThreeStateModel(obj)
*
* Descrip: Frees the list elements, sets length to 0
* If you want to save some elements, use hard_link_xxx
* to protect them from being actually destroyed in the free
*
*
* Arg: obj [UNKN ] Object which contains the list [ThreeStateModel *]
*
* Return [UNKN ] Undocumented return value [int]
*
*/
int flush_ThreeStateModel(ThreeStateModel * obj)
{
int i;
for(i=0;i<obj->len;i++) { /*for i over list length*/
if( obj->unit[i] != NULL) {
free_ThreeStateUnit(obj->unit[i]);
obj->unit[i] = NULL;
}
} /* end of for i over list length */
obj->len = 0;
return i;
}
/* Function: ThreeStateModel_alloc_std(void)
*
* Descrip: Equivalent to ThreeStateModel_alloc_len(ThreeStateModelLISTLENGTH)
*
*
*
* Return [UNKN ] Undocumented return value [ThreeStateModel *]
*
*/
ThreeStateModel * ThreeStateModel_alloc_std(void)
{
return ThreeStateModel_alloc_len(ThreeStateModelLISTLENGTH);
}
/* Function: ThreeStateModel_alloc_len(len)
*
* Descrip: Allocates len length to all lists
*
*
* Arg: len [UNKN ] Length of lists to allocate [int]
*
* Return [UNKN ] Undocumented return value [ThreeStateModel *]
*
*/
ThreeStateModel * ThreeStateModel_alloc_len(int len)
{
ThreeStateModel * out; /* out is exported at the end of function */
/* Call alloc function: return NULL if NULL */
/* Warning message alread in alloc function */
if((out = ThreeStateModel_alloc()) == NULL)
return NULL;
/* Calling ckcalloc for list elements */
if((out->unit = (ThreeStateUnit ** ) ckcalloc (len,sizeof(ThreeStateUnit *))) == NULL) {
warn("Warning, ckcalloc failed in ThreeStateModel_alloc_len");
return NULL;
}
out->len = 0;
out->maxlen = len;
return out;
}
/* Function: hard_link_ThreeStateModel(obj)
*
* Descrip: Bumps up the reference count of the object
* Meaning that multiple pointers can 'own' it
*
*
* Arg: obj [UNKN ] Object to be hard linked [ThreeStateModel *]
*
* Return [UNKN ] Undocumented return value [ThreeStateModel *]
*
*/
ThreeStateModel * hard_link_ThreeStateModel(ThreeStateModel * obj)
{
if( obj == NULL ) {
warn("Trying to hard link to a ThreeStateModel object: passed a NULL object");
return NULL;
}
obj->dynamite_hard_link++;
return obj;
}
/* Function: ThreeStateModel_alloc(void)
*
* Descrip: Allocates structure: assigns defaults if given
*
*
*
* Return [UNKN ] Undocumented return value [ThreeStateModel *]
*
*/
ThreeStateModel * ThreeStateModel_alloc(void)
{
ThreeStateModel * out; /* out is exported at end of function */
/* call ckalloc and see if NULL */
if((out=(ThreeStateModel *) ckalloc (sizeof(ThreeStateModel))) == NULL) {
warn("ThreeStateModel_alloc failed ");
return NULL; /* calling function should respond! */
}
out->dynamite_hard_link = 1;
#ifdef PTHREAD
pthread_mutex_init(&(out->dynamite_mutex),NULL);
#endif
out->name = NULL;
out->unit = NULL;
out->len = out->maxlen = 0;
out->alphabet = NULL;
out->accession = NULL;
out->threshold = 0;
out->rm = NULL;
return out;
}
/* Function: free_ThreeStateModel(obj)
*
* Descrip: Free Function: removes the memory held by obj
* Will chain up to owned members and clear all lists
*
*
* Arg: obj [UNKN ] Object that is free'd [ThreeStateModel *]
*
* Return [UNKN ] Undocumented return value [ThreeStateModel *]
*
*/
ThreeStateModel * free_ThreeStateModel(ThreeStateModel * obj)
{
int return_early = 0;
int i;
if( obj == NULL) {
warn("Attempting to free a NULL pointer to a ThreeStateModel obj. Should be trappable");
return NULL;
}
#ifdef PTHREAD
assert(pthread_mutex_lock(&(obj->dynamite_mutex)) == 0);
#endif
if( obj->dynamite_hard_link > 1) {
return_early = 1;
obj->dynamite_hard_link--;
}
#ifdef PTHREAD
assert(pthread_mutex_unlock(&(obj->dynamite_mutex)) == 0);
#endif
if( return_early == 1)
return NULL;
if( obj->name != NULL)
ckfree(obj->name);
if( obj->unit != NULL) {
for(i=0;i<obj->len;i++) {
if( obj->unit[i] != NULL)
free_ThreeStateUnit(obj->unit[i]);
}
ckfree(obj->unit);
}
if( obj->alphabet != NULL)
ckfree(obj->alphabet);
if( obj->accession != NULL)
ckfree(obj->accession);
if( obj->rm != NULL)
free_RandomModel(obj->rm);
ckfree(obj);
return NULL;
}
/* Function: hard_link_ThreeStateScoreUnit(obj)
*
* Descrip: Bumps up the reference count of the object
* Meaning that multiple pointers can 'own' it
*
*
* Arg: obj [UNKN ] Object to be hard linked [ThreeStateScoreUnit *]
*
* Return [UNKN ] Undocumented return value [ThreeStateScoreUnit *]
*
*/
ThreeStateScoreUnit * hard_link_ThreeStateScoreUnit(ThreeStateScoreUnit * obj)
{
if( obj == NULL ) {
warn("Trying to hard link to a ThreeStateScoreUnit object: passed a NULL object");
return NULL;
}
obj->dynamite_hard_link++;
return obj;
}
/* Function: ThreeStateScoreUnit_alloc(void)
*
* Descrip: Allocates structure: assigns defaults if given
*
*
*
* Return [UNKN ] Undocumented return value [ThreeStateScoreUnit *]
*
*/
ThreeStateScoreUnit * ThreeStateScoreUnit_alloc(void)
{
ThreeStateScoreUnit * out; /* out is exported at end of function */
/* call ckalloc and see if NULL */
if((out=(ThreeStateScoreUnit *) ckalloc (sizeof(ThreeStateScoreUnit))) == NULL) {
warn("ThreeStateScoreUnit_alloc failed ");
return NULL; /* calling function should respond! */
}
out->dynamite_hard_link = 1;
#ifdef PTHREAD
pthread_mutex_init(&(out->dynamite_mutex),NULL);
#endif
/* match[ALPHABET_SIZE] is an array: no default possible */
/* insert[ALPHABET_SIZE] is an array: no default possible */
/* trans[TRANSITION_LEN] is an array: no default possible */
return out;
}
/* Function: free_ThreeStateScoreUnit(obj)
*
* Descrip: Free Function: removes the memory held by obj
* Will chain up to owned members and clear all lists
*
*
* Arg: obj [UNKN ] Object that is free'd [ThreeStateScoreUnit *]
*
* Return [UNKN ] Undocumented return value [ThreeStateScoreUnit *]
*
*/
ThreeStateScoreUnit * free_ThreeStateScoreUnit(ThreeStateScoreUnit * obj)
{
int return_early = 0;
if( obj == NULL) {
warn("Attempting to free a NULL pointer to a ThreeStateScoreUnit obj. Should be trappable");
return NULL;
}
#ifdef PTHREAD
assert(pthread_mutex_lock(&(obj->dynamite_mutex)) == 0);
#endif
if( obj->dynamite_hard_link > 1) {
return_early = 1;
obj->dynamite_hard_link--;
}
#ifdef PTHREAD
assert(pthread_mutex_unlock(&(obj->dynamite_mutex)) == 0);
#endif
if( return_early == 1)
return NULL;
ckfree(obj);
return NULL;
}
/* Function: swap_ThreeStateScore(list,i,j)
*
* Descrip: swap function: an internal for qsort_ThreeStateScore
* swaps two positions in the array
*
*
* Arg: list [UNKN ] List of structures to swap in [ThreeStateScoreUnit **]
* Arg: i [UNKN ] swap position [int]
* Arg: j [UNKN ] swap position [int]
*
*/
/* swap function for qsort function */
void swap_ThreeStateScore(ThreeStateScoreUnit ** list,int i,int j)
{
ThreeStateScoreUnit * temp;
temp=list[i];
list[i]=list[j];
list[j]=temp;
}
/* Function: qsort_ThreeStateScore(list,left,right,comp)
*
* Descrip: qsort - lifted from K&R
* sorts the array using quicksort
* Probably much better to call sort_ThreeStateScore which sorts from start to end
*
*
* Arg: list [UNKN ] List of structures to swap in [ThreeStateScoreUnit **]
* Arg: left [UNKN ] left position [int]
* Arg: right [UNKN ] right position [int]
* Arg: comp [FUNCP] Function which returns -1 or 1 to sort on [int (*comp]
*
*/
void qsort_ThreeStateScore(ThreeStateScoreUnit ** list,int left,int right,int (*comp)(ThreeStateScoreUnit * ,ThreeStateScoreUnit * ))
{
int i,last;
if( left >= right )
return;
swap_ThreeStateScore(list,left,(left+right)/2);
last = left;
for ( i=left+1; i <= right;i++) {
if( (*comp)(list[i],list[left]) < 0)
swap_ThreeStateScore (list,++last,i);
}
swap_ThreeStateScore (list,left,last);
qsort_ThreeStateScore(list,left,last-1,comp);
qsort_ThreeStateScore(list,last+1,right,comp);
}
/* Function: sort_ThreeStateScore(obj,comp)
*
* Descrip: sorts from start to end using comp
* sorts the array using quicksort by calling qsort_ThreeStateScore
*
*
* Arg: obj [UNKN ] Object containing list [ThreeStateScore *]
* Arg: comp [FUNCP] Function which returns -1 or 1 to sort on [int (*comp]
*
*/
void sort_ThreeStateScore(ThreeStateScore * obj,int (*comp)(ThreeStateScoreUnit *, ThreeStateScoreUnit *))
{
qsort_ThreeStateScore(obj->unit,0,obj->len-1,comp);
return;
}
/* Function: expand_ThreeStateScore(obj,len)
*
* Descrip: Really an internal function for add_ThreeStateScore
*
*
* Arg: obj [UNKN ] Object which contains the list [ThreeStateScore *]
* Arg: len [UNKN ] Length to add one [int]
*
* Return [UNKN ] Undocumented return value [boolean]
*
*/
boolean expand_ThreeStateScore(ThreeStateScore * obj,int len)
{
if( obj->maxlen > obj->len ) {
warn("expand_ThreeStateScore called with no need");
return TRUE;
}
if( (obj->unit = (ThreeStateScoreUnit ** ) ckrealloc (obj->unit,sizeof(ThreeStateScoreUnit *)*len)) == NULL) {
warn("ckrealloc failed for expand_ThreeStateScore, returning FALSE");
return FALSE;
}
obj->maxlen = len;
return TRUE;
}
/* Function: add_ThreeStateScore(obj,add)
*
* Descrip: Adds another object to the list. It will expand the list if necessary
*
*
* Arg: obj [UNKN ] Object which contains the list [ThreeStateScore *]
* Arg: add [OWNER] Object to add to the list [ThreeStateScoreUnit *]
*
* Return [UNKN ] Undocumented return value [boolean]
*
*/
/* will expand function if necessary */
boolean add_ThreeStateScore(ThreeStateScore * obj,ThreeStateScoreUnit * add)
{
if( obj->len >= obj->maxlen) {
if( expand_ThreeStateScore(obj,obj->len + ThreeStateScoreLISTLENGTH) == FALSE)
return FALSE;
}
obj->unit[obj->len++]=add;
return TRUE;
}
/* Function: flush_ThreeStateScore(obj)
*
* Descrip: Frees the list elements, sets length to 0
* If you want to save some elements, use hard_link_xxx
* to protect them from being actually destroyed in the free
*
*
* Arg: obj [UNKN ] Object which contains the list [ThreeStateScore *]
*
* Return [UNKN ] Undocumented return value [int]
*
*/
int flush_ThreeStateScore(ThreeStateScore * obj)
{
int i;
for(i=0;i<obj->len;i++) { /*for i over list length*/
if( obj->unit[i] != NULL) {
free_ThreeStateScoreUnit(obj->unit[i]);
obj->unit[i] = NULL;
}
} /* end of for i over list length */
obj->len = 0;
return i;
}
/* Function: ThreeStateScore_alloc_std(void)
*
* Descrip: Equivalent to ThreeStateScore_alloc_len(ThreeStateScoreLISTLENGTH)
*
*
*
* Return [UNKN ] Undocumented return value [ThreeStateScore *]
*
*/
ThreeStateScore * ThreeStateScore_alloc_std(void)
{
return ThreeStateScore_alloc_len(ThreeStateScoreLISTLENGTH);
}
/* Function: ThreeStateScore_alloc_len(len)
*
* Descrip: Allocates len length to all lists
*
*
* Arg: len [UNKN ] Length of lists to allocate [int]
*
* Return [UNKN ] Undocumented return value [ThreeStateScore *]
*
*/
ThreeStateScore * ThreeStateScore_alloc_len(int len)
{
ThreeStateScore * out; /* out is exported at the end of function */
/* Call alloc function: return NULL if NULL */
/* Warning message alread in alloc function */
if((out = ThreeStateScore_alloc()) == NULL)
return NULL;
/* Calling ckcalloc for list elements */
if((out->unit = (ThreeStateScoreUnit ** ) ckcalloc (len,sizeof(ThreeStateScoreUnit *))) == NULL) {
warn("Warning, ckcalloc failed in ThreeStateScore_alloc_len");
return NULL;
}
out->len = 0;
out->maxlen = len;
return out;
}
/* Function: hard_link_ThreeStateScore(obj)
*
* Descrip: Bumps up the reference count of the object
* Meaning that multiple pointers can 'own' it
*
*
* Arg: obj [UNKN ] Object to be hard linked [ThreeStateScore *]
*
* Return [UNKN ] Undocumented return value [ThreeStateScore *]
*
*/
ThreeStateScore * hard_link_ThreeStateScore(ThreeStateScore * obj)
{
if( obj == NULL ) {
warn("Trying to hard link to a ThreeStateScore object: passed a NULL object");
return NULL;
}
obj->dynamite_hard_link++;
return obj;
}
/* Function: ThreeStateScore_alloc(void)
*
* Descrip: Allocates structure: assigns defaults if given
*
*
*
* Return [UNKN ] Undocumented return value [ThreeStateScore *]
*
*/
ThreeStateScore * ThreeStateScore_alloc(void)
{
ThreeStateScore * out; /* out is exported at end of function */
/* call ckalloc and see if NULL */
if((out=(ThreeStateScore *) ckalloc (sizeof(ThreeStateScore))) == NULL) {
warn("ThreeStateScore_alloc failed ");
return NULL; /* calling function should respond! */
}
out->dynamite_hard_link = 1;
#ifdef PTHREAD
pthread_mutex_init(&(out->dynamite_mutex),NULL);
#endif
out->unit = NULL;
out->len = out->maxlen = 0;
out->name = NULL;
out->accession = NULL;
return out;
}
/* Function: free_ThreeStateScore(obj)
*
* Descrip: Free Function: removes the memory held by obj
* Will chain up to owned members and clear all lists
*
*
* Arg: obj [UNKN ] Object that is free'd [ThreeStateScore *]
*
* Return [UNKN ] Undocumented return value [ThreeStateScore *]
*
*/
ThreeStateScore * free_ThreeStateScore(ThreeStateScore * obj)
{
int return_early = 0;
int i;
if( obj == NULL) {
warn("Attempting to free a NULL pointer to a ThreeStateScore obj. Should be trappable");
return NULL;
}
#ifdef PTHREAD
assert(pthread_mutex_lock(&(obj->dynamite_mutex)) == 0);
#endif
if( obj->dynamite_hard_link > 1) {
return_early = 1;
obj->dynamite_hard_link--;
}
#ifdef PTHREAD
assert(pthread_mutex_unlock(&(obj->dynamite_mutex)) == 0);
#endif
if( return_early == 1)
return NULL;
if( obj->unit != NULL) {
for(i=0;i<obj->len;i++) {
if( obj->unit[i] != NULL)
free_ThreeStateScoreUnit(obj->unit[i]);
}
ckfree(obj->unit);
}
if( obj->name != NULL)
ckfree(obj->name);
if( obj->accession != NULL)
ckfree(obj->accession);
ckfree(obj);
return NULL;
}
/* Function: replace_name_ThreeStateModel(obj,name)
*
* Descrip: Replace member variable name
* For use principly by API functions
*
*
* Arg: obj [UNKN ] Object holding the variable [ThreeStateModel *]
* Arg: name [OWNER] New value of the variable [char *]
*
* Return [SOFT ] member variable name [boolean]
*
*/
boolean replace_name_ThreeStateModel(ThreeStateModel * obj,char * name)
{
if( obj == NULL) {
warn("In replacement function name for object ThreeStateModel, got a NULL object");
return FALSE;
}
obj->name = name;
return TRUE;
}
/* Function: access_name_ThreeStateModel(obj)
*
* Descrip: Access member variable name
* For use principly by API functions
*
*
* Arg: obj [UNKN ] Object holding the variable [ThreeStateModel *]
*
* Return [SOFT ] member variable name [char *]
*
*/
char * access_name_ThreeStateModel(ThreeStateModel * obj)
{
if( obj == NULL) {
warn("In accessor function name for object ThreeStateModel, got a NULL object");
return NULL;
}
return obj->name;
}
/* Function: access_unit_ThreeStateModel(obj,i)
*
* Descrip: Access members stored in the unit list
* For use principly by API functions
*
*
* Arg: obj [UNKN ] Object holding the list [ThreeStateModel *]
* Arg: i [UNKN ] Position in the list [int]
*
* Return [SOFT ] Element of the list [ThreeStateUnit *]
*
*/
ThreeStateUnit * access_unit_ThreeStateModel(ThreeStateModel * obj,int i)
{
if( obj == NULL) {
warn("In accessor function unit for object ThreeStateModel, got a NULL object");
return NULL;
}
if( obj->len <= i ) {
warn("In accessor function unit for object ThreeStateModel, index %%d is greater than list length %%d",i,obj->len);
return NULL;
}
return obj->unit[i];
}
/* Function: length_unit_ThreeStateModel(obj)
*
* Descrip: discover the length of the list
* For use principly by API functions
*
*
* Arg: obj [UNKN ] Object holding the list [ThreeStateModel *]
*
* Return [UNKN ] length of the list [int]
*
*/
int length_unit_ThreeStateModel(ThreeStateModel * obj)
{
if( obj == NULL) {
warn("In length function unit for object ThreeStateModel, got a NULL object");
return -1;
}
return obj->len;
}
/* Function: replace_alphabet_ThreeStateModel(obj,alphabet)
*
* Descrip: Replace member variable alphabet
* For use principly by API functions
*
*
* Arg: obj [UNKN ] Object holding the variable [ThreeStateModel *]
* Arg: alphabet [OWNER] New value of the variable [char *]
*
* Return [SOFT ] member variable alphabet [boolean]
*
*/
boolean replace_alphabet_ThreeStateModel(ThreeStateModel * obj,char * alphabet)
{
if( obj == NULL) {
warn("In replacement function alphabet for object ThreeStateModel, got a NULL object");
return FALSE;
}
obj->alphabet = alphabet;
return TRUE;
}
/* Function: access_alphabet_ThreeStateModel(obj)
*
* Descrip: Access member variable alphabet
* For use principly by API functions
*
*
* Arg: obj [UNKN ] Object holding the variable [ThreeStateModel *]
*
* Return [SOFT ] member variable alphabet [char *]
*
*/
char * access_alphabet_ThreeStateModel(ThreeStateModel * obj)
{
if( obj == NULL) {
warn("In accessor function alphabet for object ThreeStateModel, got a NULL object");
return NULL;
}
return obj->alphabet;
}
/* Function: replace_accession_ThreeStateModel(obj,accession)
*
* Descrip: Replace member variable accession
* For use principly by API functions
*
*
* Arg: obj [UNKN ] Object holding the variable [ThreeStateModel *]
* Arg: accession [OWNER] New value of the variable [char *]
*
* Return [SOFT ] member variable accession [boolean]
*
*/
boolean replace_accession_ThreeStateModel(ThreeStateModel * obj,char * accession)
{
if( obj == NULL) {
warn("In replacement function accession for object ThreeStateModel, got a NULL object");
return FALSE;
}
obj->accession = accession;
return TRUE;
}
/* Function: access_accession_ThreeStateModel(obj)
*
* Descrip: Access member variable accession
* For use principly by API functions
*
*
* Arg: obj [UNKN ] Object holding the variable [ThreeStateModel *]
*
* Return [SOFT ] member variable accession [char *]
*
*/
char * access_accession_ThreeStateModel(ThreeStateModel * obj)
{
if( obj == NULL) {
warn("In accessor function accession for object ThreeStateModel, got a NULL object");
return NULL;
}
return obj->accession;
}
/* Function: replace_threshold_ThreeStateModel(obj,threshold)
*
* Descrip: Replace member variable threshold
* For use principly by API functions
*
*
* Arg: obj [UNKN ] Object holding the variable [ThreeStateModel *]
* Arg: threshold [OWNER] New value of the variable [double]
*
* Return [SOFT ] member variable threshold [boolean]
*
*/
boolean replace_threshold_ThreeStateModel(ThreeStateModel * obj,double threshold)
{
if( obj == NULL) {
warn("In replacement function threshold for object ThreeStateModel, got a NULL object");
return FALSE;
}
obj->threshold = threshold;
return TRUE;
}
/* Function: access_threshold_ThreeStateModel(obj)
*
* Descrip: Access member variable threshold
* For use principly by API functions
*
*
* Arg: obj [UNKN ] Object holding the variable [ThreeStateModel *]
*
* Return [SOFT ] member variable threshold [double]
*
*/
double access_threshold_ThreeStateModel(ThreeStateModel * obj)
{
if( obj == NULL) {
warn("In accessor function threshold for object ThreeStateModel, got a NULL object");
return 0;
}
return obj->threshold;
}
/* Function: replace_rm_ThreeStateModel(obj,rm)
*
* Descrip: Replace member variable rm
* For use principly by API functions
*
*
* Arg: obj [UNKN ] Object holding the variable [ThreeStateModel *]
* Arg: rm [OWNER] New value of the variable [RandomModel *]
*
* Return [SOFT ] member variable rm [boolean]
*
*/
boolean replace_rm_ThreeStateModel(ThreeStateModel * obj,RandomModel * rm)
{
if( obj == NULL) {
warn("In replacement function rm for object ThreeStateModel, got a NULL object");
return FALSE;
}
obj->rm = rm;
return TRUE;
}
/* Function: access_rm_ThreeStateModel(obj)
*
* Descrip: Access member variable rm
* For use principly by API functions
*
*
* Arg: obj [UNKN ] Object holding the variable [ThreeStateModel *]
*
* Return [SOFT ] member variable rm [RandomModel *]
*
*/
RandomModel * access_rm_ThreeStateModel(ThreeStateModel * obj)
{
if( obj == NULL) {
warn("In accessor function rm for object ThreeStateModel, got a NULL object");
return NULL;
}
return obj->rm;
}
/* Function: replace_display_char_ThreeStateUnit(obj,display_char)
*
* Descrip: Replace member variable display_char
* For use principly by API functions
*
*
* Arg: obj [UNKN ] Object holding the variable [ThreeStateUnit *]
* Arg: display_char [OWNER] New value of the variable [char]
*
* Return [SOFT ] member variable display_char [boolean]
*
*/
boolean replace_display_char_ThreeStateUnit(ThreeStateUnit * obj,char display_char)
{
if( obj == NULL) {
warn("In replacement function display_char for object ThreeStateUnit, got a NULL object");
return FALSE;
}
obj->display_char = display_char;
return TRUE;
}
/* Function: access_display_char_ThreeStateUnit(obj)
*
* Descrip: Access member variable display_char
* For use principly by API functions
*
*
* Arg: obj [UNKN ] Object holding the variable [ThreeStateUnit *]
*
* Return [SOFT ] member variable display_char [char]
*
*/
char access_display_char_ThreeStateUnit(ThreeStateUnit * obj)
{
if( obj == NULL) {
warn("In accessor function display_char for object ThreeStateUnit, got a NULL object");
return 'u';
}
return obj->display_char;
}
#ifdef _cplusplus
}
#endif
|