API reference¶
Generated from the package's own docstrings. The names here are everything
ligase exports; anything not listed is an implementation detail and may
change without notice — including ligase._core, the compiled module.
Loading data¶
A loader reads what it can from the file and takes the rest as declarations.
What it inferred, and from where, is recorded on the result:
dataset.dimension("reference").source says declared or names the header it
came from.
ligase ¶
Ligase: type-safe, reproducible computational biology pipelines.
Biological data types carry dimensions (organism, reference build, coordinate system, sample set), and the engine refuses to connect steps whose dimensions do not match -- like units in physics.
>>> import ligase as lg
>>> from ligase.types import Alignment, Reads, Reference
>>> hxb2 = lg.reference("refs/HXB2.fasta", organism="HIV-1", build="HXB2")
>>> samples = lg.samples("data/*.fastq.gz", paired=True)
>>> @lg.step(tool="minimap2")
... def align(reads: Reads, ref: Reference) -> Alignment: ...
>>> pipe = lg.Pipeline(samples.map(lambda s: align(s, hxb2)))
>>> pipe.check() # type-checks every step; nothing runs
>>> pipe.run() # parallel, cached, per-sample fan-out
reference ¶
Load a reference FASTA, inferring its contigs.
Each contig's MD5 is computed here, over the uppercased sequence, as the
SAM specification defines @SQ M5. Computing it ourselves is what lets
us check an aligner's claim about which reference it used.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
The FASTA, optionally gzipped. |
required |
organism
|
str | None
|
The organism, e.g. |
None
|
build
|
str | None
|
A human label such as |
None
|
Returns:
| Type | Description |
|---|---|
Reference
|
The loaded reference. |
Raises:
| Type | Description |
|---|---|
LoadError
|
If the file cannot be read or is not a FASTA. |
Source code in python/ligase/__init__.py
reads ¶
reads(r1: str, r2: str | None = None, *, organism: str | None = None, sample: str | None = None) -> Reads
Load sequencing reads, inferring what a FASTQ can tell us.
The quality encoding comes from the observed score range, and comes back unknown rather than guessed when the scores fall in the range Phred+33 and Phred+64 share. Guessing would shift every quality value by 31, which no downstream tool would notice.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
r1
|
str
|
The reads, or the first mate of a pair. Optionally gzipped. |
required |
r2
|
str | None
|
The second mate, if the reads are paired. |
None
|
organism
|
str | None
|
The organism. A FASTQ does not record it. |
None
|
sample
|
str | None
|
The sample identifier, overriding the one taken from the filename. |
None
|
Returns:
| Type | Description |
|---|---|
Reads
|
The loaded reads. |
Raises:
| Type | Description |
|---|---|
LoadError
|
If a file cannot be read or is not a FASTQ. |
Source code in python/ligase/__init__.py
alignment ¶
alignment(path: str, *, organism: str | None = None, build: str | None = None, samples: list[str] | None = None) -> Alignment
Load a SAM or BAM, inferring dimensions from its header.
Both containers yield identical dimensions: a lossless
samtools view -b changes nothing biological.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
The alignment file. |
required |
organism
|
str | None
|
The organism. SAM and BAM headers do not record it. |
None
|
build
|
str | None
|
A human label for the reference build. Display only. |
None
|
samples
|
list[str] | None
|
The sample identifiers, overriding the |
None
|
Returns:
| Type | Description |
|---|---|
Alignment
|
The loaded alignment. |
Raises:
| Type | Description |
|---|---|
LoadError
|
If the file cannot be read or is not a SAM/BAM. |
Source code in python/ligase/__init__.py
variants ¶
variants(path: str, *, organism: str | None = None, build: str | None = None, samples: list[str] | None = None) -> Variants
Load a VCF, inferring dimensions from its header.
Identity comes from ##contig alone. ##reference is deliberately not
trusted: it holds a path, and two runs pointing at /refs/genome.fa can
be pointing at different genomes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
The VCF, optionally gzipped or BGZF-compressed. |
required |
organism
|
str | None
|
The organism. A VCF does not record it. |
None
|
build
|
str | None
|
A human label for the reference build. Display only. |
None
|
samples
|
list[str] | None
|
The sample identifiers, overriding the header columns. |
None
|
Returns:
| Type | Description |
|---|---|
Variants
|
The loaded variant calls. |
Raises:
| Type | Description |
|---|---|
LoadError
|
If the file cannot be read or is not a VCF. |
Source code in python/ligase/__init__.py
intervals ¶
intervals(path: str, *, format: str | None = None, organism: str | None = None, build: str | None = None) -> Intervals
Load genomic intervals from a BED or GFF, inferring what they say.
The coordinate convention comes from the format — BED is 0-based half-open, GFF and GTF are 1-based closed — and that is the point: a tool handed the wrong one produces results that are off by one base and look fine.
Contigs come from the records, so they carry no length and no checksum. They are still compared against a reference by name, because comparing what is present is what makes these files checkable at all.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
The BED, GFF3 or GTF, optionally gzipped. |
required |
format
|
str | None
|
|
None
|
organism
|
str | None
|
The organism. An interval file does not record it. |
None
|
build
|
str | None
|
A human label for the reference build. Display only. |
None
|
Returns:
| Type | Description |
|---|---|
Intervals
|
The loaded intervals. |
Raises:
| Type | Description |
|---|---|
LoadError
|
If the file cannot be read, is not in the format given, or its format cannot be told from its name. |
Source code in python/ligase/__init__.py
Declaring and running steps¶
ligase ¶
Ligase: type-safe, reproducible computational biology pipelines.
Biological data types carry dimensions (organism, reference build, coordinate system, sample set), and the engine refuses to connect steps whose dimensions do not match -- like units in physics.
>>> import ligase as lg
>>> from ligase.types import Alignment, Reads, Reference
>>> hxb2 = lg.reference("refs/HXB2.fasta", organism="HIV-1", build="HXB2")
>>> samples = lg.samples("data/*.fastq.gz", paired=True)
>>> @lg.step(tool="minimap2")
... def align(reads: Reads, ref: Reference) -> Alignment: ...
>>> pipe = lg.Pipeline(samples.map(lambda s: align(s, hxb2)))
>>> pipe.check() # type-checks every step; nothing runs
>>> pipe.run() # parallel, cached, per-sample fan-out
Pipeline ¶
A graph of steps, built from its outputs and checked before it runs.
Construction walks back from the outputs through the handles each step was given, so a file passed to two steps becomes one node rather than two. Nothing is executed and nothing is read: the graph is built from signatures and from the dimensions the inputs were loaded with.
Source code in python/ligase/graph.py
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 | |
__init__ ¶
Build the graph that produces these outputs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
outputs
|
Dataset | Iterable[Dataset]
|
One handle, or an iterable of them — what
|
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no outputs were given. |
TypeError
|
If a step was passed something that is neither loaded data nor another step's output. |
Source code in python/ligase/graph.py
report ¶
Check every step and return everything found, without raising.
errors ¶
Return every problem in this pipeline, without raising.
Returns:
| Type | Description |
|---|---|
list[CheckError]
|
One error per problem, in the order the steps run. Empty when |
list[CheckError]
|
the pipeline is consistent. Nothing is computed. |
Source code in python/ligase/graph.py
check ¶
Type-check the whole pipeline. Nothing is computed.
Every problem is found before anything is raised, so the raised
error's errors attribute holds all of them.
Raises:
| Type | Description |
|---|---|
CheckError
|
If anything is wrong. The subclass says what:
|
Source code in python/ligase/graph.py
run ¶
Check the pipeline, then compute whatever is not already known.
The pipeline is checked first, every time: running an unchecked pipeline is how an overnight run ends in a dimension error.
A step runs when something that could change its result has changed — its code, a parameter, an input's contents, or the version of a tool it calls — and not otherwise. Independent steps run at once, and a step whose rerun produced the same output as before leaves everything below it alone.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
jobs
|
int | None
|
How many steps may run at once. Defaults to the number of cores. |
None
|
force
|
bool
|
Run every step, cache or no cache. For the one case the cache cannot see: a file rewritten in place, keeping its length and its timestamp. |
False
|
cache
|
str | Path | None
|
Where to keep the cache. Defaults to |
None
|
Returns:
| Type | Description |
|---|---|
RunReport
|
What every step did, and where its output is. |
Raises:
| Type | Description |
|---|---|
CheckError
|
If the pipeline does not type-check. Nothing runs. |
RunError
|
If any step failed. Everything that did succeed is on
the error's |
Source code in python/ligase/graph.py
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 | |
audit ¶
audit(step: str, *, sample: str | None = None, jobs: int | None = None, cache: str | Path | None = None) -> AuditReport
Run one step twice and report whether it is reproducible.
The pipeline is run first, normally and through the cache, so that the step being audited has its inputs. Then each node of that step is run twice more, into scratch files that are thrown away, and the two outputs are compared both as bytes and as meaning.
Three verdicts, because two would not do. A step whose bytes move
while its result does not — which is every tool that records its own
command line — is reproducible, not a failure. Only a step whose
result moves is not reproducible.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
step
|
str
|
The step's name, as written. Under per-sample fan-out there is one node of it per sample, and all of them are audited. |
required |
sample
|
str | None
|
Audit only the node for this sample. |
None
|
jobs
|
int | None
|
How many steps may run at once in the preliminary run. The audited steps are taken in turn whatever this says, so that the durations reported mean something. |
None
|
cache
|
str | Path | None
|
Where to keep the cache. Defaults to |
None
|
Returns:
| Type | Description |
|---|---|
AuditReport
|
What two runs of each node showed. |
Raises:
| Type | Description |
|---|---|
CheckError
|
If the pipeline does not type-check. Nothing runs. |
ValueError
|
If no step of that name is in the pipeline, or no node of it is for that sample. |
Source code in python/ligase/graph.py
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 | |
methods ¶
methods(*, bundle: str | Path | None = None, verify: str | Path | None = None, include: Sequence[str | Path] = (), jobs: int | None = None, cache: str | Path | None = None) -> Methods
Say how this pipeline's results were produced.
The pipeline is run first, normally and through the cache, because a provenance record is filed under a step's key and computing keys is what a run does. A pipeline already computed costs a cache lookup per step, not a recomputation.
What comes back names, for every step: the tools and the versions they ran at, the parameters as they were hashed, the command as written, and every reference by accession and checksum. A step whose output predates provenance is reported as a gap rather than left out, because nothing can reconstruct how it was produced — the command that would have said so is deliberately not in the hash.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bundle
|
str | Path | None
|
Write a reproducibility bundle into this directory. |
None
|
verify
|
str | Path | None
|
Check the bundle in this directory against what this machine just produced, and report where they differ. |
None
|
include
|
Sequence[str | Path]
|
Files to copy into the bundle as they are, such as the pipeline itself. |
()
|
jobs
|
int | None
|
How many steps may run at once in the run beforehand. |
None
|
cache
|
str | Path | None
|
Where to keep the cache. Defaults to |
None
|
Returns:
| Type | Description |
|---|---|
Methods
|
How every step was produced, with the bundle written and the |
Methods
|
verification done, where either was asked for. |
Raises:
| Type | Description |
|---|---|
CheckError
|
If the pipeline does not type-check. Nothing runs. |
RuntimeError
|
If a step failed, since a pipeline that did not finish has no methods section to write; or if a bundle cannot be written. |
ValueError
|
If the directory to verify against is not a bundle. |
Source code in python/ligase/graph.py
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 | |
__len__ ¶
Step ¶
Bases: Generic[P, R]
A function that records a call instead of running.
Attributes:
| Name | Type | Description |
|---|---|---|
function |
The undecorated callable. A run calls it once, before anything executes, to ask how the output is produced. |
|
tool |
The external tools the step shells out to, as they were given. |
|
tools |
Those tools as a tuple, whose versions join the cache key. |
|
coordinates |
The coordinate convention the step writes, for the one output kind that does not imply one. |
|
citations |
References the step asks to be cited by. |
Source code in python/ligase/graph.py
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 | |
dataset_parameters
property
¶
The parameters that take data, in declaration order.
Order matters: a dimension is inherited from the first argument that states it.
plain_parameters
property
¶
The parameters that take plain values, in declaration order.
__init__ ¶
__init__(function: Callable[P, R], *, tool: str | Sequence[str] | None = None, coordinates: str | None = None, cite: str | Sequence[str] | None = None) -> None
Read a function's signature, refusing one a graph cannot use.
Source code in python/ligase/graph.py
__call__ ¶
Record a call and return a handle on what it would produce.
The body is not run. Missing or surplus arguments still fail here, exactly as they would for the undecorated function.
Source code in python/ligase/graph.py
step ¶
step(function: Callable[P, R] | None = None, /, *, tool: str | Sequence[str] | None = None, coordinates: str | None = None, cite: str | Sequence[str] | None = None) -> Step[P, R] | Callable[[Callable[P, R]], Step[P, R]]
Make a function a pipeline step, without ever running it.
The signature is read once, here. Each parameter annotated with a Ligase
data type becomes an edge in the graph; the rest are plain values. The
return annotation is what says the step produces an Alignment, since
nothing will ask the body.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
function
|
Callable[P, R] | None
|
The function to decorate, when used bare as |
None
|
tool
|
str | Sequence[str] | None
|
The external tool the step shells out to, e.g. |
None
|
coordinates
|
str | None
|
The coordinate convention the step writes, one of
|
None
|
cite
|
str | Sequence[str] | None
|
How the step asks to be cited, as one reference or several.
|
None
|
Returns:
| Type | Description |
|---|---|
Step[P, R] | Callable[[Callable[P, R]], Step[P, R]]
|
A |
Raises:
| Type | Description |
|---|---|
StepDefinitionError
|
If the signature is one a graph cannot use —
an unannotated parameter, a missing or non-Ligase return
annotation, or |
ValueError
|
If |
Source code in python/ligase/graph.py
sh ¶
Produce the output by running a shell command.
The command is not run here and the string is not formatted here: the engine fills it in once it knows where the inputs are, and runs it at whatever width the machine allows.
Placeholders name the step's own parameters:
{ref}— the file bound to the parameterref.{reads.r1},{reads.r2}— the mates of a paired input.{min_freq}— a plain parameter's value.{out}— the file the step must write. A step that writes anywhere else produces nothing, as far as the engine is concerned.
Every value is substituted as exactly one shell word, so a path with a
space in it stays one path. For a literal brace — an awk '{{print $1}}'
— double it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
command
|
str
|
The command, with placeholders. |
required |
Returns:
| Type | Description |
|---|---|
R
|
A recipe, typed as the data the step declares, so a body reads as |
R
|
|
Source code in python/ligase/recipes.py
write ¶
Produce the output in Python, by writing the file yourself.
function is called with the path to write to. It is the one thing in a
run that takes the GIL, so steps written this way do not run in parallel
with each other — which is the right trade for an interpretation step
and the wrong one for anything that does real work. Prefer lg.sh.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
function
|
Callable[[Path], None]
|
Called with the path to write to. |
required |
Returns:
| Type | Description |
|---|---|
R
|
A recipe, typed as the data the step declares. |
Source code in python/ligase/recipes.py
handle ¶
The handle behind what a step returned.
A type checker sees align(reads, ref) as returning an Alignment,
which is what lets it follow a pipeline and catch a mis-wired one while
you are still editing. At runtime the value is a StepOutput — data that
does not exist yet — and this is how to reach it without writing a cast
at every call site.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output
|
object
|
What a step returned. |
required |
Returns:
| Type | Description |
|---|---|
StepOutput
|
The handle, with its step, its arguments and (once a |
StepOutput
|
been built) the dimensions the output will carry. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If this is not a step's output — loaded data, say, which is already the thing itself. |
Source code in python/ligase/graph.py
Checking without running¶
ligase ¶
Ligase: type-safe, reproducible computational biology pipelines.
Biological data types carry dimensions (organism, reference build, coordinate system, sample set), and the engine refuses to connect steps whose dimensions do not match -- like units in physics.
>>> import ligase as lg
>>> from ligase.types import Alignment, Reads, Reference
>>> hxb2 = lg.reference("refs/HXB2.fasta", organism="HIV-1", build="HXB2")
>>> samples = lg.samples("data/*.fastq.gz", paired=True)
>>> @lg.step(tool="minimap2")
... def align(reads: Reads, ref: Reference) -> Alignment: ...
>>> pipe = lg.Pipeline(samples.map(lambda s: align(s, hxb2)))
>>> pipe.check() # type-checks every step; nothing runs
>>> pipe.run() # parallel, cached, per-sample fan-out
check_step ¶
Check a step's inputs, raising on the first disagreement.
Every disagreement is found before anything is raised, so the raised
error's errors attribute holds all of them. Nothing is computed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
step
|
str
|
The step's name, used in the messages. |
required |
bindings
|
Mapping[str, Dataset]
|
The step's inputs, by the name the step knows each by. |
required |
Raises:
| Type | Description |
|---|---|
CheckError
|
If any two inputs disagree. The subclass says what kind
of disagreement it is: |
Source code in python/ligase/__init__.py
dimension_errors ¶
Return every dimension disagreement among a step's inputs.
One step on its own, for when you are not building a pipeline. A whole
pipeline is checked with lg.Pipeline(...).check(), which also knows
what each step requires of the ones before it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
step
|
str
|
The step's name, used in the messages. |
required |
bindings
|
Mapping[str, Dataset]
|
The step's inputs, by the name the step knows each by. |
required |
Returns:
| Type | Description |
|---|---|
list[CheckError]
|
One error per disagreement, most general first. Empty if the step's |
list[CheckError]
|
inputs are consistent. Every error carries the full list in its |
list[CheckError]
|
|
Source code in python/ligase/__init__.py
Data types¶
ligase ¶
Ligase: type-safe, reproducible computational biology pipelines.
Biological data types carry dimensions (organism, reference build, coordinate system, sample set), and the engine refuses to connect steps whose dimensions do not match -- like units in physics.
>>> import ligase as lg
>>> from ligase.types import Alignment, Reads, Reference
>>> hxb2 = lg.reference("refs/HXB2.fasta", organism="HIV-1", build="HXB2")
>>> samples = lg.samples("data/*.fastq.gz", paired=True)
>>> @lg.step(tool="minimap2")
... def align(reads: Reads, ref: Reference) -> Alignment: ...
>>> pipe = lg.Pipeline(samples.map(lambda s: align(s, hxb2)))
>>> pipe.check() # type-checks every step; nothing runs
>>> pipe.run() # parallel, cached, per-sample fan-out
Dataset ¶
Data of a known kind, carrying the dimensions inferred from it.
Source code in python/ligase/types.py
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 | |
file
property
¶
The file this data is, for code that has to open it.
path is the honest answer to "where did this come from, if
anywhere?", so it can be None — a step's output carries dimensions
worked out before anything ran, and has no file of its own until it
does. This is the answer for the other question, the one a
lg.write body asks:
return lg.write(lambda out: interpret(v.file, out))
Inside that function the steps above have run, so there is a file, and saying so in the type is what keeps a body from having to prove it.
Raises:
| Type | Description |
|---|---|
ValueError
|
If this data has no file behind it at all. |
applicable
property
¶
The dimensions that mean anything for this kind of data.
A dimension outside this set is not a gap to be filled in: asking a FASTA for its quality encoding is a category error.
dimensions
property
¶
Every dimension that has a known value, by name.
contigs
property
¶
The contigs of the reference this data is on, in file order.
__init__ ¶
dimension ¶
One dimension's value, or None if it is unknown or inapplicable.
unknown_reason ¶
Why an applicable dimension has no value.
None when the dimension is known, or when it does not apply to this kind of data at all.
Reference ¶
Reads ¶
Samples ¶
The samples a glob matched, in the order their files appeared.
Iterable, indexable and sized, so it can be used as an ordinary sequence
of Reads. map is the part the golden example uses.
Source code in python/ligase/samples.py
ids
property
¶
Each sample's identifier, in order.
Taken from the filenames, with any mate marker removed, unless the reads were loaded with the identifier declared.
__init__ ¶
map ¶
Apply a chain of steps to every sample.
Nothing is executed. build is called once per sample and returns
whatever the last step in the chain returns — a handle, not data —
so the result is one output per sample, ready for lg.Pipeline.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
build
|
Callable[[Reads], T]
|
What to do with one sample's reads. |
required |
Returns:
| Type | Description |
|---|---|
list[T]
|
One result per sample, in order. |
Source code in python/ligase/samples.py
__len__ ¶
__iter__ ¶
__getitem__ ¶
Alignment ¶
Variants ¶
Intervals ¶
Bases: Dataset
Genomic intervals (BED/GFF).
The one type whose coordinates dimension varies by format: BED is
0-based half-open, GFF is 1-based closed. Feeding one to a tool
expecting the other produces results that are plausible and off by one.
Source code in python/ligase/types.py
Contig
dataclass
¶
One sequence in a reference.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
The name as written: |
length |
int | None
|
Length in bases, or None when the file records no length. |
md5 |
str | None
|
MD5 of the uppercased sequence, as the SAM specification defines
|
Source code in python/ligase/types.py
DimensionValue
dataclass
¶
A dimension's value, and where it came from.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
The dimension's name, e.g. |
value |
str
|
The value, rendered for a human. |
source |
str
|
Where it came from, e.g. |
Source code in python/ligase/types.py
StepOutput ¶
A handle on data a step would produce.
Returned by calling a Step. It holds no data and has never touched a
file; what it knows is which step would make it, and from what. Once a
Pipeline has been built from it, dataset holds the dimensions the
engine propagated — the dimensions the output will have, worked out
without running anything.
Attributes:
| Name | Type | Description |
|---|---|---|
step |
The step that would produce it. |
|
arguments |
Everything the step was called with, by parameter name. |
Source code in python/ligase/graph.py
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 | |
dataset
property
¶
The propagated output dataset, once a Pipeline has been built.
None before that: propagation is the graph's work, and there is no
graph until a pipeline asks for one.
file
property
¶
Where the output is, once the step has produced it.
The same name Dataset.file has, because a body cannot tell which
it was handed: a step's input is loaded data for the first step of a
pipeline and another step's handle after that. A lg.write body
reads it inside the function it hands back, by which time the engine
has run whatever comes above it:
return lg.write(lambda out: interpret(v.file, out))
Raises:
| Type | Description |
|---|---|
RuntimeError
|
Before the step has run, when there is no file to
name. A shell command should use |
__init__ ¶
Record a deferred call.
Source code in python/ligase/graph.py
inputs ¶
The data arguments, paired with the parameters they filled.
Written
dataclass
¶
A step whose work is Python, and writes its own output.
Attributes:
| Name | Type | Description |
|---|---|---|
function |
Callable[[Path], None]
|
Called with the path to write to, once the engine has decided what that path is. |
Source code in python/ligase/recipes.py
Resistance interpretation¶
ligase ¶
Ligase: type-safe, reproducible computational biology pipelines.
Biological data types carry dimensions (organism, reference build, coordinate system, sample set), and the engine refuses to connect steps whose dimensions do not match -- like units in physics.
>>> import ligase as lg
>>> from ligase.types import Alignment, Reads, Reference
>>> hxb2 = lg.reference("refs/HXB2.fasta", organism="HIV-1", build="HXB2")
>>> samples = lg.samples("data/*.fastq.gz", paired=True)
>>> @lg.step(tool="minimap2")
... def align(reads: Reads, ref: Reference) -> Alignment: ...
>>> pipe = lg.Pipeline(samples.map(lambda s: align(s, hxb2)))
>>> pipe.check() # type-checks every step; nothing runs
>>> pipe.run() # parallel, cached, per-sample fan-out
Provenance and auditing¶
ligase ¶
Ligase: type-safe, reproducible computational biology pipelines.
Biological data types carry dimensions (organism, reference build, coordinate system, sample set), and the engine refuses to connect steps whose dimensions do not match -- like units in physics.
>>> import ligase as lg
>>> from ligase.types import Alignment, Reads, Reference
>>> hxb2 = lg.reference("refs/HXB2.fasta", organism="HIV-1", build="HXB2")
>>> samples = lg.samples("data/*.fastq.gz", paired=True)
>>> @lg.step(tool="minimap2")
... def align(reads: Reads, ref: Reference) -> Alignment: ...
>>> pipe = lg.Pipeline(samples.map(lambda s: align(s, hxb2)))
>>> pipe.check() # type-checks every step; nothing runs
>>> pipe.run() # parallel, cached, per-sample fan-out
Methods
dataclass
¶
How a set of results was produced.
Attributes:
| Name | Type | Description |
|---|---|---|
steps |
list[StepMethods]
|
Each distinct way a step was run, in the order the pipeline runs them. |
gaps |
list[MethodsGap]
|
Steps nothing is known about. |
references |
list[PinnedReference]
|
Every reference any step was given, pinned, with no duplicates. |
citations |
list[str]
|
The reference list, as a methods section prints it. |
uncited |
list[str]
|
Tools with nothing to cite — named rather than omitted, so a short reference list cannot pass for a complete one. |
engine |
str
|
The version of Ligase that produced the results. |
platform |
str
|
The platform they were produced on. |
summary |
str
|
One line — |
text |
str
|
The paragraph and the reference list, as the command line prints them. |
bundle |
Bundle | None
|
The bundle written, where one was asked for. |
verification |
Verification | None
|
What checking a bundle found, where one was asked for. |
Source code in python/ligase/provenance.py
accounted_for
property
¶
Whether every step's production is recorded.
False means the paragraph has a hole in it and says so.
StepMethods
dataclass
¶
One way a step was run.
One written step becomes one node per sample, and all of them are one entry here. Where two nodes of a step genuinely were run differently they are two entries, because then the difference is the thing worth reporting.
Attributes:
| Name | Type | Description |
|---|---|---|
step |
str
|
The step's name, as written. |
nodes |
int
|
How many nodes this covers. |
scopes |
list[str]
|
What tells them apart, e.g. the sample identifiers. |
scope_kind |
str | None
|
What kind of thing that is, e.g. |
tools |
list[tuple[str, str]]
|
Each tool and the whole version it printed. |
parameters |
list[tuple[str, str]]
|
Each plain parameter and its value, as it was hashed. |
command |
str | None
|
The command as written in the pipeline, placeholders and
all, or |
Source code in python/ligase/provenance.py
MethodsGap
dataclass
¶
A step nothing is known about.
Its output is in the cache from a run that recorded no provenance, and
nothing can reconstruct how it was produced: the command that would have
said so is not in the hash, by design. ligase run --force runs it
again and records it.
Attributes:
| Name | Type | Description |
|---|---|---|
step |
str
|
The step's name. |
scopes |
list[str]
|
What tells its nodes apart. |
nodes |
int
|
How many of them are unaccounted for. |
Source code in python/ligase/provenance.py
Bundle
dataclass
¶
A reproducibility bundle that was written.
Attributes:
| Name | Type | Description |
|---|---|---|
root |
str
|
Where it is. |
files |
list[str]
|
Everything in it, relative to the root. |
steps |
int
|
How many steps it accounts for. |
gaps |
int
|
How many it could not. |
Source code in python/ligase/provenance.py
__repr__ ¶
Verification
dataclass
¶
What checking a bundle against this machine found.
Attributes:
| Name | Type | Description |
|---|---|---|
results |
list[ResultCheck]
|
Every result the bundle recorded. |
inputs |
list[InputCheck]
|
Every input it recorded. |
reproduced |
bool
|
Whether every recorded result came out the same. |
verdict |
str
|
The worst thing found. |
summary |
str
|
One line — |
text |
str
|
The whole report as the command line prints it. |
Source code in python/ligase/provenance.py
moved
property
¶
The inputs that are not the ones the bundle was built from.
Worth reading before any differs verdict: a changed input explains
a changed output, and a bundle cannot fetch its own data.
PinnedReference
dataclass
¶
A reference sequence, pinned as firmly as its file allows.
Nothing here is declared or guessed. The accession is the sequence name
where the name is one — K03455.1 carries its own version — and the
checksum is the MD5 the SAM specification defines for @SQ M5, over the
uppercased sequence with whitespace removed.
Attributes:
| Name | Type | Description |
|---|---|---|
param |
str
|
The parameter it filled. |
path |
str
|
Where it was when the step ran. |
build |
str | None
|
The label it was declared under, e.g. |
accession |
str | None
|
The accession with its version, where the sequence name
is one, and |
contigs |
int
|
How many sequences it holds. |
length |
int
|
Their total length in bases. |
checksum |
str | None
|
The MD5 of the sequence, for a single-sequence reference. |
fingerprint |
str
|
A short digest of the whole identity, always present. |
Source code in python/ligase/provenance.py
AuditReport
dataclass
¶
What an audit found.
Attributes:
| Name | Type | Description |
|---|---|---|
steps |
list[StepAudit]
|
Every node audited, in graph order. |
failures |
list[StepFailure]
|
Every node that could not be audited because it failed. |
verdict |
str
|
The worst verdict any node got — the worst rather than the commonest, since one irreproducible sample in a cohort is an irreproducible step. |
summary |
str
|
One line — |
text |
str
|
The whole report as the command line prints it, worded by the engine so that every surface reads the same. |
Source code in python/ligase/audit.py
unreproducible
property
¶
The nodes whose two runs disagreed about the result.
StepAudit
dataclass
¶
What two runs of one step showed.
Attributes:
| Name | Type | Description |
|---|---|---|
step |
str
|
The step's name. |
sample |
str | None
|
The sample it was for, or |
scope |
str | None
|
How a report names this node where its step's name is shared
— |
verdict |
str
|
|
first |
str
|
The first run's output hash. |
second |
str
|
The second run's output hash. |
first_canonical |
str
|
What the first run's output means. |
second_canonical |
str
|
What the second run's output means. |
first_duration_ms |
int
|
How long the first run took. |
second_duration_ms |
int
|
How long the second run took. |
node |
int
|
Which node of the graph it was. |
Source code in python/ligase/audit.py
reproducible
property
¶
Whether the two runs agreed on the result.
True for a step whose bytes moved and whose meaning did not: that is what reproducible means here.
Report
dataclass
¶
What a check found.
Attributes:
| Name | Type | Description |
|---|---|---|
errors |
list[CheckError]
|
One error per failing step, in the order the steps run. A problem that hits four samples is four errors, each naming its own sample. |
summary |
str
|
One line summarising the lot — |
text |
str
|
The whole report as the command line prints it: each distinct problem stated once, with every sample it affects named, and the summary at the end. Worded by the engine so that every surface reports a check the same way. |
Source code in python/ligase/graph.py
RunReport
dataclass
¶
Everything a run did.
Attributes:
| Name | Type | Description |
|---|---|---|
steps |
list[StepRun]
|
Every step that produced an output, in graph order. |
failures |
list[StepFailure]
|
Every step that did not. |
summary |
str
|
One line — |
text |
str
|
The whole report as the command line prints it, worded by the engine so that every surface reads the same. |
hashed |
int
|
Input files that had to be read and hashed. |
prefiltered |
int
|
Input files whose hash was already known from their size and mtime, and so were not read at all. |
canonicalised |
int
|
Files that had to be parsed to find out what they
mean. Like |
Source code in python/ligase/run.py
outputs ¶
Where one step's outputs are, in graph order.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
step
|
str
|
The step's name. Under fan-out there is one output per sample. |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
One path per node of that name. |
Source code in python/ligase/run.py
StepRun
dataclass
¶
One step that produced an output.
Attributes:
| Name | Type | Description |
|---|---|---|
step |
str
|
The step's name. |
sample |
str | None
|
The sample it was for, or |
outcome |
str
|
|
output |
str
|
Where the output is, in the content-addressed store. |
key |
str
|
The cache key, as hex. |
hash |
str
|
The hash of the output's bytes, as hex, which is also its name in the store. |
canonical |
str
|
The hash of what the output means, as hex: its records sorted and its volatile headers stripped. This is what the steps below were keyed on, so two runs that agree here skip everything downstream however far their bytes diverged. |
duration_ms |
int
|
How long it took, when it ran; zero otherwise. |
node |
int
|
Which node of the graph it was. |
notes |
tuple[str, ...]
|
What canonicalising the output noticed and its hash cannot say — one sentence each, and almost always none. A note is not a failure: the step ran and its result stands. The only note in v0.1 reports a sample identifier that is a file name rather than a sample, which makes this output's canonical hash depend on where that file was. |
Source code in python/ligase/run.py
Errors¶
Every failure mode has its own type, so a caller can tell a reference mismatch from a naming mismatch without reading the message.
ligase ¶
Ligase: type-safe, reproducible computational biology pipelines.
Biological data types carry dimensions (organism, reference build, coordinate system, sample set), and the engine refuses to connect steps whose dimensions do not match -- like units in physics.
>>> import ligase as lg
>>> from ligase.types import Alignment, Reads, Reference
>>> hxb2 = lg.reference("refs/HXB2.fasta", organism="HIV-1", build="HXB2")
>>> samples = lg.samples("data/*.fastq.gz", paired=True)
>>> @lg.step(tool="minimap2")
... def align(reads: Reads, ref: Reference) -> Alignment: ...
>>> pipe = lg.Pipeline(samples.map(lambda s: align(s, hxb2)))
>>> pipe.check() # type-checks every step; nothing runs
>>> pipe.run() # parallel, cached, per-sample fan-out
CheckError ¶
Bases: Exception
A pipeline will not work, found before anything ran.
Attributes:
| Name | Type | Description |
|---|---|---|
step |
The step the problem was found in. |
|
dimension |
The name of the dimension involved, where one is. |
|
scope |
What distinguishes that step from the others of the same name,
as a |
|
errors |
list[CheckError]
|
Every problem found in the same pass, this one included. Checking reports all of them at once rather than one per run, because fixing errors one per overnight run is the problem Ligase exists to remove. |
Source code in python/ligase/errors.py
__init__ ¶
__init__(message: str, step: str, dimension: str | None, scope: tuple[str, str] | None = None) -> None
Record a problem, its step, its dimension and which step it was.
Source code in python/ligase/errors.py
DimensionError ¶
Bases: CheckError
Two inputs to a step disagree about a dimension.
The message names the step, both conflicting values, where each value
came from, and asks a leading question. The provenance is the part that
makes it actionable: knowing two references disagree sends you hunting,
while knowing one came from a BAM @SQ header and the other from the
FASTA you passed tells you what to change.
Source code in python/ligase/errors.py
ContigNamingError ¶
Bases: DimensionError
The same contigs under different names, such as chr1 against 1.
Distinct from a plain DimensionError because the fix is distinct: a
renaming step, not a different reference. Still a DimensionError, so
code that wants to catch any dimension problem can.
Source code in python/ligase/errors.py
ContigOrderError ¶
Bases: DimensionError
The same contigs in a different order.
htslib matches contigs by name, so bcftools does not mind. GATK
requires sequence dictionaries in matching order and will reject this.
Source code in python/ligase/errors.py
UndeclaredDimensionError ¶
Bases: DimensionError
A dimension some step requires is unknown and must be declared.
Raised only because a step actually joins on it: an unknown dimension nothing downstream requires is allowed to stay unknown. The message names the data that has to declare it and the route by which it reaches the step that needs it, which for a value propagated through the graph are two different places.
Source code in python/ligase/errors.py
StepTypeError ¶
Bases: CheckError
A step was handed a kind of data it does not declare.
Not a DimensionError: nothing disagrees about the data, the pipeline is
simply wired up wrong. Reported instead of that step's dimension errors
rather than alongside them, because comparing the dimensions of bindings
the step never declared would describe a pipeline you did not write.
Source code in python/ligase/errors.py
StepDefinitionError ¶
Bases: TypeError
A decorated function cannot be used as a step.
Raised by @lg.step as the module is imported, not at check time: a
missing annotation is a mistake in the pipeline's source, and the sooner
it is said the less there is to read. A TypeError, because that is what
a badly typed definition is.
Source code in python/ligase/errors.py
RunError ¶
Bases: Exception
A step failed.
Attributes:
| Name | Type | Description |
|---|---|---|
report |
The whole run, including everything that did succeed — which for a cohort is usually most of it. |
|
failures |
The steps that failed, as a shortcut. |
Source code in python/ligase/run.py
__init__ ¶
Carry the whole report, not just the first failure.
Source code in python/ligase/run.py
StepFailure
dataclass
¶
One step that did not produce anything.
A step whose input failed is in neither list: one cause, one failure.
Attributes:
| Name | Type | Description |
|---|---|---|
step |
str
|
The step's name. |
sample |
str | None
|
The sample it was for, where it stands for one. |
message |
str
|
What went wrong, in the tool's own words where there are any. |
node |
int
|
Which node of the graph it was. |
Source code in python/ligase/run.py
InputCheck
dataclass
¶
One input file, as a bundle recorded it and as it is here.
Attributes:
| Name | Type | Description |
|---|---|---|
step |
str
|
The step it fed. |
param |
str
|
The parameter it filled. |
path |
str
|
Where the bundle said it was. |
presence |
str
|
|
Source code in python/ligase/provenance.py
ResultCheck
dataclass
¶
One result, as a bundle recorded it and as this machine produced it.
Attributes:
| Name | Type | Description |
|---|---|---|
step |
str
|
The step's name. |
scope |
str | None
|
What tells this node apart, where anything does. |
verdict |
str
|
|
expected |
str
|
The canonical hash the bundle recorded. |
found |
str | None
|
The canonical hash produced here, or |
same_key |
bool
|
Whether the cache key matched too. False with a verdict of
|
Source code in python/ligase/provenance.py
Version¶
ligase ¶
Ligase: type-safe, reproducible computational biology pipelines.
Biological data types carry dimensions (organism, reference build, coordinate system, sample set), and the engine refuses to connect steps whose dimensions do not match -- like units in physics.
>>> import ligase as lg
>>> from ligase.types import Alignment, Reads, Reference
>>> hxb2 = lg.reference("refs/HXB2.fasta", organism="HIV-1", build="HXB2")
>>> samples = lg.samples("data/*.fastq.gz", paired=True)
>>> @lg.step(tool="minimap2")
... def align(reads: Reads, ref: Reference) -> Alignment: ...
>>> pipe = lg.Pipeline(samples.map(lambda s: align(s, hxb2)))
>>> pipe.check() # type-checks every step; nothing runs
>>> pipe.run() # parallel, cached, per-sample fan-out