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
|
#! /usr/bin/env ruby
#
# Copyright (c) 2010-2011 Giorgio Gonnella <gonnella@zbh.uni-hamburg.de>
# Copyright (c) 2010-2011 Center for Bioinformatics, University of Hamburg
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#
## Extensions to base classes ##
class Float
# round a float to a given n of decimals
# or an integer if precision is 0
def with_precision(precision)
if precision > 0
return ((self * (10 ** precision)).round.to_f) / (10 ** precision)
else
return self.round
end
end
end
class Fixnum
# given a number of seconds, return a string with hours and minutes
def s2hm
h = self / 3600
m = (self % 3600) / 60
(h > 0) ? "#{h} h #{m} min" : "#{m} min"
end
end
class String
def escape_for_latex!
self.gsub!("%", "\\%")
self.gsub!("_", "\\_")
return self
end
end
# modified from: http://blog.sethladd.com/2007/03/creating-combinations-of.html
class Array
def choose(k)
return [[]] if nil? || empty? && k == 0
return [] if nil? || empty? && k > 0
return [[]] if size > 0 && k == 0
c2 = clone
c2.pop
new_element = clone.pop
return c2.choose(k) + c2.choose(k-1).map {|l| l << new_element}
end
end
# for the -raw option:
# modified from: http://snippets.dzone.com/posts/show/5811
require 'yaml'
class Hash
def to_yaml( opts = {} )
YAML::quick_emit( object_id, opts ) do |out|
out.map( taguri, to_yaml_style ) do |map|
sort_by{|k, v| k.to_s}.each do |k, v|
map.add( k, v )
end
end
end
end
end
class Numeric
MemUnits = [:b, :kb, :Mb, :Gb, :Tb]
MemUnitsDefaultPrecision = {:b => 0, :kb => 0, :Mb => 0, :Gb => 1, :Tb => 3}
def mem_convert(from, to, precision = nil)
if !MemUnits.include?(from) or !MemUnits.include?(to)
raise ArgumentError, "allowed values: #{MemUnits.join(', ')}"
end
if precision.nil?
precision = MemUnitsDefaultPrecision[to]
end
from_factor = MemUnits.index(from)
to_factor = MemUnits.index(to)
result = self.to_f * (1024**(from_factor)) / (1024**(to_factor))
return result.with_precision(precision)
end
end
## OutputParser: search information in different kinds of logs ##
module OutputParser
module Common
# output a warning if the given variable was
# already assigned to a different value
def warn_if_not_nil(var, newvalue)
oldvalue = instance_variable_get(var)
if !oldvalue.nil? && oldvalue != newvalue && !@warned
@warned = true
STDERR.puts "#{self.class} warning: multiple measurements found! "+
"The value of #{var} was #{oldvalue.inspect}."
end
end
private :warn_if_not_nil
def disable_float_conversion
@noautofloat = true
end
private :disable_float_conversion
def enable_float_conversion
@noautofloat = false
end
private :enable_float_conversion
# assign one or more variables using a regex if a match is found
def detect(line, regex, *values)
detected = false
@operation ||= []
if line =~ regex
detected = true
values.each_with_index do |var, i|
@operation[i+1] ||= ".to_f" unless @noautofloat
value = eval("$#{i+1}#{@operation[i+1]}")
warn_if_not_nil(var, value)
instance_variable_set(var, value)
end
end
@operation = []
return detected
end
private :detect
# autodiscover all public methods and return an hash with the values
def results
mets = self.class.instance_methods - ["results"] -
self.class.superclass.instance_methods
retval = {}
mets.each do |met|
retval[met.to_sym] = send(met)
end
return retval
end
def clean_readset_name
if @readset
@readset = File.basename(@readset)
if @readset =~ /^([\w-]+).reads.fas$/
@readset = $1
end
end
end
# --- class methods ---
def self.included(klass)
klass.extend ClassMethods
end
module ClassMethods
# delegate a method to an instance variable
def delegate(method, var, var_method = method)
class_eval <<-enddef
def #{method}
@#{var}.#{var_method}
end
enddef
end
end
end
### === Log parts === ###
class Info
include Common
def initialize(log)
@operation = []
parse(log)
end
attr_reader :hostname, :compiler, :lastcommit
private
def parse(log)
@operation[1] = "" #next detect: no auto-conversion into Float for $1
detect(log, /^# hostname: (.*)\s*$/, "@hostname")
@operation[1] = "" #next detect: no auto-conversion into Float for $1
detect(log, /^# compiler: (\w+).*$/, "@compiler")
@operation[1] = "" #next detect: no auto-conversion into Float for $1
detect(log, /^# last commit: (\w{7}).*$/, "@lastcommit")
end
end
# the "parser" classes return time in s and space in Mb, as numerics;
# lengths and counts are return as numeric values
# reads most common time output formats (built-in time, GNU time, ...);
# output a warning if more than one measurement is found in a log;
# the *_time methods return nil or the time in seconds as float;
# the cpu_time is defined as sum of user and sys;
# cpu/sys/user is checked against real for plausibility (for n threads)
class Time
include Common
def initialize(log, threads = 1)
parse(log)
@threads = threads
end
attr_reader :real_time
def user_time
if @user_time
warn_if_too_large("user_time")
return @user_time
end
end
def sys_time
if @sys_time
warn_if_too_large("sys_time")
return @sys_time
end
end
def cpu_time
if @user_time.nil? || @sys_time.nil?
return nil
else
@cpu_time = @user_time.to_f + @sys_time.to_f
warn_if_too_large("cpu_time")
return @cpu_time
end
end
def real_cpu_time_diff
if @real_time.nil? || cpu_time.nil?
return nil
else
return @real_time - cpu_time
end
end
private
Tolerance = 2 # seconds
def warn_if_too_large(var)
value = eval("@#{var}")
if (!value.nil?) && (!@real_time.nil?)
if value > (@real_time * @threads + Tolerance) && !@time_warning
thrstr = ''
thrstr = " * #{@threads}" if @threads > 1
STDERR.puts "#{self.class} warning: #{var} > real#{thrstr}!"
@time_warning = true
end
end
end
def detect_hms(line, regex, var)
@t1, @t2, @t3 = nil, nil, nil
detected = detect(line, regex, "@t1", "@t2", "@t3")
if detected
t = @t1 * 3600 + @t2 * 60 + @t3
warn_if_not_nil(var, t)
eval("#{var} = t")
end
return detected
end
def detect_ms(line, regex, var)
@t1, @t2 = nil, nil
detected = detect(line, regex, "@t1", "@t2")
if detected
t = @t1 * 60 + @t2
warn_if_not_nil(var, t)
eval("#{var} = t")
end
return detected
end
def detect_usr(line, us, r_with_h, r_without_h)
detected = detect(line, us, "@user_time", "@sys_time")
if detected
detected2 = detect_hms(line, / (\d+):(\d+):(\d+.?\d*)elapsed/,
"@real_time")
if !detected2
detect_ms(line, / (\d+):(\d+.?\d*)elapsed/, "@real_time")
end
end
return detected
end
def parse(log)
log.each_line do |line|
detect(line, /^user (\d+\.\d+)/, "@user_time")
detect_ms(line, /^user\s+(\d+)m(\d+.\d+)s/, "@user_time")
detect(line, /^real (\d+\.\d+)/, "@real_time" )
detect_ms(line, /^real\s+(\d+)m(\d+.\d+)s/, "@real_time")
detect(line, /^sys (\d+\.\d+)/, "@sys_time")
detect(line, /^sys\s+(\d+)m(\d+.\d+)s/, "@sys_time")
detect_usr(line, /^(\d+\.\d+)user (\d+\.\d+)system /,
/ (\d+):(\d+):(\d+.?\d*)elapsed/,
/ (\d+):(\d+.?\d*)elapsed/)
detect_usr(line, /^(\d+\.\d+)u (\d+\.\d+)s/, / (\d+):(\d+):(\d+.\d+)/,
/ (\d+):(\d+\.\d+)/)
end
end
end
# reads the output format of the measure_space_peak script
# the values are returned as Floats and are expressed in Mb
class MeasureSpacePeak
include Common
def initialize(log)
parse(log)
correct_units
end
attr_reader :vm_peak, :vm_size, :vm_lck, :vm_hwm, :vm_rss, :vm_data,
:vm_stk, :vm_exe, :vm_lib, :vm_pte
private
def parse(log)
log.each_line do |line|
detect(line, /VmPeak:\s+(\d+) kB/, "@vm_peak")
detect(line, /VmSize:\s+(\d+) kB/, "@vm_size")
detect(line, /VmLck:\s+(\d+) kB/, "@vm_lck")
detect(line, /VmHWM:\s+(\d+) kB/, "@vm_hwm")
detect(line, /VmRSS:\s+(\d+) kB/, "@vm_rss")
detect(line, /VmData:\s+(\d+) kB/, "@vm_data")
detect(line, /VmStk:\s+(\d+) kB/, "@vm_stk")
detect(line, /VmExe:\s+(\d+) kB/, "@vm_exe")
detect(line, /VmLib:\s+(\d+) kB/, "@vm_lib")
detect(line, /VmPTE:\s+(\d+) kB/, "@vm_pte")
end
end
def correct_units
@vm_peak = @vm_peak.mem_convert(:kb, :Mb) if @vm_peak
@vm_size = @vm_size.mem_convert(:kb, :Mb) if @vm_size
@vm_lck = @vm_lck.mem_convert(:kb, :Mb) if @vm_lck
@vm_hwm = @vm_hwm.mem_convert(:kb, :Mb) if @vm_hwm
@vm_rss = @vm_rss.mem_convert(:kb, :Mb) if @vm_rss
@vm_data = @vm_data.mem_convert(:kb, :Mb) if @vm_data
@vm_stk = @vm_stk.mem_convert(:kb, :Mb) if @vm_stk
@vm_exe = @vm_exe.mem_convert(:kb, :Mb) if @vm_exe
@vm_lib = @vm_lib.mem_convert(:kb, :Mb) if @vm_lib
@vm_pte = @vm_pte.mem_convert(:kb, :Mb) if @vm_pte
end
end
# parser for the genometools -showtime and -spacepeak output
class Genometools
include Common
def initialize(log)
@time = {:real => {}, :user => {}, :sys => {}}
@space_peak = {}
parse(log)
end
attr_reader :mmap_peak, :alloc_peak, :time, :space_peak
def real_time_overall
@time[:real]["overall"]
end
def user_time_overall
@time[:user]["overall"]
end
def sys_time_overall
@time[:sys]["overall"]
end
def cpu_time_overall
if sys_time_overall && user_time_overall
sys_time_overall + user_time_overall
end
end
def real_cpu_time_diff_overall
if real_time_overall.nil? || cpu_time_overall.nil?
return nil
else
return real_time_overall - cpu_time_overall
end
end
def space_peak_overall
if @overall_peak
return @overall_peak
elsif @space_peak["overall"]
return @space_peak["overall"]
# otherwise use sum of mmap and alloc peaks
elsif mmap_peak.nil? or alloc_peak.nil?
return nil
else
return mmap_peak + alloc_peak
end
end
private
def parse(log)
log.each_line do |line|
detect(line, /# mmap space peak in megabytes: (\d+.\d+)/,
"@mmap_peak")
detect(line, /# space peak in megabytes: (\d+.\d+)/,
"@alloc_peak")
detect(line, /# combined space peak in megabytes: (\d+.\d+)/,
"@overall_peak")
@operation[1] = "" #next detect: no auto-conversion into Float for $1
d = detect(line, /# TIME (.*?) (\d+\.\d+)/, "@tmpdesc", "@tmptime")
if d
@time[:real][@tmpdesc] = @tmptime
d = detect(line, /\(user: (\d+\.\d+); sys: (\d+\.\d+)\)/, "@tmputime",
"@tmpstime")
if d
@time[:user][@tmpdesc] = @tmputime
@time[:sys][@tmpdesc] = @tmpstime
end
@tmpdesc, @tmptime, @tmputime, @tmpstime = nil, nil, nil, nil
end
@operation[1] = "" #next detect: no auto-conversion into Float for $1
d = detect(line, /# SPACE PEAK (.*?) (\d+\.\d+) Mb/, "@tmpdesc",
"@tmpspace")
if d
@space_peak[@tmpdesc] = @tmpspace
@tmpdesc, @tmpspace = nil, nil
end
end
end
end
class SeqstatContigs
include Common
def initialize(log)
parse(log)
end
attr_reader :n50, :n80, :lngst, :nofcontigs, :tcontigslen
private
def parse(log)
detect(log, /# N50:\s+(\d+)/, "@n50")
detect(log, /# N80:\s+(\d+)/, "@n80")
detect(log, /# longest contig:\s+(\d+)/, "@lngst")
detect(log,
/# number of contigs:\s+(\d+)\n# total length:\s+(\d+)/m,
"@nofcontigs", "@tcontigslen")
if !@tcontigslen
detect(log,
/# number of contigs:\s+(\d+)\n# total contigs length:\s+(\d+)/m,
"@nofcontigs", "@tcontigslen")
end
if log =~ /# no contigs/
@nofcontigs = 0
@n50 = 0
@n80 = 0
@lngst = 0
@tcontigslen = 0
end
end
end
### ===== programs ===== ###
class SgaIndex
include Common
def initialize(log)
@i = ::OutputParser::Info.new(log)
@t = ::OutputParser::Time.new(log)
@msp = ::OutputParser::MeasureSpacePeak.new(log)
parse(log)
end
attr_reader :sga_index_d, :nofreads, :readset
delegate :index_hostname, :i, :hostname
delegate :index_real_time, :t, :real_time
delegate :index_user_time, :t, :user_time
delegate :index_sys_time, :t, :sys_time
delegate :index_cpu_time, :t, :cpu_time
delegate :index_real_cpu_time_diff, :t, :real_cpu_time_diff
delegate :index_hwm_space, :msp, :vm_hwm
delegate :index_vm_peak, :msp, :vm_peak
def index_pipeline
"Sga"
end
private
def parse(log)
detect(log, /sga index.*-d (\d+).*/, "@sga_index_d")
arr = log.scan(/Merge\d+: \[\d+,(\d+)\].*/)
if !arr.empty?
@nofreads = arr.flatten.map{|x|x.to_i}.max
end
disable_float_conversion
detect(log, /Building index for (\S+)/, "@readset")
clean_readset_name
end
end
class SgaOverlap
include Common
def initialize(log)
@i = ::OutputParser::Info.new(log)
@t = ::OutputParser::Time.new(log)
@msp = ::OutputParser::MeasureSpacePeak.new(log)
parse(log)
end
attr_reader :minlen
delegate :overlap_hostname, :i, :hostname
delegate :overlap_real_time, :t, :real_time
delegate :overlap_user_time, :t, :user_time
delegate :overlap_sys_time, :t, :sys_time
delegate :overlap_cpu_time, :t, :cpu_time
delegate :overlap_real_cpu_time_diff, :t, :real_cpu_time_diff
delegate :overlap_hwm_space, :msp, :vm_hwm
delegate :overlap_vm_peak, :msp, :vm_peak
def overlap_pipeline
"Sga"
end
private
def parse(log)
detect(log, /.*sga overlap.*?-m (\d+).*/, "@minlen")
end
end
class SgaAssembly
include Common
def initialize(log)
@i = ::OutputParser::Info.new(log)
@t = ::OutputParser::Time.new(log)
@msp = ::OutputParser::MeasureSpacePeak.new(log)
@ssc = ::OutputParser::SeqstatContigs.new(log)
end
delegate :assembly_hostname, :i, :hostname
delegate :assembly_real_time, :t, :real_time
delegate :assembly_user_time, :t, :user_time
delegate :assembly_sys_time, :t, :sys_time
delegate :assembly_cpu_time, :t, :cpu_time
delegate :assembly_real_cpu_time_diff, :t, :real_cpu_time_diff
delegate :assembly_hwm_space, :msp, :vm_hwm
delegate :assembly_vm_peak, :msp, :vm_peak
delegate :nofcontigs, :ssc, :nofcontigs
delegate :lngst, :ssc, :lngst
delegate :n50, :ssc, :n50
delegate :n80, :ssc, :n80
delegate :tcontigslen, :ssc, :tcontigslen
def assembly_pipeline
"Sga"
end
end
class Leap
include Common
def initialize(log)
@i = ::OutputParser::Info.new(log)
@t = ::OutputParser::Time.new(log)
@msp = ::OutputParser::MeasureSpacePeak.new(log)
@ssc = ::OutputParser::SeqstatContigs.new(log)
parse(log)
end
attr_reader :minlen, :tcontigslen, :lngst, :nofcontigs, :nofreads,
:contreads, :contreads_percent, :tlen, :readset
delegate :overall_hostname, :i, :hostname
delegate :overall_real_time, :t, :real_time
delegate :overall_user_time, :t, :user_time
delegate :overall_sys_time, :t, :sys_time
delegate :overall_cpu_time, :t, :cpu_time
delegate :overall_real_cpu_time_diff, :t, :real_cpu_time_diff
delegate :overall_hwm_space, :msp, :vm_hwm
delegate :overall_vm_peak, :msp, :vm_peak
delegate :n50, :ssc, :n50
delegate :n80, :ssc, :n80
def overlap_pipeline
"Leap"
end
def readlen
if @minreadlen == @maxreadlen
@minreadlen
else
"variable"
end
end
private
def parse(log)
detect(log, /^overlap threshold: (\d+)/, "@minlen")
detect(log, /^total contig length: (\d+)/, "@tcontigslen")
detect(log, /^max contig length: (\d+)/, "@lngst")
detect(log, /^#contigs: (\d+)/, "@nofcontigs")
detect(log, /^#reads = (\d+)/, "@nofreads")
detect(log, /remove contained reads:.*\n#reads = (\d+)/, "@nofcfreads")
if !@nofcfreads.nil?
@contreads = @nofreads - @nofcfreads
@contreads_percent = @contreads * 100 / @nofreads
end
detect(log, /^#bases = (\d+)/, "@tlen")
@operation[1] = "" #next detect: no auto-conversion into Float for $1
detect(log, /^read input file (\S+)/, "@readset")
clean_readset_name
detect(log, /^minReadLen = (\d+)/, "@minreadlen")
detect(log, /^maxReadLen = (\d+)/, "@maxreadlen")
end
end
module EdenaCommon
def contreads
return nil if @notamb.nil? or @nofnodes.nil?
return @notamb.to_i - @nofnodes.to_i
end
def contreads_percent
return nil if contreads.nil?
return contreads.to_f / @nofreads.to_f * 100
end
end
class EdenaOverlap
include Common
include EdenaCommon
def initialize(log)
@i = ::OutputParser::Info.new(log)
@t = ::OutputParser::Time.new(log)
@msp = ::OutputParser::MeasureSpacePeak.new(log)
parse(log)
end
attr_reader :minlen, :nofreads, :introvl, :readlen, :readset
def tlen
if (readlen && nofreads)
return readlen * nofreads
end
end
delegate :overlap_hostname, :i, :hostname
delegate :overlap_real_time, :t, :real_time
delegate :overlap_user_time, :t, :user_time
delegate :overlap_sys_time, :t, :sys_time
delegate :overlap_cpu_time, :t, :cpu_time
delegate :overlap_real_cpu_time_diff, :t, :real_cpu_time_diff
delegate :overlap_hwm_space, :msp, :vm_hwm
delegate :overlap_vm_peak, :msp, :vm_peak
def overlap_pipeline
"Edena"
end
private
def parse(log)
log.each_line do |line|
if @nextisreadset
detect(line, /(\S+)/, "@readset")
@nextisreadset = false
end
detect(line, /Opening file (\S+)/, "@readset")
detect(line, /Opening file/, "@nextisreadset") if @readset.nil?
detect(line, /reads length:\s+(\d+)/i, "@readlen")
detect(line, /number of nodes:\s+(\d+)/, "@nofnodes")
detect(line, /number of edges:\s+(\d+)/, "@introvl")
detect(line, /minimum overlap size:\s+(\d+)/, "@minlen")
detect(line, /fasta entries:\s+(\d+)/, "@nofreads")
detect(line, /sequences OK:\s+(\d+)/, "@notamb")
detect(line, /Number of reads:\s+(\d+)/, "@nofreads")
@operation[1] = "" #next detect: no auto-conversion into Float for $1
clean_readset_name
end
end
end
class EdenaAssembly
include Common
include EdenaCommon
def initialize(log)
@i = ::OutputParser::Info.new(log)
@t = ::OutputParser::Time.new(log)
@msp = ::OutputParser::MeasureSpacePeak.new(log)
@ssc = ::OutputParser::SeqstatContigs.new(log)
parse(log)
end
attr_reader :minlen, :lngst, :n50, :nofreads, :introvl, :nofcontigs,
:tcontigslen
delegate :assembly_hostname, :i, :hostname
delegate :assembly_real_time, :t, :real_time
delegate :assembly_user_time, :t, :user_time
delegate :assembly_sys_time, :t, :sys_time
delegate :assembly_cpu_time, :t, :cpu_time
delegate :assembly_real_cpu_time_diff, :t, :real_cpu_time_diff
delegate :assembly_hwm_space, :msp, :vm_hwm
delegate :assembly_vm_peak, :msp, :vm_peak
delegate :ssc_nofcontigs, :ssc, :nofcontigs
delegate :n80, :ssc, :n80
delegate :ssc_tcontigslen, :ssc, :tcontigslen
def assembly_pipeline
"Edena"
end
private
def parse(log)
log.each_line do |line|
detect(line, /^\s*N50:\s+(\d+)/, "@n50")
detect(line, /max:\s+(\d+)/, "@lngst")
detect(line, /minimum overlap size:\s+(\d+)/, "@minlen")
detect(line, /number of nodes:\s+(\d+)/, "@nofnodes") if @nofnodes.nil?
detect(line, /number of edges:\s+(\d+)/, "@introvl")
detect(line, /number of reads:\s+(\d+)/, "@nofreads")
detect(line, /Number of contigs:\s+(\d+)/, "@nofcontigs")
@nofcontigs ||= ssc_nofcontigs
detect(line, /Total number of bases:\s+(\d+)/, "@tcontigslen")
@tcontigslen ||= ssc_tcontigslen
end
end
end
class Prefilter
include Common
def initialize(log)
@i = ::OutputParser::Info.new(log)
@gt = ::OutputParser::Genometools.new(log)
@t = ::OutputParser::Time.new(log)
@msp = ::OutputParser::MeasureSpacePeak.new(log)
parse(log)
end
attr_reader :prefilter_indexname, :nofreads, :tlen, :contreads,
:contreads_percent, :readset, :readlen
delegate :prefilter_hostname, :i, :hostname
delegate :prefilter_compiler, :i, :compiler
delegate :prefilter_lastcommit, :i, :lastcommit
delegate :prefilter_gt_real_time, :gt, :real_time_overall
delegate :prefilter_gt_user_time, :gt, :user_time_overall
delegate :prefilter_gt_sys_time, :gt, :sys_time_overall
delegate :prefilter_gt_cpu_time, :gt, :cpu_time_overall
delegate :prefilter_real_cpu_time_diff, :gt, :real_cpu_time_diff_overall
delegate :prefilter_gt_space, :gt, :space_peak_overall
delegate :prefilter_alloc, :gt, :alloc_peak
delegate :prefilter_mmap, :gt, :mmap_peak
delegate :prefilter_real_time, :t, :real_time
delegate :prefilter_user_time, :t, :user_time
delegate :prefilter_sys_time, :t, :sys_time
delegate :prefilter_cpu_time, :t, :cpu_time
delegate :prefilter_real_cpu_time_diff, :t, :real_cpu_time_diff
delegate :prefilter_hwm_space, :msp, :vm_hwm
delegate :prefilter_vm_peak, :msp, :vm_peak
def prefilter_pipeline
"Rdj"
end
private
def parse(log)
@operation = []
@operation[1] = "" #next detect: no auto-conversion into Float for $1
detect(log, /readset name = (\S+)/, "@readset")
clean_readset_name
@operation[1] = "" #next detect: no auto-conversion into Float for $1
detect(log, /indexname = (\S+)/, "@prefilter_indexname")
detect(log, /total input length = (\d+)/, "@tlen")
detect(log, /total length of complete readset = (\d+)/, "@tlen")
detect(log, /read length = (\d+)/, "@readlen")
detect(log, /input sequences = (\d+)/, "@nofreads")
detect(log, /number of reads in complete readset = (\d+)/, "@nofreads")
detect(log, /contained sequences = (\d+)/, "@contreads")
detect(log, /contained reads = (\d+)/, "@contreads")
if @contreads && @nofreads
@contreads_percent = @contreads * 100 / @nofreads
end
end
end
class Sequniq
include Common
def initialize(log)
@i = ::OutputParser::Info.new(log)
@gt = ::OutputParser::Genometools.new(log)
@t = ::OutputParser::Time.new(log)
@msp = ::OutputParser::MeasureSpacePeak.new(log)
end
delegate :prefilter_hostname, :i, :hostname
delegate :prefilter_compiler, :i, :compiler
delegate :prefilter_lastcommit, :i, :lastcommit
delegate :prefilter_gt_real_time, :gt, :real_time_overall
delegate :prefilter_gt_user_time, :gt, :user_time_overall
delegate :prefilter_gt_sys_time, :gt, :sys_time_overall
delegate :prefilter_gt_cpu_time, :gt, :cpu_time_overall
delegate :prefilter_real_cpu_time_diff, :gt, :real_cpu_time_diff_overall
delegate :prefilter_gt_space, :gt, :space_peak_overall
delegate :prefilter_alloc, :gt, :alloc_peak
delegate :prefilter_mmap, :gt, :mmap_peak
delegate :prefilter_real_time, :t, :real_time
delegate :prefilter_user_time, :t, :user_time
delegate :prefilter_sys_time, :t, :sys_time
delegate :prefilter_cpu_time, :t, :cpu_time
delegate :prefilter_real_cpu_time_diff, :t, :real_cpu_time_diff
delegate :prefilter_hwm_space, :msp, :vm_hwm
delegate :prefilter_vm_peak, :msp, :vm_peak
def prefilter_pipeline
"Rdj"
end
end
class Suffixerator
include Common
def initialize(log)
@i = ::OutputParser::Info.new(log)
@gt = ::OutputParser::Genometools.new(log)
@t = ::OutputParser::Time.new(log)
@msp = ::OutputParser::MeasureSpacePeak.new(log)
parse(log)
end
attr_reader :parts, :prefixlength, :maxinsertionsort, :maxbltriesort,
:maxcountingsort, :relevant, :suftabuint, :memlimit,
:sat, :sfxtotallength, :index_indexname, :index_bits
delegate :index_hostname, :i, :hostname
delegate :index_compiler, :i, :compiler
delegate :index_lastcommit, :i, :lastcommit
delegate :index_gt_real_time, :gt, :real_time_overall
delegate :index_gt_user_time, :gt, :user_time_overall
delegate :index_gt_sys_time, :gt, :sys_time_overall
delegate :index_gt_cpu_time, :gt, :cpu_time_overall
delegate :index_real_cpu_time_diff, :gt, :real_cpu_time_diff_overall
delegate :index_gt_space, :gt, :space_peak_overall
delegate :index_alloc, :gt, :alloc_peak
delegate :index_mmap, :gt, :mmap_peak
delegate :index_real_time, :t, :real_time
delegate :index_user_time, :t, :user_time
delegate :index_sys_time, :t, :sys_time
delegate :index_cpu_time, :t, :cpu_time
delegate :index_real_cpu_time_diff, :t, :real_cpu_time_diff
delegate :index_hwm_space, :msp, :vm_hwm
delegate :index_vm_peak, :msp, :vm_peak
def index_hwm_gtsp_delta
return nil if !index_hwm_space or !index_gt_space
return (index_hwm_space - index_gt_space) * 100 / index_gt_space
end
def index_pipeline
"Rdj"
end
private
def parse(log)
detect(log, /-parts (\d+)/, "@parts")
detect(log, /# parts=(\d+)/, "@parts")
detect(log, /# derived parts=(\d+)/, "@parts")
detect(log, /# prefixlength=(\d+)/, "@prefixlength")
if @prefixlength.nil?
detect(log, /# automatically determined prefixlength=(\d+)/,
"@prefixlength")
end
detect(log, /# maxinsertionsort=(\d+)/, "@maxinsertionsort")
detect(log, /# maxbltriesort=(\d+)/, "@maxbltriesort")
detect(log, /# maxcountingsort=(\d+)/, "@maxcountingsort")
detect(log, /# relevant suffixes=(\d+.\d+)\%/, "@relevant")
if @relevant.nil?
@relevant = "spmopt off"
end
@suftabuint = (log =~ /suftab uses 32bit values/) ? "on" : "off"
@operation[1] = "" #next detect: no auto-conversion into Float for $1
detect(log, /# maximumspace=(.*)\s*\n/, "@memlimit")
detect(log, /# totallength=(\d+)/, "@sfxtotallength")
@operation[1] = "" #next detect: no auto-conversion into Float for $1
detect(log, /# indexname=\"(.*)\"\s*\n/, "@index_indexname")
@operation[1] = "" #next detect: no auto-conversion into Float for $1
detect(log, /# sat=(.*)\s*\n/, "@sat")
if @sat.nil?
@operation[1] = "" #next detect: no auto-conversion into Float for $1
detect(log, /# init character encoding \((\S+)/, "@sat")
end
detect(log, /# sizeof \(GtUword\)=(\d+)/, "@index_bits")
end
end
class RdjOverlap
include Common
def initialize(log)
@i = ::OutputParser::Info.new(log)
@gt = ::OutputParser::Genometools.new(log)
@t = ::OutputParser::Time.new(log)
@msp = ::OutputParser::MeasureSpacePeak.new(log)
@index = ::OutputParser::Suffixerator.new(log)
parse(log)
end
attr_reader :minlen, :trovl, :introvl, :contreads, :contreads_percent,
:parts, :nofreads, :overlap_indexname
delegate :overlap_hostname, :i, :hostname
delegate :overlap_compiler, :i, :compiler
delegate :overlap_lastcommit, :i, :lastcommit
delegate :overlap_gt_real_time, :gt, :real_time_overall
delegate :overlap_gt_user_time, :gt, :user_time_overall
delegate :overlap_gt_sys_time, :gt, :sys_time_overall
delegate :overlap_gt_cpu_time, :gt, :cpu_time_overall
delegate :overlap_gt_real_cpu_time_diff, :gt, :real_cpu_time_diff_overall
delegate :overlap_gt_space, :gt, :space_peak_overall
delegate :overlap_alloc, :gt, :alloc_peak
delegate :overlap_mmap, :gt, :mmap_peak
delegate :overlap_real_time, :t, :real_time
delegate :overlap_user_time, :t, :user_time
delegate :overlap_sys_time, :t, :sys_time
delegate :overlap_cpu_time, :t, :cpu_time
delegate :overlap_real_cpu_time_diff, :t, :real_cpu_time_diff
delegate :overlap_hwm_space, :msp, :vm_hwm
delegate :overlap_vm_peak, :msp, :vm_peak
def overlap_hwm_gtsp_delta
return nil if !overlap_hwm_space or !overlap_gt_space
return (overlap_hwm_space - overlap_gt_space) * 100 / overlap_gt_space
end
def overlap_pipeline
"Rdj"
end
private
def parse(log)
detect(log, /-parts (\d+)/, "@parts")
detect(log, /derived parts=(\d+)/, "@parts")
detect(log, /minimal spm length.*?(\d+)/, "@minlen")
detect(log, /minimal match length.*?(\d+)/, "@minlen")
if @minlen.nil?
detect(log, /minimal overlap.*?(\d+)/, "@minlen")
end
detect(log, /omitted transitive suffix-prefix matches: (\d+)/, "@trovl")
detect(log, /number of transitive suffix-prefix matches = (\d+)/,
"@trovl")
detect(log, /-- suffix-prefix matches: (\d+)/, "@introvl")
detect(log, /number of irreducible suffix-prefix matches = (\d+)/,
"@introvl")
detect(log, /contained: (\d+) \((\d+.\d+) %\)/, "@contreads",
"@contreads_percent")
detect(log, /# reads: (\d+)/, "@nofreads")
@operation[1] = "" #next detect: no auto-conversion into Float for $1
detect(log, /indexname = \"(\S+)\"/, "@overlap_indexname")
end
end
class RdjAssembly
include Common
def initialize(log)
@i = ::OutputParser::Info.new(log)
@ssc = ::OutputParser::SeqstatContigs.new(log)
@gt = ::OutputParser::Genometools.new(log)
@t = ::OutputParser::Time.new(log)
@msp = ::OutputParser::MeasureSpacePeak.new(log)
parse(log)
end
attr_reader :minlen, :nofreads, :assembly_indexname
delegate :nofcontigs, :ssc, :nofcontigs
delegate :lngst, :ssc, :lngst
delegate :n50, :ssc, :n50
delegate :n80, :ssc, :n80
delegate :tcontigslen, :ssc, :tcontigslen
delegate :assembly_gt_real_time, :gt, :real_time_overall
delegate :assembly_gt_user_time, :gt, :user_time_overall
delegate :assembly_gt_sys_time, :gt, :sys_time_overall
delegate :assembly_gt_cpu_time, :gt, :cpu_time_overall
delegate :assembly_gt_real_cpu_time_diff, :gt, :real_cpu_time_diff_overall
delegate :assembly_real_time, :t, :real_time
delegate :assembly_user_time, :t, :user_time
delegate :assembly_sys_time, :t, :sys_time
delegate :assembly_cpu_time, :t, :cpu_time
delegate :assembly_real_cpu_time_diff, :t, :real_cpu_time_diff
delegate :assembly_gt_space, :gt, :space_peak_overall
delegate :assembly_alloc, :gt, :alloc_peak
delegate :assembly_mmap, :gt, :mmap_peak
delegate :assembly_hwm_space, :msp, :vm_hwm
delegate :assembly_vm_peak, :msp, :vm_peak
delegate :assembly_hostname, :i, :hostname
delegate :assembly_compiler, :i, :compiler
delegate :assembly_lastcommit, :i, :lastcommit
def assembly_hwm_gtsp_delta
return nil if !assembly_hwm_space or !assembly_gt_space
return (assembly_hwm_space - assembly_gt_space) * 100 / assembly_gt_space
end
def assembly_pipeline
"Rdj"
end
private
def parse(log)
detect(log, /minimal overlap.*?(\d+)/, "@minlen")
detect(log, /# reads: (\d+)/, "@nofreads")
@operation[1] = "" #next detect: no auto-conversion into Float for $1
detect(log, /indexname = \"(\S+)\"/, "@assembly_indexname")
end
end
class RdjBoth
include Common
def initialize(log)
@i = ::OutputParser::Info.new(log)
@gt = ::OutputParser::Genometools.new(log)
@t = ::OutputParser::Time.new(log)
@msp = ::OutputParser::MeasureSpacePeak.new(log)
parse(log)
end
attr_reader :minlen, :trovl, :introvl, :contreads,
:contreads_percent, :nofreads,
:overlap_gt_space,
:overlap_gt_real_time,
:overlap_gt_user_time,
:overlap_gt_sys_time,
:overlap_gt_cpu_time,
:overlap_gt_real_cpu_time_diff,
:overlap_and_assembly_indexname
attr_reader :n50, :lngst, :nofcontigs, :tcontigslen,
:assembly_gt_space,
:assembly_gt_real_time,
:assembly_gt_user_time,
:assembly_gt_sys_time,
:assembly_gt_cpu_time,
:assembly_gt_real_cpu_time_diff
delegate :overlap_and_assembly_hostname, :i, :hostname
delegate :overlap_and_assembly_compiler, :i, :compiler
delegate :overlap_and_assembly_lastcommit, :i, :lastcommit
delegate :overlap_and_assembly_gt_real_time, :gt, :real_time_overall
delegate :overlap_and_assembly_gt_user_time, :gt, :user_time_overall
delegate :overlap_and_assembly_gt_sys_time, :gt, :sys_time_overall
delegate :overlap_and_assembly_gt_cpu_time, :gt, :cpu_time_overall
delegate :overlap_and_assembly_gt_real_cpu_time_diff, :gt,
:real_cpu_time_diff_overall
delegate :overlap_and_assembly_gt_space, :gt, :space_peak_overall
delegate :overlap_and_assembly_alloc, :gt, :alloc_peak
delegate :overlap_and_assembly_mmap, :gt, :mmap_peak
delegate :overlap_and_assembly_real_time, :t, :real_time
delegate :overlap_and_assembly_user_time, :t, :user_time
delegate :overlap_and_assembly_sys_time, :t, :sys_time
delegate :overlap_and_assembly_cpu_time, :t, :cpu_time
delegate :overlap_and_assembly_real_cpu_time_diff, :t,
:real_cpu_time_diff
delegate :overlap_and_assembly_hwm_space, :msp, :vm_hwm
delegate :overlap_and_assembly_vm_peak, :msp, :vm_peak
def overlap_and_assembly_hwm_gtsp_delta
if !overlap_and_assembly_hwm_space or !overlap_and_assembly_gt_space
return nil
end
return (overlap_and_assembly_hwm_space - overlap_and_assembly_gt_space) *
100 / overlap_and_assembly_gt_space
end
def overlap_and_assembly_pipeline
"Rdj"
end
private
StageDesc =
{
# Overlap phase
:overlap_phase => "Overlap Phase",
# containments
:CNT1 => "remove contained reads", # old
:CNT2 => "identify contained reads",
:CNT3 => "save contained reads list",
:CNT4 => "load contained reads list",
# spm
:SPM1 => "count overlaps for each reads", # old
:SPM2 => "determine suffix-prefix matches",
# Assembly Phase
:assembly_phase => "Assembly Phase",
# create graph
:SG1 => "load overlap counts",
:SG2 => "create overlap graph", # old
:SG3 => "create string graph",
:SG4 => "save string graph",
:SG5 => "export string graph in GraphViz dot format",
:SG6 => "output graph information as spm list",
:SG7 => "output string graph adjacence list",
:SG8 => "load string graph",
# graph manipulation
:GM1 => "sort edges by length",
:GM2 => "reduce self-match edges",
:GM3 => "reduce withrc-match edges",
:GM4 => "reduce transitive edges",
:GM5 => "compact edges list",
:GM6 => "reduce non-maximal edges",
:GM7 => "remove dead-end paths",
:GM8 => "remove p-bubbles",
# output contigs
:OC1 => "output contigs", # old
:OC2 => "traverse graph and output contigs",
:OC3 => "convert symbolic contigs into fasta",
:OC4 => "output contig sequences from paths",
}
PhaseStages =
{:overlap => [:overlap_phase, :CNT1, :CNT2, :CNT3, :CNT4, :SPM1, :SPM2],
:assembly => [:assembly_phase, :SG1, :SG2, :SG3, :SG4, :SG5, :SG6, :SG7,
:SG8, :GM1, :GM2, :GM3, :GM4, :GM5, :GM6, :GM7, :GM8, :OC1,
:OC2, :OC3]}
def phase_time(variety, phase)
time = 0.0
PhaseStages[phase].each do |stage|
t = @gt.time[variety][StageDesc[stage]]
(time += t) if t
end
return time if time > 0.0 || variety == :sys
end
def phase_space(phase)
space = []
PhaseStages[phase].each do |stage|
s = @gt.space_peak[StageDesc[stage]]
(space.push(s)) if s
end
space.compact!
return space.max if space.size > 0
end
def parse(log)
detect(log, /# N50:\s+(\d+)/, "@n50")
detect(log, /# longest contig:\s+(\d+)/, "@lngst")
detect(log, /minimal spm length.*?(\d+)/, "@minlen")
if @minlen.nil?
detect(log, /minimal overlap.*?(\d+)/, "@minlen")
end
detect(log, /# number of contigs:\s(\d+)\n# total length:\s+(\d+)/m,
"@nofcontigs", "@tcontigslen")
d = detect(log, /nof tr edges: (\d+)/, "@trovl")
@trovl = @trovl/2 if d
detect(log, /omitted transitive suffix-prefix matches: (\d+)/,
"@trovl")
detect(log, /valid overlaps: (\d+)/, "@introvl")
detect(log, /-- suffix-prefix matches: (\d+)/, "@introvl")
detect(log, /contained: (\d+) \((\d+.\d+) %\)/, "@contreads",
"@contreads_percent")
detect(log, /# reads: (\d+)/, "@nofreads")
@overlap_gt_real_time = phase_time(:real, :overlap)
@overlap_gt_user_time = phase_time(:user, :overlap)
@overlap_gt_sys_time = phase_time(:sys, :overlap)
if @overlap_gt_user_time and @overlap_gt_sys_time
@overlap_gt_cpu_time = @overlap_gt_user_time + @overlap_gt_sys_time
end
if @overlap_gt_cpu_time and @overlap_gt_real_time
@overlap_gt_real_cpu_time_diff = @overlap_gt_real_time -
@overlap_gt_cpu_time
end
@overlap_gt_space = phase_space(:overlap)
@assembly_gt_real_time = phase_time(:real, :assembly)
@assembly_gt_user_time = phase_time(:user, :assembly)
@assembly_gt_sys_time = phase_time(:sys, :assembly)
if @assembly_gt_user_time and @assembly_gt_sys_time
@assembly_gt_cpu_time = @assembly_gt_user_time + @assembly_gt_sys_time
end
if @assembly_gt_cpu_time and @assembly_gt_real_time
@assembly_gt_real_cpu_time_diff =
@assembly_gt_real_time - @assembly_gt_cpu_time
end
@assembly_gt_space = phase_space(:assembly)
@operation[1] = "" #next detect: no auto-conversion into Float for $1
detect(log, /indexname = \"(\S+)\"/, "@overlap_and_assembly_indexname")
end
end
class ResultsFile
include Common
def initialize(log)
parse(log)
correct_units
end
attr_reader :minlen, :nofreads, :trovl, :introvl, :n50, :lngst, :parts,
:contreads, :contreads_percent, :index_time, :index_space,
:overlap_time, :overlap_space, :assembly_time
private
def parse(log)
log.each_line do |line|
detect(line, /Min SPM length\s+(\d+)/, "@minlen")
detect(line, /Number of reads \(M\)\s+(\d+\.\d+)/, "@nofreads")
detect(line, /Contained reads \(k\)\s+(\d+)/ , "@contreads")
detect(line, /Contained %\s+(\d+\.\d+)/ , "@contreads_percent")
detect(line, /Transitive SPM \(M\)\s+(\d+\.\d+)/ , "@trovl")
detect(line, /Irreducible SPM \(M\)\s+(\d+\.\d+)/, "@introvl")
detect(line, /N50 contig \(kbp\)\s+(\d+\.\d+)/ , "@n50")
detect(line, /Lngst contig \(kbp\)\s+(\d+\.\d+)/ , "@lngst")
detect(line, /Index time \(s\)\s+(\d+)/ , "@index_time")
detect(line, /Index space \(Gb\)\s+(\d+\.\d+)/ , "@index_space")
detect(line, /Overlap time \(s\)\s+(\d+)/ , "@overlap_time")
detect(line, /Assembly time \(s\)\s+(\d+)/ , "@assembly_time")
detect(line, /Overlap space \(Gb\)\s+(\d+\.\d+)/ , "@overlap_space")
detect(line, /Assembly space \(Gb\)\s+(\d+\.\d+)/, "@assembly_space")
end
end
def correct_units
@nofreads = @nofreads * 1_000_000 if @nofreads
@trovl = @trovl * 1_000_000 if @trovl
@introvl = @introvl * 1_000_000 if @introvl
@contreads = @contreads * 1_000 if @contreads
@n50 = @n50 * 1_000 if @n50
@lngst = @lngst * 1_000 if @lngst
@index_space = @index_space.mem_convert(:Gb, :Mb) if @index_space
@assembly_space = @assembly_space.mem_convert(:Gb, :Mb) if @assembly_space
end
end
end
## Table: data formatter for output ##
class Table
LabelsColSpacing = 3
DataColSpacing = 5
def initialize
@format = :txt
@tex_page = :completedocument
end
def data=(bidimensional_array)
@table = bidimensional_array
@nofcolumns = @table.size > 0 ? @table.first.size : 0
@labels_col_width = determine_labels_col_width
@data_col_witdh = determine_data_col_width
end
attr_writer :format, :tex_page, :nosideways
def show
retval = ""
if @format == :dat
return to_dat
end
if @format == :csv
return to_csv
end
if @format == :tex
retval << generate_tex_table_header(@tex_page, @nosideways)
end
retval << format_table(@format)
if @format == :tex
retval << generate_tex_table_footer(@tex_page, @nosideways)
retval.escape_for_latex!
end
return retval
end
private
def determine_labels_col_width
@labels_col_width = 0
@table.each do |row|
@labels_col_width = row.first.size if row.first.size > @labels_col_width
end
@labels_col_width += LabelsColSpacing
end
def determine_data_col_width
@data_col_width = 0
@table.each do |row|
row.each_with_index do |cell, i|
if i > 0
@data_col_width = cell.size if cell.size > @data_col_width
end
end
end
@data_col_width += DataColSpacing
end
def to_csv
rows = []
@table.each do |values|
values.each_with_index do |value, i|
rows[i] ||= []
rows[i] << value.to_s
end
end
rows[0] = rows[0].map{|x| x.gsub(" ", "_")}
retval = ""
rows.each do |row|
retval << row.join(",")
retval << "\n"
end
return retval
end
def to_dat
rows = []
@table.each do |values|
values.each_with_index do |value, i|
rows[i] ||= []
rows[i] << value.to_s
end
end
rows[0] = rows[0].map{|x| x.gsub(" ", "_")}
rows[0].unshift("#")
retval = ""
rows.each do |row|
retval << row.join(" ")
retval << "\n"
end
return retval
end
def format_table(output_format)
retval = ""
@table.each do |row|
labels_col = true
row.each do |col|
(retval << sprintf(" & ")) if output_format == :tex && !labels_col
width = labels_col ? @labels_col_width : @data_col_width
retval << sprintf("%-#{width}s", col)
labels_col = false
end
(retval << sprintf(" \\\\")) if output_format == :tex
retval << sprintf("\n")
end
return retval
end
def generate_tex_table_header(tex_page, nosideways)
retval = ""
if (tex_page == :completedocument || tex_page == :first)
retval << <<-endheader
\\documentclass[a4paper, 10pt]{article}
\\usepackage{booktabs}
\\usepackage{rotating}
\\pagestyle{empty}
\\begin{document}
endheader
elsif (tex_page == :middle || tex_page == :last)
retval << "\\newpage\n"
end
if tex_page != :none
retval << "\\begin{#{nosideways ? '' : 'sideways'}table}\n"
end
retval << "\\begin{tabular}{#{'l'*@nofcolumns}}\n"
return retval
end
def generate_tex_table_footer(tex_page, nosideways)
retval = ""
retval << "\\end{tabular}\n"
if tex_page != :none
retval << "\\end{#{nosideways ? '' : 'sideways'}table}\n"
end
if (tex_page == :completedocument || tex_page == :last)
retval << "\\end{document}\n"
end
return retval
end
end
## DataCollection: data structure to contain the extracted data ##
class DataCollection
OutOrder = [:title, :pipeline, :readset, :nofreads, :readlen, :tlen,
:contreads, :contreads_percent, :minlen, :trovl, :introvl, :parts,
:sga_index_d, :prefilter_time, :prefilter_space, :index_time,
:index_space, :overlap_time, :overlap_space, :index_and_overlap_time,
:index_and_overlap_space, :assembly_time, :assembly_space, :overall_time,
:overall_space, :nofcontigs, :tcontigslen, :n50, :lngst]
AutoCategory = {
/time/ => :time,
/space/ => :space,
/mmap/ => :space,
/alloc/ => :space,
/vm_peak/ => :space,
/hostname/ => :string,
/compiler/ => :string,
/indexname/ => :string,
/lastcommit/ => :string,
/percent/ => :percent,
/hwm_gtsp_delta/ => :percent,
/max\w+sort/ => :integer,
/bits/ => :integer,
}
Category = {
:title => :string,
:minlen => :integer,
:tlen => :millions,
:readlen => :integer,
:nofreads => :millions,
:contreads => :thousands,
:trovl => :millions,
:introvl => :millions,
:nofcontigs => :integer,
:tcontigslen => :longlength,
:n50 => :length,
:lngst => :length,
:parts => :integer,
:sga_index_d => :thousands,
:prefixlength => :integer,
:sfxtotallength => :millions,
:sat => :string,
:readset => :string,
}
Label = {
:title => "",
:minlen => "Min SPM length",
:nofreads => "Number of reads",
:tlen => "Total length",
:readlen => "Read length",
:contreads => "Contained reads",
:contreads_percent => "Contained %",
:trovl => "Transitive SPM",
:introvl => "Irreducible SPM",
:nofcontigs => "Contigs",
:tcontigslen => "Tot contigs len",
:n50 => "Assembly N50",
:lngst => "Longest contig",
:parts => "Index parts",
:sga_index_d => "Sga index -d",
:_time => "__phase_label__ time",
:_t_percent => "__phase_label__ time (%)",
:_gt_real_time => " - gt:real",
:_gt_cpu_time => " - gt:CPU",
:_gt_user_time => " - gt:user",
:_gt_sys_time => " - gt:sys",
:_real_time => " - real",
:_cpu_time => " - CPU",
:_user_time => " - user",
:_sys_time => " - sys",
:_real_cpu_time_diff => " - real-CPU",
:_gt_real_cpu_time_diff => " - gt:real-CPU",
:_space => "__phase_label__ space",
:_s_percent => "__phase_label__ space (% peak)",
:_gt_space => " - gt",
:_hwm_space => " - vm_hwm",
:_vm_peak => " - vm_peak",
:_alloc => " - alloc",
:_mmap => " - mmap",
:_hwm_gtsp_delta => " - hwm-gt (%)",
:_indexname => "Indexname [__phase_short__]",
:_hostname => "Hostname [__phase_short__]",
:_compiler => "Compiler [__phase_short__]",
:_lastcommit => "Git commit [__phase_short__]",
:_bits => "Ulong size (bits) [__phase_short__]",
:_pipeline => "Pipeline [__phase_short__]",
:indexname => "Indexname",
:hostname => "Hostname",
:compiler => "Compiler",
:lastcommit => "Git commit",
:pipeline => "Pipeline",
:readset => "Readset",
:bits => "Ulong size (bits)",
:prefixlength => "Sfx prefixlength",
:maxinsertionsort => "Sfx maxinssort",
:maxbltriesort => "Sfx maxbltsort",
:maxcountingsort => "Sfx maxcousort",
:relevant => "Sfx relevant suf (%)",
:suftabuint => "Sfx suftabuint",
:memlimit => "Sfx memlimit",
:sfxtotallength => "Sfx totallength",
:sat => "Sfx seq.ac.type",
}
UnitLabel = {
:b => " (bytes)",
:kb => " (kb)" ,
:Mb => " (Mb)" ,
:Gb => " (Gb)",
:Tb => " (Tb)",
:n => "",
:K => " (K)",
:M => " (M)",
:bp => " (bp)",
:kbp => " (kbp)",
:Mbp => " (Mbp)",
:Gbp => " (Gbp)",
:s => " (s)",
:hm => "",
}
RatioCategories = [:time, :space, :millions]
NoValue = "-"
def initialize
@unit = {:millions => :M, :thousands => :K, :time => :s, :space => :Mb,
:length => :kbp, :longlength => :Mbp}
@extended = {}
@hide = []
@show = []
@manual_cells = {}
@space_variety = :hwm_or_gt
@time_variety = nil
@series = []
@outorder = OutOrder.clone
@manual_rows = []
@customlabels = {}
@table = []
@keys = []
@index_and_overlap = false
@show_keys = false
@only_rows = []
@ratios = []
@ratiorows = []
@main_phases = [:prefilter, :index, :overlap, :assembly, :overall]
@phases = {
:prefilter => {:order => 1, :label => "Prefilter", :short => "P"},
:index => {:order => 2, :label => "Index", :short => "I"},
:overlap => {:order => 3, :label => "Overlap", :short => "O"},
:assembly => {:order => 4, :label => "Assembly", :short => "A"},
:overall => {:order => 9, :label => "Overall", :short => "all"},
}
@comb_phases = @main_phases.choose(2) + @main_phases.choose(3) +
@main_phases.choose(4)
@comb_phases.each do |phlist|
key = phlist.map{|x|x.to_s}.join("_and_")
order = @main_phases.index(phlist[0]) + 1
label = phlist.map{|x|@phases[x][:label]}.join("/")
short = phlist.map{|x|@phases[x][:short]}.join
@phases[key] = {:order => order, :label => label, :short => short}
end
@phasewisekeys = [:indexname, :pipeline, :hostname, :compiler, :lastcommit,
:bits]
end
attr_accessor :unit, :extended, :hide, :show, :manual_cells, :space_variety,
:time_variety, :show_keys, :index_and_overlap, :only_rows, :manual_rows,
:ratios, :ratiorows
def create_series(name, title)
title = name if @show_keys
@series << [name, {:title => title}]
end
def add_value(name, key, value)
if @series.assoc(name)[1][key].nil?
@series.assoc(name)[1][key] = value
end
end
def add_ratios
pairs = []
@ratiorows.map! do |str|
str.to_sym
end
(0).step(@ratios.size-1,4) {|i| pairs << @ratios.slice(i,4)}
pairs.each do |a, b, insert_after, ti|
if !a.nil? and !b.nil?
ratio_col = [:"ratio_#{a}_#{b}", {:ratio_column => true}]
a_col = @series.assoc(a)
b_col = @series.assoc(b)
next if a_col.nil? || b_col.nil?
if @ratiorows.empty?
keys = a_col[1].keys & b_col[1].keys
keys = keys.select{|k| RatioCategories.include?(category(k))}
else
keys = a_col[1].keys & b_col[1].keys & @ratiorows
end
keys.each do |key|
a_value = a_col[1][key]
next if !a_value.kind_of? Numeric
b_value = b_col[1][key]
next if !b_value.kind_of? Numeric || b_value == 0
ratio_col[1][key] = a_value.to_f / b_value.to_f
end
if @show_keys
ratio_col[1][:title] = ratio_col[0].to_s
elsif ti == '-'
autoti = "#{a_col[1][:title]}/#{b_col[1][:title]}"
ratio_col[1][:title] = autoti if autoti != "/"
else
ratio_col[1][:title] = ti
end
insertion_point = @series.index(@series.assoc(insert_after)) + 1
@series.insert(insertion_point, ratio_col)
end
end
end
def prepare!(rawmode)
select_time_values(@time_variety)
select_space_values(@space_variety)
add_index_and_overlap_time
add_index_and_overlap_space
add_overall_time
add_overall_space
add_ratios if !@ratios.empty?
if rawmode
puts to_yaml
exit
end
if !@only_rows.nil? && !@only_rows.empty?
@outorder = @only_rows.map{|key|key.to_sym}
end
apply_manual_rows
apply_manual_cells
apply_extended
@show.each {|key| append_row(key.to_sym) }
apply_hide_option
@outorder.uniq!
end
def tabulize
prepare_first_column
apply_space_time_extended
maxwidth = 0
@series.each do |n, values|
@keys.each_with_index do |key, i|
if values.has_key?(key)
v = values[key]
if values[:ratio_column]
if key == :title || category(key) == :string
str = format_value(v, :string)
else
str = format_value(v, :ratio)
end
elsif values[:"#{key}_string"]
str = format_value(v, :string)
else
str = format_value(v, category(key))
end
else
str = NoValue
end
str = str.to_s
@table[i] << str
maxwidth = str.size if str.size > maxwidth
end
end
@colsize = maxwidth + 6
return @table
end
private
def category(key)
return Category[key] if Category.has_key?(key)
AutoCategory.each do |regex, categ|
return categ if key.to_s =~ regex
end
return :string
end
def label(key)
return @customlabels[key] if @customlabels.has_key?(key)
return Label[key] if Label.has_key?(key)
@phases.each_key do |phase|
if key.to_s =~ /#{phase}(_.*)/
subkey = $1.to_sym
if Label.has_key?(subkey)
template = Label[subkey].dup
template.gsub!("__phase_label__", @phases[phase][:label])
template.gsub!("__phase_short__", @phases[phase][:short])
return template
end
end
end
return ""
end
def select_time_values(variety_to_use)
if variety_to_use.to_s =~ /(.*)_or_gt_(.*)/
select_time_values(:"gt_#{$1}")
select_time_values(:"#{$1}")
elsif variety_to_use.to_s =~ /gt_(.*)_or_(.*)/
select_time_values(:"#{$1}")
select_time_values(:"gt_#{$1}")
else
@series.each do |n, s|
@main_phases.each do |ph|
if s[:"#{ph}_#{variety_to_use}_time"]
s[:"#{ph}_time"] = s[:"#{ph}_#{variety_to_use}_time"]
end
end
end
end
end
def select_space_values(variety_to_use)
if variety_to_use == :hwm_or_gt
select_space_values(:gt)
select_space_values(:hwm)
elsif variety_to_use == :gt_or_hwm
select_space_values(:hwm)
select_space_values(:gt)
else
@series.each do |n, s|
@main_phases.each do |ph|
if s[:"#{ph}_#{variety_to_use}_space"]
s[:"#{ph}_space"] ||= s[:"#{ph}_#{variety_to_use}_space"]
end
end
end
end
end
def has?(key)
@series.each do |n, values|
if !values[key].nil?
return true
end
end
return false
end
def delete_row(key)
pos = @keys.index(key)
if pos
@keys[pos] = nil
@keys.compact!
@table[pos] = nil
@table.compact!
end
end
def insert_row(key, after)
if has?(key) && !@keys.include?(key)
pos = @keys.index(after)
if pos
@keys.insert(pos + 1, key)
@table.insert(pos + 1, [prepare_label(key)])
end
end
end
def append_row(key)
if has?(key) && !@keys.include?(key)
@keys << key
@table << [prepare_label(key)]
end
end
def apply_hide_option
@hide.each do |key|
if key =~ /(.*):(.*)/
key = $1
col = $2
@series.assoc(col)[1][key.to_sym] = nil
else
@series.each do |n, values|
values[key.to_sym] = nil
end
end
end
end
def apply_manual_cells
@manual_cells.each do |string|
if string =~ /(.*):(.*):(.*)/
key = $1
col = $2
value = $3
@series.assoc(col)[1][key.to_sym] = value
@series.assoc(col)[1][(key + "_string").to_sym] = true
else
STDERR.puts "Error: -setvalue #{string} not valid"
end
end
end
def apply_space_time_extended
if @extended[:space]
spkeys = %w{hwm_gtsp_delta vm_peak hwm_space gt_space mmap alloc}
@main_phases.each do |ph|
spkeys.each {|v| insert_row(:"#{ph}_#{v}", :"#{ph}_space")}
end
spkeys.reverse.each {|v| append_row(:"overlap_and_assembly_#{v}")}
end
if @extended[:s_percent] or @extended[:space]
@series.each do |n, values|
if !values[:ratio_column]
time = values[:overall_space]
if !time.nil?
(@main_phases - [:overall]).each do |ph|
v = values[:"#{ph}_space"]
if !v.nil?
values[:"#{ph}_s_percent"] = v.to_f * 100 / time if v
end
end
end
end
end
@main_phases.each {|ph| insert_row(:"#{ph}_s_percent", :"#{ph}_space")}
end
if @extended[:time]
tk = %w{sys_time user_time real_cpu_time_diff cpu_time real_time
gt_sys_time gt_user_time gt_real_cpu_time_diff gt_cpu_time
gt_real_time}
@main_phases.each do |ph|
tk.each {|v| insert_row(:"#{ph}_#{v}", :"#{ph}_time")}
end
tk.reverse.each {|v| append_row(:"overlap_and_assembly_#{v}") }
end
if @extended[:t_percent] or @extended[:time]
@series.each do |n, values|
if !values[:ratio_column]
time = values[:overall_time]
if !time.nil?
(@main_phases - [:overall]).each do |ph|
v = values[:"#{ph}_time"]
if !v.nil?
values[:"#{ph}_t_percent"] = v.to_f * 100 / time if v
end
end
end
end
end
@main_phases.each {|ph| insert_row(:"#{ph}_t_percent", :"#{ph}_time")}
end
end
def apply_extended
extra_keys = @phasewisekeys.clone + [:prefixlength, :maxinsertionsort,
:maxbltriesort, :maxcountingsort, :relevant, :suftabuint, :memlimit,
:sat, :sfxtotallength]
@phasewisekeys.each do |k|
summarized = true
@series.each do |n, values|
vs = @phases.keys.map {|ph| values[:"#{ph}_#{k}"]}.compact!
if vs.uniq.size == 1
values[k] = vs[0]
else
summarized = false
end
end
if !summarized
extra_keys += @phases.keys.map {|ph| :"#{ph}_#{k}"}
end
end
if @extended[:extra]
extra_keys.each {|k| append_row(k)}
end
end
def apply_manual_rows
@manual_rows.each do |row|
key = row.shift
label = row.shift
[row.size, @series.size].min.times do |i|
@series[i][1][key] = row[i]
end
if label != "-" || label(key) == ""
@customlabels[key] = label
end
if !@outorder.include?(key)
@outorder << key
end
end
end
def prepare_label(key)
if (@show_keys)
if key == :title
str = ""
else
str = key.to_s
end
else
str = label(key)
unit = UnitLabel[@unit[category(key)]]
(str << unit) if !unit.nil?
end
return str
end
def prepare_first_column
keys = []
@series.each do |n, values|
keys << values.keys
end
keys.uniq!
keys.flatten!
@outorder.each do |key|
next if !has?(key)
next if @keys.include?(key)
if keys.include?(key)
@keys << key
@table << [prepare_label(key)]
end
end
sizes = @table.map{|l| l[0].size}
@firstcolsize = sizes.size > 0 ? sizes.max + 4 : 0
end
def format_number(number, divider, precision)
return nil if !number
number = number.to_f / divider
number.with_precision(precision).to_s
end
def format_value(value, category)
return NoValue if value.nil?
case category
when :time
if @unit[:time] == :s
return value.to_f.round.to_s
elsif @unit[:time] == :hm
return value.to_f.round.s2hm
end
when :space
if @unit[:space] == :Mb
return value.round.to_s
elsif @unit[:space] == :Gb
value = value.to_f.mem_convert(:Mb, :Gb)
return value.to_f.with_precision(1).to_s
end
when :length
if @unit[:length] == :kbp
return format_number(value, 1_000, 1)
elsif @unit[:length] == :bp
return value.to_f.round.to_s
end
when :longlength
if @unit[:longlength] == :Mbp
return format_number(value, 1_000_000, 1)
elsif @unit[:longlength] == :bp
return value.to_f.round.to_s
end
when :millions
if @unit[:millions] == :M
return format_number(value, 1_000_000, 1)
elsif @unit[:millions] == :n
return value.to_f.round.to_s
end
when :thousands
if @unit[:thousands] == :K
return format_number(value, 1_000, 1)
elsif @unit[:thousands] == :n
return value.to_f.round.to_s
end
when :integer
return value.to_f.round.to_s
when :percent
return value.to_f.with_precision(1).to_s
when :string
return value
when :ratio
precision = 2
return sprintf("%.#{precision}f x", value.to_f.with_precision(precision))
end
end
def overall_needed
if @overall_needed.nil?
@overall_needed = false
@series.each do |n, values|
skeys = 0
tkeys = 0
@main_phases.each do |ph|
(skeys += 1) if values.has_key?(:"#{ph}_space")
(tkeys += 1) if values.has_key?(:"#{ph}_time")
end
if skeys > 1 || tkeys > 1
@overall_needed = true
break
end
end
end
return @overall_needed
end
def add_index_and_overlap_space
if @index_and_overlap
@series.each do |n, values|
spaces = []
(spaces << values[:index_space]) if values[:index_space]
(spaces << values[:overlap_space]) if values[:overlap_space]
values[:index_and_overlap_space] = spaces.max
end
end
end
def add_index_and_overlap_time
if @index_and_overlap
@series.each do |n, values|
time = 0
(time += values[:index_time]) if values[:index_time]
(time += values[:overlap_time]) if values[:overlap_time]
time = nil if time == 0
values[:index_and_overlap_time] = time
end
end
end
def add_overall_space
if overall_needed
@series.each do |n, values|
spaces = []
@main_phases.each do |ph|
(spaces << values[:"#{ph}_space"]) if values[:"#{ph}_space"]
end
values[:overall_space] = spaces.max
end
end
end
def add_overall_time
if overall_needed
@series.each do |n, values|
time = 0
@main_phases.each do |ph|
(time += values[:"#{ph}_time"]) if values[:"#{ph}_time"]
end
time = nil if time == 0
values[:overall_time] = time
end
end
end
end
class DataCollectionOptions
end
## ScriptRunner: parse arguments and coordinate execution ##
class ScriptRunner
UsageMsg =<<-end_usage_msg
Collect information from the standard output of suffixerator/readjoiner and
some related programs in tabular form.
Usage: #$0 [options] [<type>] <file> [[-<type>] <file>]+
end_usage_msg
BasicUsageMsg=<<-end_usage_msg
#{UsageMsg}
Use the -help option for more information.
end_usage_msg
ExtendedUsageMsg=<<-end_usage_msg
#{UsageMsg}
If two files for the same program are in phases order (e.g. I followed by O),
they are grouped in a single column unless separated by --.
An unique prefix of the filename is enough.
Running time:
-cpu use cpu time = sum of user+sys [default]
-real use real time
-user use user time
-tm prefer time measurements by \"time\" over gt showtime [default]
-gttm prefer gt showtime over \"time\"
-sec express running time in seconds [default]
-hm express running time in hours and minutes
-t% additional show phase running time as percent of overall
-t output all available running times
Space peak:
-Mb express space peaks in megabytes [default]
-Gb express space peaks in gigabytes
-hwm prefer vm_hwm over gt space peak [default]
-gtsp prefer gt space peak over vm_hwm
-s% additional show phase space peaks as percent of overall peak
-s output all available space peaks
Further information:
-m use multipliers for lengths/counts (millions/thousands) [default]
-n display exact values of lenghts/counts
-x show extra information, such as hostname
-io show consolidate values for index + overlap
Columns/Rows modifications:
-- force start new column
-ti xxx yyy ... --
specify column titles
-ratio key1 key2 key2 [title|-] --
display ratio key2 / key1 after column key2
either give ratio the default title (-) or the specified title
-ratiorows key1 key2 ... --
display ratio only for specified columns
-hide key1 key2:column ... --
hide specified rows (key1) or values (key2:column)
-show key1 ... --
additionally show specified rows (key1)
-only key1 key2 .... --
show only specified rows, in that order
-setrow :symbol [label|-] value1 value2 ... --
add specified row or manually set existing row to given values
-setvalue key:column:value ... --
manually set given values
Tex table:
-tex output a latex table
-no_page output just the tabular content
-first_page skip page end
-middle_page skip page start and end
-last_page skip page end
-no_sw do not use sidewaystable
Gnuplot data:
-dat output data for GnuPlot
CSV:
-csv output data as comma delimited values
File type override:
-sfx suffixerator
-rdj[OA] readjoiner
-edn[OA] edena
-sga[IOA] sga
-sum results file
Further options:
-keys visualize row and column keys
-raw display the hash with the gathered data in yaml format and exit
-clean remove progress bars, \\r and trailing whitespaces from input files
and exit (any other argument is considered to be a filename)
-help show this help message and exit
Example usage:
#$0 -tex -ti before_rebase after_rebase -- \\
before_rebase.sfx.log before_rebase.rdj.log \\
after_rebase.sfx.log after_rebase.rdj.log
end_usage_msg
LogTypes = ["-sfx", "-rdj", "-rdjO", "-rdjA", "-sum", "-ednO", "-ednA",
"-sgaI", "-sgaO", "-sgaA", "-leap", "-pflt", "-uniq"]
ParserClass = {
"-sfx" => OutputParser::Suffixerator,
"-rdjO" => OutputParser::RdjOverlap,
"-rdjA" => OutputParser::RdjAssembly,
"-rdj" => OutputParser::RdjBoth,
"-sum" => OutputParser::ResultsFile,
"-ednO" => OutputParser::EdenaOverlap,
"-ednA" => OutputParser::EdenaAssembly,
"-sgaI" => OutputParser::SgaIndex,
"-sgaO" => OutputParser::SgaOverlap,
"-sgaA" => OutputParser::SgaAssembly,
"-leap" => OutputParser::Leap,
"-uniq" => OutputParser::Sequniq,
"-pflt" => OutputParser::Prefilter,
}
SameColumn = {
"-sfx" => ["-rdj", "-rdjO"],
"-rdjO" => ["-rdjA"],
"-rdjA" => [],
"-rdj" => [],
"-sum" => [],
"-ednO" => ["-ednA"],
"-ednA" => [],
"-sgaI" => ["-sgaO"],
"-sgaO" => ["-sgaA"],
"-sgaA" => [],
"-leap" => [],
"-uniq" => ["-sfx"],
"-pflt" => ["-sfx", "-rdjO"],
}
Signatures =
[
# the first found in this order:
["prefixlength", "-sfx" ],
["gt readjoiner -overlap", "-rdjO"],
["gt readjoiner -assembly", "-rdjA"],
["gt readjoiner overlap", "-rdjO"],
["gt readjoiner assembly", "-rdjA"],
["gt readjoiner prefilter", "-pflt"],
["Computing overlaps", "-ednO"],
["loading transitively reduced overlap graph", "-ednA"],
["Contigs elongations were stopped", "-ednA"],
["calling mkqs", "-sgaI"],
["[sga::overlap]", "-sgaO"],
["sga assemble", "-sgaA"],
["Lngst", "-sum" ],
["LEAP", "-leap"],
["have been removed", "-uniq"],
["encseq2spm", "-sfx" ],
]
def parse!(args)
parse_special_options!(args)
parse_data_collection_options!(args)
parse_output_options!(args)
@titles = parse_stringarray!("-ti", args)
@titles = nil if @titles.size == 0
@data.hide += parse_stringarray!("-hide", args)
@data.show = parse_stringarray!("-show", args)
@data.only_rows = parse_stringarray!("-only", args)
@data.ratios = parse_stringarray!("-ratio", args)
@data.ratiorows = parse_stringarray!("-ratiorows", args)
@data.manual_cells = parse_stringarray!("-setvalue", args)
parse_setrow!(args)
parse_series(args)
end
def initialize(arguments)
@data = DataCollection.new
@table = Table.new
parse!(arguments)
@series.each_with_index do |s, i|
t = @titles ? @titles[i] : nil
@data.create_series(i.to_s, t)
s.each do |filename, logtype|
log = IO.read(filename)
parser = ParserClass[logtype].new(log)
parser.results.each_pair do |key, value|
@data.add_value(i.to_s, key, value)
end
end
end
@data.prepare!(@raw)
@table.data = @data.tabulize
puts @table.show
end
def new_series?(logtype, previous)
return true if previous.nil? or logtype == previous
return !SameColumn[previous].include?(logtype)
end
# delete progress bar lines and \r from transcripts
def clean_script_transcript(filename)
input = IO.read(filename)
o = File.open(filename, "w")
# remove \r:
input.gsub!("\r\n", "\n")
input.gsub!("\r", "\n")
# delete progress bar and extra whitespace:
input.each_line do |line|
if line !~ /\d{1,3}\% \|[ \*]+\| .*ETA$/
next if line =~ /cat: \/proc\/(\d+)\/status: No such file or directory/
if line =~ / *\d{1,3}\% \|[ \*]+\| +(\d+:)?\d+:\d+ ?E?T?A?/
line.gsub!(/ *\d{1,3}\% \|[ \*]+\| +(\d+:)?\d+:\d+ ?E?T?A?/, "")
if line.gsub(/[\s:]/,"") != ""
o.puts line.strip
end
else
o.puts line.strip
end
end
end
o.close
end
def backup_transcript(filename, data)
@backup ||= {}
unless @backup[filename]
b = File.open(filename + ".bak", "w")
b.puts data
b.close
@backup[filename] = true
STDERR.puts "The original transcript has been preserved"+
"as #{filename}.bak"
end
end
def clean_edena_transcript(filename)
input = IO.read(filename)
o = File.open(filename, "w")
state = :normal
previous_line = ""
# delete progress bar and extra whitespace:
input.lines.each_with_index do |line, lineno|
case state
when :normal
if line =~ /^reading fasta entries/
state = :reading_fasta_entries
elsif line =~ /^Computing overlaps /
state = :computing_overlaps
elsif line =~ /^Removing transitive edges/
state = :removing_transitive_edges
next
end
when :reading_fasta_entries
if line =~ /^fasta entries: /
o.puts previous_line
state = :normal
elsif line =~ /^\d+/ or line.strip.empty?
previous_line = line
next
else
STDERR.puts "Warning: forced exit from "+
"reading_fasta_entries state in #{filename}:#{lineno}"
backup_transcript(filename, input)
state = :normal
end
when :computing_overlaps
if line =~ /^done/
o.puts previous_line
state = :normal
elsif line =~ /^\d+/
previous_line = line
next
else
STDERR.puts "Warning: forced exit from "+
"computing_overlaps state in #{filename}:#{lineno}"
backup_transcript(filename, input)
state = :normal
end
when :removing_transitive_edges
if line =~ /^Removing transitive edges... done/
state = :normal
elsif line =~ /^Removing transitive edges...(\d+)/
next
else
STDERR.puts "Warning: forced exit from "+
"removing_transitive_edges state in #{filename}:#{lineno}"
backup_transcript(filename, input)
state = :normal
end
end
o.puts line
end
o.close
end
def parse_special_options!(args)
if args.size < 1
puts BasicUsageMsg
exit
end
if args.delete("-help")
puts ExtendedUsageMsg
exit
end
if args.delete("-clean")
args.each do |filename|
clean_script_transcript(filename)
if ["-ednO"].include?(guess_logtype(IO.read(filename)))
clean_edena_transcript(filename)
end
end
exit
end
end
def parse_data_collection_options!(args)
@data.unit[:space] = :Mb if args.delete("-Mb")
@data.unit[:space] = :Gb if args.delete("-Gb")
@data.unit[:time] = :s if args.delete("-sec")
@data.unit[:time] = :hm if args.delete("-hm")
had_m = args.delete("-m")
had_n = args.delete("-n")
@data.unit[:length] = :kbp if had_m
@data.unit[:length] = :bp if had_n
@data.unit[:longlength] = :Mbp if had_m
@data.unit[:longlength] = :bp if had_n
@data.unit[:millions] = :M if had_m
@data.unit[:millions] = :n if had_n
@data.unit[:thousands] = :k if had_m
@data.unit[:thousands] = :n if had_n
v = "cpu" # default
v = "cpu" if args.delete("-cpu")
v = "real" if args.delete("-real")
v = "user" if args.delete("-user")
@data.time_variety = :"#{v}_or_gt_#{v}" # default
@data.time_variety = :"#{v}_or_gt_#{v}" if args.delete("-tm")
@data.time_variety = :"gt_#{v}_or_#{v}" if args.delete("-gttm")
@data.space_variety = :hwm_or_gt if args.delete("-hwm")
@data.space_variety = :gt_or_hwm if args.delete("-gtsp")
@data.extended[:space] = (args.delete("-s"))
@data.extended[:time] = (args.delete("-t"))
@data.extended[:extra] = (args.delete("-x"))
@data.extended[:t_percent] = (args.delete("-t%"))
@data.extended[:s_percent] = (args.delete("-s%"))
@data.show_keys = true if (args.delete("-keys"))
@data.index_and_overlap = true if (args.delete("-io"))
if @data.index_and_overlap
@data.hide += [:index_time, :index_space, :overlap_time, :overlap_space]
end
end
def parse_output_options!(args)
@raw = (args.delete("-raw"))
@table.format = :tex if args.delete("-tex")
@table.format = :dat if args.delete("-dat")
@table.format = :csv if args.delete("-csv")
@table.tex_page = :first if (args.delete("-first_page"))
@table.tex_page = :middle if (args.delete("-middle_page"))
@table.tex_page = :last if (args.delete("-last_page"))
@table.tex_page = :none if (args.delete("-no_page"))
@table.nosideways = (args.delete("-nosw"))
end
def parse_stringarray!(starter, args)
samode = false
results = []
args.each_with_index do |a, i|
if !samode
if a == starter
samode = true
args[i] = nil
end
else
if a == "--"
samode = false
else
results << a
end
args[i] = nil
end
end
args.compact!
return results
end
def parse_setrow!(args)
all_setrow = parse_stringarray!("-setrow", args)
@data.manual_rows = []
all_setrow.each do |a|
if a =~ /:(.*)/
@data.manual_rows << [$1.to_sym]
else
if @data.manual_rows.empty?
STDERR.puts "-setrow: missing \":<key>\""
exit(-1)
end
@data.manual_rows.last << a
end
end
end
def guess_logtype(log)
Signatures.each do |key, value|
if log.index(key)
logtype = value
return logtype
end
end
return nil
end
def parse_series(args)
logtype = nil
previous = nil
@series = []
args.each do |a|
if LogTypes.include?(a)
logtype = a
next
end
if a == "--"
@series << [] unless @series.size == 0 or @series.last.size == 0
next
end
if !logtype
if (!File.exists?(a))
g = Dir.glob("#{a}*")
if (g.size == 1)
a = g[0]
else
STDERR.puts \
"File \"#{a}\" not found (or "+
"filename prefix not unique), skipped"
next
end
end
logtype = guess_logtype(IO.read(a))
end
if !logtype
puts "Error: unknown logtype of #{a}, skipped"
next
end
if new_series?(logtype, previous)
@series << []
end
@series.last << [a, logtype]
previous = logtype
logtype = nil
end
if @series.empty?
STDOUT.puts "Filenames list is empty, aborting..."
exit(1)
end
end
end
if $0 == __FILE__
ScriptRunner.new(ARGV)
end
|