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 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154
|
/* File: belvuWindow.c
* Author: Gemma Barson, 2011-04-11
* Copyright (c) 2011 - 2012 Genome Research Ltd
* ---------------------------------------------------------------------------
* SeqTools is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 3
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
* or see the on-line version at http://www.gnu.org/copyleft/gpl.txt
* ---------------------------------------------------------------------------
* This file is part of the SeqTools sequence analysis package,
* written by
* Gemma Barson (Sanger Institute, UK) <gb10@sanger.ac.uk>
*
* based on original code by
* Erik Sonnhammer (SBC, Sweden) <Erik.Sonnhammer@sbc.su.se>
*
* and utilizing code taken from the AceDB and ZMap packages, written by
* Richard Durbin (Sanger Institute, UK) <rd@sanger.ac.uk>
* Jean Thierry-Mieg (CRBM du CNRS, France) <mieg@kaa.crbm.cnrs-mop.fr>
* Ed Griffiths (Sanger Institute, UK) <edgrif@sanger.ac.uk>
* Roy Storey (Sanger Institute, UK) <rds@sanger.ac.uk>
* Malcolm Hinsley (Sanger Institute, UK) <mh17@sanger.ac.uk>
*
* Description: see belvuWindow.h
*----------------------------------------------------------------------------
*/
#include "belvuApp/belvuWindow.hpp"
#include "belvuApp/belvuAlignment.hpp"
#include "belvuApp/belvuTree.hpp"
#include "belvuApp/belvuConsPlot.hpp"
#include "belvuApp/belvu_.hpp"
#include <gbtools/gbtools.hpp>
#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>
#include <string.h>
#include <unistd.h>
#include <algorithm>
using namespace std;
#define DEFAULT_WINDOW_BORDER_WIDTH 1 /* used to change the default border width around the blixem window */
#define DEFAULT_FONT_SIZE_ADJUSTMENT 0 /* used to start with a smaller font than the default widget font */
#define MAIN_BELVU_WINDOW_NAME "BelvuWindow"
#define WRAPPED_BELVU_WINDOW_NAME "WrappedBelvuWindow"
#define BELVU_ORGS_WINDOW_NAME "BelvuOrgsWindow"
#define DEFAULT_WRAP_WINDOW_WIDTH_FRACTION 0.6 /* default width of wrap window (as fraction of screen width) */
#define DEFAULT_WRAP_WINDOW_HEIGHT_FRACTION 0.85 /* default height of wrap window (as fraction of screen height) */
#define MAX_ORGS_WINDOW_WIDTH_FRACTION 0.5 /* max width of organisms window (as fraction of screen width) */
#define MAX_ORGS_WINDOW_HEIGHT_FRACTION 0.7 /* max height of organisms window (as fraction of screen height) */
#define MAX_ANNOTATION_WINDOW_WIDTH_FRACTION 0.6 /* max width of annotation window (as fraction of screen width) */
#define MAX_ANNOTATION_WINDOW_HEIGHT_FRACTION 0.7 /* max height of annotation window (as fraction of screen height) */
#define ORGS_WINDOW_XPAD 20 /* x padding for the organisms window */
#define ORGS_WINDOW_YPAD 20 /* y padding for the organisms window */
/* Utility struct to pass data to the color-changed callback
* when a color has been changed on the edit-colors dialog */
typedef struct _ColorChangeData
{
GtkWidget *colorButton; /* The color-picker button */
char *residue; /* The residue that this color applies to */
} ColorChangeData;
/* Properties specific to the belvu window */
class BelvuWindowProperties
{
public:
GtkWidget *widget; /* The belvu window */
BelvuContext *bc; /* The belvu context */
GtkWidget *statusBar; /* Message bar at the bottom of the main window */
GtkWidget *feedbackBox; /* Feedback area showing info about the current selction */
GtkActionGroup *actionGroup;
};
/* Properties for generic windows */
class GenericWindowProperties
{
public:
GtkWidget *widget; /* The window */
BelvuContext *bc; /* The belvu context */
GtkActionGroup *actionGroup;
};
/* Local function declarations */
static void onCloseMenu(GtkAction *action, gpointer data);
static void onQuitMenu(GtkAction *action, gpointer data);
static void onHelpMenu(GtkAction *action, gpointer data);
static void onAboutMenu(GtkAction *action, gpointer data);
static void onPrintMenu(GtkAction *action, gpointer data);
static void onFindMenu(GtkAction *action, gpointer data);
static void onWrapMenu(GtkAction *action, gpointer data);
static void onShowTreeMenu(GtkAction *action, gpointer data);
static void onRecalcTreeMenu(GtkAction *action, gpointer data);
static void onTreeOptsMenu(GtkAction *action, gpointer data);
static void onConsPlotMenu(GtkAction *action, gpointer data);
static void onSaveMenu(GtkAction *action, gpointer data);
static void onSaveAsMenu(GtkAction *action, gpointer data);
static void onOutputMenu(GtkAction *action, gpointer data);
static void onFetchWWWMenu(GtkAction *action, gpointer data);
static void onCompareMenu(GtkAction *action, gpointer data);
static void onCleanUpMenu(GtkAction *action, gpointer data);
static void onrmPickedMenu(GtkAction *action, gpointer data);
static void onRemoveSeqsMenu(GtkAction *action, gpointer data);
static void onrmGappySeqsMenu(GtkAction *action, gpointer data);
static void onrmPartialSeqsMenu(GtkAction *action, gpointer data);
static void onrmRedundantMenu(GtkAction *action, gpointer data);
static void onrmOutliersMenu(GtkAction *action, gpointer data);
static void onrmScoreMenu(GtkAction *action, gpointer data);
static void onrmColumnPromptMenu(GtkAction *action, gpointer data);
static void onrmColumnLeftMenu(GtkAction *action, gpointer data);
static void onrmColumnRightMenu(GtkAction *action, gpointer data);
static void onrmColumnCutoffMenu(GtkAction *action, gpointer data);
static void onrmGappyColumnsMenu(GtkAction *action, gpointer data);
static void onAutoRmEmptyColumnsMenu(GtkAction *action, gpointer data);
static void onreadLabelsMenu(GtkAction *action, gpointer data);
static void onselectGapsMenu(GtkAction *action, gpointer data);
static void onhideMenu(GtkAction *action, gpointer data);
static void onunhideMenu(GtkAction *action, gpointer data);
static void onToggleSchemeType(GtkRadioAction *action, GtkRadioAction *current, gpointer data);
static void onToggleColorScheme(GtkRadioAction *action, GtkRadioAction *current, gpointer data);
static void onToggleSortOrder(GtkRadioAction *action, GtkRadioAction *current, gpointer data);
static void ontogglePaletteMenu(GtkAction *action, gpointer data);
static void ontoggleColorByResIdMenu(GtkAction *action, gpointer data);
static void oncolorByResIdMenu(GtkAction *action, gpointer data);
static void onsaveColorSchemeMenu(GtkAction *action, gpointer data);
static void onloadColorSchemeMenu(GtkAction *action, gpointer data);
static void onignoreGapsMenu(GtkAction *action, gpointer data);
static void onprintColorsMenu(GtkAction *action, gpointer data);
static void onexcludeHighlightedMenu(GtkAction *action, gpointer data);
static void ondisplayColorsMenu(GtkAction *action, gpointer data);
static void onlowercaseMenu(GtkAction *action, gpointer data);
static void oneditColorSchemeMenu(GtkAction *action, gpointer data);
static void onSaveTreeMenu(GtkAction *action, gpointer data);
static void onFindOrthogsMenu(GtkAction *action, gpointer data);
static void onShowOrgsMenu(GtkAction *action, gpointer data);
static void onZoomInMenu(GtkAction *action, gpointer data);
static void onZoomOutMenu(GtkAction *action, gpointer data);
static void onSetFontMenu(GtkAction *action, gpointer data);
static void showHelpDialog();
static void showAboutDialog(GtkWidget *parent);
static void showFindDialog(BelvuContext *bc, GtkWidget *window);
static void showWrapDialog(BelvuContext *bc, GtkWidget *belvuWindow);
static void createWrapWindow(GtkWidget *belvuWindow, const int linelen, const gchar *title);
static void widgetGetDrawing(GtkWidget *window, gpointer data);
static void showMakeNonRedundantDialog(GtkWidget *belvuWindow);
static void showRemoveOutliersDialog(GtkWidget *belvuWindow);
static void showRemoveByScoreDialog(GtkWidget *belvuWindow);
static void startRemovingSequences(GtkWidget *belvuWindow);
static void endRemovingSequences(GtkWidget *belvuWindow);
static void showRemoveGappySeqsDialog(GtkWidget *belvuWindow);
static void showRemoveColumnsDialog(GtkWidget *belvuWindow);
static void showRemoveColumnsCutoffDialog(GtkWidget *belvuWindow);
static void showRemoveGappyColumnsDialog(GtkWidget *belvuWindow);
static void showColorByResIdDialog(GtkWidget *belvuWindow);
static void showEditResidueColorsDialog(GtkWidget *belvuWindow, const gboolean bringToFront);
static void showEditConsColorsDialog(GtkWidget *belvuWindow, const gboolean bringToFront);
static void saveOrResetConsColors(BelvuContext *bc, const gboolean save);
static void showSelectGapCharDialog(GtkWidget *belvuWindow);
static GtkWidget* createPromptDialog(GtkWidget *window, const char *defaultResult, const char *title, const char *text1, const char *text2, GtkWidget **entry);
static gboolean saveAlignmentPrompt(GtkWidget *window, BelvuContext *bc);
static void showFontDialog(BelvuContext *bc, GtkWidget *window);
static const char* saveFasta(BelvuContext *bc, GtkWidget *parent);
static const char* saveMul(BelvuContext *bc, GtkWidget *parent);
static const char* saveMsf(BelvuContext *bc, GtkWidget *parent);
static void showSaveAsDialog(BelvuContext *bc, GtkWidget *window);
static gboolean saveAlignment(BelvuContext *bc, GtkWidget *window);
static BelvuWindowProperties* belvuWindowGetProperties(GtkWidget *widget);
static GenericWindowProperties* windowGetProperties(GtkWidget *widget);
static BelvuContext* windowGetContext(GtkWidget *window);
static void createOrganismWindow(BelvuContext *bc);
static void onDestroyBelvuWindow(GtkWidget *belvuWindow);
/***********************************************************
* Menus and Toolbar *
***********************************************************/
#define rmPickedStr "Remove highlighted line"
#define rmPickedDesc "Remove highlighted line"
#define rmManyStr "Remove many sequences..."
#define rmManyDesc "Remove many sequences"
#define rmGappySeqsStr "Remove gappy sequences..."
#define rmGappySeqsDesc "Remove gappy sequences"
#define rmPartialSeqsStr "Remove partial sequences"
#define rmPartialSeqsDesc "Remove partial sequences"
#define rmRedundantStr "Make non-redundant..."
#define rmRedundantDesc "Remove sequences that are more than a given percentage identical"
#define rmOutliersStr "Remove outliers..."
#define rmOutliersDesc "Remove sequences that are less than a given percentage identical"
#define rmScoreStr "Remove sequences by score..."
#define rmScoreDesc "Remove sequences below a given score"
#define rmColumnPromptStr "Remove columns..."
#define rmColumnPromptDesc "Remove specific columns"
#define rmColumnLeftStr "<- Remove columns left of selection (inclusive)"
#define rmColumnLeftDesc "Remove columns to the left of the currently-selected column (inclusive)"
#define rmColumnRightStr "Remove columns right of selection (inclusive) ->"
#define rmColumnRightDesc "Remove columns to the right of the currently-selected column (inclusive) -> "
#define rmColumnCutoffStr "Remove columns by conservation..."
#define rmColumnCutoffDesc "Remove columns with conservation between specific values"
#define rmGappyColumnsStr "Remove gappy columns..."
#define rmGappyColumnsDesc "Remove columns with more than a specified percentage of gaps"
#define readLabelsStr "Read labels of highlighted sequence and spread them"
#define readLabelsDesc "Read labels of highlighted sequence and spread them"
#define selectGapsStr "Select gap character..."
#define selectGapsDesc "Select the character to use for displaying gaps"
#define hideStr "Hide highlighted line"
#define hideDesc "Hide the currently-highlighted line"
#define unhideStr "Unhide all hidden lines"
#define unhideDesc "Unhide all hidden lines"
#define togglePaletteStr "Toggle color schemes"
#define togglePaletteDesc "Toggle between conservation and residue color schemes"
#define colorByResIdStr "Set %ID threshold..."
#define colorByResIdDesc "Set the threshold above which to color residues"
#define saveColorSchemeStr "Save colour scheme..."
#define saveColorSchemeDesc "Save current colour scheme"
#define loadColorSchemeStr "Load colour scheme..."
#define loadColorSchemeDesc "Read colour scheme from file"
#define editColorSchemeStr "Edit current colour scheme..."
#define editColorSchemeDesc "Edit the current colour scheme"
#define SaveTreeStr "Save Tree"
#define SaveTreeDesc "Save Tree in New Hampshire format"
#define FindOrthogsStr "Find putative orthologs"
#define FindOrthogsDesc "Find putative orthologs"
#define ShowOrgsStr "Show organisms"
#define ShowOrgsDesc "Show current organisms"
#define PlotOptsStr "Plot settings..."
#define PlotOptsDesc "Edit conservation-plot settings"
#define autoRmEmptyColumnsStr "Automatically remove empty columns"
#define autoRmEmptyColumnsDesc "Automatically remove columns that are 100% gaps after sequence deletions"
#define excludeHighlightedStr "Exclude highlighted from calculations"
#define excludeHighlightedDesc "Exclude highlighted from calculations"
#define lowercaseStr "Highlight lowercase characters"
#define lowercaseDesc "Highlight lowercase characters"
#define colorSimStr "By average similarity by Blosum62"
#define colorIdStr "By percent identity"
#define colorIdSimStr "By percent identity + Blosum62"
#define displayColorsStr "Display colors (faster without)"
#define printColorsStr "Use gray shades (for printing)"
#define ignoreGapsStr "Ignore gaps in conservation calculation"
#define thresholdStr "Only colour residues above %ID threshold"
#define ConsPlotStr "Show conservation p_lot"
#define ConsPlotDesc "Plot conservation profile"
#define WrapStr "_Wrap for printing..."
#define WrapDesc "Wrap alignments for printing"
#define OutputStr "_Output score/coords"
#define OutputDesc "Output current alignment's score and coords"
#define CompareStr "Compare all and output identities"
#define CompareDesc "Compage all sequences against all others and output their identities"
#define FetchWWWStr "Fetch sequences via WWW"
#define FetchWWWDesc "Fetch sequences via WWW"
/* Define the menu actions for standard menu entries */
static const GtkActionEntry menuEntries[] = {
{ "FileMenuAction", NULL, "_File"},
{ "EditMenuAction", NULL, "_Edit"},
{ "ColorMenuAction", NULL, "_Color"},
{ "SettingsMenuAction", NULL, "_Settings"},
{ "SortMenuAction", NULL, "S_ort"},
{ "HelpMenuAction", NULL, "_Help"},
{ "Close", GTK_STOCK_CLOSE, "_Close", "<control>W", "Close", G_CALLBACK(onCloseMenu)},
{ "Quit", GTK_STOCK_QUIT, "_Quit", "<control>Q", "Quit Ctrl+Q", G_CALLBACK(onQuitMenu)},
{ "Help", GTK_STOCK_HELP, "_Help", "<control>H", "Display help Ctrl+H", G_CALLBACK(onHelpMenu)},
{ "About", GTK_STOCK_ABOUT, "A_bout", NULL, "About", G_CALLBACK(onAboutMenu)},
{ "Print", GTK_STOCK_PRINT, "_Print...", "<control>P", "Print Ctrl+P", G_CALLBACK(onPrintMenu)},
{ "Find", GTK_STOCK_FIND, "_Find...", "<control>F", "Find Ctrl+F", G_CALLBACK(onFindMenu)},
{ "Wrap", NULL, WrapStr, NULL, WrapDesc, G_CALLBACK(onWrapMenu)},
{ "ShowTree", NULL, "Show _tree", NULL, "Show tree", G_CALLBACK(onShowTreeMenu)},
{ "RecalcTree", NULL, "Recalculate tree", NULL, "Recalculate tree (e.g. after alignment has changed or to reset after swapping nodes)", G_CALLBACK(onRecalcTreeMenu)},
{ "TreeOpts", GTK_STOCK_PREFERENCES,"Tree settings...", NULL, "Edit tree settings", G_CALLBACK(onTreeOptsMenu)},
{ "ConsPlot", NULL, ConsPlotStr, NULL, ConsPlotDesc, G_CALLBACK(onConsPlotMenu)},
{ "Save", GTK_STOCK_SAVE, "_Save", "<control>S", "Save alignment", G_CALLBACK(onSaveMenu)},
{ "SaveAs", GTK_STOCK_SAVE_AS, "Save _as...", "<shift><control>S", "Save alignment as", G_CALLBACK(onSaveAsMenu)},
{ "Output", NULL, OutputStr, NULL, OutputDesc, G_CALLBACK(onOutputMenu)},
{ "Compare", NULL, CompareStr, NULL, CompareDesc, G_CALLBACK(onCompareMenu)},
{ "CleanUp", GTK_STOCK_CLEAR, "Clean _up windows", NULL, "Clean up windows", G_CALLBACK(onCleanUpMenu)},
{"rmPicked", NULL, rmPickedStr, NULL, rmPickedDesc, G_CALLBACK(onrmPickedMenu)},
{"rmGappySeqs", NULL, rmGappySeqsStr, NULL, rmGappySeqsDesc, G_CALLBACK(onrmGappySeqsMenu)},
{"rmPartialSeqs", NULL, rmPartialSeqsStr, "<control>T" , rmPartialSeqsDesc, G_CALLBACK(onrmPartialSeqsMenu)},
{"rmRedundant", NULL, rmRedundantStr, "<control>R", rmRedundantDesc, G_CALLBACK(onrmRedundantMenu)},
{"rmOutliers", NULL, rmOutliersStr, NULL, rmOutliersDesc, G_CALLBACK(onrmOutliersMenu)},
{"rmScore", NULL, rmScoreStr, NULL, rmScoreDesc, G_CALLBACK(onrmScoreMenu)},
{"rmColumnPrompt", NULL, rmColumnPromptStr, NULL, rmColumnPromptDesc, G_CALLBACK(onrmColumnPromptMenu)},
{"rmColumnLeft", GTK_STOCK_GO_BACK, rmColumnLeftStr, NULL, rmColumnLeftDesc, G_CALLBACK(onrmColumnLeftMenu)},
{"rmColumnRight", GTK_STOCK_GO_FORWARD, rmColumnRightStr, NULL, rmColumnRightDesc, G_CALLBACK(onrmColumnRightMenu)},
{"rmColumnCutoff", NULL, rmColumnCutoffStr, NULL, rmColumnCutoffDesc, G_CALLBACK(onrmColumnCutoffMenu)},
{"rmGappyColumns", NULL, rmGappyColumnsStr, NULL, rmGappyColumnsDesc, G_CALLBACK(onrmGappyColumnsMenu)},
{"readLabels", NULL, readLabelsStr, NULL, readLabelsDesc, G_CALLBACK(onreadLabelsMenu)},
{"selectGaps", NULL, selectGapsStr, NULL, selectGapsDesc, G_CALLBACK(onselectGapsMenu)},
{"hide", NULL, hideStr, NULL, hideDesc, G_CALLBACK(onhideMenu)},
{"unhide", NULL, unhideStr, NULL, unhideDesc, G_CALLBACK(onunhideMenu)},
{"togglePalette", NULL, togglePaletteStr, "T", togglePaletteDesc, G_CALLBACK(ontogglePaletteMenu)},
{"colorByResId", NULL, colorByResIdStr, NULL, colorByResIdDesc, G_CALLBACK(oncolorByResIdMenu)},
{"saveColorScheme", NULL, saveColorSchemeStr, NULL, saveColorSchemeDesc, G_CALLBACK(onsaveColorSchemeMenu)},
{"loadColorScheme", NULL, loadColorSchemeStr, NULL, loadColorSchemeDesc, G_CALLBACK(onloadColorSchemeMenu)},
{"editColorScheme", GTK_STOCK_SELECT_COLOR, editColorSchemeStr, NULL, editColorSchemeDesc, G_CALLBACK(oneditColorSchemeMenu)},
{"SaveTree", GTK_STOCK_FLOPPY, SaveTreeStr, NULL, SaveTreeDesc, G_CALLBACK(onSaveTreeMenu)},
{"ShowOrgs", NULL, ShowOrgsStr, NULL, ShowOrgsDesc, G_CALLBACK(onShowOrgsMenu)},
{"PlotOpts", GTK_STOCK_PROPERTIES, PlotOptsStr, NULL, PlotOptsDesc, G_CALLBACK(onPlotOptsMenu)},
{"ZoomIn", GTK_STOCK_ZOOM_IN, "Zoom in", NULL, "Zoom in =", G_CALLBACK(onZoomInMenu)},
{"ZoomOut", GTK_STOCK_ZOOM_OUT, "Zoom out", NULL, "Zoom out -", G_CALLBACK(onZoomOutMenu)},
{"SetFont", NULL, "Set font size", NULL, "Set font size", G_CALLBACK(onSetFontMenu)}
};
/* Define the menu actions for toggle menu entries */
static const GtkToggleActionEntry toggleMenuEntries[] = {
{"FetchWWW", NULL, FetchWWWStr, NULL, FetchWWWDesc, G_CALLBACK(onFetchWWWMenu), FALSE},
{"rmMany", GTK_STOCK_DELETE, rmManyStr, NULL, rmManyDesc, G_CALLBACK(onRemoveSeqsMenu), FALSE},
{"FindOrthogs", NULL, FindOrthogsStr, NULL, FindOrthogsDesc, G_CALLBACK(onFindOrthogsMenu), FALSE},
{"autoRmEmptyColumns", NULL, autoRmEmptyColumnsStr, NULL, autoRmEmptyColumnsDesc, G_CALLBACK(onAutoRmEmptyColumnsMenu), TRUE},
{"toggleColorByResId", NULL, thresholdStr, NULL, thresholdStr, G_CALLBACK(ontoggleColorByResIdMenu), FALSE},
{"ignoreGaps", NULL, ignoreGapsStr, NULL, ignoreGapsStr, G_CALLBACK(onignoreGapsMenu), FALSE},
{"printColors", NULL, printColorsStr, NULL, printColorsStr, G_CALLBACK(onprintColorsMenu), FALSE},
{"excludeHighlighted", NULL, excludeHighlightedStr, NULL, excludeHighlightedDesc, G_CALLBACK(onexcludeHighlightedMenu), FALSE},
{"displayColors", NULL, displayColorsStr, NULL, displayColorsStr, G_CALLBACK(ondisplayColorsMenu), TRUE},
{"lowercase", NULL, lowercaseStr, NULL, lowercaseDesc, G_CALLBACK(onlowercaseMenu), FALSE}
};
/* Define the menu actions for radio-button menu entries */
static const GtkRadioActionEntry schemeMenuEntries[] = {
{"ColorByResidue", NULL, "Color by _residue", NULL, "Color by residue", BELVU_SCHEME_TYPE_RESIDUE},
{"ColorByCons", NULL, "Color by _conservation", NULL, "Color by conservation", BELVU_SCHEME_TYPE_CONS}
};
static const GtkRadioActionEntry colorSchemeMenuEntries[] = {
{"colorSchemeStandard", NULL, "By residue: Erik's", NULL, "Erik's", BELVU_SCHEME_ERIK},
{"colorSchemeGibson", NULL, "By residue: Toby's", NULL, "Toby's", BELVU_SCHEME_GIBSON},
{"colorSchemeCGP", NULL, "By residue: Cys/Gly/Pro", NULL, "Cys/Gly/Pro", BELVU_SCHEME_CGP},
{"colorSchemeCGPH", NULL, "By residue: Cys/Gly/Pro/His", NULL, "Cys/Gly/Pro/His", BELVU_SCHEME_CGPH},
{"colorSchemeEmpty", NULL, "By residue: Clean slate", NULL, "Clean slate", BELVU_SCHEME_NONE},
{"colorSchemeCustom", NULL, "By residue: Custom", NULL, "Custom", BELVU_SCHEME_CUSTOM},
{"colorSim", NULL, colorSimStr, NULL, colorSimStr, BELVU_SCHEME_BLOSUM},
{"colorId", NULL, colorIdStr, NULL, colorIdStr, BELVU_SCHEME_ID},
{"colorIdSim", NULL, colorIdSimStr, NULL, colorIdSimStr, BELVU_SCHEME_ID_BLOSUM}
};
static const GtkRadioActionEntry sortMenuEntries[] = {
{"unsorted", NULL, "unsorted", NULL, "Unsorted", BELVU_UNSORTED},
{"consSort", NULL, "by conservation", NULL, "Sort by conservation", BELVU_SORT_CONS},
{"scoreSort", NULL, "by score", NULL, "Sort by score", BELVU_SORT_SCORE},
{"alphaSort", GTK_STOCK_SORT_ASCENDING, "alphabetically", NULL, "Sort alphabetically", BELVU_SORT_ALPHA},
{"organismSort", NULL, "by swissprot organism", NULL, "Sort by swissprot organism", BELVU_SORT_ORGANISM},
{"treeSort", NULL, "by tree order", NULL, "Sort by tree order", BELVU_SORT_TREE},
{"simSort", NULL, "by similarity to selected sequence", NULL, "Sort by similarity to highlighted sequence", BELVU_SORT_SIM},
{"idSort", NULL, "by identity to selected sequence", NULL, "Sort by identity to highlighted sequence", BELVU_SORT_ID}
};
/* Define the menu layout */
static const char standardMenuDescription[] =
"<ui>"
/* ACCELERATORS */
" <accelerator action='togglePalette'/>"
" <accelerator action='Find'/>"
/* MAIN MENU BAR */
" <menubar name='MenuBar' accelerators='true'>"
/* File menu */
" <menu action='FileMenuAction'>"
" <menuitem action='Quit'/>"
" <menuitem action='Wrap'/>"
" <menuitem action='Print'/>"
" <separator/>"
" <menuitem action='ShowTree'/>"
" <menuitem action='TreeOpts'/>"
" <menuitem action='RecalcTree'/>"
" <separator/>"
" <menuitem action='ConsPlot'/>"
" <separator/>"
" <menuitem action='Save'/>"
" <menuitem action='SaveAs'/>"
" <menuitem action='Output'/>"
" <separator/>"
" <menuitem action='FetchWWW'/>"
" <menuitem action='Compare'/>"
" <menuitem action='CleanUp'/>"
" </menu>"
/* Edit menu */
" <menu action='EditMenuAction'>"
" <menuitem action='rmPicked'/>"
" <menuitem action='rmMany'/>"
" <menuitem action='rmGappySeqs'/>"
" <menuitem action='rmPartialSeqs'/>"
" <menuitem action='rmRedundant'/>"
" <menuitem action='rmOutliers'/>"
" <menuitem action='rmScore'/>"
" <separator/>"
" <menuitem action='rmColumnPrompt'/>"
" <menuitem action='rmColumnLeft'/>"
" <menuitem action='rmColumnRight'/>"
" <menuitem action='rmColumnCutoff'/>"
" <menuitem action='rmGappyColumns'/>"
" <menuitem action='autoRmEmptyColumns'/>"
" <separator/>"
" <menuitem action='readLabels'/>"
" <menuitem action='selectGaps'/>"
" <menuitem action='hide'/>"
" <menuitem action='unhide'/>"
" </menu>"
/* Color schemes menu */
" <menu action='ColorMenuAction'>"
" <menuitem action='colorSchemeStandard'/>"
" <menuitem action='colorSchemeGibson'/>"
" <menuitem action='colorSchemeCGP'/>"
" <menuitem action='colorSchemeCGPH'/>"
" <menuitem action='colorSchemeEmpty'/>"
" <menuitem action='colorSchemeCustom'/>"
" <separator/>"
" <menuitem action='colorSim'/>"
" <menuitem action='colorId'/>"
" <menuitem action='colorIdSim'/>"
" <separator/>"
" <menuitem action='editColorScheme'/>"
" <menuitem action='saveColorScheme'/>"
" <menuitem action='loadColorScheme'/>"
" </menu>"
/* Settings menu */
" <menu action='SettingsMenuAction'>"
" <menuitem action='toggleColorByResId'/>"
" <menuitem action='colorByResId'/>"
" <menuitem action='ignoreGaps'/>"
" <separator/>"
" <menuitem action='excludeHighlighted'/>"
" <menuitem action='printColors'/>"
" <menuitem action='displayColors'/>"
" <menuitem action='lowercase'/>"
" </menu>"
/* Sort menu */
" <menu action='SortMenuAction'>"
" <menuitem action='scoreSort'/>"
" <menuitem action='alphaSort'/>"
" <menuitem action='organismSort'/>"
" <menuitem action='treeSort'/>"
" <menuitem action='simSort'/>"
" <menuitem action='idSort'/>"
" </menu>"
/* Help menu */
" <menu action='HelpMenuAction'>"
" <menuitem action='Help'/>"
" <menuitem action='About'/>"
" </menu>"
" </menubar>"
/* CONTEXT MENUS */
/* Main context menu */
" <popup name='ContextMenu' accelerators='true'>"
" <menuitem action='Quit'/>"
" <menuitem action='Wrap'/>"
" <menuitem action='Print'/>"
" <separator/>"
" <menuitem action='ShowTree'/>"
" <menuitem action='TreeOpts'/>"
" <menuitem action='RecalcTree'/>"
" <separator/>"
" <menuitem action='ConsPlot'/>"
" <separator/>"
" <menuitem action='Save'/>"
" <menuitem action='SaveAs'/>"
" <menuitem action='Output'/>"
" <separator/>"
" <menuitem action='FetchWWW'/>"
" <menuitem action='Compare'/>"
" <menuitem action='CleanUp'/>"
" </popup>"
/* Wrapped-alignments window context menu */
" <popup name='WrapContextMenu' accelerators='true'>"
" <menuitem action='Close'/>"
" <menuitem action='Print'/>"
" <menuitem action='Wrap'/>"
" </popup>"
/* Organisms window context menu */
" <popup name='OrgsContextMenu' accelerators='true'>"
" <menuitem action='Close'/>"
" <menuitem action='Print'/>"
" </popup>"
/* Tree context menu */
" <popup name='TreeContextMenu' accelerators='true'>"
" <menuitem action='Close'/>"
" <menuitem action='Print'/>"
" <menuitem action='SaveTree'/>"
" <separator/>"
" <menuitem action='TreeOpts'/>"
" <menuitem action='RecalcTree'/>"
" <separator/>"
" <menuitem action='FindOrthogs'/>"
" <menuitem action='ShowOrgs'/>"
" </popup>"
/* Conservation-plot context menu */
" <popup name='PlotContextMenu' accelerators='true'>"
" <menuitem action='Close'/>"
" <menuitem action='Print'/>"
" <separator/>"
" <menuitem action='PlotOpts'/>"
" </popup>"
/* TOOLBAR */
" <toolbar name='Toolbar'>"
" <toolitem action='Help'/>"
" <toolitem action='rmMany'/>"
" <toolitem action='editColorScheme'/>"
" <toolitem action='alphaSort'/>"
" <separator/>"
" <toolitem action='ZoomIn'/>"
" <toolitem action='ZoomOut'/>"
" <toolitem action='Find'/>"
" </toolbar>"
"</ui>";
/* Utility function to create the UI manager for the menus */
GtkUIManager* createUiManager(GtkWidget *window,
BelvuContext *bc,
GtkActionGroup **actionGroupOut)
{
GtkActionGroup *action_group = gtk_action_group_new ("MenuActions");
gtk_action_group_add_actions(action_group, menuEntries, G_N_ELEMENTS(menuEntries), window);
gtk_action_group_add_toggle_actions(action_group, toggleMenuEntries, G_N_ELEMENTS(toggleMenuEntries), window);
gtk_action_group_add_radio_actions(action_group, schemeMenuEntries, G_N_ELEMENTS(schemeMenuEntries), bc->schemeType, G_CALLBACK(onToggleSchemeType), window);
gtk_action_group_add_radio_actions(action_group, colorSchemeMenuEntries, G_N_ELEMENTS(colorSchemeMenuEntries), BELVU_SCHEME_BLOSUM, G_CALLBACK(onToggleColorScheme), window);
gtk_action_group_add_radio_actions(action_group, sortMenuEntries, G_N_ELEMENTS(sortMenuEntries), BELVU_SORT_CONS, G_CALLBACK(onToggleSortOrder), window);
greyOutInvalidActionsForGroup(bc, action_group);
GtkUIManager *ui_manager = gtk_ui_manager_new();
gtk_ui_manager_insert_action_group(ui_manager, action_group, 0);
gtk_ui_manager_set_add_tearoffs(ui_manager, TRUE);
GtkAccelGroup *accel_group = gtk_ui_manager_get_accel_group(ui_manager);
gtk_window_add_accel_group(GTK_WINDOW(window), accel_group);
if (actionGroupOut)
*actionGroupOut = action_group;
return ui_manager;
}
/* Create a menu */
GtkWidget* createBelvuMenu(GtkWidget *window,
const char *path,
GtkUIManager *ui_manager)
{
GError *error = NULL;
if (!gtk_ui_manager_add_ui_from_string (ui_manager, standardMenuDescription, -1, &error))
{
prefixError(error, "Building menus failed: ");
reportAndClearIfError(&error, G_LOG_LEVEL_ERROR);
}
GtkWidget *menu = gtk_ui_manager_get_widget (ui_manager, path);
return menu;
}
/* The following functions implement the menu actions */
/* FILE MENU ACTIONS */
static void onCloseMenu(GtkAction *action, gpointer data)
{
GtkWidget *window = GTK_WIDGET(data);
BelvuContext *bc = windowGetContext(window);
if (window == bc->consPlot) /* conservation plot is persistent, so just hide it rather than closing */
gtk_widget_hide_all(window);
else
gtk_widget_destroy(window);
}
static void onQuitMenu(GtkAction *action, gpointer data)
{
GtkWidget *window = GTK_WIDGET(data);
BelvuContext *bc = windowGetContext(window);
if (stringsEqual(gtk_widget_get_name(window), MAIN_BELVU_WINDOW_NAME, TRUE))
{
/* If this is the main window, just call its destructor function, which
* handles save-checking and quitting the application itself (and we don't
* want to do that twice). */
onDestroyBelvuWindow(window);
}
else
{
gboolean quit = TRUE;
/* Check if the alignment has been save and if not give the option to cancel */
if (!bc->saved)
quit = saveAlignmentPrompt(window, bc);
if (quit)
gtk_main_quit();
}
}
static void onHelpMenu(GtkAction *action, gpointer data)
{
showHelpDialog();
}
static void onAboutMenu(GtkAction *action, gpointer data)
{
GtkWidget *belvuWindow = GTK_WIDGET(data);
showAboutDialog(belvuWindow);
}
/* For some widget the print function prints the visible window as it is, for
* others it prints only the cached drawables. This returns true if the latter. */
static gboolean printCachedDrawablesOnly(GtkWidget *widget)
{
const char *name = gtk_widget_get_name(widget);
return (stringsEqual(name, WRAPPED_BELVU_WINDOW_NAME, TRUE) ||
stringsEqual(name, BELVU_TREE_WINDOW_NAME, TRUE) ||
stringsEqual(name, BELVU_ORGS_WINDOW_NAME, TRUE));
}
static void onPrintMenu(GtkAction *action, gpointer data)
{
GtkWidget *window = GTK_WIDGET(data);
static GtkPageSetup *pageSetup = NULL;
static GtkPrintSettings *printSettings = NULL;
if (!pageSetup)
{
pageSetup = gtk_page_setup_new();
gtk_page_setup_set_orientation(pageSetup, GTK_PAGE_ORIENTATION_PORTRAIT);
}
if (!printSettings)
{
printSettings = gtk_print_settings_new();
gtk_print_settings_set_orientation(printSettings, GTK_PAGE_ORIENTATION_PORTRAIT);
gtk_print_settings_set_quality(printSettings, GTK_PRINT_QUALITY_HIGH);
gtk_print_settings_set_resolution(printSettings, DEFAULT_PRINT_RESOLUTION);
}
/* If we're just printing the cached drawable, get the actual drawing
* area widget that should be drawn. (Otherwise it gets clipped to the
* size of the container widget) */
const gboolean printCachedOnly = printCachedDrawablesOnly(window);
PrintScaleType scaleType = PRINT_FIT_BOTH;
GtkWidget *widgetToPrint = NULL;
if (printCachedOnly)
{
widgetGetDrawing(window, &widgetToPrint);
scaleType = PRINT_FIT_WIDTH; /* might be very tall, so allow multiple pages height-wise */
}
else
{
widgetToPrint = window;
}
blxPrintWidget(widgetToPrint, NULL, GTK_WINDOW(window), &printSettings, &pageSetup, NULL, printCachedOnly, scaleType);
}
static void onFindMenu(GtkAction *action, gpointer data)
{
GtkWidget *window = GTK_WIDGET(data);
BelvuContext *bc = windowGetContext(window);
showFindDialog(bc, window);
}
static void onWrapMenu(GtkAction *action, gpointer data)
{
GtkWidget *window = GTK_WIDGET(data);
BelvuContext *bc = windowGetContext(window);
showWrapDialog(bc, bc->belvuWindow);
}
static void onShowTreeMenu(GtkAction *action, gpointer data)
{
GtkWidget *belvuWindow = GTK_WIDGET(data);
BelvuWindowProperties *properties = belvuWindowGetProperties(belvuWindow);
if (!properties->bc->belvuTree)
{
/* If the tree exists, create a window from it. Otherwise we need to
* create it before we show it. */
if (properties->bc->mainTree && properties->bc->mainTree->head)
createBelvuTreeWindow(properties->bc, properties->bc->mainTree, TRUE);
else
createAndShowBelvuTree(properties->bc, TRUE);
}
if (properties->bc->belvuTree)
gtk_window_present(GTK_WINDOW(properties->bc->belvuTree));
}
/* Utility to extract the context from any toplevel window type (i.e. the main
* window, the tree, or a wrapped-alignment window). */
static BelvuContext* windowGetContext(GtkWidget *window)
{
BelvuContext *bc = NULL;
const char *name = gtk_widget_get_name(window);
if (stringsEqual(name, MAIN_BELVU_WINDOW_NAME, TRUE))
{
BelvuWindowProperties *properties = belvuWindowGetProperties(window);
bc = properties->bc;
}
else if (stringsEqual(name, BELVU_TREE_WINDOW_NAME, TRUE))
{
bc = belvuTreeGetContext(window);
}
else if (stringsEqual(name, BELVU_CONS_PLOT_WINDOW_NAME, TRUE))
{
bc = consPlotGetContext(window);
}
else /* generic windows */
{
GenericWindowProperties *properties = windowGetProperties(window);
bc = properties->bc;
}
return bc;
}
static void onRecalcTreeMenu(GtkAction *action, gpointer data)
{
GtkWidget *window = GTK_WIDGET(data);
BelvuContext *bc = windowGetContext(window);
if (bc->belvuTree)
{
/* Update the tree window */
belvuTreeRemakeTree(bc->belvuTree);
}
else
{
/* No tree window, but make/re-make the underlying tree structure */
separateMarkupLines(bc);
Tree *tree = treeMake(bc, FALSE, TRUE);
reInsertMarkupLines(bc);
belvuContextSetTree(bc, &tree);
onTreeOrderChanged(bc);
}
}
static void onTreeOptsMenu(GtkAction *action, gpointer data)
{
GtkWidget *window = GTK_WIDGET(data);
BelvuContext *bc = windowGetContext(window);
showTreeSettingsDialog(window, bc);
}
static void onConsPlotMenu(GtkAction *action, gpointer data)
{
GtkWidget *window = GTK_WIDGET(data);
BelvuContext *bc = windowGetContext(window);
if (bc->consPlot)
{
gtk_widget_show_all(bc->consPlot);
gtk_window_present(GTK_WINDOW(bc->consPlot));
}
else
{
createConsPlot(bc);
}
}
static void onSaveMenu(GtkAction *action, gpointer data)
{
GtkWidget *window = GTK_WIDGET(data);
BelvuContext *bc = windowGetContext(window);
saveAlignment(bc, window);
}
static void onSaveAsMenu(GtkAction *action, gpointer data)
{
GtkWidget *window = GTK_WIDGET(data);
BelvuContext *bc = windowGetContext(window);
showSaveAsDialog(bc, window);
}
static void onOutputMenu(GtkAction *action, gpointer data)
{
GtkWidget *belvuWindow = GTK_WIDGET(data);
BelvuContext *bc = windowGetContext(belvuWindow);
if (!bc->selectedAln)
{
g_critical("Please select a sequence first.\n");
}
else
{
g_message("%.1f %s/%d-%d\n",
bc->selectedAln->score,
bc->selectedAln->name,
bc->selectedAln->start,
bc->selectedAln->end);
fflush(stdout);
}
}
static void onCompareMenu(GtkAction *action, gpointer data)
{
GtkWidget *window = GTK_WIDGET(data);
BelvuContext *bc = windowGetContext(window);
listIdentity(bc);
}
static void onFetchWWWMenu(GtkAction *action, gpointer data)
{
GtkWidget *window = GTK_WIDGET(data);
BelvuContext *bc = windowGetContext(window);
bc->useWWWFetch = gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(action));
}
/* This just calls gtk_widget_destroy but accepts gpointer arguments so
* that we can call it from a foreach fucntion. */
static void destroyWidget(gpointer widget, gpointer data)
{
gtk_widget_destroy(GTK_WIDGET(widget));
}
static void onCleanUpMenu(GtkAction *action, gpointer data)
{
/* Close all windows that were spawned from the main window */
GtkWidget *belvuWindow = GTK_WIDGET(data);
BelvuWindowProperties *properties = belvuWindowGetProperties(belvuWindow);
g_slist_foreach(properties->bc->spawnedWindows, destroyWidget, NULL);
}
/* EDIT MENU ACTIONS */
static void onrmPickedMenu(GtkAction *action, gpointer data)
{
GtkWidget *belvuWindow = GTK_WIDGET(data);
BelvuWindowProperties *properties = belvuWindowGetProperties(belvuWindow);
removeSelectedSequence(properties->bc, properties->bc->belvuAlignment);
}
static void onrmGappySeqsMenu(GtkAction *action, gpointer data)
{
GtkWidget *belvuWindow = GTK_WIDGET(data);
showRemoveGappySeqsDialog(belvuWindow);
}
static void onrmPartialSeqsMenu(GtkAction *action, gpointer data)
{
GtkWidget *belvuWindow = GTK_WIDGET(data);
BelvuWindowProperties *properties = belvuWindowGetProperties(belvuWindow);
removePartialSeqs(properties->bc, properties->bc->belvuAlignment);
}
static void onrmRedundantMenu(GtkAction *action, gpointer data)
{
GtkWidget *belvuWindow = GTK_WIDGET(data);
showMakeNonRedundantDialog(belvuWindow);
}
static void onrmOutliersMenu(GtkAction *action, gpointer data)
{
GtkWidget *belvuWindow = GTK_WIDGET(data);
showRemoveOutliersDialog(belvuWindow);
}
static void onrmScoreMenu(GtkAction *action, gpointer data)
{
GtkWidget *belvuWindow = GTK_WIDGET(data);
showRemoveByScoreDialog(belvuWindow);
}
static void onrmColumnPromptMenu(GtkAction *action, gpointer data)
{
GtkWidget *belvuWindow = GTK_WIDGET(data);
showRemoveColumnsDialog(belvuWindow);
}
static void onrmColumnLeftMenu(GtkAction *action, gpointer data)
{
GtkWidget *belvuWindow = GTK_WIDGET(data);
BelvuWindowProperties *properties = belvuWindowGetProperties(belvuWindow);
if (properties->bc->selectedCol > 0)
{
rmColumn(properties->bc, 1, properties->bc->selectedCol);
rmFinaliseColumnRemoval(properties->bc);
updateOnAlignmentLenChanged(properties->bc->belvuAlignment);
properties->bc->selectedCol = 0; /* cancel selection, because this col is deleted now */
properties->bc->highlightedCol = 0; /* cancel selection, because this col is deleted now */
onColSelectionChanged(properties->bc);
}
else
{
g_critical("Please select a column first.\n\nMiddle-click with the mouse to select a column.\n");
}
}
static void onrmColumnRightMenu(GtkAction *action, gpointer data)
{
GtkWidget *belvuWindow = GTK_WIDGET(data);
BelvuWindowProperties *properties = belvuWindowGetProperties(belvuWindow);
if (properties->bc->selectedCol > 0)
{
rmColumn(properties->bc, properties->bc->selectedCol, properties->bc->maxLen);
rmFinaliseColumnRemoval(properties->bc);
updateOnAlignmentLenChanged(properties->bc->belvuAlignment);
properties->bc->selectedCol = 0; /* cancel selection, because this col is deleted now */
properties->bc->highlightedCol = 0; /* cancel selection, because this col is deleted now */
onColSelectionChanged(properties->bc);
}
else
{
g_critical("Please select a column first.\n\nMiddle-click with the mouse to select a column.\n");
}
}
/* Remove columns based on a conservation-cutoff */
static void onrmColumnCutoffMenu(GtkAction *action, gpointer data)
{
GtkWidget *belvuWindow = GTK_WIDGET(data);
BelvuWindowProperties *properties = belvuWindowGetProperties(belvuWindow);
if (!colorByConservation(properties->bc))
{
g_critical("Please select a conservation coloring scheme from the Color menu first.\n");
return;
}
showRemoveColumnsCutoffDialog(belvuWindow);
}
/* Remove columns with more than a specified percentage of gaps */
static void onrmGappyColumnsMenu(GtkAction *action, gpointer data)
{
GtkWidget *belvuWindow = GTK_WIDGET(data);
showRemoveGappyColumnsDialog(belvuWindow);
}
/* Toggle the 'remove-many-sequences' option on or off */
static void onRemoveSeqsMenu(GtkAction *action, gpointer data)
{
GtkWidget *belvuWindow = GTK_WIDGET(data);
const gboolean optionOn = gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(action));
if (optionOn)
startRemovingSequences(belvuWindow);
else
endRemovingSequences(belvuWindow);
}
/* Toggle the 'auto-remove empty columns' option */
static void onAutoRmEmptyColumnsMenu(GtkAction *action, gpointer data)
{
GtkWidget *belvuWindow = GTK_WIDGET(data);
BelvuWindowProperties *properties = belvuWindowGetProperties(belvuWindow);
const gboolean newVal = gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(action));
if (properties->bc->rmEmptyColumnsOn != newVal)
{
properties->bc->rmEmptyColumnsOn = newVal;
}
}
static void onreadLabelsMenu(GtkAction *action, gpointer data)
{
GtkWidget *belvuWindow = GTK_WIDGET(data);
BelvuWindowProperties *properties = belvuWindowGetProperties(belvuWindow);
if (!properties->bc->selectedAln)
{
g_critical("Please select a sequence first.\n");
return;
}
char *title = g_strdup_printf("Read labels of %s from file", properties->bc->selectedAln->name);
const char *filename = getLoadFileName(belvuWindow, properties->bc->dirName, title);
g_free(title);
FILE *fil = fopen(filename, "r");
if (fil)
{
readLabels(properties->bc, fil);
belvuAlignmentRedrawAll(properties->bc->belvuAlignment);
}
}
static void onselectGapsMenu(GtkAction *action, gpointer data)
{
GtkWidget *belvuWindow = GTK_WIDGET(data);
showSelectGapCharDialog(belvuWindow);
}
static void onhideMenu(GtkAction *action, gpointer data)
{
GtkWidget *belvuWindow = GTK_WIDGET(data);
BelvuWindowProperties *properties = belvuWindowGetProperties(belvuWindow);
if (!properties->bc->selectedAln)
{
g_critical("Please select a sequence to hide.\n");
}
else
{
properties->bc->selectedAln->hide = TRUE;
belvuAlignmentRedrawAll(properties->bc->belvuAlignment);
}
}
static void onunhideMenu(GtkAction *action, gpointer data)
{
GtkWidget *belvuWindow = GTK_WIDGET(data);
BelvuWindowProperties *properties = belvuWindowGetProperties(belvuWindow);
/* Reset the 'hide' flag to false in all sequences */
int i = 0;
for (i = 0; i < (int)properties->bc->alignArr->len; ++i)
{
g_array_index(properties->bc->alignArr, ALN*, i)->hide = FALSE;
}
belvuAlignmentRedrawAll(properties->bc->belvuAlignment);
}
/***********************************************************
* Save on exit dialog *
***********************************************************/
/* Pops up a dialog asking the user whether they want to save the alignment
* or not. Deals with the save, if applicable, and returns true if the user
* still wishes to quit (or false if the user cancelled). */
static gboolean saveAlignmentPrompt(GtkWidget *widget, BelvuContext *bc)
{
char *title = g_strdup_printf("%sSave alignment?", belvuGetTitlePrefix(bc));
GtkWidget *dialog = gtk_dialog_new_with_buttons(title,
GTK_WINDOW(widget),
(GtkDialogFlags)(GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT),
GTK_STOCK_YES, GTK_RESPONSE_YES, /* yes, save the alignment and exit */
GTK_STOCK_NO, GTK_RESPONSE_NO, /* no, don't save (but still exit) */
GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT, /* don't save and don't exit */
NULL);
g_free(title);
gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_YES);
/* Put message and icon into an hbox */
GtkWidget *hbox = gtk_hbox_new(FALSE, 0);
gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), hbox, TRUE, TRUE, 0);
GtkWidget *image = gtk_image_new_from_stock(GTK_STOCK_DIALOG_QUESTION, GTK_ICON_SIZE_DIALOG);
gtk_box_pack_start(GTK_BOX(hbox), image, TRUE, TRUE, 0);
GtkWidget *label = gtk_label_new("Alignment was modified - save ?");
gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, TRUE, 0);
gtk_widget_show_all(hbox);
gint response = gtk_dialog_run(GTK_DIALOG(dialog));
gboolean quit = FALSE;
if (response == GTK_RESPONSE_YES)
{
quit = saveAlignment(bc, widget);
}
else if (response == GTK_RESPONSE_NO)
{
quit = TRUE;
}
gtk_widget_destroy(dialog);
return quit;
}
/***********************************************************
* File menu actions *
***********************************************************/
static const char* saveFasta(BelvuContext *bc, GtkWidget *parent)
{
char *title = g_strdup_printf("%s", bc->saveFormat == BELVU_FILE_UNALIGNED_FASTA ? "Save as unaligned Fasta file:" : "Save as aligned Fasta file:");
const char *filename = getSaveFileName(parent, bc->fileName, bc->dirName, NULL, title);
g_free(title);
FILE *fil = fopen(filename, "w");
if (fil)
{
writeFasta(bc, fil);
}
return filename;
}
static const char* saveMsf(BelvuContext *bc, GtkWidget *parent)
{
const char *filename = getSaveFileName(parent, bc->fileName, bc->dirName, NULL, "Save as MSF (/) file:");
FILE *fil = fopen(filename, "w");
if (fil)
{
writeMSF(bc, fil);
}
return filename;
}
static const char* saveMul(BelvuContext *bc, GtkWidget *parent)
{
const char *filename = getSaveFileName(parent, bc->fileName, bc->dirName, NULL, "Save as Stockholm file:");
FILE *fil = fopen(filename, "w");
if (fil)
{
writeMul(bc, fil);
}
return filename;
}
/***********************************************************
* Colour menu actions *
***********************************************************/
/* This function is called when the color scheme has been changed. It performs all
* required updates. */
static void onColorSchemeChanged(BelvuWindowProperties *properties)
{
/* Make sure the correct scheme type is set in the menus */
switch (properties->bc->schemeType)
{
case BELVU_SCHEME_TYPE_RESIDUE:
setToggleMenuStatus(properties->actionGroup, "ColorByResidue", TRUE);
break;
case BELVU_SCHEME_TYPE_CONS:
setToggleMenuStatus(properties->actionGroup, "ColorByCons", TRUE);
break;
default:
g_warning("Program error: unrecognised color scheme type '%d'.\n", properties->bc->schemeType);
break;
};
/* Some menu actions are enabled/disabled depending on which scheme type is selected */
greyOutInvalidActions(properties->bc);
/* Update the display */
updateSchemeColors(properties->bc);
belvuAlignmentRedrawAll(properties->bc->belvuAlignment);
}
static void onToggleSchemeType(GtkRadioAction *action, GtkRadioAction *current, gpointer data)
{
GtkWidget *belvuWindow = GTK_WIDGET(data);
BelvuWindowProperties *properties = belvuWindowGetProperties(belvuWindow);
BelvuSchemeType newScheme = (BelvuSchemeType)gtk_radio_action_get_current_value(current);
if (newScheme != properties->bc->schemeType)
{
properties->bc->schemeType = newScheme;
/* Toggle the actual scheme to the current default for this scheme type */
if (newScheme == BELVU_SCHEME_TYPE_RESIDUE)
setRadioMenuStatus(properties->actionGroup, "colorSchemeStandard", properties->bc->residueScheme);
else
setRadioMenuStatus(properties->actionGroup, "colorSchemeStandard", properties->bc->consScheme);
onColorSchemeChanged(properties);
}
}
static void onToggleColorScheme(GtkRadioAction *action, GtkRadioAction *current, gpointer data)
{
GtkWidget *belvuWindow = GTK_WIDGET(data);
BelvuWindowProperties *properties = belvuWindowGetProperties(belvuWindow);
BelvuContext *bc = properties->bc;
/* Get the new color scheme */
BelvuColorScheme newScheme = (BelvuColorScheme)gtk_radio_action_get_current_value(current);
/* Determine what scheme type this puts us in */
if (newScheme > NUM_RESIDUE_SCHEMES)
{
/* The new scheme is a color-by-conservation scheme type */
if (bc->schemeType != BELVU_SCHEME_TYPE_CONS || bc->consScheme != newScheme)
{
bc->schemeType = BELVU_SCHEME_TYPE_CONS;
bc->consScheme = newScheme;
onColorSchemeChanged(properties);
}
}
else
{
/* The new scheme is a color-by-residue scheme type */
if (bc->schemeType != BELVU_SCHEME_TYPE_RESIDUE || bc->residueScheme != newScheme)
{
bc->schemeType = BELVU_SCHEME_TYPE_RESIDUE;
bc->residueScheme = newScheme;
setResidueSchemeColors(bc);
onColorSchemeChanged(properties);
}
}
}
static void onToggleSortOrder(GtkRadioAction *action, GtkRadioAction *current, gpointer data)
{
GtkWidget *belvuWindow = GTK_WIDGET(data);
BelvuWindowProperties *properties = belvuWindowGetProperties(belvuWindow);
properties->bc->sortType = (BelvuSortType)gtk_radio_action_get_current_value(current);
doSort(properties->bc, properties->bc->sortType, TRUE);
/* To do: This is a hack to overcome a bug where the sort order gets messed
* up when switching to tree-sort from a different sort order after having
* changed the tree order by swapping nodes. Calling doSort again seems to
* sort it out, although obviously this is not ideal. */
if (properties->bc->sortType == BELVU_SORT_TREE)
doSort(properties->bc, properties->bc->sortType, TRUE);
centerHighlighted(properties->bc, properties->bc->belvuAlignment);
belvuAlignmentRedrawAll(properties->bc->belvuAlignment);
}
/* Toggle between color-by-conservation and color-by-residue modes */
static void ontogglePaletteMenu(GtkAction *action, gpointer data)
{
GtkWidget *window = GTK_WIDGET(data);
if (stringsEqual(gtk_widget_get_name(window), MAIN_BELVU_WINDOW_NAME, TRUE))
{
BelvuWindowProperties *properties = belvuWindowGetProperties(window);
if (properties->bc->schemeType == BELVU_SCHEME_TYPE_CONS)
setToggleMenuStatus(properties->actionGroup, "ColorByResidue", TRUE);
else
setToggleMenuStatus(properties->actionGroup, "ColorByCons", TRUE);
}
}
/* This controls whether the color-by-residue-id option is toggle on or off */
static void ontoggleColorByResIdMenu(GtkAction *action, gpointer data)
{
GtkWidget *belvuWindow = GTK_WIDGET(data);
BelvuWindowProperties *properties = belvuWindowGetProperties(belvuWindow);
/* Toggle the flag */
properties->bc->colorByResIdOn = !properties->bc->colorByResIdOn;
/* Update the color scheme and redraw */
updateSchemeColors(properties->bc);
belvuAlignmentRedrawAll(properties->bc->belvuAlignment);
}
/* This pops up a dialog to set the color-by-res-id threshold, and turns the option on */
static void oncolorByResIdMenu(GtkAction *action, gpointer data)
{
GtkWidget *belvuWindow = GTK_WIDGET(data);
showColorByResIdDialog(belvuWindow);
}
static void onsaveColorSchemeMenu(GtkAction *action, gpointer data)
{
GtkWidget *belvuWindow = GTK_WIDGET(data);
BelvuWindowProperties *properties = belvuWindowGetProperties(belvuWindow);
const char *filename = getSaveFileName(belvuWindow, properties->bc->fileName, properties->bc->dirName, NULL, "Save colour scheme");
FILE *fil = fopen(filename, "w");
if (filename)
{
if (properties->bc->dirName) g_free(properties->bc->dirName);
if (properties->bc->fileName) g_free(properties->bc->fileName);
properties->bc->dirName = g_path_get_dirname(filename);
properties->bc->fileName = g_path_get_basename(filename);
}
saveResidueColorScheme(properties->bc, fil);
}
static void onloadColorSchemeMenu(GtkAction *action, gpointer data)
{
GtkWidget *belvuWindow = GTK_WIDGET(data);
BelvuWindowProperties *properties = belvuWindowGetProperties(belvuWindow);
const char *filename = getLoadFileName(belvuWindow, properties->bc->dirName, "Read color scheme");
FILE *fil = fopen(filename, "r");
if (filename)
{
if (properties->bc->dirName) g_free(properties->bc->dirName);
if (properties->bc->fileName) g_free(properties->bc->fileName);
properties->bc->dirName = g_path_get_dirname(filename);
properties->bc->fileName = g_path_get_basename(filename);
}
readResidueColorScheme(properties->bc, fil, getColorArray(), TRUE);
setRadioMenuStatus(properties->actionGroup, "colorSchemeStandard", BELVU_SCHEME_CUSTOM);
setToggleMenuStatus(properties->actionGroup, "ColorByResidue", TRUE);
onColorSchemeChanged(properties);
}
static void onignoreGapsMenu(GtkAction *action, gpointer data)
{
GtkWidget *belvuWindow = GTK_WIDGET(data);
BelvuWindowProperties *properties = belvuWindowGetProperties(belvuWindow);
/* Toggle the 'ignore gaps' option */
properties->bc->ignoreGapsOn = !properties->bc->ignoreGapsOn;
onColorSchemeChanged(properties);
}
static void onprintColorsMenu(GtkAction *action, gpointer data)
{
GtkWidget *belvuWindow = GTK_WIDGET(data);
BelvuWindowProperties *properties = belvuWindowGetProperties(belvuWindow);
/* Toggle the 'ignore gaps' option */
properties->bc->printColorsOn = !properties->bc->printColorsOn;
onColorSchemeChanged(properties);
}
static void onexcludeHighlightedMenu(GtkAction *action, gpointer data)
{
GtkWidget *belvuWindow = GTK_WIDGET(data);
BelvuWindowProperties *properties = belvuWindowGetProperties(belvuWindow);
const gboolean exclude = gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(action));
setExcludeFromConsCalc(properties->bc, exclude);
belvuAlignmentRedrawAll(properties->bc->belvuAlignment);
}
static void ondisplayColorsMenu(GtkAction *action, gpointer data)
{
GtkWidget *belvuWindow = GTK_WIDGET(data);
BelvuWindowProperties *properties = belvuWindowGetProperties(belvuWindow);
const gboolean newVal = gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(action));
if (properties->bc->displayColors != newVal)
{
properties->bc->displayColors = newVal;
belvuAlignmentRedrawAll(properties->bc->belvuAlignment);
}
}
static void onlowercaseMenu(GtkAction *action, gpointer data)
{
GtkWidget *belvuWindow = GTK_WIDGET(data);
BelvuWindowProperties *properties = belvuWindowGetProperties(belvuWindow);
properties->bc->lowercaseOn = !properties->bc->lowercaseOn;
belvuAlignmentRedrawAll(properties->bc->belvuAlignment);
}
static void oneditColorSchemeMenu(GtkAction *action, gpointer data)
{
GtkWidget *belvuWindow = GTK_WIDGET(data);
BelvuContext *bc = windowGetContext(belvuWindow);
if (colorByConservation(bc))
showEditConsColorsDialog(belvuWindow, TRUE);
else
showEditResidueColorsDialog(belvuWindow, TRUE);
}
static void onSaveTreeMenu(GtkAction *action, gpointer data)
{
GtkWidget *window = GTK_WIDGET(data);
BelvuContext *bc = windowGetContext(window);
const char *filename = getSaveFileName(window, bc->fileName, bc->dirName, NULL, "Save tree in New Hampshire format");
FILE *file = fopen(filename, "w");
if (file)
{
saveTreeNH(bc->mainTree, bc->mainTree->head, file);
/* Add a terminating line and close the file. */
fprintf(file, ";\n");
fclose(file);
g_message_info("Tree saved to %s\n", filename);
}
}
static void onFindOrthogsMenu(GtkAction *action, gpointer data)
{
GtkWidget *window = GTK_WIDGET(data);
BelvuContext *bc = windowGetContext(window);
GtkWidget *treeWindow = NULL;
/* If the current window is a tree, use that; otherwise use the main belvu tree */
if (stringsEqual(gtk_widget_get_name(window), BELVU_TREE_WINDOW_NAME, TRUE))
treeWindow = window;
else
treeWindow = bc->belvuTree;
bc->highlightOrthologs = gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(action));
/* If turning the option on, print the orthologs to stdout */
if (bc->highlightOrthologs)
treePrintOrthologs(bc, treeWindow);
/* Refresh the tree to show or hide the orthologs */
belvuTreeRedrawAll(bc->belvuTree, NULL);
}
static void onShowOrgsMenu(GtkAction *action, gpointer data)
{
GtkWidget *window = GTK_WIDGET(data);
BelvuContext *bc = windowGetContext(window);
if (bc->organismArr->len < 1)
{
g_critical("No organism details found.\n");
}
else if (bc->orgsWindow)
{
gtk_widget_show_all(bc->orgsWindow);
gtk_window_present(GTK_WINDOW(bc->orgsWindow));
}
else
{
createOrganismWindow(bc);
}
}
static void onZoomInMenu(GtkAction *action, gpointer data)
{
GtkWidget *window = GTK_WIDGET(data);
BelvuContext *bc = windowGetContext(window);
incrementFontSize(bc);
}
static void onZoomOutMenu(GtkAction *action, gpointer data)
{
GtkWidget *window = GTK_WIDGET(data);
BelvuContext *bc = windowGetContext(window);
decrementFontSize(bc);
}
static void onSetFontMenu(GtkAction *action, gpointer data)
{
GtkWidget *window = GTK_WIDGET(data);
BelvuContext *bc = windowGetContext(window);
showFontDialog(bc, window);
}
/***********************************************************
* Properties *
***********************************************************/
static BelvuWindowProperties* belvuWindowGetProperties(GtkWidget *widget)
{
return widget ? (BelvuWindowProperties*)(g_object_get_data(G_OBJECT(widget), "BelvuWindowProperties")) : NULL;
}
/* Does the job of destroying the belvu window */
static void destroyBelvuWindow(GtkWidget *belvuWindow)
{
BelvuWindowProperties *properties = belvuWindowGetProperties(belvuWindow);
if (properties)
{
destroyBelvuContext(&properties->bc);
/* Free the properties struct itself */
delete properties;
properties = NULL;
g_object_set_data(G_OBJECT(belvuWindow), "BelvuWindowProperties", NULL);
}
gtk_main_quit();
}
/* Signal handler for when the main belvu window is closed (note that if the
* alignment is not saved the user may cancel) */
static void onDestroyBelvuWindow(GtkWidget *belvuWindow)
{
gboolean destroy = TRUE;
BelvuWindowProperties *properties = belvuWindowGetProperties(belvuWindow);
if (!properties->bc->saved)
{
/* The alignment has not been saved - ask the user if they want to save/cancel */
BelvuWindowProperties *properties = belvuWindowGetProperties(belvuWindow);
destroy = saveAlignmentPrompt(belvuWindow, properties->bc);
}
if (destroy)
{
destroyBelvuWindow(belvuWindow);
}
}
/* Create the properties struct and initialise all values. */
static void belvuWindowCreateProperties(GtkWidget *belvuWindow,
BelvuContext *bc,
GtkWidget *statusBar,
GtkWidget *feedbackBox,
GtkActionGroup *actionGroup)
{
if (belvuWindow)
{
BelvuWindowProperties *properties = new BelvuWindowProperties;
properties->widget = belvuWindow;
properties->bc = bc;
properties->statusBar = statusBar;
properties->feedbackBox = feedbackBox;
properties->actionGroup = actionGroup;
g_object_set_data(G_OBJECT(belvuWindow), "BelvuWindowProperties", properties);
g_signal_connect(G_OBJECT(belvuWindow), "destroy", G_CALLBACK (onDestroyBelvuWindow), NULL);
}
}
GtkActionGroup* belvuWindowGetActionGroup(GtkWidget *belvuWindow)
{
BelvuWindowProperties *properties = belvuWindowGetProperties(belvuWindow);
return (properties ? properties->actionGroup : NULL);
}
/* Properties for generic windows */
static GenericWindowProperties* windowGetProperties(GtkWidget *widget)
{
return widget ? (GenericWindowProperties*)(g_object_get_data(G_OBJECT(widget), "GenericWindowProperties")) : NULL;
}
static void onDestroyGenericWindow(GtkWidget *window)
{
GenericWindowProperties *properties = windowGetProperties(window);
/* We must remove the window from the list of spawned windows */
properties->bc->spawnedWindows = g_slist_remove(properties->bc->spawnedWindows, window);
if (properties)
{
/* Free the properties struct */
delete properties;
properties = NULL;
g_object_set_data(G_OBJECT(window), "GenericWindowProperties", NULL);
}
}
/* Create the properties struct and initialise all values for a generic window. */
static void genericWindowCreateProperties(GtkWidget *wrapWindow,
BelvuContext *bc,
GtkActionGroup *actionGroup)
{
if (wrapWindow)
{
GenericWindowProperties *properties = new GenericWindowProperties;
properties->widget = wrapWindow;
properties->bc = bc;
properties->actionGroup = actionGroup;
g_object_set_data(G_OBJECT(wrapWindow), "GenericWindowProperties", properties);
g_signal_connect(G_OBJECT(wrapWindow), "destroy", G_CALLBACK (onDestroyGenericWindow), NULL);
}
}
/***********************************************************
* Font size *
***********************************************************/
static void showFontDialog(BelvuContext *bc, GtkWidget *window)
{
GtkWidget *entry = NULL;
const int oldSize = pango_font_description_get_size(window->style->font_desc) / PANGO_SCALE;
char *defaultText = g_strdup_printf("%d", oldSize);
char *title = g_strdup_printf("%sFont", belvuGetTitlePrefix(bc));
GtkWidget *dialog = createPromptDialog(window, defaultText, title, "Select font size:", "", &entry);
g_free(title);
gtk_widget_show_all(dialog);
if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT)
{
const int newSize = convertStringToInt(gtk_entry_get_text(GTK_ENTRY(entry)));
if (newSize >= MIN_FONT_SIZE && newSize <= MAX_FONT_SIZE)
{
widgetSetFontSize(bc->belvuWindow, GINT_TO_POINTER(newSize));
widgetSetFontSize(bc->belvuTree, GINT_TO_POINTER(newSize));
onBelvuAlignmentFontSizeChanged(bc->belvuAlignment);
onBelvuTreeFontSizeChanged(bc->belvuTree);
}
else
{
g_critical("Invalid font size %d; font size must be between %d and %d.\n", newSize, MIN_FONT_SIZE, MAX_FONT_SIZE);
}
}
gtk_widget_destroy(dialog);
}
void incrementFontSize(BelvuContext *bc)
{
if (bc->belvuAlignment)
{
int size = pango_font_description_get_size(bc->belvuAlignment->style->font_desc) / PANGO_SCALE;
widgetSetFontSizeAndCheck(bc->belvuAlignment, size + 1);
onBelvuAlignmentFontSizeChanged(bc->belvuAlignment);
}
}
void decrementFontSize(BelvuContext *bc)
{
if (bc->belvuAlignment)
{
int size = pango_font_description_get_size(bc->belvuAlignment->style->font_desc) / PANGO_SCALE;
widgetSetFontSizeAndCheck(bc->belvuAlignment, size - 1);
onBelvuAlignmentFontSizeChanged(bc->belvuAlignment);
}
}
/***********************************************************
* Remove sequences *
***********************************************************/
/* This should be called when the 'removing sequences' option has changed */
static void updateSequenceRemovalMode(GtkWidget *belvuWindow)
{
BelvuWindowProperties *properties = belvuWindowGetProperties(belvuWindow);
if (properties->bc->removingSeqs)
{
gdk_window_set_cursor(belvuWindow->window, properties->bc->removeSeqsCursor);
g_message_info("Double-click on sequences to remove. Esc or right-click to cancel.\n");
}
else
{
gdk_window_set_cursor(belvuWindow->window, properties->bc->defaultCursor);
g_message_info("Finished removing sequences.\n");
}
/* Force cursor to change immediately */
while (gtk_events_pending())
gtk_main_iteration();
}
static void startRemovingSequences(GtkWidget *belvuWindow)
{
BelvuWindowProperties *properties = belvuWindowGetProperties(belvuWindow);
if (!properties->bc->removingSeqs)
{
properties->bc->removingSeqs = TRUE;
updateSequenceRemovalMode(belvuWindow);
}
}
static void endRemovingSequences(GtkWidget *belvuWindow)
{
BelvuWindowProperties *properties = belvuWindowGetProperties(belvuWindow);
properties->bc->removingSeqs = FALSE;
updateSequenceRemovalMode(belvuWindow);
}
/***********************************************************
* About dialog *
***********************************************************/
/* A GtkAboutDialogActivateLinkFunc() called when user clicks on website link in "About" window. */
static void aboutDialogOpenLinkCB(GtkAboutDialog *about, const gchar *link, gpointer data)
{
GError *error = NULL ;
if (!seqtoolsLaunchWebBrowser(link, &error))
g_critical("Cannot show link in web browser: \"%s\"", link) ;
}
/* Shows the 'About' dialog */
static void showAboutDialog(GtkWidget *parent)
{
#if CHECK_GTK_VERSION(2, 6)
const gchar *authors[] = {AUTHOR_LIST, NULL} ;
gtk_about_dialog_set_url_hook(aboutDialogOpenLinkCB, NULL, NULL) ;
gtk_show_about_dialog(GTK_WINDOW(parent),
"authors", authors,
"comments", belvuGetCommentsString(),
"copyright", belvuGetCopyrightString(),
"license", belvuGetLicenseString(),
"name", belvuGetAppName(),
"version", belvuGetVersionString(),
"website", belvuGetWebSiteString(),
NULL) ;
#endif
return ;
}
/***********************************************************
* Help dialog *
***********************************************************/
static void showHelpDialog()
{
GError *error = NULL;
/* The docs should live in /share/doc/seqtools/, in the same parent
* directory that our executable's 'bin' directory is in. Open the 'quick
* start' page. */
char rel_path[100] = "../share/doc/seqtools/belvu_quick_start.html";
/* Find the executable's path */
char *exe = g_find_program_in_path(g_get_prgname());
gboolean ok = (exe != NULL);
if (ok)
{
/* Get the executable's directory */
char *dir = g_path_get_dirname(exe);
ok = dir != NULL;
if (ok)
{
/* Get the path to the html page */
char *path = g_strdup_printf("%s/%s", dir, rel_path);
ok = path != NULL;
if (ok)
{
g_message_info("Opening help page '%s'\n", path);
seqtoolsLaunchWebBrowser(path, &error);
g_free(path);
}
g_free(dir);
}
g_free(exe);
}
if (!ok)
{
if (error)
reportAndClearIfError(&error, G_LOG_LEVEL_CRITICAL);
else
g_critical("Could not find help documentation: %s\n", rel_path);
}
}
/***********************************************************
* Save As dialog *
***********************************************************/
/* Utility to call the correct save function for the current save format.
* Returns true if successful (false if not saved, e.g. if the user cancelled
* the save dialog). */
static gboolean saveAlignment(BelvuContext *bc, GtkWidget *window)
{
const char *filename = NULL;
if (bc->saveFormat == BELVU_FILE_MSF)
filename = saveMsf(bc, window);
else if (bc->saveFormat == BELVU_FILE_ALIGNED_FASTA)
filename = saveFasta(bc, window);
else if (bc->saveFormat == BELVU_FILE_UNALIGNED_FASTA)
filename = saveFasta(bc, window);
else
filename = saveMul(bc, window);
/* Remember the last filename */
if (filename)
{
if (bc->dirName) g_free(bc->dirName);
if (bc->fileName) g_free(bc->fileName);
bc->dirName = g_path_get_dirname(filename);
bc->fileName = g_path_get_basename(filename);
}
/* If the filename is null, the user must have cancelled. */
return (filename != NULL);
}
/* This creates a drop-down box for selecting a file format */
static GtkComboBox* createFileFormatCombo(const int initFormatId)
{
GtkComboBox *combo = createComboBox();
GtkTreeIter *iter = NULL;
int i = 0;
for ( ; i < BELVU_NUM_FILE_FORMATS; ++i)
addComboItem(combo, iter, i, getFileFormatString(i), initFormatId);
return combo;
}
/* Callback called when the 'save coords' toggle button is toggled. It updates
* the given widget (passed as data) to be enabled if the toggle button is active
* or disabled otherwise. */
static void onSaveCoordsToggled(GtkWidget *button, gpointer data)
{
GtkWidget *otherWidget = GTK_WIDGET(data);
if (otherWidget)
{
const gboolean isActive = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button));
gtk_widget_set_sensitive(otherWidget, isActive);
}
}
static void showSaveAsDialog(BelvuContext *bc, GtkWidget *window)
{
char *title = g_strdup_printf("%sSave As", belvuGetTitlePrefix(bc));
GtkWidget *dialog = gtk_dialog_new_with_buttons(title,
GTK_WINDOW(window),
(GtkDialogFlags)(GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT),
GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
NULL);
g_free(title);
gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT);
GtkBox *contentArea = GTK_BOX(GTK_DIALOG(dialog)->vbox);
/* Create a drop-down for selectin the file format */
GtkWidget *hbox = gtk_hbox_new(FALSE, DIALOG_XPAD);
gtk_box_pack_start(contentArea, hbox, FALSE, FALSE, DIALOG_XPAD);
GtkWidget *label = gtk_label_new("Format: ");
gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, DIALOG_XPAD);
GtkComboBox *combo = createFileFormatCombo(bc->saveFormat);
gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(combo), FALSE, FALSE, DIALOG_YPAD);
/* Create a tick box for enabling the 'save coords' option */
GtkToggleButton *checkButton = GTK_TOGGLE_BUTTON(gtk_check_button_new_with_mnemonic("Save _coordinates"));
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkButton), bc->saveCoordsOn);
gtk_box_pack_start(contentArea, GTK_WIDGET(checkButton), FALSE, FALSE, DIALOG_YPAD);
/* Create selection buttons to allow user to specify separator char */
GtkBox *hbox2 = GTK_BOX(gtk_hbox_new(FALSE, DIALOG_XPAD));
gtk_box_pack_start(contentArea, GTK_WIDGET(hbox2), FALSE, FALSE, DIALOG_YPAD);
GtkWidget *separatorLabel = gtk_label_new("Separator character between name and coords:\n(Use = for GCG)");
gtk_misc_set_alignment(GTK_MISC(separatorLabel), 0.0, 0.0);
gtk_box_pack_start(hbox2, separatorLabel, FALSE, FALSE, DIALOG_XPAD);
GtkBox *vbox = GTK_BOX(gtk_vbox_new(FALSE, DIALOG_YPAD));
gtk_box_pack_start(hbox2, GTK_WIDGET(vbox), FALSE, FALSE, DIALOG_XPAD);
const gboolean button1Active = (bc->saveSeparator == '/');
GtkWidget *button1 = gtk_radio_button_new_with_label_from_widget(NULL, "slash (/) ");
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button1), button1Active);
gtk_box_pack_start(vbox, button1, FALSE, FALSE, 0);
GtkWidget *button2 = gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(button1), "equals (=) ");
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button2), !button1Active);
gtk_box_pack_start(vbox, button2, FALSE, FALSE, 0);
/* The save separator is only applicable if saving coords */
gtk_widget_set_sensitive(GTK_WIDGET(hbox2), bc->saveCoordsOn);
g_signal_connect(G_OBJECT(checkButton), "toggled", G_CALLBACK(onSaveCoordsToggled), hbox2);
gtk_widget_show_all(dialog);
if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT)
{
bc->saveFormat = (BelvuFileFormat)gtk_combo_box_get_active(combo);
bc->saveCoordsOn = gtk_toggle_button_get_active(checkButton);
if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button1)))
bc->saveSeparator = '/';
else
bc->saveSeparator = '=';
saveAlignment(bc, window);
}
gtk_widget_destroy(dialog);
}
/***********************************************************
* Find dialog *
***********************************************************/
static void findSeqs(BelvuContext *bc, const char *searchStr, const gboolean findAgain, const gboolean searchBackwards)
{
/* Loop through each alignment and see if the name matches. If so,
* remember the index of the matching alignment. We start searching
* from the beginning of the alignment array, unless this is a 'find again'
* search, when we search from the next alignment after the previous result */
static int startIdx = 0;
if (findAgain && searchBackwards)
--startIdx;
else if (findAgain)
++startIdx;
else
startIdx = 0;
const int increment = (searchBackwards ? -1 : 1);
int i = startIdx;
gboolean found = FALSE;
for ( ; i >= 0 && i < (int)bc->alignArr->len; i += increment)
{
ALN *alnp = g_array_index(bc->alignArr, ALN*, i);
if (wildcardSearch(alnp->name, searchStr))
{
bc->selectedAln = alnp;
onRowSelectionChanged(bc);
found = TRUE;
startIdx = i;
break;
}
}
/* If it's a find-again search and we failed to find a result, try
* again starting from the beginning */
if (findAgain && !found &&
((searchBackwards && startIdx != (int)bc->alignArr->len - 1) || (!searchBackwards && startIdx != 0)) )
{
startIdx = (searchBackwards ? bc->alignArr->len - 1 : 0);
i = startIdx;
for ( ; i >= 0 && i < (int)bc->alignArr->len; i += increment)
{
ALN *alnp = g_array_index(bc->alignArr, ALN*, i);
if (wildcardSearch(alnp->name, searchStr))
{
bc->selectedAln = alnp;
onRowSelectionChanged(bc);
found = TRUE;
startIdx = i;
break;
}
}
}
if (!found)
g_critical("Alignment name '%s' not found.\n", searchStr);
}
static gboolean onFindSeqs(GtkWidget *button, const gint responseId, gpointer data)
{
if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button)))
{
const char *searchStr = getStringFromTextEntry(GTK_ENTRY(data));
GtkWidget *dialog = gtk_widget_get_toplevel(button);
GtkWidget *window = GTK_WIDGET(gtk_window_get_transient_for(GTK_WINDOW(dialog)));
BelvuContext *bc = windowGetContext(window);
/* If the the user hit forward or back, do a find-again search in the appropriate
* direction; otherwise do a normal search */
if (responseId == BLX_RESPONSE_FORWARD)
findSeqs(bc, searchStr, TRUE, FALSE);
else if (responseId == BLX_RESPONSE_BACK)
findSeqs(bc, searchStr, TRUE, TRUE);
else
findSeqs(bc, searchStr, FALSE, FALSE);
}
return TRUE;
}
/* To do: implement functionality to search for sequences by a pattern of residues */
/*
static gboolean onFindResidues(GtkWidget *button, const gint responseId, gpointer data)
{
if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button)))
{
const char *searchStr = getStringFromTextEntry(GTK_ENTRY(data));
GtkWidget *dialog = gtk_widget_get_toplevel(button);
GtkWidget *window = GTK_WIDGET(gtk_window_get_transient_for(GTK_WINDOW(dialog)));
BelvuContext *bc = windowGetContext(window);
if (responseId == BLX_RESPONSE_FORWARD)
findResidues(bc, searchStr, TRUE, FALSE);
else if (responseId == BLX_RESPONSE_BACK)
findResidues(bc, searchStr, TRUE, TRUE);
else
findResidues(bc, searchStr, FALSE, FALSE);
}
return TRUE;
}
*/
static void showFindDialog(BelvuContext *bc, GtkWidget *window)
{
const BelvuDialogId dialogId = BELDIALOG_FIND;
GtkWidget *dialog = getPersistentDialog(bc->dialogList, dialogId);
if (!dialog)
{
char *title = g_strdup_printf("%sFind sequences", belvuGetTitlePrefix(bc));
dialog = gtk_dialog_new_with_buttons(title,
GTK_WINDOW(window),
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_STOCK_GO_BACK,
BLX_RESPONSE_BACK,
GTK_STOCK_GO_FORWARD,
BLX_RESPONSE_FORWARD,
GTK_STOCK_CLOSE,
GTK_RESPONSE_REJECT,
GTK_STOCK_OK,
GTK_RESPONSE_ACCEPT,
NULL);
g_free(title);
/* These calls are required to make the dialog persistent... */
addPersistentDialog(bc->dialogList, dialogId, dialog);
g_signal_connect(dialog, "delete-event", G_CALLBACK(gtk_widget_hide_on_delete), NULL);
GtkBox *contentArea = GTK_BOX(GTK_DIALOG(dialog)->vbox);
const int numRows = 2;
const int numCols = 2;
GtkTable *table = GTK_TABLE(gtk_table_new(numRows, numCols, FALSE));
gtk_box_pack_start(contentArea, GTK_WIDGET(table), TRUE, TRUE, 0);
/*GtkRadioButton *button1 =*/ createRadioButton(table, 0, 0, NULL, "_Name search (wildcards * and ?)", TRUE, TRUE, FALSE, onFindSeqs, window, NULL);
/*createRadioButton(table, 0, 1, button1, "_Residue sequence search", FALSE, TRUE, FALSE, onFindResidues, window, NULL);*/
gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(window));
g_signal_connect(dialog, "response", G_CALLBACK(onResponseDialog), GINT_TO_POINTER(TRUE));
}
gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT);
gtk_widget_show_all(dialog);
gtk_window_present(GTK_WINDOW(dialog));
}
/***********************************************************
* Remove sequences dialogs *
***********************************************************/
static GtkWidget* createPromptDialog(GtkWidget *window,
const char *defaultResult,
const char *title,
const char *text1,
const char *text2,
GtkWidget **entry)
{
GtkWidget *dialog = gtk_dialog_new_with_buttons(title,
GTK_WINDOW(window),
(GtkDialogFlags)(GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT),
GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
NULL);
gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT);
if (window)
pango_font_description_set_size(dialog->style->font_desc, pango_font_description_get_size(window->style->font_desc));
GtkWidget *hbox = gtk_hbox_new(FALSE, 0);
gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), hbox, FALSE, FALSE, 12);
GtkWidget *label1 = gtk_label_new(text1);
gtk_misc_set_alignment(GTK_MISC(label1), 1, 0.5);
gtk_box_pack_start(GTK_BOX(hbox), label1, FALSE, FALSE, 0);
*entry = gtk_entry_new();
gtk_box_pack_start(GTK_BOX(hbox), *entry, FALSE, FALSE, 0);
gtk_entry_set_width_chars(GTK_ENTRY(*entry), 3);
gtk_entry_set_activates_default(GTK_ENTRY(*entry), TRUE);
gtk_entry_set_text(GTK_ENTRY(*entry), defaultResult);
GtkWidget *label2 = gtk_label_new(text2);
gtk_misc_set_alignment(GTK_MISC(label2), 0, 0.5);
gtk_box_pack_start(GTK_BOX(hbox), label2, FALSE, FALSE, 0);
gtk_widget_show_all(dialog);
return dialog;
}
/* Show a dialog to ask the user what threshold to use for removing
* "gappy" sequences (i.e. sequences that are more than the given
* percentage of gaps). */
static void showRemoveGappySeqsDialog(GtkWidget *belvuWindow)
{
static char *inputText = NULL;
if (!inputText)
inputText = g_strdup("50");
GtkWidget *entry = NULL;
BelvuContext *bc = windowGetContext(belvuWindow);
char *title = g_strdup_printf("%sremove sequences", belvuGetTitlePrefix(bc));
GtkWidget *dialog = createPromptDialog(belvuWindow, inputText, title, "Remove sequences that are ", "% or more gaps.", &entry);
g_free(title);
if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT)
{
if (inputText)
g_free(inputText);
inputText = g_strdup(gtk_entry_get_text(GTK_ENTRY(entry)));
const gdouble cutoff = g_strtod(inputText, NULL);
BelvuWindowProperties *properties = belvuWindowGetProperties(belvuWindow);
removeGappySeqs(properties->bc, properties->bc->belvuAlignment, cutoff);
}
gtk_widget_destroy(dialog);
}
static void showMakeNonRedundantDialog(GtkWidget *belvuWindow)
{
static char *inputText = NULL;
if (!inputText)
inputText = g_strdup("80.0");
GtkWidget *entry = NULL;
BelvuContext *bc = windowGetContext(belvuWindow);
char *title = g_strdup_printf("%sremove sequences", belvuGetTitlePrefix(bc));
GtkWidget *dialog = createPromptDialog(belvuWindow, inputText, title, "Remove sequences that are more than ", "% identical.", &entry);
g_free(title);
if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT)
{
if (inputText)
g_free(inputText);
inputText = g_strdup(gtk_entry_get_text(GTK_ENTRY(entry)));
const gdouble cutoff = g_strtod(inputText, NULL);
BelvuWindowProperties *properties = belvuWindowGetProperties(belvuWindow);
removeRedundantSeqs(properties->bc, properties->bc->belvuAlignment, cutoff);
}
gtk_widget_destroy(dialog);
}
static void showRemoveOutliersDialog(GtkWidget *belvuWindow)
{
static char *inputText = NULL;
if (!inputText)
inputText = g_strdup("20.0");
GtkWidget *entry = NULL;
BelvuContext *bc = windowGetContext(belvuWindow);
char *title = g_strdup_printf("%sremove sequences", belvuGetTitlePrefix(bc));
GtkWidget *dialog = createPromptDialog(belvuWindow, inputText, title, "Remove sequences that are less than ", "% identical with any other.", &entry);
g_free(title);
if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT)
{
if (inputText)
g_free(inputText);
inputText = g_strdup(gtk_entry_get_text(GTK_ENTRY(entry)));
const gdouble cutoff = g_strtod(inputText, NULL);
BelvuWindowProperties *properties = belvuWindowGetProperties(belvuWindow);
removeOutliers(properties->bc, properties->bc->belvuAlignment, cutoff);
}
gtk_widget_destroy(dialog);
}
static void showRemoveByScoreDialog(GtkWidget *belvuWindow)
{
static char *inputText = NULL;
if (!inputText)
inputText = g_strdup("20.0");
GtkWidget *entry = NULL;
BelvuContext *bc = windowGetContext(belvuWindow);
char *title = g_strdup_printf("%sremove sequences", belvuGetTitlePrefix(bc));
GtkWidget *dialog = createPromptDialog(belvuWindow, inputText, title, "Remove sequences that have a score less than ", "", &entry);
g_free(title);
if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT)
{
if (inputText)
g_free(inputText);
inputText = g_strdup(gtk_entry_get_text(GTK_ENTRY(entry)));
const gdouble cutoff = g_strtod(inputText, NULL);
BelvuWindowProperties *properties = belvuWindowGetProperties(belvuWindow);
removeByScore(properties->bc, properties->bc->belvuAlignment, cutoff);
}
gtk_widget_destroy(dialog);
}
/***********************************************************
* Remove columns *
***********************************************************/
static void showRemoveColumnsDialog(GtkWidget *belvuWindow)
{
BelvuWindowProperties *properties = belvuWindowGetProperties(belvuWindow);
BelvuContext *bc = properties->bc;
char *title = g_strdup_printf("%sRemove Columns", belvuGetTitlePrefix(bc));
GtkWidget *dialog = gtk_dialog_new_with_buttons(title,
GTK_WINDOW(belvuWindow),
(GtkDialogFlags)(GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT),
GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
NULL);
g_free(title);
gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT);
GtkWidget *hbox = gtk_hbox_new(FALSE, 0);
gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), hbox, FALSE, FALSE, 12);
GtkWidget *label1 = gtk_label_new("Remove columns from");
gtk_misc_set_alignment(GTK_MISC(label1), 1, 0.5);
gtk_box_pack_start(GTK_BOX(hbox), label1, FALSE, FALSE, 0);
char *maxLenText = g_strdup_printf("%d", bc->maxLen);
GtkWidget *entry1 = gtk_entry_new();
gtk_box_pack_start(GTK_BOX(hbox), entry1, FALSE, FALSE, 0);
gtk_entry_set_width_chars(GTK_ENTRY(entry1), strlen(maxLenText) + 1);
gtk_entry_set_activates_default(GTK_ENTRY(entry1), TRUE);
gtk_entry_set_text(GTK_ENTRY(entry1), "1");
GtkWidget *label2 = gtk_label_new("to");
gtk_misc_set_alignment(GTK_MISC(label2), 0, 0.5);
gtk_box_pack_start(GTK_BOX(hbox), label2, FALSE, FALSE, 0);
GtkWidget *entry2 = gtk_entry_new();
gtk_box_pack_start(GTK_BOX(hbox), entry2, FALSE, FALSE, 0);
gtk_entry_set_width_chars(GTK_ENTRY(entry2), strlen(maxLenText) + 3);
gtk_entry_set_activates_default(GTK_ENTRY(entry2), TRUE);
gtk_entry_set_text(GTK_ENTRY(entry2), maxLenText);
g_free(maxLenText);
maxLenText = NULL;
gtk_widget_show_all(dialog);
if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT)
{
const char *inputText1 = gtk_entry_get_text(GTK_ENTRY(entry1));
const int fromVal = convertStringToInt(inputText1);
const char *inputText2 = gtk_entry_get_text(GTK_ENTRY(entry2));
const int toVal = convertStringToInt(inputText2);
rmColumn(bc, fromVal, toVal);
rmFinaliseColumnRemoval(bc);
updateOnAlignmentLenChanged(bc->belvuAlignment);
}
gtk_widget_destroy(dialog);
}
/* Remove columns with conservation below a given cutoff */
static void showRemoveColumnsCutoffDialog(GtkWidget *belvuWindow)
{
BelvuWindowProperties *properties = belvuWindowGetProperties(belvuWindow);
BelvuContext *bc = properties->bc;
static char *fromText = NULL;
static char *toText = NULL;
if (!fromText)
fromText = g_strdup_printf("%.2f", -1.0);
if (!toText)
toText = g_strdup_printf("%.2f", 0.9);
char *title = g_strdup_printf("%sRemove Columns", belvuGetTitlePrefix(bc));
GtkWidget *dialog = gtk_dialog_new_with_buttons(title,
GTK_WINDOW(belvuWindow),
(GtkDialogFlags)(GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT),
GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
NULL);
g_free(title);
gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT);
GtkWidget *vbox = gtk_vbox_new(FALSE, DIALOG_YPAD);
gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), vbox, FALSE, FALSE, DIALOG_YPAD);
/* Place a label at the top */
GtkWidget *label1 = gtk_label_new("Remove columns with a (maximum) conservation between: ");
gtk_misc_set_alignment(GTK_MISC(label1), 0.0, 0.5);
gtk_box_pack_start(GTK_BOX(vbox), label1, FALSE, FALSE, 0);
/* Place the text entry boxes in an hbox */
GtkWidget *hbox = gtk_hbox_new(FALSE, 0);
gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, DIALOG_YPAD);
gtk_box_pack_start(GTK_BOX(hbox), gtk_label_new(""), FALSE, FALSE, DIALOG_XPAD);
GtkWidget *entry1 = gtk_entry_new();
gtk_box_pack_start(GTK_BOX(hbox), entry1, FALSE, FALSE, DIALOG_XPAD);
gtk_entry_set_width_chars(GTK_ENTRY(entry1), strlen(fromText) + 1);
gtk_entry_set_activates_default(GTK_ENTRY(entry1), TRUE);
gtk_entry_set_text(GTK_ENTRY(entry1), fromText);
GtkWidget *label2 = gtk_label_new("< conservation <=");
gtk_misc_set_alignment(GTK_MISC(label2), 0, 0.5);
gtk_box_pack_start(GTK_BOX(hbox), label2, FALSE, FALSE, 0);
GtkWidget *entry2 = gtk_entry_new();
gtk_box_pack_start(GTK_BOX(hbox), entry2, FALSE, FALSE, DIALOG_XPAD);
gtk_entry_set_width_chars(GTK_ENTRY(entry2), strlen(toText) + 3);
gtk_entry_set_activates_default(GTK_ENTRY(entry2), TRUE);
gtk_entry_set_text(GTK_ENTRY(entry2), toText);
gtk_widget_show_all(dialog);
if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT)
{
g_free(fromText);
fromText = g_strdup(gtk_entry_get_text(GTK_ENTRY(entry1)));
const double fromVal = g_strtod(fromText, NULL);
g_free(toText);
toText = g_strdup(gtk_entry_get_text(GTK_ENTRY(entry2)));
const double toVal = g_strtod(toText, NULL);
rmColumnCutoff(bc, fromVal, toVal);
updateOnAlignmentLenChanged(bc->belvuAlignment);
}
gtk_widget_destroy(dialog);
}
/* Remove columns with a higher fraction of gaps than a specified cutoff */
static void showRemoveGappyColumnsDialog(GtkWidget *belvuWindow)
{
BelvuWindowProperties *properties = belvuWindowGetProperties(belvuWindow);
BelvuContext *bc = properties->bc;
static char *inputText = NULL;
if (!inputText)
inputText = g_strdup_printf("%.0f", 50.0);
GtkWidget *entry = NULL;
char *title = g_strdup_printf("%sRemove Columns", belvuGetTitlePrefix(bc));
GtkWidget *dialog = createPromptDialog(belvuWindow, inputText, title, "Remove columns with more than ", " % gaps", &entry);
g_free(title);
if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT)
{
g_free(inputText);
inputText = g_strdup(gtk_entry_get_text(GTK_ENTRY(entry)));
const double cutoff = g_strtod(inputText, NULL);
rmEmptyColumns(bc, cutoff/100.0);
rmFinaliseColumnRemoval(bc);
updateOnAlignmentLenChanged(bc->belvuAlignment);
}
gtk_widget_destroy(dialog);
}
/***********************************************************
* Select gap character dialog *
***********************************************************/
static void showSelectGapCharDialog(GtkWidget *belvuWindow)
{
BelvuWindowProperties *properties = belvuWindowGetProperties(belvuWindow);
BelvuContext *bc = properties->bc;
char *title = g_strdup_printf("%sGap Character", belvuGetTitlePrefix(bc));
GtkWidget *dialog = gtk_dialog_new_with_buttons(title,
GTK_WINDOW(belvuWindow),
(GtkDialogFlags)(GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_MODAL),
GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
NULL);
g_free(title);
g_signal_connect(dialog, "response", G_CALLBACK(onResponseDialog), belvuWindow);
gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT);
GtkBox *hbox = GTK_BOX(gtk_hbox_new(FALSE, 12));
gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), GTK_WIDGET(hbox), FALSE, FALSE, 12);
GtkWidget *label = gtk_label_new("Select gap character:");
gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.0);
gtk_box_pack_start(hbox, label, FALSE, FALSE, 12);
/* Create radio buttons for each gap character (only dot or dash at the moment) */
GtkBox *vbox = GTK_BOX(gtk_vbox_new(FALSE, 12));
gtk_box_pack_start(hbox, GTK_WIDGET(vbox), TRUE, TRUE, 0);
const gboolean button1Active = (bc->gapChar == '.');
GtkWidget *button1 = gtk_radio_button_new_with_label_from_widget(NULL, "dot (.) ");
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button1), button1Active);
gtk_box_pack_start(vbox, button1, FALSE, FALSE, 0);
GtkWidget *button2 = gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(button1), "dash (-) ");
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button2), !button1Active);
gtk_box_pack_start(vbox, button2, FALSE, FALSE, 0);
gtk_window_set_default_size(GTK_WINDOW(dialog), 300, -1);
gtk_widget_show_all(dialog);
if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT)
{
char newChar;
if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button1)))
newChar = '.';
else
newChar = '-';
if (newChar != bc->gapChar)
{
bc->gapChar = newChar;
/* Change all the gaps in the sequences to use the new gap char */
int i,j;
for (i = 0; i < (int)bc->alignArr->len; ++i)
{
ALN *alnp = g_array_index(bc->alignArr, ALN*, i);
char *alnpSeq = alnGetSeq(alnp);
for (j = 0; j < bc->maxLen; ++j)
{
if (isGap(alnpSeq[j]))
alnpSeq[j] = bc->gapChar;
}
}
belvuAlignmentRedrawAll(bc->belvuAlignment);
}
}
gtk_widget_destroy(dialog);
}
/***********************************************************
* Color by residue ID dialog *
***********************************************************/
/* Dialog to prompt the user to enter a threshold for coloring residues by ID */
static void showColorByResIdDialog(GtkWidget *belvuWindow)
{
static char *inputText = NULL;
if (!inputText)
inputText = g_strdup("20.0");
GtkWidget *entry = NULL;
BelvuContext *bc = windowGetContext(belvuWindow);
char *title = g_strdup_printf("%sColor by Residue ID", belvuGetTitlePrefix(bc));
GtkWidget *dialog = createPromptDialog(belvuWindow, inputText, title, "Only colour residues above ", "% identity", &entry);
g_free(title);
if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT)
{
if (inputText)
g_free(inputText);
inputText = g_strdup(gtk_entry_get_text(GTK_ENTRY(entry)));
BelvuWindowProperties *properties = belvuWindowGetProperties(belvuWindow);
properties->bc->colorByResIdCutoff = g_strtod(inputText, NULL);
/* This sets the flag and also updates the associated 'toggle' menu item */
setToggleMenuStatus(properties->actionGroup, "toggleColorByResId", TRUE);
/* Update the color scheme and redraw */
updateSchemeColors(properties->bc);
belvuAlignmentRedrawAll(properties->bc->belvuAlignment);
}
gtk_widget_destroy(dialog);
}
/***********************************************************
* Edit Colors dialog *
***********************************************************/
/* This creates a drop-down box for selecting a color */
static GtkComboBox* createColorCombo(const int colorNum)
{
GtkComboBox *combo = createComboBox();
GtkTreeIter *iter = NULL;
int i = 0;
for (i = 0; i < NUM_TRUECOLORS; ++i)
addComboItem(combo, iter, i, getColorNumName(i), colorNum);
return combo;
}
/* This is called when a color combo box has been changed and it updates
* the given color button (passed as the user data) to be the same color */
static void updateColorButton(GtkWidget *combo, gpointer data)
{
GtkWidget *colorButton = GTK_WIDGET(data);
const int colorNum = gtk_combo_box_get_active(GTK_COMBO_BOX(combo));
GdkColor color;
convertColorNumToGdkColor(colorNum, FALSE, &color);
gtk_widget_modify_bg(colorButton, GTK_STATE_NORMAL, &color);
}
/* This is called when a color combo box has been changed and it updates the
* given residue (passed as the user data) */
static void updateColorResidue(GtkWidget *combo, gpointer data)
{
const int colorNum = gtk_combo_box_get_active(GTK_COMBO_BOX(combo));
const char *residue = (const char*)data;
setColor(*residue, colorNum);
GtkWindow *dialogWindow = GTK_WINDOW(gtk_widget_get_toplevel(combo));
GtkWidget *belvuWindow = GTK_WIDGET(gtk_window_get_transient_for(dialogWindow));
BelvuWindowProperties *properties = belvuWindowGetProperties(belvuWindow);
onColorSchemeChanged(properties);
}
/* Create a color chooser button. This is a bit of a hack because it has to
* deal with the old-style acedb colors, whereas ideally we would get rid of
* those and just use a GTK color-button widget. */
static void createColorButton(const int colorNum,
GtkTable *table,
const int row,
const int col,
const int xpad,
const int ypad,
GCallback callbackFunc,
gpointer data)
{
/* Create the color chooser. First get the current color for this residue */
GdkColor color;
convertColorNumToGdkColor(colorNum, FALSE, &color);
/* Create a color box to display the currently-selected color. NB ideally we would get
* rid of the drop-down box and have a color-picker button instead, but this requires
* changes to the way colors are stored and saved in order to support more colors than
* just the old-style acedb list. */
GtkWidget *colorButton = gtk_event_box_new();
gtk_table_attach(table, colorButton, col, col + 1, row, row + 1, GTK_SHRINK, GTK_SHRINK, xpad, ypad);
gtk_widget_set_size_request(colorButton, 40, 20);
gtk_widget_modify_bg(colorButton, GTK_STATE_NORMAL, &color);
/* Create a drop-down box to allow the user to select one of the old-style acedb colors. */
GtkWidget *combo = GTK_WIDGET(createColorCombo(colorNum));
gtk_table_attach(table, combo, col + 1, col + 2, row, row + 1, GTK_SHRINK, GTK_SHRINK, xpad, ypad);
/* This just updates the gtk color button with the new color when the combo box value has changed. */
g_signal_connect(G_OBJECT(combo), "changed", G_CALLBACK(updateColorButton), colorButton);
/* This attaches the 'proper' user callback function */
g_signal_connect(G_OBJECT(combo), "changed", callbackFunc, data);
}
/* This creates a single color item on the edit-residue-colors dialog */
static void createResidueColorBox(GtkTable *table,
char *residue,
GString *groups[],
int *row,
int *col,
const int xpad,
const int ypad)
{
/* Create the label */
GtkWidget *label = gtk_label_new(residue);
gtk_table_attach(table, label, *col, *col + 1, *row, *row + 1, GTK_SHRINK, GTK_SHRINK, xpad, ypad);
/* Create the color chooser. First get the current color for this residue */
const int colorNum = getColor(*residue);
createColorButton(colorNum, table, *row, *col + 1, xpad, ypad, G_CALLBACK(updateColorResidue), residue);
/* Append this residue to the group for this color */
//to do: g_string_append(groups[colorNum], residue);
*row += 1;
}
/* Utility function to create the list of residues that belvu knows about */
static GSList* createResidueList()
{
GSList *list = NULL;
list = g_slist_prepend(list, g_strdup("V"));
list = g_slist_prepend(list, g_strdup("Y"));
list = g_slist_prepend(list, g_strdup("W"));
list = g_slist_prepend(list, g_strdup("T"));
list = g_slist_prepend(list, g_strdup("S"));
list = g_slist_prepend(list, g_strdup("P"));
list = g_slist_prepend(list, g_strdup("F"));
list = g_slist_prepend(list, g_strdup("M"));
list = g_slist_prepend(list, g_strdup("K"));
list = g_slist_prepend(list, g_strdup("L"));
list = g_slist_prepend(list, g_strdup("I"));
list = g_slist_prepend(list, g_strdup("H"));
list = g_slist_prepend(list, g_strdup("G"));
list = g_slist_prepend(list, g_strdup("E"));
list = g_slist_prepend(list, g_strdup("Q"));
list = g_slist_prepend(list, g_strdup("C"));
list = g_slist_prepend(list, g_strdup("D"));
list = g_slist_prepend(list, g_strdup("N"));
list = g_slist_prepend(list, g_strdup("R"));
list = g_slist_prepend(list, g_strdup("A"));
return list;
}
/* Create the colour boxes for the edit-residue-colors dialog */
static void createResidueColorBoxes(GtkBox *box, GSList *residueList, GString *groups[])
{
const int numRows = 10;
const int numCols = 7;
int xpad = 4;
int ypad = TABLE_YPAD;
GtkTable *table = GTK_TABLE(gtk_table_new(numRows, numCols, FALSE));
gtk_box_pack_start(box, GTK_WIDGET(table), FALSE, FALSE, 0);
int row = 0;
int col = 0;
int i = 0;
GSList *residueItem = residueList;
const int numResidues = g_slist_length(residueList);
for ( ; residueItem && i < numResidues / 2; ++i, residueItem = residueItem->next)
{
createResidueColorBox(table, (char*)(residueItem->data), groups, &row, &col, xpad, ypad);
}
GtkWidget *spacer = gtk_label_new(" ");
gtk_table_attach(table, spacer, col + 3, col + 4, row, row + 1, GTK_SHRINK, GTK_SHRINK, 30, ypad);
col += 4;
row = 0;
for ( ; residueItem; residueItem = residueItem->next)
{
createResidueColorBox(table, (char*)(residueItem->data), groups, &row, &col, xpad, ypad);
}
}
/* Create the content for the edit-residue-colors dialog */
static void createEditResidueContent(GtkBox *box)
{
GtkBox *vbox = GTK_BOX(gtk_vbox_new(FALSE, 0));
gtk_box_pack_start(box, GTK_WIDGET(vbox), TRUE, TRUE, 0);
static GSList *residueList = NULL;
if (!residueList)
residueList = createResidueList();
// GString* groups[NUM_TRUECOLORS];
// int i = 0;
// for (i = 0; i < NUM_TRUECOLORS; ++i)
// groups[i] = g_string_new("");
createResidueColorBoxes(vbox, residueList, NULL);
// GtkTable *table = GTK_TABLE(gtk_table_new(g_slist_length(residueList) + 1, 3, FALSE));
// gtk_box_pack_start(vbox, GTK_WIDGET(table), TRUE, TRUE, 0);
// int row = 0;
// const int xpad = TABLE_XPAD;
// const int ypad = TABLE_YPAD;
//
// GtkWidget *header = gtk_label_new("Groups:");
// gtk_table_attach(table, header, 0, 1, row, row + 1, GTK_SHRINK, GTK_SHRINK, xpad, ypad);
// ++row;
//
// for (i = 0; i < NUM_TRUECOLORS; ++i)
// {
// if (groups[i]->len > 0 && groups[i]->str)
// {
// GdkColor color;
// convertColorNumToGdkColor(i, FALSE, &color);
//
// GtkWidget *eventBox = gtk_event_box_new();
// gtk_widget_modify_bg(eventBox, GTK_STATE_NORMAL, &color);
// gtk_table_attach(table, eventBox, 0, 1, row, row + 1, GTK_FILL, GTK_SHRINK, xpad, ypad);
//
// GtkWidget *label = gtk_label_new(getColorNumName(i));
// gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.0);
// gtk_container_add(GTK_CONTAINER(eventBox), label);
//
// gtk_table_attach(table, gtk_label_new(":"), 1, 2, row, row + 1, GTK_FILL, GTK_SHRINK, xpad, ypad);
//
// label = gtk_label_new(groups[i]->str);
// gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.0);
// gtk_table_attach(table, label, 2, 3, row, row + 1, GTK_FILL, GTK_SHRINK, xpad, ypad);
//
// ++row;
// }
// }
//
}
/* Called when the user responds to the edit-residue-colors dialog */
void onResponseEditResidueColorsDialog(GtkDialog *dialog, gint responseId, gpointer data)
{
gboolean destroy = TRUE;
GtkWidget *belvuWindow = GTK_WIDGET(data);
BelvuWindowProperties *properties = belvuWindowGetProperties(belvuWindow);
BelvuContext *bc = properties->bc;
switch (responseId)
{
case GTK_RESPONSE_ACCEPT:
if (widgetCallAllCallbacks(GTK_WIDGET(dialog), GINT_TO_POINTER(responseId)))
{
/* Save the current color set and set the color scheme to 'custom' */
destroy = TRUE;
saveCustomColors(bc);
setToggleMenuStatus(properties->actionGroup, "colorSchemeCustom", TRUE);
}
break;
case GTK_RESPONSE_CANCEL:
case GTK_RESPONSE_REJECT:
/* Reset the color scheme, refresh, and close the dialog. */
destroy = TRUE;
setResidueSchemeColors(bc);
updateSchemeColors(bc);
belvuAlignmentRedrawAll(bc->belvuAlignment);
break;
default:
break;
};
if (destroy)
{
gtk_widget_hide_all(GTK_WIDGET(dialog));
}
}
/* Show a dialog to allow the user to edit the residue colors */
static void showEditResidueColorsDialog(GtkWidget *belvuWindow, const gboolean bringToFront)
{
BelvuWindowProperties *properties = belvuWindowGetProperties(belvuWindow);
BelvuContext *bc = properties->bc;
const BelvuDialogId dialogId = BELDIALOG_EDIT_RESIDUE_COLORS;
GtkWidget *dialog = getPersistentDialog(bc->dialogList, dialogId);
if (!dialog)
{
char *title = g_strdup_printf("%sEdit Residue Colors", belvuGetTitlePrefix(bc));
dialog = gtk_dialog_new_with_buttons(title,
GTK_WINDOW(belvuWindow),
(GtkDialogFlags)(GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_MODAL),
GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
NULL);
g_free(title);
/* These calls are required to make the dialog persistent... */
addPersistentDialog(bc->dialogList, dialogId, dialog);
g_signal_connect(dialog, "delete-event", G_CALLBACK(gtk_widget_hide_on_delete), NULL);
g_signal_connect(dialog, "response", G_CALLBACK(onResponseEditResidueColorsDialog), belvuWindow);
}
else
{
/* Need to refresh the dialog contents, so clear and re-create content area */
dialogClearContentArea(GTK_DIALOG(dialog));
}
gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT);
GtkBox *vbox = GTK_BOX(GTK_DIALOG(dialog)->vbox);
createEditResidueContent(vbox);
/* Show / bring to front */
gtk_widget_show_all(dialog);
if (bringToFront)
{
gtk_window_present(GTK_WINDOW(dialog));
}
}
/* Called when the user responds to the edit-conservation-colors dialog */
void onResponseConsColorsDialog(GtkDialog *dialog, gint responseId, gpointer data)
{
gboolean destroy = TRUE;
GtkWidget *belvuWindow = GTK_WIDGET(data);
BelvuWindowProperties *properties = belvuWindowGetProperties(belvuWindow);
BelvuContext *bc = properties->bc;
switch (responseId)
{
case GTK_RESPONSE_ACCEPT:
/* Close dialog if successful */
destroy = widgetCallAllCallbacks(GTK_WIDGET(dialog), GINT_TO_POINTER(responseId));
setToggleMenuStatus(properties->actionGroup, "ColorByCons", TRUE);
break;
case GTK_RESPONSE_APPLY:
/* Never close */
destroy = FALSE;
widgetCallAllCallbacks(GTK_WIDGET(dialog), GINT_TO_POINTER(responseId));
setToggleMenuStatus(properties->actionGroup, "ColorByCons", TRUE);
break;
case GTK_RESPONSE_CANCEL:
case GTK_RESPONSE_REJECT:
/* Reset the color scheme. */
destroy = TRUE;
saveOrResetConsColors(bc, FALSE); /* restores old values */
break;
default:
break;
};
onColorSchemeChanged(properties);
if (destroy)
{
gtk_widget_hide_all(GTK_WIDGET(dialog));
}
}
/* Callback called when a foreground conservation color has been changed */
static void updateConsFgColor(GtkWidget *combo, gpointer data)
{
int *colorNum = (int*)data;
*colorNum = gtk_combo_box_get_active(GTK_COMBO_BOX(combo));
GtkWindow *dialogWindow = GTK_WINDOW(gtk_widget_get_toplevel(combo));
GtkWidget *belvuWindow = GTK_WIDGET(gtk_window_get_transient_for(dialogWindow));
BelvuWindowProperties *properties = belvuWindowGetProperties(belvuWindow);
onColorSchemeChanged(properties);
}
/* Callback called when a background conservation color has been changed */
static void updateConsBgColor(GtkWidget *combo, gpointer data)
{
int *colorNum = (int*)data;
*colorNum = gtk_combo_box_get_active(GTK_COMBO_BOX(combo));
GtkWindow *dialogWindow = GTK_WINDOW(gtk_widget_get_toplevel(combo));
GtkWidget *belvuWindow = GTK_WIDGET(gtk_window_get_transient_for(dialogWindow));
BelvuWindowProperties *properties = belvuWindowGetProperties(belvuWindow);
onColorSchemeChanged(properties);
}
/* Callback called when the user 'ok's the edit-conservation-colors dialog
* to set the new threshold values. The given widget must be a GtkEntry and the
* user data a pointer to a double. */
static gboolean onConsThresholdChanged(GtkWidget *widget, gint responseId, gpointer data)
{
GtkEntry *entry = GTK_ENTRY(widget);
double *val = (double*)data;
const gchar *inputText = gtk_entry_get_text(entry);
*val = g_strtod(inputText, NULL);
return TRUE;
}
/* Add a single line in the edit-cons-colors dialog */
static void addConsColorLine(BelvuContext *bc, const char *labelText, const BelvuConsLevel consLevel, double *cutoff, GtkTable *table, int *row)
{
/* Label */
GtkWidget *label = gtk_label_new(labelText);
gtk_misc_set_alignment(GTK_MISC(label), 1.0, 0.0);
gtk_table_attach(table, label, 0, 1, *row, *row + 1, GTK_FILL, GTK_SHRINK, TABLE_XPAD, TABLE_YPAD);
/* Threshold entry box */
GtkWidget *entry = gtk_entry_new();
gtk_entry_set_activates_default(GTK_ENTRY(entry), TRUE);
char *defaultInput = g_strdup_printf("%.1f", *cutoff);
gtk_entry_set_text(GTK_ENTRY(entry), defaultInput);
gtk_entry_set_width_chars(GTK_ENTRY(entry), strlen(defaultInput) + 2);
g_free(defaultInput);
defaultInput = NULL;
gtk_table_attach(table, entry, 1, 2, *row, *row + 1, GTK_FILL, GTK_SHRINK, TABLE_XPAD, TABLE_YPAD);
widgetSetCallbackData(entry, onConsThresholdChanged, cutoff);
/* Text color chooser */
int *fgColorNum = getConsColor(bc, consLevel, TRUE);
createColorButton(*fgColorNum, table, *row, 2, 2, TABLE_YPAD, G_CALLBACK(updateConsFgColor), fgColorNum);
/* Background color chooser */
int *bgColorNum = getConsColor(bc, consLevel, FALSE);
createColorButton(*bgColorNum, table, *row, 4, 2, TABLE_YPAD, G_CALLBACK(updateConsBgColor), bgColorNum);
*row += 1;
}
/* Hacky function to save the current conservation colors or reset them to
* previously saved values (if 'save' is false). Ideally, the drawing
* functions would not use the colors in the BelvuContext directly and we'd
* therefore be able to show the user different colors without having to change
* the BelvuContext, and hence without the need for this hacky undo function. */
static void saveOrResetConsColors(BelvuContext *bc, const gboolean save)
{
/* These are all the values we need to be able to restore if the dialog
* is cancelled... */
static double lowIdCutoff = 0;
static double midIdCutoff = 0;
static double maxIdCutoff = 0;
static double lowSimCutoff = 0;
static double midSimCutoff = 0;
static double maxSimCutoff = 0;
static int maxfgColor = 0;
static int midfgColor = 0;
static int lowfgColor = 0;
static int maxbgColor = 0;
static int midbgColor = 0;
static int lowbgColor = 0;
static int maxfgPrintColor = 0;
static int midfgPrintColor = 0;
static int lowfgPrintColor = 0;
static int maxbgPrintColor = 0;
static int midbgPrintColor = 0;
static int lowbgPrintColor = 0;
if (save)
{
/* Remember the current conservation colors */
lowIdCutoff = bc->lowIdCutoff;
midIdCutoff = bc->midIdCutoff;
maxIdCutoff = bc->maxIdCutoff;
lowSimCutoff = bc->lowSimCutoff;
midSimCutoff = bc->midSimCutoff;
maxSimCutoff = bc->maxSimCutoff;
maxfgColor = bc->maxfgColor;
midfgColor = bc->midfgColor;
lowfgColor = bc->lowfgColor;
maxbgColor = bc->maxbgColor;
midbgColor = bc->midbgColor;
lowbgColor = bc->lowbgColor;
maxfgPrintColor = bc->maxfgPrintColor;
midfgPrintColor = bc->midfgPrintColor;
lowfgPrintColor = bc->lowfgPrintColor;
maxbgPrintColor = bc->maxbgPrintColor;
midbgPrintColor = bc->midbgPrintColor;
lowbgPrintColor = bc->lowbgPrintColor;
}
else
{
/* Reset to the previously-saved values */
bc->lowIdCutoff = lowIdCutoff;
bc->midIdCutoff = midIdCutoff;
bc->maxIdCutoff = maxIdCutoff;
bc->lowSimCutoff = lowSimCutoff;
bc->midSimCutoff = midSimCutoff;
bc->maxSimCutoff = maxSimCutoff;
bc->maxfgColor = maxfgColor;
bc->midfgColor = midfgColor;
bc->lowfgColor = lowfgColor;
bc->maxbgColor = maxbgColor;
bc->midbgColor = midbgColor;
bc->lowbgColor = lowbgColor;
bc->maxfgPrintColor = maxfgPrintColor;
bc->midfgPrintColor = midfgPrintColor;
bc->lowfgPrintColor = lowfgPrintColor;
bc->maxbgPrintColor = maxbgPrintColor;
bc->midbgPrintColor = midbgPrintColor;
bc->lowbgPrintColor = lowbgPrintColor;
}
}
/* Create the content for the edit-conservation-color-scheme dialog */
static void createEditConsColorsContent(GtkBox *box, BelvuContext *bc)
{
/* Save current values so that we can restore them later if we cancel */
saveOrResetConsColors(bc, TRUE);
/* We'll put everything in a vbox */
GtkBox *vbox = GTK_BOX(gtk_vbox_new(FALSE, 0));
gtk_box_pack_start(box, GTK_WIDGET(vbox), FALSE, FALSE, 0);
/* Create the labels */
char *tmpStr = g_strdup_printf("Coloring by %s", bc->consScheme == BELVU_SCHEME_BLOSUM ? "average BLOSUM62 score" : "% identity");
GtkWidget *label = gtk_label_new(tmpStr);
gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.0);
gtk_box_pack_start(vbox, label, FALSE, FALSE, DIALOG_YPAD);
g_free(tmpStr);
tmpStr = NULL;
const gboolean colorById = (bc->consScheme == BELVU_SCHEME_ID || bc->consScheme == BELVU_SCHEME_ID_BLOSUM);
const gboolean colorBySim = (bc->consScheme == BELVU_SCHEME_BLOSUM || bc->consScheme == BELVU_SCHEME_ID_BLOSUM);
if (colorBySim)
{
label = gtk_label_new("Similar residues according to BLOSUM62 are coloured as the most conserved one.");
gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.0);
gtk_box_pack_start(vbox, label, FALSE, FALSE, DIALOG_YPAD);
}
/* Place the main widgets in a table */
GtkTable *table = GTK_TABLE(gtk_table_new(4, 6, FALSE));
gtk_box_pack_start(vbox, GTK_WIDGET(table), TRUE, TRUE, DIALOG_YPAD);
/* 1st row contains labels */
int row = 0;
label = gtk_label_new("Threshold");\
gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.0);
gtk_table_attach(table, label, 1, 2, row, row + 1, GTK_FILL, GTK_SHRINK, TABLE_XPAD, TABLE_YPAD);
label = gtk_label_new("Text colour");
gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.0);
gtk_table_attach(table, label, 2, 4, row, row + 1, GTK_FILL, GTK_SHRINK, TABLE_XPAD, TABLE_YPAD);
label = gtk_label_new("Background colour");
gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.0);
gtk_table_attach(table, label, 4, 6, row, row + 1, GTK_FILL, GTK_SHRINK, TABLE_XPAD, TABLE_YPAD);
++row;
addConsColorLine(bc, "Max:", CONS_LEVEL_MAX, colorById ? &bc->maxIdCutoff : &bc->maxSimCutoff, table, &row);
addConsColorLine(bc, "Mid:", CONS_LEVEL_MID, colorById ? &bc->midIdCutoff : &bc->midSimCutoff, table, &row);
addConsColorLine(bc, "Low:", CONS_LEVEL_LOW, colorById ? &bc->lowIdCutoff : &bc->lowSimCutoff, table, &row);
label = gtk_label_new("Press Enter or click Add to update the display after changing threshold values.");
gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.0);
gtk_box_pack_start(vbox, label, FALSE, FALSE, DIALOG_YPAD);
label = gtk_label_new("Click OK to save changes.");
gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.0);
gtk_box_pack_start(vbox, label, FALSE, FALSE, DIALOG_YPAD);
}
/* Show a dialog to allow the user to edit the conservation color scheme */
static void showEditConsColorsDialog(GtkWidget *belvuWindow, const gboolean bringToFront)
{
BelvuWindowProperties *properties = belvuWindowGetProperties(belvuWindow);
BelvuContext *bc = properties->bc;
const BelvuDialogId dialogId = BELDIALOG_EDIT_CONS_COLORS;
GtkWidget *dialog = getPersistentDialog(bc->dialogList, dialogId);
if (!dialog)
{
char *title = g_strdup_printf("%sEdit Conservation Colors", belvuGetTitlePrefix(bc));
dialog = gtk_dialog_new_with_buttons(title,
GTK_WINDOW(belvuWindow),
(GtkDialogFlags)(GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_MODAL),
GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
GTK_STOCK_ADD, GTK_RESPONSE_APPLY,
GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
NULL);
g_free(title);
/* These calls are required to make the dialog persistent... */
addPersistentDialog(bc->dialogList, dialogId, dialog);
g_signal_connect(dialog, "delete-event", G_CALLBACK(gtk_widget_hide_on_delete), NULL);
g_signal_connect(dialog, "response", G_CALLBACK(onResponseConsColorsDialog), belvuWindow);
}
else
{
/* Need to refresh the dialog contents, so clear and re-create content area */
dialogClearContentArea(GTK_DIALOG(dialog));
}
gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_APPLY);
GtkBox *vbox = GTK_BOX(GTK_DIALOG(dialog)->vbox);
createEditConsColorsContent(vbox, bc);
/* Show / bring to front */
gtk_widget_show_all(dialog);
if (bringToFront)
{
gtk_window_present(GTK_WINDOW(dialog));
}
}
/***********************************************************
* Wrap window *
***********************************************************/
/* Create a text entry with a label. 'labelText' gives the label text and
* defaultInput gives the default input to show in the text entry (may be null).
* Adds the result to table, if given, and returns the text entry widget */
static GtkWidget* createTextEntryWithLabel(const char *labelText,
const char *defaultInput,
GtkTable *table,
const int col,
const int row)
{
const int xpad = 2;
const int ypad = 2;
/* Create the label in the given column */
GtkWidget *label = gtk_label_new(labelText);
gtk_misc_set_alignment(GTK_MISC(label), 1, 0);
gtk_table_attach(table, label, col, col + 1, row, row + 1, GTK_SHRINK, GTK_SHRINK, xpad, ypad);
/* Create the entry in the next column */
GtkWidget *entry = gtk_entry_new();
gtk_entry_set_activates_default(GTK_ENTRY(entry), TRUE);
gtk_table_attach(table, entry, col + 1, col + 2, row, row + 1, (GtkAttachOptions)(GTK_EXPAND | GTK_FILL), GTK_SHRINK, xpad, ypad);
if (defaultInput)
{
gtk_entry_set_text(GTK_ENTRY(entry), defaultInput);
const int defaultLen = min((int)strlen(defaultInput) * 8, 500);
gtk_widget_set_size_request(entry, defaultLen, -1);
}
return entry;
}
/* This shows a dialog that asks the user for settings for the wrap-alignment
* view and then opens the wrap-alignment window on ok. */
static void showWrapDialog(BelvuContext *bc, GtkWidget *belvuWindow)
{
char *title = g_strdup_printf("%swrap alignment", belvuGetTitlePrefix(bc));
GtkWidget *dialog = gtk_dialog_new_with_buttons(title,
GTK_WINDOW(belvuWindow),
(GtkDialogFlags)(GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT),
GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
NULL);
g_free(title);
gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT);
GtkWidget *contentArea = GTK_DIALOG(dialog)->vbox;
/* Create a text entry for the line width and title */
GtkWidget *table = gtk_table_new(2, 2, FALSE);
gtk_box_pack_start(GTK_BOX(contentArea), table, TRUE, TRUE, 0);
GtkWidget *widthEntry = createTextEntryWithLabel("Line width", "80", GTK_TABLE(table), 0, 0);
GtkWidget *titleEntry = createTextEntryWithLabel("Title", bc->Title, GTK_TABLE(table), 0, 1);
gtk_widget_show_all(dialog);
if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT)
{
const gchar *inputText = gtk_entry_get_text(GTK_ENTRY(widthEntry));
const int linelen = convertStringToInt(inputText);
const gchar *title = gtk_entry_get_text(GTK_ENTRY(titleEntry));
createWrapWindow(belvuWindow, linelen, title);
}
gtk_widget_destroy(dialog);
}
/* Utility function to return the child widget of the given container that
* has a cached drawable. Returns the first found (i.e. expects there to be
* only one).
* Sets the result in the user data, if found. The value of *result must be
* null on the first call. */
static void widgetGetDrawing(GtkWidget *widget, gpointer data)
{
GtkWidget **result = (GtkWidget**)data;
if (*result != NULL)
{
return;
}
else if (widgetGetDrawable(widget))
{
*result = widget;
}
else if (GTK_IS_CONTAINER(widget))
{
gtk_container_foreach(GTK_CONTAINER(widget), widgetGetDrawing, result);
}
}
static void setWrapWindowStyleProperties(GtkWidget *window)
{
gtk_widget_set_name(window, WRAPPED_BELVU_WINDOW_NAME);
/* Set the initial window size based on some fraction of the screen size */
int screenWidth = 300, screenHeight = 200;
gbtools::GUIGetTrueMonitorSize(window, &screenWidth, &screenHeight);
const int width = screenWidth * DEFAULT_WRAP_WINDOW_WIDTH_FRACTION;
const int height = screenHeight * DEFAULT_WRAP_WINDOW_HEIGHT_FRACTION;
gtk_window_set_default_size(GTK_WINDOW(window), width, height);
}
static void createWrapWindow(GtkWidget *belvuWindow, const int linelen, const gchar *title)
{
BelvuWindowProperties *properties = belvuWindowGetProperties(belvuWindow);
/* Create the window */
GtkWidget *wrapWindow = gtk_window_new(GTK_WINDOW_TOPLEVEL);
setWrapWindowStyleProperties(wrapWindow);
BelvuContext *bc = windowGetContext(belvuWindow);
char *windowTitle = g_strdup_printf("%s%s", belvuGetTitlePrefix(bc), properties->bc->Title);
gtk_window_set_title(GTK_WINDOW(wrapWindow), windowTitle);
g_free(windowTitle);
/* We must add all toplevel windows to the list of spawned windows */
properties->bc->spawnedWindows = g_slist_prepend(properties->bc->spawnedWindows, wrapWindow);
/* Create the context menu and set a callback to show it */
GtkActionGroup *actionGroup = NULL;
GtkUIManager *uiManager = createUiManager(wrapWindow, properties->bc, &actionGroup);
GtkWidget *contextmenu = createBelvuMenu(wrapWindow, "/WrapContextMenu", uiManager);
gtk_widget_add_events(wrapWindow, GDK_BUTTON_PRESS_MASK);
g_signal_connect(G_OBJECT(wrapWindow), "button-press-event", G_CALLBACK(onButtonPressBelvu), contextmenu);
/* We'll place everything in a vbox */
GtkWidget *vbox = gtk_vbox_new(FALSE, 0);
gtk_container_add(GTK_CONTAINER(wrapWindow), vbox);
/* Add the alignment section */
GtkWidget *wrappedAlignment = createBelvuAlignment(properties->bc, title, linelen);
gtk_box_pack_start(GTK_BOX(vbox), wrappedAlignment, TRUE, TRUE, 0);
/* Set properties */
genericWindowCreateProperties(wrapWindow, properties->bc, actionGroup);
/* Show window */
gtk_widget_show_all(wrapWindow);
gtk_window_present(GTK_WINDOW(wrapWindow));
/* Make sure the font size is up to date */
onBelvuAlignmentFontSizeChanged(wrappedAlignment);
}
/***********************************************************
* Organisms window *
***********************************************************/
static void setOrgsWindowStyleProperties(GtkWidget *window, BelvuContext *bc)
{
gtk_widget_set_name(window, BELVU_ORGS_WINDOW_NAME);
/* Set default size based on number of alignments and max name width */
gdouble charWidth = 0, charHeight = 0;
getFontCharSize(window, window->style->font_desc, &charWidth, &charHeight);
int screenWidth = 100, screenHeight = 100;
gbtools::GUIGetTrueMonitorSize(window, &screenWidth, &screenHeight);
const int maxWidth = screenWidth * MAX_ORGS_WINDOW_WIDTH_FRACTION;
const int maxHeight = screenHeight * MAX_ORGS_WINDOW_HEIGHT_FRACTION;
int width = min((gdouble)maxWidth, charWidth * bc->maxNameLen + ORGS_WINDOW_XPAD * 2);
int height = min((gdouble)maxHeight, charHeight * bc->organismArr->len + ORGS_WINDOW_YPAD * 2);
gtk_window_set_default_size(GTK_WINDOW(window), width, height);
}
/* This does the work to draw the organisms. */
static void drawOrganisms(GtkWidget *widget, GdkDrawable *drawable, BelvuContext *bc)
{
GdkGC *gc = gdk_gc_new(drawable);
GdkColor color;
gdouble charHeight = 0;
getFontCharSize(widget, widget->style->font_desc, NULL, &charHeight);
int y = ORGS_WINDOW_YPAD;
const int x = ORGS_WINDOW_XPAD;
int i = 0;
for ( ; i < (int)bc->organismArr->len; ++i)
{
ALN *alnp = g_array_index(bc->organismArr, ALN*, i);
convertColorNumToGdkColor(alnp->color, FALSE, &color);
gdk_gc_set_foreground(gc, &color);
int text_width = 0;
drawText(widget, drawable, gc, x, y, alnp->organism, &text_width, NULL);
y += charHeight;
}
g_message_info("%d organisms found\n", bc->organismArr->len);
g_object_unref(gc);
}
/* Expose handler for the organisms view */
static gboolean onExposeOrganismsView(GtkWidget *widget, GdkEventExpose *event, gpointer data)
{
GdkDrawable *window = GTK_LAYOUT(widget)->bin_window;
BelvuContext *bc = (BelvuContext*)data;
if (window)
{
GdkDrawable *bitmap = widgetGetDrawable(widget);
if (!bitmap)
{
/* There isn't a bitmap yet. Create it now. */
guint width = 0, height = 0;
gtk_layout_get_size(GTK_LAYOUT(widget), &width, &height);
bitmap = createBlankSizedPixmap(widget, window, width, height);
drawOrganisms(widget, bitmap, bc);
}
if (bitmap)
{
/* Push the bitmap onto the window */
GdkGC *gc = gdk_gc_new(window);
gdk_draw_drawable(window, gc, bitmap, 0, 0, 0, 0, -1, -1);
g_object_unref(gc);
}
else
{
g_warning("Failed to draw Organisms view [%p] - could not create bitmap.\n", widget);
}
}
return TRUE;
}
static void createOrganismWindow(BelvuContext *bc)
{
/* Create the window */
bc->orgsWindow = gtk_window_new(GTK_WINDOW_TOPLEVEL);
setOrgsWindowStyleProperties(bc->orgsWindow, bc);
g_signal_connect(bc->orgsWindow, "delete-event", G_CALLBACK(gtk_widget_hide_on_delete), NULL);
char *title = g_strdup_printf("%sOrganisms", belvuGetTitlePrefix(bc));
gtk_window_set_title(GTK_WINDOW(bc->orgsWindow), title);
g_free(title);
/* We must add all toplevel windows to the list of spawned windows */
bc->spawnedWindows = g_slist_prepend(bc->spawnedWindows, bc->orgsWindow);
/* Create the context menu and set a callback to show it */
GtkActionGroup *actionGroup = NULL;
GtkUIManager *uiManager = createUiManager(bc->orgsWindow, bc, &actionGroup);
GtkWidget *contextmenu = createBelvuMenu(bc->orgsWindow, "/OrgsContextMenu", uiManager);
gtk_widget_add_events(bc->orgsWindow, GDK_BUTTON_PRESS_MASK);
g_signal_connect(G_OBJECT(bc->orgsWindow), "button-press-event", G_CALLBACK(onButtonPressBelvu), contextmenu);
/* Create a scrollable drawing area */
GtkWidget *scrollWin = gtk_scrolled_window_new(NULL, NULL);
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrollWin), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
gtk_container_add(GTK_CONTAINER(bc->orgsWindow), scrollWin);
GtkWidget *drawing = gtk_layout_new(NULL, NULL);
gtk_container_add(GTK_CONTAINER(scrollWin), drawing);
g_signal_connect(G_OBJECT(drawing), "expose-event", G_CALLBACK(onExposeOrganismsView), bc);
/* Set layout size big enough to fit all organisms */
gdouble width = 0, height = 0;
getFontCharSize(drawing, drawing->style->font_desc, &width, &height);
width *= (bc->maxOrganismLen + 1);
height *= (bc->organismArr->len + 1);
/* The size is only approximate (especially the width), so add a sizeable buffer (e.g. double
* it). It's important the layout is not too small but doesn't matter if it's too big (because
* it will be in a scrollwin) */
gtk_layout_set_size(GTK_LAYOUT(drawing), width * 2, height + 10);
/* Add some padding in the main window for space around the layout etc. It doesn't matter too
* much if this is too small because the window is resizable */
gtk_window_set_default_size(GTK_WINDOW(bc->orgsWindow), width * 2 + 20, height + 20) ;
/* Set default background color */
GdkColor *bgColor = getGdkColor(BELCOLOR_BACKGROUND, bc->defaultColors, FALSE, FALSE);
gtk_widget_modify_bg(drawing, GTK_STATE_NORMAL, bgColor);
/* Set properties */
genericWindowCreateProperties(bc->orgsWindow, bc, actionGroup);
gtk_widget_show_all(bc->orgsWindow);
gtk_window_present(GTK_WINDOW(bc->orgsWindow));
}
/***********************************************************
* Updates *
***********************************************************/
void showAnnotationWindow(BelvuContext *bc)
{
/* If there are no annotations, there's nothing to do */
if (g_slist_length(bc->annotationList) < 1)
return;
/* Loop through each annotation line */
GString *resultStr = g_string_new("");
int maxLen = 0;
GSList *annItem = bc->annotationList;
for ( ; annItem; annItem = annItem->next)
{
/* Calculate the max line length */
const char *cp = (const char*)(annItem->data);
if ((int)strlen(cp) > maxLen)
maxLen = strlen(cp);
/* Append this text to the string */
g_string_append_printf(resultStr, "%s\n", cp);
}
/* Create the dialog */
char *title = g_strdup_printf("%sAnnotations", belvuGetTitlePrefix(bc));
GtkWidget *dialog = gtk_dialog_new_with_buttons(title,
NULL,
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_STOCK_CLOSE, GTK_RESPONSE_ACCEPT,
NULL);
g_free(title);
gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_CLOSE);
g_signal_connect(G_OBJECT(dialog), "response", G_CALLBACK(gtk_widget_destroy), NULL);
/* Use a fixed-width font */
const char *fontFamily = findFixedWidthFont(dialog);
PangoFontDescription *fontDesc = pango_font_description_from_string(fontFamily);
pango_font_description_set_size(fontDesc, pango_font_description_get_size(dialog->style->font_desc));
GtkWidget *textView = createScrollableTextView(resultStr->str, FALSE, fontDesc, FALSE, NULL, NULL, NULL);
gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), textView, TRUE, TRUE, 0);
const gchar *env = g_getenv(FONT_SIZE_ENV_VAR);
if (env)
widgetSetFontSizeAndCheck(dialog, convertStringToInt(env));
/* Set the initial size */
double charWidth, charHeight;
getFontCharSize(dialog, fontDesc, &charWidth, &charHeight);
int width = ((maxLen + 1) * charWidth) + scrollBarWidth();
int height = ((g_slist_length(bc->annotationList) + 1) * charHeight) + scrollBarWidth() + 40; /* extra fudge to allow space for buttons */
int maxWidth = 300, maxHeight = 200;
gbtools::GUIGetTrueMonitorSizeFraction(dialog, MAX_ANNOTATION_WINDOW_WIDTH_FRACTION, MAX_ANNOTATION_WINDOW_HEIGHT_FRACTION,
&maxWidth, &maxHeight);
width = min(width, maxWidth);
height = min(height, maxHeight);
gtk_window_set_default_size(GTK_WINDOW(dialog), width, height);
gtk_widget_show_all(dialog);
}
/***********************************************************
* Updates *
***********************************************************/
/* Update the feedback box to show info about the currently-selected items */
static void updateFeedbackBox(BelvuContext *bc, GtkWidget *feedbackBox)
{
GString *resultStr = g_string_new("");
char *tmpStr = NULL;
/* If a column is selected, display the column number */
if (bc->selectedCol > 0)
{
tmpStr = g_strdup_printf("Column %d: ", bc->selectedCol);
g_string_append(resultStr, tmpStr);
g_free(tmpStr);
}
/* If an alignment is selected, display info about it */
if (bc->selectedAln && alnGetSeq(bc->selectedAln))
{
char *selectedSeq = alnGetSeq(bc->selectedAln);
tmpStr = g_strdup_printf("%s/%d-%d", bc->selectedAln->name, bc->selectedAln->start, bc->selectedAln->end);
g_string_append(resultStr, tmpStr);
g_free(tmpStr);
/* If a column is selected, display info about the selected alignment's
* coord at that column position. */
if (bc->selectedCol > 0)
{
/* Print the char of the current sequence at the selected column */
tmpStr = g_strdup_printf(" %c = ", selectedSeq[bc->selectedCol - 1]);
g_string_append(resultStr, tmpStr);
g_free(tmpStr);
/* Loop through each column before the selected column and calculate the
* number of gaps. Also note whether we see an asterisk in the sequence */
gboolean hasAsterisk = FALSE;
int numGaps = 0;
int colIdx = 0;
for ( ; colIdx < bc->selectedCol; colIdx++)
{
if (isGap(selectedSeq[colIdx]))
numGaps++;
else if (selectedSeq[colIdx] == '*')
hasAsterisk = TRUE;
}
if (hasAsterisk)
{
g_string_append(resultStr, "(unknown position due to insertion)");
}
else
{
tmpStr = g_strdup_printf("%d", bc->selectedCol - 1 + bc->selectedAln->start - numGaps);
g_string_append(resultStr, tmpStr);
g_free(tmpStr);
}
}
/* Display the total number of highlighted alignments */
const int numHighlighted = g_slist_length(bc->highlightedAlns);
tmpStr = g_strdup_printf(" (%d match", numHighlighted);
g_string_append(resultStr, tmpStr);
g_free(tmpStr);
if (numHighlighted != 1)
g_string_append(resultStr, "es");
g_string_append(resultStr, ")");
}
gtk_entry_set_text(GTK_ENTRY(feedbackBox), resultStr->str);
g_string_free(resultStr, TRUE);
}
/* This should be called whenever the selected sequence has changed */
void onRowSelectionChanged(BelvuContext *bc)
{
/* Redraw the alignment widget */
belvuAlignmentRedrawAll(bc->belvuAlignment);
centerHighlighted(bc, bc->belvuAlignment);
/* Redraw all of the trees */
g_slist_foreach(bc->spawnedWindows, belvuTreeRedrawAll, NULL);
/* Set the status of the 'exclude highlighted' toggle menu option
* depending on whether the newly-selected sequence is selected or not
* (or grey it out if nothing is selected) */
BelvuWindowProperties *properties = belvuWindowGetProperties(bc->belvuWindow);
enableMenuAction(properties->actionGroup, "excludeHighlighted", bc->selectedAln != NULL);
if (bc->selectedAln)
{
setToggleMenuStatus(properties->actionGroup, "excludeHighlighted", bc->selectedAln->nocolor);
/* Copy the selected sequence name to the PRIMARY clipboard */
setPrimaryClipboardText(bc->selectedAln->name);
}
/* Highlight any alignments that have the same name as the selected alignment */
g_slist_free(bc->highlightedAlns); /* clear current list */
bc->highlightedAlns = NULL;
int i = 0;
for (i = 0; i < (int)bc->alignArr->len; ++i)
{
ALN *alnp = g_array_index(bc->alignArr, ALN*, i);
if (alignmentHighlighted(bc, alnp))
bc->highlightedAlns = g_slist_prepend(bc->highlightedAlns, alnp);
}
/* Update the feedback box */
updateFeedbackBox(properties->bc, properties->feedbackBox);
/* If the current sort method is by similarity/id to the selected sequence,
* this has effectively been 'invalidated' by the fact that the selected
* sequence has changed. We don't undo the sort, but we must set the sort
* method to 'unsorted' so that the user can re-select the sort-by-sim/sort-by-id
* radio button if they want to sort by similarity/id to the newly-selected sequence */
setRadioMenuStatus(properties->actionGroup, "unsorted", BELVU_UNSORTED);
}
/* This should be called whenever the selected column has changed */
void onColSelectionChanged(BelvuContext *bc)
{
/* Update the feedback box */
BelvuWindowProperties *properties = belvuWindowGetProperties(bc->belvuWindow);
updateFeedbackBox(properties->bc, properties->feedbackBox);
/* Refresh the alignment widget */
belvuAlignmentRefreshAll(bc->belvuAlignment);
}
/* This is called after a tree has changed */
void onTreeOrderChanged(BelvuContext *bc)
{
/* If sorting by tree order, we need to refresh the sort order */
if (bc->sortType == BELVU_SORT_TREE)
doSort(bc, bc->sortType, FALSE);
/* Recenter on the highlighted alignment */
centerHighlighted(bc, bc->belvuAlignment);
/* Redraw the tree and the alignment list */
belvuTreeRedrawAll(bc->belvuTree, NULL);
belvuAlignmentRedrawAll(bc->belvuAlignment);
}
/***********************************************************
* Key handlers *
***********************************************************/
static gboolean onKeyPressEscape(BelvuContext *bc)
{
if (bc->removingSeqs)
{
/* Cancel 'removing sequences' mode */
BelvuWindowProperties *properties = belvuWindowGetProperties(bc->belvuWindow);
setToggleMenuStatus(properties->actionGroup, "rmMany", !bc->removingSeqs);
}
return TRUE;
}
static gboolean onKeyPressHomeEnd(BelvuContext *bc, const gboolean home, const gboolean ctrl, const gboolean shift)
{
/* Scroll to the top/bottom of the alignment list */
vScrollStartEnd(bc->belvuAlignment, home);
return TRUE;
}
static gboolean onKeyPressPageUpDown(BelvuContext *bc, const gboolean up, const gboolean ctrl, const gboolean shift)
{
/* Scroll to the top/bottom of the alignment list */
vScrollPageUpDown(bc->belvuAlignment, up);
return TRUE;
}
static gboolean onKeyPressLeftRight(BelvuContext *bc, const gboolean left, const gboolean ctrl, const gboolean shift)
{
if (ctrl)
{
/* Scroll one character left/right */
hScrollLeftRight(bc->belvuAlignment, left, 1);
}
else
{
/* Scroll to the top/bottom of the alignment list */
hScrollPageLeftRight(bc->belvuAlignment, left);
}
return TRUE;
}
static gboolean onKeyPressUpDown(BelvuContext *bc, const gboolean up, const gboolean ctrl, const gboolean shift)
{
if (ctrl)
{
/* Scroll one row up/down */
vScrollUpDown(bc->belvuAlignment, up, 1);
}
else
{
/* Scroll one page up/down */
vScrollPageUpDown(bc->belvuAlignment, up);
}
return TRUE;
}
static gboolean onKeyPressCommaPeriod(BelvuContext *bc, const gboolean comma, const gboolean ctrl, const gboolean shift)
{
if (ctrl)
{
if (shift) /* scroll to very start/end */
hScrollStartEnd(bc->belvuAlignment, comma);
else
hScrollPageLeftRight(bc->belvuAlignment, comma); /* Scroll left/right by one page */
}
else
{
/* Scroll left/right by one character */
hScrollLeftRight(bc->belvuAlignment, comma, 1);
}
return TRUE;
}
static gboolean onKeyPressInsDel(BelvuContext *bc, const gboolean insert, const gboolean ctrl, const gboolean shift)
{
/* Scroll to the leftmost/rightmost extent of the display */
hScrollStartEnd(bc->belvuAlignment, insert);
return TRUE;
}
static gboolean onKeyPressPlusMinus(BelvuContext *bc, const gboolean plus, const gboolean ctrl, const gboolean shift)
{
/* Zoom in/out */
if (plus)
incrementFontSize(bc);
else
decrementFontSize(bc);
return TRUE;
}
/***********************************************************
* Events *
***********************************************************/
/* Key press handler */
gboolean onKeyPressBelvu(GtkWidget *window, GdkEventKey *event, gpointer data)
{
gboolean handled = FALSE;
BelvuContext *bc = (BelvuContext*)data;
const gboolean ctrl = (event->state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK;
const gboolean shift = (event->state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK;
switch (event->keyval)
{
case GDK_Escape: handled = onKeyPressEscape(bc); break;
case GDK_Home: handled = onKeyPressHomeEnd(bc, TRUE, ctrl, shift); break;
case GDK_End: handled = onKeyPressHomeEnd(bc, FALSE, ctrl, shift); break;
case GDK_Page_Up: handled = onKeyPressPageUpDown(bc, TRUE, ctrl, shift); break;
case GDK_Page_Down: handled = onKeyPressPageUpDown(bc, FALSE, ctrl, shift); break;
case GDK_Left: handled = onKeyPressLeftRight(bc, TRUE, ctrl, shift); break;
case GDK_Right: handled = onKeyPressLeftRight(bc, FALSE, ctrl, shift); break;
case GDK_Up: handled = onKeyPressUpDown(bc, TRUE, ctrl, shift); break;
case GDK_Down: handled = onKeyPressUpDown(bc, FALSE, ctrl, shift); break;
case GDK_less: /* fall through */
case GDK_comma: handled = onKeyPressCommaPeriod(bc, TRUE, ctrl, shift); break;
case GDK_greater: /* fall through */
case GDK_period: handled = onKeyPressCommaPeriod(bc, FALSE, ctrl, shift); break;
case GDK_Insert: handled = onKeyPressInsDel(bc, TRUE, ctrl, shift); break;
case GDK_Delete: handled = onKeyPressInsDel(bc, FALSE, ctrl, shift); break;
case GDK_plus: /* fall through */
case GDK_equal: handled = onKeyPressPlusMinus(bc, TRUE, ctrl, shift); break;
case GDK_minus: /* fall through */
case GDK_underscore: handled = onKeyPressPlusMinus(bc, FALSE, ctrl, shift); break;
default: break;
};
return handled;
}
/* Mouse button handler */
gboolean onButtonPressBelvu(GtkWidget *window, GdkEventButton *event, gpointer data)
{
gboolean handled = FALSE;
if (event->type == GDK_BUTTON_PRESS && event->button == 3) /* right click */
{
/* For the main window, if we're removing sequences, then just cancel that mode.
* Otherwise (and for any other window type) show the context menu. */
if (stringsEqual(gtk_widget_get_name(window), MAIN_BELVU_WINDOW_NAME, TRUE))
{
BelvuWindowProperties *properties = belvuWindowGetProperties(window);
if (properties->bc->removingSeqs)
{
setToggleMenuStatus(properties->actionGroup, "rmMany", !properties->bc->removingSeqs);
handled = TRUE;
}
}
if (!handled)
{
GtkMenu *contextMenu = GTK_MENU(data);
gtk_menu_popup (contextMenu, NULL, NULL, NULL, NULL, event->button, event->time);
handled = TRUE;
}
}
return handled;
}
/***********************************************************
* Initialisation *
***********************************************************/
static GtkWidget* createFeedbackBox(GtkToolbar *toolbar)
{
/* Bit of a hack, but add some space before the feedback box, just
* to avoid the toolbar being too cluttered. */
addToolbarWidget(toolbar, gtk_label_new(" "), -1);
GtkWidget *feedbackBox = gtk_entry_new();
/* User can copy text out but not edit contents */
gtk_editable_set_editable(GTK_EDITABLE(feedbackBox), FALSE);
GtkToolItem *item = addToolbarWidget(toolbar, feedbackBox, -1);
gtk_tool_item_set_expand(item, TRUE);
/* We want the box to be printed, so connect the expose function that will
* draw to a pixmap for printing */
g_signal_connect(G_OBJECT(feedbackBox), "expose-event", G_CALLBACK(onExposePrintable), NULL);
return feedbackBox;
}
/* Set various properties for the main belvu window components */
static void setStyleProperties(GtkWidget *window, GtkToolbar *toolbar)
{
/* Set the initial window size based on some fraction of the screen size */
int width = 300, height = 200;
gbtools::GUIGetTrueMonitorSizeFraction(window, DEFAULT_BELVU_WINDOW_WIDTH_FRACTION, DEFAULT_BELVU_WINDOW_HEIGHT_FRACTION,
&width, &height);
gtk_window_set_default_size(GTK_WINDOW(window), width, height);
gtk_container_set_border_width (GTK_CONTAINER(window), DEFAULT_WINDOW_BORDER_WIDTH);
gtk_window_set_mnemonic_modifier(GTK_WINDOW(window), GDK_MOD1_MASK); /* MOD1 is ALT on most systems */
/* Set toolbar style properties */
gtk_toolbar_set_style(toolbar, GTK_TOOLBAR_ICONS);
gtk_toolbar_set_icon_size(toolbar, GTK_ICON_SIZE_SMALL_TOOLBAR);
}
gboolean createBelvuWindow(BelvuContext *bc, BlxMessageData *msgData)
{
gboolean ok = TRUE;
GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_widget_set_name(window, MAIN_BELVU_WINDOW_NAME);
/* Set a pointer to the main window in the context */
bc->belvuWindow = window;
/* Set the title */
char *title = g_strdup_printf("%s%s", belvuGetTitlePrefix(bc), bc->Title);
gtk_window_set_title(GTK_WINDOW(window), title);
g_free(title);
/* Create the status bar */
GtkWidget *statusBar = gtk_statusbar_new();
gtk_statusbar_set_has_resize_grip(GTK_STATUSBAR(statusBar), TRUE);
setStatusBarShadowStyle(statusBar, "GTK_SHADOW_NONE");
gtk_statusbar_set_has_resize_grip(GTK_STATUSBAR(statusBar), FALSE);
/* Set the window and statusbar in the message handler data, now that we know them */
msgData->parent = GTK_WINDOW(window);
msgData->statusBar = GTK_STATUSBAR(statusBar);
/* Create the menu and toolbar */
GtkActionGroup *actionGroup = NULL;
GtkUIManager *uiManager = createUiManager(window, bc, &actionGroup);
GtkWidget *menubar = createBelvuMenu(window, "/MenuBar", uiManager);
GtkWidget *contextmenu = createBelvuMenu(window, "/ContextMenu", uiManager);
GtkWidget *toolbar = createBelvuMenu(window, "/Toolbar", uiManager);
addToolbarWidget(GTK_TOOLBAR(toolbar), gtk_label_new(" "), 0); /* hacky way to add some space at start of toolbar */
/* Create the feedback box on the toolbar */
GtkWidget *feedbackBox = createFeedbackBox(GTK_TOOLBAR(toolbar));
/* Set the style properties */
setStyleProperties(window, GTK_TOOLBAR(toolbar));
/* Create the alignment section. Store it in the context so that we can update it. */
bc->belvuAlignment = createBelvuAlignment(bc, NULL, UNSET_INT);
/* We'll put everything in a vbox */
GtkWidget *vbox = gtk_vbox_new(FALSE, 0);
gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(vbox));
/* Put the menu and toolbar on the same row using an hbox */
GtkWidget *hbox = gtk_hbox_new(FALSE, 0);
gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(hbox), menubar, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(hbox), toolbar, TRUE, TRUE, 0);
gtk_box_pack_start(GTK_BOX(vbox), bc->belvuAlignment, TRUE, TRUE, 0);
gtk_box_pack_start(GTK_BOX(vbox), statusBar, FALSE, FALSE, 0);
/* Connect signals */
gtk_widget_add_events(window, GDK_BUTTON_PRESS_MASK);
gtk_widget_add_events(window, GDK_KEY_PRESS_MASK);
g_signal_connect(G_OBJECT(window), "button-press-event", G_CALLBACK(onButtonPressBelvu), contextmenu);
g_signal_connect(G_OBJECT(window), "key-press-event", G_CALLBACK(onKeyPressBelvu), bc);
belvuWindowCreateProperties(window, bc, statusBar, feedbackBox, actionGroup);
/* Set the default cursor (can only get the window's cursor after window is shown) */
bc->defaultCursor = NULL;
/* Show the main window (unless we only want the tree) */
if (!bc->onlyTree)
gtk_widget_show_all(window);
/* If the BELVU_FONT_SIZE environment variable is set, we'll use it to set the
* default font size for all the widgets. */
const gchar *env = g_getenv(FONT_SIZE_ENV_VAR);
if (env)
{
if (bc->belvuWindow)
widgetSetFontSizeAndCheck(bc->belvuWindow, convertStringToInt(env));
if (bc->belvuTree)
widgetSetFontSizeAndCheck(bc->belvuTree, convertStringToInt(env));
}
env = g_getenv(STATUSBAR_SIZE_ENV_VAR);
if (env)
{
const int height = convertStringToInt(env);
/* If too small, hide the statusbar */
if (height < MIN_FONT_SIZE)
gtk_widget_hide_all(statusBar);
else
widgetSetFontSizeAndCheck(statusBar, height);
}
/* Make sure the alignment font size isup to date. Note: do this before
* creating the tree, because the tree flushes all pending gtk calls and
* we must update the font size before the alignment is realised. */
onBelvuAlignmentFontSizeChanged(bc->belvuAlignment);
/* Show the tree on startup, if requested */
if (bc->initTree)
{
createAndShowBelvuTree(bc, TRUE);
onBelvuTreeFontSizeChanged(bc->belvuTree);
}
if (!bc->onlyTree)
{
gtk_window_present(GTK_WINDOW(window));
if (bc->sortType)
setRadioMenuStatus(actionGroup, "unsorted", bc->sortType);
setToggleMenuStatus(actionGroup, "displayColors", bc->displayColors);
if (bc->schemeType == BELVU_SCHEME_TYPE_RESIDUE)
setRadioMenuStatus(actionGroup, "colorSchemeStandard", bc->residueScheme);
else
setRadioMenuStatus(actionGroup, "colorSchemeStandard", bc->consScheme);
if (bc->initTree)
belvuAlignmentRedrawAll(bc->belvuAlignment); /* redraw, because tree creation removes markup which can mess this up */
}
return ok;
}
|