Framework¶
A framework is the coordinate system a survey runs inside: the taxon namespace, each alignment with its neighbor-joining tree, the charts with their anchors and geometry, and the settings that fix the coordinates. The substitution model, the metric weight and the occupancy floor decide where the charts are, so they belong to the framework. The niche size and the origin decide how one run bins a chart, so they belong to the run.
FrameworkSpec is the recipe. It is small enough to write by hand, and it
reads from and writes to TOML. Framework.build turns the recipe into a
Framework, at the cost of one neighbor-joining pass per alignment, so a batch
of work is given the built form. Each chart of a framework is a
FrameworkChart: three anchor labels and the triangle they embed.
Framework.digest identifies a framework. Two surveys with the same digest
project into one coordinate system. explain_mismatch says how two frameworks
differ when their digests do not match. A Batch names the work
done inside a framework, and a survey file holds the framework
together with that work.
FrameworkSpec
dataclass
¶
The recipe for a framework: which alignments, which charts, what settings.
The spec validates its own labels at construction, so a typo raises where the user wrote it rather than after several minutes of neighbor joining.
Attributes:
| Name | Type | Description |
|---|---|---|
alignments |
dict
|
Label to alignment path. A label names an HDF5 group in the survey file, so it may not contain a slash. |
charts |
list of tuple
|
Each chart as three distinct anchor labels, in the order that fixes which corner is which. |
chart_labels |
list of str
|
A name per chart, in the same order. Shorter than |
model |
str
|
Substitution model name, or |
w |
float
|
Topology weight of the tree metric, in [0, 1]. |
min_occupancy |
float
|
The fraction of a gene's alignment a taxon must carry to enter that gene's tree. A taxon carrying nothing is left out whatever this says. |
Source code in src/hifuku/framework.py
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 | |
from_toml
classmethod
¶
Read a framework file.
The file holds a [framework] table of settings, an [alignments]
table of label to path, and one [[charts]] table per chart holding
anchors and an optional label.
Source code in src/hifuku/framework.py
from_mapping
classmethod
¶
Build a spec from an already-parsed mapping.
A batch file may carry a framework inline, so the mapping and the file are read by one function and the two forms cannot drift apart.
Source code in src/hifuku/framework.py
to_toml
¶
as_toml_lines
¶
The framework file as lines, for writing alone or inside a batch.
Source code in src/hifuku/framework.py
Framework
dataclass
¶
The built coordinate system: the trees, the charts, and their provenance.
Construct one with :meth:build from a :class:FrameworkSpec. Everything
a coordinate depends on is decided once, when the framework is built, so
that a batch run against it later cannot move the frame under its own
results.
Source code in src/hifuku/framework.py
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 | |
wall_seconds
property
¶
Elapsed seconds this framework took to build.
Paid once, however many batches then run inside it. A framework read from a file that recorded no timing reports zero.
cpu_seconds
property
¶
Processor seconds the build held, user and system together.
build
classmethod
¶
Read the alignments, build the trees, and embed the charts.
The three steps scale differently, so each takes its own span on the clock. Neighbor joining costs the cube of the taxon count and takes over on a large namespace, where reading the alignments and embedding the triangles do not.
Every triangle is embedded before the framework returns, so a chart that will not embed reports in seconds rather than after a survey has run.
Source code in src/hifuku/framework.py
digest
¶
The key two frameworks are compared on.
Covers what the framework produced rather than what went into it: the taxon set, the trees, the chart geometry, the model and the metric weight. The niche size and origin are not here, because they belong to a run and two runs at different resolutions share these coordinates.
Source code in src/hifuku/framework.py
write
¶
Write this framework into one HDF5 group.
The digest is stored beside the parts it covers, so a reader can check
what it was handed against what it was told. Each alignment gets a
group named for it, because framework/alignments/PF00410 is what a
reader wants to type.
Source code in src/hifuku/framework.py
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 | |
read
classmethod
¶
Rebuild a framework from one HDF5 group.
The digest is recomputed from what was read and checked against the stored one. A file truncated in transit, or edited by hand, is refused here rather than becoming a framework that later runs are checked against.
A file written under an older digest scheme is read and not refused.
Its digest covers what a digest covered then, so it cannot match one
computed now, and refusing it would make a change to the scheme destroy
the files written before it. Such a framework carries no identity a
later run can be checked against, so the reader is warned and told what
that costs. See DIGEST_SCHEME.
Source code in src/hifuku/framework.py
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 | |
check_spec
¶
Raise unless this framework is what spec asks for.
Appending to a project file uses the framework the file already holds, which saves rebuilding every tree. That saving is only safe if the batch was asking for those coordinates, so this compares the inputs a framework is built from: the alignment files and their contents, the chart anchors and their order, the substitution model, the metric weight and the occupancy floor.
Every one of those is recorded, so the check costs a file digest per alignment rather than a neighbor-joining pass.
A spec names each alignment by the path it had when the spec was written. A file at that path must be the recorded alignment. A path with no file there is not checked: the alignment has moved, and the framework holds it or finds it by its digest.
Raises:
| Type | Description |
|---|---|
ValueError
|
The spec asks for different coordinates. The message names the first thing that differs. |
Source code in src/hifuku/framework.py
alignment
¶
The pool entry with this label.
Source code in src/hifuku/framework.py
chart
¶
Return one chart, given either its label or its position.
A chart can be named two ways. Its position is the integer a batch
file writes as chart = 0, and it is stored with every surveyed
niche. Its label is the text a person reads, capsid+tf2s+vltf3 by
default, and a caller may set it to anything.
Both are accepted here so that analysis code can select by the name a reader knows, while stored data keeps referring to the position. The position is used for storage because a label may be changed and a stored reference must not move when it is.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
int or str
|
A position in |
required |
Raises:
| Type | Description |
|---|---|
KeyError
|
No chart carries this label. |
IndexError
|
This position is past the end of |
Source code in src/hifuku/framework.py
chart_index
¶
Return the position of a chart, given its label or its position.
A batch and a survey record refer to a chart by position, so code that takes a label from a user converts it here before storing anything.
Source code in src/hifuku/framework.py
timing_report
¶
What the build cost, step by step, longest first.
Source code in src/hifuku/framework.py
FrameworkChart
dataclass
¶
One chart: three anchor labels and the triangle they embed.
The anchor order is kept as the chart was built with, because that order fixes which corner of the triangle is which.
label is what a reader selects the chart by. Unset, it is the three
anchors joined. It names the chart and nothing else: a chart is identified
within a framework by its position, which is what a batch and every stored
niche refer to, so renaming one moves nothing.
Source code in src/hifuku/framework.py
explain_mismatch
¶
Why two frameworks that should agree do not.
A digest says that two frameworks differ and nothing about why. The provenance of each says where it was built, and a difference there is usually the cause: a package version that moved the numerics, a different host, a different device architecture. This names those before it reports the digests, because the digests are the part a reader can do nothing with.
Two frameworks built in one environment differ because their inputs differ, and the report says so rather than listing nothing.
Source code in src/hifuku/framework.py
chart_label
¶
The name a chart carries when its caller gives it none.
Three anchors joined, which is what a reader recognizes a chart by and what they would have written themselves. It is a name and nothing more: the framework digest does not cover it, so renaming a chart leaves the coordinates it defines unchanged.