/usr/bin/edirect is in ncbi-entrez-direct 7.40.20170928+ds-1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 | #!/usr/bin/perl
# ===========================================================================
#
# PUBLIC DOMAIN NOTICE
# National Center for Biotechnology Information (NCBI)
#
# This software/database is a "United States Government Work" under the
# terms of the United States Copyright Act. It was written as part of
# the author's official duties as a United States Government employee and
# thus cannot be copyrighted. This software/database is freely available
# to the public for use. The National Library of Medicine and the U.S.
# Government do not place any restriction on its use or reproduction.
# We would, however, appreciate having the NCBI and the author cited in
# any work or product based on this material.
#
# Although all reasonable efforts have been taken to ensure the accuracy
# and reliability of the software and data, the NLM and the U.S.
# Government do not and cannot warrant the performance or results that
# may be obtained by using this software or data. The NLM and the U.S.
# Government disclaim all warranties, express or implied, including
# warranties of performance, merchantability or fitness for any particular
# purpose.
#
# ===========================================================================
#
# File Name: edirect.pl
#
# Author: Jonathan Kans
#
# Version Creation Date: 8/20/12
#
# ==========================================================================
# Entrez Direct - EDirect
# use strict;
use warnings;
my ($LibDir, $ScriptName);
use File::Spec;
# EDirect version number
$version = "7.40";
BEGIN
{
my $Volume;
($Volume, $LibDir, $ScriptName) = File::Spec->splitpath($0);
$LibDir = File::Spec->catpath($Volume, $LibDir, '');
if (my $RealPathname = eval {readlink $0}) {
do {
$RealPathname = File::Spec->rel2abs($RealPathname, $LibDir);
($Volume, $LibDir, undef) = File::Spec->splitpath($RealPathname);
$LibDir = File::Spec->catpath($Volume, $LibDir, '')
} while ($RealPathname = eval {readlink $RealPathname});
} else {
$LibDir = File::Spec->rel2abs($LibDir)
}
$LibDir .= '/aux/lib/perl5';
}
use lib $LibDir;
# usage - edirect.pl -function arguments
use Data::Dumper;
use Encode;
use Getopt::Long;
use HTML::Entities;
use LWP::Simple;
use LWP::UserAgent;
use Net::hostent;
use POSIX;
use Time::HiRes;
use URI::Escape;
# required first argument is name of function to run
$fnc = shift or die "Must supply function name on command line\n";
# get starting time
$begin_time = Time::HiRes::time();
# definitions
use constant false => 0;
use constant true => 1;
# URL address components
$base = "https://eutils.ncbi.nlm.nih.gov/entrez/eutils/";
$ecitmat = "ecitmatch.cgi";
$efetch = "efetch.fcgi";
$einfo = "einfo.fcgi";
$elink = "elink.fcgi";
$epost = "epost.fcgi";
$esearch = "esearch.fcgi";
$espell = "espell.fcgi";
$esummary = "esummary.fcgi";
# utility subroutines
sub clearflags {
@rest = ();
%labels = ();
%macros = ();
$alias = "";
$author = "";
$basx = "";
$batch = false;
$chr_start = -1;
$chr_stop = -1;
$clean = false;
$cmd = "";
$complexity = 0;
$db = "";
$dbase = "";
$dbs = "";
$dbto = "";
$debug = false;
$drop = false;
$dttype = "";
$emaddr = "";
$email = "";
$err = "";
$extend = -1;
$extrafeat = -1;
$field = "";
$fields = false;
$feature = "";
$gtype = "";
$help = false;
$holding = "";
$http = "";
$id = "";
$input = "";
$journal = "";
$just_num = false;
$key = "";
$lbl = "";
$links = false;
$location = "";
$log = false;
$max = 0;
$meadow = "";
$min = 0;
$mndate = "";
$mode = "";
$molecule = "";
$mxdate = "";
$name = "";
$neighbor = false;
$num = "";
$organism = "";
$output = "";
$page = "";
$pair = "";
$pipe = false;
$pub = "";
$query = "";
$raw = false;
$related = false;
$rldate = 0;
$seq_start = 0;
$seq_stop = 0;
$showgi = false;
$silent = false;
$sort = "";
$source = "";
$spell = false;
$split = "";
$status = "";
$stp = "";
$strand = "";
$tool = "";
$trim = false;
$trunc = false;
$tuul = "";
$type = "";
$verbose = false;
$volume = "";
$web = "";
$word = false;
$year = "";
$stop_words="#a#about#again#all#almost#also#although#always#among#an#and#" .
"another#any#are#as#at#be#because#been#before#being#between#both#but#by#can#" .
"could#did#do#does#done#due#during#each#either#enough#especially#etc#for#" .
"found#from#further#had#has#have#having#here#how#however#i#if#in#into#is#it#" .
"its#itself#just#kg#km#made#mainly#make#may#mg#might#ml#mm#most#mostly#" .
"must#nearly#neither#no#nor#obtained#of#often#on#our#overall#perhaps#pmid#" .
"quite#rather#really#regarding#seem#seen#several#should#show#showed#shown#" .
"shows#significantly#since#so#some#such#than#that#the#their#theirs#them#" .
"then#there#therefore#these#they#this#those#through#thus#to#upon#use#used#" .
"using#various#very#was#we#were#what#when#which#while#with#within#without#would#";
# $os = "$^O";
$os = "";
$api_key = "";
$api_key = $ENV{NCBI_API_KEY} if defined $ENV{NCBI_API_KEY};
}
# gets a live UID for any database
sub get_zero_uid {
my $db = shift (@_);
my $val = "";
%zeroUidHash = (
'assembly' => '443538',
'bioproject' => '146229',
'biosample' => '3737421',
'biosystems' => '1223165',
'blastdbinfo' => '1023214',
'books' => '1371014',
'cdd' => '277499',
'clinvar' => '10510',
'clone' => '18646800',
'dbvar' => '6173073',
'gap' => '872875',
'gds' => '200022309',
'gencoll' => '398148',
'gene' => '3667',
'genome' => '52',
'genomeprj' => '72363',
'geoprofiles' => '16029743',
'homologene' => '510',
'medgen' => '162753',
'mesh' => '68007328',
'nlmcatalog' => '0404511',
'nuccore' => '1322283',
'nucest' => '338968657',
'nucgss' => '168803471',
'nucleotide' => '1322283',
'omia' => '1920',
'omim' => '176730',
'pcassay' => '1901',
'pccompound' => '16132302',
'pcsubstance' => '126522451',
'pmc' => '209839',
'popset' => '27228303',
'probe' => '9997691',
'protein' => '4557671',
'proteinclusters' => '2945638',
'pubmed' => '2539356',
'pubmedhealth' => '27364',
'seqannot' => '9561',
'snp' => '137853337',
'sra' => '190091',
'structure' => '61024',
'taxonomy' => '562',
'unigene' => '1132160',
);
if ( defined $zeroUidHash{$db} ) {
$val = $zeroUidHash{$db};
}
# return $val below to restore debugging test
return 0;
}
# support for substitution of (#keyword) to full query phrase or URL component
sub map_labels {
my $qury = shift (@_);
if ( $query !~ /\(#/ ) {
return $qury;
}
if ( scalar (keys %labels) > 0 ) {
for ( keys %labels ) {
$ky = $_;
$vl = $labels{$_};
$qury =~ s/\((#$ky)\)/\($vl#\)/g;
}
$qury =~ s/\((\w+)#\)/\(#$1\)/g;
}
return $qury;
}
sub map_macros {
my $qury = shift (@_);
if ( $qury !~ /\(#/ ) {
return $qury;
}
if ( scalar (keys %macros) > 0 ) {
for ( keys %macros ) {
$ky = $_;
$vl = $macros{$_};
$qury =~ s/\((\#$ky)\)/$vl/g;
}
}
return $qury;
}
sub read_aliases {
if ( $alias ne "" ) {
if (open (my $PROXY_IN, $alias)) {
while ( $thisline = <$PROXY_IN> ) {
$thisline =~ s/\r//;
$thisline =~ s/\n//;
$thisline =~ s/ +/ /g;
$thisline =~ s/> </></g;
if ( $thisline =~ /(.+)\t(.+)/ ) {
$ky = $1;
$vl = $2;
$vl =~ s/\"//g;
$macros{"$ky"} = "$vl";
}
}
close ($PROXY_IN);
} else {
print STDERR "Unable to open alias file '$alias'\n";
}
}
}
# base EUtils URL can be overridden for access to test versions of server
sub adjust_base {
if ( $basx eq "" ) {
# if base not overridden, check URL of previous query, stick with main or colo site,
# since history server data for EUtils does not copy between locations, by design
if ( $web ne "" and $web =~ /NCID_\d+_\d+_(\d+)\.\d+\.\d+\.\d+_\d+_\d+_\d+/ ) {
if ( $1 == 130 ) {
$base = "https://eutils.be-md.ncbi.nlm.nih.gov/entrez/eutils/";
} elsif ( $1 == 165 ) {
$base = "https://eutils.st-va.ncbi.nlm.nih.gov/entrez/eutils/";
}
}
return;
}
# shortcut for eutilstest base
if ( $basx eq "test" ) {
$basx = "https://eutilstest.ncbi.nlm.nih.gov/entrez/eutils";
}
if ( $basx =~ /\(#/ ) {
$basx = map_macros ($basx);
}
if ( $basx !~ /^https:\/\// ) {
$basx = "https://" . $basx;
}
if ( $basx !~ /\/$/ ) {
$basx .= "/";
}
if ( $basx !~ /\/entrez\/eutils\/$/ ) {
$basx .= "entrez/eutils/";
}
$base = $basx;
}
# ensure that ENTREZ_DIRECT data structure contains required fields
sub test_edirect {
my $dbsx = shift (@_);
my $webx = shift (@_);
my $keyx = shift (@_);
my $numx = shift (@_);
my $label = shift (@_);
if ( $dbsx eq "" ) {
close (STDOUT);
die "Db value not found in $label input\n";
}
if ( $webx eq "" ) {
close (STDOUT);
die "WebEnv value not found in $label input\n";
}
if ( $keyx eq "" ) {
close (STDOUT);
die "QueryKey value not found in $label input\n";
}
if ( $numx eq "" ) {
close (STDOUT);
die "Count value not found in $label input\n";
}
}
sub get_email {
# adapted from code provided by Aaron Ucko
my $addr = "";
if (defined $ENV{EMAIL}) {
$addr = $ENV{EMAIL};
} else {
# Failing that, try to combine the username from USER or whoami
# with the contents of /etc/mailname if available or the system's
# qualified host name. (Its containing domain may be a better
# choice in many cases, but anyone contacting abusers can extract
# it if necessary.)
my $lhs = $ENV{USER} || `whoami`;
my $rhs = "";
if (-r '/etc/mailname') {
$rhs = `cat /etc/mailname`;
} else {
my @uname = POSIX::uname();
$rhs = $uname[1];
if ($rhs !~ /\./) {
# clearly unqualified, try to resolve back and forth
my $h = gethostbyname($rhs);
if (defined $h && $h->name =~ /\./) {
$rhs = $h->name;
}
}
}
$addr = $lhs . '@' . $rhs;
}
return $addr;
}
# elink and epost currently need a separate ESearch to get the correct result count
sub get_count {
my $dbsx = shift (@_);
my $webx = shift (@_);
my $keyx = shift (@_);
my $tulx = shift (@_);
my $emlx = shift (@_);
test_edirect ( $dbsx, $webx, $keyx, "1", "count" );
$url = $base . $esearch;
$url .= "?db=$dbsx&query_key=$keyx&WebEnv=$webx";
$url .= "&retmax=0&usehistory=y";
$url .= "&edirect=$version";
if ( $os ne "" ) {
$url .= "&os=$os";
}
if ( $api_key ne "" ) {
$url .= "&api_key=$api_key";
}
if ( $tulx eq "" ) {
$tulx = "entrez-direct";
}
if ( $tulx ne "" ) {
$tulx =~ s/\s+/\+/g;
$url .= "&tool=$tulx-count";
}
if ( $emlx eq "" ) {
$emlx = get_email ();
}
if ( $emlx ne "" ) {
$emlx =~ s/\s+/\+/g;
$url .= "&email=$emlx";
}
$keyx = "";
$numx = "";
$errx = "";
$output = get ($url);
if ( $output eq "" ) {
print STDERR "No get_count output returned from '$url'\n";
}
if ( $debug ) {
print STDERR "$output\n";
}
$keyx = $1 if ($output =~ /<QueryKey>(\S+)<\/QueryKey>/);
$numx = $1 if ($output =~ /<Count>(\S+)<\/Count>/);
$errx = $1 if ($output =~ /<Error>(.+?)<\/Error>/i);
if ( $errx ne "" ) {
close (STDOUT);
die "ERROR in count output: $errx\nURL: $url\n\n";
}
if ( $numx eq "" ) {
die "Count value not found in count output - WebEnv $webx\n";
}
return $numx, $keyx;
}
sub get_uids {
my @working = ();
my $dbsx = shift (@_);
my $webx = shift (@_);
my $keyx = shift (@_);
my $sttx = shift (@_);
my $chkx = shift (@_);
my $numx = shift (@_);
my $tulx = shift (@_);
my $emlx = shift (@_);
test_edirect ( $dbsx, $webx, $keyx, $numx, "uids" );
# adjust retmax if -stop has been overridden
# e.g., efetch -format uid -start 2 -stop 9
if ( $sttx + $chkx > $numx ) {
$chkx = $numx - $sttx;
}
$url = $base . $esearch . "?db=$dbsx&query_key=$keyx&WebEnv=$webx";
$url .= "&rettype=uilist&retmode=text";
$url .= "&retstart=$sttx&retmax=$chkx";
$url .= "&edirect=$version";
if ( $os ne "" ) {
$url .= "&os=$os";
}
if ( $api_key ne "" ) {
$url .= "&api_key=$api_key";
}
if ( $tulx eq "" ) {
$tulx = "edirect";
}
if ( $tulx ne "" ) {
$tulx =~ s/\s+/\+/g;
$url .= "&tool=$tulx";
}
if ( $emlx eq "" ) {
$emlx = get_email ();
}
if ( $emlx ne "" ) {
$emlx =~ s/\s+/\+/g;
$url .= "&email=$emlx";
}
if ( $debug ) {
print STDERR "$url\n";
}
$data = get ($url);
if ( $data eq "" ) {
print STDERR "No get_uids output returned from '$url'\n";
}
if ( $debug ) {
print STDERR "$data\n";
}
my @ids = ($data =~ /<Id>(\d+)<\/Id>/g);
foreach $uid (@ids) {
push (@working, $uid);
}
return @working;
}
# send actual query
sub do_post_yielding_ref {
my $urlx = shift (@_);
my $argx = shift (@_);
my $tulx = shift (@_);
my $emlx = shift (@_);
my $intr = shift (@_);
if ( $os ne "" ) {
$argx .= "&os=$os";
}
if ( $api_key ne "" ) {
$argx .= "&api_key=$api_key";
}
$argx .= "&edirect=$version";
if ( $intr ) {
if ( $tulx eq "" ) {
$tulx = "edirect";
}
if ( $tulx ne "" ) {
$tulx =~ s/\s+/\+/g;
$argx .= "&tool=$tulx";
}
if ( $emlx eq "" ) {
$emlx = get_email ();
}
if ( $emlx ne "" ) {
$emlx =~ s/\s+/\+/g;
$argx .= "&email=$emlx";
}
}
my $empty = '';
$rslt = \$empty;
if ( $debug or $log ) {
print STDERR "$urlx?$argx\n";
}
if ( $http eq "get" or $http eq "GET" ) {
if ( $argx ne "" ) {
$urlx .= "?";
$urlx .= "$argx";
}
$rslt = get ($urlx);
if ( $rslt eq "" ) {
print STDERR "No do_get output returned from '$urlx'\n";
}
if ( $debug ) {
print STDERR "$rslt\n";
}
return \$rslt;
}
$usragnt = new LWP::UserAgent (timeout => 300);
$usragnt->env_proxy;
$req = new HTTP::Request POST => "$urlx";
$req->content_type('application/x-www-form-urlencoded');
$req->content("$argx");
$res = $usragnt->request ( $req );
if ( $res->is_success) {
$rslt = $res->content_ref;
} else {
print STDERR $res->status_line . "\n";
}
if ( $$rslt eq "" ) {
if ( $argx ne "" ) {
$urlx .= "?";
$urlx .= "$argx";
}
print STDERR "No do_post output returned from '$urlx'\n";
print STDERR "Result of do_post http request is\n";
print STDERR Dumper($res);
print STDERR "\n";
}
if ( $debug ) {
print STDERR $$rslt, "\n";
}
return $rslt;
}
sub do_post {
my $rslt = do_post_yielding_ref(@_);
return $$rslt;
}
# read ENTREZ_DIRECT data structure
sub read_edirect {
my $dbsx = "";
my $webx = "";
my $keyx = "";
my $numx = "";
my $stpx = "";
my $errx = "";
my $tulx = "";
my $emlx = "";
my $inlabel = false;
my $inmacro = false;
my $ky = "";
my $vl = "";
@other = ();
$has_num = false;
$all_num = true;
while ( defined($thisline = <STDIN>) ) {
$thisline =~ s/\r//;
$thisline =~ s/\n//;
$thisline =~ s/^\s+//;
$thisline =~ s/\s+$//;
if ( $thisline =~ /<Labels>/ ) {
$inlabel = true;
} elsif ( $thisline =~ /<\/Labels>/ ) {
$inlabel = false;
} elsif ( $thisline =~ /<Macros>/ ) {
$inmacro = true;
} elsif ( $thisline =~ /<\/Macros>/ ) {
$inmacro = false;
} elsif ( $inlabel ) {
if ( $thisline =~ /<Label>/ ) {
$ky = "";
$vl = "";
} elsif ( $thisline =~ /<\/Label>/ ) {
if ( $vl ne "" and $ky ne "" ) {
$labels{"$ky"} = "$vl";
}
} elsif ( $thisline =~ /<Key>(.+)<\/Key>/ ) {
$ky = $1;
} elsif ( $thisline =~ /<Val>(.+)<\/Val>/ ) {
$vl = $1;
}
} elsif ( $inmacro ) {
if ( $thisline =~ /<Macro>/ ) {
$ky = "";
$vl = "";
} elsif ( $thisline =~ /<\/Macro>/ ) {
if ( $vl ne "" and $ky ne "" ) {
$macros{"$ky"} = "$vl";
}
} elsif ( $thisline =~ /<Key>(.+)<\/Key>/ ) {
$ky = $1;
} elsif ( $thisline =~ /<Val>(.+)<\/Val>/ ) {
$vl = $1;
}
} elsif ( $thisline =~ /<Db>(\S+)<\/Db>/ ) {
$dbsx = $1;
} elsif ( $thisline =~ /<WebEnv>(\S+)<\/WebEnv>/ ) {
$webx = $1;
} elsif ( $thisline =~ /<QueryKey>(\S+)<\/QueryKey>/ ) {
$keyx = $1;
} elsif ( $thisline =~ /<Count>(\S+)<\/Count>/ ) {
$numx = $1;
} elsif ( $thisline =~ /<Step>(\S+)<\/Step>/ ) {
$stpx = $1 + 1;
} elsif ( $thisline =~ /<Error>(.+?)<\/Error>/i ) {
$errx = $1;
} elsif ( $thisline =~ /<Tool>(.+?)<\/Tool>/i ) {
$tulx = $1;
} elsif ( $thisline =~ /<Email>(.+?)<\/Email>/i ) {
$emlx = $1;
} elsif ( $thisline =~ /<Silent>Y<\/Silent>/i ) {
$silent = true;
} elsif ( $thisline =~ /<Silent>N<\/Silent>/i ) {
$silent = false;
} elsif ( $thisline =~ /<Verbose>Y<\/Verbose>/i ) {
$verbose = true;
} elsif ( $thisline =~ /<Verbose>N<\/Verbose>/i ) {
$verbose = false;
} elsif ( $thisline =~ /<Debug>Y<\/Debug>/i ) {
$debug = true;
$silent = false;
} elsif ( $thisline =~ /<Debug>N<\/Debug>/i ) {
$debug = false;
} elsif ( $thisline =~ /<Log>Y<\/Log>/i ) {
$log = true;
} elsif ( $thisline =~ /<Log>N<\/Log>/i ) {
$log = false;
} elsif ( $thisline =~ /<ENTREZ_DIRECT>/i ) {
} elsif ( $thisline =~ /<\/ENTREZ_DIRECT>/i ) {
} elsif ( $thisline =~ /<Labels>/i ) {
} elsif ( $thisline =~ /<\/Labels>/i ) {
} elsif ( $thisline =~ /<Macros>/i ) {
} elsif ( $thisline =~ /<\/Macros>/i ) {
} elsif ( $thisline =~ /^(\d+)$/ ) {
push (@other, $1);
$has_num = true;
} elsif ( $thisline =~ /^(.+)$/ ) {
push (@other, $1);
$all_num = false;
}
}
return ( $dbsx, $webx, $keyx, $numx, $stpx, $errx,
$tulx, $emlx, $has_num && $all_num, @other );
}
# write ENTREZ_DIRECT data structure
sub write_edirect {
my $dbsx = shift (@_);
my $webx = shift (@_);
my $keyx = shift (@_);
my $numx = shift (@_);
my $stpx = shift (@_);
my $errx = shift (@_);
my $tulx = shift (@_);
my $emlx = shift (@_);
my $seconds = "";
my $end_time = Time::HiRes::time();
my $elapsed = $end_time - $begin_time;
if ( $elapsed > 0.0005 ) {
if ( $elapsed =~ /(\d+)\.(\d\d\d)\d+/ ) {
$seconds = "$1.$2";
}
}
if ( $stpx eq "" and $webx ne "" ) {
$stpx = "1";
}
if ( $tulx ne "" ) {
$tulx =~ s/\s+/\+/g;
}
if ( $emlx ne "" ) {
$emlx =~ s/\s+/\+/g;
}
if ( $verbose ) {
print STDERR "\n";
print STDERR "edirutil";
if ( $dbsx ne "" ) {
print STDERR " -db $dbsx";
}
if ( $webx ne "" ) {
print STDERR " -web $webx";
}
if ( $keyx ne "" ) {
print STDERR " -key $keyx";
}
if ( $numx ne "" ) {
print STDERR " -count $numx";
}
if ( $stpx ne "" ) {
print STDERR " -step $stpx";
}
if ( $seconds ne "" ) {
print STDERR " -seconds $seconds";
}
print STDERR "\n\n";
}
if ( false ) {
print STDERR "\n";
print STDERR "<ENTREZ_DIRECT>\n";
if ( $dbsx ne "" ) {
print STDERR " <Db>$dbsx</Db>\n";
}
if ( $webx ne "" ) {
print STDERR " <WebEnv>$webx</WebEnv>\n";
}
if ( $keyx ne "" ) {
print STDERR " <QueryKey>$keyx</QueryKey>\n";
}
if ( $numx ne "" ) {
print STDERR " <Count>$numx</Count>\n";
}
if ( $stpx ne "" ) {
print STDERR " <Step>$stpx</Step>\n";
}
if ( $errx ne "" ) {
print STDERR " <Error>$errx</Error>\n";
}
if ( $tulx ne "" ) {
print STDERR " <Tool>$tulx</Tool>\n";
}
if ( $emlx ne "" ) {
print STDERR " <Email>$emlx</Email>\n";
}
print STDERR "</ENTREZ_DIRECT>\n";
print STDERR "\n";
}
print "<ENTREZ_DIRECT>\n";
if ( $dbsx ne "" ) {
print " <Db>$dbsx</Db>\n";
}
if ( $webx ne "" ) {
print " <WebEnv>$webx</WebEnv>\n";
}
if ( $keyx ne "" ) {
print " <QueryKey>$keyx</QueryKey>\n";
}
if ( $numx ne "" ) {
print " <Count>$numx</Count>\n";
}
if ( $stpx ne "" ) {
print " <Step>$stpx</Step>\n";
}
if ( $errx ne "" ) {
print " <Error>$errx</Error>\n";
}
if ( $tulx ne "" ) {
print " <Tool>$tulx</Tool>\n";
}
if ( $emlx ne "" ) {
print " <Email>$emlx</Email>\n";
}
if ( $silent ) {
print " <Silent>Y</Silent>\n";
}
if ( $verbose ) {
print " <Verbose>Y</Verbose>\n";
}
if ( $debug ) {
print " <Debug>Y</Debug>\n";
}
if ( $log ) {
print " <Log>Y</Log>\n";
}
if ( scalar (keys %labels) > 0 ) {
print " <Labels>\n";
for ( keys %labels ) {
print " <Label>\n";
print " <Key>$_</Key>\n";
print " <Val>$labels{$_}</Val>\n";
print " </Label>\n";
}
print " </Labels>\n";
}
if ( scalar (keys %macros) > 0 ) {
print " <Macros>\n";
for ( keys %macros ) {
print " <Macro>\n";
print " <Key>$_</Key>\n";
print " <Val>$macros{$_}</Val>\n";
print " </Macro>\n";
}
print " </Macros>\n";
}
print "</ENTREZ_DIRECT>\n";
}
# wrapper to detect command line errors
sub MyGetOptions {
my $help_msg = shift @_;
if ( !GetOptions(@_) ) {
die $help_msg;
} elsif (@ARGV) {
die ("Entrez Direct does not support positional arguments.\n"
. "Please remember to quote parameter values containing\n"
. "whitespace or shell metacharacters.\n");
}
}
# subroutines for each -function
# ecntc prepares the requested tool and email arguments for an EUtils pipe
my $cntc_help = qq{
-email Contact person's address
-tool Name of script or program
};
sub ecntc {
# ... | edirect.pl -contact -email darwin@beagle.edu -tool edirect_test | ...
clearflags ();
MyGetOptions(
$cntc_help,
"email=s" => \$emaddr,
"tool=s" => \$tuul,
"help" => \$help,
"silent" => \$silent,
"verbose" => \$verbose,
"debug" => \$debug,
"log" => \$log,
"http=s" => \$http,
"https=s" => \$http,
"alias=s" => \$alias,
"base=s" => \$basx
);
if ( $help ) {
print "econtact $version\n";
print $cntc_help;
return;
}
if ( -t STDIN and not @ARGV ) {
} else {
( $dbase, $web, $key, $num, $stp, $err, $tool, $email, $just_num, @rest ) = read_edirect ();
}
read_aliases ();
adjust_base ();
if ( $tuul ne "" ) {
$tool = $tuul;
}
if ( $emaddr ne "" ) {
$email = $emaddr;
}
write_edirect ( $dbase, $web, $key, $num, $stp, $err, $tool, $email );
}
# efilt performs ESearch query refinement on the EUtils history server
my $filt_help = qq{
Query Specification
-query Query string
Document Order
-sort Result presentation order
Date Constraint
-days Number of days in the past
-datetype Date field abbreviation
-mindate Start of date range
-maxdate End of date range
Limit by Field
-field Query words individually in field
-pairs Query overlapping word pairs
Spell Check
-spell Correct misspellings in query
Publication Filters
-pub abstract, clinical, english, free, historical,
journal, last_week, last_month, last_year,
preprint, review, structured
Sequence Filters
-feature gene, mrna, cds, mat_peptide, ...
-location mitochondrion, chloroplast, plasmid, plastid
-molecule genomic, mrna, trna, rrna, ncrna
-organism animals, archaea, bacteria, eukaryotes, fungi,
human, insects, mammals, plants, prokaryotes,
protists, rodents, viruses
-source genbank, insd, pdb, pir, refseq, swissprot, tpa
Gene Filters
-status alive
-type coding, pseudo
Miscellaneous Arguments
-label Alias for query step
};
sub process_extras {
my $frst = shift (@_);
my $publ = shift (@_);
my $fkey = shift (@_);
my $locn = shift (@_);
my $bmol = shift (@_);
my $orgn = shift (@_);
my $sorc = shift (@_);
my $stat = shift (@_);
my $gtyp = shift (@_);
$publ = lc($publ);
$fkey = lc($fkey);
$bmol = lc($bmol);
$locn = lc($locn);
$orgn = lc($orgn);
$sorc = lc($sorc);
$stat = lc($stat);
$gtyp = lc($gtyp);
%pubHash = (
'abstract' => 'has abstract [FILT]',
'clinical' => 'clinical trial [FILT]',
'english' => 'english [FILT]',
'free' => 'freetext [FILT]',
'historical' => 'historical article [FILT]',
'journal' => 'journal article [FILT]',
'last_month' => 'published last month [FILT]',
'last month' => 'published last month [FILT]',
'last_week' => 'published last week [FILT]',
'last week' => 'published last week [FILT]',
'last_year' => 'published last year [FILT]',
'last year' => 'published last year [FILT]',
'preprint' => 'ahead of print [FILT]',
'review' => 'review [FILT]',
'structured' => 'hasstructuredabstract [WORD]',
'trial' => 'clinical trial [FILT]',
);
@featureArray = (
"-10_signal",
"-35_signal",
"3'clip",
"3'utr",
"5'clip",
"5'utr",
"allele",
"assembly_gap",
"attenuator",
"c_region",
"caat_signal",
"cds",
"centromere",
"conflict",
"d_segment",
"d-loop",
"enhancer",
"exon",
"gap",
"gc_signal",
"gene",
"idna",
"intron",
"j_segment",
"ltr",
"mat_peptide",
"misc_binding",
"misc_difference",
"misc_feature",
"misc_recomb",
"misc_rna",
"misc_signal",
"misc_structure",
"mobile_element",
"modified_base",
"mrna",
"mutation",
"n_region",
"ncrna",
"old_sequence",
"operon",
"orit",
"polya_signal",
"polya_site",
"precursor_rna",
"prim_transcript",
"primer_bind",
"promoter",
"propeptide",
"protein_bind",
"rbs",
"regulatory",
"rep_origin",
"repeat_region",
"repeat_unit",
"rrna",
"s_region",
"satellite",
"scrna",
"sig_peptide",
"snorna",
"snrna",
"source",
"stem_loop",
"sts",
"tata_signal",
"telomere",
"terminator",
"tmrna",
"transit_peptide",
"trna",
"unsure",
"v_region",
"v_segment",
"variation"
);
%locationHash = (
'mitochondria' => 'mitochondrion [FILT]',
'mitochondrial' => 'mitochondrion [FILT]',
'mitochondrion' => 'mitochondrion [FILT]',
'chloroplast' => 'chloroplast [FILT]',
'plasmid' => 'plasmid [FILT]',
'plastid' => 'plastid [FILT]',
);
%moleculeHash = (
'genomic' => 'biomol genomic [PROP]',
'mrna' => 'biomol mrna [PROP]',
'trna' => 'biomol trna [PROP]',
'rrna' => 'biomol rrna [PROP]',
'ncrna' => 'biomol ncrna [PROP]',
);
%organismHash = (
'animal' => 'animals [FILT]',
'animals' => 'animals [FILT]',
'archaea' => 'archaea [FILT]',
'archaeal' => 'archaea [FILT]',
'archaean' => 'archaea [FILT]',
'archaebacteria' => 'archaea [FILT]',
'archaebacterial' => 'archaea [FILT]',
'bacteria' => 'bacteria [FILT]',
'bacterial' => 'bacteria [FILT]',
'bacterium' => 'bacteria [FILT]',
'eubacteria' => 'bacteria [FILT]',
'eubacterial' => 'bacteria [FILT]',
'eukaryota' => 'eukaryota [ORGN]',
'eukaryote' => 'eukaryota [ORGN]',
'eukaryotes' => 'eukaryota [ORGN]',
'fungal' => 'fungi [FILT]',
'fungi' => 'fungi [FILT]',
'fungus' => 'fungi [FILT]',
'human' => 'human [ORGN]',
'humans' => 'human [ORGN]',
'insect' => 'insecta [ORGN]',
'insecta' => 'insecta [ORGN]',
'insects' => 'insecta [ORGN]',
'mammal' => 'mammals [FILT]',
'mammalia' => 'mammals [FILT]',
'mammalian' => 'mammals [FILT]',
'mammals' => 'mammals [FILT]',
'man' => 'human [ORGN]',
'metaphyta' => 'plants [FILT]',
'metazoa' => 'animals [FILT]',
'monera' => 'prokaryota [ORGN]',
'plant' => 'plants [FILT]',
'plants' => 'plants [FILT]',
'prokaryota' => 'prokaryota [ORGN]',
'prokaryote' => 'prokaryota [ORGN]',
'prokaryotes' => 'prokaryota [ORGN]',
'protist' => 'protists [FILT]',
'protista' => 'protists [FILT]',
'protists' => 'protists [FILT]',
'rodent' => 'rodents [ORGN]',
'rodentia' => 'rodents [ORGN]',
'rodents' => 'rodents [ORGN]',
'viral' => 'viruses [FILT]',
'virus' => 'viruses [FILT]',
'viruses' => 'viruses [FILT]',
);
%sourceHash = (
'ddbj' => 'srcdb ddbj [PROP]',
'embl' => 'srcdb embl [PROP]',
'genbank' => 'srcdb genbank [PROP]',
'insd' => 'srcdb ddbj/embl/genbank [PROP]',
'pdb' => 'srcdb pdb [PROP]',
'pir' => 'srcdb pir [PROP]',
'refseq' => 'srcdb refseq [PROP]',
'swissprot' => 'srcdb swiss prot [PROP]',
'tpa' => 'srcdb tpa ddbj/embl/genbank [PROP]',
);
%statusHash = (
'alive' => 'alive [PROP]',
'live' => 'alive [PROP]',
'living' => 'alive [PROP]',
);
%typeHash = (
'coding' => 'genetype protein coding [PROP]',
'pseudo' => 'genetype pseudo [PROP]',
);
my @working = ();
if ( $frst ne "" ) {
push (@working, $frst);
}
if ( $publ ne "" ) {
if ( defined $pubHash{$publ} ) {
$val = $pubHash{$publ};
push (@working, $val);
} else {
die "\nUnrecognized -pub argument '$publ', use efilter -help to see available choices\n\n";
}
}
if ( $fkey ne "" ) {
if ( grep( /^$fkey$/, @featureArray ) ) {
$val = $fkey . " [FKEY]";
push (@working, $val);
} else {
die "\nUnrecognized -feature argument '$fkey', use efilter -help to see available choices\n\n";
}
}
if ( $locn ne "" ) {
if ( defined $locationHash{$locn} ) {
$val = $locationHash{$locn};
push (@working, $val);
} else {
die "\nUnrecognized -location argument '$locn', use efilter -help to see available choices\n\n";
}
}
if ( $bmol ne "" ) {
if ( defined $moleculeHash{$bmol} ) {
$val = $moleculeHash{$bmol};
push (@working, $val);
} else {
die "\nUnrecognized -molecule argument '$bmol', use efilter -help to see available choices\n\n";
}
}
if ( $orgn ne "" ) {
if ( defined $organismHash{$orgn} ) {
$val = $organismHash{$orgn};
push (@working, $val);
} else {
die "\nUnrecognized -organism argument '$orgn', use efilter -help to see available choices\n\n";
}
}
if ( $sorc ne "" ) {
if ( defined $sourceHash{$sorc} ) {
$val = $sourceHash{$sorc};
push (@working, $val);
} else {
die "\nUnrecognized -source argument '$sorc', use efilter -help to see available choices\n\n";
}
}
if ( $stat ne "" ) {
if ( defined $statusHash{$stat} ) {
$val = $statusHash{$stat};
push (@working, $val);
} else {
die "\nUnrecognized -status argument '$stat', use efilter -help to see available choices\n\n";
}
}
if ( $gtyp ne "" ) {
if ( defined $typeHash{$gtyp} ) {
$val = $typeHash{$gtyp};
push (@working, $val);
} else {
die "\nUnrecognized -type argument '$gtyp', use efilter -help to see available choices\n\n";
}
}
my $xtras = join (" AND ", @working);
return $xtras;
}
# correct misspellings in query
sub spell_check_query {
my $db = shift (@_);
my $qury = shift (@_);
my $url = $base . $espell;
my $enc = uri_escape($query);
$arg = "db=$db&term=$enc";
my $data = do_post ($url, $arg, $tool, $email, true);
Encode::_utf8_on($data);
$qury = $1 if ( $data =~ /<CorrectedQuery>(.+)<\/CorrectedQuery>/ );
return $qury;
}
sub efilt {
# ... | edirect.pl -filter -query "bacteria [ORGN]" -days 365 | ...
clearflags ();
MyGetOptions(
$filt_help,
"query=s" => \$query,
"sort=s" => \$sort,
"days=i" => \$rldate,
"mindate=s" => \$mndate,
"maxdate=s" => \$mxdate,
"datetype=s" => \$dttype,
"label=s" => \$lbl,
"field=s" => \$field,
"spell" => \$spell,
"pairs=s" => \$pair,
"pub=s" => \$pub,
"feature=s" => \$feature,
"location=s" => \$location,
"molecule=s" => \$molecule,
"organism=s" => \$organism,
"source=s" => \$source,
"status=s" => \$status,
"type=s" => \$gtype,
"api_key=s" => \$api_key,
"email=s" => \$emaddr,
"tool=s" => \$tuul,
"help" => \$help,
"silent" => \$silent,
"verbose" => \$verbose,
"debug" => \$debug,
"log" => \$log,
"http=s" => \$http,
"https=s" => \$http,
"alias=s" => \$alias,
"base=s" => \$basx
);
if ( $help ) {
print "efilter $version\n";
print $filt_help;
return;
}
# process special filter flags, add to query string
$query = process_extras ( $query, $pub, $feature, $location, $molecule, $organism, $source, $status, $gtype );
if ( -t STDIN ) {
if ( $query eq "" ) {
die "Must supply -query or -days or -mindate and -maxdate arguments on command line\n";
}
print "efilter -query \"$query\"\n";
return;
}
( $dbase, $web, $key, $num, $stp, $err, $tool, $email, $just_num, @rest ) = read_edirect ();
read_aliases ();
adjust_base ();
if ( $err ne "" ) {
write_edirect ( "", "", "", "", "", $err, "", "" );
close (STDOUT);
if ( ! $silent ) {
die "ERROR in filt input: $err\n\n";
}
return;
}
if ( $tuul ne "" ) {
$tool = $tuul;
}
if ( $emaddr ne "" ) {
$email = $emaddr;
}
if ( $query eq "" && $rldate < 1 and $mndate eq "" and $mxdate eq "" ) {
die "Must supply -query or -days or -mindate and -maxdate arguments on command line\n";
}
binmode STDOUT, ":utf8";
if ( $dbase ne "" and $web ne "" and $key eq "" and $num eq "0" ) {
write_edirect ( $dbase, $web, $key, $num, $stp, $err, $tool, $email );
close (STDOUT);
die "QueryKey value not found in filter input\n";
return;
}
# warn on mismatch between filter argument and database
if ( $dbase ne "pubmed" ) {
if ( $pub ne "" ) {
print STDERR "\nUnexpected use of pubmed filter argument\n\n";
}
}
if ( $dbase ne "nucleotide" and
$dbase ne "nuccore" and
$dbase ne "est" and
$dbase ne "gss" and
$dbase ne "protein" ) {
if ( $feature ne "" or
$location ne "" or
$molecule ne "" or
$organism ne "" or
$source ne "" ) {
print STDERR "\nUnexpected use of sequence filter argument\n\n";
}
}
test_edirect ( $dbase, $web, $key, $num, "filter" );
# -field combines -drop and -split (-field TITL produces same behavior as Web PubMed)
if ( $field ne "" ) {
$query = remove_stop_words ($query);
$query = field_each_word ($field, $query);
}
# -pairs separately fields query word pairs, breaking chain at stop words
if ( $pair ne "" ) {
$query = remove_punctuation ($query);
if ( $query =~ /^ +(.+)$/ ) {
$query = $1;
}
if ( $query =~ /^(.+) +$/ ) {
$query = $1;
}
$query =~ s/ +/ /g;
$query = field_each_pair ($pair, $query);
}
# spell check each query word
if ( $spell ) {
$query = spell_check_query ($dbase, $query);
}
$url = $base . $esearch;
$arg = "db=$dbase&query_key=$key&WebEnv=$web";
if ( $sort ne "" ) {
$arg .= "&sort=$sort";
}
$arg .= "&retmax=0&usehistory=y";
if ( $query ne "" ) {
$query = map_labels ($query);
$query = map_macros ($query);
$enc = uri_escape($query);
$arg .= "&term=$enc";
}
if ( $rldate > 0 ) {
$arg .= "&reldate=$rldate";
if ( $dttype eq "" ) {
$dttype = "PDAT";
}
}
if ( $mndate ne "" and $mxdate ne "" ) {
$arg .= "&mindate=$mndate&maxdate=$mxdate";
if ( $dttype eq "" ) {
$dttype = "PDAT";
}
}
if ( $dttype ne "" ) {
$arg .= "&datetype=$dttype";
}
$wb = $web;
$web = "";
$key = "";
$num = "";
$err = "";
my $trn = "";
$output = "";
for ( $tries = 0; $tries < 3 && $web eq ""; $tries++) {
$output = do_post ($url, $arg, $tool, $email, true);
$err = $1 if ($output =~ /<Error>(.+?)<\/Error>/i);
if ( $err eq "" ) {
$web = $1 if ($output =~ /<WebEnv>(\S+)<\/WebEnv>/);
$key = $1 if ($output =~ /<QueryKey>(\S+)<\/QueryKey>/);
$num = $1 if ($output =~ /<Count>(\S+)<\/Count>/);
$trn = $1 if ($output =~ /<QueryTranslation>(.+?)<\/QueryTranslation>/i);
} else {
if ( ! $silent ) {
print STDERR "Retrying efilter, step $stp: $err\n";
}
sleep 3;
}
}
if ( $err ne "" ) {
write_edirect ( "", "", "", "", "", $err, "", "" );
close (STDOUT);
if ( ! $silent) {
die "ERROR in filt output: $err\nURL: $arg\nResult: $output\n\n";
}
return;
}
if ( $web eq "" ) {
die "WebEnv value not found in filt output - WebEnv1 $wb\n";
}
if ( $key eq "" ) {
die "QueryKey value not found in filt output - WebEnv1 $wb\n";
}
if ( $web ne $wb ) {
$err = "WebEnv mismatch in filt output - WebEnv1 $wb, WebEnv2 $web";
write_edirect ( "", $wb, "", "", "", $err, "", "" );
close (STDOUT);
die "WebEnv value changed in filt output - WebEnv1 $wb\nWebEnv2 $web\n";
}
if ( $num eq "" ) {
die "Count value not found in filt output - WebEnv1 $wb\n";
}
if ( $lbl ne "" and $key ne "" ) {
$labels{"$lbl"} = "$key";
}
write_edirect ( $dbase, $web, $key, $num, $stp, $err, $tool, $email );
if ( $log ) {
if ( $trn ne "" ) {
print STDERR "$trn\n";
}
}
}
# efetch -format docsum calls esmry to retrieve document summaries
sub fix_mixed_content {
my $x = shift (@_);
while ( $x =~ /\&\;/ || $x =~ /\<\;/ || $x =~ /\>\;/ ) {
HTML::Entities::decode_entities($x);
}
# removed mixed content tags
$x =~ s|<b>||g;
$x =~ s|<i>||g;
$x =~ s|<u>||g;
$x =~ s|<sup>||g;
$x =~ s|<sub>||g;
$x =~ s|</b>||g;
$x =~ s|</i>||g;
$x =~ s|</u>||g;
$x =~ s|</sup>||g;
$x =~ s|</sub>||g;
$x =~ s|<b/>||g;
$x =~ s|<i/>||g;
$x =~ s|<u/>||g;
$x =~ s|<sup/>||g;
$x =~ s|<sub/>||g;
# Reencode any resulting less-than or greater-than entities to avoid breaking the XML.
$x =~ s/</</g;
$x =~ s/>/>/g;
return $x;
}
my %fields_to_fix = (
'biosample' => ['SampleData'],
'medgen' => ['ConceptMeta'],
'sra' => ['ExpXml', 'Runs']
);
sub fix_one_encoding {
my $dbase = shift (@_);
my $data = shift (@_);
if ( $dbase eq "pubmed" ) {
if ( $data =~ /<Title>(.+?)<\/Title>/ ) {
my $x = $1;
if ( $x =~ /\&\;/ || $x =~ /\<\;/ || $x =~ /\>\;/ ) {
$x = fix_mixed_content($x);
$data =~ s/<Title>(.+?)<\/Title>/<Title>$x<\/Title>/;
}
}
} elsif ( $dbase eq "gene" ) {
if ( $data =~ /<Summary>(.+?)<\/Summary>/ ) {
my $x = $1;
if ( $x =~ /\&\;/ ) {
HTML::Entities::decode_entities($x);
# Reencode any resulting less-than or greater-than entities to avoid breaking the XML.
$x =~ s/</</g;
$x =~ s/>/>/g;
$data =~ s/<Summary>(.+?)<\/Summary>/<Summary>$x<\/Summary>/;
}
}
# $data =~ s/(\s+?)<ChrStart>(\d+)<\/ChrStart>/$1<ChrStart>$2<\/ChrStart>$1<SeqStart>${\($2 + 1)}<\/SeqStart>/g;
# $data =~ s/(\s+?)<ChrStop>(\d+)<\/ChrStop>/$1<ChrStop>$2<\/ChrStop>$1<SeqStop>${\($2 + 1)}<\/SeqStop>/g;
} elsif ( $dbase eq "assembly" ) {
if ( $data =~ /<Meta>(.+?)<\/Meta>/ ) {
my $x = $1;
if ( $x =~ /<!\[CDATA\[\s*(.+?)\s*\]\]>/ ) {
$x = $1;
if ( $x =~ /</ and $x =~ />/ ) {
# If CDATA contains embedded XML, simply remove CDATA wrapper
$data =~ s/<Meta>(.+?)<\/Meta>/<Meta>$x<\/Meta>/;
}
}
}
} elsif (defined $fields_to_fix{$dbase}) {
foreach $f (@{$fields_to_fix{$dbase}}) {
if ( $data =~ /<$f>(.+?)<\/$f>/ ) {
my $x = $1;
if ( $x =~ /\<\;/ and $x =~ /\>\;/ ) {
HTML::Entities::decode_entities($x);
$data =~ s/<$f>(.+?)<\/$f>/<$f>$x<\/$f>/;
}
}
}
}
return $data;
}
sub fix_bad_encoding {
my $dbase = shift (@_);
my $data = shift (@_);
if ( $dbase eq "pubmed" || $dbase eq "gene" || $dbase eq "assembly" || defined $fields_to_fix{$dbase} ) {
my @accum = ();
my @working = ();
my $prefix = "";
my $suffix = "";
my $docsumset_attrs = '';
if ( $data =~ /(.+?)<DocumentSummarySet(\s+.+?)?>(.+)<\/DocumentSummarySet>(.+)/s ) {
$prefix = $1;
$docsumset_attrs = $2;
my $docset = $3;
$suffix = $4;
my @vals = ($docset =~ /<DocumentSummary>(.+?)<\/DocumentSummary>/sg);
foreach $val (@vals) {
push (@working, "<DocumentSummary>");
push (@working, fix_one_encoding ( $dbase, $val) );
push (@working, "</DocumentSummary>");
}
}
if ( scalar @working > 0 ) {
push (@accum, $prefix);
push (@accum, "<DocumentSummarySet$docsumset_attrs>");
push (@accum, @working);
push (@accum, "</DocumentSummarySet>");
push (@accum, $suffix);
$data = join ("\n", @accum);
$data =~ s/\n\n/\n/g;
}
}
return $data;
}
sub esmry {
my $dbase = shift (@_);
my $web = shift (@_);
my $key = shift (@_);
my $num = shift (@_);
my $id = shift (@_);
my $mode = shift (@_);
my $min = shift (@_);
my $max = shift (@_);
my $tool = shift (@_);
my $email = shift (@_);
my $silent = shift (@_);
my $verbose = shift (@_);
my $debug = shift (@_);
my $log = shift (@_);
my $http = shift (@_);
my $alias = shift (@_);
my $basx = shift (@_);
$dbase = lc($dbase);
if ( $dbase ne "" and $id ne "" ) {
if ( $id eq "0" ) {
# id "0" returns a live UID for any database
$id = get_zero_uid ($dbase);
if ( $id eq "0" ) {
# id "0" is an unrecognized accession
return;
}
}
$url = $base . $esummary;
$arg = "db=$dbase&id=$id";
$arg .= "&version=2.0";
if ( $mode ne "" and $mode ne "text" ) {
$arg .= "&retmode=$mode";
}
$data = do_post ($url, $arg, $tool, $email, true);
if ($data =~ /<eSummaryResult>/i and $data =~ /<ERROR>(.+?)<\/ERROR>/i) {
$err = $1;
if ( $err ne "" ) {
if ( ! $silent ) {
print STDERR "ERROR in esummary: $err\n";
}
}
if ( $err =~ "Invalid uid" ) {
# remove Invalid uid error message from XML
$data =~ s/<ERROR>.+?<\/ERROR>//g;
} else {
return;
}
}
$data =~ s/<DocumentSummary uid=\"(\d+)\">/<DocumentSummary><Id>$1<\/Id>/g;
Encode::_utf8_on($data);
if (! $raw) {
$data = fix_bad_encoding($dbase, $data);
}
# remove eSummaryResult wrapper
$data =~ s/<!DOCTYPE eSummaryResult PUBLIC/<!DOCTYPE DocumentSummarySet PUBLIC/g;
$data =~ s/<eSummaryResult>//g;
$data =~ s/<\/eSummaryResult>//g;
print "$data";
return;
}
if ( $dbase ne "" and $web ne "" and $key eq "" and $num eq "0" ) {
die "QueryKey value not found in summary input\n";
return;
}
test_edirect ( $dbase, $web, $key, $num, "summary" );
$stpminusone = $stp - 1;
if ( $max == 0 ) {
if ( $silent ) {
return;
}
}
# use larger chunk for document summaries
$chunk = 1000;
for ( $start = $min; $start < $max; $start += $chunk ) {
$url = $base . $esummary;
$chkx = $chunk;
if ( $start + $chkx > $max ) {
$chkx = $max - $start;
}
$arg = "db=$dbase&query_key=$key&WebEnv=$web";
$arg .= "&retstart=$start&retmax=$chkx&version=2.0";
if ( $mode ne "" and $mode ne "text" ) {
$arg .= "&retmode=$mode";
}
$data = "";
$retry = true;
for ( $tries = 0; $tries < 3 && $retry; $tries++) {
$data = do_post ($url, $arg, $tool, $email, true);
if ($data =~ /<eSummaryResult>/i and $data =~ /<ERROR>(.+?)<\/ERROR>/i ) {
if ( ! $silent ) {
print STDERR "Retrying esummary, step $stp: $err\n";
}
sleep 3;
} else {
$retry = false;
}
}
if ($data =~ /<eSummaryResult>/i and $data =~ /<ERROR>(.+?)<\/ERROR>/i) {
$err = $1;
if ( $err ne "" ) {
if ( ! $silent ) {
my $from = $start + 1;
my $to = $start + $chunk;
if ( $to > $max ) {
$to = $max;
}
print STDERR "ERROR in esummary ($from-$to / $max): $err\n";
print STDERR "Replicate for debugging with:\n";
print STDERR " edirutil -db $dbase -web $web -key $key -count $num";
if ( $stpminusone > 0 ) {
print STDERR " -step $stpminusone";
}
my $seconds = "";
my $end_time = Time::HiRes::time();
my $elapsed = $end_time - $begin_time;
if ( $elapsed > 0.0005 ) {
if ( $elapsed =~ /(\d+)\.(\d\d\d)\d+/ ) {
$seconds = "$1.$2";
}
}
if ( $seconds ne "" ) {
print STDERR " -seconds $seconds";
}
print STDERR " | efetch -format docsum -start $from -stop $to\n";
}
}
} else {
if ( $verbose ) {
my $from = $start + 1;
my $to = $start + $chunk;
if ( $to > $max ) {
$to = $max;
}
print STDERR "( edirutil -db $dbase -web $web -key $key -count $num";
if ( $stpminusone > 0 ) {
print STDERR " -step $stpminusone";
}
my $seconds = "";
my $end_time = Time::HiRes::time();
my $elapsed = $end_time - $begin_time;
if ( $elapsed > 0.0005 ) {
if ( $elapsed =~ /(\d+)\.(\d\d\d)\d+/ ) {
$seconds = "$1.$2";
}
}
if ( $seconds ne "" ) {
print STDERR " -seconds $seconds";
}
print STDERR " | efetch -format docsum -start $from -stop $to )\n";
$begin_time = $end_time;
}
$data =~ s/<DocumentSummary uid=\"(\d+)\">/<DocumentSummary><Id>$1<\/Id>/g;
Encode::_utf8_on($data);
if (! $raw) {
$data = fix_bad_encoding($dbase, $data);
}
# remove eSummaryResult wrapper
$data =~ s/<!DOCTYPE eSummaryResult PUBLIC/<!DOCTYPE DocumentSummarySet PUBLIC/g;
$data =~ s/<eSummaryResult>//g;
$data =~ s/<\/eSummaryResult>//g;
print "$data";
}
sleep 1;
}
}
# eftch can read all arguments from the command line or participate in an EUtils pipe
my $ftch_help = qq{
Format Selection
-format Format of record or report
-mode text, xml, asn.1, json
Direct Record Selection
-db Database name
-id Unique identifier or accession number
Sequence Range
-seq_start First sequence position to retrieve
-seq_stop Last sequence position to retrieve
-strand Strand of DNA to retrieve
Gene Range
-chr_start Sequence range from 0-based coordinates
-chr_stop in gene docsum GenomicInfoType object
Miscellaneous
-complexity 0 = default, 1 = bioseq, 3 = nuc-prot set
-extend Extend sequence retrieval in both directions
-extrafeat Bit flag specifying extra features
Format Examples
-db -format -mode Report Type
___ _______ _____ ___________
(all)
docsum DocumentSummarySet XML
docsum json DocumentSummarySet JSON
full Same as native except for mesh
uid Unique Identifier List
url Entrez URL
xml Same as -format full -mode xml
bioproject
native BioProject Report
native xml RecordSet XML
biosample
native BioSample Report
native xml BioSampleSet XML
biosystems
native xml Sys-set XML
gds
native xml RecordSet XML
summary Summary
gene
gene_table Gene Table
native Gene Report
native asn.1 Entrezgene ASN.1
native xml Entrezgene-Set XML
tabular Tabular Report
homologene
alignmentscores Alignment Scores
fasta FASTA
homologene Homologene Report
native Homologene List
native asn.1 HG-Entry ASN.1
native xml Entrez-Homologene-Set XML
mesh
full Full Record
native MeSH Report
native xml RecordSet XML
nlmcatalog
native Full Record
native xml NLMCatalogRecordSet XML
pmc
medline MEDLINE
native xml pmc-articleset XML
pubmed
abstract Abstract
medline MEDLINE
native asn.1 Pubmed-entry ASN.1
native xml PubmedArticleSet XML
(sequences)
acc Accession Number
est EST Report
fasta FASTA
fasta xml TinySeq XML
fasta_cds_aa FASTA of CDS Products
fasta_cds_na FASTA of Coding Regions
ft Feature Table
gb GenBank Flatfile
gb xml GBSet XML
gbc xml INSDSet XML
gbwithparts GenBank with Contig Sequences
gene_fasta FASTA of Gene
gp GenPept Flatfile
gp xml GBSet XML
gpc xml INSDSet XML
gss GSS Report
ipg Identical Protein Report
ipg xml IPGReportSet XML
native text Seq-entry ASN.1
native xml Bioseq-set XML
seqid Seq-id ASN.1
snp
chr Chromosome Report
docset Summary
fasta FASTA
flt Flat File
native asn.1 Rs ASN.1
native xml ExchangeSet XML
rsr RS Cluster Report
ssexemplar SS Exemplar List
sra
native xml EXPERIMENT_PACKAGE_SET XML
runinfo xml SraRunInfo XML
structure
mmdb Ncbi-mime-asn1 strucseq ASN.1
native MMDB Report
native xml RecordSet XML
taxonomy
native Taxonomy List
native xml TaxaSet XML
};
sub fix_sra_xml_encoding {
my $dbase = shift (@_);
my $data = shift (@_);
if ( $dbase eq "sra" ) {
$data =~ s/<!--[^<]+</</g;
$data =~ s/>\s*-->/>/g;
}
return $data;
}
sub fix_pubmed_xml_encoding {
my $dbase = shift (@_);
my $data = shift (@_);
if ( $dbase eq "pubmed" ) {
if ( $data =~ /<ArticleTitle>(.+?)<\/ArticleTitle>/ ) {
my $x = $1;
if ( $x =~ /\&\;/ || $x =~ /\<\;/ || $x =~ /\>\;/ ) {
$x = fix_mixed_content($x);
$data =~ s/<ArticleTitle>(.+?)<\/ArticleTitle>/<ArticleTitle>$x<\/ArticleTitle>/;
}
}
if ( $data =~ /<AbstractText>(.+?)<\/AbstractText>/ ) {
my $x = $1;
if ( $x =~ /\&\;/ || $x =~ /\<\;/ || $x =~ /\>\;/ ) {
$x = fix_mixed_content($x);
$data =~ s/<AbstractText>(.+?)<\/AbstractText>/<AbstractText>$x<\/AbstractText>/;
}
}
}
return $data;
}
sub eftch {
# ... | edirect.pl -fetch -format gp | ...
clearflags ();
MyGetOptions(
$ftch_help,
"db=s" => \$db,
"id=s" => \$id,
"format=s" => \$type,
"mode=s" => \$mode,
"seq_start=i" => \$seq_start,
"seq_stop=i" => \$seq_stop,
"strand=s" => \$strand,
"complexity=i" => \$complexity,
"chr_start=i" => \$chr_start,
"chr_stop=i" => \$chr_stop,
"showgi" => \$showgi,
"extend=i" => \$extend,
"extrafeat=i" => \$extrafeat,
"start=i" => \$min,
"stop=i" => \$max,
"api_key=s" => \$api_key,
"email=s" => \$emaddr,
"tool=s" => \$tuul,
"pipe" => \$pipe,
"help" => \$help,
"silent" => \$silent,
"verbose" => \$verbose,
"debug" => \$debug,
"log" => \$log,
"raw" => \$raw,
"http=s" => \$http,
"https=s" => \$http,
"alias=s" => \$alias,
"base=s" => \$basx
);
if ( $help ) {
print "efetch $version\n";
print $ftch_help;
return;
}
# convert spaces between UIDs to commas
$id =~ s/ /,/g;
$id =~ s/,,/,/g;
# "-format xml" is a shortcut for "-format full -mode xml"
if ( $type eq "xml" and $mode eq "" ) {
$type = "full";
$mode = "xml";
}
if ( -t STDIN and not @ARGV ) {
} elsif ( $db ne "" and $id ne "" ) {
} else {
( $dbase, $web, $key, $num, $stp, $err, $tool, $email, $just_num, @rest ) = read_edirect ();
}
read_aliases ();
adjust_base ();
if ( $err ne "" ) {
if ( ! $silent ) {
die "ERROR in fetch input: $err\n\n";
}
return;
}
if ( $dbase eq "" ) {
$dbase = $db;
}
$dbase = lc($dbase);
if ( $type eq "" and $db ne "" ) {
if ( get_zero_uid ($db) eq "" ) {
die "Must supply -format report type on command line\n";
}
$type = "native";
}
if ( $mode eq "" ) {
$mode = "text";
}
if ( $tuul ne "" ) {
$tool = $tuul;
}
if ( $emaddr ne "" ) {
$email = $emaddr;
}
if ( $strand eq "plus" ) {
$strand = "1";
}
if ( $strand eq "minus" ) {
$strand = "2";
}
binmode STDOUT, ":utf8";
# arguments can override loop start and stop
if ( $min > 0 ) {
$min--;
}
if ( $max == 0 ) {
$max = $num
}
if ( $type eq "docsum" or $fnc eq "-summary" ) {
esmry ( $dbase, $web, $key, $num, $id, $mode, $min, $max, $tool, $email,
$silent, $verbose, $debug, $log, $http, $alias, $basx );
return;
}
if ( $dbase eq "structure" and $type eq "mmdb" ) {
emmdb ( $dbase, $web, $key, $num, $id, $tool, $email );
return;
}
if ( $dbase ne "" and ( $type eq "UID" or $type eq "uid" ) ) {
if ( $id ne "" ) {
my @ids = split (',', $id);
foreach $uid (@ids) {
print "$uid\n";
}
return;
}
if ( $web eq "" ) {
die "WebEnv value not found in fetch input\n";
}
if ( $pipe ) {
write_edirect ( $dbase, $web, $key, $num, $stp, $err, $tool, $email );
}
if ( $max == 0 ) {
if ( $silent ) {
return;
}
}
# use larger chunk for UID format
$chunk = 5000;
for ( $start = $min; $start < $max; $start += $chunk ) {
my @ids = get_uids ( $dbase, $web, $key, $start, $chunk, $max, $tool, $email );
foreach $uid (@ids) {
print "$uid\n";
}
}
return;
}
if ( $dbase ne "" and ( $type eq "URL" or $type eq "url" ) ) {
if ( $id ne "" ) {
my @ids = split (',', $id);
$url = "https://www.ncbi.nlm.nih.gov/";
$url .= "$dbase/";
my $pfx = "";
foreach $uid (@ids) {
$url .= "$pfx$uid";
$pfx = ",";
}
print "$url\n";
return;
}
if ( $web eq "" ) {
die "WebEnv value not found in fetch input\n";
}
if ( $pipe ) {
write_edirect ( $dbase, $web, $key, $num, $stp, $err, $tool, $email );
}
if ( $max == 0 ) {
if ( $silent ) {
return;
}
}
# use larger chunk for URL format
$chunk = 2000;
for ( $start = $min; $start < $max; $start += $chunk ) {
my @ids = get_uids ( $dbase, $web, $key, $start, $chunk, $max, $tool, $email );
$url = "https://www.ncbi.nlm.nih.gov/";
$url .= "$dbase/";
my $pfx = "";
foreach $uid (@ids) {
$url .= "$pfx$uid";
$pfx = ",";
}
print "$url\n";
}
return;
}
if ( $dbase ne "" and ( $type eq "URLS" or $type eq "urls" ) ) {
if ( $id ne "" ) {
my @ids = split (',', $id);
foreach $uid (@ids) {
print "https://www.ncbi.nlm.nih.gov/$dbase/$uid\n";
}
return;
}
if ( $web eq "" ) {
die "WebEnv value not found in fetch input\n";
}
if ( $pipe ) {
write_edirect ( $dbase, $web, $key, $num, $stp, $err, $tool, $email );
}
if ( $max == 0 ) {
if ( $silent ) {
return;
}
}
# use larger chunk for URL format
$chunk = 2000;
for ( $start = $min; $start < $max; $start += $chunk ) {
my @ids = get_uids ( $dbase, $web, $key, $start, $chunk, $max, $tool, $email );
foreach $uid (@ids) {
print "https://www.ncbi.nlm.nih.gov/$dbase/$uid\n";
}
}
return;
}
if ( $dbase ne "" and $id ne "" ) {
if ( $id eq "0" ) {
# id "0" returns a live UID for any database
$id = get_zero_uid ($dbase);
if ( $id eq "0" ) {
# id "0" is an unrecognized accession
return;
}
}
$url = $base . $efetch;
$arg = "db=$dbase&id=$id";
$arg .= "&rettype=$type&retmode=$mode";
# -chr_start and -chr_stop are for 0-based sequence coordinates from EntrezGene
if ( $chr_start > -1 && $chr_stop > -1 ) {
$seq_start = $chr_start + 1;
$seq_stop = $chr_stop + 1;
}
# if -seq_start > -seq_stop, swap values to normalize, indicate minus strand with -strand 2
if ( $seq_start > 0 && $seq_stop > 0 ) {
if ( $seq_start > $seq_stop ) {
my $tmp = $seq_start;
$seq_start = $seq_stop;
$seq_stop = $tmp;
$strand = "2";
}
}
# option to show GI number (undocumented)
if ( $showgi ) {
$arg .= "&showgi=1";
}
# optionally extend retrieved sequence range in both directions
if ( $extend > 0 ) {
$seq_start -= $extend;
$seq_stop += $extend;
}
if ( $strand ne "" ) {
$arg .= "&strand=$strand";
}
if ( $seq_start > 0 ) {
$arg .= "&seq_start=$seq_start";
}
if ( $seq_stop > 0 ) {
$arg .= "&seq_stop=$seq_stop";
}
if ( $complexity > 0 ) {
$arg .= "&complexity=$complexity";
}
if ( $extrafeat > -1 ) {
$arg .= "&extrafeat=$extrafeat";
}
$data = do_post_yielding_ref ($url, $arg, $tool, $email, true);
if ($$data =~ /<eFetchResult>/i and $$data =~ /<ERROR>(.+?)<\/ERROR>/i) {
$err = $1;
if ( $err ne "" ) {
if ( ! $silent ) {
print STDERR "ERROR in efetch: $err\n";
}
}
}
Encode::_utf8_on($$data);
if (! $raw) {
if ( $dbase eq "sra" and $type eq "full" and $mode eq "xml" ) {
$$data = fix_sra_xml_encoding($dbase, $$data);
}
if ( $dbase eq "pubmed" and $type eq "full" and $mode eq "xml" ) {
$$data = fix_pubmed_xml_encoding($dbase, $$data);
}
if ( $type eq "fasta" or $type eq "fasta_cds_aa" or $type eq "fasta_cds_na" or $type eq "gene_fasta" ) {
# remove blank lines in FASTA format
$$data =~ s/\n+/\n/g;
}
}
print $$data;
return;
}
if ( $dbase ne "" and $web ne "" and $key eq "" and $num eq "0" ) {
die "QueryKey value not found in fetch input\n";
return;
}
test_edirect ( $dbase, $web, $key, $num, "fetch" );
$stpminusone = $stp - 1;
if ( $max == 0 ) {
if ( $silent ) {
return;
}
}
# use small chunk because fetched records could be quite large
$chunk = 100;
# use larger chunk for accessions
if ( $dbase eq "nucleotide" or
$dbase eq "nuccore" or
$dbase eq "est" or
$dbase eq "gss" or
$dbase eq "protein" ) {
if ( $type eq "ACCN" or $type eq "accn" or $type eq "ACC" or $type eq "acc" ) {
$chunk = 4000;
}
}
for ( $start = $min; $start < $max; $start += $chunk ) {
$url = $base . $efetch;
$chkx = $chunk;
if ( $start + $chkx > $max ) {
$chkx = $max - $start;
}
$arg = "db=$dbase&query_key=$key&WebEnv=$web";
$arg .= "&rettype=$type&retmode=$mode";
$arg .= "&retstart=$start&retmax=$chkx";
if ( $strand ne "" ) {
$arg .= "&strand=$strand";
}
if ( $seq_start > 0 ) {
$arg .= "&seq_start=$seq_start";
}
if ( $seq_stop > 0 ) {
$arg .= "&seq_stop=$seq_stop";
}
if ( $complexity > 0 ) {
$arg .= "&complexity=$complexity";
}
if ( $extrafeat > -1 ) {
$arg .= "&extrafeat=$extrafeat";
}
$data = "";
$retry = true;
for ( $tries = 0; $tries < 3 && $retry; $tries++) {
$data = do_post_yielding_ref ($url, $arg, $tool, $email, true);
if ($$data =~ /<eFetchResult>/i and $$data =~ /<ERROR>(.+?)<\/ERROR>/i) {
if ( ! $silent ) {
print STDERR "Retrying efetch, step $stp: $err\n";
}
sleep 3;
} else {
$retry = false;
}
}
if ($$data =~ /<eFetchResult>/i and $$data =~ /<ERROR>(.+?)<\/ERROR>/i) {
$err = $1;
if ( $err ne "" ) {
if ( ! $silent ) {
my $from = $start + 1;
my $to = $start + $chunk;
if ( $to > $num ) {
$to = $num;
}
print STDERR "ERROR in efetch ($from-$to / $num): $err\n";
print STDERR "Replicate for debugging with:\n";
print STDERR " edirutil -db $dbase -web $web -key $key -count $num";
if ( $stpminusone > 0 ) {
print STDERR " -step $stpminusone";
}
my $seconds = "";
my $end_time = Time::HiRes::time();
my $elapsed = $end_time - $begin_time;
if ( $elapsed > 0.0005 ) {
if ( $elapsed =~ /(\d+)\.(\d\d\d)\d+/ ) {
$seconds = "$1.$2";
}
}
if ( $seconds ne "" ) {
print STDERR " -seconds $seconds";
}
print STDERR " | efetch -format $type";
if ( $mode ne "text" ) {
print STDERR " -mode $mode";
}
print STDERR " -start $from -stop $to\n";
}
}
} else {
if ( $verbose ) {
my $from = $start + 1;
my $to = $start + $chunk;
if ( $to > $num ) {
$to = $num;
}
print STDERR "( edirutil -db $dbase -web $web -key $key -count $num";
if ( $stpminusone > 0 ) {
print STDERR " -step $stpminusone";
}
my $seconds = "";
my $end_time = Time::HiRes::time();
my $elapsed = $end_time - $begin_time;
if ( $elapsed > 0.0005 ) {
if ( $elapsed =~ /(\d+)\.(\d\d\d)\d+/ ) {
$seconds = "$1.$2";
}
}
if ( $seconds ne "" ) {
print STDERR " -seconds $seconds";
}
print STDERR " | efetch -format $type";
if ( $mode ne "text" ) {
print STDERR " -mode $mode";
}
print STDERR " -start $from -stop $to )\n";
$begin_time = $end_time;
}
Encode::_utf8_on($$data);
if (! $raw) {
if ( $dbase eq "sra" and $type eq "full" and $mode eq "xml" ) {
$$data = fix_sra_xml_encoding($dbase, $$data);
}
if ( $dbase eq "pubmed" and $type eq "full" and $mode eq "xml" ) {
$$data = fix_pubmed_xml_encoding($dbase, $$data);
}
if ( $type eq "fasta" or $type eq "fasta_cds_aa" or $type eq "fasta_cds_na" or $type eq "gene_fasta" ) {
# remove blank lines in FASTA format
$$data =~ s/\n+/\n/g;
}
}
print $$data;
}
sleep 1;
}
}
# einfo obtains names of databases or names of fields and links per database
my $info_help = qq{
Database Selection
-db Database name
-dbs Get all database names
Data Summaries
-fields Print field names
-links Print link names
Field Example
<Field>
<Name>ALL</Name>
<FullName>All Fields</FullName>
<Description>All terms from all searchable fields</Description>
<TermCount>138982028</TermCount>
<IsDate>N</IsDate>
<IsNumerical>N</IsNumerical>
<SingleToken>N</SingleToken>
<Hierarchy>N</Hierarchy>
<IsHidden>N</IsHidden>
<IsTruncatable>Y</IsTruncatable>
<IsRangable>N</IsRangable>
</Field>
Link Example
<Link>
<Name>pubmed_protein</Name>
<Menu>Protein Links</Menu>
<Description>Published protein sequences</Description>
<DbTo>protein</DbTo>
</Link>
<Link>
<Name>pubmed_protein_refseq</Name>
<Menu>Protein (RefSeq) Links</Menu>
<Description>Link to Protein RefSeqs</Description>
<DbTo>protein</DbTo>
</Link>
};
sub einfo {
# ... | edirect.pl -info -db pubmed | ...
clearflags ();
MyGetOptions(
$info_help,
"db=s" => \$db,
"dbs" => \$dbs,
"fields" => \$fields,
"links" => \$links,
"api_key=s" => \$api_key,
"email=s" => \$emaddr,
"tool=s" => \$tuul,
"help" => \$help,
"silent" => \$silent,
"verbose" => \$verbose,
"debug" => \$debug,
"log" => \$log,
"http=s" => \$http,
"https=s" => \$http,
"alias=s" => \$alias,
"base=s" => \$basx
);
if ( $help ) {
print "einfo $version\n";
print $info_help;
return;
}
read_aliases ();
adjust_base ();
if ( @ARGV || ($^O =~ /^MSWin/ && ! -t STDIN) ) {
while ( defined($thisline = <STDIN>) ) {
$tool = $1 if ( $thisline =~ /<Tool>(.+?)<\/Tool>/i );
$email = $1 if ( $thisline =~ /<Email>(.+?)<\/Email>/i );
}
}
if ( $dbase eq "" ) {
$dbase = $db;
}
$dbase = lc($dbase);
if ( $dbase eq "" and (! $dbs) ) {
die "Must supply -db or -dbs on command line\n";
}
if ( $tuul ne "" ) {
$tool = $tuul;
}
if ( $emaddr ne "" ) {
$email = $emaddr;
}
binmode STDOUT, ":utf8";
$url = $base . $einfo;
$prefix = "?";
if ( $dbase ne "" ) {
$url .= "$prefix" . "db=$dbase&version=2.0";
$prefix = "&";
}
if ( $os ne "" ) {
$url .= "$prefix" . "os=$os";
$prefix = "&";
}
if ( $api_key ne "" ) {
$url .= "$prefix" . "api_key=$api_key";
$prefix = "&";
}
$url .= "$prefix" . "edirect=$version";
$prefix = "&";
if ( $tool eq "" ) {
$tool = "edirect";
}
if ( $tool ne "" ) {
$url .= "$prefix" . "tool=$tool";
$prefix = "&";
}
if ( $email eq "" ) {
$email = get_email ();
}
if ( $email ne "" ) {
$url .= "$prefix" . "email=$email";
$prefix = "&";
}
if ( $debug or $log ) {
print STDERR "$url\n";
}
$output = get ($url);
if ($output =~ /IsTrunc/ or $output =~ /IsRang/) {
# print STDERR "New server is out with IsTrunc/IsRang - update executable\n";
}
if ( $output eq "" ) {
print STDERR "No einfo output returned from '$url'\n";
}
if ( $debug ) {
print STDERR "$output\n";
}
if ( $dbs and $output =~ /<DbName>/ ) {
# -dbs now extracts database names from XML
$output =~ s/\r//g;
$output =~ s/\n//g;
$output =~ s/\t//g;
$output =~ s/ +/ /g;
$output =~ s/> +</></g;
my @databases = ($output =~ /<DbName>(.+?)<\/DbName>/g);
foreach $dtbs (@databases) {
print "$dtbs\n";
}
return;
}
if ( ( $fields or $links ) and $output =~ /<DbInfo>/ ) {
# -db can print information directly without need to process XML with xtract
$output =~ s/\r//g;
$output =~ s/\n//g;
$output =~ s/\t//g;
$output =~ s/ +/ /g;
$output =~ s/> +</></g;
my $name = "";
my $full = "";
my $menu = "";
if ( $fields ) {
my @flds = ($output =~ /<Field>(.+?)<\/Field>/g);
foreach $fld (@flds) {
$name = "";
$full = "_";
if ( $fld =~ /<Name>(.+?)<\/Name>/ ) {
$name = $1;
}
if ( $fld =~ /<FullName>(.+?)<\/FullName>/ ) {
$full = $1;
}
if ( $name ne "" and $full ne "" ) {
print "$name\t$full\n";
}
}
}
if ( $links ) {
my @lnks = ($output =~ /<Link>(.+?)<\/Link>/g);
foreach $lnk (@lnks) {
$name = "";
$menu = "_";
if ( $lnk =~ /<Name>(.+?)<\/Name>/ ) {
$name = $1;
}
if ( $lnk =~ /<Menu>(.+?)<\/Menu>/ ) {
$menu = $1;
}
if ( $name ne "" and $menu ne "" ) {
print "$name\t$menu\n";
}
}
}
return;
}
print "$output";
}
# common link history processing
sub acheck_test {
my $dbase = shift (@_);
my $dbto = shift (@_);
my $name = shift (@_);
my $web = shift (@_);
my $key = shift (@_);
my $num = shift (@_);
my $stp = shift (@_);
my $err = shift (@_);
my $tool = shift (@_);
my $email = shift (@_);
if ( $num > 0 ) {
return;
}
# if failure, use acheck to confirm that there are no links
$url = $base . $elink;
$arg = "dbfrom=$dbase&query_key=$key&WebEnv=$web&cmd=acheck";
$data = do_post ($url, $arg, $tool, $email, true);
# remove newlines, tabs, space between tokens, compress runs of spaces,
$data =~ s/\r//g;
$data =~ s/\n//g;
$data =~ s/\t//g;
$data =~ s/ +/ /g;
$data =~ s/> </></g;
if ($data =~ /<Error>(.+?)<\/Error>/i) {
$err = $1;
if ( $err ne "" ) {
write_edirect ( $dbto, $web, $key, $num, $stp, $err, $tool, $email );
close (STDOUT);
die "ERROR in acheck test: $err\n";
}
}
if ( $data !~ /<LinkInfo>/ ) {
write_edirect ( $dbto, $web, $key, $num, $stp, $err, $tool, $email );
close (STDOUT);
die "Elink acheck confirmation test failed\n";
}
if ( $data =~ /<LinkName>$name<\/LinkName>/ ) {
write_edirect ( $dbto, $web, $key, $num, $stp, $err, $tool, $email );
close (STDOUT);
die "Elink acheck test indicates non-zero count expected\n";
}
}
sub process_history_link {
my $arg = shift (@_);
my $output = shift (@_);
my $dbase = shift (@_);
my $dbto = shift (@_);
my $name = shift (@_);
my $wb = shift (@_);
my $web = shift (@_);
my $key = shift (@_);
my $stp = shift (@_);
my $err = shift (@_);
my $lbl = shift (@_);
my $tool = shift (@_);
my $email = shift (@_);
my $num = "";
if ( $wb eq "" ) {
$wb = $web;
}
if ( $err ne "" ) {
write_edirect ( "", $wb, "", "", "", $err, "", "" );
close (STDOUT);
if ( ! $silent ) {
die "ERROR in link output: $err\nWebEnv: $wb\nURL: $arg\nResult: $output\n\n";
}
return;
}
if ( $web eq "" ) {
die "WebEnv value not found in link output - WebEnv1 $wb\n";
}
if ( $key eq "" ) {
write_edirect ( $dbto, $wb, $key, "0", $stp, $err, $tool, $email );
close (STDOUT);
# no neighbors or links can be a normal response,
# e.g., elink -db gene -id 496376 -target medgen
# so suppress this message
# die "QueryKey value not found in link output - WebEnv1 $wb\n";
return;
}
if ( $web ne $wb ) {
$err = "WebEnv mismatch in link-search output - WebEnv1 $wb, WebEnv2 $web";
write_edirect ( "", $web, "", "", "", $err, "", "" );
close (STDOUT);
die "WebEnv value changed in link-search output - WebEnv1 $wb\nWebEnv2 $web\n";
}
( $num, $key ) = get_count ( $dbto, $web, $key, $tool, $email );
if ( $num eq "" ) {
$err = "Missing count in link-search output - WebEnv $web";
write_edirect ( "", $web, "", "", "", $err, "", "" );
close (STDOUT);
die "Count value not found in link-search output - WebEnv $web\n";
}
if ( $num == 0 ) {
acheck_test ( $dbase, $dbto, $name, $web, $key, $num, $stp, $err, $tool, $email );
}
if ( $lbl ne "" and $key ne "" ) {
$labels{"$lbl"} = "$key";
}
write_edirect ( $dbto, $web, $key, $num, $stp, $err, $tool, $email );
}
# for large lists, break into chunks, merge result on client, post to server
sub batch_elink {
my $dbase = shift (@_);
my $dbto = shift (@_);
my $name = shift (@_);
my $web = shift (@_);
my $key = shift (@_);
my $num = shift (@_);
my $stp = shift (@_);
my $err = shift (@_);
my $lbl = shift (@_);
my $tool = shift (@_);
my $email = shift (@_);
my $auto = shift (@_);
my %seen = ();
my @uniq = ();
if ( $num == 0 ) {
if ( $silent ) {
write_edirect ( "", "", "", "", "", $err, "", "" );
close (STDOUT);
return;
}
}
$chunk = 200;
for ( $start = 0; $start < $num; $start += $chunk ) {
my @ids = get_uids ( $dbase, $web, $key, $start, $chunk, $num, $tool, $email );
$url = $base . $elink;
$arg = "dbfrom=$dbase&db=$dbto&cmd=neighbor&linkname=$name";
if ( $mode ne "" ) {
$arg .= "&retmode=$mode";
}
$arg .= "&id=";
$arg .= join (',', @ids);
$data = "";
$retry = true;
for ( $tries = 0; $tries < 3 && $retry; $tries++) {
$data = do_post ($url, $arg, $tool, $email, true);
if ($data =~ /<Error>(.+?)<\/Error>/i) {
if ( ! $silent ) {
print STDERR "Retrying batch elink, step $stp: $err\n";
}
sleep 3;
} else {
$retry = false;
}
}
# remove newlines, tabs, space between tokens, compress runs of spaces,
$data =~ s/\r//g;
$data =~ s/\n//g;
$data =~ s/\t//g;
$data =~ s/ +/ /g;
$data =~ s/> </></g;
if ($data =~ /<Error>(.+?)<\/Error>/i) {
$err = $1;
if ( $err ne "" ) {
if ( ! $silent ) {
my $from = $start + 1;
my $to = $start + $chunk;
if ( $to > $num ) {
$to = $num;
}
print STDERR "ERROR in batch elink ($from-$to / $num): $err\n";
}
}
}
if ($data !~ /<LinkSetDb>/i) {
if ( ! $silent ) {
print STDERR "LinkSetDb missing in batch elink result\n";
}
}
while ( $data =~ /<LinkSetDb>(.*?)<\/LinkSetDb>/g ) {
$linkset = $1;
while ( $linkset =~ /<Id>(\d+)<\/Id>/g ) {
$uid = $1;
if ( ! $seen{$uid}++ ) {
push (@uniq, $uid);
}
}
}
}
$dbase = $dbto;
$dbase = lc($dbase);
$num = scalar @uniq;
if ( $num == 0 ) {
acheck_test ( $dbase, $dbto, $name, $web, $key, $num, $stp, $err, $tool, $email );
write_edirect ( $dbase, $web, $key, "0", $stp, $err, $tool, $email );
if ( $auto ) {
close (STDOUT);
die "Automatic batch link failed\n";
}
return;
}
# not certain if sort is necessary - need to experiment before final release
@sorted = sort { $a <=> $b } @uniq;
$url = $base . $epost;
$arg = "db=$dbase";
if ( $key ne "" ) {
$arg .= "&query_key=$key";
}
if ( $web ne "" ) {
$arg .= "&WebEnv=$web";
}
$ids = join (',', @sorted);
$arg .= "&id=$ids";
$output = do_post ($url, $arg, $tool, $email, true);
if ( $debug ) {
print STDERR "$output\n";
}
$wb = $web;
$web = "";
$key = "";
$err = "";
$web = $1 if ($output =~ /<WebEnv>(\S+)<\/WebEnv>/);
$key = $1 if ($output =~ /<QueryKey>(\S+)<\/QueryKey>/);
$err = $1 if ($output =~ /<Error>(.+?)<\/Error>/i);
process_history_link ( $arg, $output, $dbase, $dbto, $name, $wb, $web, $key, $stp, $err, $lbl, $tool, $email );
}
# elink without a target uses the source database for neighboring
my $link_help = qq{
Destination Database
-related Neighbors in same database
-target Links in different database
-name Link name (e.g., pubmed_protein_refseq)
Direct Record Selection
-db Database name
-id Unique identifier(s)
Advanced Control
-cmd Command type (returns eLinkResult XML)
-mode "ref" uses LinkOut provider's web site
-holding Name of LinkOut provider
Batch Processing
-batch Bypass Entrez history mechanism
Miscellaneous Arguments
-label Alias for query step
Command Option Examples
-cmd Result
____ ______
neighbor Neighbors or links
neighbor_score Neighbors with computed similarity scores
acheck All links available
ncheck Existence of neighbors
lcheck Existence of external links (LinkOuts)
llinks Non-library LinkOut providers
llinkslib All LinkOut providers
prlinks Primary LinkOut provider,
or URL for single UID with -mode ref
};
sub elink {
# ... | edirect.pl -link -target structure | ...
clearflags ();
MyGetOptions(
$link_help,
"db=s" => \$db,
"id=s" => \$id,
"format=s" => \$type,
"target=s" => \$dbto,
"name=s" => \$name,
"related" => \$related,
"neighbor" => \$neighbor,
"cmd=s" => \$cmd,
"mode=s" => \$mode,
"batch" => \$batch,
"holding=s" => \$holding,
"label=s" => \$lbl,
"api_key=s" => \$api_key,
"email=s" => \$emaddr,
"tool=s" => \$tuul,
"help" => \$help,
"silent" => \$silent,
"verbose" => \$verbose,
"debug" => \$debug,
"log" => \$log,
"http=s" => \$http,
"https=s" => \$http,
"alias=s" => \$alias,
"base=s" => \$basx
);
if ( $help ) {
print "elink $version\n";
print $link_help;
return;
}
# convert spaces between UIDs to commas
$id =~ s/ /,/g;
$id =~ s/,,/,/g;
if ( -t STDIN and not @ARGV ) {
} elsif ( $db ne "" and $id ne "" ) {
} else {
( $dbase, $web, $key, $num, $stp, $err, $tool, $email, $just_num, @rest ) = read_edirect ();
}
read_aliases ();
adjust_base ();
if ( $err ne "" ) {
write_edirect ( "", "", "", "", "", $err, "", "" );
close (STDOUT);
if ( ! $silent ) {
die "ERROR in link input: $err\n\n";
}
return;
}
if ( $dbase eq "" ) {
$dbase = $db;
}
$dbase = lc($dbase);
my $adddbto = true;
if ( $dbto eq "" ) {
if ( $cmd eq "acheck" or
$cmd eq "ncheck" or
$cmd eq "lcheck" or
$cmd eq "llinks" or
$cmd eq "llinkslib" or
$cmd eq "prlinks" ) {
$dbto = $dbase;
$adddbto = false;
}
}
if ( $dbto eq "" and (! $related) and (! $neighbor) ) {
die "Must supply -target or -related on command line\n";
}
if ( $tuul ne "" ) {
$tool = $tuul;
}
if ( $emaddr ne "" ) {
$email = $emaddr;
}
binmode STDOUT, ":utf8";
if ( $dbto eq "" ) {
$dbto = $dbase;
}
if ( $name eq "" ) {
$name = $dbase . "_" . $dbto;
}
if ( $cmd eq "" ) {
$cmd = "neighbor_history";
}
if ( $dbase eq "nlmcatalog" ) {
die "Entrez Direct does not support links for the nlmcatalog database\n";
}
if ( $dbase ne "" and $id ne "" ) {
# process db and id command-line arguments instead of getting from history
$url = $base . $elink;
$arg = "dbfrom=$dbase";
if ( $adddbto ) {
$arg .= "&db=$dbto";
}
$arg .= "&cmd=$cmd&linkname=$name";
if ( $mode ne "" ) {
$arg .= "&retmode=$mode";
}
$arg .= "&id=$id";
if ( $type eq "acc" ) {
$arg .= "&idtype=acc";
}
$data = do_post ($url, $arg, $tool, $email, true);
if ( $cmd ne "neighbor_history" ) {
# if not neighbor_history, write eLinkResult XML instead of ENTREZ_DIRECT
print "$data";
return;
}
$wb = $web;
$web = "";
$key = "";
$err = "";
$err = $1 if ($data =~ /<Error>(.+?)<\/Error>/i);
if ( $err eq "" ) {
$web = $1 if ($data =~ /<WebEnv>(\S+)<\/WebEnv>/);
$key = $1 if ($data =~ /<QueryKey>(\S+)<\/QueryKey>/);
}
process_history_link ( $arg, $data, $dbase, $dbto, $name, $wb, $web, $key, $stp, $err, $lbl, $tool, $email );
return;
}
test_edirect ( $dbase, $web, $key, $num, "link" );
if ( $cmd ne "neighbor_history" ) {
# if not neighbor_history, write eLinkResult XML instead of ENTREZ_DIRECT
if ( $num == 0 ) {
if ( $silent ) {
return;
}
}
$chunk = 200;
for ( $start = 0; $start < $num; $start += $chunk ) {
my @ids = get_uids ( $dbase, $web, $key, $start, $chunk, $num, $tool, $email );
$url = $base . $elink;
$arg = "dbfrom=$dbase";
if ( $adddbto ) {
$arg .= "&db=$dbto";
}
$arg .= "&cmd=$cmd&linkname=$name";
if ( $mode ne "" ) {
$arg .= "&retmode=$mode";
}
$arg .= "&id=";
$arg .= join ('&id=', @ids);
if ( $type eq "acc" ) {
$arg .= "&idtype=acc";
}
$data = do_post ($url, $arg, $tool, $email, true);
print "$data";
}
return;
}
if ( $batch ) {
# large list bypass
batch_elink ( $dbase, $dbto, $name, $web, $key, $num, $stp, "", $lbl, $tool, $email, false );
return;
}
# if not breaking large lists into chunks, use neighbor_history on server
$url = $base . $elink;
$arg = "dbfrom=$dbase";
if ( $adddbto ) {
$arg .= "&db=$dbto";
}
$arg .= "&query_key=$key&WebEnv=$web";
$arg .= "&cmd=$cmd&linkname=$name";
if ( $mode ne "" ) {
$arg .= "&retmode=$mode";
}
if ( $type eq "acc" ) {
$arg .= "&idtype=acc";
}
$wb = $web;
$ky = $key;
$nm = $num;
$web = "";
$key = "";
$err = "";
$output = "";
for ( $tries = 0; $tries < 3 && $web eq ""; $tries++) {
$output = do_post ($url, $arg, $tool, $email, true);
$err = $1 if ($output =~ /<Error>(.+?)<\/Error>/i);
if ( $err eq "" ) {
$web = $1 if ($output =~ /<WebEnv>(\S+)<\/WebEnv>/);
$key = $1 if ($output =~ /<QueryKey>(\S+)<\/QueryKey>/);
} else {
if ( ! $silent ) {
print STDERR "Retrying elink, step $stp: $err\n";
}
sleep 3;
}
}
# automatically fail over to batch mode under certain failure conditions
$stpminusone = $stp - 1;
if ( $err =~ "^Query failed" or
$err =~ "^Timeout waiting" or
$err =~ "^Unable to obtain" or
$err =~ "^The read request has timed out" ) {
if ( ! $silent ) {
print STDERR "$err\nReplicate for debugging with:\n";
print STDERR " edirutil -db $dbase -web $wb -key $ky -count $nm";
if ( $stpminusone > 0 ) {
print STDERR " -step $stpminusone";
}
my $seconds = "";
my $end_time = Time::HiRes::time();
my $elapsed = $end_time - $begin_time;
if ( $elapsed > 0.0005 ) {
if ( $elapsed =~ /(\d+)\.(\d\d\d)\d+/ ) {
$seconds = "$1.$2";
}
}
if ( $seconds ne "" ) {
print STDERR " -seconds $seconds";
}
if ( $dbase eq $dbto ) {
print STDERR " | elink -related\n";
} else {
print STDERR " | elink -target $dbto\n";
}
print STDERR "Automatically switching to -batch mode\n";
}
batch_elink ( $dbase, $dbto, $name, $wb, $ky, $nm, $stp, "", $lbl, $tool, $email, true );
return;
}
# finish reality checks, get count and key, and write ENTREZ_DIRECT structure
process_history_link ( $arg, $output, $dbase, $dbto, $name, $wb, $web, $key, $stp, $err, $lbl, $tool, $email );
}
# emmdb downloads "Ncbi-mime-asn1 ::= strucseq" ASN.1 from MMDB unique identifiers
sub emmdb {
# ... | edirect.pl -fetch -format mmdb | ...
$dbase = shift (@_);
$web = shift (@_);
$key = shift (@_);
$num = shift (@_);
$id = shift (@_);
$tool = shift (@_);
$email = shift (@_);
if ( $err ne "" ) {
die "ERROR in mmdb input: $err\n\n";
}
$mbase = "https://www.ncbi.nlm.nih.gov/Structure/mmdb/";
$mprog = "mmdbsrv.cgi";
if ( $id ne "" ) {
my @ids = split (',', $id);
foreach $uid (@ids) {
$url = $mbase . $mprog;
$arg = "uid=$uid";
$arg .= "&save=asntext&form=6&db=t&Dopt=j&Complexity=Cn3D%20Subset";
$mmdb = do_post ($url, $arg, $tool, $email, true);
print "$mmdb\n";
}
return;
}
test_edirect ( $dbase, $web, $key, $num, "mmdb" );
$chunk = 100;
for ( $start = 0; $start < $num; $start += $chunk ) {
my @ids = get_uids ( $dbase, $web, $key, $start, $chunk, $num, $tool, $email );
foreach $uid (@ids) {
$url = $mbase . $mprog;
$arg = "uid=$uid";
$arg .= "&save=asntext&form=6&db=t&Dopt=j&Complexity=Cn3D%20Subset";
$mmdb = do_post ($url, $arg, $tool, $email, true);
print "$mmdb\n";
}
}
}
# entfy sends e-mail
my $ntfy_help = qq{
-email Contact person's address
-tool Name of script or program
};
sub entfy {
# ... | edirect.pl -notify
clearflags ();
MyGetOptions(
$ntfy_help,
"api_key=s" => \$api_key,
"email=s" => \$emaddr,
"tool=s" => \$tuul,
"help" => \$help,
"silent" => \$silent,
"verbose" => \$verbose,
"debug" => \$debug,
"log" => \$log,
"http=s" => \$http,
"https=s" => \$http,
"alias=s" => \$alias,
"base=s" => \$basx
);
if ( $help ) {
print "enotify $version\n";
print $ntfy_help;
return;
}
( $dbase, $web, $key, $num, $stp, $err, $tool, $email, $just_num, @rest ) = read_edirect ();
read_aliases ();
adjust_base ();
if ( $err ne "" ) {
die "ERROR in notify input: $err\n\n";
}
test_edirect ( $dbase, $web, $key, $num, "notify" );
if ( $tuul ne "" ) {
$tool = $tuul;
}
if ( $emaddr ne "" ) {
$email = $emaddr;
}
if ( $email eq "" ) {
$email = get_email ();
}
if ( $email eq "" ) {
die "Email value not found in notify input\n";
}
binmode STDOUT, ":utf8";
if ( $num > 0 ) {
$chunk = 100;
for ( $start = 0; $start < $num; $start += $chunk ) {
my @ids = get_uids ( $dbase, $web, $key, $start, $chunk, $num, $tool, $email );
foreach $uid (@ids) {
$txt = "echo \"https://www.ncbi.nlm.nih.gov/$dbase/$uid\n\"";
$str = "mail -s \"A new $dbase record is in Entrez\" $email";
system "$txt | $str";
}
}
}
}
# epost uploads UIDs or accessions
sub post_chunk {
my $dbsx = shift (@_);
my $webx = shift (@_);
my $keyx = shift (@_);
my $tulx = shift (@_);
my $emlx = shift (@_);
my $uids = shift (@_);
my $qryx = shift (@_);
$url = $base;
$arg = "";
$wb = $webx;
if ( $uids ne "" ) {
$url .= $epost;
$arg = "db=$dbsx";
if ( $web ne "" ) {
$arg .= "&WebEnv=$webx";
}
$arg .= "&id=$uids";
} elsif ( $qryx ne "" ) {
$url .= $esearch;
$qryx = map_labels ($qryx);
$qryx = map_macros ($qryx);
$enc = uri_escape($qryx);
$arg = "db=$dbsx&term=$enc";
if ( $web ne "" ) {
$arg .= "&WebEnv=$webx";
}
$arg .= "&retmax=0&usehistory=y";
if ( $rldate > 0 ) {
$arg .= "&reldate=$rldate";
if ( $dttype eq "" ) {
$dttype = "PDAT";
}
}
if ( $mndate ne "" and $mxdate ne "" ) {
$arg .= "&mindate=$mndate&maxdate=$mxdate";
if ( $dttype eq "" ) {
$dttype = "PDAT";
}
}
if ( $dttype ne "" ) {
$arg .= "&datetype=$dttype";
}
}
$output = do_post ($url, $arg, $tulx, $emlx, true);
$webx = "";
$keyx = "";
$err = "";
$webx = $1 if ($output =~ /<WebEnv>(\S+)<\/WebEnv>/);
$keyx = $1 if ($output =~ /<QueryKey>(\S+)<\/QueryKey>/);
$err = $1 if ($output =~ /<Error>(.+?)<\/Error>/i);
if ( $err ne "" ) {
write_edirect ( "", "", "", "", "", $err, "", "" );
close (STDOUT);
die "ERROR in post output: $err\nURL: $arg\n\n";
}
if ( $webx eq "" ) {
die "WebEnv value not found in post output\n";
}
if ( $keyx eq "" ) {
die "QueryKey value not found in post output\n";
}
if ( $wb ne "" and $webx ne $wb ) {
$err = "WebEnv mismatch in post output - WebEnv1 $wb, WebEnv2 $webx";
write_edirect ( "", $wb, "", "", "", $err, "", "" );
close (STDOUT);
die "WebEnv value changed in post output - WebEnv1 $wb\nWebEnv2 $webx\n";
}
return $webx, $keyx;
}
my $post_help = qq{
-db Database name
-id Unique identifier(s) or accession number(s)
-format uid or acc
-input Read from file instead of stdin
-label Alias for query step
};
sub epost {
# ... | edirect.pl -post -db nucleotide -format uid | ...
clearflags ();
MyGetOptions(
$post_help,
"db=s" => \$db,
"id=s" => \$id,
"format=s" => \$field,
"input=s" => \$input,
"label=s" => \$lbl,
"api_key=s" => \$api_key,
"email=s" => \$emaddr,
"tool=s" => \$tuul,
"help" => \$help,
"silent" => \$silent,
"verbose" => \$verbose,
"debug" => \$debug,
"log" => \$log,
"http=s" => \$http,
"https=s" => \$http,
"alias=s" => \$alias,
"base=s" => \$basx
);
if ( $help ) {
print "epost $version\n";
print $post_help;
return;
}
# convert spaces between UIDs to commas
$id =~ s/ /,/g;
$id =~ s/,,/,/g;
if ( -t STDIN and not @ARGV ) {
} else {
( $dbase, $web, $key, $num, $stp, $err, $tool, $email, $just_num, @rest ) = read_edirect ();
}
read_aliases ();
adjust_base ();
if ( $err ne "" ) {
die "ERROR in post input: $err\n\n";
}
if ( $dbase eq "" ) {
$dbase = $db;
}
$dbase = lc($dbase);
if ( $dbase eq "" ) {
die "Must supply -db database on command line\n";
}
if ( $tuul ne "" ) {
$tool = $tuul;
}
if ( $emaddr ne "" ) {
$email = $emaddr;
}
binmode STDOUT, ":utf8";
if ( $field eq "" ) {
$field = "UID";
}
# read data from input file instead of piping from stdin
if ( $input ne "" ) {
if (open (my $FILE_IN, $input)) {
$has_num = false;
$all_num = true;
while ( $thisline = <$FILE_IN> ) {
$thisline =~ s/\r//;
$thisline =~ s/\n//;
$thisline =~ s/^\s+//;
$thisline =~ s/\s+$//;
if ( $thisline =~ /^(\d+)$/ ) {
push (@rest, $1);
$has_num = true;
} elsif ( $thisline =~ /^(.+)$/ ) {
push (@rest, $1);
$all_num = false;
}
}
close ($FILE_IN);
if ( $has_num && $all_num ) {
$just_num = true;
}
} else {
print STDERR "Unable to open input file '$input'\n";
}
}
my $combo = "";
my $pfx = "";
my $loops = 0;
my $accession_mode = false;
if ( $field eq "ACCN" or $field eq "accn" or $field eq "ACC" or $field eq "acc" ) {
$accession_mode = true;
}
if ( ! $just_num ) {
if ( $dbase eq "nucleotide" or
$dbase eq "nuccore" or
$dbase eq "est" or
$dbase eq "gss" or
$dbase eq "protein" ) {
$accession_mode = true;
$field = "acc";
}
}
if ( $field eq "UID" or $field eq "uid" ) {
if ( $id ne "" ) {
( $web, $key ) = post_chunk ( $dbase, $web, $key, $tool, $email, $id, "" );
$combo .= $pfx . "#" . $key;
$pfx = " OR ";
$loops++;
} else {
while ( @rest ) {
my @chunk = splice(@rest, 0, 2000);
$ids = join (',', @chunk);
if ( $ids =~ /[a-zA-Z]/ ) {
if ( $dbase eq "nucleotide" or
$dbase eq "nuccore" or
$dbase eq "est" or
$dbase eq "gss" or
$dbase eq "protein" ) {
$accession_mode = true;
$field = "acc";
} else {
die "Non-numeric value found in post input\n";
}
}
( $web, $key ) = post_chunk ( $dbase, $web, $key, $tool, $email, $ids, "" );
$combo .= $pfx . "#" . $key;
$pfx = " OR ";
$loops++;
}
}
} else {
if ( $id ne "" ) {
my @chunk = split (',', $id);
if ( $accession_mode ) {
$query = join (' [ACCN] OR ', @chunk);
$query .= " [ACCN]";
$query =~ s/\./_/g;
} else {
$query = join (' OR ', @chunk);
$query .= " [$field]";
}
if ( $accession_mode and $dbase eq "assembly" ) {
$query =~ s/\[ACCN\]/[ASAC]/g;
}
( $web, $key ) = post_chunk ( $dbase, $web, $key, $tool, $email, "", $query );
$combo .= $pfx . "#" . $key;
$pfx = " OR ";
$loops++;
} else {
while ( @rest ) {
my @chunk = splice(@rest, 0, 2000);
if ( $accession_mode ) {
$query = join (' [ACCN] OR ', @chunk);
} else {
$query = join (' OR ', @chunk);
}
if ( $query eq "" ) {
die "Must pipe data into stdin\n";
}
if ( $accession_mode ) {
} elsif ( ! $just_num ) {
die "Non-numeric value found in post input\n";
}
if ( $accession_mode ) {
$query .= " [ACCN]";
$query =~ s/\./_/g;
} else {
$query .= " [$field]";
}
if ( $accession_mode and $dbase eq "assembly" ) {
$query =~ s/\[ACCN\]/[ASAC]/g;
}
( $web, $key ) = post_chunk ( $dbase, $web, $key, $tool, $email, "", $query );
$combo .= $pfx . "#" . $key;
$pfx = " OR ";
$loops++;
}
}
}
if ( $combo eq "" ) {
die "Failure of post to find data to load\n";
}
if ( $loops > 1 ) {
$url = $base . $esearch;
$enc = uri_escape($combo);
$arg = "db=$dbase&term=$enc&WebEnv=$web";
$arg .= "&retmax=0&usehistory=y";
$output = do_post ($url, $arg, $tool, $email, true);
$web = "";
$key = "";
$err = "";
$web = $1 if ($output =~ /<WebEnv>(\S+)<\/WebEnv>/);
$key = $1 if ($output =~ /<QueryKey>(\S+)<\/QueryKey>/);
$err = $1 if ($output =~ /<Error>(.+?)<\/Error>/i);
}
( $num, $key ) = get_count ( $dbase, $web, $key, $tool, $email );
if ( $num eq "" ) {
die "Count value not found in post output - WebEnv1 $web\n";
}
if ( $lbl ne "" and $key ne "" ) {
$labels{"$lbl"} = "$key";
}
write_edirect ( $dbase, $web, $key, $num, $stp, $err, $tool, $email );
}
# espel performs an ESpell search
my $spell_help = qq{
-db Database name
-query Query string
};
sub espel {
# ... | edirect.pl -spell -db pubmed -query "asthmaa OR alergies" | ...
clearflags ();
MyGetOptions(
$spell_help,
"db=s" => \$db,
"query=s" => \$query,
"api_key=s" => \$api_key,
"email=s" => \$emaddr,
"tool=s" => \$tuul,
"help" => \$help,
"silent" => \$silent,
"verbose" => \$verbose,
"debug" => \$debug,
"log" => \$log,
"http=s" => \$http,
"https=s" => \$http,
"alias=s" => \$alias,
"base=s" => \$basx
);
if ( $help ) {
print "espell $version\n";
print $spell_help;
return;
}
# convert spaces between UIDs to commas
$id =~ s/ /,/g;
$id =~ s/,,/,/g;
if ( -t STDIN and not @ARGV ) {
} else {
( $dbase, $web, $key, $num, $stp, $err, $tool, $email, $just_num, @rest ) = read_edirect ();
}
read_aliases ();
adjust_base ();
if ( $err ne "" ) {
die "ERROR in spell input: $err\n\n";
}
if ( $dbase eq "" ) {
$dbase = $db;
}
$dbase = lc($dbase);
if ( $dbase eq "" ) {
die "Must supply -db database on command line\n";
}
if ( $tuul ne "" ) {
$tool = $tuul;
}
if ( $emaddr ne "" ) {
$email = $emaddr;
}
binmode STDOUT, ":utf8";
if ( $query eq "" ) {
die "Must supply -query term expression on command line\n";
}
$url = $base . $espell;
$enc = uri_escape($query);
$arg = "db=$dbase&term=$enc";
$data = do_post ($url, $arg, $tool, $email, true);
Encode::_utf8_on($data);
print "$data";
}
# ecitmtch performs an ECitMatch search
my $citmatch_help = qq{
-journal Journal Title
-year Year
-volume Volume
-page First Page
-author Author Name
};
sub ecitmtch {
# ... | edirect.pl -citmatch -journal "proc natl acad sci u s a" -year 2005 ...
clearflags ();
MyGetOptions(
$citmatch_help,
"journal=s" => \$journal,
"year=s" => \$year,
"volume=s" => \$volume,
"page=s" => \$page,
"author=s" => \$author,
"email=s" => \$emaddr,
"tool=s" => \$tuul,
"help" => \$help,
"silent" => \$silent,
"verbose" => \$verbose,
"debug" => \$debug,
"log" => \$log,
"http=s" => \$http,
"https=s" => \$http,
"alias=s" => \$alias,
"base=s" => \$basx
);
if ( $help ) {
print "ecitmatch $version\n";
print $citmatch_help;
return;
}
# convert spaces between UIDs to commas
$id =~ s/ /,/g;
$id =~ s/,,/,/g;
if ( -t STDIN and not @ARGV ) {
} else {
( $dbase, $web, $key, $num, $stp, $err, $tool, $email, $just_num, @rest ) = read_edirect ();
}
read_aliases ();
adjust_base ();
if ( $err ne "" ) {
die "ERROR in citation match input: $err\n\n";
}
if ( $tuul ne "" ) {
$tool = $tuul;
}
if ( $emaddr ne "" ) {
$email = $emaddr;
}
binmode STDOUT, ":utf8";
$url = $base . $ecitmat;
$query = "";
if ( $journal ne "" ) {
$query .= $journal;
}
$query .= "|";
if ( $year ne "" ) {
$query .= $year;
}
$query .= "|";
if ( $volume ne "" ) {
$query .= $volume;
}
$query .= "|";
if ( $page ne "" ) {
$query .= $page;
}
$query .= "|";
if ( $author ne "" ) {
$query .= $author;
}
$query .= "||";
$enc = uri_escape($query);
$arg = "db=pubmed&retmode=xml&bdata=$enc";
$data = do_post ($url, $arg, $tool, $email, true);
Encode::_utf8_on($data);
if ( $data =~ "NOT_FOUND" ) {
return;
}
if ( $data =~ /.+\|AMBIGUOUS (.+)$/ ) {
my $my_uids = $1;
my @ids = split (',', $my_uids);
foreach $uid (@ids) {
print "$uid\n";
}
return;
}
if ( $data =~ /.+\|(\d+)$/ ) {
my $my_uid = $1;
print "$my_uid\n";
}
}
# eprxy reads a file of query proxies, can also pipe from stdin
my $prxy_help = qq{
-alias File of aliases
-pipe Read aliases from stdin
};
sub eprxy {
# ... | edirect.pl -proxy -alias file_name | ...
clearflags ();
MyGetOptions(
$prxy_help,
"pipe" => \$pipe,
"help" => \$help,
"silent" => \$silent,
"verbose" => \$verbose,
"debug" => \$debug,
"log" => \$log,
"http=s" => \$http,
"https=s" => \$http,
"alias=s" => \$alias,
"base=s" => \$basx
);
if ( $help ) {
print "eproxy $version\n";
print $prxy_help;
return;
}
if ( -t STDIN and not @ARGV ) {
} elsif ( $pipe ) {
} else {
( $dbase, $web, $key, $num, $stp, $err, $tool, $email, $just_num, @rest ) = read_edirect ();
}
read_aliases ();
adjust_base ();
if ( $pipe ) {
while ( defined($thisline = <STDIN>) ) {
$thisline =~ s/\r//;
$thisline =~ s/\n//;
$thisline =~ s/ +/ /g;
$thisline =~ s/> </></g;
if ( $thisline =~ /(.+)\t(.+)/ ) {
$ky = $1;
$vl = $2;
$vl =~ s/\"//g;
$macros{"$ky"} = "$vl";
}
}
}
write_edirect ( $dbase, $web, $key, $num, $stp, $err, $tool, $email );
}
# esrch performs a new EUtils search, but can read a previous web environment value
my $srch_help = qq{
Query Specification
-db Database name
-query Query string
Document Order
-sort Result presentation order
Date Constraint
-days Number of days in the past
-datetype Date field abbreviation
-mindate Start of date range
-maxdate End of date range
Limit by Field
-field Query words individually in field
-pairs Query overlapping word pairs
Spell Check
-spell Correct misspellings in query
Miscellaneous Arguments
-label Alias for query step
Sort Order Examples
-db -sort
___ _____
gene
Chromosome
Gene Weight
Name
Relevance
geoprofiles
Default Order
Deviation
Mean Value
Outliers
Subgroup Effect
pubmed
First Author
Journal
Last Author
Pub Date
Recently Added
Relevance
Title
(sequences)
Accession
Date Modified
Date Released
Default Order
Organism Name
Taxonomy ID
snp
Chromosome Base Position
Default Order
Heterozygosity
Organism
SNP_ID
Success Rate
};
sub remove_punctuation {
my $qury = shift (@_);
$qury =~ s/[^a-zA-Z0-9]/ /g;
$qury =~ s/ +/ /g;
return $qury;
}
sub remove_stop_words {
my $qury = shift (@_);
# split to protect against regular expression artifacts
$qury =~ s/[^a-zA-Z0-9]/ /g;
$qury =~ s/ +/ /g;
my @words = split (' ', $qury);
my $kept = "";
my $pfx = "";
foreach $term (@words) {
my $trm = lc($term);
$trm = "#$trm#";
if ($stop_words !~ /$trm/) {
$kept .= "$pfx$term";
$pfx = " ";
}
}
if ( $kept ne "" ) {
$qury = $kept;
}
return $qury;
}
sub field_each_word {
my $fld = shift (@_);
my $qury = shift (@_);
$qury =~ s/,/ /g;
$qury =~ s/ +/ /g;
my @words = split (' ', $qury);
$qury = "";
my $pfx = "";
foreach $term (@words) {
$qury .= "$pfx$term [$fld]";
$pfx = " AND ";
}
return $qury;
}
sub merge_each_word {
my $fld = shift (@_);
my $qury = shift (@_);
$qury =~ s/,/ /g;
$qury =~ s/ +/ /g;
my @words = split (' ', $qury);
$qury = "";
my $pfx = "";
foreach $term (@words) {
$qury .= "$pfx$term [$fld]";
$pfx = " OR ";
}
return $qury;
}
sub field_each_pair {
my $fld = shift (@_);
my $qury = shift (@_);
my @words = split (' ', $qury);
$qury = "";
my $pfx = "";
my $prev = "";
foreach $term (@words) {
my $trm = lc($term);
$trm = "#$trm#";
if ($stop_words =~ /$trm/) {
$prev = "";
$term = "";
}
if ( $prev ne "" ) {
$qury .= "$pfx\"$prev $term\" [$fld]";
$pfx = " AND ";
}
$prev = $term;
}
return $qury;
}
sub esrch {
# ... | edirect.pl -search -db nucleotide -query "M6506* [ACCN] OR 1322283 [UID]" -days 365 | ...
clearflags ();
MyGetOptions(
$srch_help,
"db=s" => \$db,
"query=s" => \$query,
"sort=s" => \$sort,
"days=i" => \$rldate,
"mindate=s" => \$mndate,
"maxdate=s" => \$mxdate,
"datetype=s" => \$dttype,
"label=s" => \$lbl,
"pub=s" => \$pub,
"feature=s" => \$feature,
"location=s" => \$location,
"molecule=s" => \$molecule,
"organism=s" => \$organism,
"source=s" => \$source,
"status=s" => \$status,
"type=s" => \$gtype,
"clean" => \$clean,
"field=s" => \$field,
"word" => \$word,
"drop" => \$drop,
"trim" => \$trim,
"trunc" => \$trunc,
"spell" => \$spell,
"split=s" => \$split,
"merge=s" => \$meadow,
"pairs=s" => \$pair,
"api_key=s" => \$api_key,
"email=s" => \$emaddr,
"tool=s" => \$tuul,
"help" => \$help,
"silent" => \$silent,
"verbose" => \$verbose,
"debug" => \$debug,
"log" => \$log,
"http=s" => \$http,
"https=s" => \$http,
"alias=s" => \$alias,
"base=s" => \$basx
);
if ( $help ) {
print "esearch $version\n";
print $srch_help;
return;
}
if ( -t STDIN and not @ARGV ) {
} else {
( $dbase, $web, $key, $num, $stp, $err, $tool, $email, $just_num, @rest ) = read_edirect ();
}
read_aliases ();
adjust_base ();
if ( $err ne "" ) {
die "ERROR in search input: $err\n\n";
}
if ( $db ne "" ) {
$dbase = $db;
}
$dbase = lc($dbase);
if ( $dbase eq "" ) {
die "Must supply -db database on command line\n";
}
if ( $tuul ne "" ) {
$tool = $tuul;
}
if ( $emaddr ne "" ) {
$email = $emaddr;
}
binmode STDOUT, ":utf8";
# support all efilter shortcut flags in esearch (undocumented)
$query = process_extras ( $query, $pub, $feature, $location, $molecule, $organism, $source, $status, $gtype );
if ( $query eq "" ) {
die "Must supply -query search expression on command line\n";
}
$url = $base . $esearch;
$query = map_labels ($query);
$query = map_macros ($query);
# multi-step query cleaning (undocumented)
if ( $clean ) {
if ( $query =~ /^(.*)\(.+\)(.*)$/ ) {
$query = "$1 $2";
}
if ( $query =~ /^ +(.+)$/ ) {
$query = $1;
}
if ( $query =~ /^(.+) +$/ ) {
$query = $1;
}
$query =~ s/ +/ /g;
$query = remove_stop_words ($query);
$query = spell_check_query ($dbase, $query);
}
# remove punctuation from query (undocumented)
if ( $word ) {
$query = remove_punctuation ($query);
}
# drop stop words from query (undocumented)
if ( $drop ) {
$query = remove_stop_words ($query);
}
# trim words within parentheses (undocumented)
if ( $trim ) {
if ( $query =~ /^(.*)\(.+\)(.*)$/ ) {
$query = "$1 $2";
}
}
# truncate words at first parenthesis (undocumented)
if ( $trunc ) {
if ( $query =~ /^(.+)\(.*$/ ) {
$query = $1;
}
}
# remove leading, trailing, and multiple spaces
if ( $query =~ /^ +(.+)$/ ) {
$query = $1;
}
if ( $query =~ /^(.+) +$/ ) {
$query = $1;
}
$query =~ s/ +/ /g;
# spell check each query word
if ( $spell ) {
$query = spell_check_query ($dbase, $query);
}
# force each query word to be separately fielded, combined with AND (undocumented)
if ( $split ne "" ) {
$query = field_each_word ($split, $query);
}
# force each query word to be separately fielded, combined with OR (undocumented)
if ( $meadow ne "" ) {
$query = merge_each_word ($meadow, $query);
}
# -field combines -drop and -split (-field TITL produces same behavior as Web PubMed)
if ( $field ne "" ) {
$query = remove_stop_words ($query);
$query = field_each_word ($field, $query);
}
# -pairs separately fields query word pairs, breaking chain at stop words
if ( $pair ne "" ) {
$query = remove_punctuation ($query);
if ( $query =~ /^ +(.+)$/ ) {
$query = $1;
}
if ( $query =~ /^(.+) +$/ ) {
$query = $1;
}
$query =~ s/ +/ /g;
$query = field_each_pair ($pair, $query);
}
$enc = uri_escape($query);
$arg = "db=$dbase&term=$enc";
if ( $web ne "" ) {
$arg .= "&WebEnv=$web";
}
if ( $sort ne "" ) {
$arg .= "&sort=$sort";
}
$arg .= "&retmax=0&usehistory=y";
if ( $rldate > 0 ) {
$arg .= "&reldate=$rldate";
if ( $dttype eq "" ) {
$dttype = "PDAT";
}
}
if ( $mndate ne "" and $mxdate ne "" ) {
$arg .= "&mindate=$mndate&maxdate=$mxdate";
if ( $dttype eq "" ) {
$dttype = "PDAT";
}
}
if ( $dttype ne "" ) {
$arg .= "&datetype=$dttype";
}
$wb = $web;
$output = do_post ($url, $arg, $tool, $email, true);
$web = "";
$key = "";
$num = "";
$err = "";
my $trn = "";
$web = $1 if ($output =~ /<WebEnv>(\S+)<\/WebEnv>/);
$key = $1 if ($output =~ /<QueryKey>(\S+)<\/QueryKey>/);
$num = $1 if ($output =~ /<Count>(\S+)<\/Count>/);
$err = $1 if ($output =~ /<Error>(.+?)<\/Error>/i);
$trn = $1 if ($output =~ /<QueryTranslation>(.+?)<\/QueryTranslation>/i);
if ( $err ne "" ) {
write_edirect ( "", "", "", "", "", $err, "", "" );
close (STDOUT);
die "ERROR in search output: $err\nURL: $arg\n\n";
}
if ( $web eq "" ) {
die "WebEnv value not found in search output - WebEnv1 $wb\n";
}
if ( $key eq "" ) {
die "QueryKey value not found in search output - WebEnv1 $wb\n";
}
if ( $wb ne "" and $web ne $wb ) {
$err = "WebEnv mismatch in search output - WebEnv1 $wb, WebEnv2 $web";
write_edirect ( "", $wb, "", "", "", $err, "", "" );
close (STDOUT);
die "WebEnv value changed in search output - WebEnv1 $wb\nWebEnv2 $web\n";
}
if ( $num eq "" ) {
die "Count value not found in search output - WebEnv1 $web\n";
}
if ( $lbl ne "" and $key ne "" ) {
$labels{"$lbl"} = "$key";
}
write_edirect ( $dbase, $web, $key, $num, $stp, $err, $tool, $email );
if ( $log ) {
if ( $trn ne "" ) {
print STDERR "$trn\n";
}
}
}
# eaddr returns the current user's e-mail address
sub eaddr {
my $addr = get_email ();
print "$addr\n";
}
# etest is an unadvertised function for development
sub etest {
# $addr = get_email ();
# print "e-mail: $addr\n";
}
# esample is an unadvertised function for development
my $sample_pubmed = qq{
<PubmedArticle>
<MedlineCitation Status="MEDLINE" Owner="NLM">
<PMID Version="1">6301692</PMID>
<DateCreated>
<Year>1983</Year>
<Month>06</Month>
<Day>17</Day>
</DateCreated>
<DateCompleted>
<Year>1983</Year>
<Month>06</Month>
<Day>17</Day>
</DateCompleted>
<DateRevised>
<Year>2007</Year>
<Month>11</Month>
<Day>14</Day>
</DateRevised>
<Article PubModel="Print">
<Journal>
<ISSN IssnType="Print">0092-8674</ISSN>
<JournalIssue CitedMedium="Print">
<Volume>32</Volume>
<Issue>4</Issue>
<PubDate>
<Year>1983</Year>
<Month>Apr</Month>
</PubDate>
</JournalIssue>
<Title>Cell</Title>
<ISOAbbreviation>Cell</ISOAbbreviation>
</Journal>
<ArticleTitle>Site-specific relaxation and recombination by the Tn3 resolvase: recognition of the DNA path between oriented res sites.</ArticleTitle>
<Pagination>
<MedlinePgn>1313-24</MedlinePgn>
</Pagination>
<Abstract>
<AbstractText Label="RESULTS>We studied the dynamics of site-specific recombination by the resolvase encoded by the Escherichia coli transposon Tn3.
The pure enzyme recombined supercoiled plasmids containing two directly repeated recombination sites, called res sites.
Resolvase is the first strictly site-specific topoisomerase.
It relaxed only plasmids containing directly repeated res sites; substrates with zero, one or two inverted sites were inert.
Even when the proximity of res sites was ensured by catenation of plasmids with a single site, neither relaxation nor recombination occurred.
The two circular products of recombination were catenanes interlinked only once.
These properties of resolvase require that the path of the DNA between res sites be clearly defined and that strand exchange occur with a unique geometry.</AbstractText>
<AbstractText Label="SUMMARY">A model in which one subunit of a dimeric resolvase is bound at one res site,
while the other searches along adjacent DNA until it encounters the second site,
would account for the ability of resolvase to distinguish intramolecular from intermolecular sites,
to sense the relative orientation of sites and to produce singly interlinked catenanes.
Because resolvase is a type 1 topoisomerase, we infer that it makes the required duplex bDNA breaks of recombination one strand at a time.</AbstractText>
</Abstract>
<AuthorList CompleteYN="Y">
<Author ValidYN="Y">
<LastName>Krasnow</LastName>
<ForeName>Mark A</ForeName>
<Initials>MA</Initials>
</Author>
<Author ValidYN="Y">
<LastName>Cozzarelli</LastName>
<ForeName>Nicholas R</ForeName>
<Initials>NR</Initials>
</Author>
</AuthorList>
<Language>eng</Language>
<GrantList CompleteYN="Y">
<Grant>
<GrantID>GM-07281</GrantID>
<Acronym>GM</Acronym>
<Agency>NIGMS NIH HHS</Agency>
<Country>United States</Country>
</Grant>
</GrantList>
<PublicationTypeList>
<PublicationType UI="D016428">Journal Article</PublicationType>
<PublicationType UI="D013487">Research Support, U.S. Gov't, P.H.S.</PublicationType>
</PublicationTypeList>
</Article>
<MedlineJournalInfo>
<Country>United States</Country>
<MedlineTA>Cell</MedlineTA>
<NlmUniqueID>0413066</NlmUniqueID>
<ISSNLinking>0092-8674</ISSNLinking>
</MedlineJournalInfo>
<ChemicalList>
<Chemical>
<RegistryNumber>0</RegistryNumber>
<NameOfSubstance UI="D004269">DNA, Bacterial</NameOfSubstance>
</Chemical>
<Chemical>
<RegistryNumber>0</RegistryNumber>
<NameOfSubstance UI="D004278">DNA, Superhelical</NameOfSubstance>
</Chemical>
<Chemical>
<RegistryNumber>0</RegistryNumber>
<NameOfSubstance UI="D004279">DNA, Viral</NameOfSubstance>
</Chemical>
<Chemical>
<RegistryNumber>EC 2.7.7.-</RegistryNumber>
<NameOfSubstance UI="D009713">Nucleotidyltransferases</NameOfSubstance>
</Chemical>
<Chemical>
<RegistryNumber>EC 2.7.7.-</RegistryNumber>
<NameOfSubstance UI="D019895">Transposases</NameOfSubstance>
</Chemical>
<Chemical>
<RegistryNumber>EC 5.99.1.2</RegistryNumber>
<NameOfSubstance UI="D004264">DNA Topoisomerases, Type I</NameOfSubstance>
</Chemical>
</ChemicalList>
<CitationSubset>IM</CitationSubset>
<MeshHeadingList>
<MeshHeading>
<DescriptorName UI="D004264" MajorTopicYN="N">DNA Topoisomerases, Type I</DescriptorName>
<QualifierName UI="Q000378" MajorTopicYN="N">metabolism</QualifierName>
</MeshHeading>
<MeshHeading>
<DescriptorName UI="D004269" MajorTopicYN="N">DNA, Bacterial</DescriptorName>
<QualifierName UI="Q000378" MajorTopicYN="Y">metabolism</QualifierName>
</MeshHeading>
<MeshHeading>
<DescriptorName UI="D004278" MajorTopicYN="N">DNA, Superhelical</DescriptorName>
<QualifierName UI="Q000378" MajorTopicYN="N">metabolism</QualifierName>
</MeshHeading>
<MeshHeading>
<DescriptorName UI="D004279" MajorTopicYN="N">DNA, Viral</DescriptorName>
<QualifierName UI="Q000378" MajorTopicYN="Y">metabolism</QualifierName>
</MeshHeading>
<MeshHeading>
<DescriptorName UI="D008957" MajorTopicYN="N">Models, Genetic</DescriptorName>
</MeshHeading>
<MeshHeading>
<DescriptorName UI="D009690" MajorTopicYN="Y">Nucleic Acid Conformation</DescriptorName>
</MeshHeading>
<MeshHeading>
<DescriptorName UI="D009713" MajorTopicYN="N">Nucleotidyltransferases</DescriptorName>
<QualifierName UI="Q000302" MajorTopicYN="N">isolation & purification</QualifierName>
<QualifierName UI="Q000378" MajorTopicYN="Y">metabolism</QualifierName>
</MeshHeading>
<MeshHeading>
<DescriptorName UI="D010957" MajorTopicYN="N">Plasmids</DescriptorName>
</MeshHeading>
<MeshHeading>
<DescriptorName UI="D011995" MajorTopicYN="Y">Recombination, Genetic</DescriptorName>
</MeshHeading>
<MeshHeading>
<DescriptorName UI="D012091" MajorTopicYN="N">Repetitive Sequences, Nucleic Acid</DescriptorName>
</MeshHeading>
<MeshHeading>
<DescriptorName UI="D013539" MajorTopicYN="N">Simian virus 40</DescriptorName>
</MeshHeading>
<MeshHeading>
<DescriptorName UI="D019895" MajorTopicYN="N">Transposases</DescriptorName>
</MeshHeading>
</MeshHeadingList>
</MedlineCitation>
<PubmedData>
<History>
<PubMedPubDate PubStatus="pubmed">
<Year>1983</Year>
<Month>4</Month>
<Day>1</Day>
</PubMedPubDate>
<PubMedPubDate PubStatus="medline">
<Year>1983</Year>
<Month>4</Month>
<Day>1</Day>
<Hour>0</Hour>
<Minute>1</Minute>
</PubMedPubDate>
<PubMedPubDate PubStatus="entrez">
<Year>1983</Year>
<Month>4</Month>
<Day>1</Day>
<Hour>0</Hour>
<Minute>0</Minute>
</PubMedPubDate>
</History>
<PublicationStatus>ppublish</PublicationStatus>
<ArticleIdList>
<ArticleId IdType="pubmed">6301692</ArticleId>
<ArticleId IdType="pii">0092-8674(83)90312-4</ArticleId>
</ArticleIdList>
</PubmedData>
</PubmedArticle>
};
sub esample {
print "$sample_pubmed";
}
# main block dispatches control to appropriate subroutine
if ( scalar @ARGV > 0 and $ARGV[0] eq "-version" ) {
print "$version\n";
} elsif ( $fnc eq "-search" ) {
esrch ();
} elsif ( $fnc eq "-link" ) {
elink ();
} elsif ( $fnc eq "-filter" ) {
efilt ();
} elsif ( $fnc eq "-summary" ) {
eftch ();
} elsif ( $fnc eq "-fetch" ) {
eftch ();
} elsif ( $fnc eq "-info" ) {
einfo ();
} elsif ( $fnc eq "-post" ) {
epost ();
} elsif ( $fnc eq "-spell" ) {
espel ();
} elsif ( $fnc eq "-citmatch" ) {
ecitmtch ();
} elsif ( $fnc eq "-proxy" ) {
eprxy ();
} elsif ( $fnc eq "-contact" ) {
ecntc ();
} elsif ( $fnc eq "-notify" ) {
entfy ();
} elsif ( $fnc eq "-address" ) {
eaddr ();
} elsif ( $fnc eq "-test" ) {
etest ();
} elsif ( $fnc eq "-sample" ) {
esample ();
} else {
die "Function name '$fnc' not recognized\n";
}
# close input and output files
close (STDIN);
close (STDOUT);
close (STDERR);
|