crispr_analysis_utils.igvf_export¶
crispr_analysis_utils.igvf_export ¶
Write the guide design in the IGVF per-guide metadata format.
The three steps before this one between them know everything the format asks: alignment gives each guide its site and its PAM, annotation gives the genes, and element mapping gives the element and the guide's role.
What a guide targets is decided from the genome, not from the design's own label for the element. The exception is a validated enhancer, since that an element was shown to regulate a gene is experimental knowledge no annotation can supply.
COLUMNS
module-attribute
¶
COLUMNS = {'guide_id': 'Unique name of the guide.', 'spacer': "The targeting sequence of the gRNA, read 5' to 3', in DNA bases.", 'oligo': "The sequence the library ordered, without the PAM: the spacer plus any base 5' of it, such as a G added for U6 transcription.", 'n_oligos': 'How many library entries share this spacer. Above one, they are one feature in the counts and the reads cannot be told apart, so the counts are a sum.', 'targeting': 'TRUE when the guide targets a locus relevant to the experiment. FALSE for a safe-targeting or non-targeting control.', 'type': "The guide's role: targeting, safe-targeting, non-targeting or positive control.", 'guide_chr': "Chromosome of the guide's target sequence.", 'guide_start': "Start of the guide's target sequence, 0-based.", 'guide_end': 'End of it, half-open, and without the PAM.', 'strand': 'Strand of the genomic sequence being targeted.', 'pam': "The protospacer adjacent motif as the genome holds it, 5' to 3' on the targeted strand, immediately 3' of the spacer.", 'element_location': 'genic when the element overlaps a protein-coding gene, intergenic when it does not. Independent of genomic_element, which tests promoter and enhancer before it ever looks at the gene body.', 'genomic_element': 'What the targeted element is: promoter, enhancer, distal element, exon or intron. Decided from the genome.', 'intended_target_name': "Names the target: the gene's ENSEMBL id for a promoter, the exon's ENSEMBL id for an exon, and the coordinates otherwise.", 'intended_target_chr': 'Chromosome of the target element.', 'intended_target_start': 'Start of the target element, 0-based.', 'intended_target_end': 'End of it, half-open.', 'putative_target_genes': "Every gene in ENSEMBL associated with the element, comma-separated. A measured pair can name several, as a bidirectional promoter does; an inferred one names the nearest TSS's gene alone.", 'reporter': 'Sequence of the reporter element. Unused here.', 'imperfect': 'Sequence of the matching perfect guide. Unused here.'}
The columns of the IGVF per-guide metadata table, in order.
ELEMENTS
module-attribute
¶
ELEMENTS = (PROMOTER, ENHANCER, DISTAL, EXON, INTRON)
The genomic_element values this writes. The format allows more.
PROMOTER_WINDOW
module-attribute
¶
PROMOTER_WINDOW = 2000
Within this of a TSS, an element is a promoter.
The format defines distal element as lying more than 2 kb from any
annotated TSS, so the same threshold decides the other side.
VALIDATED
module-attribute
¶
VALIDATED = 'e2g_validated'
The one element category taken from the design rather than the genome.
POSITIVE_CATEGORIES
module-attribute
¶
POSITIVE_CATEGORIES = ('promoter', VALIDATED)
The design's element kinds meant as positive controls.
ExportError ¶
Bases: RuntimeError
The inputs cannot produce a valid table.
Source code in src/crispr_analysis_utils/igvf_export.py
123 124 | |
RunResult
dataclass
¶
What run produced.
Attributes:
-
outdir(Path) –The output folder.
-
table(DataFrame) –The IGVF table, one row per guide.
-
elements(DataFrame) –How each element was classified.
-
metadata(dict) –The record written under
run_metadata/.
Source code in src/crispr_analysis_utils/igvf_export.py
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 | |
classify_elements ¶
classify_elements(elements: DataFrame, store, promoters: DataFrame, *, promoter_window: int = PROMOTER_WINDOW, genes: Mapping[str, list[str]] | None = None) -> pd.DataFrame
Decide what each element is, and what it targets.
Parameters:
-
elements(DataFrame) –The elements, as
element_mapping.read_elementsreturns them. -
store–The annotation store, as
guide_annotation.load_storereturns it. -
promoters(DataFrame) –Transcription start sites, as
guide_annotation.read_promotersreturns them. -
promoter_window(int, default:PROMOTER_WINDOW) –Within this many bases of a TSS, an element is a promoter.
-
genes(Mapping[str, list[str]] | None, default:None) –Element id to the ENSEMBL ids known to be regulated by it, for the elements where that was measured rather than inferred.
Returns:
-
DataFrame–One row per element:
genomic_element,intended_target_name, the target's coordinates andputative_target_genes.
Notes
Everything but VALIDATED is decided from the genome. The design's own
label for an element is not evidence about what the element is.
Source code in src/crispr_analysis_utils/igvf_export.py
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 | |
build_table ¶
build_table(alignment: DataFrame, mapping: DataFrame, elements: DataFrame, *, positive_categories: tuple[str, ...] = POSITIVE_CATEGORIES) -> pd.DataFrame
Assemble the IGVF table, one row per guide.
Parameters:
-
alignment(DataFrame) –guide_genome_annotation.tsv. -
mapping(DataFrame) –guide_element_mapping.tsv. -
elements(DataFrame) –What
classify_elementsreturned. -
positive_categories(tuple[str, ...], default:POSITIVE_CATEGORIES) –The design's element categories meant as positive controls. A guide is only called one when the genome agrees the element is a promoter, or the element is a validated enhancer.
Returns:
-
DataFrame–The columns of
COLUMNS, one row per guide, in library order.
Raises:
-
ExportError–A guide has more than one spacer, which the format forbids.
Source code in src/crispr_analysis_utils/igvf_export.py
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 | |
write_table ¶
write_table(path: str | PathLike[str], table: DataFrame) -> None
Write the IGVF table, with empty cells where a field does not apply.
Source code in src/crispr_analysis_utils/igvf_export.py
535 536 537 | |
write_columns_yaml ¶
write_columns_yaml(path: str | PathLike[str]) -> None
Write guide_metadata_columns.yaml, generated from COLUMNS so it cannot drift.
Source code in src/crispr_analysis_utils/igvf_export.py
540 541 542 543 544 | |
counts ¶
counts(table: DataFrame, elements: DataFrame) -> dict
What the table holds, by type and by element class.
Source code in src/crispr_analysis_utils/igvf_export.py
547 548 549 550 551 552 553 554 555 556 557 558 | |
run ¶
run(alignment: str | PathLike[str], mapping: str | PathLike[str], elements: str | PathLike[str], store: str | PathLike[str], outdir: str | PathLike[str], *, promoters: str | PathLike[str] | None = None, genes: str | PathLike[str] | None = None, promoter_window: int = PROMOTER_WINDOW) -> RunResult
Write the guide design in the IGVF per-guide metadata format.
Parameters:
-
alignment(str | PathLike[str]) –guide_genome_annotation.tsv. -
mapping(str | PathLike[str]) –guide_element_mapping.tsv. -
elements(str | PathLike[str]) –The elements BED the mapping used.
-
store(str | PathLike[str]) –The annotation store, which supplies the genes, exons and exon ids.
-
outdir(str | PathLike[str]) –Where the table goes. Nothing is written outside it.
-
promoters(str | PathLike[str] | None, default:None) –A TSS BED. Without one, the store's reference transcript starts.
-
genes(str | PathLike[str] | None, default:None) –A TSV of measured element-to-gene pairs, with an element id column and an ENSEMBL id column. Used for the elements whose gene was measured rather than inferred.
-
promoter_window(int, default:PROMOTER_WINDOW) –Within this many bases of a TSS, an element is a promoter.
Returns:
-
RunResult–The table, the element classification and the record.
Source code in src/crispr_analysis_utils/igvf_export.py
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 | |