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
|
package Bio::GMOD::Bulkfiles::FeatureWriter;
use strict;
=head1 NAME
Bio::GMOD::Bulkfiles::FeatureWriter ; was ChadoFeatDump
=head1 SYNOPSIS
use Bio::GMOD::Bulkfiles;
my $sequtil= Bio::GMOD::Bulkfiles->new( # was SeqUtil2
configfile => 'seqdump-r4',
);
my $fwriter= $sequtil->getFeatureWriter();
## was Bio::GMOD::ChadoFeatDump->new( configfile => 'chadofeatdump', sequtil => $sequtil );
my $result= $fwriter->makeFiles(
infiles => [ @$seqfiles, @$chrfeats ], # required
formats => [ qw(fff gff fasta)] , # optional
);
=head1 NOTES
genomic sequence file utilities, part3;
parts from
flybase/work.local/chado_r3_2_26/soft/chadosql2flatfeat.pl
=head1 AUTHOR
D.G. Gilbert, 2004, gilbertd@indiana.edu
=head1 METHODS
=cut
#-----------------
# debug
#use lib("/bio/biodb/common/perl/lib", "/bio/biodb/common/system-local/perl/lib");
use POSIX;
use FileHandle;
use File::Spec::Functions qw/ catdir catfile /;
use File::Basename;
use Bio::GMOD::Bulkfiles::BulkWriter;
use base qw(Bio::GMOD::Bulkfiles::BulkWriter);
our $DEBUG = 0;
my $VERSION = "1.1";
use constant BULK_TYPE => 'fff+gff';#??
use constant CONFIG_FILE => 'chadofeatdump';
## !! change these from our to use vars() for package scope
our $maxout = 0;
our $ntotalout= 0;
our $chromosome= {}; ## read info from chado dump chromosomes.tsv
our $fff_mergecols=1; # $self->{fff_mergecols} add chr,start cols for merge
our $gff_keepoids= 0; # $self->{gff_keepoids}
our @outformats= ();
our @defaultformats= qw(fff gff); # cmap ?? fasta - no
our %formatOk= ( fff => 1, gff => 1 ); # only these handled here ?
our @fclone_fields = qw(chr type fulltype name id oid fmin fmax offloc attr writefff writegff);
our $outfile= undef; # "chadofeat"; ## replace w/ get_filename !
our $append=0; # $self->{append} #?? is this used?
our %gffForwards=();
our @gffForwards=();
use constant TOP_SORT => -9999999;
use constant MAX_FORWARD_RANGE => 990000; # at 500000 lost a handful of oidobs refs; maximum base length allowed for collecting forward refs
use constant MIN_FORWARD_RANGE => 20000; # minimum base length for collecting forward refs
## our == global scope; use vars == package scope
use vars qw/
%maptype
%maptype_pattern
%mapname_pattern
%mapattr_pattern
%maptype_gff
%segmentfeats
%simplefeat
%skipaskid
%dropfeat_fff
%dropfeat_gff %oidisid_gff
%dropid %nameisid
%dropname
%mergematch
%hasdups
%keepstrand
$rename_child_type
$name2type_pattern
@GModelParts
%GModelParents
$CDS_spanType
$CDS_exonType
/;
## $duptype_pattern
sub init
{
my $self= shift;
$self->SUPER::init();
$self->{outh} = {};
## superclass does these??
$DEBUG= $self->{debug} if defined $self->{debug};
# $self->{bulktype} = $self->BULK_TYPE; # dont need hash val?
# $self->{configfile}= $self->CONFIG_FILE unless defined $self->{configfile};
$self->setDefaultValues(); #?? use or not? hold-over from pre-config work
}
=item initData
initialize data from config
=cut
sub initData
{
my($self)= @_;
$self->SUPER::initData();
my $config = $self->{config};
my $sconfig= $self->handler_config;
## SUPER does now
#$config->{idpattern} = $self->getconfig('idpattern') || '';
#$config->{intronpatch} = $self->getconfig('intronpatch') || '';
#$config->{utrpatch} = $self->getconfig('utrpatch') || '';
#$config->{gmodel_parts_rename} = $self->getconfig('gmodel_parts_rename') || '';
#$config->{ignore_missingparent} = $self->getconfig('maptype_ignore_missingparent') || '';
## should get this from $sconfig->{fileset}->{gff}->{noforwards}
my $gffinfo= $self->handler()->getFilesetInfo('gff');
$gffinfo->{GFF_source} = $sconfig->{GFF_source} if( $sconfig->{GFF_source});
$self->{gff_config}= $gffinfo;
$config->{noforwards} = ($gffinfo && defined $gffinfo->{noforwards})
? $gffinfo->{noforwards}
: $config->{noforwards_gff};
@outformats= @{ $config->{outformats} || \@defaultformats } ;
$self->{outputlist}= [];
$fff_mergecols= (defined $config->{fff_mergecols} && $config->{fff_mergecols}) || 1; ## add chr,start cols for merge
$gff_keepoids = (defined $config->{gff_keepoids} && $config->{gff_keepoids}) || 0;
# @csomes= @{ $config->{chromosomes} } if (ref $config->{chromosomes});
if (ref $config->{chromosome}) {
$chromosome= $config->{chromosome};
}
else {
$chromosome= $self->handler()->getChromosomeTable();
$config->{chromosome}= $chromosome;
}
$rename_child_type= $config->{rename_child_type} if ($config->{rename_child_type});
$name2type_pattern= $config->{name2type_pattern};
## $duptype_pattern = $config->{duptype_pattern};
%maptype = %{ $config->{'maptype'} } if ref $config->{'maptype'};
%maptype_pattern= %{ $config->{'maptype_pattern'} } if ref $config->{'maptype_pattern'};
%mapname_pattern= %{ $config->{'mapname_pattern'} } if ref $config->{'mapname_pattern'};
%mapattr_pattern= %{ $config->{'mapattr_pattern'} } if ref $config->{'mapattr_pattern'};
%maptype_gff = %{ $config->{'maptype_gff'} } if ref $config->{'maptype_gff'};
%segmentfeats = %{ $config->{'segmentfeats'} } if ref $config->{'segmentfeats'};
%simplefeat = %{ $config->{'simplefeat'} } if ref $config->{'simplefeat'};
%skipaskid = %{ $config->{'skipaskid'} } if ref $config->{'skipaskid'};
%dropfeat_fff = %{ $config->{'dropfeat_fff'} } if ref $config->{'dropfeat_fff'};
%dropfeat_gff = %{ $config->{'dropfeat_gff'} } if ref $config->{'dropfeat_gff'};
%dropid = %{ $config->{'dropid'} } if ref $config->{'dropid'};
%nameisid = %{ $config->{'nameisid'} } if ref $config->{'nameisid'};
%dropname = %{ $config->{'dropname'} } if ref $config->{'dropname'};
%mergematch = %{ $config->{'mergematch'} } if ref $config->{'mergematch'};
%hasdups = %{ $config->{'hasdups'} } if ref $config->{'hasdups'};
%keepstrand = %{ $config->{'keepstrand'} } if ref $config->{'keepstrand'};
%oidisid_gff = %{ $config->{'oidisid_gff'} } if ref $config->{'oidisid_gff'};
my $gmp= $config->{'GModelParts'} || 'CDS five_prime_UTR three_prime_UTR intron';
@GModelParts= (ref $gmp) ? @$gmp : split(/[,\s]+/,$gmp);
#@GModelParts = qw( CDS five_prime_UTR three_prime_UTR intron );
#@GModelParts = @{ $config->{'GModelParts'} } if ref $config->{'GModelParts'};
## jan06: replace CDS/CDS_exon with protein/CDS ... per GFFv3 usage
## fly chado uses 'protein' for mRNA equivalent feature (start,stop) of cds
## and same exons for mRNA and protein
$gmp= $config->{'GModelParents'} || 'mRNA';
%GModelParents = map { $_, 1; } ((ref $gmp) ? @$gmp : split(/[,\s]+/,$gmp));
$CDS_spanType= $config->{'CDS_spanType'} || 'CDS'; # change to 'protein' or other ...
$CDS_exonType= $config->{'CDS_exonType'} || 'CDS_exon';# change back to CDS
push(@GModelParts,$CDS_spanType) unless(grep(/$CDS_spanType/,@GModelParts));
#? require segmentfeats be simplefeat ?
map { $simplefeat{$_}=1; } keys %segmentfeats;
delete $simplefeat{'gene'}; # dont make this mistake
delete $simplefeat{'mRNA'}; #
## merge config from this INTO handler config ?
## that is best place to keep common <featmap> and <featset>
## ? move this out of here; use separate featmap/featset include file?
my $fset= $config->{featset};
if (ref $fset && !$sconfig->{featset}) {
$sconfig->{featset}= $fset;
}
my $fmap= $config->{featmap};
if (ref $fmap) {
my $smap= $sconfig->{featmap};
unless(ref $smap) { $sconfig->{featmap}= $smap= {}; }
my @keys= keys %$fmap;
foreach my $k (@keys) { $smap->{$k}= $fmap->{$k} unless defined $smap->{$k}; }
}
# $fff_mergecols=1; # add chr,start cols for merge
# $gff_keepoids= 0; #$DEBUG; #?
}
#-------------- subs -------------
=item makeFiles( %args )
primary method
makes bulk genome sequence files in standard formats.
input file sets are intermediate chado db dump tables.
arguments:
infiles => \@fileset, # required
formats => [ 'gff', 'fff' ] # optional
=cut
sub makeFiles
{
my $self= shift;
my %args= @_;
my $fileset = $args{infiles};
my $chromosomes = $args{chromosomes};
my $intype= $self->config->{informat} || 'feature_table'; #? maybe array
# 0710: no_csomesplit : no perchr files, only makeall
my $no_csomesplit= $self->handler_config->{no_csomesplit} || 0; # FIXME: 0710
my $makeall= !$no_csomesplit && !$args{noall} && ($self->config->{makeall} || $self->{gff_config}->{makeall});
$self->{append}=1 if($no_csomesplit); #?????? TEST ME
unless(@$fileset) {
$fileset = $self->handler->getFiles($intype, $chromosomes);
unless(@$fileset) {
warn "FeatureWriter: no input '$intype' files found\n";
return $self->status(-1);
}
}
my @saveformats= @outformats;
## this may be a mistake: config formats are what we need to make(?)
## args{formats} are what caller/customer wants as result
if ($args{formats}) {
my $formats= $args{formats};
if(ref $formats) { @outformats= @$formats; }
else { @outformats=($formats); }
}
@outformats= grep { $formatOk{$_}; } @outformats;
print STDERR "FeatureWriter::makeFiles outformats= @outformats\n" if $DEBUG;
my $status= 0;
my $ok= 1;
for (my $ipart= 0; $ok; $ipart++) {
$ok= 0;
my $inh= $self->openInput($fileset, $ipart);
if ($inh) {
my $res= $self->processChadoTable( $inh);
close($inh);
$status += $res;
$ok= 1;
}
}
if ($makeall && $status > 0) {
foreach my $fmt (@outformats) {
$self->makeall( $chromosomes, "", $fmt) unless ($fmt eq 'fff');
}
}
@outformats = @saveformats;
print STDERR "FeatureWriter::makeFiles: done n=$status\n" if $DEBUG;
return $self->status($status); #?? check files made
}
## just now can do only for gff; leave fff split by chr
sub makeall
{
my $self= shift;
my( $chromosomes, $feature, $format )= @_;
return if ($format eq 'fff');
$feature= "";
$self->{curformat}= $format;
$self->config->{path}= $format; #???? # setconfig ??
print STDERR "makeall: $format\n" if $DEBUG;
$self->SUPER::makeall($chromosomes, $feature, $format); #?? not seen
$self->{curformat}= '';
$self->config->{path}= ''; #???? # setconfig ??
# my $outdir= $self->outputpath();
# $chromosomes= $self->handler()->getChromosomes() unless (ref $chromosomes);
#
# ## this loop can be common to other writers: makeall( $chromosomes, $feature, $format) ...
# my $allfn= $self->get_filename ( $self->{org}, 'all', $feature, $self->{rel}, $format);
# $allfn= catfile( $outdir, $allfn);
#
# my @parts=();
# foreach my $chr (@$chromosomes) {
# next if ('all' eq $chr);
# my $fn= $self->get_filename ( $self->{org}, $chr, $feature, $self->{rel}, $format);
# $fn= catfile( $outdir, $fn);
# next unless (-e $fn);
# push(@parts, $fn);
# }
#
# if (@parts) {
# unlink $allfn if -e $allfn; # dont append existing
# my $allfh= new FileHandle(">$allfn"); ## DONT open-append
# foreach my $fn (@parts) {
# my $fh= new FileHandle("$fn");
# while (<$fh>) { print $allfh $_; }
# close($fh);
# unlink $fn if (defined $self->config->{perchr} && $self->config->{perchr} == 0);
# }
# close($allfh);
# }
}
=item openInput( $fileset, $ipart )
handle input files
=cut
sub openInput
{
my $self= shift;
my( $fileset, $ipart )= @_; # do per-csome/name
my $inh= undef;
return undef unless(ref $fileset);
my $intype= $self->config->{informat} || 'feature_table'; #? maybe array
my $atpart= 0;
# print STDERR "openInput: type=$intype part=$ipart \n" if $DEBUG;
foreach my $fs (@$fileset) {
my $fp= $fs->{path};
my $name= $fs->{name};
my $type= $fs->{type};
next unless($fs->{type} eq $intype);
unless(-e $fp) { warn "missing dumpfile $fp"; next; }
$atpart++;
next unless($atpart > $ipart);
print STDERR "openInput[$ipart]: name=$name, type=$type, $fp\n" if $DEBUG;
if ($fp =~ m/\.(gz|Z)$/) { open(INF,"gunzip -c $fp|"); }
else { open(INF,"$fp"); }
$inh= *INF;
## want option to ignore file date, use config date ??
##my $ftime= $^T - 24*60*60*(-M $fp);
## $self->{date}= POSIX::strftime("%d-%B-%Y", localtime( $ftime ));
my ($sfile, undef) = File::Basename::fileparse($fp);
$self->{sourcefile}= $sfile;
return $inh; # only 1 at a time FIXME ...
}
print STDERR "openInput: nothing matches part=$ipart, type=$intype\n" if $DEBUG;
return undef;
}
=item openCloseOutput($outh,$chr,$flags)
handle output files
=cut
sub openCloseOutput
{
my $self= shift;
my($outh,$chr,$flags)= @_;
my $chrfile= $chr;
my $app= defined $self->{append} ? $self->{append} : $append;
# 0710: no_csomesplit : no perchr files, only makeall
my $no_csomesplit= $self->handler_config->{no_csomesplit} || 0; # FIXME: 0710
if( $no_csomesplit ) {
$app= 1;
$chrfile="all"; # or "sum" ??
}
if ($outh && $flags =~ /open|close/) {
foreach my $fmt (@outformats) {
close($outh->{$fmt}) if ($outh->{$fmt});
}
}
$outh= {};
if ($flags =~ /open/) {
$chrfile='undef' unless($chrfile);
#?? for unsorted input need to change $append to true after first open?
foreach my $fmt (@outformats) {
next if ($fmt eq "dummy"); # dang bug w/ config xml
my $suffix= $fmt;
my $subdir= $fmt;
my $outset= $self->{fileset}{$fmt}; #= $self->handler->getFilesetInfo($fmt);
if($outset) {
$subdir= $outset->{path} || $subdir;
$suffix= $outset->{suffix} || $suffix;
}
## need option to append or create !?
my $ap=($app) ? ">>" : ">";
my $fn;
if ($outfile) { $fn="$outfile-$chrfile.$suffix"; }
else { $fn= $self->get_filename( $self->{org}, $chrfile, '', $self->{rel}, $suffix); }
my $featdir= $self->handler()->getReleaseSubdir( $subdir);
my $fpath = catfile( $featdir, $fn);
push( @{$self->{outputlist}}, $fpath); #? or save as hash w/ $fmt;...
my $exists= ($app && -e $fpath) ? 1 : 0;
print STDERR "# output $fpath (append=$exists)\n" if $DEBUG;
$outh->{$fmt}= new FileHandle("$ap$fpath");
$self->writeHeader($outh,$fmt,$chr,$exists);
}
}
return $outh;
}
=item remapXXX
processChadoTable handlers to fix various table inputs, according to config mappings
=cut
sub remapId
{
my $self= shift;
my ($type,$id,$name)= @_;
my $save= $id;
if (($nameisid{$type}) && $name) { $id= $name; } ## ? not for gff
elsif ($dropid{$type} || $id =~ /^NULL:/ || $id =~ /^:\d+/) { $id= undef; }
#?? or not# elsif (!$id) { $id= $name; }
return ($id,$save);
}
sub remapName
{
my $self= shift;
my ($type,$name,$id,$fulltype)= @_;
my $save= $name;
if ( $dropname{$type} ) { $name= ''; }
## handle stupid match name = all the match type + ...
#elsif ($type eq 'transposable_element_pred') { $name =~ s/JOSHTRANSPOSON-//; }
## clean unwieldy predictor names: contig...contig...
elsif ($type =~ /^(gene|mRNA)/ && $name =~ s/Contig[_\d]+//g) {
##if ($name =~ m/^(twinscan|genewise|genscan)/i) { $name= "${id}_${name}"; }
if ($name =~ m/^(twinscan|genewise|genscan|piecegenie)/i) { $name= "${id}_$1"; }
}
elsif (!$name) { $name= $id unless ($id =~ /^NULL:/i || $id =~ /^:\d+/); }
## dmelr4.1 ; must apply below name patches to id (no name)
## this one could be time sink .. use evaled sub {} ?
foreach my $mp (sort keys %mapname_pattern) {
next if ($mp eq 'null'); # dummy?
my $mtype= $mapname_pattern{$mp}->{type};
next if ($mtype && $type !~ m/$mtype/);
if ($mapname_pattern{$mp}->{cuttype}) {
my @tparts= split(/[_:.-]/, $type);
push(@tparts, split(/[_:.-]/, $fulltype) ); #??
foreach my $t (@tparts) { $name =~ s/\W?$t\W?//; }
next;
}
my $from= $mapname_pattern{$mp}->{from}; next unless($from);
my $to = $mapname_pattern{$mp}->{to};
if ($to =~ /\$/) { $name =~ s/$from/eval($to)/e; }
else { $name =~ s/$from/$to/g; }
}
return ($name,$save);
}
=item remapArm
2 3 segment Contig3266_Contig6542 - complement(3..1555441) Contig3266_Contig654
2
2 1555569 segment Contig143_Contig447 - complement(1555569..2614209) Contig143_Contig447
-- unordered contigs -- singles (? no feats) and doubles - put into common out files?
-- if so, need to offset start/end to fit into unorderd 'chromosome'
Contig1090 1 contig - - 1..211 Contig1090 GB:AADE01008166;
Contig2258_Contig2260 1 contig - - 1..3082 Contig2258 GB:AADE01005006;
# Double Dang - need to use segment offset/strand to map segment features
=cut
sub remapArm
{
my $self= shift;
my ($arm,$fmin,$fmax,$strand)= @_;
my $save= $arm;
my $armfile= $arm;
# my $rf= $armContigs{$arm};
# if ($rf) {
# my($armr,$b,$e,$st,$contig)= @$rf;
# $arm= $armr;
# if ($st eq '-') { #?? do we need to flip all - min,max relative to arm.e ?
# $strand= -$strand;
# ($fmax,$fmin) = ($e - $fmin-1, $e - $fmax-1);
# }
# else {
# $fmin += $b - 1;
# $fmax += $b - 1;
# }
# }
# $armfile=$arm;
#
# ## need to fix dmel synteny.dump to not put gene name => arm for ortho:nnn
# if ($arm eq $save) {
# if (lc($org) eq 'dmel' && $arm =~ m/\-/) { # -PA .. others -xxx ?
# $armfile= 'genes';
# }
# elsif ($arm =~ m/^Contig[^_]+_Contig/) {
# $armfile= 'unordered2';
# }
# elsif ($arm =~ m/^Contig\w+/) {
# $armfile= 'unordered1';
# }
# }
return($arm,$fmin,$fmax,$strand,$armfile,$save)
}
sub readArmContigs
{
my $self= shift;
my ($gffh)= @_;
# unless($gffh) { warn "cant read arm contigs"; return; }
# while(<$gffh>){
# next unless(/^\w/);
# my($arm,$x0,$type,$b,$e,$x1,$st,$x2,$attr)= split;
# if($type eq 'segment' || $type eq 'golden_path' ||$type eq 'golden_path_region') { # golden_path_region in sql dump
# my $contig = ($attr=~m/(Name|dbID)=(\w+)/) ? $2 : '';
# $armContigs{$contig}= [$arm,$b,$e,$st,$contig];
# }
# }
}
=item remapType
Types from name ... only when needed
Dpse uses gene name_(genscan|genewise|twinscan) ...
Dmel uses mRNA name-(genscan|piecegenie) ...
?? anything with '-dummy-' in name is computed type?
for Dpse which has gene ..., need to reType mRNA kids also
mRNA 13903,12560-AE003590.Sept-dummy-piecegenie
mRNA 15793,12560-AE003590.Sept-dummy-genscan
transposable_element Name=JOSHTRANSPOSON-jockey{}277-pred
transposable_element DBID=TE19092;Name=jockey{}277;cyto_range=21A3-21A3;Dbxref="FlyBase:FBti0019092";Dbxref="Gadfly:TE19092";gbunit=AE003590
Handle more complex types
change this to allow complex type:subtype:.. for analysis, other features
with pseudo-type like 'match:program:source'
want final gff-type/source 'match',fgenesh{_source} or fgenesh:source
want final fff-type match_fgenesh{_source} or match:fgenesh{_source} ?
check how both gbrowse_fb and gnomap read/handle types
gnomap/annomap -- underscores generally used but '.' also
## remap FBan.acode PRG:DB choices
blastx_masked_aa_SPTR.worm=blastx_otherspp
blastx_masked_aa_SP.hyp.dros=blastx_dros
sim4_na_EST.all_nr.dros=EST
genscan_dummy=genscan
=cut
sub remapType
{
my $self= shift;
my ($type,$name)= @_;
my $save= $type;
$type =~ s/\s/_/g; # must change?
## this one could be time sink .. use evaled sub {} ?
foreach my $mp (keys %maptype_pattern) {
next if ($mp eq 'null');
my $mname= $maptype_pattern{$mp}->{typename};
next if ($mname && $name !~ m/$mname/);
my $from= $maptype_pattern{$mp}->{from};
my $to = $maptype_pattern{$mp}->{to};
$type =~ s/$from/$to/;
}
my $nutype = $type;
# this should be config pattern: ..genscan..
##if (defined $name && $name =~ m/[-_](genscan|piecegenie|twinscan|genewise|pred|trnascan)/i) {
if ($name2type_pattern && defined $name && $name =~ m/$name2type_pattern/i) {
$nutype .= "_".lc($1);
}
$nutype =~ s/[:\.]/_/g; #?
$type = $maptype{$nutype} || $type;
my $fulltype = $type; #?? here or what.
$type =~ s/[:\.]/_/g; #?
return ($type,$fulltype,$save);
}
=item processChadoTable
Read input feature table, write bulk output formats FFF and GFF
(other formats are derived from these)
This step takes longest, e.g. ~ 20 hr on single cpu for D. melangaster.
Split by chromosome data among processors to speed up.
Joins table lines/feature; builds compound features; checks feature names/types, etc.
Input chado feature table dump format (see sql)
arm fmin fmax strand type name id oid attr_type attribute
2L 0 305900 1 golden_path AE003590 AE003590 1273141 various_key value
Outputs: FFF (also used for fasta, gnomap), GFF
FIXME: something here gets very memory piggy, slow, with input feature tables
full of match: analysis types (messy names, types, etc.)
-- no feats written to fff in many hours !? - due to holding BAC and cytoband features
-- try dropping gffForwards; maybe better (gff written) but still memuse balloons
-- added clearFinishedObs() - no apparent help; dont see what else is holding objects here
-- ok now, added min base loc to keep in oidobs, delete all before
runs fast - chr 3L in 10 min. instead of >2hr.
=cut
use constant LINEBUF_SIZE => 2000; # for forward refs
sub getline {
my $self= shift;
my($fh)= @_;
my $n= scalar( @{$self->{linebuf}} );
while (<$fh>) {
next unless(/^\w/);
next if(/^arm\tfmin/); # header from sql out
chomp;
push @{$self->{linebuf}}, $_;
$n++;
last if ($n >= LINEBUF_SIZE);
}
my $fin= shift @{$self->{linebuf}};
return $fin;
}
sub popline {
my $self= shift;
my $fin = shift @{$self->{linebuf}};
return $fin;
}
sub peekline {
my $self= shift;
my($n)= @_;
$n= 0 unless($n);
my $fin= ${$self->{linebuf}}[$n];
return $fin;
}
sub grepline {
my $self= shift;
my($patt)= @_;
my $grep= grep /$patt/, @{$self->{linebuf}};
return $grep;
}
sub hasObForwards {
my $self= shift;
my($fobs,$oidobs)= @_;
foreach my $fob (@$fobs) {
my $oid= $fob->{oid};
my $paroid= $fob->{paroid}; # may be one of many ! need $oidobs->{parent}
my $ftype= $fob->{type};
# my $issimple= $simplefeat{$ftype};
next unless($paroid || $ftype =~ m/^(mRNA|gene)$/); # add CDS ? or do any types w/ paroid?
#my $hasfor= grepline("\b$oid\b"); # mainly looking for attrib: parent_oid\t$oid
my $hasfor= $self->grepline("parent_oid\t".$oid);
my $isfor= 0;
# if ($DEBUG && $hasfor) {
# # my @val= grep /parent_oid\t$oid/, @{$self->{linebuf}};
# print STDERR "hasForward: $ftype, ",$fob->{name},", $oid\n>","\n"; #join("\n>",@val),"\n";
# }
## ? need reverse: if fob has parent_oid, grep for its object_oid ?
unless($hasfor) {
$isfor= ($paroid && $self->grepline("\b$paroid\b"));
# if ($DEBUG && $isfor) {
# # my @val= grep /\b$paroid\b/, @{$self->{linebuf}};
# print STDERR "isForward: $ftype, ",$fob->{name},", par=$paroid\n>", "\n"; # ,join("\n>",@val),"\n";
# }
}
return 1 if ($hasfor || $isfor);
}
return 0;
}
sub newParentOid
{
my $self= shift;
my($fob,$attr_type,$attribute,$oidobs)= @_;
## my $paroid= $fob->{paroid};
##BAD-exon has many parents## return if($paroid);
# my $type= $fob->{type}; return if ($simplefeat{$type}); ## TEST before call
my $oid = $fob->{oid};
# do part of this when fob is created:
# >> add paroid->child and oid->{parent} refs
# defer any requirement for parent/child ob till putLink()
##my($attr_type,$attribute)= split "\t",$addattr;
if ($attribute && $attr_type eq 'parent_oid' ) {
my($paroid,$rank)= ($attribute, 0);
if ($paroid =~ s/:(.*)$//) { $rank=$1; } # dont need rank, but must drop from paroid
$fob->{paroid}= $paroid; ## replace OLD ok ??
## push( @{$fob->{attr}}, "rank\t$attribute"); # ? need this for exon, utr - but tied to parent_oid
## ? got dupl parent_oid for dpse genscan/twinscan genes only ?? screen here? -- gff output only?
## >> problem looks like oids are duplicated among gene/mRNA/CDS and the related genscan/genewise/twinscan/... objects
$oidobs->{$paroid}->{child}= [] unless (ref $oidobs->{$paroid}->{child});
push( @{$oidobs->{$paroid}->{child}}, $fob); ##? use $rank to position in {child} array ??
$oidobs->{$oid}->{parent}= [] unless (ref $oidobs->{$oid}->{parent});
push( @{$oidobs->{$oid}->{parent}}, $paroid);
}
}
## ???? for sgd gene->cds model; insert gene->mrna->cds/exon
sub add_mRNA
{
my $self= shift;
my($geneob,$oidobs)= @_;
my $geneoid = $geneob->{oid};
my $type= $geneob->{type};
my $make_mrna;
$make_mrna= $self->config->{feat_model}->{$type}->{make_mrna};
if ($make_mrna) {
# my $mrnaob= { %$geneob }; # shallow clone !
my $mrnaob= $self->cloneBase($geneob); # need locs
$mrnaob->{type}= 'mRNA';
# need new $oid; insert in $oidobs->{$oid}->{parent}; ..
$self->newParentOid( $mrnaob, 'parent_oid', $geneoid, $oidobs);
## and move kidobs from geneob to mrnaob ...
# $mrnaob->{paroid}= $geneoid;
# my @kids= @{$oidobs->{$geneoid}->{child}};
# push( @{$oidobs->{$geneoid}->{child}}, $mrnaob);
# push( @{$oidobs->{$oid}->{parent}}, $geneoid);
}
}
sub updateParentKidLinks
{
my $self= shift;
my($fobs,$oidobs)= @_;
foreach my $fob (@$fobs) {
$self->update1ParentKidLinks($fob,$oidobs);
}
}
sub update1ParentKidLinks
{
my $self= shift;
my($fob,$oidobs)= @_;
## my $paroid= $fob->{paroid}; ## FIXME: exons have many parent
return unless( $fob->{paroid} );
my $oid = $fob->{oid};
my $type= $fob->{type};
my $ignore_missingparent= $self->config->{maptype_ignore_missingparent} || '^xxxx';
foreach my $paroid ( @{$oidobs->{$oid}->{parent}} ) {
my $parob= $oidobs->{$paroid}->{fob};
unless($parob) {
warn "MISSING parent ob $paroid for $type:$oid\n"
unless ($type =~ /$ignore_missingparent/); # || $id =~ /GA\d/
# these match parts miss parent often: 'repeat|blast|genscan|sim4'
next; # return;
}
## another fixup for CDS/protein-of-mRNA feature set
## was bad - simplefeat included gene, pseudogene
## dang; now gene children:
# insertion, aberration_junction,regulatory_region,
# sequence_variant,rescue_fragment, enhancer, etc are missing
# -> only gone from fff, not gff
## <rename_child_type>pseudogene|\w+RNA</rename_child_type>
## sgdlite has this stuff :
## tRNA contain ncRNA; pseudogene contains CDS (sic!); no mRNA
if ($rename_child_type && $fob->{type} ne 'mRNA'
&& $fob->{type} =~ m/^($rename_child_type)/) {
# this is bad for real gene subfeatures like point_mutation
my $ptype= $fob->{type};
## feb05:
## this is causing problems for featuretype purists ; should leave 'gene' and subtype \w+RNA
## as is ?? but fix software to process right; use fulltype == orig; type = recoding ?
if ($parob && ( $parob->{type} eq 'gene' || $parob->{type} eq $ptype) ) {
##$parob->{fulltype}= $parob->{type}= $ptype;
##$fob->{fulltype}= $fob->{type}= 'mRNA';
$parob->{type}= $ptype;
$fob->{type}= 'mRNA';
}
# warn ">pse2: $arm,$fmin,".$parob->{type}."/".$fob->{type}.",$name,$oid,$l_oid\n" if $DEBUG;
}
if ($fob->{type} =~ m/^(mRNA|CDS)$/) {
## for genscan/twinscan etc mrna's - retype as parent gene_pred type
if ($parob->{type} =~ m/^gene([_:.-]\w+)/ ) {
$fob->{type} .= $1;
if ($parob->{fulltype} =~ m/^gene([_:.-]\w+)/ ) { $fob->{fulltype} .= $1; }
}
# copy gene id dbxref attr
# got gene ids to all mRNA; missing some in CDS; need to do CDS after mRNA
my $idpattern= $self->config->{idpattern};
foreach my $pidattr (@{$parob->{attr}}) {
next if ($pidattr =~ m/2nd/); #? dbxref_2nd:
if (!$idpattern || $pidattr =~ m/$idpattern/) { ## (FBgn|FBti)\d+
push( @{$fob->{attr}}, $pidattr) unless( grep {$pidattr eq $_} @{$fob->{attr}});
last; # add only 1st/primary
}
}
}
}
}
sub handleAttrib
{
my $self= shift;
my($addattr, $attr_type, $attribute, $fobadd)= @_;
# nasty fix for _Escape ; to_name=Aaa,CGid should probably be two table lines
if ($attr_type eq 'to_name' && $attribute =~ /,/) {
my $attr1; ($attr1,$attribute)= split(/,/,$attribute,2);
push( @$addattr, "$attr_type\t$attr1");
}
# chado-gff loader does odd thing like adding unwanted 'DB:' prefix;
# and dbxref=GFF_source:SGD
# elsif ($attr_type eq 'dbxref' && $attribute =~ /^DB:\w+:\w+/) {
# $attribute =~ s/^DB://;
# }
# elsif ($attr_type =~ /^dbxref/ && $attribute =~ /^FlyBase Annotation IDs/) {
# $attribute =~ s/FlyBase Annotation IDs/FBannot/;
# }
# elsif ($attr_type eq 'dbxref' && $attribute =~ /^GFF_source:(\S+)/) {
# if($fobadd) { $fobadd->{gffsource} = $1; }
# $attribute='';
# }
foreach my $mp (sort keys %mapattr_pattern) {
next if ($mp eq 'null'); # dummy
my $mtype= $mapattr_pattern{$mp}->{type};
next if ($mtype && $attr_type !~ m/$mtype/);
my $from= $mapattr_pattern{$mp}->{from}; next unless($from);
my $to = $mapattr_pattern{$mp}->{to};
if ($to =~ /\$/) { $attribute =~ s/$from/eval($to)/e; }
else { $attribute =~ s/$from/$to/g; }
}
if ($attr_type eq 'dbxref' && $attribute =~ /^GFF_source:(\S+)/) {
if($fobadd) { $fobadd->{gffsource} = $1; }
$attribute='';
}
push( @$addattr, "$attr_type\t$attribute") if $attribute;
}
sub processChadoTable
{
my $self= shift;
my($fh, $outh)= @_;
$outh= $self->{outh} unless(ref $outh);
my %origin_one= %{ $self->config->{origin_one} || {} };
my $utrpatch= $self->config->{utrpatch} ;
my $intronpatch= $self->config->{intronpatch} ;
# patch for intron type; oct04: fmin - no+1,fmax, add+1
my $nozombiechromosomes= $self->config->{nozombiechromosomes};
# dpse chado duplicate 0-length chromosome entries
my $tab= "\t"; # '[\|]'; ##"\t"; < '|' is bad sep cause some names have it !
my @fobs=();
my %oidobs=(); # this hash will grow big; can we delete before next chr ?
my $fob= undef;
my $max_max=0; my $min_max= 0;
my $armlen=0;
my $ndone= 0;
my ($l_arm,$l_oid,$l_fmin,$l_fmax,$l_type)= (0,0,0);
my ($arm,$fmin,$fmax,$strand,$type,$name,$id,$oid,$attr_type,$attribute) ;
my($s_type, $fulltype, $s_arm, $armfile, $s_name, $s_id);
my ($fin,$fhpeek);
my %addfob=();
#? use line buffer @fhpeek to grep for missing forward refs ? eg. PA for mRNA ?
$self->{linebuf}= [];
# while(<$fh>) {
# next unless(/^\w/);
# next if(/^arm\tfmin/); # header from sql out
# chomp;
# $fin=$_; }
while( $fin= $self->getline($fh) ) {
$_= $fin;
$ndone++;
my @addattr=();
## loop here over <$fh> while $oid == $l_oid
## only part changing is $attr_type/$attribute
my $sameoid= 0;
do {
($arm,$fmin,$fmax,$strand,$type,$name,$id,$oid,$attr_type,$attribute)
= split("\t",$fin);
$self->handleAttrib(\@addattr,$attr_type,$attribute,\%addfob) if ($attribute);
## inner read loop problem? need to process parent_oid attrib only once below
my $nextin= $self->peekline(0) || "";
my $joid= index($nextin,"$id\t$oid\t");
$sameoid= ($joid>0);
if ($sameoid) {
my $ioid= index($fin,"$id\t$oid\t");
$sameoid= ($ioid==$joid && substr($nextin,0,$ioid) eq substr($fin,0,$ioid) );
if ($sameoid) { $fin= $self->popline(); }
}
} while ($sameoid);
#my $tss= ($DEBUG && $type eq 'transcription_start_site');
#warn ">tss1: $arm,$fmin,$type,$name,$oid,$l_oid\n" if $tss;
## data fixes
## dpse chado has chromosomes of fmin=1; fmax = NULL ! no length; drop these (dupl)
if ($nozombiechromosomes && $segmentfeats{$type} && $fmax <= $fmin) {
($l_oid,$l_fmin)= (-1,$fmin);
next;
}
if( !defined $fmax ) { $fmax=0; }
if( !defined $fmin ) { $fmin=0; }
elsif ($intronpatch && $type eq 'intron') { $fmax += 1; }
elsif ($utrpatch && $type =~ /_prime_untranslated_region|_prime_UTR/) {
$fmin= $fmax if ($fmax == $fmin-1);
}
elsif( ! ($origin_one{$type} || $fmin == $fmax) ) { $fmin += 1; } # dang -1 chado start
if( !defined $strand ) { $strand=0; }
# feb05: the zero-base insertion sites ( fmin==fmax ) should not have fmin+1 adjustment
# 2L 131986 131986 1 1 transposable_element_insertion_site
## this check only for intron,UTR chado-computed locs ??
## also looks like computed UTR's can be off by 1 out of gene bounds, if UTR == 0
## CG2657 = 2L:21918..23888 ; exon1 = 22983..23888 ; exon2 = 21918..22687
## dmel_chado says -u3 = 21918..21917<too low
## -u5 = too high>23889..23888 ; -intron = no+1>22688..22982
if ($fmax < $fmin) {
($fmin,$fmax)= ($fmax,$fmin);
$strand= ($strand==0) ? -1 : -$strand;
}
# ($arm,$fmin,$fmax,$strand,$armfile,$s_arm)
# = $self->remapArm($arm,$fmin,$fmax,$strand); # for dpse joined contigs
($type,$fulltype,$s_type)= $self->remapType($type,$name);
if (!$type && $DEBUG && !/NULL|repeatmask/) { print STDERR "missing type: $_\n"; } ##<< repeatmasker kid objs
if ($type eq 'skip' || !$type) { # or what? undef? got some bad feats w/ no type??
## dont keep old oid: ($l_arm,$l_oid,$l_fmin)= ($arm,$oid,$fmin);
##dont save arm for skip !? if changed here, cant miss below openout..
($l_oid,$l_fmin)= (-1,$fmin);
next;
}
# ($id,$s_id)= $self->remapId($type,$id,$name);
($name,$s_name)= $self->remapName($type,$name,$id,$fulltype);
## dmelr4.1 patch; cant do this for all dropid - gff needs real ids for exons for instance
#if (($dropid{$type} || $nameisid{$type}) && $name) { $id= $name; } ##
## do this in remapId ..
## if (($nameisid{$type}) && $name) { $id= $name; } ## ? not for gff
my $loc="$fmin\t$fmax\t$strand";
# dmelr4.1 - need add band attrib even if attrib == parent_oid
if ($type eq 'chromosome_band') { ## && !$attribute
my $battr_type = 'cyto_range';
my $battribute = $s_name;
$battribute =~ s/(cyto|band|\-)//g;
push( @addattr, "$battr_type\t$battribute");
$name =~ s/\-cyto//;
}
## find quicker way to screen out many match_ dup things ; same simple loc, no id...
## # hasdups -- need to check id == l_id, name = l_name ..
## match_blastn_na_dbEST_dpse="1"
## match_sim4_na_dbEST_same_dmel="1"
## ? do something like this also for EST, protein which differ only by dbxref id
## i.e. feature is location w/ several items matching
## need to turn name/id into dbxref attrib
## feats: processed_transcript , EST, protein
## some chado exons, introns are dupl of same data... diff uniquename for no useful reason
## also check for $oidobs{$oid}->{fob};
if ($oid ne $l_oid && ! $simplefeat{$type}
&& exists $oidobs{$oid}->{fob}) {
my $ok=0;
foreach my $dob (@fobs) {
if ($dob->{oid} eq $oid) { $ok=1; last; }
}
if ($ok) {
$fob= $oidobs{$oid}->{fob};
$oid= $l_oid= $fob->{oid};
}
else {
## FIXME - bad if fob not in @fobs
## .. e.g. repeat region - many locs over arm, few oid's
## most of these we dont want to join - too far apart; need max_max setting below to keep small ranges together?
# print STDERR "missed join to last $type,$name,$oid\n" if $DEBUG;
}
}
if ($oid ne $l_oid && $hasdups{$type}) {
foreach my $dob (@fobs) {
next unless($dob->{type} eq $type);
my $dloc= $dob->{loc}->[0];
my($dmin,$dmax,$dstrand)= split("\t",$dloc);
if ( $dmin eq $fmin
&& $dmax eq $fmax
&& $dstrand eq $strand
) {
$fob= $dob;
$oid= $l_oid= $fob->{oid};
last;
}
}
}
#warn ">tss2d: new $arm,$fmin,$oid,$l_oid\n" if $tss;
## all TSS has same oid now !???? -- odd bug $l_oid == $oid
if ( $oid eq $l_oid ) {
# same object - cat attributes into one set
push( @{$fob->{loc}}, $loc) unless(grep /$loc/,@{$fob->{loc}});
#warn ">tss2S: new $arm,$fmin,$oid,$l_oid\n" if $tss;
foreach my $fk (keys %addfob) { $fob->{$fk}= $addfob{$fk}; } %addfob=();
}
else {
## new feature object here ..
if ($arm ne $l_arm) {
$self->putFeats($outh,\@fobs,\%oidobs,'final');
undef @fobs; @fobs=();
undef %oidobs; %oidobs=();
undef %gffForwards; %gffForwards=();
$max_max=0; $min_max= 0;
$outh= $self->openCloseOutput($outh, $arm, 'open');
}
#? do we need to set a max @fbobs ?
## is this where we lose PA/CDS associated with mRNA/gene ? havent got to yet before putFeats?
my $flushok= ($fmin >= $max_max && $fmin > $min_max && scalar(@fobs)>5);
if ($flushok) {
if ($self->hasObForwards(\@fobs, \%oidobs)) {
$flushok = 0;
$min_max= $fmin + 2000; ##smaller step so we dont miss chance to flush
}
warn "hasObForwards no=$flushok at $fmin $type:$name $oid\n" if ($DEBUG>1);
}
if ($flushok) {
##warn "flushobs at $fmin $type:$name $oid\n" if $DEBUG;
my ($nstart, $nleft, $nobs)=(0,0,0);
if ($DEBUG>1) { $nobs= scalar(@fobs); }
$self->putFeats( $outh, \@fobs, \%oidobs, '');
undef @fobs; @fobs=();
$min_max= $fmin + MIN_FORWARD_RANGE; #?? will this help join parts
## %oidobs will grow big;
## can we clear out other obs yet: %oidobs=(); %gffForwards=(); if no forwards ?
if ($DEBUG>1) { while( each %oidobs ){ $nstart++; }}
my $clearflag= ($outh->{fff} || !$outh->{gff}) ? 'writefff' : 'writegff';
my $nclear= $self->clearFinishedObs( $clearflag, \%oidobs, $fmin - MAX_FORWARD_RANGE);
if ($DEBUG>1) {
while( each %oidobs ){ $nleft++; }
print STDERR " printed n=$nobs; oidobs: pre-clear=$nstart, cleared=$nclear, left=$nleft\n";
print STDERR " fmin=$fmin, fmax=$fmax, l_fmin=$l_fmin, min_max=$min_max, max_max=$max_max\n";
}
}
my $newob= {};
push(@fobs,$newob);
$fob= $newob;
foreach my $fk (keys %addfob) { $fob->{$fk}= $addfob{$fk}; } %addfob=();
#?? dont add here if it is simple feature; wait till know if it is parent or kid?
# this is bad for 'gene' NOT? simple feat
unless( $simplefeat{$type} ) {
$oidobs{$oid}->{fob}= $newob;
}
# my @fclone_fields = qw(chr type fulltype name id oid fmin fmax offloc attr writefff writegff);
$fob->{chr} = $arm;
$fob->{type}= $type;
$fob->{fulltype}= $fulltype; # colon-delimited complex type 'match:program:source'
$fob->{name}= $name;
$fob->{id} = $id;
$fob->{oid} = $oid;
$fob->{fmin}= $fmin;
$fob->{fmax}= $fmax;
$fob->{loc} = [];
$fob->{attr}= [];
##warn ">tss2x: new $arm,$fmin,$oid\n" if $tss;
push( @{$fob->{loc}}, $loc);
##moved below## foreach my $at (@addattr) { push( @{$fob->{attr}}, $at); }
}
## make oid crossref here so outputters know feature relations
## change this (see above $samoid read loop)
## FIXME 05: this sub should be run only after forward parent_oid is found;
## or change input to sort given model gene > mRNA > CDS (ignoring seq start)
foreach my $at (@addattr) {
my $paroid='';
if ($at =~ /parent_oid\t(.+)/) { $paroid=$1; }
push( @{$fob->{attr}}, $at)
; # unless( grep {$at eq $_} @{$fob->{attr}}); #? do we have any dupls?
## REMEMBER SOME (exons) HAVE MULTIPLE parent_oid attributes
if ($paroid && !$simplefeat{$type}) {
$self->newParentOid($fob, 'parent_oid', $paroid, \%oidobs);
}
}
# $self->newParentKidLink($fob, \%oidobs); # uses @{$fob->{attr}} parent_oid
## MOVED parent_oid attrib TO putFeats: $self->update1ParentKidLinks($fob, \%oidobs);
## forward ref checkpoint .. maybe skip more than segmentfeats here ? what is big?
if ($fmax > $max_max && !$segmentfeats{$fob->{type}}) {
$max_max= $fmax;
my $supermax= $min_max - MIN_FORWARD_RANGE + MAX_FORWARD_RANGE;
$max_max= $supermax if ($max_max > $supermax); # is it < or > ? was > (set to SMALLER)
}
## only need save these:
($l_arm,$l_oid,$l_fmin,$l_fmax,$l_type)= ($arm,$oid,$fmin,$fmax,$type);
}
$self->putFeats($outh,\@fobs,\%oidobs, 'final');
@fobs=(); %oidobs=();
$outh= $self->openCloseOutput($outh,'','close');
print STDERR "\nprocessChadoTable ndone = $ndone\n" if $DEBUG;
return $ndone;
}
sub keepfeat_fff
{
my $self= shift;
my ($ftype)= @_;
my $dropfeat= ($dropfeat_fff{$ftype} || $ftype =~ /^match_part/);
return(!$dropfeat);
}
sub _debugObj
{
my ($name,$obj)= @_;
require Data::Dumper;
my $dd = Data::Dumper->new([$obj]); $dd->Terse(1);
print STDERR "DEBUG obj: $name=", $dd->Dump(),"\n";
}
=item makeFlatFeats($fobs,$oidobs)
handle gene model, other cases to make simple & compound features
return ref to features array
used for fff and fasta outputs
=cut
=item missing prots check
This is list of prot genes lacking proteins - many/most cases where
there are protein and CDS feats in features.tsv and intermediat files,
but missing in fff output
13472 gene.list
18716 protgn.list
13458 protgnuniq.list -- diff from gene.list below
.. feb04, dmelr41 check .. still missing some PA entries in fff, found in gff, featdump
chipmunk% comm -3 genecg41.list prot*list
;; these -Px proteins are in featdump, .gff, not .fff
CG10272 -- 3R
CG10324 -- 3R
CG11798 -- 2R
CG12591 -- 3R
CG17998 -- 3R
CG31092 -- 3R
CG3973 -- X
CG4993 -- 2L
CG5789 -- 3R
>> several of these missing prots are in features.tsv as CDS, not in fff output tho !?
dghome2% comm -3 gene.list protgnu.list
CG11989 3L
CG18675 3L
CG32373 3L
CG32406 3L
CG12094 X
CG1692 X
CG31243 3R
CG32600
CG4196
CG4444
CG5490
CG6669
CG7210
CG7369
CG8742
Gyc76C == CG8742
for this case CG18675; gff has right data, fff lacks CDS,three_prime_UTR
distance is gene:4157385 to CDS:4157485 = 100 b
chipmunk% gunzip $dr/gff.save/*gz
grep CG18675 ../../gff.chipmunk% grep CG18675 ../../gff.save//*3L*ff
chipmunk% grep CG18675 ../../fff.save//*3L*ff
=cut
sub makeFlatFeats
{
my $self= shift;
my ($fobs,$oidobs)= @_;
## debug missing from fff: insertion_site, regulatory
# my %GMM= map { $_,1; } qw(enhancer insertion_site aberration_junction
# regulatory_region rescue_fragment sequence_variant);
my @cobs=();
my $gmodel_parts_rename= $self->config->{gmodel_parts_rename};
foreach my $fob (@$fobs) {
my $oid= $fob->{oid};
my ($iskid,$ispar)= (0,0);
my $oidob= $oidobs->{$oid};
my $ftype= $fob->{type};
my $fulltype= $fob->{fulltype};
my $id= $fob->{id};
my $issimple= $simplefeat{$ftype};
# my $GMM= $GMM{$ftype} && $DEBUG;
## missing exons: CG10033 (2L?)
## missing proteins: 3L CG11989 CG18675 CG32373 CG32406
##my $GMM= ($DEBUG && $id =~ /CG11989|CG18675|CG32373|CG32406/) ? 1 : 0; # jan05 bug test, mRNA misses last 2 exons
my $GMM= 0; ##($DEBUG && $id =~ /CG4993|CG11798|CG10272|CG3973/) ? 1 : 0; # feb05 bug test, mRNA misses last 2 exons
if (!$issimple && $oidob) {
$iskid= (defined $oidob->{parent} && @{$oidob->{parent}} > 0);
$ispar= (defined $oidob->{child} && @{$oidob->{child}} > 0);
if ($iskid) { # check we have backref to parend obj ??
my $ok= 0;
foreach my $poid (@{$oidob->{parent}}) {
if ($oidobs->{$poid}) { $ok=1; last; }
}
$iskid= $ok;
}
}
warn ">gmm1 $ftype $id ispar=$ispar iskid=$iskid\n" if $GMM;
my $keepfeat= ($ispar || $self->keepfeat_fff($ftype));
if ($keepfeat) {
$issimple= ($issimple || !$ispar || $ftype eq 'gene'); # $ftype !~ m/^(CDS)$/ &&
#NEED THIS# $issimple = 1 if ($ftype =~ m/^gene$/); #?? otherwise misc. gene parts GMM get flagged as written
#BUT for complex flybase data; not for sgdlite w/o mrna features
if ($issimple && $ftype eq 'gene') { $issimple= 0 if($self->config->{gene_is_complex}); }
if ($issimple) { push(@cobs, $fob); } # simple feature
else { # has kids, make compound feature
my $kidobs= $oidob->{child};
my $cob= $self->makeCompound( $fob, $kidobs, $ftype);
push(@cobs, $cob);
# $self->listkids($cob,$kidobs) if($DEBUG && $ftype =~ m/^(gene|mRNA)$/); ## was loosing kids to bad $oidobs
}
warn ">gmm2 add $ftype $id \n" if $GMM;
## _debugObj("gmmisc=$id object",$cobs[-1]) if $GMM;
}
# UTR here ? ?? insert CDS between UTR's ?
## some of intron,UTR have swapped locs = 4650373..4650371
=item debug parent/kid feature objects
print STDERR "makeFlatFeats $ftype par=$id check kids\n" ;#if $DEBUG;
# got here, missing protein/CDS kids.
_debugObj("par=$id objects",$oidob);
makeFlatFeats mRNA par=CG18001-RA check kids
DEBUG obj: par=CG18001-RA objects={
'parent' => [
509313
],
'fob' => {
'writefff' => 1,
'chr' => '2h',
'attr' => [
'parent_oid 509313'
],
'name' => 'CG18001-RA',
'id' => 'CG18001-RA',
'oid' => 509314,
'type' => 'mRNA',
'loc' => [
'42592 43051 -1'
]
},
'child' => [
{
'writefff' => 1,
'chr' => '2h',
'attr' => [
'parent_oid 509314:2'
],
'name' => 'CG18001:2',
'id' => 'CG18001:2',
'oid' => 509316,
'type' => 'exon',
'loc' => [
'42592 42914 -1'
]
},
...
}
=cut
#
## %GModelParents = ( mRNA => 1, otherRnas ?? => );
## $CDS_spanType = 'CDS' ; # change to 'protein' or other ...
## $CDS_exonType = 'CDS_exon' ; # change to 'CDS'
## But for fff, need to rename $CDS_spanType 'protein' to 'CDS' for output fff type
#if ($ispar && $ftype eq 'mRNA')
if ($ispar && $GModelParents{$ftype})
{
foreach my $ftname (@GModelParts) {
my $utrob= undef;
my $cdsob= undef;
my $exonobs=[];
my $mrnaexons=[];
my $kidobs=[];
foreach my $kidob (@{$oidob->{child}}) {
if ($kidob->{type} eq 'exon') {
push(@$mrnaexons, $kidob); # save in case missing CDS_exon
}
if ($kidob->{type} eq $CDS_spanType) { $cdsob= $kidob; } # only for utr patch ?
if ($ftname eq $CDS_spanType && $kidob->{type} eq $CDS_spanType) {
$utrob= $kidob unless($utrob);
## urk - need to keep loc:start/stop to adjust CDS_exon end points !
}
elsif ($id =~ /CG32491/ && $ftname eq $CDS_spanType && $kidob->{type} eq 'exon') {
## patch for mdg4 bug
push(@$exonobs, $kidob);
}
elsif ($ftname eq $CDS_spanType && $kidob->{type} eq $CDS_exonType) {
push(@$kidobs, $kidob);
## missing this for het db ... FIXME
# bad CDS_exon for transspliced mdg4 ... sigh ... need to keep also regular exons?
}
## ?? want instead: if(kidob->type in (UTR,...)) add to kids
elsif ($kidob->{type} eq $ftname) { # these will be UTR's, other things (?)
$utrob= $kidob unless($utrob); #?? dont do this?
push(@$kidobs, $kidob);
## repair bad names; only if bad !?
## FIXME apr05 - intron,UTR fff output needs CG ids (in gff, not fff, due to
## name = gene-symbol, FBgn ID; ... need uniquename
## apr05 - this renaming bad now ? at keep old name,id as 2ndary ?
if ($gmodel_parts_rename) {
my $part="";
if ($ftname eq 'three_prime_UTR') { $part= "-u3"; }
elsif ($ftname eq 'five_prime_UTR') { $part= "-u5"; }
elsif ($ftname eq 'intron') { $part= "-in"; }
if ($part) {
$utrob->{name}= $fob->{name}.$part;
$utrob->{id}= $fob->{id}.$part;
}
}
}
}
## ERROR - CDS/protein w/o CDS_exon parts - not harvard chado 'reporting' db
## fixme ... recreate from cds start/stop + mrna location ?
if ($utrob && !@$kidobs) {
if ($ftname eq $CDS_spanType && @$mrnaexons) {
$kidobs= $self->getCDSexons($utrob, $mrnaexons);
}
}
if ($utrob) {
## copy gene model dbxref id into these features, as per above
my $idpattern= $self->config->{idpattern};
foreach my $pidattr (@{$fob->{attr}}) {
next if ($pidattr =~ m/2nd/); #dbxref_2nd:
if (!$idpattern || $pidattr =~ m/$idpattern/) {
push( @{$utrob->{attr}}, $pidattr) unless( grep {$pidattr eq $_} @{$utrob->{attr}});
last; # add only 1st/primary ?? also add CG/CR .. ? or is that always there?
}
}
if ($ftname =~ /UTR/ && $self->config->{utrpatch}) {
$self->patchUTRs( $utrob, $cdsob, $mrnaexons, $kidobs);
}
##print STDERR "makeCompound $ftname par=$id, kid=",$utrob->{id}, "\n" if $DEBUG;
# below # if ($ftname eq 'CDS') { $kidobs= adjustCDSendpoints( $utrob, $kidobs); }
## jan06: problem here w/ change to protein/cds: all GModelParts end up fff feature
## CDS_exon, exon end up as compound types same as mRNA, CDS/protein
my $cob= $self->makeCompound( $utrob, $kidobs, $ftname);
# $self->listkids($cob,$kidobs) if($DEBUG); ## was loosing kids to bad $oidobs
# patch bad data -- use getCDSexons above ??
if ($id =~ /CG32491/ && $ftname eq $CDS_spanType) {
my @exlocs=();
foreach my $kid (@$exonobs) {
foreach my $loc (@{$kid->{loc}}) { push( @exlocs, $loc); }
}
$cob->{exons}= \@exlocs;
}
push(@cobs, $cob);
}
}
}
## else { } # $iskid only - dont save
}
return \@cobs;
}
## jan06: makeFlatFeats -> makeFlatFeatsNew
## change to config->{feat_model}->{$type}: @parts, $parent, $typelabel, $types
sub makeFlatFeatsNew
{
my $self= shift;
my ($fobs,$oidobs)= @_;
my @cobs=(); # these compound features get added to output
foreach my $fob (@$fobs) {
my $oid= $fob->{oid};
my ($iskid,$ispar)= (0,0);
my $oidob= $oidobs->{$oid};
my $ftype= $fob->{type};
#my $fulltype= $fob->{fulltype};
my $id= $fob->{id};
my $issimple= $simplefeat{$ftype};
my $feat_model= $self->config->{'feat_model'}->{$ftype};
## get issimple from feat_model
my $GMM=0; # ($DEBUG && $id =~ /CG17245|CG32013|CG2125|CG3973/) ? 1 : 0; # feb05 bug test, mRNA misses last 2 exons
if (!$issimple && $oidob) {
$iskid= (defined $oidob->{parent} && @{$oidob->{parent}} > 0);
$ispar= (defined $oidob->{child} && @{$oidob->{child}} > 0);
if ($iskid) { # check we have backref to parend obj ??
my $ok= 0;
foreach my $poid (@{$oidob->{parent}}) {
if ($oidobs->{$poid}) { $ok=1; last; }
}
$iskid= $ok;
}
}
warn ">gmm1 $ftype $id ispar=$ispar iskid=$iskid\n" if $GMM;
my $keepfeat= ($ispar || $self->keepfeat_fff($ftype));
if ($keepfeat) {
if(!$ispar) { $issimple=1; }
elsif($feat_model && defined($feat_model->{simple})) { $issimple= $feat_model->{simple}; }
elsif($ftype eq 'gene' && !$self->config->{gene_is_complex}) { $issimple=1; }
#NEED THIS# $issimple = 1 if ($ftype =~ m/^gene$/); #?? otherwise misc. gene parts GMM get flagged as written
#BUT for complex flybase data; not for sgdlite w/o mrna features
if ($issimple) { push(@cobs, $fob); } # simple feature
else { # has kids, make compound feature >> (m,t,s)RNA here
my $kidobs= $oidob->{child};
my $cob= $self->makeCompound( $fob, $kidobs, $ftype);
push(@cobs, $cob);
# $self->listkids($cob,$kidobs) if($DEBUG && $ftype =~ m/^(gene|mRNA)$/); ## was loosing kids to bad $oidobs
}
warn ">gmm2 add $ftype $id \n" if $GMM;
}
## %GModelParents = ( mRNA => 1, otherRnas ?? => );
## $CDS_spanType = 'CDS' ; # change to 'protein' or other ...
## $CDS_exonType = 'CDS_exon' ; # change to 'CDS'
## But for fff, need to rename $CDS_spanType 'protein' to 'CDS' for output fff type
## ?? this is only for 3-level models (gene/mRNA/protein) where
## submodel parts are contained in mainmodel kid list (protein-CDS in mRNA)
if ($ispar && $feat_model && $feat_model->{submodels})
{
my $parob= $fob;
my $submodels = $feat_model->{submodels};
my @submodels = (ref $submodels) ? @$submodels : split(/[,\s]+/,$submodels);
foreach my $subtype (@submodels) {
my $sub_model= $self->config->{'feat_model'}->{$subtype};
my $makepartsfrom = $sub_model->{makepartsfrom} || 'exon';
my $hasspan = (defined $sub_model->{hasspan}) ? $sub_model->{hasspan}
: ($subtype eq $CDS_spanType); # old version
my $typelabel= $sub_model->{typelabel} || $subtype;
# my $parent= $sub_model->{parent};
my $kidparts = $sub_model->{parts} || 'exon'; #? no default
my @kidparts = (ref $kidparts) ? @$kidparts : split(/[,\s]+/,$kidparts);
my %kidparts = map { $_,1; } @kidparts;
my $makemethod = $sub_model->{makemethod};
my $subob= undef;
my $spanob= undef;
my $mrnaexons=[];
my $kidobs=[];
foreach my $kidob (@{$oidob->{child}}) {
my $ktype= $kidob->{type};
if ($ktype =~ /^$makepartsfrom$/) {
push(@$mrnaexons, $kidob); # save in case missing CDS_exon
}
if ( $ktype eq $CDS_spanType ) { $spanob= $kidob; } # only for utr patch !
if ( $ktype eq $subtype ) {
$subob= $kidob unless($subob);
}
elsif ($kidparts{$ktype}) {
push(@$kidobs, $kidob);
}
}
## CDS/protein w/o CDS_exon parts ... recreate from cds start/stop + mrna location
if ($subob && !@$kidobs && $hasspan && @$mrnaexons) {
warn ">gmmC getCDSexons $sub_model $kidparts $subob, ne=",scalar(@$mrnaexons),"\n" if $GMM;
$kidobs= $self->getCDSexons($subob, $mrnaexons);
#($subob,$kidobs)= eval "\$self->$makemethod(\$subob, \$mrnaexons);";
}
## for making UTRs, introns: mar06 # makemethod == makeUtr5,makeIntrons,...
elsif( !@$kidobs && @$mrnaexons && $makemethod) {
$subob= $parob unless($subob); #??
# warn ">gmmU $makemethod $sub_model $kidparts $subob, ne=",scalar(@$mrnaexons),"\n" if $GMM;
($subob,$kidobs)= eval "\$self->$makemethod(\$subob, \$mrnaexons);";
if($@ && $DEBUG){ warn "$makemethod err: $@"; } #? die if ($self->{failonerror}) ?
warn ">gmmU $makemethod $sub_model np=",scalar(@$kidobs),"\n" if $GMM;
}
if ($subob) {
## copy gene model dbxref id into these features, as per above
my $idpattern= $self->config->{idpattern};
foreach my $pidattr (@{$fob->{attr}}) {
next if ($pidattr =~ m/2nd/); #dbxref_2nd:
if (!$idpattern || $pidattr =~ m/$idpattern/) {
push( @{$subob->{attr}}, $pidattr) unless( grep {$pidattr eq $_} @{$subob->{attr}});
last; # add only 1st/primary
}
}
if ($subtype =~ /UTR/ && $self->config->{utrpatch}) {
$self->patchUTRs( $subob, $spanob, $mrnaexons, $kidobs);
}
## jan06: problem here w/ change to protein/cds: all GModelParts end up fff feature
## CDS_exon, exon end up as compound types same as mRNA, CDS/protein
my $cob= $self->makeCompound( $subob, $kidobs, $subtype);
# $self->listkids($cob,$kidobs) if($DEBUG); ## was loosing kids to bad $oidobs
$cob->{type}= $typelabel;
warn ">gmmCOB $typelabel $cob np=",scalar(@$kidobs),"\n" if $GMM;
push(@cobs, $cob);
}
}
}
## else { } # $iskid only - dont save
}
return \@cobs;
}
=item patchUTRs($utrob,$mrnaexons,$kidobs)
make sure utr's are in $mrnaexons range
patch for buggy utr-data
=cut
sub patchUTRs
{
my $self= shift;
my ($utrob,$cdsob,$mrnaexons,$kidobs)= @_;
return if ($utrob->{patched} || scalar(@$mrnaexons)==0);
my($minex,$minex1,$maxex,$maxex1)=(-1,-1,-1,-1);
foreach my $ex (@$mrnaexons) {
my ($start,$stop,$st) = split("\t", $ex->{loc}->[0]);
if ($minex==-1 || $start < $minex) { ($minex,$minex1)= ($start,$stop); }
if ($maxex==-1 || $stop > $maxex) { ($maxex,$maxex1)= ($stop,$start); }
}
# got weird utr mid points 2,3 bases below/above CDS start/stop;
# always use protein start/stop if need change?
if ($cdsob) {
my $offsetloc = $cdsob->{loc}->[0] ; # only 1 we hope
my ($offstart,$offstop,$offstrand) = split("\t",$offsetloc);
$minex1= $offstart-1 if ($offstart > $minex); # && $offstart <= $minex1
$maxex1= $offstop+1 if ($offstop < $maxex); #$offstop >= $maxex1 &&
}
## kidobs[0] == utrob always ? only 1 kidob ?
foreach my $kid (@$kidobs) {
my $c= 0;
my ($start,$stop,$st) = split("\t", $kid->{loc}->[0]);
if ($start < $minex) { $c=1; $start= $minex; $stop= $minex1; } #if ($stop < $start)
if ($stop > $maxex) { $c=1; $stop= $maxex; $start= $maxex1; } #if ($start > $stop)
# print STDERR "patchUTRs ".($c?'':'NOT ').$kid->{name}." ".$kid->{loc}->[0]." => $start..$stop\n" if $DEBUG;
if ($c) {
$kid->{loc}->[0]= join("\t", $start,$stop,$st);
$utrob->{'writefff'}= $utrob->{'writegff'}= -1 if ($stop==$start);
}
# dont write bogus empty UTR
elsif ($stop==$start) { $utrob->{'writefff'}= $utrob->{'writegff'}= -1; }
}
$utrob->{patched}=1;
}
=item makeUtr5,3,makeIntron
generate UTR's, introns from exons, protein-span features
added mar06
call:
my $makemethod = $sub_model->{makemethod}; # makeUtr5,makeIntrons,...
($subob,$kidobs)= $self->&{$makemethod}($subob, $mrnaexons);
where returned $subob is new feature: UTRs or intron(s)
=cut
sub makeUtr5 { return shift->makeUtr53(5,@_); }
sub makeUtr3 { return shift->makeUtr53(3,@_); }
sub makeUtr53
{
my $self= shift;
my ($uside, $mrnaob, $mrnaexons)= @_;
return (undef,[]) unless($uside == 5 || $uside == 3);
return (undef,[]) unless ($mrnaob && scalar(@$mrnaexons));
my($cdsob); # get from exon list
my @kidobs= (); # make from exons
foreach my $ex (@$mrnaexons) {
my $ktype= $ex->{type};
if($ktype eq 'protein') { $cdsob= $ex; }
}
# warn "makeUtr$uside $cdsob\n" if $DEBUG;
return (undef,[]) unless ($cdsob);
my $offsetloc = $cdsob->{loc}->[0] ; # only 1 we hope
my ($offstart,$offstop,$offstrand) = split("\t",$offsetloc);
## need to watch strand effect: 5prime for -strand is hi value, not low
# but genome-locs are always start<stop;
my $rev= ($offstrand < 0);
my $ulow = (($uside == 5 && !$rev) || ($uside == 3 && $rev));
my $uhigh = (($uside == 3 && !$rev) || ($uside == 5 && $rev));
foreach my $ex (@$mrnaexons) {
my $ktype= $ex->{type};
next unless($ktype eq 'exon');
my ($start,$stop,$st) = split("\t", $ex->{loc}->[0]);
# FIXME strand...
next if($ulow && $start >= $offstart);
next if($uhigh && $stop <= $offstop);
# my $cex= { %$ex }; # shallow clone; ok?
my $cex= $self->cloneBase($ex); # need locs
$cex->{'writefff'}= $cex->{'writegff'}= 0; # -1 ??
$cex->{type}= ($uside == 5) ? 'five_prime_UTR' : 'three_prime_UTR';
my $c= 0;
# FIXME strand
if ($ulow && $stop >= $offstart) { $c=1; $stop = $offstart - 1; }
if ($uhigh && $start <= $offstop) { $c=1; $start= $offstop + 1; }
if ($c) {
$cex->{loc}->[0]= join("\t", $start,$stop,$st);
}
push(@kidobs,$cex);
}
# warn "makeUtr$uside kids=",scalar(@kidobs),"\n" if $DEBUG;
return (undef,[]) unless (@kidobs);
# my $utrob= { %$mrnaob }; # shallow clone !
my $utrob= $self->cloneBase($mrnaob); # need locs
$utrob->{fulltype}= $utrob->{type}= ($uside == 5) ? 'five_prime_UTR' : 'three_prime_UTR';
my $part= ($uside == 5) ? "_utr5" : "_utr3";
$utrob->{name} .= $part;
$utrob->{id} .= $part;
$utrob->{'writefff'}= $utrob->{'writegff'}= 0;
# # need new $oid; insert in $oidobs->{$oid}->{parent}; ..
# $self->newParentOid( $mrnaob, 'parent_oid', $geneoid, $oidobs);
$utrob->{patched}=1;
return($utrob,\@kidobs);
}
sub makeIntrons
{
my $self= shift;
my ($mrnaob, $mrnaexons)= @_;
return () unless ($mrnaob && scalar(@$mrnaexons));
my @kidobs= (); # make from exons
my ($lstart,$lstop,$lst)= (0)x3;
foreach my $ex (@$mrnaexons) {
my $ktype= $ex->{type};
next unless($ktype eq 'exon');
my ($start,$stop,$st) = split("\t", $ex->{loc}->[0]);
# FIXME strand...
#? assume ordered exons here ?
if($lstop>0 && $start > $lstop) {
# my $cex= { %$ex }; # shallow clone; ok?
my $cex= $self->cloneBase($ex); # need locs
my($istart,$istop,$ist)= ($lstop+1,$start-1,$lst);
$cex->{loc}->[0]= join("\t", $istart,$istop,$ist);
$cex->{type}= 'intron';
$cex->{name} .= "_intron";
$cex->{id} .= "_intron";
push(@kidobs,$cex);
}
($lstart,$lstop,$lst)= ($start,$stop,$st);
}
return () unless (@kidobs);
# my $intronob= { %$mrnaob }; # shallow clone !
my $intronob= $self->cloneBase($mrnaob); # need locs
$intronob->{fulltype}= $intronob->{type}= 'intron_set'; # intron collection !
$intronob->{name} .= "_introns";
$intronob->{id} .= "_introns";
$intronob->{'writefff'}= $intronob->{'writegff'}= 0; # intron collection !
return($intronob,\@kidobs);
}
=item getCDSexons($cdsob,$exonobs,$ftype)
create compound feature from parent, kids (e.g., mRNA + exons)
=cut
sub getCDSexons
{
my $self= shift;
my ($cdsob,$exonobs,$ftype)= @_;
my $offsetloc = $cdsob->{loc}->[0]; # only 1 we hope
my ($offstart,$offstop,$offstrand) = split("\t",$offsetloc);
if ($offstart > $offstop) { ($offstart,$offstop)= ($offstop,$offstart); } #? need
$cdsob->{offloc}= $offsetloc;
my @cdsobs=();
foreach my $kid (@$exonobs) {
my ($start,$stop,$st) = split("\t", $kid->{loc}->[0]);
if ($stop >= $offstart && $start <= $offstop) {
push(@cdsobs, $kid);
}
}
return \@cdsobs;
}
sub listkids { ## DEBUG only
my $self= shift;
my ($cob,$kidobs)= @_;
my $name=$cob->{name};
my $ftype=$cob->{type};
my @locs= @ { $cob->{loc} };
print STDERR "COB $ftype:$name";
print STDERR " locs=",join(",",@locs);
print STDERR " kids=";
foreach my $kid (@$kidobs) {
print STDERR $kid->{type},":",$kid->{name}," ";
print STDERR join(",", @{$kid->{loc}})," ";
}
print STDERR "\n";
}
sub cloneBase ## shallow clone
{
my $self= shift;
my ($fob)= @_;
my $cob= {}; # are these all constant per oid ?
@{%$cob}{@fclone_fields}= @{%$fob}{@fclone_fields}; #? what is vodoo
# $cob->{chr} = $fob->{chr};
# $cob->{type}= $fob->{type};
# $cob->{fulltype}= $fob->{fulltype};
# $cob->{name}= $fob->{name};
# $cob->{id} = $fob->{id};
# $cob->{oid} = $fob->{oid};
# $cob->{'writefff'}= $fob->{'writefff'}; # if ($fob->{'writefff'}<0); # in case flagged in utr checker
# $cob->{'writegff'}= $fob->{'writegff'}; # if ($fob->{'writegff'}<0); # in case flagged in utr checker
# ## need locs ...
$cob->{loc} = []; push( @{$cob->{loc}}, $_) foreach (@{$fob->{loc}});
$cob->{attr}= []; push( @{$cob->{attr}}, $_) foreach (@{$fob->{attr}});
# foreach my $attr (@{$fob->{attr}}) { push( @{$cob->{attr}}, $attr); }
return $cob;
}
=item makeCompound($fob,$kidobs,$ftype)
create compound feature from parent, kids (e.g., mRNA + exons)
=cut
sub makeCompound
{
my $self= shift;
my ($fob,$kidobs,$ftype)= @_;
my $cob= $self->cloneBase($fob);
$fob->{'writefff'}=1; # need here also !? this is messy...
# my $cob= {}; # are these all constant per oid ?
# $cob->{chr} = $fob->{chr};
# $cob->{type}= $fob->{type};
# $cob->{fulltype}= $fob->{fulltype};
# $cob->{name}= $fob->{name};
# $cob->{id} = $fob->{id};
# $cob->{oid} = $fob->{oid};
# $cob->{'writefff'}= $fob->{'writefff'} if ($fob->{'writefff'}<0); # in case flagged in utr checker
# $fob->{'writefff'}=1; # need here also !?
#
# #$cob->{attr}= $fob->{attr};
# $cob->{attr}= [];
# foreach my $attr (@{$fob->{attr}}) {
# push( @{$cob->{attr}}, $attr);
# }
#
##FIXME - parent loc may need drop for kids locs (mRNA)
## bad also to pick all kids - only exon type for mRNA, others?
## FIXME - for protein && CDS types which are only child of mRNA, need to merge into
## compound feat.
## FIXME - for dang transspliced mod(mdg4) - if strands in locs differ -> getLocation
my @locs= ();
#my @kidlist=(); ## debug only?
## need to skip kids for 'gene', others ?
foreach my $kid (@$kidobs) {
##next if ($fob->{type} eq 'mRNA' && $kid->{type} ne 'exon');
#if ($DEBUG && $fob->{type} =~ m/^(mRNA|gene)$/) {
# push(@kidlist, $kid->{name}, $kid->{type});
# }
next if ($fob->{type} =~ m/^(mRNA|gene)$/ && $kid->{type} ne 'exon');
if ($ftype eq $CDS_spanType && $kid->{type} eq 'mature_peptide')
{
$ftype= $cob->{type}= 'mature_peptide';
}
# next if ($fob->{type} eq 'CDS' && $kid->{type} ne 'CDS_exon');
$kid->{'writefff'}=1; # need here also !?
foreach my $loc (@{$kid->{loc}}) { push( @locs, $loc); }
}
if ($ftype eq $CDS_spanType) {
my $offsetloc = $fob->{loc}->[0]; # only 1 we hope
$cob->{offloc}= $offsetloc;
# $ftype= $cob->{type}= 'CDS' if(1); ## FIXME another flag to rename CDS spantype?
}
unless(@locs) {
#? never keep main loc if have kid loc?
foreach my $loc (@{$fob->{loc}}) { push( @locs, $loc); }
}
$cob->{loc}= \@locs;
# $cob->{kidlist}= \@kidlist if ($DEBUG); ## debug only?
return $cob;
}
=item getLocation($fob,@loc)
get feature genbank/embl/ddbj location string (FTstring)
including transplice complexity
return ($location, $start, $strand);
## feb05: need to preserve strand==0/undefined for some features which have mixture
## fixed - for dang transspliced mod(mdg4) - if strands in locs differ
### looks like chado pg reporting instance with CDS_exons is bad for transspliced mod(mdg4)
=cut
sub getLocation
{
my $self= shift;
my($fob,@loc)= @_;
my $srange='';
my $bstart= -999;
my($l_strand,$istrans)=(0,0);
my ($offstart,$offstop,$offstrand)= (0,0,0);
## if $fob is CDS check offset strand, flip compl.
if (defined $fob->{offloc}) {
# now: DID NOT adjusted @loc by off start/stop
($offstart,$offstop,$offstrand) = split("\t",$fob->{offloc});
}
## assume not istrans - only 1 in 15,000 - redo if istrans
foreach my $loc (@loc) {
my ($start,$stop,$strand)= split("\t",$loc);
if ($offstop != 0) {
next if ($stop < $offstart || $start > $offstop);
$start= $offstart if ($start<$offstart);
$stop = $offstop if ($stop>$offstop);
## $strand= -$strand if ($offstrand < 0); #? is this bad for CDS ??
}
if ($bstart == -999 || $start<$bstart) { $bstart= $start; }
$srange .= "$start..$stop,";
if ($l_strand ne 0 && $strand ne $l_strand) { $istrans= 1; last; }
$l_strand= $strand;
}
if ($istrans) {
$srange='';
$l_strand= 0;
$l_strand= $offstrand if ($offstrand < 0);
## hack patch for bad cds exons for transpliced mdg4
if (defined $fob->{exons}) {
my $exonlocs= $fob->{exons};
@loc= @$exonlocs if (@$exonlocs);
print STDERR "transplice ",$fob->{name}," replaced cds_exons with mrna exons\n" if $DEBUG;
}
foreach my $loc (@loc) {
my ($start,$stop,$strand)= split("\t",$loc);
if ($offstop != 0) {
next if ($stop < $offstart || $start > $offstop);
## revcomp tricks here
if ( $l_strand < 0 && $strand >= 0 ) { #&& $strand >= 0
print STDERR "transplice ",$fob->{name}," rev ex=$start,$stop,$strand ; off=$offstart,$offstop\n" if $DEBUG;
$stop = $offstart if ($start < $offstart); #($stop>$offstart); ##
}
else {
# next if ($stop < $offstart || $start > $offstop);
$start= $offstart if ($start<$offstart);
$stop = $offstop if ($stop>$offstop);
}
}
$strand= -$strand if ($l_strand < 0);
if ($strand < 0) { $srange .= "complement($start..$stop),"; }
else { $srange .= "$start..$stop,"; }
}
}
$srange =~ s/,$//;
if ($l_strand < 0) { $srange= "complement($srange)"; }
elsif($srange =~ m/,/) { $srange= "join($srange)"; }
return ($srange, $bstart, $l_strand);
}
=item clearFinishedObs($flag,$oidobs)
undef/release objects from %oidobs -
otherwise fills up for full chromosome and overruns memory available
-- ok now, added min base loc to keep in oidobs, delete all before
runs fast - chr 3L in 10 min. instead of >2hr.
before this, oidobs was retaining *all* objects per input chr file;
and mem swapping to death before end. Now looks stable around 50 MB mem use.
AND speeds up greatly; fly chr 3L in 10 min. instead of >2hr.
=cut
sub clearFinishedObs
{
my $self= shift;
my ( $flag, $oidobs, $beforebase )= @_;
##my $flag= 'writefff';
my $nclear= 0;
if ($self->config->{noforwards}) {
my @oid; my @parids; my @kids;
foreach my $oid (keys %{$oidobs}) {
my $isfree= 1;
my $parids= $oidobs->{$oid}->{parent};
foreach my $parid (@{$parids}) {
my $pob = $oidobs->{$parid};
my $done= ($pob && $pob->{$flag}); #? this is bad?
if(!$done && $pob && $pob->{fob}) {
my $ptype= $pob->{fob}->{type} || "";
if ($simplefeat{$ptype}) { $done=1; }
}
unless($done) { $isfree=0; last; }
}
my $kids= $oidobs->{$oid}->{child};
foreach my $kidob (@{$kids}) {
my $done= ($kidob->{$flag});
unless($done) { $isfree=0; last; }
}
## dont free here -- finish iterate then do
if ($isfree) {
push(@oid, @{$parids}) if $parids;
push(@kids, $kids) if $kids;
push(@oid, $oid) if $oid;
}
}
foreach my $kids (@kids) { undef @{$kids}; $nclear++; }
foreach my $oid (@oid) {
my $ob= delete $oidobs->{$oid}; $nclear++;
if ($ob) {
undef @{$ob->{parent}};
undef @{$ob->{child}};
undef %{$ob->{fob}};
undef $ob;
}
}
## this fix looks like it is controlling memory overload
## before this, oidobs was retaining *all* objects per input chr file;
## and mem swapping to death before end. Now looks stable around 50 MB mem use.
## AND speeds up greatly over last data dump; < 1hr/chr versus 3hr+
if ($beforebase>0) {
while( my($oid,$ob)= each(%{$oidobs}) ) {
if ($ob->{fob} && $ob->{fob}->{fmax} < $beforebase) {
undef @{$ob->{parent}};
undef @{$ob->{child}};
undef %{$ob->{fob}};
undef $ob;
delete $oidobs->{$oid}; $nclear++;
}
}
}
}
# need to use gffForwards check
# NOTE: not tested; need likely above $beforebase fix to keep from retaining all oidobs
else {
foreach my $foid (keys %gffForwards) {
if ($gffForwards{$foid} == -1) {
delete $gffForwards{$foid};
delete $oidobs->{$foid}; #? need to undef/delete $oidobs{n}->parts ?
$nclear++;
}
}
}
return $nclear;
}
=item checkForward($flag,$fob,$oidobs)
check for any remaining forwarded (unseen) objects (for gff)
>> forward checks are problematic w/ new feats;
causing gff to sit in mem for full chromosome
=cut
sub checkForward
{
my $self= shift;
my ($flag,$fob,$oidobs)= @_;
my $thisforward=0;
my $anyforward=0;
my $oid= undef;
return $anyforward if ($self->config->{noforwards});
my $issimple= ($fob && $simplefeat{$fob->{type}} );
## this is wrong - need to check kid ids written (also!?)
## ?? also need to check fob->{loc}/{fmax} to see if we have past that point ??
if ($fob && $oidobs) { # && !$issimple
$oid= $fob->{oid};
# must skip segment, big features, etc. here even if have {parent}
my $parids= $oidobs->{$oid}->{parent};
if ($parids && !$issimple) {
foreach my $parid (@{$parids}) {
if (defined $gffForwards{$parid} && $gffForwards{$parid}<0) { next; }
my $pob= $oidobs->{$parid};
my $done= ($pob && $pob->{$flag}); #? this is bad?
my $ptype= $pob->{fob}->{type};
if ($pob && $pob->{fob} && ($simplefeat{$ptype})) { $done=1; }
if (!$done) { $gffForwards{$parid}=1; $thisforward=1; }
else { $gffForwards{$parid}=-1; }
}
}
my $kids= $oidobs->{$oid}->{child};
if ($kids) {
foreach my $kidob (@{$kids}) {
my $kidoid= $kidob->{oid};
if (defined $gffForwards{$kidoid} && $gffForwards{$kidoid}<0) { next; }
my $done= ($kidob->{$flag});
if (!$done) { $gffForwards{$kidoid}=1; $thisforward=1; }
else { $gffForwards{$kidoid}=-1; }
}
}
}
## need $flag check here?
foreach my $need (values %gffForwards) { if ($need>0) { $anyforward=1; last; } }
$gffForwards{$oid}=-1 if ($oid); # about to write this $fob
return $anyforward;
#return (wantarray) ? ($anyforward,$thisforward) : $anyforward;
}
sub getForwards
{
my $self= shift;
my $anyforward='';
foreach my $oid (sort keys %gffForwards) { if ($gffForwards{$oid}>0) { $anyforward .="$oid "; } }
return $anyforward;
}
=item putFeats($outh,$fobs,$oidobs,$flag)
output feature object (fobs) in selected formats (fff,gff,fasta)
=cut
sub putFeats
{
my $self= shift;
my ($outh,$fobs,$oidobs,$flag)= @_;
return unless($fobs && @$fobs > 0);
my($hasforward,$l_hasforward)=(0,0);
my $n= scalar(@$fobs);
if ($DEBUG && $flag =~ /final/) { # $DEBUG>1 ||
print STDERR "putFeats n=$n, total=".($n+$ntotalout)
.", oid1=".(($n>0)?$fobs->[0]->{oid}:0)."\n";
}
elsif ($DEBUG) {
print STDERR ".";
}
$self->updateParentKidLinks($fobs, $oidobs); #05feb: logic change ; was in processChadoTable
if ($outh->{fff}) { ## || $outh->{fasta} < moved out
my $ffh= $outh->{fff};
# my $fah= $outh->{fasta};
$self->{curformat}= 'fff';
my $cobs= $self->makeFlatFeatsNew($fobs,$oidobs);
# need to undef @$cobs when done !
my $nout= 0;
foreach my $fob (@$cobs) {
##$self->writeFFF( $outh->{fff}, $fob, $oidobs);
my $fffline= $self->getFFF( $fob, $oidobs );
if($fffline) {
print $ffh $fffline;
$nout++;
}
undef $fob;
}
undef $cobs;
$ffh->flush();
$ntotalout += $nout;
}
if ($outh->{gff}) {
$self->{curformat}= 'gff';
my $gffh= $outh->{gff};
my $noforw= $self->config->{noforwards};
# print $gffh "# fwd oid=".$self->getForwards()."\n"; # is this a section break?
my $gffend= 0;
$l_hasforward= ($noforw) ? 0 : $self->checkForward('writegff');
foreach my $fob (@$fobs) {
$hasforward= ($noforw) ? 0 : $self->checkForward('writegff',$fob,$oidobs);
if ($hasforward && !$l_hasforward && !$gffend) { $self->writeGFFendfeat($gffh); $gffend++; }
$l_hasforward= $hasforward; #?
if ($hasforward) {
$fob->{'writegff'}=1; # flag we have it for checkForward
push(@gffForwards, $fob);
}
else {
while (@gffForwards) { $self->writeGFF( $gffh, shift @gffForwards,$oidobs) ; }
## if we drop use of ID=oid, need to resolve all forwards before writeGFF
$self->writeGFF( $gffh,$fob,$oidobs) ;
$gffend=0;
}
}
if ($flag =~ /final/) {
while (@gffForwards) { $self->writeGFF( $gffh,shift @gffForwards,$oidobs) ; }
}
$gffh->flush();
}
$self->{curformat}= '';
}
sub writeHeader
{
my $self= shift;
my($outh,$fmt,$chr,$appending)= @_;
my $chrlen= defined $chromosome->{$chr} && $chromosome->{$chr}->{length} || 0;
## foreach $fmt (@formats) { $self->{$fmt}->writeheader($outh->{$fmt},$chr,$chrlen); }
$self->writeFFF1header($outh->{$fmt},$chr,$chrlen) if ($fmt eq 'fff' && !$appending);
$self->writeGFF3header($outh->{$fmt},$chr,$chrlen) if ($fmt eq 'gff' && !$appending);
## add fasta output - no header ?
}
## SONG/so Revision: 1.45
## @is_a@oligo ; SO:0000696 ; SOFA:SOFA ; synonym:oligonucleotide
## 'so' is no longer valid
## old value: @is_a@so ; SO:1000000
## -- options are limited: located_sequence_feature, SO:0000110 ??
## -- in flybase, 'so' seems used for protein blast matches?
## segment not in this
## alt choices ...
# @is_a@assembly ; SO:0000353 ; SOFA:SOFA
# ** @is_a@golden_path ; SO:0000688 ; SOFA:SOFA <<
# ** @is_a@supercontig ; SO:0000148 ; SOFA:SOFA ; synonym:scaffold <<
# @is_a@tiling_path ; SO:0000472 ; SOFA:SOFA
# @is_a@virtual_sequence ; SO:0000499 ; SOFA:SOFA
# @is_a@chromosome ; SO:0000340
# @part_of@chromosome_arm ; SO:0000105
## aug04: add new analysis features (HDP,RNAiHDP,fgenesh,)
## these are like exons but parent feature lacks featureloc
## - need to join together by object_oid/parent_oid and compute parent feature (has name)
## SO type.subtype should be match.program
## SONG: match, match_part match_set nucleotide_match cross_genome_match cDNA_match EST_match
#? use '.' instead of '_' for part type? would that throw gnomap/gbrowse usage? probably
sub setDefaultValues
{
my($self)= @_;
%maptype = (
golden_path_region => "scaffold", # "golden_path", ##was "segment", .. is again
oligonucleotide => "oligo",
transposable_element_pred => "transposable_element_pred",
three_prime_untranslated_region => "three_prime_UTR",
five_prime_untranslated_region => "five_prime_UTR",
);
%maptype_pattern = ();
%mapname_pattern = ();
%mapattr_pattern = ();
%maptype_gff = (
tRNA_trnascan => "tRNA:trnascan",
transposable_element_pred => "transposable_element:predicted",
);
%segmentfeats = ( # == big feats; no kids
chromosome => 1, chromosome_arm => 1, chromosome_band => 1,
source => 1,
BAC => 1,
segment => 1, golden_path => 1, golden_path_region => 1,
## segment no longer valid SO; supercontig or golden_path are best
);
## some common ones needing simple start/end, not compound
%simplefeat = (
## NOT these: gene => 1, pseudogene => 1, #? but has mRNA-like transcripts
oligonucleotide => 1,
point_mutation => 1,
transcription_start_site => 1,
repeat_region => 1,
region => 1, # attached to gene parents .. RpL40-misc_feature-1
);
map { $simplefeat{$_}=1; } keys %segmentfeats;
## drop 'remark' feat from all ?
%dropfeat_fff = ( ## for the parent/kid test for compound feats
exon => 1,
remark => 1,
CDS_exon => 1, #? better type?
# these following are not dropped, but compounded under each mRNA
three_prime_UTR => 1,
five_prime_UTR => 1,
CDS => 1,
intron => 1,
);
%dropfeat_gff = ( ## for the parent/kid test for compound feats
CDS_exon => 1,
remark => 1,
);
# these uniquename's from chado are not useful .. same as name always?
# now only for fff output? keep all ID for gff part resolving
%dropid = (
exon => 1,
transcription_start_site => 1,
transposable_element_pred => 1,
intron => 1,
repeat_region => 1,
oligonucleotide => 1,
processed_transcript => 1,
EST => 1,
cDNA_clone => 1,
chromosome_band => 1,
);
%dropname = (
mRNA_piecegenie => 1,
mRNA_genscan => 1,
tRNA_trnascan => 1,
transcription_start_site => 1, # if these are like 174396-174397-AE003590.Sept-dummy-promoter
## drop 'JOSHTRANSPOSON-' from name of transposable_element_pred 'JOSHTRANSPOSON-copia{}293-pred'
);
## need to turn name/id into dbxref attrib
## feats: processed_transcript , EST, protein -- instead make compound by same OID !
%mergematch = (
##EST => 1,
##processed_transcript => 1,
##### protein => 1, # only if not CDS!!!
);
%keepstrand=();
%hasdups = (
exon => 1,
three_prime_UTR => 1,
five_prime_UTR => 1,
);
##map { $hasdups{$_}=1; } keys %mergematch;
# these are ones where parent feature == gene needs renaming
$rename_child_type = ""; # old: join('|', 'pseudogene','\w+RNA' );
}
#---- FFF output -- separate package ?
sub writeFFF1header
{
my $self= shift;
my($fh,$seqid,$start,$stop)= @_;
if ((!defined $stop || $stop == 0)) {
$stop= $start; $start= 1; # start == length
}
my $date = $self->{date};
my $sourcetitle = $self->{sourcetitle};
my $sourcefile = $self->{sourcefile};
my $org= $self->{species} || $self->{org};
print $fh "# Features for $org from $sourcetitle [$sourcefile, $date]\n";
print $fh "# gnomap-version 1\n";
print $fh "# source: ",join("\t", $seqid, "$start..$stop"),"\n";
##print $fh "# ",join("\t", qw(Feature gene map range id db_xref notes)),"\n";
print $fh "# ",join("\t", qw(Feature name cytomap location id db_xref notes)),"\n";
print $fh "#\n";
if ($stop > $start) {
if ($fff_mergecols) {
my $bstart= TOP_SORT; # if ($self->{config}->{topsort}->{$fob->{type}});
print $fh join("\t", $seqid, $bstart, "source", $org, $seqid, "$start..$stop", $seqid,)."\n";
}
else {
print $fh join("\t", "source", $org, $seqid, "$start..$stop", $seqid,)."\n";
}
}
}
sub _fffEscape
{
my $v= shift;
# $v =~ tr/ /+/; #? leave in spc ?
$v =~ s/([\t\n\=&;,])/sprintf("%%%X",ord($1))/ge;
return $v;
}
=item getFFF v1
return tab-delimied feature lines in this format
# gnomap-version $gnomapvers
# Feature gene map range id db_xref notes
feature == feature type
gene == gene name
map == cytology map
range == GenBank/EMBL/DDBJ location, BioPerl FTstring)
id == feature id
db_xref == database crossrefs (, delimited)
notes == miscellany, now key=value; list
=cut
sub getFFF
{
my $self= shift;
my($fob,$oidobs)= @_;
return if ($fob->{'writefff'}); #?? so far ok but for mature_peptide/CDS thing
$fob->{'writefff'}=1;
my @loc= @{$fob->{loc}};
my @attr= @{$fob->{attr}};
my $oid= $fob->{oid};
my $featname= $fob->{type};
my $fulltype= $fob->{fulltype};
my($id,$s_id)= $self->remapId($featname,$fob->{id},'-');
$id= '-' unless (defined($id) && $id);
(my $ftop= $fulltype) =~ s/[\:\.].*$//;
if ($ftop && $featname =~ /^$ftop/) { $featname= $fulltype; } #?? want this
my $sym= $fob->{name} || '-';
$sym = _fffEscape($sym);
my $map= '-';
my $dbxref=""; my $dbxref_2nd="";
my $notes= "";
my %at=();
foreach (@attr) {
my ($k,$v)= split "\t";
## synonym_2nd=ribosomal protein S3&agr;; << problem; escape
$v = _fffEscape($v); # _gffEscape; at least any [\t\n\=&;,]
if ($k eq "object_oid") {
# skip
}
elsif ($k eq "synonym" && ($v eq $id || $v eq $sym)) { next; }
elsif ($k eq "parent_oid") { ## added apr05
next if $segmentfeats{$featname}; # dont do parent for these ... ?
$v =~ s/:.*$//; #$v= $oidmap{$v} || $v;
$k= 'Parent';
my $parob= $oidobs->{$v}->{fob};
if ($parob && $parob->{id}) {
$v= $parob->{id};
#? if ($oidisid_gff{$type}) { $v= $parob->{oid}; }
if ($v eq $id) { ## FIXME .. ? try to use index in parent->{child} array ?
my $i= 1;
my $paroid= $parob->{oid};
my $kids = $oidobs->{$paroid}->{child};
if ($kids) {
foreach my $kidob (@{$kids}) {
last if ($kidob->{oid} eq $oid);
$i++;
}
}
$id= "$id.$i";
# $at[0]= "ID="._gffEscape($id);
}
$at{$k} .= ',' if $at{$k};
$at{$k} .= $v;
}
else {
#next if ($fulltype =~ /match_part|cytology|band|oligo|BAC/ || $id =~ /GA\d/);
#print STDERR "GFF: missed Parent ID for i/o/t:",$id,"/",$oid,"/",$fulltype,
# " parob=",$parob," k/v=",$k,"/",$v, " \n" if $DEBUG;
next; # always skip writing bogus Parent= to gff
}
}
elsif ($k eq "cyto_range") { $map= $v; }
elsif ($k eq "dbxref") { ## and dbxref_2nd; put after dbxref !
$dbxref .= "$v;";
}
elsif ($k eq "dbxref_2nd") {
$dbxref_2nd .= "$v;";
}
elsif ($k) {
#$notes .= "$k=$v;"
$at{$k} .= ',' if $at{$k};
$at{$k} .= $v;
}
}
my @at=();
foreach my $k (sort keys %at) { push(@at, "$k=$at{$k}"); }
$notes = join(";",@at);
$dbxref .= $dbxref_2nd; # aug04: making sure 2nd are last is enough to get 1st ID
my ($srange,$bstart,$strand);
#my $srange = $fob->{location}; # computed already for transsplice ?
#my $bstart = $fob->{start}; # computed already for transsplice ?
#unless($srange && defined $bstart) ...
($srange,$bstart,$strand) = $self->getLocation($fob,@loc);
## feb05: need to preserve strand==0/undefined for some features which have mixture
if ($strand == 0 && $keepstrand{$featname}) { $notes .= "strand=0;"; }
## add chr,start to front cols for sort-merge
if ($fff_mergecols) {
my $chr= $fob->{chr};
return join("\t", $chr,$bstart,$featname,$sym,$map,$srange,$id,$dbxref,$notes)."\n";
}
else {
return join("\t", $featname,$sym,$map,$srange,$id,$dbxref,$notes)."\n";
}
}
sub writeFFF
{
my $self= shift;
my($fh,$fob,$oidobs)= @_;
my $fffline= $self->getFFF($fob,$oidobs);
print $fh $fffline if $fffline;
}
#---- GFF output -- separate package ?
=item writeGFF v3
##gff-version 3
##sequence-region ctg123 1 1497228 == source in fff
ctg123 . gene 1000 9000 . + . ID=gene00001;Name=EDEN
ctg123 . TF_binding_site 1000 1012 . + . ID=tfbs00001;Parent=gene00001
ctg123 . mRNA 1050 9000 . + . ID=mRNA00001;Parent=gene00001;Name=EDEN.1
ctg123 . 5_prime_UTR 1050 1200 . + . Parent=mRNA0001
ctg123 . CDS 1201 1500 . + 0 Parent=mRNA0001
ctg123 . CDS 3000 3902 . + 0 Parent=mRNA0001
ctg123 . CDS 5000 5500 . + 0 Parent=mRNA0001
ctg123 . CDS 7000 7600 . + 0 Parent=mRNA0001
ctg123 . 3_prime_UTR 7601 9000 . + . Parent=mRNA0001
=cut
sub writeGFF3header
{
my $self= shift;
my($fh,$seqid,$start,$stop)= @_;
if ((!defined $stop || $stop == 0)) {
$stop= $start; $start= 1; # start == length
}
my $date = $self->{date};
my $sourcetitle = $self->{sourcetitle};
my $org= $self->{species} || $self->{org};
print $fh "##gff-version\t3\n";
print $fh "##sequence-region\t$seqid\t$start\t$stop\n" if($seqid && $stop); #? always or only if missing chromosome?
print $fh "#organism\t$org\n";
print $fh "#source\t$sourcetitle\n";
print $fh "#date\t$date\n";
print $fh "#\n";
## DONT write chromosome twice -- check fobs
##sequence-region ctg123 1 1497228 == source in fff
## if ($stop > $start) ...
print $fh join("\t", $seqid, ".","chromosome", $start, $stop, '.', '.', '.', "ID=$seqid"),"\n"
if ($seqid && $stop && $self->config->{gff_addchromosome}); # also "chromosome" needs to be config-type
}
sub writeGFFendfeat
{
my $self= shift;
my($fh)= @_;
print $fh "###\n";
}
sub splitGffType
{
my $self= shift;
my($gffsource,$type,$fulltype)= @_;
my($newgffs)=('');
#? use fulltype instead of type? as 'match:sim4:na_EST_complete_dros'
# convert mRNA_genscan,mRNA_piecegenie to gffsource,mRNA ?
if ($maptype_gff{$type}) {
##($type,$newgffs)= @{$maptype_gff{$type}};
($type,$newgffs)= split(/[\.:]/,$maptype_gff{$type},2);
}
elsif ($fulltype =~ m/^([\w\_]+)[\.:]([\w\_\.:]+)$/) {
($type,$newgffs)=($1,$2);
}
elsif ($type =~ m/^([\w\_]+)[\.:]([\w\_\.:]+)$/) {
($type,$newgffs)=($1,$2);
}
else { $type= $fulltype; } #?? feb05; want snRNA not mRNA .. leave in fulltype ?
$gffsource= $newgffs if($newgffs && $newgffs ne '.');
return($gffsource,$type);
}
sub _gffEscape
{
my $v= shift;
$v =~ tr/ /+/;
$v =~ s/([\t\n\=&;,])/sprintf("%%%X",ord($1))/ge; # Bio::Tools::GFF _gff3_string escaper
return $v;
}
=item writeGFF
write one feature in gff3
feature may have sub location parts (multi line)
=cut
sub writeGFF
{
my $self= shift;
my($fh,$fob,$oidobs)= @_;
my $type= $fob->{type};
my $fulltype= $fob->{fulltype};
return if ($fob->{'writegff'});
$fob->{'writegff'}=1;
if ($dropfeat_gff{$type}) { return; }
my $gffsource= $fob->{gffsource} || $self->{gff_config}->{GFF_source} || ".";
my $oid= $fob->{oid};
my $id = $fob->{id}; ## was: $fob->{oid}; -- preserve uniquename ?
my $chr= $fob->{chr};
my @loc= @{$fob->{loc}};
my @attr= @{$fob->{attr}};
my $at="";
my @at= ();
my %at= ();
=item gff IDs
## gff3 loader is using ID for uniquename, unless give attr key for uniquename
## ? do we want to drop $oid and use id/dbid - is it always uniq in gff file?
## feb05; need to test parid != id; problem now w/ some features (match/match_part same id)
## feb05 - EST's now have same ID for different location matches; need uniq gff id
## sim4:na_dbEST.diff.dmel .. use object_oid ?
=cut
if ($oidisid_gff{$type}) { $id= $oid; }
# my($id,$s_id)= $self->remapId($type,$fob->{id}); #?? want for gff also ??
my $ignore_missingparent= $self->config->{maptype_ignore_missingparent} || '^xxxx';
my $v;
push @at, "ID="._gffEscape($id) if ($id); # use this for gff internal id instead of public id?
# ^^ if have parent, drop id ?? always or sometimes ?
push @at, "Name="._gffEscape($v) if (($v= $fob->{name}) && $v ne $id);
if ($gff_keepoids) { push @at, "oid=$oid"; }
foreach (@attr) {
my ($k,$v)= split "\t";
if (!$v) { next; }
elsif ($k eq "object_oid") { next; }
elsif ($k eq "parent_oid") {
if ($gff_keepoids) { $at{$k} .= ',' if $at{$k}; $at{$k} .= $v; }
next if $segmentfeats{$type}; # dont do parent for these ... ?
$v =~ s/:.*$//; #$v= $oidmap{$v} || $v;
$k= 'Parent'; #push @at, "Parent=$v";
## now need to convert oid to parent id, given above change to id
## BUT this is bad when Parent hasn't been seen yet !
=item BUG
## Dec04 -- sometimes miss parent id here; get OID instead in output
## grep CG32584 dmel-X-r4.0.gff
## mRNA ID=CG32584-RB;Parent=3108188;
## mRNA ID=CG32584-RA;Parent=CG32584
## lots for match_part .. ignore those?
>> not many; 1/2 per csome;
>> could be due to garbage collect. on oidobs; try MAX_FORWARD_RANGE+++
>> MAX_FORWARD_RANGE => 990000 seems to have fixed it
=cut
my $parob= $oidobs->{$v}->{fob};
if ($parob && $parob->{id}) {
$v= $parob->{id};
if ($oidisid_gff{$type}) { $v= $parob->{oid}; }
if ($v eq $id) { ## FIXME .. ? try to use index in parent->{child} array ?
my $i= 1;
my $paroid= $parob->{oid};
my $kids = $oidobs->{$paroid}->{child};
if ($kids) {
foreach my $kidob (@{$kids}) {
last if ($kidob->{oid} eq $oid);
$i++;
}
}
$id= "$id.$i";
$at[0]= "ID="._gffEscape($id);
}
}
else {
unless($fulltype =~ /$ignore_missingparent/) { ## || $id =~ /GA\d/
# dpse GA genes; odd parent = csome; ignore parent here? FIXME
print STDERR "GFF: MISSING parent ob for i/o/t:",$id,"/",$oid,"/",$fulltype,
" parob=",$parob," k/v=",$k,"/",$v, " \n" if $DEBUG;
}
next; # always skip writing bogus Parent= to gff
}
}
elsif ($k eq "dbxref" || $k eq "db_xref") { # dbxref_2nd - leave as separate
$k= 'Dbxref';
##$v= "\"$v\""; # NO quotes - spec says to but BioPerl::GFFv3 reader doesn't strip quotes
}
elsif ($k eq "synonym") { # check dupl ID
next if ($v eq $id || $v eq $fob->{name});
}
if ($k) {
$at{$k} .= ',' if $at{$k}; # got duplicate Parent=aaa,aaa in dpse data; why?
$at{$k} .= _gffEscape($v); # should be urlencode($v) - at least any [=,;\s]
}
}
($gffsource,$type)= $self->splitGffType($gffsource,$type,$fulltype);
## drop ID if Parent ; sometimes ?
my $parent= delete $at{'Parent'};
if( $parent && $dropid{$type} ) { $at[0]= "Parent=$parent"; }
elsif ($parent){ push(@at, "Parent=$parent"); }
foreach my $k (sort keys %at) { push(@at, "$k=$at{$k}"); }
$at = join(";",@at);
## need to make uniq ids for dupl oids - any @loc > 1 ?
## and need to make parent feature to join. Use ID=OID.1... OID.n
if (@loc>1) {
my ($b,$e,$str)=(-999,0,0);
foreach my $loc (@loc) {
my($start,$stop,$strand)= split("\t",$loc);
if ($b == -999) { ($b,$e) = ($start,$stop); $str= $strand; }
else { $b= $start if ($b > $start); $e= $stop if ($e < $stop); }
}
$str= (!defined $str || $str eq '') ? '.' : ($str < 0) ? '-' : ($str >= 1)? '+' : '.';
print $fh join("\t", $chr,$gffsource,$type,$b,$e,".",$str,".",$at),"\n";
## GFF v3 spec is unclear on what this $gffsource item contains.
## gffsource used for genscan, etc. type modifier, also for database sig, e.g. SGD
$gffsource='part_of' if ($gffsource eq '.'); #? was 'part'
foreach my $i (1..$#loc+1) {
my($start,$stop,$strand)= split("\t",$loc[$i-1]);
$strand= (!defined $strand || $strand eq '') ? '.' : ($strand < 0) ? '-' : ($strand >= 1)? '+' : '.';
$at= "ID=$id.$i;Parent=$id"; #?
print $fh join("\t", $chr,$gffsource,$type,$start,$stop,".",$strand,".",$at),"\n";
}
}
else {
my $loc= shift @loc;
my($start,$stop,$strand)= split("\t",$loc);
$strand= (!defined $strand || $strand eq '') ? '.' : ($strand < 0) ? '-' : ($strand >= 1)? '+' : '.';
print $fh join("\t", $chr,$gffsource,$type,$start,$stop,".",$strand,".",$at),"\n";
}
}
1;
__END__
|